Skip to content
Draft
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
83 changes: 65 additions & 18 deletions cmd/cluster-capi-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package main

import (
"context"
"crypto/tls"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -65,6 +66,7 @@ import (
"github.com/openshift/cluster-capi-operator/pkg/operatorstatus"
"github.com/openshift/cluster-capi-operator/pkg/util"
"github.com/openshift/cluster-capi-operator/pkg/webhook"
utiltls "github.com/openshift/library-go/pkg/controllerruntime/tls"
)

const (
Expand Down Expand Up @@ -95,6 +97,11 @@ func main() {
scheme := runtime.NewScheme()
initScheme(scheme)

// Create a context that can be cancelled when there is a need to shut down the manager .
ctx, cancel := context.WithCancel(ctrl.SetupSignalHandler())
// Ensure the context is cancelled when the program exits.
defer cancel()

leaderElectionConfig := config.LeaderElectionConfiguration{
LeaderElect: true,
LeaseDuration: util.LeaseDuration,
Expand Down Expand Up @@ -148,6 +155,29 @@ func main() {
capiflags.AddManagerOptions(pflag.CommandLine, &capiManagerOptions)
pflag.Parse()

cfg := ctrl.GetConfigOrDie()

k8sClient, err := client.New(cfg, client.Options{Scheme: scheme})
if err != nil {
klog.Error(err, "unable to create Kubernetes client")
os.Exit(1)
}

// Fetch the TLS profile from the APIServer resource.
tlsSecurityProfileSpec, err := utiltls.FetchAPIServerTLSProfile(ctx, k8sClient)
if err != nil {
klog.Error(err, "unable to get TLS profile from API server")
os.Exit(1)
}

// Create the TLS configuration function for the server endpoints.
tlsConfig, unsupportedCiphers := utiltls.NewTLSConfigFromProfile(tlsSecurityProfileSpec)
if len(unsupportedCiphers) > 0 {
klog.Info("TLS configuration contains unsupported ciphers that will be ignored",
"unsupportedCiphers", unsupportedCiphers,
)
}

if err := setFeatureGatesEnvVars(); err != nil {
klog.Error(err, "unable to set feature gates environment variables")
os.Exit(1)
Expand All @@ -157,32 +187,37 @@ func main() {
klog.LogToStderr(*logToStderr)
}

_, diagnosticsOpts, err := capiflags.GetManagerOptions(capiManagerOptions)
_, metricsOptions, err := capiflags.GetManagerOptions(capiManagerOptions)
if err != nil {
klog.Error(err, "unable to get manager options")
os.Exit(1)
}

// Override the TLS options for the metrics server with the ones specified centrally in the APIServer resource.
tlsOptions := []func(config *tls.Config){tlsConfig}
metricsOptions.TLSOpts = tlsOptions

syncPeriod := 10 * time.Minute

cacheOpts := getDefaultCacheOptions(*managedNamespace, syncPeriod)

cfg := ctrl.GetConfigOrDie()

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
Metrics: *diagnosticsOpts,
Metrics: *metricsOptions,
HealthProbeBindAddress: *healthAddr,
LeaderElectionNamespace: leaderElectionConfig.ResourceNamespace,
LeaderElection: leaderElectionConfig.LeaderElect,
LeaseDuration: &leaderElectionConfig.LeaseDuration.Duration,
LeaderElectionID: leaderElectionConfig.ResourceName,
RetryPeriod: &leaderElectionConfig.RetryPeriod.Duration,
RenewDeadline: &leaderElectionConfig.RenewDeadline.Duration,
Cache: cacheOpts,
// Release the leader election when the context is cancelled, to recover quicker on restarts.
LeaderElectionReleaseOnCancel: true,
RetryPeriod: &leaderElectionConfig.RetryPeriod.Duration,
RenewDeadline: &leaderElectionConfig.RenewDeadline.Duration,
Cache: cacheOpts,
WebhookServer: crwebhook.NewServer(crwebhook.Options{
Port: *webhookPort,
CertDir: *webhookCertDir,
TLSOpts: tlsOptions,
}),
})
if err != nil {
Expand Down Expand Up @@ -220,7 +255,7 @@ func main() {
os.Exit(1)
}

setupPlatformReconcilers(mgr, infra, platform, containerImages, applyClient, apiextensionsClient, *managedNamespace)
setupPlatformReconcilers(mgr, infra, platform, containerImages, applyClient, apiextensionsClient, *managedNamespace, tlsOptions, tlsSecurityProfileSpec, cancel)

// +kubebuilder:scaffold:builder

Expand All @@ -236,7 +271,7 @@ func main() {

klog.Info("Starting manager")

if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
if err := mgr.Start(ctx); err != nil {
klog.Error(err, "problem running manager")
os.Exit(1)
}
Expand All @@ -252,17 +287,17 @@ func getClusterOperatorStatusClient(mgr manager.Manager, controller string, plat
}
}

func setupPlatformReconcilers(mgr manager.Manager, infra *configv1.Infrastructure, platform configv1.PlatformType, containerImages map[string]string, applyClient *kubernetes.Clientset, apiextensionsClient *apiextensionsclient.Clientset, managedNamespace string) {
func setupPlatformReconcilers(mgr manager.Manager, infra *configv1.Infrastructure, platform configv1.PlatformType, containerImages map[string]string, applyClient *kubernetes.Clientset, apiextensionsClient *apiextensionsclient.Clientset, managedNamespace string, tlsOptions []func(config *tls.Config), tlsSecurityProfileSpec configv1.TLSProfileSpec, cancel context.CancelFunc) {
// Only setup reconcile controllers and webhooks when the platform is supported.
// This avoids unnecessary CAPI providers discovery, installs and reconciles when the platform is not supported.
isUnsupportedPlatform := false

switch platform {
case configv1.AWSPlatformType:
setupReconcilers(mgr, infra, platform, &awsv1.AWSCluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace)
setupReconcilers(mgr, infra, platform, &awsv1.AWSCluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace, tlsOptions, tlsSecurityProfileSpec, cancel)
setupWebhooks(mgr)
case configv1.GCPPlatformType:
setupReconcilers(mgr, infra, platform, &gcpv1.GCPCluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace)
setupReconcilers(mgr, infra, platform, &gcpv1.GCPCluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace, tlsOptions, tlsSecurityProfileSpec, cancel)
setupWebhooks(mgr)
case configv1.AzurePlatformType:
azureCloudEnvironment := getAzureCloudEnvironment(infra.Status.PlatformStatus)
Expand All @@ -272,20 +307,20 @@ func setupPlatformReconcilers(mgr manager.Manager, infra *configv1.Infrastructur
isUnsupportedPlatform = true
} else {
// The ClusterOperator Controller must run in all cases.
setupReconcilers(mgr, infra, platform, &azurev1.AzureCluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace)
setupReconcilers(mgr, infra, platform, &azurev1.AzureCluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace, tlsOptions, tlsSecurityProfileSpec, cancel)
setupWebhooks(mgr)
}
case configv1.PowerVSPlatformType:
setupReconcilers(mgr, infra, platform, &ibmpowervsv1.IBMPowerVSCluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace)
setupReconcilers(mgr, infra, platform, &ibmpowervsv1.IBMPowerVSCluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace, tlsOptions, tlsSecurityProfileSpec, cancel)
setupWebhooks(mgr)
case configv1.VSpherePlatformType:
setupReconcilers(mgr, infra, platform, &vspherev1.VSphereCluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace)
setupReconcilers(mgr, infra, platform, &vspherev1.VSphereCluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace, tlsOptions, tlsSecurityProfileSpec, cancel)
setupWebhooks(mgr)
case configv1.OpenStackPlatformType:
setupReconcilers(mgr, infra, platform, &openstackv1.OpenStackCluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace)
setupReconcilers(mgr, infra, platform, &openstackv1.OpenStackCluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace, tlsOptions, tlsSecurityProfileSpec, cancel)
setupWebhooks(mgr)
case configv1.BareMetalPlatformType:
setupReconcilers(mgr, infra, platform, &metal3v1.Metal3Cluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace)
setupReconcilers(mgr, infra, platform, &metal3v1.Metal3Cluster{}, containerImages, applyClient, apiextensionsClient, managedNamespace, tlsOptions, tlsSecurityProfileSpec, cancel)
setupWebhooks(mgr)
default:
klog.Infof("Detected platform %q is not supported, skipping capi controllers setup", platform)
Expand All @@ -297,7 +332,7 @@ func setupPlatformReconcilers(mgr manager.Manager, infra *configv1.Infrastructur
setupClusterOperatorController(mgr, platform, managedNamespace, isUnsupportedPlatform)
}

func setupReconcilers(mgr manager.Manager, infra *configv1.Infrastructure, platform configv1.PlatformType, infraClusterObject client.Object, containerImages map[string]string, applyClient *kubernetes.Clientset, apiextensionsClient *apiextensionsclient.Clientset, managedNamespace string) {
func setupReconcilers(mgr manager.Manager, infra *configv1.Infrastructure, platform configv1.PlatformType, infraClusterObject client.Object, containerImages map[string]string, applyClient *kubernetes.Clientset, apiextensionsClient *apiextensionsclient.Clientset, managedNamespace string, tlsOptions []func(config *tls.Config), tlsSecurityProfileSpec configv1.TLSProfileSpec, cancel context.CancelFunc) {
if err := (&corecluster.CoreClusterController{
ClusterOperatorStatusClient: getClusterOperatorStatusClient(mgr, "cluster-capi-operator-cluster-resource-controller", platform, managedNamespace),
Cluster: &clusterv1.Cluster{},
Expand Down Expand Up @@ -333,6 +368,7 @@ func setupReconcilers(mgr manager.Manager, infra *configv1.Infrastructure, platf
Platform: platform,
ApplyClient: applyClient,
APIExtensionsClient: apiextensionsClient,
TLSOpts: tlsOptions,
}).SetupWithManager(mgr); err != nil {
klog.Error(err, "unable to create capi installer controller", "controller", "CAPIInstaller")
os.Exit(1)
Expand All @@ -349,6 +385,17 @@ func setupReconcilers(mgr manager.Manager, infra *configv1.Infrastructure, platf
klog.Error(err, "unable to create infracluster controller", "controller", "InfraCluster")
os.Exit(1)
}

// Set up the TLS security profile watcher controller.
// This will trigger a graceful shutdown when the TLS profile changes.
if err := (&utiltls.TLSSecurityProfileWatcher{
Client: mgr.GetClient(),
InitialTLSProfileSpec: tlsSecurityProfileSpec,
Shutdown: cancel,
}).SetupWithManager(mgr); err != nil {
klog.Error(err, "unable to create controller", "controller", "TLSSecurityProfileWatcher")
os.Exit(1)
}
}

func setupWebhooks(mgr ctrl.Manager) {
Expand Down
12 changes: 7 additions & 5 deletions cmd/machine-api-migration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func main() {
klog.LogToStderr(*logToStderr)
}

_, diagnosticsOpts, err := capiflags.GetManagerOptions(capiManagerOptions)
_, metricsOpts, err := capiflags.GetManagerOptions(capiManagerOptions)
if err != nil {
klog.Error(err, "unable to get manager options")
os.Exit(1)
Expand All @@ -139,15 +139,17 @@ func main() {

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
Metrics: *diagnosticsOpts,
Metrics: *metricsOpts,
HealthProbeBindAddress: *healthAddr,
LeaderElectionNamespace: leaderElectionConfig.ResourceNamespace,
LeaderElection: leaderElectionConfig.LeaderElect,
LeaseDuration: &leaderElectionConfig.LeaseDuration.Duration,
LeaderElectionID: leaderElectionConfig.ResourceName,
RetryPeriod: &leaderElectionConfig.RetryPeriod.Duration,
RenewDeadline: &leaderElectionConfig.RenewDeadline.Duration,
Cache: cacheOpts,
// Release the leader election when the context is cancelled, to recover quicker on restarts.
LeaderElectionReleaseOnCancel: true,
RetryPeriod: &leaderElectionConfig.RetryPeriod.Duration,
RenewDeadline: &leaderElectionConfig.RenewDeadline.Duration,
Cache: cacheOpts,
})
if err != nil {
klog.Error(err, "unable to create manager")
Expand Down
12 changes: 6 additions & 6 deletions e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ require (
github.com/openshift/api v0.0.0-20260105114749-aae5635a71a7
github.com/openshift/cluster-api-actuator-pkg v0.0.0-20251203134942-d9bd7b8593f3
github.com/openshift/cluster-api-provider-baremetal v0.0.0-20250619124612-fb678fec5f7e
k8s.io/api v0.34.1
k8s.io/apimachinery v0.34.1
k8s.io/client-go v0.34.1
k8s.io/api v0.34.3
k8s.io/apimachinery v0.34.3
k8s.io/client-go v0.34.3
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d
sigs.k8s.io/cluster-api v1.11.3
sigs.k8s.io/cluster-api-provider-aws/v2 v2.10.0
Expand All @@ -30,7 +30,7 @@ require (
sigs.k8s.io/cluster-api-provider-ibmcloud v0.12.0
sigs.k8s.io/cluster-api-provider-openstack v0.13.1
sigs.k8s.io/cluster-api-provider-vsphere v1.14.0
sigs.k8s.io/controller-runtime v0.22.4
sigs.k8s.io/controller-runtime v0.22.5
sigs.k8s.io/yaml v1.6.0
)

Expand Down Expand Up @@ -123,8 +123,8 @@ require (
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.34.1 // indirect
k8s.io/component-base v0.34.1 // indirect
k8s.io/apiextensions-apiserver v0.34.3 // indirect
k8s.io/component-base v0.34.3 // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
Expand Down
21 changes: 7 additions & 14 deletions e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,12 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/api v0.34.1 h1:jC+153630BMdlFukegoEL8E/yT7aLyQkIVuwhmwDgJM=
k8s.io/api v0.34.1/go.mod h1:SB80FxFtXn5/gwzCoN6QCtPD7Vbu5w2n1S0J5gFfTYk=
k8s.io/apiextensions-apiserver v0.34.1 h1:NNPBva8FNAPt1iSVwIE0FsdrVriRXMsaWFMqJbII2CI=
k8s.io/apiextensions-apiserver v0.34.1/go.mod h1:hP9Rld3zF5Ay2Of3BeEpLAToP+l4s5UlxiHfqRaRcMc=
k8s.io/apimachinery v0.34.1 h1:dTlxFls/eikpJxmAC7MVE8oOeP1zryV7iRyIjB0gky4=
k8s.io/apimachinery v0.34.1/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw=
k8s.io/apiserver v0.34.1 h1:U3JBGdgANK3dfFcyknWde1G6X1F4bg7PXuvlqt8lITA=
k8s.io/apiserver v0.34.1/go.mod h1:eOOc9nrVqlBI1AFCvVzsob0OxtPZUCPiUJL45JOTBG0=
k8s.io/client-go v0.34.1 h1:ZUPJKgXsnKwVwmKKdPfw4tB58+7/Ik3CrjOEhsiZ7mY=
k8s.io/client-go v0.34.1/go.mod h1:kA8v0FP+tk6sZA0yKLRG67LWjqufAoSHA2xVGKw9Of8=
k8s.io/component-base v0.34.1 h1:v7xFgG+ONhytZNFpIz5/kecwD+sUhVE6HU7qQUiRM4A=
k8s.io/component-base v0.34.1/go.mod h1:mknCpLlTSKHzAQJJnnHVKqjxR7gBeHRv0rPXA7gdtQ0=
k8s.io/api v0.34.3 h1:D12sTP257/jSH2vHV2EDYrb16bS7ULlHpdNdNhEw2S4=
k8s.io/apiextensions-apiserver v0.34.3 h1:p10fGlkDY09eWKOTeUSioxwLukJnm+KuDZdrW71y40g=
k8s.io/apimachinery v0.34.3 h1:/TB+SFEiQvN9HPldtlWOTp0hWbJ+fjU+wkxysf/aQnE=
k8s.io/apiserver v0.34.3 h1:uGH1qpDvSiYG4HVFqc6A3L4CKiX+aBWDrrsxHYK0Bdo=
k8s.io/client-go v0.34.3 h1:wtYtpzy/OPNYf7WyNBTj3iUA0XaBHVqhv4Iv3tbrF5A=
k8s.io/component-base v0.34.3 h1:zsEgw6ELqK0XncCQomgO9DpUIzlrYuZYA0Cgo+JWpVk=
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
Expand All @@ -391,8 +385,7 @@ sigs.k8s.io/cluster-api-provider-openstack v0.13.1 h1:vN+NMrJMByn33EH3NiLvveZO7n
sigs.k8s.io/cluster-api-provider-openstack v0.13.1/go.mod h1:8zIJiDXVHjSHgCZX49JbsR1Z03zhvCXk6a0zYpUZTcQ=
sigs.k8s.io/cluster-api-provider-vsphere v1.14.0 h1:MR3Ry1DvFeeLHH4ldFi1kChpkkB5HPOWHP0viURbL8c=
sigs.k8s.io/cluster-api-provider-vsphere v1.14.0/go.mod h1:QilGYtsQutBXDmdhSRyMDvJaKiuVaUaAf5LIirlZFZM=
sigs.k8s.io/controller-runtime v0.22.4 h1:GEjV7KV3TY8e+tJ2LCTxUTanW4z/FmNB7l327UfMq9A=
sigs.k8s.io/controller-runtime v0.22.4/go.mod h1:+QX1XUpTXN4mLoblf4tqr5CQcyHPAki2HLXqQMY6vh8=
sigs.k8s.io/controller-runtime v0.22.5 h1:v3nfSUMowX/2WMp27J9slwGFyAt7IV0YwBxAkrUr0GE=
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE=
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96 h1:PFWFSkpArPNJxFX4ZKWAk9NSeRoZaXschn+ULa4xVek=
Expand Down
15 changes: 8 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.24.0
// TODO: these replaces should be removed when corresponding PRs are merged
replace (
github.com/openshift/cluster-api-actuator-pkg/testutils => github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-20251211141525-c707612472dc
github.com/openshift/library-go => github.com/damdo/library-go v0.0.0-20260120133104-12bddc18ba38
sigs.k8s.io/cluster-api-provider-azure => github.com/openshift/cluster-api-provider-azure v0.0.0-20251202084521-c2e0e38d1e0e
)

Expand All @@ -29,12 +30,12 @@ require (
github.com/spf13/pflag v1.0.10
golang.org/x/tools v0.38.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.34.1
k8s.io/apiextensions-apiserver v0.34.1
k8s.io/apimachinery v0.34.1
k8s.io/apiserver v0.34.1
k8s.io/client-go v0.34.1
k8s.io/component-base v0.34.1
k8s.io/api v0.34.3
k8s.io/apiextensions-apiserver v0.34.3
k8s.io/apimachinery v0.34.3
k8s.io/apiserver v0.34.3
k8s.io/client-go v0.34.3
k8s.io/component-base v0.34.3
k8s.io/klog/v2 v2.130.1
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d
sigs.k8s.io/cluster-api v1.11.3
Expand All @@ -44,7 +45,7 @@ require (
sigs.k8s.io/cluster-api-provider-ibmcloud v0.12.0
sigs.k8s.io/cluster-api-provider-openstack v0.13.1
sigs.k8s.io/cluster-api-provider-vsphere v1.14.0
sigs.k8s.io/controller-runtime v0.22.4
sigs.k8s.io/controller-runtime v0.22.5
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20240927101401-4381fa0aeee4
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96
sigs.k8s.io/randfill v1.0.0
Expand Down
Loading