Skip to content

Commit

Permalink
fix: remove List KamajiControlPlanes call
Browse files Browse the repository at this point in the history
* remove List KamajiControlPlanes call

* add check to ensure TenantControlPlane is present on external clusters
  • Loading branch information
phoban01 authored Oct 18, 2024
1 parent 9936f4c commit 50099b0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions controllers/kamajicontrolplane_controller_externalreference.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package controllers

import (
"context"

Check failure on line 7 in controllers/kamajicontrolplane_controller_externalreference.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1"

Check failure on line 8 in controllers/kamajicontrolplane_controller_externalreference.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/clastix/cluster-api-control-plane-provider-kamaji) (gci)

Check failure on line 9 in controllers/kamajicontrolplane_controller_externalreference.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/clastix/cluster-api-control-plane-provider-kamaji) (gci)
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
Expand All @@ -20,11 +21,12 @@ const (
)

var (
ErrExternalClusterReferenceNotEnabled = errors.New("external cluster feature gates are not enabled")
ErrExternalClusterReferenceCrossNamespaceReference = errors.New("the ExternalClusterReference is enforcing kubeconfig in the same Namespace, ExternalClusterReferenceCrossNamespace must be enabled")
ErrExternalCLusterReferenceSecretEmptyError = errors.New("could not extract kubeconfig for external cluster reference, secret is empty")
ErrExternalClusterReferenceSecretKeyEmpty = errors.New("could not extract kubeconfig for external cluster reference, key is empty")
ErrExternalClusterReferenceNonInitializedStore = errors.New("remote manager is not yet initialized")
ErrExternalClusterReferenceNotEnabled = errors.New("external cluster feature gates are not enabled")
ErrExternalClusterReferenceCrossNamespaceReference = errors.New("the ExternalClusterReference is enforcing kubeconfig in the same Namespace, ExternalClusterReferenceCrossNamespace must be enabled")
ErrExternalCLusterReferenceSecretEmptyError = errors.New("could not extract kubeconfig for external cluster reference, secret is empty")
ErrExternalClusterReferenceSecretKeyEmpty = errors.New("could not extract kubeconfig for external cluster reference, key is empty")
ErrExternalClusterReferenceNonInitializedStore = errors.New("remote manager is not yet initialized")
ErrExternalClusterReferenceTenantControlPlaneNotFound = errors.New("TenantControlPlane custom resource not available in external cluster")
)

//nolint:cyclop
Expand Down Expand Up @@ -65,8 +67,10 @@ func (r *KamajiControlPlaneReconciler) extractRemoteClient(ctx context.Context,
return nil, ErrExternalClusterReferenceNonInitializedStore
}

if err := mgr.GetClient().List(ctx, &v1alpha1.KamajiControlPlaneList{}); err != nil {
return nil, errors.Wrapf(err, "cannot list KamajiControlPlane resources")
// Use the RESTMapper to check if the CRD is installed
gvr := kamajiv1alpha1.GroupVersion.WithResource("tenantcontrolplanes")
if _, err := mgr.GetRESTMapper().KindFor(gvr); err != nil {
return nil, ErrExternalClusterReferenceTenantControlPlaneNotFound
}

return mgr.GetClient(), nil
Expand Down

0 comments on commit 50099b0

Please sign in to comment.