Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix Webhook Clean #2109

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions cmd/webhook-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,23 @@ const (

// Config admission-controller server config.
type Config struct {
KubeClientOptions kube.ClientOptions
CertFile string
KeyFile string
CaCertFile string
CertData []byte
KeyData []byte
CaCertData []byte
ListenAddress string
Port int
PrintVersion bool
WebhookName string
WebhookNamespace string
SchedulerName string
WebhookURL string
ConfigPath string
EnabledAdmission string
KubeClientOptions kube.ClientOptions
CertFile string
KeyFile string
CaCertFile string
CertData []byte
KeyData []byte
CaCertData []byte
ListenAddress string
Port int
PrintVersion bool
WebhookName string
WebhookServiceName string
WebhookNamespace string
SchedulerName string
WebhookURL string
ConfigPath string
EnabledAdmission string
}

type DecryptFunc func(c *Config) error
Expand All @@ -76,7 +77,8 @@ func (c *Config) AddFlags(fs *pflag.FlagSet) {

fs.StringVar(&c.CaCertFile, "ca-cert-file", c.CaCertFile, "File containing the x509 Certificate for HTTPS.")
fs.StringVar(&c.WebhookNamespace, "webhook-namespace", "", "The namespace of this webhook")
fs.StringVar(&c.WebhookName, "webhook-service-name", "", "The name of this webhook")
fs.StringVar(&c.WebhookName, "webhook-name", "", "The name of this webhook")
fs.StringVar(&c.WebhookServiceName, "webhook-service-name", "", "The webhook service's name ")
fs.StringVar(&c.WebhookURL, "webhook-url", "", "The url of this webhook")
fs.StringVar(&c.EnabledAdmission, "enabled-admission", defaultEnabledAdmission, "enabled admission webhooks")

Expand Down
10 changes: 5 additions & 5 deletions cmd/webhook-manager/app/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ func registerWebhookConfig(kubeClient *kubernetes.Clientset, config *options.Con
clientConfig.URL = &url
klog.Infof("The URL of webhook manager is <%s>.", url)
}
if config.WebhookName != "" && config.WebhookNamespace != "" {
if config.WebhookServiceName != "" && config.WebhookNamespace != "" {
clientConfig.Service = &v1.ServiceReference{
Name: config.WebhookName,
Name: config.WebhookServiceName,
Namespace: config.WebhookNamespace,
Path: &service.Path,
}
klog.Infof("The service of webhook manager is <%s/%s/%s>.",
config.WebhookName, config.WebhookNamespace, service.Path)
config.WebhookServiceName, config.WebhookNamespace, service.Path)
}
if service.MutatingConfig != nil {
for i := range service.MutatingConfig.Webhooks {
service.MutatingConfig.Webhooks[i].SideEffects = &sideEffect
service.MutatingConfig.Webhooks[i].AdmissionReviewVersions = reviewVersions
service.MutatingConfig.Webhooks[i].ClientConfig = clientConfig
}

// fix webhook name pattern whether use service or url
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// fix webhook name pattern whether use service or url
// fix webhook name pattern whether use service or url

service.MutatingConfig.ObjectMeta.Name = webhookConfigName(config.WebhookName, service.Path)

if err := registerMutateWebhook(kubeClient, service.MutatingConfig); err != nil {
Expand Down Expand Up @@ -195,7 +195,7 @@ func registerValidateWebhook(clientset *kubernetes.Clientset, hook *v1.Validatin

func webhookConfigName(name, path string) string {
if name == "" {
name = "webhook"
name = "volcano-webhook"
}

re := regexp.MustCompile(`-+`)
Expand Down
42 changes: 42 additions & 0 deletions installer/volcano-development-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8096,3 +8096,45 @@ status:
plural: ""
conditions: []
storedVersions: []

---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: volcano-webhook-jobs-mutate

---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: volcano-webhook-pods-mutate

---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: volcano-webhook-podgroups-mutate

---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: volcano-webhook-queues-mutate

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: volcano-webhook-jobs-validate

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: volcano-webhook-pods-validate

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: volcano-webhook-queues-validate
41 changes: 41 additions & 0 deletions installer/volcano-development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8096,3 +8096,44 @@ status:
plural: ""
conditions: []
storedVersions: []
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: volcano-webhook-jobs-mutate

---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: volcano-webhook-pods-mutate

---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: volcano-webhook-podgroups-mutate

---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: volcano-webhook-queues-mutate

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: volcano-webhook-jobs-validate

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: volcano-webhook-pods-validate

---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: volcano-webhook-queues-validate