Skip to content

[BUG] Mistyped labels/annotations are silently ignored sometimes (not leading to errors) #403

@cbarbian-sap

Description

@cbarbian-sap

Describe the bug

The bug reported here happens for objects

  • which are not recognized by the effective target schema (typically CRDs) and
  • for which the active generator renders invalid labels or annotations, in the sense that the values are not string values (typical scenario: forgotten quotes around booleans or numerics).

These label/annotation key/value pairs are just swallowed. That is, the object is applied without any error to Kubernetes, without the erroneous label/annotation (obviously), and no error is thrown.

Tested with Version

v0.3.134

To Reproduce

Create a component containing a dependent object which is an instance of a CRD. Having a label with a non-string value. Observe that the component is applied without complaints, without the label (of course).

Expected behavior

An error should be raised during rendering.

Additional context

This seems to happen because objects not recognized by the target schema are processed through the unstructured client. If, for such an object,

func (u *Unstructured) GetLabels() map[string]string

or

func (u *Unstructured) GetAnnotations() map[string]string

is called, things start to go wrong. Because these two methods (only these?) involve the functionNestedNullCoercingStringMap() (https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured#NestedNullCoercingStringMap), but ignore any errors returned by this function:

func (u *Unstructured) GetLabels() map[string]string {
	m, _, _ := NestedNullCoercingStringMap(u.Object, "metadata", "labels")
	return m
}

(such as type mismatch caused errors).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions