mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
Generate updated ns transformer
This commit is contained in:
@@ -52,6 +52,7 @@ func (p *NamespaceTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||
}
|
||||
}
|
||||
p.updateClusterRoleBinding(m)
|
||||
p.updateServiceReference(m)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -125,3 +126,40 @@ func (p *NamespaceTransformerPlugin) updateClusterRoleBinding(m resmap.ResMap) {
|
||||
objMap["subjects"] = subjects
|
||||
}
|
||||
}
|
||||
|
||||
func (p *NamespaceTransformerPlugin) updateServiceReference(m resmap.ResMap) {
|
||||
svc := gvk.Gvk{Version: "v1", Kind: "Service"}
|
||||
svcMap := map[string]bool{}
|
||||
for _, id := range m.AllIds() {
|
||||
if id.Gvk.Equals(svc) {
|
||||
svcMap[id.Name] = true
|
||||
}
|
||||
}
|
||||
|
||||
for _, res := range m.Resources() {
|
||||
if res.OrgId().Kind != "ValidatingWebhookConfiguration" &&
|
||||
res.OrgId().Kind != "MutatingWebhookConfiguration" {
|
||||
continue
|
||||
}
|
||||
objMap := res.Map()
|
||||
webhooks, ok := objMap["webhooks"].([]interface{})
|
||||
if webhooks == nil || !ok {
|
||||
continue
|
||||
}
|
||||
for i := range webhooks {
|
||||
webhook := webhooks[i].(map[string]interface{})
|
||||
transformers.MutateField(
|
||||
webhook, []string{"clientConfig", "service"},
|
||||
false, func(obj interface{}) (interface{}, error) {
|
||||
svc := obj.(map[string]interface{})
|
||||
svcName, foundN := svc["name"]
|
||||
if foundN && svcMap[svcName.(string)] {
|
||||
svc["namespace"] = p.Namespace
|
||||
}
|
||||
return svc, nil
|
||||
})
|
||||
webhooks[i] = webhook
|
||||
}
|
||||
objMap["webhooks"] = webhooks
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user