diff --git a/api/krusty/no_list_items_test.go b/api/krusty/no_list_items_test.go index 27b8ae726..b6cc58742 100644 --- a/api/krusty/no_list_items_test.go +++ b/api/krusty/no_list_items_test.go @@ -61,8 +61,6 @@ metadata: apiVersion: example.com/v1alpha1 kind: MyResourceList metadata: - annotations: - kustomize.config.k8s.io/convertToInlineList: "false" name: test rules: [] `) @@ -77,8 +75,6 @@ metadata: apiVersion: example.com/v1alpha1 kind: MyResourceList metadata: - annotations: - kustomize.config.k8s.io/convertToInlineList: "false" name: test rules: [] `) @@ -95,8 +91,6 @@ resources: apiVersion: infra.protonbase.io/v1alpha1 kind: AccessWhiteList metadata: - annotations: - kustomize.config.k8s.io/convertToInlineList: "false" name: wlmls5769f namespace: dc7i4hyxzw spec: @@ -110,8 +104,6 @@ spec: apiVersion: infra.protonbase.io/v1alpha1 kind: AccessWhiteList metadata: - annotations: - kustomize.config.k8s.io/convertToInlineList: "false" name: wlmls5769f namespace: dc7i4hyxzw spec: @@ -119,4 +111,104 @@ spec: - sourceIps: 0.0.0.0/16 `) +} + +func TestListToIndividualResources(t *testing.T) { + th := kusttest_test.MakeHarness(t) + th.WriteK(".", ` +resources: +- list.yaml +`) + + th.WriteF("list.yaml", ` +apiVersion: v1 +kind: PodList +items: + - apiVersion: v1 + kind: Pod + metadata: + name: my-pod-1 + namespace: default + labels: + app: my-app + spec: + containers: + - name: my-container + image: nginx:1.19.10 + ports: + - containerPort: 80 + - apiVersion: v1 + kind: Pod + metadata: + name: my-pod-2 + namespace: default + labels: + app: my-app + spec: + containers: + - name: my-container + image: nginx:1.19.10 + ports: + - containerPort: 80 + - apiVersion: v1 + kind: Pod + metadata: + name: my-pod-3 + namespace: default + labels: + app: my-app + spec: + containers: + - name: my-container + image: nginx:1.19.10 + ports: + - containerPort: 80 +`) + + m := th.Run(".", th.MakeDefaultOptions()) + + + th.AssertActualEqualsExpected(m, ` +apiVersion: v1 +kind: Pod +metadata: + labels: + app: my-app + name: my-pod-1 + namespace: default +spec: + containers: + - image: nginx:1.19.10 + name: my-container + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Pod +metadata: + labels: + app: my-app + name: my-pod-2 + namespace: default +spec: + containers: + - image: nginx:1.19.10 + name: my-container + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Pod +metadata: + labels: + app: my-app + name: my-pod-3 + namespace: default +spec: + containers: + - image: nginx:1.19.10 + name: my-container + ports: + - containerPort: 80 +`) } \ No newline at end of file diff --git a/api/resource/factory.go b/api/resource/factory.go index c4c6a6e9a..a42f93bb8 100644 --- a/api/resource/factory.go +++ b/api/resource/factory.go @@ -7,7 +7,6 @@ import ( "encoding/json" "fmt" "log" - "strconv" "strings" "sigs.k8s.io/kustomize/api/ifc" @@ -190,16 +189,6 @@ func (rf *Factory) inlineAnyEmbeddedLists( var n0 *yaml.RNode for len(nodes) > 0 { n0, nodes = nodes[0], nodes[1:] - annotations := n0.GetAnnotations() - convertToInlineList, err := strconv.ParseBool(annotations["kustomize.config.k8s.io/convertToInlineList"]) - if err != nil { - convertToInlineList = true - } - if !convertToInlineList { - // if the annotation is set to true, then we should not convert the list to inline - result = append(result, n0) - continue - } kind := n0.GetKind() if !strings.HasSuffix(kind, "List") { result = append(result, n0) @@ -213,7 +202,10 @@ func (rf *Factory) inlineAnyEmbeddedLists( } items, ok := m["items"] if !ok { - // treat as an empty list + // Items field is not present. + // This is not a collections resource. + // read more https://kubernetes.io/docs/reference/using-api/api-concepts/#collections + result = append(result, n0) continue } slice, ok := items.([]interface{})