Skip to content

Commit b380252

Browse files
committed
Share common webhook config between hosted and default mode
Signed-off-by: Ben Perry <[email protected]>
1 parent 731dbc4 commit b380252

File tree

11 files changed

+220
-74
lines changed

11 files changed

+220
-74
lines changed

deploy/cluster-manager/chart/cluster-manager/crds/0000_01_operator.open-cluster-management.io_clustermanagers.crd.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,24 @@ spec:
171171
The Address must be reachable by apiserver of the hub cluster.
172172
pattern: ^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$
173173
type: string
174+
healthProbeBindAddress:
175+
default: :8000
176+
description: |-
177+
HealthProbeBindAddress represents the healthcheck address of a webhook-server. The default value is ":8000".
178+
Healthchecks may be disabled by setting a value of "0" or "".
179+
type: string
180+
hostNetwork:
181+
description: |-
182+
HostNetwork enables running webhook pods with hostNetwork: true
183+
This may be required in some installations, such as EKS with Calico CNI,
184+
to allow the API Server to communicate with the webhook pods.
185+
type: boolean
186+
metricsBindAddress:
187+
default: :8080
188+
description: |-
189+
MetricsBindAddress represents the metrics address of a webhook-server. The default value is ":8080"
190+
Metrics may be disabled by setting a value of "0" or "".
191+
type: string
174192
port:
175193
default: 443
176194
description: Port represents the port of a webhook-server.
@@ -192,6 +210,24 @@ spec:
192210
The Address must be reachable by apiserver of the hub cluster.
193211
pattern: ^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$
194212
type: string
213+
healthProbeBindAddress:
214+
default: :8000
215+
description: |-
216+
HealthProbeBindAddress represents the healthcheck address of a webhook-server. The default value is ":8000".
217+
Healthchecks may be disabled by setting a value of "0" or "".
218+
type: string
219+
hostNetwork:
220+
description: |-
221+
HostNetwork enables running webhook pods with hostNetwork: true
222+
This may be required in some installations, such as EKS with Calico CNI,
223+
to allow the API Server to communicate with the webhook pods.
224+
type: boolean
225+
metricsBindAddress:
226+
default: :8080
227+
description: |-
228+
MetricsBindAddress represents the metrics address of a webhook-server. The default value is ":8080"
229+
Metrics may be disabled by setting a value of "0" or "".
230+
type: string
195231
port:
196232
default: 443
197233
description: Port represents the port of a webhook-server.

deploy/cluster-manager/config/crds/0000_01_operator.open-cluster-management.io_clustermanagers.crd.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,24 @@ spec:
171171
The Address must be reachable by apiserver of the hub cluster.
172172
pattern: ^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$
173173
type: string
174+
healthProbeBindAddress:
175+
default: :8000
176+
description: |-
177+
HealthProbeBindAddress represents the healthcheck address of a webhook-server. The default value is ":8000".
178+
Healthchecks may be disabled by setting a value of "0" or "".
179+
type: string
180+
hostNetwork:
181+
description: |-
182+
HostNetwork enables running webhook pods with hostNetwork: true
183+
This may be required in some installations, such as EKS with Calico CNI,
184+
to allow the API Server to communicate with the webhook pods.
185+
type: boolean
186+
metricsBindAddress:
187+
default: :8080
188+
description: |-
189+
MetricsBindAddress represents the metrics address of a webhook-server. The default value is ":8080"
190+
Metrics may be disabled by setting a value of "0" or "".
191+
type: string
174192
port:
175193
default: 443
176194
description: Port represents the port of a webhook-server.
@@ -192,6 +210,24 @@ spec:
192210
The Address must be reachable by apiserver of the hub cluster.
193211
pattern: ^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$
194212
type: string
213+
healthProbeBindAddress:
214+
default: :8000
215+
description: |-
216+
HealthProbeBindAddress represents the healthcheck address of a webhook-server. The default value is ":8000".
217+
Healthchecks may be disabled by setting a value of "0" or "".
218+
type: string
219+
hostNetwork:
220+
description: |-
221+
HostNetwork enables running webhook pods with hostNetwork: true
222+
This may be required in some installations, such as EKS with Calico CNI,
223+
to allow the API Server to communicate with the webhook pods.
224+
type: boolean
225+
metricsBindAddress:
226+
default: :8080
227+
description: |-
228+
MetricsBindAddress represents the metrics address of a webhook-server. The default value is ":8080"
229+
Metrics may be disabled by setting a value of "0" or "".
230+
type: string
195231
port:
196232
default: 443
197233
description: Port represents the port of a webhook-server.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module open-cluster-management.io/ocm
33
go 1.23.6
44

