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 @@ -26,11 +26,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-installer bin/capi-controllers bin/machine-api-migration bin/crd-compatibility-checker bin/cluster-capi-operator-tests-ext manifests-gen ## Build all binaries
.PHONY: generate
generate:
go generate ./...

build: generate bin/capi-operator bin/capi-installer bin/capi-controllers bin/machine-api-migration bin/crd-compatibility-checker bin/cluster-capi-operator-tests-ext 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: 10 additions & 10 deletions cmd/capi-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ import (
)

var (
errPodIdentityNotSet = errors.New("POD_NAME and POD_NAMESPACE must be set")
errContainerNotInPod = errors.New("container not found in pod spec")
errPodIdentityNotSet = errors.New("POD_NAME and POD_NAMESPACE must be set")
errContainerNotInPod = errors.New("container not found in pod spec")
errInfrastructurePlatformStatusNotSet = errors.New("infrastructure platform status is not set")
)

const (
Expand Down Expand Up @@ -106,22 +107,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