Skip to content

Commit cbd5749

Browse files
stefanonardoclaude
andcommitted
Migrate four controllers to per-controller condition reporting
Migrate CoreCluster, InfraCluster, Kubeconfig, and SecretSync controllers from ClusterOperatorStatusClient (merge-patch, shared top-level conditions) to ControllerResultGenerator (server-side apply, per-controller prefixed conditions). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7189785 commit cbd5749

13 files changed

Lines changed: 442 additions & 543 deletions

File tree

cmd/capi-controllers/main.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,35 +172,37 @@ func setupPlatformReconcilers(log logr.Logger, mgr manager.Manager, operatorConf
172172

173173
func setupReconcilers(mgr manager.Manager, operatorConfig commoncmdoptions.OperatorConfig, infra *configv1.Infrastructure, platform configv1.PlatformType, infraClusterObject client.Object) error {
174174
if err := (&corecluster.CoreClusterController{
175-
ClusterOperatorStatusClient: operatorConfig.GetClusterOperatorStatusClient(mgr, platform, "cluster-resource"),
176-
Cluster: &clusterv1.Cluster{},
177-
Platform: platform,
178-
Infra: infra,
175+
Client: mgr.GetClient(),
176+
ManagedNamespace: *operatorConfig.CAPINamespace,
177+
Cluster: &clusterv1.Cluster{},
178+
Platform: platform,
179+
Infra: infra,
179180
}).SetupWithManager(mgr); err != nil {
180181
return fmt.Errorf("unable to create corecluster controller: %w", err)
181182
}
182183

183184
if err := (&secretsync.UserDataSecretController{
184-
ClusterOperatorStatusClient: operatorConfig.GetClusterOperatorStatusClient(mgr, platform, "user-data-secret"),
185-
Scheme: mgr.GetScheme(),
185+
Client: mgr.GetClient(),
186+
ManagedNamespace: *operatorConfig.CAPINamespace,
187+
Scheme: mgr.GetScheme(),
186188
}).SetupWithManager(mgr); err != nil {
187189
return fmt.Errorf("unable to create user-data-secret controller: %w", err)
188190
}
189191

190192
if err := (&kubeconfig.KubeconfigReconciler{
191-
ClusterOperatorStatusClient: operatorConfig.GetClusterOperatorStatusClient(mgr, platform, "kubeconfig"),
192-
Scheme: mgr.GetScheme(),
193-
RestCfg: mgr.GetConfig(),
193+
Client: mgr.GetClient(),
194+
Scheme: mgr.GetScheme(),
195+
RestCfg: mgr.GetConfig(),
194196
}).SetupWithManager(mgr); err != nil {
195197
return fmt.Errorf("unable to create kubeconfig controller: %w", err)
196198
}
197199

198200
if err := (&infracluster.InfraClusterController{
199-
ClusterOperatorStatusClient: operatorConfig.GetClusterOperatorStatusClient(mgr, platform, "infracluster"),
200-
Scheme: mgr.GetScheme(),
201-
RestCfg: mgr.GetConfig(),
202-
Platform: platform,
203-
Infra: infra,
201+
Client: mgr.GetClient(),
202+
Scheme: mgr.GetScheme(),
203+
RestCfg: mgr.GetConfig(),
204+
Platform: platform,
205+
Infra: infra,
204206
}).SetupWithManager(mgr, infraClusterObject); err != nil {
205207
return fmt.Errorf("unable to create infracluster controller: %w", err)
206208
}

pkg/commoncmdoptions/commonoptions.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,9 @@ import (
3939
"k8s.io/klog/v2"
4040
"k8s.io/klog/v2/textlogger"
4141

42-
configv1 "github.com/openshift/api/config/v1"
4342
libgocrypto "github.com/openshift/library-go/pkg/crypto"
4443

4544
"github.com/openshift/cluster-capi-operator/pkg/controllers"
46-
"github.com/openshift/cluster-capi-operator/pkg/operatorstatus"
47-
"github.com/openshift/cluster-capi-operator/pkg/util"
4845
)
4946

5047
// The default durations for the leader election operations.
@@ -179,19 +176,6 @@ func InitOperatorConfig(ctx context.Context, cfg *rest.Config, scheme *runtime.S
179176
}, initManager(cfg, setupSecurityProfileWatcher), nil
180177
}
181178

182-
// GetClusterOperatorStatusClient returns a ClusterOperatorStatusClient struct which has been
183-
// initialised with values from the command line.
184-
func (opts *OperatorConfig) GetClusterOperatorStatusClient(mgr ctrl.Manager, platform configv1.PlatformType, controllerName string) operatorstatus.ClusterOperatorStatusClient {
185-
return operatorstatus.ClusterOperatorStatusClient{
186-
Client: mgr.GetClient(),
187-
Recorder: mgr.GetEventRecorderFor(opts.managerName + "-" + controllerName),
188-
ReleaseVersion: util.GetReleaseVersion(),
189-
ManagedNamespace: *opts.CAPINamespace,
190-
OperatorNamespace: *opts.OperatorNamespace,
191-
Platform: platform,
192-
}
193-
}
194-
195179
func initManager(cfg *rest.Config, securityProfileWatcher func(ctrl.Manager, context.CancelFunc) error) func(ctx context.Context, cancel context.CancelFunc, mgrOpts ctrl.Options) (ctrl.Manager, error) {
196180
return func(ctx context.Context, cancel context.CancelFunc, mgrOpts ctrl.Options) (ctrl.Manager, error) {
197181
mgr, err := ctrl.NewManager(cfg, mgrOpts)

pkg/controllers/clusteroperator/clusteroperator_controller.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ import (
2929
configv1 "github.com/openshift/api/config/v1"
3030
configv1apply "github.com/openshift/client-go/config/applyconfigurations/config/v1"
3131
"github.com/openshift/cluster-capi-operator/pkg/controllers"
32+
"github.com/openshift/cluster-capi-operator/pkg/controllers/corecluster"
33+
"github.com/openshift/cluster-capi-operator/pkg/controllers/infracluster"
3234
"github.com/openshift/cluster-capi-operator/pkg/controllers/installer"
35+
"github.com/openshift/cluster-capi-operator/pkg/controllers/kubeconfig"
3336
"github.com/openshift/cluster-capi-operator/pkg/controllers/revision"
37+
"github.com/openshift/cluster-capi-operator/pkg/controllers/secretsync"
3438
"github.com/openshift/cluster-capi-operator/pkg/operatorstatus"
3539
"github.com/openshift/cluster-capi-operator/pkg/util"
3640
)
@@ -175,11 +179,10 @@ func (r *ClusterOperatorController) aggregatedStatus(currentConditions []configv
175179
subControllers := []operatorstatus.ControllerResultGenerator{
176180
installer.ResultGenerator,
177181
revision.ResultGenerator,
178-
// TBD as they are migrated:
179-
// - corecluster
180-
// - infracluster
181-
// - secretsync
182-
// - kubeconfig
182+
corecluster.ResultGenerator,
183+
infracluster.ResultGenerator,
184+
kubeconfig.ResultGenerator,
185+
secretsync.ResultGenerator,
183186
}
184187

185188
subcontrollerStatuses := util.SliceMap(subControllers, func(subController operatorstatus.ControllerResultGenerator) subcontrollerStatus {

0 commit comments

Comments
 (0)