diff --git a/internal/kubernetes/unstructured.go b/internal/kubernetes/unstructured.go index ee4d591..66af6e0 100644 --- a/internal/kubernetes/unstructured.go +++ b/internal/kubernetes/unstructured.go @@ -3,7 +3,6 @@ package kubernetes import ( "encoding/json" "fmt" - "strconv" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" @@ -51,26 +50,21 @@ func ToUnstructured(manifest map[string]interface{}) (unstructured.Unstructured, // Attempt to get annotations as map[string]string // If no errors then nothing else needs to be done - if _, _, err := unstructured.NestedStringMap(m, "metadata", "annotations"); err == nil { + if _, _, err := unstructured.NestedStringMap(u.Object, "metadata", "annotations"); err == nil { return u, nil } - annotationsMap, exists, err := unstructured.NestedMap(m, "metadata", "annotations") + // Attempt to get annotations as map[string]interface{} + annotationsMap, exists, err := unstructured.NestedMap(u.Object, "metadata", "annotations") if err != nil || !exists { return u, err } - // If annotations exist in manifest and are map[string]interface, attempt to convert to map[string]string - annotations := make(map[string]string, len(m)) + // If annotations exist in manifest and are map[string]interface, convert to map[string]string + annotations := make(map[string]string, len(u.Object)) for k, v := range annotationsMap { - if str, ok := v.(string); ok { - annotations[k] = str - } else if int, ok := v.(int); ok { - annotations[k] = strconv.Itoa(int) - } else { - return u, fmt.Errorf("%v accessor error: contains non-string key in the map: %v is of the type %T, expected string", ".metadata.annotations", v, v) - } + annotations[k] = fmt.Sprintf("%v", v) } u.SetAnnotations(annotations)