Skip to content

Commit cb3cad6

Browse files
authored
Merge pull request #43 from devtron-labs/wrong-kind
fix: added check to ensure last-applied config has same kind as the object
2 parents 7ac5c70 + 0cd3682 commit cb3cad6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

kubedd/kubedd.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import (
2222
"fmt"
2323
"github.com/devtron-labs/silver-surfer/pkg"
2424
kLog "github.com/devtron-labs/silver-surfer/pkg/log"
25+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2526
"os"
27+
"strings"
2628
)
2729

2830
var yamlSeparator = []byte("\n---\n")
@@ -114,8 +116,14 @@ func ValidateCluster(cluster *pkg.Cluster, conf *pkg.Config) ([]pkg.ValidationRe
114116
annotations := obj.GetAnnotations()
115117
k8sObj := ""
116118
if val, ok := annotations["kubectl.kubernetes.io/last-applied-configuration"]; ok {
117-
k8sObj = val
118-
} else {
119+
var uns unstructured.Unstructured
120+
if err := uns.UnmarshalJSON([]byte(val)); err != nil {
121+
if strings.EqualFold(uns.GetKind(), obj.GetKind()) {
122+
k8sObj = val
123+
}
124+
}
125+
}
126+
if len(k8sObj) == 0 {
119127
bt, err := obj.MarshalJSON()
120128
if err != nil {
121129
continue

0 commit comments

Comments
 (0)