diff --git a/pkg/controller/release/observe.go b/pkg/controller/release/observe.go index 21662c3..366dcc0 100644 --- a/pkg/controller/release/observe.go +++ b/pkg/controller/release/observe.go @@ -61,7 +61,7 @@ func generateObservation(in *release.Release) v1beta1.ReleaseObservation { } // isUpToDate checks whether desired spec up to date with the observed state for a given release -func isUpToDate(ctx context.Context, kube client.Client, spec *v1beta1.ReleaseSpec, observed *release.Release, s v1beta1.ReleaseStatus) (bool, error) { // nolint:gocyclo +func isUpToDate(ctx context.Context, kube client.Client, managementPoliciesEnabled bool, spec *v1beta1.ReleaseSpec, observed *release.Release, s v1beta1.ReleaseStatus) (bool, error) { // nolint:gocyclo if observed.Info == nil { return false, errors.New(errReleaseInfoNilInObservedRelease) } @@ -88,7 +88,7 @@ func isUpToDate(ctx context.Context, kube client.Client, spec *v1beta1.ReleaseSp mp := sets.New[xpv1.ManagementAction](spec.ManagementPolicies...) - if len(mp) != 0 && !mp.HasAny(xpv1.ManagementActionUpdate, xpv1.ManagementActionAll) { + if managementPoliciesEnabled && len(mp) != 0 && !mp.HasAny(xpv1.ManagementActionUpdate, xpv1.ManagementActionAll) { // Treated as up-to-date as we don't update or create the resource return true, nil } diff --git a/pkg/controller/release/release.go b/pkg/controller/release/release.go index cf08e12..af17b04 100644 --- a/pkg/controller/release/release.go +++ b/pkg/controller/release/release.go @@ -94,17 +94,18 @@ func Setup(mgr ctrl.Manager, o controller.Options, timeout time.Duration) error reconcilerOptions := []managed.ReconcilerOption{ managed.WithExternalConnecter(&connector{ - client: mgr.GetClient(), - logger: o.Logger, - usage: resource.NewProviderConfigUsageTracker(mgr.GetClient(), &helmv1beta1.ProviderConfigUsage{}), - kcfgExtractorFn: resource.CommonCredentialExtractor, - gcpExtractorFn: resource.CommonCredentialExtractor, - gcpInjectorFn: gke.WrapRESTConfig, - azureExtractorFn: resource.CommonCredentialExtractor, - azureInjectorFn: azure.WrapRESTConfig, - newRestConfigFn: clients.NewRESTConfig, - newKubeClientFn: clients.NewKubeClient, - newHelmClientFn: helmClient.NewClient, + client: mgr.GetClient(), + logger: o.Logger, + usage: resource.NewProviderConfigUsageTracker(mgr.GetClient(), &helmv1beta1.ProviderConfigUsage{}), + managementPoliciesEnabled: o.Features.Enabled(feature.EnableBetaManagementPolicies), + kcfgExtractorFn: resource.CommonCredentialExtractor, + gcpExtractorFn: resource.CommonCredentialExtractor, + gcpInjectorFn: gke.WrapRESTConfig, + azureExtractorFn: resource.CommonCredentialExtractor, + azureInjectorFn: azure.WrapRESTConfig, + newRestConfigFn: clients.NewRESTConfig, + newKubeClientFn: clients.NewKubeClient, + newHelmClientFn: helmClient.NewClient, }), managed.WithPollInterval(o.PollInterval), managed.WithLogger(o.Logger.WithValues("controller", name)), @@ -130,9 +131,10 @@ func Setup(mgr ctrl.Manager, o controller.Options, timeout time.Duration) error } type connector struct { - logger logging.Logger - client client.Client - usage resource.Tracker + logger logging.Logger + client client.Client + usage resource.Tracker + managementPoliciesEnabled bool kcfgExtractorFn func(ctx context.Context, src xpv1.CredentialsSource, c client.Client, ccs xpv1.CommonCredentialSelectors) ([]byte, error) gcpExtractorFn func(ctx context.Context, src xpv1.CredentialsSource, c client.Client, ccs xpv1.CommonCredentialSelectors) ([]byte, error) @@ -251,20 +253,22 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E } return &helmExternal{ - logger: l, - localKube: c.client, - kube: k, - helm: h, - patch: newPatcher(), + logger: l, + localKube: c.client, + kube: k, + helm: h, + patch: newPatcher(), + managementPoliciesEnabled: c.managementPoliciesEnabled, }, nil } type helmExternal struct { - logger logging.Logger - localKube client.Client - kube client.Client - helm helmClient.Client - patch Patcher + logger logging.Logger + localKube client.Client + kube client.Client + helm helmClient.Client + patch Patcher + managementPoliciesEnabled bool } func (e *helmExternal) Observe(ctx context.Context, mg resource.Managed) (managed.ExternalObservation, error) { @@ -301,7 +305,7 @@ func (e *helmExternal) Observe(ctx context.Context, mg resource.Managed) (manage return managed.ExternalObservation{ResourceExists: true}, nil } - s, err := isUpToDate(ctx, e.localKube, &cr.Spec, rel, cr.Status) + s, err := isUpToDate(ctx, e.localKube, e.managementPoliciesEnabled, &cr.Spec, rel, cr.Status) if err != nil { return managed.ExternalObservation{}, errors.Wrap(err, errFailedToCheckIfUpToDate) }