Skip to content

Commit bf252e8

Browse files
committed
allow custom jsonpatches in configuration
Signed-off-by: Markus Blaschke <[email protected]>
1 parent 4bbc771 commit bf252e8

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

config/config.go

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type (
3434

3535
PoolConfigNode struct {
3636
Roles PoolConfigNodeValueMap `yaml:"roles"`
37+
JsonPatches []k8s.JsonPatchObject `yaml:"jsonPatches"`
3738
ConfigSource *PoolConfigNodeConfigSource `yaml:"configSource"`
3839
Labels PoolConfigNodeValueMap `yaml:"labels"`
3940
Annotations PoolConfigNodeValueMap `yaml:"annotations"`
@@ -145,6 +146,7 @@ func (p *PoolConfig) IsMatchingNode(logger *zap.SugaredLogger, node *corev1.Node
145146
func (p *PoolConfig) CreateJsonPatchSet(node *corev1.Node) (patchSet *k8s.JsonPatchSet) {
146147
patchSet = k8s.NewJsonPatchSet()
147148

149+
// node roles
148150
for roleName, roleValue := range p.Node.Roles.Entries() {
149151
label := fmt.Sprintf("node-role.kubernetes.io/%s", roleName)
150152
if roleValue != nil {
@@ -162,6 +164,7 @@ func (p *PoolConfig) CreateJsonPatchSet(node *corev1.Node) (patchSet *k8s.JsonPa
162164
}
163165
}
164166

167+
// node config source
165168
if p.Node.ConfigSource != nil {
166169
patchSet.Add(k8s.JsonPatchObject{
167170
Op: "replace",
@@ -170,6 +173,7 @@ func (p *PoolConfig) CreateJsonPatchSet(node *corev1.Node) (patchSet *k8s.JsonPa
170173
})
171174
}
172175

176+
// node labels
173177
for labelName, labelValue := range p.Node.Labels.Entries() {
174178
if labelValue != nil {
175179
value := *labelValue
@@ -186,6 +190,7 @@ func (p *PoolConfig) CreateJsonPatchSet(node *corev1.Node) (patchSet *k8s.JsonPa
186190
}
187191
}
188192

193+
// node annotations
189194
for annotationName, annotationValue := range p.Node.Annotations.Entries() {
190195
if annotationValue != nil {
191196
value := *annotationValue
@@ -202,5 +207,10 @@ func (p *PoolConfig) CreateJsonPatchSet(node *corev1.Node) (patchSet *k8s.JsonPa
202207
}
203208
}
204209

210+
// custom patches
211+
for _, patch := range p.Node.JsonPatches {
212+
patchSet.Add(patch)
213+
}
214+
205215
return
206216
}

example.yaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ pools:
88
# sets the kubernetes node role
99
roles: [linux]
1010

11+
jsonPatches:
12+
# see https://en.wikipedia.org/wiki/JSON_Patch
13+
- op: replace
14+
path: /metadata/labels/foobar
15+
value: barfoo
16+
1117
- pool: windows
1218
continue: true
1319
selector:
@@ -46,7 +52,7 @@ pools:
4652
selector:
4753
- path: "{.spec.providerID}"
4854
# regexp match
49-
regexp: "^.+virtualMachineScaleSets\\/aks-agents-35471996-vmss\\/.+$"
55+
regexp: "^.+virtualMachineScaleSets\\/aks-agents-.+\\/.+$"
5056
node:
5157
# sets the kubernetes node role
5258
roles:

k8s/patch.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ type (
1616
}
1717

1818
JsonPatchObject struct {
19-
JsonPatch
20-
Op string `json:"op"`
21-
Path string `json:"path"`
22-
Value interface{} `json:"value"`
19+
JsonPatch `json:"-"`
20+
Op string `json:"op"`
21+
Path string `json:"path"`
22+
Value interface{} `json:"value,omitempty"`
2323
}
2424

2525
JsonPatchSet struct {

0 commit comments

Comments
 (0)