Skip to content

Commit

Permalink
add disable-independent-webhooks parameter for yurt-manager
Browse files Browse the repository at this point in the history
Signed-off-by: hxcGit <houxc_mail@163.com>
  • Loading branch information
xavier-hou committed Apr 20, 2023
1 parent 8a54339 commit 2d7a601
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions charts/openyurt/templates/yurt-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ spec:
{{- if .Values.yurtManager.controllers }}
- --controllers={{ .Values.yurtManager.controllers }}
{{- end }}
- {{- if .Values.yurtManager.webhooks }}
- --controllers={{ .Values.yurtManager.webhooks }}
- {{- if .Values.yurtManager.disableIndependentWebhooks }}
- --disable-independent-webhooks={{ .Values.yurtManager.disableIndependentWebhooks }}
{{- end }}
command:
- /usr/local/bin/yurt-manager
Expand Down
3 changes: 2 additions & 1 deletion charts/openyurt/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ yurtManager:
port: 10271
# format should be "foo,-bar,*"
controllers: ""
webhooks: ""
# format should be "foo,*"
disableIndependentWebhooks: ""
healthProbe:
port: 10272
# resources of yurt-manager container
Expand Down
8 changes: 4 additions & 4 deletions cmd/yurt-manager/app/options/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewGenericOptions() *GenericOptions {
RestConfigBurst: 50,
WorkingNamespace: "kube-system",
Controllers: []string{enableAll},
Webhooks: []string{enableAll},
DisabledWebhooks: []string{},
},
}
}
Expand Down Expand Up @@ -72,7 +72,7 @@ func (o *GenericOptions) ApplyTo(cfg *config.GenericConfiguration) error {
cfg.RestConfigBurst = o.RestConfigBurst
cfg.WorkingNamespace = o.WorkingNamespace
cfg.Controllers = o.Controllers
cfg.Webhooks = o.Webhooks
cfg.DisabledWebhooks = o.DisabledWebhooks

return nil
}
Expand All @@ -93,8 +93,8 @@ func (o *GenericOptions) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&o.WorkingNamespace, "working-namespace", o.WorkingNamespace, "The namespace where the yurt-manager is working.")
fs.StringSliceVar(&o.Controllers, "controllers", o.Controllers, "A list of controllers to enable. "+
"'*' enables all on-by-default controllers, 'foo' enables the controller named 'foo', '-foo' disables the controller named 'foo'.")
fs.StringSliceVar(&o.Webhooks, "webhooks", o.Webhooks, "A list of webhooks to enable. "+
"'*' enables all on-by-default webhooks, 'foo' enables the webhook named 'foo', '-foo' disables the webhook named 'foo'.")
fs.StringSliceVar(&o.DisabledWebhooks, "disable-independent-webhooks", o.DisabledWebhooks, "A list of webhooks to disable. "+
"'*' disables all webhooks, 'foo' disables the webhook named 'foo'.")

features.DefaultMutableFeatureGate.AddFlag(fs)
}
5 changes: 3 additions & 2 deletions pkg/controller/apis/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type GenericConfiguration struct {
// '-foo' means "disable 'foo'"
// first item for a particular name wins
Controllers []string
// Same as Controllers
Webhooks []string
// DisabledWebhooks is used to specify the disabled webhooks
// Only care about controller-independent webhooks
DisabledWebhooks []string
}
13 changes: 9 additions & 4 deletions pkg/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,26 @@ func SetupWithManager(c *config.CompletedConfig, mgr manager.Manager) error {

// set up independent webhooks
for name, s := range webhooks {
if !util.IsWebhookEnabled(name, c.ComponentConfig.Generic.Webhooks) {
if util.IsWebhookDisabled(name, c.ComponentConfig.Generic.DisabledWebhooks) {
klog.Warningf("Webhook %v is disabled", name)
continue
}
return setup(s)
if err := setup(s); err != nil {
return err
}
}

// set up controller webhooks
for controllerName, list := range controllerWebhooks {
if !ctrlutil.IsControllerEnabled(controllerName, c.ComponentConfig.Generic.Controllers) {
if !ctrlutil.IsControllerEnabled(controllerName, c.ComponentConfig.Generic.Controllers) ||
util.IsWebhookDisabled(controllerName, c.ComponentConfig.Generic.DisabledWebhooks) {
klog.Warningf("Webhook for %v is disabled", controllerName)
continue
}
for _, s := range list {
return setup(s)
if err := setup(s); err != nil {
return err
}
}
}
return nil
Expand Down
13 changes: 5 additions & 8 deletions pkg/webhook/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,16 @@ func GenerateValidatePath(gvk schema.GroupVersionKind) string {
gvk.Version + "-" + strings.ToLower(gvk.Kind)
}

// IsWebhookEnabled check if a specified webhook enabled or not.
func IsWebhookEnabled(name string, webhooks []string) bool {
// IsWebhookDisabled check if a specified webhook disabled or not.
func IsWebhookDisabled(name string, webhooks []string) bool {
hasStar := false
for _, ctrl := range webhooks {
if ctrl == name {
return true
}
if ctrl == "-"+name {
return false
}
if ctrl == "*" {
return true
hasStar = true
}
}

return false
return hasStar
}

0 comments on commit 2d7a601

Please sign in to comment.