@@ -50,13 +50,7 @@ import (
5050 "sigs.k8s.io/controller-runtime/pkg/client"
5151)
5252
53- type WebhookType string
54-
55- const (
56- WebhookTypeService WebhookType = "service"
57- WebhookTypeUrl WebhookType = "url"
58- repositoryValidationEndpoint = "/validate-repository"
59- )
53+ const repositoryValidationEndpoint = "/validate-repository"
6054
6155var (
6256 cert tls.Certificate
@@ -67,10 +61,6 @@ var tracer = otel.Tracer("repository-webhook")
6761
6862// WebhookConfig defines the configuration for the Repository validation webhook
6963type WebhookConfig struct {
70- Type WebhookType
71- ServiceName string // only used if Type == WebhookTypeService
72- ServiceNamespace string // only used if Type == WebhookTypeService
73- Host string // only used if Type == WebhookTypeUrl
7464 Port int32
7565 RepositoryPath string
7666 RepoServiceName string
@@ -84,21 +74,6 @@ type WebhookConfig struct {
8474// newWebhookConfig creates a new WebhookConfig object filled with values read from environment variables
8575func newWebhookConfig (ctx context.Context ) * WebhookConfig {
8676 var cfg WebhookConfig
87- // NOTE: CERT_NAMESPACE is supported for backward compatibility.
88- // TODO: We may consider using only WEBHOOK_SERVICE_NAMESPACE instead.
89- if hasEnv ("CERT_NAMESPACE" ) ||
90- hasEnv ("WEBHOOK_SERVICE_NAME" ) ||
91- hasEnv ("WEBHOOK_SERVICE_NAMESPACE" ) ||
92- ! hasEnv ("WEBHOOK_HOST" ) {
93-
94- cfg .Type = WebhookTypeService
95- cfg .ServiceName , cfg .ServiceNamespace = webhookServiceName (ctx )
96- cfg .Host = fmt .Sprintf ("%s.%s.svc" , cfg .ServiceName , cfg .ServiceNamespace )
97- } else {
98- cfg .Type = WebhookTypeUrl
99- cfg .Host = getEnv ("WEBHOOK_HOST" , "localhost" )
100- }
101- // Always use the WebhookTypeService for repository webhook validation
10277 cfg .RepositoryPath = repositoryValidationEndpoint
10378 cfg .RepoServiceName , cfg .RepoServiceNamespace = webhookServiceName (ctx )
10479 cfg .RepoHost = fmt .Sprintf ("%s.%s.svc" , cfg .RepoServiceName , cfg .RepoServiceNamespace )
@@ -183,17 +158,9 @@ func setupWebhooks(ctx context.Context, clientReader client.Reader) error {
183158}
184159
185160func createCerts (cfg * WebhookConfig ) ([]byte , error ) {
186- klog .Infof ("creating self-signing TLS cert and key for %q in directory %s" , cfg .Host , cfg .CertStorageDir )
187- commonName := cfg .Host
161+ klog .Infof ("creating self-signing TLS cert and key for %q in directory %s" , cfg .RepoHost , cfg .CertStorageDir )
162+ commonName := cfg .RepoHost
188163 dnsNames := []string {commonName }
189- if cfg .Type == WebhookTypeService {
190- dnsNames = append (dnsNames , cfg .ServiceName )
191- dnsNames = append (dnsNames , fmt .Sprintf ("%s.%s" , cfg .ServiceName , cfg .ServiceNamespace ))
192- dnsNames = append (dnsNames , fmt .Sprintf ("%s.%s.svc" , cfg .ServiceName , cfg .ServiceNamespace ))
193- dnsNames = append (dnsNames , fmt .Sprintf ("%s.%s.svc.cluster.local" , cfg .ServiceName , cfg .ServiceNamespace ))
194- }
195-
196- // DNS names for CA config - repository-validating-webhook
197164 dnsNames = append (dnsNames , cfg .RepoServiceName )
198165 dnsNames = append (dnsNames , fmt .Sprintf ("%s.%s" , cfg .RepoServiceName , cfg .RepoServiceNamespace ))
199166 dnsNames = append (dnsNames , fmt .Sprintf ("%s.%s.svc" , cfg .RepoServiceName , cfg .RepoServiceNamespace ))
@@ -295,7 +262,7 @@ func WriteFile(filepath string, c []byte) error {
295262
296263func createValidatingWebhook (ctx context.Context , cfg * WebhookConfig , caCert []byte ) error {
297264
298- klog .Infof ("Creating validating webhook for %s:%d" , cfg .Host , cfg .Port )
265+ klog .Infof ("Creating validating webhook for %s:%d" , cfg .RepoHost , cfg .Port )
299266
300267 kubeConfig := ctrl .GetConfigOrDie ()
301268 kubeClient , err := kubernetes .NewForConfig (kubeConfig )
@@ -502,11 +469,6 @@ func writeErr(errMsg string, w *http.ResponseWriter) {
502469 }
503470}
504471
505- func hasEnv (key string ) bool {
506- _ , found := os .LookupEnv (key )
507- return found
508- }
509-
510472func getEnv (key string , defaultValue string ) string {
511473 value , found := os .LookupEnv (key )
512474 if ! found {
0 commit comments