Skip to content

Commit c9da873

Browse files
committed
enable webhooks
1 parent 5b2e7cd commit c9da873

File tree

7 files changed

+98
-2
lines changed

7 files changed

+98
-2
lines changed

api/crds/manifests/openmcp.cloud_clusterproviders.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,17 @@ spec:
22652265
- info
22662266
- error
22672267
type: string
2268+
webhook:
2269+
description: Webhook contains the webhook configuration for the provider,
2270+
if any.
2271+
properties:
2272+
enabled:
2273+
default: false
2274+
description: Enabled indicates whether the webhook is enabled.
2275+
type: boolean
2276+
required:
2277+
- enabled
2278+
type: object
22682279
required:
22692280
- image
22702281
type: object

api/crds/manifests/openmcp.cloud_platformservices.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,17 @@ spec:
22652265
- info
22662266
- error
22672267
type: string
2268+
webhook:
2269+
description: Webhook contains the webhook configuration for the provider,
2270+
if any.
2271+
properties:
2272+
enabled:
2273+
default: false
2274+
description: Enabled indicates whether the webhook is enabled.
2275+
type: boolean
2276+
required:
2277+
- enabled
2278+
type: object
22682279
required:
22692280
- image
22702281
type: object

api/crds/manifests/openmcp.cloud_serviceproviders.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,17 @@ spec:
22652265
- info
22662266
- error
22672267
type: string
2268+
webhook:
2269+
description: Webhook contains the webhook configuration for the provider,
2270+
if any.
2271+
properties:
2272+
enabled:
2273+
default: false
2274+
description: Enabled indicates whether the webhook is enabled.
2275+
type: boolean
2276+
required:
2277+
- enabled
2278+
type: object
22682279
required:
22692280
- image
22702281
type: object

api/provider/v1alpha1/deployment_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ type DeploymentSpec struct {
9494
// +listType=map
9595
// +listMapKey=topologyKey
9696
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty" patchStrategy:"merge" patchMergeKey:"topologyKey"`
97+
98+
// Webhook contains the webhook configuration for the provider, if any.
99+
// +optional
100+
Webhook *WebhookConfiguration `json:"webhook,omitempty"`
101+
}
102+
103+
type WebhookConfiguration struct {
104+
// Enabled indicates whether the webhook is enabled.
105+
// +kubebuilder:default=false
106+
Enabled bool `json:"enabled"`
97107
}
98108

99109
// DeploymentStatus defines the observed state of a provider.

api/provider/v1alpha1/zz_generated.deepcopy.go

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

internal/controllers/provider/install/deployment.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/openmcp-project/controller-utils/pkg/resources"
1717

1818
"github.com/openmcp-project/openmcp-operator/api/install"
19+
libutils "github.com/openmcp-project/openmcp-operator/lib/utils"
1920
)
2021

2122
type deploymentMutator struct {
@@ -57,6 +58,28 @@ func (m *deploymentMutator) Mutate(d *appsv1.Deployment) error {
5758
return err
5859
}
5960

61+
volumes := m.values.deploymentSpec.ExtraVolumes
62+
volumeMounts := m.values.deploymentSpec.ExtraVolumeMounts
63+
if m.values.deploymentSpec.Webhook != nil && m.values.deploymentSpec.Webhook.Enabled {
64+
whSecretName, err := libutils.WebhookSecretName(m.values.provider.GetName())
65+
if err != nil {
66+
return err
67+
}
68+
volumes = append(volumes, corev1.Volume{
69+
Name: "webhook-tls",
70+
VolumeSource: corev1.VolumeSource{
71+
Secret: &corev1.SecretVolumeSource{
72+
SecretName: whSecretName,
73+
},
74+
},
75+
})
76+
volumeMounts = append(volumeMounts, corev1.VolumeMount{
77+
Name: "webhook-tls",
78+
MountPath: "/tmp/k8s-webhook-server/serving-certs",
79+
ReadOnly: true,
80+
})
81+
}
82+
6083
runCmd := slices.Clone(m.values.deploymentSpec.RunCommand)
6184
if len(runCmd) == 0 {
6285
runCmd = []string{"run"}
@@ -86,12 +109,12 @@ func (m *deploymentMutator) Mutate(d *appsv1.Deployment) error {
86109
ImagePullPolicy: corev1.PullIfNotPresent,
87110
Args: runCmd,
88111
Env: env,
89-
VolumeMounts: m.values.deploymentSpec.ExtraVolumeMounts,
112+
VolumeMounts: volumeMounts,
90113
},
91114
},
92115
ImagePullSecrets: m.values.ImagePullSecrets(),
93116
ServiceAccountName: m.values.NamespacedDefaultResourceName(),
94-
Volumes: m.values.deploymentSpec.ExtraVolumes,
117+
Volumes: volumes,
95118
TopologySpreadConstraints: m.values.deploymentSpec.TopologySpreadConstraints,
96119
},
97120
},

lib/utils/utils.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,13 @@ func StableMCPIdentifier(onboardingName, onboardingNamespace string) (string, er
7070
}
7171
return res, nil
7272
}
73+
74+
// WebhookSecretName computes the name the secret containing the webhook TLS certificate is expected to have, based on the provider's name.
75+
func WebhookSecretName(providerName string) (string, error) {
76+
suffix := "-webhook-tls"
77+
base, err := controller.ShortenToXCharacters(providerName, controller.K8sMaxNameLength-len(suffix))
78+
if err != nil {
79+
return "", fmt.Errorf("error computing webhook secret name: %w", err)
80+
}
81+
return base + suffix, nil
82+
}

0 commit comments

Comments
 (0)