Skip to content

Commit

Permalink
Reverting the last commit
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Tyr <jiri.tyr@gmail.com>
  • Loading branch information
jtyr committed Apr 7, 2024
1 parent 93567c4 commit 5d2fcbe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/release/observe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, managementPoliciesEnabled bool, spec *v1beta1.ReleaseSpec, observed *release.Release, s v1beta1.ReleaseStatus) (bool, error) { // nolint:gocyclo
func isUpToDate(ctx context.Context, kube client.Client, spec *v1beta1.ReleaseSpec, observed *release.Release, s v1beta1.ReleaseStatus) (bool, error) { // nolint:gocyclo
if observed.Info == nil {
return false, errors.New(errReleaseInfoNilInObservedRelease)
}
Expand All @@ -88,7 +88,7 @@ func isUpToDate(ctx context.Context, kube client.Client, managementPoliciesEnabl

mp := sets.New[xpv1.ManagementAction](spec.ManagementPolicies...)

if managementPoliciesEnabled && len(mp) != 0 && !mp.HasAny(xpv1.ManagementActionUpdate, xpv1.ManagementActionAll) {
if 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
}
Expand Down
54 changes: 25 additions & 29 deletions pkg/controller/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,17 @@ 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{}),
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,
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,
}),
managed.WithPollInterval(o.PollInterval),
managed.WithLogger(o.Logger.WithValues("controller", name)),
Expand All @@ -131,10 +130,9 @@ func Setup(mgr ctrl.Manager, o controller.Options, timeout time.Duration) error
}

type connector struct {
logger logging.Logger
client client.Client
usage resource.Tracker
managementPoliciesEnabled bool
logger logging.Logger
client client.Client
usage resource.Tracker

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)
Expand Down Expand Up @@ -253,22 +251,20 @@ 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(),
managementPoliciesEnabled: c.managementPoliciesEnabled,
logger: l,
localKube: c.client,
kube: k,
helm: h,
patch: newPatcher(),
}, nil
}

type helmExternal struct {
logger logging.Logger
localKube client.Client
kube client.Client
helm helmClient.Client
patch Patcher
managementPoliciesEnabled bool
logger logging.Logger
localKube client.Client
kube client.Client
helm helmClient.Client
patch Patcher
}

func (e *helmExternal) Observe(ctx context.Context, mg resource.Managed) (managed.ExternalObservation, error) {
Expand Down Expand Up @@ -305,7 +301,7 @@ func (e *helmExternal) Observe(ctx context.Context, mg resource.Managed) (manage
return managed.ExternalObservation{ResourceExists: true}, nil
}

s, err := isUpToDate(ctx, e.localKube, e.managementPoliciesEnabled, &cr.Spec, rel, cr.Status)
s, err := isUpToDate(ctx, e.localKube, &cr.Spec, rel, cr.Status)
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, errFailedToCheckIfUpToDate)
}
Expand Down

0 comments on commit 5d2fcbe

Please sign in to comment.