55
// TEMPORARY while waiting for upstream tag – must be removed before merge
6-
replace open-cluster-management.io/api => github.com/bhperry/ocm-api v0.0.0-20250612225613-ffa7865df0a9
6+
replace open-cluster-management.io/api => github.com/bhperry/ocm-api v0.0.0-20250709152251-dc6f14dcb9c0
77

88
require (
99
github.com/aws/aws-sdk-go-v2 v1.36.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ github.com/aws/smithy-go v1.22.2 h1:6D9hW43xKFrRx/tXXfAlIZc4JI+yQe6snnWcQyxSyLQ=
5858
github.com/aws/smithy-go v1.22.2/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
5959
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
6060
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
61-
github.com/bhperry/ocm-api v0.0.0-20250612225613-ffa7865df0a9 h1:Cs8jDa7M7sGmQA3OmGYsnn+yD/aytxyhYym6qtZHsVs=
62-
github.com/bhperry/ocm-api v0.0.0-20250612225613-ffa7865df0a9/go.mod h1:/OeqXycNBZQoe3WG6ghuWsMgsKGuMZrK8ZpsU6gWL0Y=
61+
github.com/bhperry/ocm-api v0.0.0-20250709152251-dc6f14dcb9c0 h1:BGB/xHmOWNgwbuz6vqFBk+hf+dXhcSI5IBbRwim3CjA=
62+
github.com/bhperry/ocm-api v0.0.0-20250709152251-dc6f14dcb9c0/go.mod h1:/OeqXycNBZQoe3WG6ghuWsMgsKGuMZrK8ZpsU6gWL0Y=
6363
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
6464
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
6565
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=

pkg/operator/operators/clustermanager/controllers/clustermanagercontroller/clustermanager_controller.go

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ func ensureSAKubeconfigs(ctx context.Context, clusterManagerName, clusterManager
367367

368368
// TODO: support IPV6 address
369369
func isIPFormat(address string) bool {
370+
if address == "" {
371+
return false
372+
}
373+
370374
runes := []rune(address)
371375
for i := 0; i < len(runes); i++ {
372376
if (runes[i] < '0' || runes[i] > '9') && runes[i] != '.' {
@@ -379,44 +383,45 @@ func isIPFormat(address string) bool {
379383
func webhookConfigurations(deployOption operatorapiv1.ClusterManagerDeployOption) (registration, work manifests.Webhook) {
380384
switch deployOption.Mode {
381385
case operatorapiv1.InstallModeDefault:
382-
if deployOption.Default == nil {
383-
registration.Port = defaultWebhookPort
384-
registration.HealthProbeBindAddress = defaultHealthProbeBindAddr
385-
registration.MetricsBindAddress = defaultMetricsBindAddr
386-
work.Port = defaultWebhookPort
387-
work.HealthProbeBindAddress = defaultHealthProbeBindAddr
388-
work.MetricsBindAddress = defaultMetricsBindAddr
389-
} else {
386+
if deployOption.Default != nil {
390387
registration = convertDefaultWebhookConfiguration(deployOption.Default.RegistrationWebhookConfiguration)
391388
work = convertDefaultWebhookConfiguration(deployOption.Default.WorkWebhookConfiguration)
389+
return
392390
}
393391
case operatorapiv1.InstallModeHosted:
394-
if deployOption.Hosted == nil {
395-
registration.Port = defaultWebhookPort
396-
work.Port = defaultWebhookPort
397-
} else {
392+
if deployOption.Hosted != nil {
398393
registration = convertHostedWebhookConfiguration(deployOption.Hosted.RegistrationWebhookConfiguration)
399394
work = convertHostedWebhookConfiguration(deployOption.Hosted.WorkWebhookConfiguration)
395+
return
400396
}
401397
}
402-
return registration, work
398+
399+
registration = manifests.Webhook{
400+
Port: defaultWebhookPort,
401+
HealthProbeBindAddress: defaultHealthProbeBindAddr,
402+
MetricsBindAddress: defaultMetricsBindAddr,
403+
}
404+
work = manifests.Webhook{
405+
Port: defaultWebhookPort,
406+
HealthProbeBindAddress: defaultHealthProbeBindAddr,
407+
MetricsBindAddress: defaultMetricsBindAddr,
408+
}
409+
return
403410
}
404411

405-
func convertHostedWebhookConfiguration(webhookConfiguration operatorapiv1.WebhookConfiguration) manifests.Webhook {
406-
// If we are deploying in the hosted mode, it requires us to create webhook in a different way with the default mode.
407-
// In the hosted mode, the webhook servers is running in the management cluster but the users are accessing the hub cluster.
408-
// So we need to add configuration to make the apiserver of the hub cluster could access the webhook servers on the management cluster.
412+
func convertDefaultWebhookConfiguration(webhookConfiguration operatorapiv1.DefaultWebhookConfiguration) manifests.Webhook {
409413
return manifests.Webhook{
410-
Address: webhookConfiguration.Address,
411-
Port: webhookConfiguration.Port,
412-
IsIPFormat: isIPFormat(webhookConfiguration.Address),
414+
Port: webhookConfiguration.Port,
415+
HealthProbeBindAddress: webhookConfiguration.HealthProbeBindAddress,
416+
MetricsBindAddress: webhookConfiguration.MetricsBindAddress,
417+
HostNetwork: webhookConfiguration.HostNetwork,
413418
}
414419
}
415420

416-
func convertDefaultWebhookConfiguration(webhookConfiguration operatorapiv1.WebhookDefaultConfiguration) manifests.Webhook {
417-
// In default mode, webhooks run inside the hub cluster.
418-
// These configurations allow the webhooks to configured for different kubernetes environements.
421+
func convertHostedWebhookConfiguration(webhookConfiguration operatorapiv1.HostedWebhookConfiguration) manifests.Webhook {
419422
return manifests.Webhook{
423+
Address: webhookConfiguration.Address,
424+
IsIPFormat: isIPFormat(webhookConfiguration.Address),
420425
Port: webhookConfiguration.Port,
421426
HealthProbeBindAddress: webhookConfiguration.HealthProbeBindAddress,
422427
MetricsBindAddress: webhookConfiguration.MetricsBindAddress,

test/integration/operator/integration_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ var _ = ginkgo.BeforeSuite(func() {
167167
DeployOption: operatorapiv1.ClusterManagerDeployOption{
168168
Mode: operatorapiv1.InstallModeHosted,
169169
Hosted: &operatorapiv1.HostedClusterManagerConfiguration{
170-
RegistrationWebhookConfiguration: operatorapiv1.WebhookConfiguration{
170+
RegistrationWebhookConfiguration: operatorapiv1.HostedWebhookConfiguration{
171171
Address: "localhost",
172172
Port: 443,
173173
},
174-
WorkWebhookConfiguration: operatorapiv1.WebhookConfiguration{
174+
WorkWebhookConfiguration: operatorapiv1.HostedWebhookConfiguration{
175175
Address: "localhost",
176176
Port: 443,
177177
},

vendor/modules.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ open-cluster-management.io/addon-framework/pkg/agent
17181718
open-cluster-management.io/addon-framework/pkg/assets
17191719
open-cluster-management.io/addon-framework/pkg/index
17201720
open-cluster-management.io/addon-framework/pkg/utils
1721-
# open-cluster-management.io/api v1.0.0 => github.com/bhperry/ocm-api v0.0.0-20250612225613-ffa7865df0a9
1721+
# open-cluster-management.io/api v1.0.0 => github.com/bhperry/ocm-api v0.0.0-20250709152251-dc6f14dcb9c0
17221722
## explicit; go 1.23.6
17231723
open-cluster-management.io/api/addon/v1alpha1
17241724
open-cluster-management.io/api/client/addon/clientset/versioned
@@ -1948,4 +1948,4 @@ sigs.k8s.io/structured-merge-diff/v4/value
19481948
sigs.k8s.io/yaml
19491949
sigs.k8s.io/yaml/goyaml.v2
19501950
sigs.k8s.io/yaml/goyaml.v3
1951-
# open-cluster-management.io/api => github.com/bhperry/ocm-api v0.0.0-20250612225613-ffa7865df0a9
1951+
# open-cluster-management.io/api => github.com/bhperry/ocm-api v0.0.0-20250709152251-dc6f14dcb9c0

vendor/open-cluster-management.io/api/operator/v1/0000_01_operator.open-cluster-management.io_clustermanagers.crd.yaml

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)