@@ -16,6 +16,7 @@ package admission
16
16
17
17
import (
18
18
"context"
19
+ "maps"
19
20
"net/http"
20
21
21
22
. "github.com/onsi/ginkgo/v2"
@@ -42,8 +43,13 @@ var _ = Describe("Defaulter Handler", func() {
42
43
},
43
44
})
44
45
Expect (resp .Allowed ).Should (BeTrue ())
45
- Expect (resp .Patches ).To (HaveLen (3 ))
46
+ Expect (resp .Patches ).To (HaveLen (4 ))
46
47
Expect (resp .Patches ).To (ContainElements (
48
+ jsonpatch.JsonPatchOperation {
49
+ Operation : "add" ,
50
+ Path : "/labels" ,
51
+ Value : map [string ]any {"foo" : "bar" },
52
+ },
47
53
jsonpatch.JsonPatchOperation {
48
54
Operation : "add" ,
49
55
Path : "/replica" ,
@@ -74,8 +80,13 @@ var _ = Describe("Defaulter Handler", func() {
74
80
},
75
81
})
76
82
Expect (resp .Allowed ).Should (BeTrue ())
77
- Expect (resp .Patches ).To (HaveLen (2 ))
83
+ Expect (resp .Patches ).To (HaveLen (3 ))
78
84
Expect (resp .Patches ).To (ContainElements (
85
+ jsonpatch.JsonPatchOperation {
86
+ Operation : "add" ,
87
+ Path : "/labels" ,
88
+ Value : map [string ]any {"foo" : "bar" },
89
+ },
79
90
jsonpatch.JsonPatchOperation {
80
91
Operation : "add" ,
81
92
Path : "/replica" ,
@@ -109,6 +120,8 @@ var _ = Describe("Defaulter Handler", func() {
109
120
var _ runtime.Object = & TestDefaulter {}
110
121
111
122
type TestDefaulter struct {
123
+ Labels map [string ]string `json:"labels,omitempty"`
124
+
112
125
Replica int `json:"replica,omitempty"`
113
126
TotalReplicas int `json:"totalReplicas,omitempty"`
114
127
}
@@ -118,6 +131,7 @@ var testDefaulterGVK = schema.GroupVersionKind{Group: "foo.test.org", Version: "
118
131
func (d * TestDefaulter ) GetObjectKind () schema.ObjectKind { return d }
119
132
func (d * TestDefaulter ) DeepCopyObject () runtime.Object {
120
133
return & TestDefaulter {
134
+ Labels : maps .Clone (d .Labels ),
121
135
Replica : d .Replica ,
122
136
TotalReplicas : d .TotalReplicas ,
123
137
}
@@ -141,6 +155,12 @@ type TestCustomDefaulter struct{}
141
155
142
156
func (d * TestCustomDefaulter ) Default (ctx context.Context , obj runtime.Object ) error {
143
157
o := obj .(* TestDefaulter )
158
+
159
+ if o .Labels == nil {
160
+ o .Labels = map [string ]string {}
161
+ }
162
+ o .Labels ["foo" ] = "bar"
163
+
144
164
if o .Replica < 2 {
145
165
o .Replica = 2
146
166
}
0 commit comments