Skip to content
Open
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
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ verify-%:
make $*
./hack/verify-diff.sh

verify: fmt lint verify-ocp-manifests ## Run formatting and linting checks
verify: generate fmt lint verify-ocp-manifests ## Run formatting and linting checks

test: verify unit ## Run verification and unit tests

build: bin/capi-operator bin/capi-controllers bin/machine-api-migration bin/crd-compatibility-checker manifests-gen ## Build all binaries
.PHONY: generate
generate:
go generate ./...

build: generate bin/capi-operator bin/capi-controllers bin/machine-api-migration bin/crd-compatibility-checker manifests-gen ## Build all binaries

clean:
rm -rf bin/*
Expand Down
30 changes: 16 additions & 14 deletions cmd/capi-controllers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,35 +172,37 @@ func setupPlatformReconcilers(log logr.Logger, mgr manager.Manager, operatorConf

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

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

if err := (&kubeconfig.KubeconfigReconciler{
ClusterOperatorStatusClient: operatorConfig.GetClusterOperatorStatusClient(mgr, platform, "kubeconfig"),
Scheme: mgr.GetScheme(),
RestCfg: mgr.GetConfig(),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
RestCfg: mgr.GetConfig(),
}).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create kubeconfig controller: %w", err)
}

if err := (&infracluster.InfraClusterController{
ClusterOperatorStatusClient: operatorConfig.GetClusterOperatorStatusClient(mgr, platform, "infracluster"),
Scheme: mgr.GetScheme(),
RestCfg: mgr.GetConfig(),
Platform: platform,
Infra: infra,
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
RestCfg: mgr.GetConfig(),
Platform: platform,
Infra: infra,
}).SetupWithManager(mgr, infraClusterObject); err != nil {
return fmt.Errorf("unable to create infracluster controller: %w", err)
}
Expand Down
20 changes: 11 additions & 9 deletions cmd/capi-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ import (
"github.com/openshift/cluster-capi-operator/pkg/util"
)

var errPodIdentityNotSet = errors.New("POD_NAME and POD_NAMESPACE must be set")
var (
errPodIdentityNotSet = errors.New("POD_NAME and POD_NAMESPACE must be set")
errInfrastructurePlatformStatusNotSet = errors.New("infrastructure platform status is not set")
)

const (
managerName = "capi-operator"
Expand Down Expand Up @@ -116,22 +119,21 @@ func setupControllers(ctx context.Context, log logr.Logger, mgr ctrl.Manager, op
return fmt.Errorf("unable to get infrastructure: %w", err)
}

platform, err := util.GetPlatformFromInfra(infra)
if err != nil {
return fmt.Errorf("unable to get platform: %w", err)
}

featureGates, err := util.GetFeatureGates(ctx, log, managerName, mgr.GetConfig(), cancel)
if err != nil {
return fmt.Errorf("unable to get feature gates: %w", err)
}

if infra.Status.PlatformStatus == nil {
return errInfrastructurePlatformStatusNotSet
}

supportedPlatform := util.IsCAPIEnabledForPlatform(featureGates, infra.Status.PlatformStatus.Type)

if err := (&clusteroperator.ClusterOperatorController{
ClusterOperatorStatusClient: operatorConfig.GetClusterOperatorStatusClient(mgr, platform, "clusteroperator"),
Scheme: mgr.GetScheme(),
IsUnsupportedPlatform: !supportedPlatform,
Client: mgr.GetClient(),
ReleaseVersion: util.GetReleaseVersion(),
IsUnsupportedPlatform: !supportedPlatform,
}).SetupWithManager(mgr); err != nil {
return fmt.Errorf("unable to create clusteroperator controller: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tool (
github.com/openshift/api/machine/v1beta1/zz_generated.crd-manifests
github.com/openshift/api/operator/v1/zz_generated.crd-manifests
github.com/openshift/api/operator/v1alpha1/zz_generated.crd-manifests
golang.org/x/tools/cmd/stringer
sigs.k8s.io/controller-runtime/tools/setup-envtest
)

Expand Down
16 changes: 0 additions & 16 deletions pkg/commoncmdoptions/commonoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ import (
"k8s.io/klog/v2"
"k8s.io/klog/v2/textlogger"

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

"github.com/openshift/cluster-capi-operator/pkg/controllers"
"github.com/openshift/cluster-capi-operator/pkg/operatorstatus"
"github.com/openshift/cluster-capi-operator/pkg/util"
)

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

// GetClusterOperatorStatusClient returns a ClusterOperatorStatusClient struct which has been
// initialised with values from the command line.
func (opts *OperatorConfig) GetClusterOperatorStatusClient(mgr ctrl.Manager, platform configv1.PlatformType, controllerName string) operatorstatus.ClusterOperatorStatusClient {
return operatorstatus.ClusterOperatorStatusClient{
Client: mgr.GetClient(),
Recorder: mgr.GetEventRecorderFor(opts.managerName + "-" + controllerName),
ReleaseVersion: util.GetReleaseVersion(),
ManagedNamespace: *opts.CAPINamespace,
OperatorNamespace: *opts.OperatorNamespace,
Platform: platform,
}
}

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) {
return func(ctx context.Context, cancel context.CancelFunc, mgrOpts ctrl.Options) (ctrl.Manager, error) {
mgr, err := ctrl.NewManager(cfg, mgrOpts)
Expand Down
Loading