Skip to content

Commit

Permalink
testing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
abe garcia committed Jan 9, 2024
1 parent bd7726b commit 34e0e6a
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions internal/kubernetes/unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"encoding/json"
"fmt"
"strconv"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 34e0e6a

Please sign in to comment.