-
Notifications
You must be signed in to change notification settings - Fork 567
OCPBUGS-79539: fix(cpo-v2): preserve HCCO modifications to OCM Controllers field #8072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ import ( | |
| "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/cvo" | ||
| cpomanifests "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/manifests" | ||
| cpoauth "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/oauth" | ||
| "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/ocm" | ||
| "github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/api" | ||
| alerts "github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/alerts" | ||
| azureresources "github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/azure" | ||
| "github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/cco" | ||
|
|
@@ -52,6 +54,7 @@ import ( | |
| "github.com/openshift/api/annotations" | ||
| configv1 "github.com/openshift/api/config/v1" | ||
| imageregistryv1 "github.com/openshift/api/imageregistry/v1" | ||
| openshiftcpv1 "github.com/openshift/api/openshiftcontrolplane/v1" | ||
| operatorv1 "github.com/openshift/api/operator/v1" | ||
|
|
||
| admissionregistrationv1 "k8s.io/api/admissionregistration/v1" | ||
|
|
@@ -422,12 +425,70 @@ func (r *reconciler) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result | |
| errs = append(errs, fmt.Errorf("failed to reconcile rbac: %w", err)) | ||
| } | ||
|
|
||
| // Reconcile the image registry only if the image registry capability is enabled. | ||
| // Skip this step if the user explicitly disabled image registry. | ||
| registryConfig := manifests.Registry() | ||
| var registryConfigExists bool | ||
| // Check if the registry config exists | ||
| if err := r.client.Get(ctx, client.ObjectKeyFromObject(registryConfig), registryConfig); err != nil { | ||
| if !apierrors.IsNotFound(err) { | ||
| return ctrl.Result{}, fmt.Errorf("failed to get registry config: %w", err) | ||
| } | ||
| } else { | ||
| registryConfigExists = true | ||
| } | ||
|
|
||
| // For platforms where cluster-image-registry-operator (CIRO) needs a PVC to be created, bootstrap needs to happen | ||
| // in CIRO before the registry config is created. For now, this is the case for the OpenStack platform. | ||
| // If the object exist, we reconcile the registry config for other fields as it should be fine since the PVC would | ||
| // exist at this point. | ||
| if capabilities.IsImageRegistryCapabilityEnabled(hcp.Spec.Capabilities) { | ||
| log.Info("reconciling image registry") | ||
| if regErrs := r.reconcileImageRegistry(ctx, hcp); len(regErrs) > 0 { | ||
| errs = append(errs, regErrs...) | ||
| if imageRegistryPlatformWithPVC(hcp.Spec.Platform.Type) && (!registryConfigExists || registryConfig == nil) { | ||
| log.Info("skipping registry config to let CIRO bootstrap") | ||
| } else { | ||
| log.Info("reconciling image registry validating admission policy") | ||
| if r.platformType == hyperv1.AzurePlatform { | ||
| if err := registry.ReconcileRegistryConfigValidatingAdmissionPolicies(ctx, hcp, r.client, r.CreateOrUpdate); err != nil { | ||
| errs = append(errs, fmt.Errorf("failed to reconcile image registry validating admission policy: %w", err)) | ||
| } | ||
| } | ||
| log.Info("reconciling registry config") | ||
| if _, err := r.CreateOrUpdate(ctx, r.client, registryConfig, func() error { | ||
| err = registry.ReconcileRegistryConfig(registryConfig, r.platformType, hcp.Spec.InfrastructureAvailabilityPolicy) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| }); err != nil { | ||
| errs = append(errs, fmt.Errorf("failed to reconcile imageregistry config: %w", err)) | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| // TODO: remove this when ROSA HCP stops setting the managementState to Removed to disable the Image Registry | ||
| if registryConfig.Spec.ManagementState == operatorv1.Removed && r.platformType != hyperv1.IBMCloudPlatform && r.platformType != hyperv1.AzurePlatform { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add unit tests for managementState == Removed OCM ConfigMap logic
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a comment why IBM and Azure are being excluded from the managementState check?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, this should have been "only AWS" not "not IBM and not Azure". It is part of the revert as well though. |
||
| log.Info("imageregistry operator managementstate is removed, disabling openshift-controller-manager controllers and cleaning up resources") | ||
| ocmConfigMap := cpomanifests.OpenShiftControllerManagerConfig(r.hcpNamespace) | ||
| if _, err := r.CreateOrUpdate(ctx, r.cpClient, ocmConfigMap, func() error { | ||
| if ocmConfigMap.Data == nil { | ||
| // CPO has not created the configmap yet, wait for create | ||
| // This should not happen as we are started by the CPO after the configmap should be created | ||
| return nil | ||
| } | ||
| config := &openshiftcpv1.OpenShiftControllerManagerConfig{} | ||
| if configStr, exists := ocmConfigMap.Data[ocm.ConfigKey]; exists && len(configStr) > 0 { | ||
| err := util.DeserializeResource(configStr, config, api.Scheme) | ||
| if err != nil { | ||
| return fmt.Errorf("unable to decode existing openshift controller manager configuration: %w", err) | ||
| } | ||
| } | ||
| config.Controllers = []string{"*", fmt.Sprintf("-%s", openshiftcpv1.OpenShiftServiceAccountPullSecretsController)} | ||
| configStr, err := util.SerializeResource(config, api.Scheme) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to serialize openshift controller manager configuration: %w", err) | ||
| } | ||
| ocmConfigMap.Data[ocm.ConfigKey] = configStr | ||
| return nil | ||
| }); err != nil { | ||
| errs = append(errs, fmt.Errorf("failed to reconcile openshift-controller-manager config: %w", err)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -3417,52 +3478,3 @@ func imageRegistryPlatformWithPVC(platform hyperv1.PlatformType) bool { | |
| return false | ||
| } | ||
| } | ||
|
|
||
| // reconcileImageRegistry reconciles the image registry configuration. | ||
| // It handles: | ||
| // - Platform-specific PVC logic (e.g., OpenStack needs CIRO bootstrap first) | ||
| // - Validating admission policies (Azure only) | ||
| // - Registry configuration reconciliation | ||
| func (r *reconciler) reconcileImageRegistry( | ||
| ctx context.Context, | ||
| hcp *hyperv1.HostedControlPlane, | ||
| ) []error { | ||
| log := ctrl.LoggerFrom(ctx) | ||
| var errs []error | ||
|
|
||
| registryConfig := manifests.Registry() | ||
| var registryConfigExists bool | ||
| // Check if the registry config exists | ||
| if err := r.client.Get(ctx, client.ObjectKeyFromObject(registryConfig), registryConfig); err != nil { | ||
| if !apierrors.IsNotFound(err) { | ||
| return []error{fmt.Errorf("failed to get registry config: %w", err)} | ||
| } | ||
| } else { | ||
| registryConfigExists = true | ||
| } | ||
|
|
||
| // For platforms where cluster-image-registry-operator (CIRO) needs a PVC to be created, bootstrap needs to happen | ||
| // in CIRO before the registry config is created. For now, this is the case for the OpenStack platform. | ||
| // If the object exist, we reconcile the registry config for other fields as it should be fine since the PVC would | ||
| // exist at this point. | ||
| if imageRegistryPlatformWithPVC(hcp.Spec.Platform.Type) && (!registryConfigExists || registryConfig == nil) { | ||
| log.Info("skipping registry config to let CIRO bootstrap") | ||
| return nil | ||
| } | ||
|
|
||
| log.Info("reconciling image registry validating admission policy") | ||
| if r.platformType == hyperv1.AzurePlatform { | ||
| if err := registry.ReconcileRegistryConfigValidatingAdmissionPolicies(ctx, hcp, r.client, r.CreateOrUpdate); err != nil { | ||
| errs = append(errs, fmt.Errorf("failed to reconcile image registry validating admission policy: %w", err)) | ||
| } | ||
| } | ||
|
|
||
| log.Info("reconciling registry config") | ||
| if _, err := r.CreateOrUpdate(ctx, r.client, registryConfig, func() error { | ||
| return registry.ReconcileRegistryConfig(registryConfig, r.platformType, hcp.Spec.InfrastructureAvailabilityPolicy) | ||
| }); err != nil { | ||
| errs = append(errs, fmt.Errorf("failed to reconcile imageregistry config: %w", err)) | ||
| } | ||
|
|
||
| return errs | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registry config fetch moved outside capability guard
Medium Severity
The
r.client.Getcall for the registry config was moved outside theIsImageRegistryCapabilityEnabledcheck. Previously,reconcileImageRegistrywas only called when the capability was enabled, so the Get never executed when the capability was disabled. Now it runs unconditionally. If the ImageRegistry capability is disabled and theimageregistry.operator.openshift.io/v1CRD is absent from the guest cluster, the Get returns a non-NotFound error, triggering a hardreturn ctrl.Result{}, errthat aborts the entire reconciliation — blocking all subsequent steps like ingress, additional trusted CAs, etc. TheregistryConfigandregistryConfigExistsvariables are only consumed inside the capability-enabled block, so the fetch can be moved back inside that guard.