Skip to content

Commit f28c512

Browse files
authored
check that label/annotation values are strings in case of unstructured dependents (#407)
1 parent 65ad3d8 commit f28c512

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

internal/kustomize/kustomization.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func parseKustomization(fsys fs.FS, kustomizationPath string, options Kustomizat
196196

197197
for _, path := range options.IncludedFiles {
198198
if filepath.IsAbs(path) {
199-
return nil, fmt.Errorf("include path (%s) must be absolute", path)
199+
return nil, fmt.Errorf("include path (%s) must not be absolute", path)
200200
}
201201
absolutePath := filepath.Clean(filepath.Join(kustomizationPath, path))
202202
if isSubdirectory(absolutePath, kustomizationPath) {

pkg/reconciler/util.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ func normalizeObjects(objects []client.Object, scheme *runtime.Scheme) ([]client
234234
if gvk.Version == "" || gvk.Kind == "" {
235235
return nil, fmt.Errorf("unstructured object %s is missing type information", types.ObjectKeyToString(object))
236236
}
237+
// explicitly check that metadata.labels and metadata.annotations are map[string]string;
238+
// the same method unstructured.NestedNullCoercingStringMap() is used in GetLabels() and GetAnnotations(), but errors
239+
// are discarded there; this is why we check it here
240+
if _, _, err := unstructured.NestedNullCoercingStringMap(unstructuredObject.Object, "metadata", "labels"); err != nil {
241+
return nil, legacyerrors.Wrapf(err, "unstructured object %s has invalid labels (probably because of non-string label values)", types.ObjectKeyToString(object))
242+
}
243+
if _, _, err := unstructured.NestedNullCoercingStringMap(unstructuredObject.Object, "metadata", "annotations"); err != nil {
244+
return nil, legacyerrors.Wrapf(err, "unstructured object %s has invalid annotations (probably because of non-string annotation values)", types.ObjectKeyToString(object))
245+
}
237246
if scheme.Recognizes(gvk) {
238247
typedObject, err := scheme.New(gvk)
239248
if err != nil {

0 commit comments

Comments
 (0)