Skip to content

Commit

Permalink
Issue #790 - Fix application controller panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Matyushentsev authored and Alexander Matyushentsev committed Nov 16, 2018
1 parent 361931f commit fd4f27f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
12 changes: 10 additions & 2 deletions util/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,16 @@ func removeNamespaceAnnotation(orig *unstructured.Unstructured) *unstructured.Un
metadata := metadataIf.(map[string]interface{})
delete(metadata, "namespace")
if annotationsIf, ok := metadata["annotations"]; ok {
annotation := annotationsIf.(map[string]interface{})
if len(annotation) == 0 {
shouldDelete := false
if annotationsIf == nil {
shouldDelete = true
} else {
annotation := annotationsIf.(map[string]interface{})
if len(annotation) == 0 {
shouldDelete = true
}
}
if shouldDelete {
delete(metadata, "annotations")
}
}
Expand Down
20 changes: 20 additions & 0 deletions util/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,23 @@ func TestThreeWayDiffExplicitNamespace(t *testing.T) {
assert.Nil(t, err)
log.Println(ascii)
}

func TestRemoveNamespaceAnnotation(t *testing.T) {
obj := removeNamespaceAnnotation(&unstructured.Unstructured{Object: map[string]interface{}{
"metadata": map[string]interface{}{
"name": "test",
"namespace": "default",
},
}})
assert.Equal(t, "", obj.GetNamespace())

obj = removeNamespaceAnnotation(&unstructured.Unstructured{Object: map[string]interface{}{
"metadata": map[string]interface{}{
"name": "test",
"namespace": "default",
"annotations": make(map[string]interface{}),
},
}})
assert.Equal(t, "", obj.GetNamespace())
assert.Nil(t, obj.GetAnnotations())
}

0 comments on commit fd4f27f

Please sign in to comment.