Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃尡 clusterctl upgrade cert-manager ignore provider CRDs #5681

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 31 additions & 3 deletions cmd/clusterctl/client/cluster/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/scheme"
"sigs.k8s.io/cluster-api/version"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -62,7 +63,8 @@ type Proxy interface {

// ListResources lists namespaced and cluster-wide resources matching the labels. Namespaced resources are only listed
// in the given namespaces.
// If labels contains the ProviderLabelName label, CRDs of other providers are excluded.
// If labels contains the ProviderLabelName label, CRDs of other providers are excluded; if labels indicates that
// resources for cert-manager should be listed, CRDs for all the providers are excluded.
// This is done to avoid errors when listing resources of providers which have already been deleted.
ListResources(labels map[string]string, namespaces ...string) ([]unstructured.Unstructured, error)

Expand Down Expand Up @@ -207,7 +209,8 @@ func (k *proxy) CheckClusterAvailable() error {

// ListResources lists namespaced and cluster-wide resources matching the labels. Namespaced resources are only listed
// in the given namespaces.
// If labels contains the ProviderLabelName label, CRDs of other providers are excluded.
// If labels contains the ProviderLabelName label, CRDs of other providers are excluded; if labels indicates that
// resources for cert-manager should be listed, CRDs for all the providers are excluded.
// This is done to avoid errors when listing resources of providers which have already been deleted.
// For example:
// * The AWS provider has already been deleted, but there are still cluster-wide resources of AWSClusterControllerIdentity.
Expand Down Expand Up @@ -237,8 +240,9 @@ func (k *proxy) ListResources(labels map[string]string, namespaces ...string) ([
return nil, errors.Wrap(err, "failed to list api resources")
}

// If labels indicates that resources of a specific provider should be listed, exclude CRDs of other providers.
crdsToExclude := sets.String{}

// If labels indicates that resources of a specific provider should be listed, exclude CRDs of other providers.
if providerName, ok := labels[clusterv1.ProviderLabelName]; ok {
// List all CRDs in the cluster.
crdList := &apiextensionsv1.CustomResourceDefinitionList{}
Expand All @@ -262,6 +266,30 @@ func (k *proxy) ListResources(labels map[string]string, namespaces ...string) ([
}
}

// If labels indicates that resources for cert-manager should be listed, exclude CRDs for all the providers.
if object, ok := labels[clusterctlv1.ClusterctlCoreLabelName]; ok && (object == clusterctlv1.ClusterctlCoreLabelCertManagerValue) {
// List all CRDs in the cluster.
crdList := &apiextensionsv1.CustomResourceDefinitionList{}
if err := retryWithExponentialBackoff(newReadBackoff(), func() error {
return c.List(ctx, crdList)
}); err != nil {
return nil, errors.Wrap(err, "failed to list CRDs")
}

// Exclude CRDs for providers.
for _, crd := range crdList.Items {
if _, ok := crd.Labels[clusterv1.ProviderLabelName]; ok {
for _, version := range crd.Spec.Versions {
crdsToExclude.Insert(metav1.GroupVersionKind{
Group: crd.Spec.Group,
Version: version.Name,
Kind: crd.Spec.Names.Kind,
}.String())
}
}
}
}

// Select resources with list and delete methods (list is required by this method, delete by the callers of this method)
resourceList = discovery.FilteredBy(discovery.SupportsAllVerbs{Verbs: []string{"list", "delete"}}, resourceList)

Expand Down