Skip to content

ClusterProviderConfigs in-use protection never engages #220

Description

@jbw976

What happened?

crossplane/provider-template#171 looks to be applicable to this repo as well, the pattern was probably picked up from provider-template in the first place.

TL;DR: The ClusterProviderConfig controller counts ClusterProviderConfigUsage records, and nothing in this provider creates one, so you can delete a ClusterProviderConfig that namespaced MRs for this provider are still using and it's not protected.

The ClusterProviderConfigUsage type can be removed, just use ProviderConfigUsage instead for namespaced MRs using either ProviderConfig or ClusterProviderConfig. That is the only usage kind crossplane-runtime's tracker creates for modern namespaced MRs.

  • the cluster config controller:
    of := resource.ProviderConfigKinds{
    Config: v1alpha1.ClusterProviderConfigGroupVersionKind,
    Usage: v1alpha1.ClusterProviderConfigUsageGroupVersionKind,
    UsageList: v1alpha1.ClusterProviderConfigUsageListGroupVersionKind,
    }
    r := providerconfig.NewReconciler(mgr, of,
    providerconfig.WithLogger(o.Logger.WithValues("controller", name)),
    providerconfig.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name)))) //nolint:staticcheck
    return ctrl.NewControllerManagedBy(mgr).
    Named(name).
    WithOptions(o.ForControllerRuntime()).
    For(&v1alpha1.ClusterProviderConfig{}).
    Watches(&v1alpha1.ClusterProviderConfigUsage{}, &resource.EnqueueRequestForProviderConfig{}).
  • the tracker the managed resources use:
    usage: resource.NewProviderConfigUsageTracker(mgr.GetClient(), &apisv1alpha1.ProviderConfigUsage{}),

crossplane/provider-template#171 has more details, but the fix itself is small: point the controller and its watch at ProviderConfigUsage, then delete the unused ClusterProviderConfigUsage types and CRD.

How can we reproduce it?

I haven't run this particular provider directly, I'm just opening this from what was learned/observed in provider-template. But I expect that:

  • a namespaced MR referencing a ClusterProviderConfig, .status.users on that config should be 1 but will probably be 0
  • kubectl delete clusterproviderconfig <name> should be blocked while in use but it will probably be removed right away

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions