Skip to content

Commit

Permalink
Merge pull request #43 from devtron-labs/wrong-kind
Browse files Browse the repository at this point in the history
fix: added check to ensure last-applied config has same kind as the object
  • Loading branch information
ajaydevtron authored Sep 4, 2024
2 parents 7ac5c70 + 0cd3682 commit cb3cad6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions kubedd/kubedd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
"fmt"
"github.com/devtron-labs/silver-surfer/pkg"
kLog "github.com/devtron-labs/silver-surfer/pkg/log"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"os"
"strings"
)

var yamlSeparator = []byte("\n---\n")
Expand Down Expand Up @@ -114,8 +116,14 @@ func ValidateCluster(cluster *pkg.Cluster, conf *pkg.Config) ([]pkg.ValidationRe
annotations := obj.GetAnnotations()
k8sObj := ""
if val, ok := annotations["kubectl.kubernetes.io/last-applied-configuration"]; ok {
k8sObj = val
} else {
var uns unstructured.Unstructured
if err := uns.UnmarshalJSON([]byte(val)); err != nil {
if strings.EqualFold(uns.GetKind(), obj.GetKind()) {
k8sObj = val
}
}
}
if len(k8sObj) == 0 {
bt, err := obj.MarshalJSON()
if err != nil {
continue
Expand Down

0 comments on commit cb3cad6

Please sign in to comment.