Skip to content
Merged
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
17 changes: 8 additions & 9 deletions cmd/install/assets/hypershift_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,9 +1065,6 @@ func (o HyperShiftOperatorService) Build() *corev1.Service {
Labels: map[string]string{
"name": HypershiftOperatorName,
},
Annotations: map[string]string{
"service.beta.openshift.io/serving-cert-secret-name": "manager-serving-cert",
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeClusterIP,
Expand Down Expand Up @@ -2075,6 +2072,7 @@ func (o HyperShiftReaderClusterRoleBinding) Build() *rbacv1.ClusterRoleBinding {
type HyperShiftMutatingWebhookConfiguration struct {
Namespace *corev1.Namespace
EnableAuditLogPersistence bool
CABundle []byte
}

const (
Expand All @@ -2095,9 +2093,6 @@ func (o HyperShiftMutatingWebhookConfiguration) Build() *admissionregistrationv1
ObjectMeta: metav1.ObjectMeta{
Namespace: o.Namespace.Name,
Name: hyperv1.GroupVersion.Group,
Annotations: map[string]string{
"service.beta.openshift.io/inject-cabundle": "true",
},
},
Webhooks: []admissionregistrationv1.MutatingWebhook{
{
Expand All @@ -2116,6 +2111,7 @@ func (o HyperShiftMutatingWebhookConfiguration) Build() *admissionregistrationv1
},
},
ClientConfig: admissionregistrationv1.WebhookClientConfig{
CABundle: o.CABundle,
Service: &admissionregistrationv1.ServiceReference{
Namespace: "hypershift",
Name: "operator",
Expand All @@ -2142,6 +2138,7 @@ func (o HyperShiftMutatingWebhookConfiguration) Build() *admissionregistrationv1
},
},
ClientConfig: admissionregistrationv1.WebhookClientConfig{
CABundle: o.CABundle,
Service: &admissionregistrationv1.ServiceReference{
Namespace: "hypershift",
Name: "operator",
Expand Down Expand Up @@ -2182,6 +2179,7 @@ func (o HyperShiftMutatingWebhookConfiguration) Build() *admissionregistrationv1
},
},
ClientConfig: admissionregistrationv1.WebhookClientConfig{
CABundle: o.CABundle,
Service: &admissionregistrationv1.ServiceReference{
Namespace: "hypershift",
Name: "operator",
Expand Down Expand Up @@ -2211,6 +2209,7 @@ func (o HyperShiftMutatingWebhookConfiguration) Build() *admissionregistrationv1
},
},
ClientConfig: admissionregistrationv1.WebhookClientConfig{
CABundle: o.CABundle,
Service: &admissionregistrationv1.ServiceReference{
Namespace: "hypershift",
Name: "operator",
Expand All @@ -2231,6 +2230,7 @@ func (o HyperShiftMutatingWebhookConfiguration) Build() *admissionregistrationv1

type HyperShiftValidatingWebhookConfiguration struct {
Namespace string
CABundle []byte
}

func (o HyperShiftValidatingWebhookConfiguration) Build() *admissionregistrationv1.ValidatingWebhookConfiguration {
Expand All @@ -2248,9 +2248,6 @@ func (o HyperShiftValidatingWebhookConfiguration) Build() *admissionregistration
ObjectMeta: metav1.ObjectMeta{
Namespace: o.Namespace,
Name: hyperv1.GroupVersion.Group,
Annotations: map[string]string{
"service.beta.openshift.io/inject-cabundle": "true",
},
},
Webhooks: []admissionregistrationv1.ValidatingWebhook{
{
Expand All @@ -2270,6 +2267,7 @@ func (o HyperShiftValidatingWebhookConfiguration) Build() *admissionregistration
},
},
ClientConfig: admissionregistrationv1.WebhookClientConfig{
CABundle: o.CABundle,
Service: &admissionregistrationv1.ServiceReference{
Namespace: "hypershift",
Name: "operator",
Expand Down Expand Up @@ -2298,6 +2296,7 @@ func (o HyperShiftValidatingWebhookConfiguration) Build() *admissionregistration
},
},
ClientConfig: admissionregistrationv1.WebhookClientConfig{
CABundle: o.CABundle,
Service: &admissionregistrationv1.ServiceReference{
Namespace: "hypershift",
Name: "operator",
Expand Down
20 changes: 17 additions & 3 deletions cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/openshift/hypershift/cmd/install/assets"
"github.com/openshift/hypershift/cmd/util"
"github.com/openshift/hypershift/hypershift-operator/controllers/sharedingress"
"github.com/openshift/hypershift/hypershift-operator/controllers/webhookcerts"
hyperapi "github.com/openshift/hypershift/support/api"
"github.com/openshift/hypershift/support/config"
"github.com/openshift/hypershift/support/metrics"
Expand Down Expand Up @@ -678,17 +679,30 @@ func hyperShiftOperatorManifests(ctx context.Context, client crclient.Client, op
operatorServiceAccount, rbacObjs := setupRBAC(opts, operatorNamespace)
objects = append(objects, rbacObjs...)

// Generate self-managed webhook CA and serving cert when any webhook is enabled.
var webhookCABundle []byte
if opts.EnableDefaultingWebhook || opts.EnableConversionWebhook || opts.EnableValidatingWebhook || opts.EnableAuditLogPersistence {
caSecret, servingSecret, caBundle, err := webhookcerts.GenerateInitialWebhookCerts(operatorNamespace.Name, assets.HypershiftOperatorName)
if err != nil {
return nil, nil, fmt.Errorf("failed to generate webhook certs: %w", err)
}
objects = append(objects, caSecret, servingSecret)
webhookCABundle = caBundle
}

if opts.EnableDefaultingWebhook || opts.EnableAuditLogPersistence {
mutatingWebhookConfiguration := assets.HyperShiftMutatingWebhookConfiguration{
Namespace: operatorNamespace,
EnableAuditLogPersistence: opts.EnableAuditLogPersistence,
CABundle: webhookCABundle,
}.Build()
objects = append(objects, mutatingWebhookConfiguration)
}

if opts.EnableValidatingWebhook {
validatingWebhookConfiguration := assets.HyperShiftValidatingWebhookConfiguration{
Namespace: operatorNamespace.Name,
CABundle: webhookCABundle,
}.Build()
objects = append(objects, validatingWebhookConfiguration)
}
Expand Down Expand Up @@ -740,7 +754,7 @@ func hyperShiftOperatorManifests(ctx context.Context, client crclient.Client, op
objects = append(objects, sharedIngressObjs...)
}

crds, err = setupCRDs(ctx, client, opts, operatorNamespace, operatorService)
crds, err = setupCRDs(ctx, client, opts, operatorNamespace, operatorService, webhookCABundle)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -783,7 +797,7 @@ var ipamCRDNames = set.New(
// related to etcd are excluded from the list. If the option EnableConversionWebhook is set to true, the CRDs related
// to hypershift.openshift.io group are annotated with the necessary annotations to enable the conversion webhook.
// If a client is provided, IPAM CRDs that already exist in the cluster are skipped to avoid conflicts.
func setupCRDs(ctx context.Context, client crclient.Client, opts Options, operatorNamespace *corev1.Namespace, operatorService *corev1.Service) ([]crclient.Object, error) {
func setupCRDs(ctx context.Context, client crclient.Client, opts Options, operatorNamespace *corev1.Namespace, operatorService *corev1.Service, webhookCABundle []byte) ([]crclient.Object, error) {
// Build a set of existing IPAM CRDs if a client is available
existingIPAMCRDs := set.New[string]()
if client != nil {
Expand Down Expand Up @@ -866,7 +880,6 @@ func setupCRDs(ctx context.Context, client crclient.Client, opts Options, operat
if crd.Annotations != nil {
crd.Annotations = map[string]string{}
}
crd.Annotations["service.beta.openshift.io/inject-cabundle"] = "true"
crd.Spec.Conversion = &apiextensionsv1.CustomResourceConversion{
Strategy: apiextensionsv1.WebhookConverter,
Webhook: &apiextensionsv1.WebhookConversion{
Expand All @@ -877,6 +890,7 @@ func setupCRDs(ctx context.Context, client crclient.Client, opts Options, operat
Port: ptr.To[int32](443),
Path: ptr.To("/convert"),
},
CABundle: webhookCABundle,
},
ConversionReviewVersions: []string{"v1beta1", "v1alpha1"},
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/install/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func TestSetupCRDs(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
g := NewGomegaWithT(t)
crds, err := setupCRDs(t.Context(), nil, tc.inputOptions, &corev1.Namespace{}, nil)
crds, err := setupCRDs(t.Context(), nil, tc.inputOptions, &corev1.Namespace{}, nil, nil)
g.Expect(err).ToNot(HaveOccurred())
nodePoolCRDS := make([]crclient.Object, 0)
var machineDeploymentCRD crclient.Object
Expand Down
Loading
Loading