mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Keep empty map in kustomize output
This commit is contained in:
@@ -156,7 +156,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: busybox-persistent-storage
|
name: busybox-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: busybox-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: busybox-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -232,7 +233,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: nginx-persistent-storage
|
name: nginx-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: nginx-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: nginx-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -258,7 +260,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: busybox-persistent-storage
|
name: busybox-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: busybox-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: busybox-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -332,7 +335,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: nginx-persistent-storage
|
name: nginx-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: nginx-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: nginx-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -459,7 +463,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: busybox-persistent-storage
|
name: busybox-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: busybox-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: busybox-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -559,7 +564,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: busybox-persistent-storage
|
name: busybox-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: busybox-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: busybox-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -661,7 +667,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: busybox-persistent-storage
|
name: busybox-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: busybox-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: busybox-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -762,7 +769,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: busybox-persistent-storage
|
name: busybox-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: busybox-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: busybox-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -957,7 +965,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: busybox-persistent-storage
|
name: busybox-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: busybox-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: busybox-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -1171,7 +1180,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: busybox-persistent-storage
|
name: busybox-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: busybox-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: busybox-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
|
|||||||
@@ -79,7 +79,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: nginx-persistent-storage
|
name: nginx-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: nginx-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: nginx-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
@@ -222,7 +223,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: nginx-persistent-storage
|
name: nginx-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: nginx-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: nginx-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
|
|||||||
@@ -540,7 +540,8 @@ spec:
|
|||||||
- mountPath: /tmp/ps
|
- mountPath: /tmp/ps
|
||||||
name: nginx-persistent-storage
|
name: nginx-persistent-storage
|
||||||
volumes:
|
volumes:
|
||||||
- name: nginx-persistent-storage
|
- emptyDir: {}
|
||||||
|
name: nginx-persistent-storage
|
||||||
- configMap:
|
- configMap:
|
||||||
name: staging-team-foo-configmap-in-base-798k5k7g9f
|
name: staging-team-foo-configmap-in-base-798k5k7g9f
|
||||||
name: configmap-in-base
|
name: configmap-in-base
|
||||||
|
|||||||
@@ -67,14 +67,15 @@ func (e ElementSetter) Filter(rn *RNode) (*RNode, error) {
|
|||||||
matchingElementFound := false
|
matchingElementFound := false
|
||||||
for i := range rn.YNode().Content {
|
for i := range rn.YNode().Content {
|
||||||
elem := rn.Content()[i]
|
elem := rn.Content()[i]
|
||||||
|
newNode := NewRNode(elem)
|
||||||
|
|
||||||
// empty elements are not valid -- they at least need an associative key
|
// empty elements are not valid -- they at least need an associative key
|
||||||
if IsEmpty(NewRNode(elem)) {
|
if IsEmpty(newNode) || IsEmptyMap(newNode) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if this is the element we are matching
|
// check if this is the element we are matching
|
||||||
val, err := NewRNode(elem).Pipe(FieldMatcher{Name: e.Key, StringValue: e.Value})
|
val, err := newNode.Pipe(FieldMatcher{Name: e.Key, StringValue: e.Value})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ kind: Deployment
|
|||||||
spec:
|
spec:
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
containers: {}
|
containers: []
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ kind: Deployment
|
|||||||
{description: `remove list -- empty in src`,
|
{description: `remove list -- empty in src`,
|
||||||
source: `
|
source: `
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items: {}
|
items: []
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -273,7 +273,7 @@ items:
|
|||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
items: {}
|
items: []
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,8 +167,8 @@ spec: {}
|
|||||||
expected: `
|
expected: `
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
spec:
|
spec:
|
||||||
foo: bar1
|
|
||||||
baz: buz
|
baz: buz
|
||||||
|
foo: bar1
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ kind: Deployment
|
|||||||
{description: `remove scalar -- empty in src`,
|
{description: `remove scalar -- empty in src`,
|
||||||
source: `
|
source: `
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
field: {}
|
field: null
|
||||||
`,
|
`,
|
||||||
dest: `
|
dest: `
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -99,7 +99,6 @@ field: value1
|
|||||||
`,
|
`,
|
||||||
expected: `
|
expected: `
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
field: {}
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ kind: Deployment
|
|||||||
spec:
|
spec:
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
containers: {}
|
containers: null
|
||||||
`,
|
`,
|
||||||
update: `
|
update: `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
@@ -379,7 +379,7 @@ kind: Deployment
|
|||||||
spec:
|
spec:
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
containers: {}
|
containers: null
|
||||||
`,
|
`,
|
||||||
local: `
|
local: `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
@@ -584,7 +584,7 @@ kind: Deployment
|
|||||||
spec:
|
spec:
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
containers: {}
|
containers: null
|
||||||
`,
|
`,
|
||||||
local: `
|
local: `
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
|
|||||||
@@ -44,16 +44,17 @@ func IsMissingOrNull(node *RNode) bool {
|
|||||||
return node == nil || node.YNode() == nil || node.YNode().Tag == NullNodeTag
|
return node == nil || node.YNode() == nil || node.YNode().Tag == NullNodeTag
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsEmpty returns true if the RNode is MissingOrNull, or is either a MappingNode with
|
// IsEmpty returns true if the RNode is MissingOrNull
|
||||||
// no fields.
|
|
||||||
func IsEmpty(node *RNode) bool {
|
func IsEmpty(node *RNode) bool {
|
||||||
if IsMissingOrNull(node) {
|
return IsMissingOrNull(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsEmptyMap returns true if the RNode is an empty node or an empty map
|
||||||
|
func IsEmptyMap(node *RNode) bool {
|
||||||
|
if IsEmpty(node) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Empty sequence is a special case and temporarily not considered as empty here.
|
|
||||||
// Some users may want to keep empty sequence for compatibility reason.
|
|
||||||
// For example, use JSON 6902 patch.
|
|
||||||
return node.YNode().Kind == yaml.MappingNode && len(node.YNode().Content) == 0
|
return node.YNode().Kind == yaml.MappingNode && len(node.YNode().Content) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -221,19 +221,19 @@ func TestIsEmpty_Arrays(t *testing.T) {
|
|||||||
func TestIsEmpty_Maps(t *testing.T) {
|
func TestIsEmpty_Maps(t *testing.T) {
|
||||||
node := NewMapRNode(nil)
|
node := NewMapRNode(nil)
|
||||||
// empty map
|
// empty map
|
||||||
if !IsEmpty(node) {
|
if !IsEmptyMap(node) {
|
||||||
t.Fatalf("input: empty map")
|
t.Fatalf("input: empty map")
|
||||||
}
|
}
|
||||||
// map with 1 item
|
// map with 1 item
|
||||||
node = NewMapRNode(&map[string]string{
|
node = NewMapRNode(&map[string]string{
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
})
|
})
|
||||||
if IsEmpty(node) {
|
if IsEmptyMap(node) {
|
||||||
t.Fatalf("input: map with 1 item")
|
t.Fatalf("input: map with 1 item")
|
||||||
}
|
}
|
||||||
// delete the item in map
|
// delete the item in map
|
||||||
node.value.Content = nil
|
node.value.Content = nil
|
||||||
if !IsEmpty(node) {
|
if !IsEmptyMap(node) {
|
||||||
t.Fatalf("input: empty map")
|
t.Fatalf("input: empty map")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func (l *Walker) walkAssociativeSequence() (*yaml.RNode, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if yaml.IsEmpty(val) {
|
if yaml.IsEmpty(val) || yaml.IsEmptyMap(val) {
|
||||||
_, err = dest.Pipe(yaml.ElementSetter{Key: key, Value: value})
|
_, err = dest.Pipe(yaml.ElementSetter{Key: key, Value: value})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -467,7 +467,6 @@ spec:
|
|||||||
replicas: 1
|
replicas: 1
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
creationTimestamp: null
|
|
||||||
labels:
|
labels:
|
||||||
workload.sas.com/class: stateless
|
workload.sas.com/class: stateless
|
||||||
spec:
|
spec:
|
||||||
@@ -498,45 +497,6 @@ spec:
|
|||||||
name: tmp
|
name: tmp
|
||||||
`
|
`
|
||||||
|
|
||||||
// This is the current (incorrect) result we get with kustomize 3.8.1
|
|
||||||
const currentCleanedDeployment = `apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
workload.sas.com/class: stateless
|
|
||||||
name: sas-crunchy-data-postgres-operator
|
|
||||||
spec:
|
|
||||||
replicas: 1
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
workload.sas.com/class: stateless
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- envFrom: []
|
|
||||||
image: sas-crunchy-data-operator-api-server
|
|
||||||
imagePullPolicy: IfNotPresent
|
|
||||||
name: apiserver
|
|
||||||
ports:
|
|
||||||
- containerPort: 8443
|
|
||||||
volumeMounts:
|
|
||||||
- mountPath: /security-ssh
|
|
||||||
name: security-ssh
|
|
||||||
- mountPath: /tmp
|
|
||||||
name: tmp
|
|
||||||
imagePullSecrets: []
|
|
||||||
initContainers: []
|
|
||||||
serviceAccountName: postgres-operator
|
|
||||||
tolerations:
|
|
||||||
- effect: NoSchedule
|
|
||||||
key: workload.sas.com/class
|
|
||||||
operator: Equal
|
|
||||||
value: stateful
|
|
||||||
volumes:
|
|
||||||
- name: security-ssh
|
|
||||||
- name: tmp
|
|
||||||
`
|
|
||||||
|
|
||||||
func TestPatchStrategicMergeTransformerCleanupItems(t *testing.T) {
|
func TestPatchStrategicMergeTransformerCleanupItems(t *testing.T) {
|
||||||
th := kusttest_test.MakeEnhancedHarness(t).
|
th := kusttest_test.MakeEnhancedHarness(t).
|
||||||
PrepBuiltin("PatchStrategicMergeTransformer")
|
PrepBuiltin("PatchStrategicMergeTransformer")
|
||||||
@@ -571,7 +531,7 @@ paths:
|
|||||||
- patch.yaml
|
- patch.yaml
|
||||||
`,
|
`,
|
||||||
anUncleanDeploymentResource,
|
anUncleanDeploymentResource,
|
||||||
currentCleanedDeployment) // prefer expectedCleanedDeployment
|
expectedCleanedDeployment) // prefer expectedCleanedDeployment
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStrategicMergeTransformerNoSchema(t *testing.T) {
|
func TestStrategicMergeTransformerNoSchema(t *testing.T) {
|
||||||
|
|||||||
@@ -9,4 +9,7 @@ require (
|
|||||||
sigs.k8s.io/yaml v1.2.0
|
sigs.k8s.io/yaml v1.2.0
|
||||||
)
|
)
|
||||||
|
|
||||||
replace sigs.k8s.io/kustomize/api v0.5.1 => ../../../api
|
replace (
|
||||||
|
sigs.k8s.io/kustomize/api v0.5.1 => ../../../api
|
||||||
|
sigs.k8s.io/kustomize/kyaml v0.4.2 => ../../../kyaml
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user