diff --git a/cmd/gardener-extension-provider-openstack/app/app.go b/cmd/gardener-extension-provider-openstack/app/app.go index a19c0c87a..4a5e71433 100644 --- a/cmd/gardener-extension-provider-openstack/app/app.go +++ b/cmd/gardener-extension-provider-openstack/app/app.go @@ -112,9 +112,8 @@ func NewControllerManagerCommand(ctx context.Context) *cobra.Command { Namespace: os.Getenv("WEBHOOK_CONFIG_NAMESPACE"), } - gardenerVersion = new(string) controllerSwitches = openstackcmd.ControllerSwitchOptions() - webhookSwitches = openstackcmd.WebhookSwitchOptions(gardenerVersion) + webhookSwitches = openstackcmd.WebhookSwitchOptions() webhookOptions = webhookcmd.NewAddToManagerOptions( openstack.Name, genericactuator.ShootWebhooksResourceName, @@ -190,12 +189,8 @@ func NewControllerManagerCommand(ctx context.Context) *cobra.Command { if err := mgr.Add(gardenCluster); err != nil { return fmt.Errorf("failed adding garden cluster to manager: %w", err) } - if err != nil { - return err - } - log.Info("Adding controllers to manager") - *gardenerVersion = generalOpts.Completed().GardenerVersion + log.Info("Adding controllers to manager") configFileOpts.Completed().ApplyETCDStorage(&openstackcontrolplaneexposure.DefaultAddOptions.ETCDStorage) configFileOpts.Completed().ApplyHealthCheckConfig(&healthcheck.DefaultAddOptions.HealthCheckConfig) configFileOpts.Completed().ApplyBastionConfig(&openstackbastion.DefaultAddOptions.BastionConfig) diff --git a/pkg/cmd/options.go b/pkg/cmd/options.go index 061a7d807..098f72959 100644 --- a/pkg/cmd/options.go +++ b/pkg/cmd/options.go @@ -49,9 +49,9 @@ func ControllerSwitchOptions() *controllercmd.SwitchOptions { } // WebhookSwitchOptions are the webhookcmd.SwitchOptions for the provider webhooks. -func WebhookSwitchOptions(gardenerVersion *string) *webhookcmd.SwitchOptions { +func WebhookSwitchOptions() *webhookcmd.SwitchOptions { return webhookcmd.NewSwitchOptions( - webhookcmd.Switch(extensioncontrolplanewebhook.WebhookName, controlplanewebhook.AddToManager(gardenerVersion)), + webhookcmd.Switch(extensioncontrolplanewebhook.WebhookName, controlplanewebhook.AddToManager), webhookcmd.Switch(extensioncontrolplanewebhook.ExposureWebhookName, controlplaneexposurewebhook.AddToManager), webhookcmd.Switch(extensionscloudproviderwebhook.WebhookName, cloudproviderwebhook.AddToManager), webhookcmd.Switch(infrastructurewebhook.WebhookName, infrastructurewebhook.AddToManager), diff --git a/pkg/webhook/controlplane/add.go b/pkg/webhook/controlplane/add.go index a5e9a7945..63beaca48 100644 --- a/pkg/webhook/controlplane/add.go +++ b/pkg/webhook/controlplane/add.go @@ -5,9 +5,6 @@ package controlplane import ( - "fmt" - - "github.com/Masterminds/semver/v3" extensionswebhook "github.com/gardener/gardener/extensions/pkg/webhook" "github.com/gardener/gardener/extensions/pkg/webhook/controlplane" "github.com/gardener/gardener/extensions/pkg/webhook/controlplane/genericmutator" @@ -17,7 +14,6 @@ import ( oscutils "github.com/gardener/gardener/pkg/component/extensions/operatingsystemconfig/utils" appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" vpaautoscalingv1 "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/manager" @@ -27,43 +23,22 @@ import ( var ( logger = log.Log.WithName("openstack-controlplane-webhook") - // TODO(LucaBernstein): Clean up the gardener version check after October/2024. - versionConstraintGreaterEqual198 *semver.Constraints ) -func init() { - var err error - versionConstraintGreaterEqual198, err = semver.NewConstraint(">= 1.98") - utilruntime.Must(err) -} - // AddToManager creates a webhook and adds it to the manager. -func AddToManager(gardenerVersion *string) func(mgr manager.Manager) (*extensionswebhook.Webhook, error) { - return func(mgr manager.Manager) (*extensionswebhook.Webhook, error) { - var objectSelector *metav1.LabelSelector - if gardenerVersion != nil && len(*gardenerVersion) > 0 { - version, err := semver.NewVersion(*gardenerVersion) - if err != nil { - return nil, fmt.Errorf("failed to parse gardener version: %v", err) - } - if versionConstraintGreaterEqual198.Check(version) { - objectSelector = &metav1.LabelSelector{MatchLabels: map[string]string{v1beta1constants.LabelExtensionProviderMutatedByControlplaneWebhook: "true"}} - } - } - - logger.Info("Adding webhook to manager") - fciCodec := oscutils.NewFileContentInlineCodec() - return controlplane.New(mgr, controlplane.Args{ - Kind: controlplane.KindShoot, - Provider: openstack.Type, - Types: []extensionswebhook.Type{ - {Obj: &appsv1.Deployment{}}, - {Obj: &vpaautoscalingv1.VerticalPodAutoscaler{}}, - {Obj: &extensionsv1alpha1.OperatingSystemConfig{}}, - }, - ObjectSelector: objectSelector, - Mutator: genericmutator.NewMutator(mgr, NewEnsurer(logger), oscutils.NewUnitSerializer(), - kubelet.NewConfigCodec(fciCodec), fciCodec, logger), - }) - } +func AddToManager(mgr manager.Manager) (*extensionswebhook.Webhook, error) { + logger.Info("Adding webhook to manager") + fciCodec := oscutils.NewFileContentInlineCodec() + return controlplane.New(mgr, controlplane.Args{ + Kind: controlplane.KindShoot, + Provider: openstack.Type, + Types: []extensionswebhook.Type{ + {Obj: &appsv1.Deployment{}}, + {Obj: &vpaautoscalingv1.VerticalPodAutoscaler{}}, + {Obj: &extensionsv1alpha1.OperatingSystemConfig{}}, + }, + ObjectSelector: &metav1.LabelSelector{MatchLabels: map[string]string{v1beta1constants.LabelExtensionProviderMutatedByControlplaneWebhook: "true"}}, + Mutator: genericmutator.NewMutator(mgr, NewEnsurer(logger), oscutils.NewUnitSerializer(), + kubelet.NewConfigCodec(fciCodec), fciCodec, logger), + }) }