From 745148d85d5f3f753c444049b4fef142ebf7cc7e Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Tue, 28 May 2024 11:01:02 +0100 Subject: [PATCH] :seedling: Use upstream cluster RESTConfig utility This commit simplifies the codebase by removing custom kubeconfig code and instead using the existing fucntionality from cluster-api project. --- controllers/controllers_test.go | 27 ++- .../helmreleaseproxy_controller.go | 27 +-- .../helmreleaseproxy_controller_test.go | 33 ++-- controllers/suite_test.go | 30 ++-- internal/helm_client.go | 63 +++---- internal/kubeconfig.go | 154 ------------------ internal/mocks/doc.go | 2 - internal/mocks/helm_client_mock.go | 25 +-- internal/mocks/kubeconfig_mock.go | 71 -------- main.go | 1 - 10 files changed, 103 insertions(+), 330 deletions(-) delete mode 100644 internal/kubeconfig.go delete mode 100644 internal/mocks/kubeconfig_mock.go diff --git a/controllers/controllers_test.go b/controllers/controllers_test.go index 7568fae2..9c2510b4 100644 --- a/controllers/controllers_test.go +++ b/controllers/controllers_test.go @@ -28,12 +28,12 @@ import ( addonsv1alpha1 "sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/util/conditions" + "sigs.k8s.io/cluster-api/util/secret" "sigs.k8s.io/controller-runtime/pkg/client" ) var ( testNamespace = "test-namespace" - kubeconfig = "test-kubeconfig" newVersion = "new-version" defaultProxy = &addonsv1alpha1.HelmChartProxy{ @@ -88,6 +88,29 @@ var ( } ) +func newKubeconfigSecretForCluster(cluster *clusterv1.Cluster) *corev1.Secret { + return &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: cluster.Name + "-kubeconfig", + Namespace: cluster.Namespace, + }, + Data: map[string][]byte{ + secret.KubeconfigDataName: []byte(`apiVersion: v1 +kind: Config +clusters: +- cluster: + server: http://127.0.0.1:8080 + name: ` + cluster.Name + ` +contexts: +- context: + cluster: ` + cluster.Name + ` + name: ` + cluster.Name + ` +current-context: ` + cluster.Name + ` +`), + }, + } +} + var _ = Describe("Testing HelmChartProxy and HelmReleaseProxy reconcile", func() { var ( waitForHelmChartProxyCondition = func(objectKey client.ObjectKey, condition func(helmChartProxy *addonsv1alpha1.HelmChartProxy) bool) { @@ -117,6 +140,8 @@ var _ = Describe("Testing HelmChartProxy and HelmReleaseProxy reconcile", func() cluster := cluster1.DeepCopy() err := k8sClient.Create(ctx, cluster) Expect(err).ToNot(HaveOccurred()) + err = k8sClient.Create(ctx, newKubeconfigSecretForCluster(cluster)) + Expect(err).ToNot(HaveOccurred()) patch := client.MergeFrom(cluster.DeepCopy()) cluster.Status.Conditions = clusterv1.Conditions{ diff --git a/controllers/helmreleaseproxy/helmreleaseproxy_controller.go b/controllers/helmreleaseproxy/helmreleaseproxy_controller.go index 0dada508..7a30f645 100644 --- a/controllers/helmreleaseproxy/helmreleaseproxy_controller.go +++ b/controllers/helmreleaseproxy/helmreleaseproxy_controller.go @@ -28,9 +28,11 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/rest" addonsv1alpha1 "sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1" "sigs.k8s.io/cluster-api-addon-provider-helm/internal" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + "sigs.k8s.io/cluster-api/controllers/remote" "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/patch" @@ -46,9 +48,8 @@ import ( // HelmReleaseProxyReconciler reconciles a HelmReleaseProxy object. type HelmReleaseProxyReconciler struct { client.Client - Scheme *runtime.Scheme - KubeconfigGetter internal.Getter - HelmClient internal.Client + Scheme *runtime.Scheme + HelmClient internal.Client // WatchFilterValue is the label value used to filter events prior to reconciliation. WatchFilterValue string @@ -152,7 +153,7 @@ func (r *HelmReleaseProxyReconciler) Reconcile(ctx context.Context, req ctrl.Req // our finalizer is present, so lets handle any external dependency if err := r.Client.Get(ctx, clusterKey, cluster); err == nil { log.V(2).Info("Getting kubeconfig for cluster", "cluster", cluster.Name) - kubeconfig, err := r.KubeconfigGetter.GetClusterKubeconfig(ctx, clusterKey) + restConfig, err := remote.RESTConfig(ctx, "caaph", r.Client, clusterKey) if err != nil { wrappedErr := errors.Wrapf(err, "failed to get kubeconfig for cluster") conditions.MarkFalse(helmReleaseProxy, addonsv1alpha1.ClusterAvailableCondition, addonsv1alpha1.GetKubeconfigFailedReason, clusterv1.ConditionSeverityError, wrappedErr.Error()) @@ -161,7 +162,7 @@ func (r *HelmReleaseProxyReconciler) Reconcile(ctx context.Context, req ctrl.Req } conditions.MarkTrue(helmReleaseProxy, addonsv1alpha1.ClusterAvailableCondition) - if err := r.reconcileDelete(ctx, helmReleaseProxy, r.HelmClient, kubeconfig); err != nil { + if err := r.reconcileDelete(ctx, helmReleaseProxy, r.HelmClient, restConfig); err != nil { // if fail to delete the external dependency here, return with error // so that it can be retried return ctrl.Result{}, err @@ -206,8 +207,8 @@ func (r *HelmReleaseProxyReconciler) Reconcile(ctx context.Context, req ctrl.Req return ctrl.Result{}, nil } - log.V(2).Info("Getting kubeconfig for cluster", "cluster", cluster.Name) - kubeconfig, err := r.KubeconfigGetter.GetClusterKubeconfig(ctx, clusterKey) + log.V(2).Info("Getting REST config for cluster", "cluster", cluster.Name) + restConfig, err := remote.RESTConfig(ctx, "caaph", r.Client, clusterKey) if err != nil { wrappedErr := errors.Wrapf(err, "failed to get kubeconfig for cluster") conditions.MarkFalse(helmReleaseProxy, addonsv1alpha1.ClusterAvailableCondition, addonsv1alpha1.GetKubeconfigFailedReason, clusterv1.ConditionSeverityError, wrappedErr.Error()) @@ -249,14 +250,14 @@ func (r *HelmReleaseProxyReconciler) Reconcile(ctx context.Context, req ctrl.Req } log.V(2).Info("Reconciling HelmReleaseProxy", "releaseProxyName", helmReleaseProxy.Name) - err = r.reconcileNormal(ctx, helmReleaseProxy, r.HelmClient, credentialsPath, caFilePath, kubeconfig) + err = r.reconcileNormal(ctx, helmReleaseProxy, r.HelmClient, credentialsPath, caFilePath, restConfig) return ctrl.Result{}, err } // reconcileNormal handles HelmReleaseProxy reconciliation when it is not being deleted. This will install or upgrade the HelmReleaseProxy on the Cluster. // It will set the ReleaseName on the HelmReleaseProxy if the name is generated and also set the release status and release revision. -func (r *HelmReleaseProxyReconciler) reconcileNormal(ctx context.Context, helmReleaseProxy *addonsv1alpha1.HelmReleaseProxy, client internal.Client, credentialsPath, caFilePath string, kubeconfig string) error { +func (r *HelmReleaseProxyReconciler) reconcileNormal(ctx context.Context, helmReleaseProxy *addonsv1alpha1.HelmReleaseProxy, client internal.Client, credentialsPath, caFilePath string, restConfig *rest.Config) error { log := ctrl.LoggerFrom(ctx) log.V(2).Info("Reconciling HelmReleaseProxy on cluster", "HelmReleaseProxy", helmReleaseProxy.Name, "cluster", helmReleaseProxy.Spec.ClusterRef.Name) @@ -268,7 +269,7 @@ func (r *HelmReleaseProxyReconciler) reconcileNormal(ctx context.Context, helmRe }) } - release, err := client.InstallOrUpgradeHelmRelease(ctx, kubeconfig, credentialsPath, caFilePath, helmReleaseProxy.Spec) + release, err := client.InstallOrUpgradeHelmRelease(ctx, restConfig, credentialsPath, caFilePath, helmReleaseProxy.Spec) if err != nil { log.Error(err, fmt.Sprintf("Failed to install or upgrade release '%s' on cluster %s", helmReleaseProxy.Spec.ReleaseName, helmReleaseProxy.Spec.ClusterRef.Name)) conditions.MarkFalse(helmReleaseProxy, addonsv1alpha1.HelmReleaseReadyCondition, addonsv1alpha1.HelmInstallOrUpgradeFailedReason, clusterv1.ConditionSeverityError, err.Error()) @@ -297,12 +298,12 @@ func (r *HelmReleaseProxyReconciler) reconcileNormal(ctx context.Context, helmRe } // reconcileDelete handles HelmReleaseProxy deletion. This will uninstall the HelmReleaseProxy on the Cluster or return nil if the HelmReleaseProxy is not found. -func (r *HelmReleaseProxyReconciler) reconcileDelete(ctx context.Context, helmReleaseProxy *addonsv1alpha1.HelmReleaseProxy, client internal.Client, kubeconfig string) error { +func (r *HelmReleaseProxyReconciler) reconcileDelete(ctx context.Context, helmReleaseProxy *addonsv1alpha1.HelmReleaseProxy, client internal.Client, restConfig *rest.Config) error { log := ctrl.LoggerFrom(ctx) log.V(2).Info("Deleting HelmReleaseProxy on cluster", "HelmReleaseProxy", helmReleaseProxy.Name, "cluster", helmReleaseProxy.Spec.ClusterRef.Name) - _, err := client.GetHelmRelease(ctx, kubeconfig, helmReleaseProxy.Spec) + _, err := client.GetHelmRelease(ctx, restConfig, helmReleaseProxy.Spec) if err != nil { log.V(2).Error(err, "error getting release from cluster", "cluster", helmReleaseProxy.Spec.ClusterRef.Name) @@ -320,7 +321,7 @@ func (r *HelmReleaseProxyReconciler) reconcileDelete(ctx context.Context, helmRe log.V(2).Info("Preparing to uninstall release on cluster", "releaseName", helmReleaseProxy.Spec.ReleaseName, "clusterName", helmReleaseProxy.Spec.ClusterRef.Name) - response, err := client.UninstallHelmRelease(ctx, kubeconfig, helmReleaseProxy.Spec) + response, err := client.UninstallHelmRelease(ctx, restConfig, helmReleaseProxy.Spec) if err != nil { log.V(2).Info("Error uninstalling chart with Helm:", err) conditions.MarkFalse(helmReleaseProxy, addonsv1alpha1.HelmReleaseReadyCondition, addonsv1alpha1.HelmReleaseDeletionFailedReason, clusterv1.ConditionSeverityError, err.Error()) diff --git a/controllers/helmreleaseproxy/helmreleaseproxy_controller_test.go b/controllers/helmreleaseproxy/helmreleaseproxy_controller_test.go index d2d4288d..e47b9169 100644 --- a/controllers/helmreleaseproxy/helmreleaseproxy_controller_test.go +++ b/controllers/helmreleaseproxy/helmreleaseproxy_controller_test.go @@ -28,6 +28,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" addonsv1alpha1 "sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1" "sigs.k8s.io/cluster-api-addon-provider-helm/internal/mocks" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" @@ -40,7 +41,7 @@ var ( ctx = ctrl.SetupSignalHandler() fakeScheme = runtime.NewScheme() - kubeconfig = "test-kubeconfig" + restConfig = &rest.Config{} defaultProxy = &addonsv1alpha1.HelmReleaseProxy{ TypeMeta: metav1.TypeMeta{ @@ -171,7 +172,7 @@ func TestReconcileNormal(t *testing.T) { name: "successfully install a Helm release", helmReleaseProxy: defaultProxy.DeepCopy(), clientExpect: func(g *WithT, c *mocks.MockClientMockRecorder) { - c.InstallOrUpgradeHelmRelease(ctx, kubeconfig, "", "", defaultProxy.DeepCopy().Spec).Return(&helmRelease.Release{ + c.InstallOrUpgradeHelmRelease(ctx, restConfig, "", "", defaultProxy.DeepCopy().Spec).Return(&helmRelease.Release{ Name: "test-release", Version: 1, Info: &helmRelease.Info{ @@ -195,7 +196,7 @@ func TestReconcileNormal(t *testing.T) { name: "successfully install a Helm release with a generated name", helmReleaseProxy: generateNameProxy, clientExpect: func(g *WithT, c *mocks.MockClientMockRecorder) { - c.InstallOrUpgradeHelmRelease(ctx, kubeconfig, "", "", generateNameProxy.Spec).Return(&helmRelease.Release{ + c.InstallOrUpgradeHelmRelease(ctx, restConfig, "", "", generateNameProxy.Spec).Return(&helmRelease.Release{ Name: "test-release", Version: 1, Info: &helmRelease.Info{ @@ -219,7 +220,7 @@ func TestReconcileNormal(t *testing.T) { name: "Helm release pending", helmReleaseProxy: defaultProxy.DeepCopy(), clientExpect: func(g *WithT, c *mocks.MockClientMockRecorder) { - c.InstallOrUpgradeHelmRelease(ctx, kubeconfig, "", "", defaultProxy.Spec).Return(&helmRelease.Release{ + c.InstallOrUpgradeHelmRelease(ctx, restConfig, "", "", defaultProxy.Spec).Return(&helmRelease.Release{ Name: "test-release", Version: 1, Info: &helmRelease.Info{ @@ -246,7 +247,7 @@ func TestReconcileNormal(t *testing.T) { name: "Helm client returns error", helmReleaseProxy: defaultProxy.DeepCopy(), clientExpect: func(g *WithT, c *mocks.MockClientMockRecorder) { - c.InstallOrUpgradeHelmRelease(ctx, kubeconfig, "", "", defaultProxy.Spec).Return(nil, errInternal).Times(1) + c.InstallOrUpgradeHelmRelease(ctx, restConfig, "", "", defaultProxy.Spec).Return(nil, errInternal).Times(1) }, expect: func(g *WithT, hrp *addonsv1alpha1.HelmReleaseProxy) { _, ok := hrp.Annotations[addonsv1alpha1.IsReleaseNameGeneratedAnnotation] @@ -264,7 +265,7 @@ func TestReconcileNormal(t *testing.T) { name: "Helm release in a failed state, no client error", helmReleaseProxy: defaultProxy.DeepCopy(), clientExpect: func(g *WithT, c *mocks.MockClientMockRecorder) { - c.InstallOrUpgradeHelmRelease(ctx, kubeconfig, "", "", defaultProxy.Spec).Return(&helmRelease.Release{ + c.InstallOrUpgradeHelmRelease(ctx, restConfig, "", "", defaultProxy.Spec).Return(&helmRelease.Release{ Name: "test-release", Version: 1, Info: &helmRelease.Info{ @@ -304,7 +305,7 @@ func TestReconcileNormal(t *testing.T) { Build(), } - err := r.reconcileNormal(ctx, tc.helmReleaseProxy, clientMock, "", "", kubeconfig) + err := r.reconcileNormal(ctx, tc.helmReleaseProxy, clientMock, "", "", restConfig) if tc.expectedError != "" { g.Expect(err).To(HaveOccurred()) g.Expect(err).To(MatchError(tc.expectedError), err.Error()) @@ -330,7 +331,7 @@ func TestReconcileNormalWithCredentialRef(t *testing.T) { name: "successfully install a Helm release", helmReleaseProxy: defaultProxyWithCredentialRef.DeepCopy(), clientExpect: func(g *WithT, c *mocks.MockClientMockRecorder) { - c.InstallOrUpgradeHelmRelease(ctx, kubeconfig, "/tmp/oci-credentials-xyz.json", "", defaultProxyWithCredentialRef.Spec).Return(&helmRelease.Release{ + c.InstallOrUpgradeHelmRelease(ctx, restConfig, "/tmp/oci-credentials-xyz.json", "", defaultProxyWithCredentialRef.Spec).Return(&helmRelease.Release{ Name: "test-release", Version: 1, Info: &helmRelease.Info{ @@ -370,7 +371,7 @@ func TestReconcileNormalWithCredentialRef(t *testing.T) { Build(), } - err := r.reconcileNormal(ctx, tc.helmReleaseProxy, clientMock, "/tmp/oci-credentials-xyz.json", "", kubeconfig) + err := r.reconcileNormal(ctx, tc.helmReleaseProxy, clientMock, "/tmp/oci-credentials-xyz.json", "", restConfig) if tc.expectedError != "" { g.Expect(err).To(HaveOccurred()) g.Expect(err).To(MatchError(tc.expectedError), err.Error()) @@ -396,7 +397,7 @@ func TestReconcileNormalWithACertificateRef(t *testing.T) { name: "successfully install a Helm release", helmReleaseProxy: defaultProxyWithCACertRef.DeepCopy(), clientExpect: func(g *WithT, c *mocks.MockClientMockRecorder) { - c.InstallOrUpgradeHelmRelease(ctx, kubeconfig, "", "/tmp/ca-xyz.crt", defaultProxyWithCACertRef.Spec).Return(&helmRelease.Release{ + c.InstallOrUpgradeHelmRelease(ctx, restConfig, "", "/tmp/ca-xyz.crt", defaultProxyWithCACertRef.Spec).Return(&helmRelease.Release{ Name: "test-release", Version: 1, Info: &helmRelease.Info{ @@ -436,7 +437,7 @@ func TestReconcileNormalWithACertificateRef(t *testing.T) { Build(), } - err := r.reconcileNormal(ctx, tc.helmReleaseProxy, clientMock, "", "/tmp/ca-xyz.crt", kubeconfig) + err := r.reconcileNormal(ctx, tc.helmReleaseProxy, clientMock, "", "/tmp/ca-xyz.crt", restConfig) if tc.expectedError != "" { g.Expect(err).To(HaveOccurred()) g.Expect(err).To(MatchError(tc.expectedError), err.Error()) @@ -462,14 +463,14 @@ func TestReconcileDelete(t *testing.T) { name: "successfully uninstall a Helm release", helmReleaseProxy: defaultProxy.DeepCopy(), clientExpect: func(g *WithT, c *mocks.MockClientMockRecorder) { - c.GetHelmRelease(ctx, kubeconfig, defaultProxy.DeepCopy().Spec).Return(&helmRelease.Release{ + c.GetHelmRelease(ctx, restConfig, defaultProxy.DeepCopy().Spec).Return(&helmRelease.Release{ Name: "test-release", Version: 1, Info: &helmRelease.Info{ Status: helmRelease.StatusDeployed, }, }, nil).Times(1) - c.UninstallHelmRelease(ctx, kubeconfig, defaultProxy.DeepCopy().Spec).Return(&helmRelease.UninstallReleaseResponse{}, nil).Times(1) + c.UninstallHelmRelease(ctx, restConfig, defaultProxy.DeepCopy().Spec).Return(&helmRelease.UninstallReleaseResponse{}, nil).Times(1) }, expect: func(g *WithT, hrp *addonsv1alpha1.HelmReleaseProxy) { g.Expect(conditions.Has(hrp, addonsv1alpha1.HelmReleaseReadyCondition)).To(BeTrue()) @@ -484,7 +485,7 @@ func TestReconcileDelete(t *testing.T) { name: "Helm release already uninstalled", helmReleaseProxy: defaultProxy.DeepCopy(), clientExpect: func(g *WithT, c *mocks.MockClientMockRecorder) { - c.GetHelmRelease(ctx, kubeconfig, defaultProxy.DeepCopy().Spec).Return(nil, helmDriver.ErrReleaseNotFound).Times(1) + c.GetHelmRelease(ctx, restConfig, defaultProxy.DeepCopy().Spec).Return(nil, helmDriver.ErrReleaseNotFound).Times(1) }, expect: func(g *WithT, hrp *addonsv1alpha1.HelmReleaseProxy) { g.Expect(conditions.Has(hrp, addonsv1alpha1.HelmReleaseReadyCondition)).To(BeTrue()) @@ -499,7 +500,7 @@ func TestReconcileDelete(t *testing.T) { name: "error attempting to get Helm release", helmReleaseProxy: defaultProxy.DeepCopy(), clientExpect: func(g *WithT, c *mocks.MockClientMockRecorder) { - c.GetHelmRelease(ctx, kubeconfig, defaultProxy.DeepCopy().Spec).Return(nil, errInternal).Times(1) + c.GetHelmRelease(ctx, restConfig, defaultProxy.DeepCopy().Spec).Return(nil, errInternal).Times(1) }, expect: func(g *WithT, hrp *addonsv1alpha1.HelmReleaseProxy) { g.Expect(conditions.Has(hrp, addonsv1alpha1.HelmReleaseReadyCondition)).To(BeTrue()) @@ -530,7 +531,7 @@ func TestReconcileDelete(t *testing.T) { Build(), } - err := r.reconcileDelete(ctx, tc.helmReleaseProxy, clientMock, kubeconfig) + err := r.reconcileDelete(ctx, tc.helmReleaseProxy, clientMock, restConfig) if tc.expectedError != "" { g.Expect(err).To(HaveOccurred()) g.Expect(err).To(MatchError(tc.expectedError), err.Error()) diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 5fc636ed..3bc35240 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -50,13 +50,12 @@ import ( // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. var ( - k8sClient client.Client - testEnv *envtest.Environment - k8sManager manager.Manager - ctx context.Context - cancel context.CancelFunc - helmClient *mocks.MockClient - kubeconfigGetter *mocks.MockGetter + k8sClient client.Client + testEnv *envtest.Environment + k8sManager manager.Manager + ctx context.Context + cancel context.CancelFunc + helmClient *mocks.MockClient ) const ( @@ -64,7 +63,7 @@ const ( interval = time.Millisecond * 250 ) -func TestAPIs(t *testing.T) { +func TestControllers(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "Controller Suite") @@ -128,12 +127,10 @@ var _ = BeforeSuite(func() { Expect(k8sClient).NotTo(BeNil()) helmClient = mocks.NewMockClient(gomock.NewController(&TestReporter{})) - kubeconfigGetter = mocks.NewMockGetter(gomock.NewController(&TestReporter{})) - kubeconfigGetter.EXPECT().GetClusterKubeconfig(gomock.Any(), client.ObjectKeyFromObject(cluster1)).Return(kubeconfig, nil).AnyTimes() - helmClient.EXPECT().InstallOrUpgradeHelmRelease(gomock.Any(), kubeconfig, gomock.Any(), gomock.Any(), gomock.Any()).Return(helmReleaseDeployed, nil).AnyTimes() - helmClient.EXPECT().UninstallHelmRelease(gomock.Any(), kubeconfig, gomock.Any()).Return(&helmRelease.UninstallReleaseResponse{}, nil).AnyTimes() - helmClient.EXPECT().GetHelmRelease(gomock.Any(), kubeconfig, gomock.Any()).Return(&helmRelease.Release{}, nil).AnyTimes() + helmClient.EXPECT().InstallOrUpgradeHelmRelease(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(helmReleaseDeployed, nil).AnyTimes() + helmClient.EXPECT().UninstallHelmRelease(gomock.Any(), gomock.Any(), gomock.Any()).Return(&helmRelease.UninstallReleaseResponse{}, nil).AnyTimes() + helmClient.EXPECT().GetHelmRelease(gomock.Any(), gomock.Any(), gomock.Any()).Return(&helmRelease.Release{}, nil).AnyTimes() err = (&helmchartproxy.HelmChartProxyReconciler{ Client: k8sManager.GetClient(), @@ -142,10 +139,9 @@ var _ = BeforeSuite(func() { Expect(err).ToNot(HaveOccurred()) err = (&helmreleaseproxy.HelmReleaseProxyReconciler{ - Client: k8sManager.GetClient(), - Scheme: k8sManager.GetScheme(), - KubeconfigGetter: kubeconfigGetter, - HelmClient: helmClient, + Client: k8sManager.GetClient(), + Scheme: k8sManager.GetScheme(), + HelmClient: helmClient, }).SetupWithManager(ctx, k8sManager, controller.Options{}) Expect(err).ToNot(HaveOccurred()) diff --git a/internal/helm_client.go b/internal/helm_client.go index 734773ee..ea47d91e 100644 --- a/internal/helm_client.go +++ b/internal/helm_client.go @@ -37,7 +37,6 @@ import ( helmDriver "helm.sh/helm/v3/pkg/storage/driver" "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/client-go/rest" - "k8s.io/client-go/tools/clientcmd" "k8s.io/klog/v2" "k8s.io/utils/ptr" addonsv1alpha1 "sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1" @@ -45,9 +44,9 @@ import ( ) type Client interface { - InstallOrUpgradeHelmRelease(ctx context.Context, kubeconfig string, credentialsPath, caFilePath string, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.Release, error) - GetHelmRelease(ctx context.Context, kubeconfig string, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.Release, error) - UninstallHelmRelease(ctx context.Context, kubeconfig string, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.UninstallReleaseResponse, error) + InstallOrUpgradeHelmRelease(ctx context.Context, restConfig *rest.Config, credentialsPath, caFilePath string, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.Release, error) + GetHelmRelease(ctx context.Context, restConfig *rest.Config, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.Release, error) + UninstallHelmRelease(ctx context.Context, restConfig *rest.Config, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.UninstallReleaseResponse, error) } type HelmClient struct{} @@ -57,17 +56,6 @@ func GetActionConfig(ctx context.Context, namespace string, config *rest.Config) log := ctrl.LoggerFrom(ctx) log.V(4).Info("Getting action config") actionConfig := new(helmAction.Configuration) - // var cliConfig *genericclioptions.ConfigFlags - // cliConfig := &genericclioptions.ConfigFlags{ - // Namespace: &env.namespace, - // Context: &env.KubeContext, - // BearerToken: &env.KubeToken, - // APIServer: &env.KubeAPIServer, - // CAFile: &env.KubeCaFile, - // KubeConfig: &env.KubeConfig, - // Impersonate: &env.KubeAsUser, - // ImpersonateGroup: &env.KubeAsGroups, - // } insecure := true cliConfig := genericclioptions.NewConfigFlags(false) cliConfig.APIServer = &config.Host @@ -89,33 +77,22 @@ func GetActionConfig(ctx context.Context, namespace string, config *rest.Config) } // HelmInit initializes Helm. -func HelmInit(ctx context.Context, namespace string, kubeconfig string) (*helmCli.EnvSettings, *helmAction.Configuration, error) { +func HelmInit(ctx context.Context, namespace string, restConfig *rest.Config) (*helmCli.EnvSettings, *helmAction.Configuration, error) { // log := ctrl.LoggerFrom(ctx) settings := helmCli.New() - restConfig, err := clientcmd.RESTConfigFromKubeConfig([]byte(kubeconfig)) - if err != nil { - return nil, nil, err - } - actionConfig, err := GetActionConfig(ctx, namespace, restConfig) if err != nil { return nil, nil, err } - // settings.KubeConfig = kubeconfig - // actionConfig := new(helmAction.Configuration) - // if err := actionConfig.Init(settings.RESTClientGetter(), "default", "secret", logf); err != nil { - // return nil, nil, err - // } - return settings, actionConfig, nil } // InstallOrUpgradeHelmRelease installs a Helm release if it does not exist, or upgrades it if it does and differs from the spec. // It returns a boolean indicating whether an install or upgrade was performed. -func (c *HelmClient) InstallOrUpgradeHelmRelease(ctx context.Context, kubeconfig string, credentialsPath, caFilePath string, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.Release, error) { +func (c *HelmClient) InstallOrUpgradeHelmRelease(ctx context.Context, restConfig *rest.Config, credentialsPath, caFilePath string, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.Release, error) { log := ctrl.LoggerFrom(ctx) log.V(2).Info("Installing or upgrading Helm release") @@ -123,16 +100,16 @@ func (c *HelmClient) InstallOrUpgradeHelmRelease(ctx context.Context, kubeconfig // historyClient := helmAction.NewHistory(actionConfig) // historyClient.Max = 1 // if _, err := historyClient.Run(spec.ReleaseName); err == helmDriver.ErrReleaseNotFound { - existingRelease, err := c.GetHelmRelease(ctx, kubeconfig, spec) + existingRelease, err := c.GetHelmRelease(ctx, restConfig, spec) if err != nil { if errors.Is(err, helmDriver.ErrReleaseNotFound) { - return c.InstallHelmRelease(ctx, kubeconfig, credentialsPath, caFilePath, spec) + return c.InstallHelmRelease(ctx, restConfig, credentialsPath, caFilePath, spec) } return nil, err } - return c.UpgradeHelmReleaseIfChanged(ctx, kubeconfig, credentialsPath, caFilePath, spec, existingRelease) + return c.UpgradeHelmReleaseIfChanged(ctx, restConfig, credentialsPath, caFilePath, spec, existingRelease) } // generateHelmInstallConfig generates default helm install config using helmOptions specified in HCP CR spec. @@ -192,10 +169,10 @@ func generateHelmUpgradeConfig(actionConfig *helmAction.Configuration, helmOptio } // InstallHelmRelease installs a Helm release. -func (c *HelmClient) InstallHelmRelease(ctx context.Context, kubeconfig string, credentialsPath, caFilePath string, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.Release, error) { +func (c *HelmClient) InstallHelmRelease(ctx context.Context, restConfig *rest.Config, credentialsPath, caFilePath string, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.Release, error) { log := ctrl.LoggerFrom(ctx) - settings, actionConfig, err := HelmInit(ctx, spec.ReleaseNamespace, kubeconfig) + settings, actionConfig, err := HelmInit(ctx, spec.ReleaseNamespace, restConfig) if err != nil { return nil, err } @@ -312,10 +289,10 @@ func getHelmChartAndRepoName(chartName, repoURL string) (string, string, error) } // UpgradeHelmReleaseIfChanged upgrades a Helm release. The boolean refers to if an upgrade was attempted. -func (c *HelmClient) UpgradeHelmReleaseIfChanged(ctx context.Context, kubeconfig string, credentialsPath, caFilePath string, spec addonsv1alpha1.HelmReleaseProxySpec, existing *helmRelease.Release) (*helmRelease.Release, error) { +func (c *HelmClient) UpgradeHelmReleaseIfChanged(ctx context.Context, restConfig *rest.Config, credentialsPath, caFilePath string, spec addonsv1alpha1.HelmReleaseProxySpec, existing *helmRelease.Release) (*helmRelease.Release, error) { log := ctrl.LoggerFrom(ctx) - settings, actionConfig, err := HelmInit(ctx, spec.ReleaseNamespace, kubeconfig) + settings, actionConfig, err := HelmInit(ctx, spec.ReleaseNamespace, restConfig) if err != nil { return nil, err } @@ -451,12 +428,12 @@ func shouldUpgradeHelmRelease(ctx context.Context, existing helmRelease.Release, } // GetHelmRelease returns a Helm release if it exists. -func (c *HelmClient) GetHelmRelease(ctx context.Context, kubeconfig string, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.Release, error) { +func (c *HelmClient) GetHelmRelease(ctx context.Context, restConfig *rest.Config, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.Release, error) { if spec.ReleaseName == "" { return nil, helmDriver.ErrReleaseNotFound } - _, actionConfig, err := HelmInit(ctx, spec.ReleaseNamespace, kubeconfig) + _, actionConfig, err := HelmInit(ctx, spec.ReleaseNamespace, restConfig) if err != nil { return nil, err } @@ -470,8 +447,8 @@ func (c *HelmClient) GetHelmRelease(ctx context.Context, kubeconfig string, spec } // ListHelmReleases lists all Helm releases in a namespace. -func (c *HelmClient) ListHelmReleases(ctx context.Context, kubeconfig string, spec addonsv1alpha1.HelmReleaseProxySpec) ([]*helmRelease.Release, error) { - _, actionConfig, err := HelmInit(ctx, spec.ReleaseNamespace, kubeconfig) +func (c *HelmClient) ListHelmReleases(ctx context.Context, restConfig *rest.Config, spec addonsv1alpha1.HelmReleaseProxySpec) ([]*helmRelease.Release, error) { + _, actionConfig, err := HelmInit(ctx, spec.ReleaseNamespace, restConfig) if err != nil { return nil, err } @@ -506,8 +483,8 @@ func generateHelmUninstallConfig(actionConfig *helmAction.Configuration, helmOpt } // UninstallHelmRelease uninstalls a Helm release. -func (c *HelmClient) UninstallHelmRelease(ctx context.Context, kubeconfig string, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.UninstallReleaseResponse, error) { - _, actionConfig, err := HelmInit(ctx, spec.ReleaseNamespace, kubeconfig) +func (c *HelmClient) UninstallHelmRelease(ctx context.Context, restConfig *rest.Config, spec addonsv1alpha1.HelmReleaseProxySpec) (*helmRelease.UninstallReleaseResponse, error) { + _, actionConfig, err := HelmInit(ctx, spec.ReleaseNamespace, restConfig) if err != nil { return nil, err } @@ -523,8 +500,8 @@ func (c *HelmClient) UninstallHelmRelease(ctx context.Context, kubeconfig string } // RollbackHelmRelease rolls back a Helm release. -func (c *HelmClient) RollbackHelmRelease(ctx context.Context, kubeconfig string, spec addonsv1alpha1.HelmReleaseProxySpec) error { - _, actionConfig, err := HelmInit(ctx, spec.ReleaseNamespace, kubeconfig) +func (c *HelmClient) RollbackHelmRelease(ctx context.Context, restConfig *rest.Config, spec addonsv1alpha1.HelmReleaseProxySpec) error { + _, actionConfig, err := HelmInit(ctx, spec.ReleaseNamespace, restConfig) if err != nil { return err } diff --git a/internal/kubeconfig.go b/internal/kubeconfig.go deleted file mode 100644 index 7d30643b..00000000 --- a/internal/kubeconfig.go +++ /dev/null @@ -1,154 +0,0 @@ -/* -Copyright 2022 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package internal - -import ( - "context" - "os" - "path/filepath" - - "github.com/pkg/errors" - "k8s.io/client-go/rest" - "k8s.io/client-go/tools/clientcmd" - clientcmdapi "k8s.io/client-go/tools/clientcmd/api" - "sigs.k8s.io/cluster-api/cmd/clusterctl/client" - "sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster" - ctrl "sigs.k8s.io/controller-runtime" - ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" - configclient "sigs.k8s.io/controller-runtime/pkg/client/config" -) - -type Getter interface { - GetClusterKubeconfig(ctx context.Context, clusterKey ctrlclient.ObjectKey) (string, error) -} - -type KubeconfigGetter struct{} - -// GetClusterKubeconfig returns the kubeconfig for a selected Cluster as a string. -func (k *KubeconfigGetter) GetClusterKubeconfig(ctx context.Context, clusterKey ctrlclient.ObjectKey) (string, error) { - log := ctrl.LoggerFrom(ctx) - - log.V(2).Info("Initializing management cluster kubeconfig") - managementKubeconfig, err := initInClusterKubeconfig(ctx) - if err != nil { - return "", errors.Wrapf(err, "failed to initialize management cluster kubeconfig") - } - - c, err := client.New(ctx, "") - if err != nil { - return "", err - } - - options := client.GetKubeconfigOptions{ - Kubeconfig: client.Kubeconfig(*managementKubeconfig), - WorkloadClusterName: clusterKey.Name, - Namespace: clusterKey.Namespace, - } - - log.V(4).Info("Getting kubeconfig for cluster", "cluster", clusterKey.Name) - kubeconfig, err := c.GetKubeconfig(ctx, options) - if err != nil { - return "", err - } - - return kubeconfig, nil -} - -// initInClusterKubeconfig generates a kubeconfig file for the management cluster. -// Note: The k8s.io/client-go/tools/clientcmd/api package and associated tools require a path to a kubeconfig file rather than the data stored in an object. -func initInClusterKubeconfig(ctx context.Context) (*cluster.Kubeconfig, error) { - log := ctrl.LoggerFrom(ctx) - - log.V(2).Info("Generating kubeconfig file") - restConfig := configclient.GetConfigOrDie() - - apiConfig := constructInClusterKubeconfig(ctx, restConfig, "") - - filePath := "tmp/management.kubeconfig" - if err := writeInClusterKubeconfigToFile(ctx, filePath, *apiConfig); err != nil { - log.Error(err, "error writing kubeconfig to file") - return nil, err - } - kubeconfigPath := filePath - kubeContext := apiConfig.CurrentContext - - return &cluster.Kubeconfig{Path: kubeconfigPath, Context: kubeContext}, nil -} - -// GetClusterKubeconfig generates a kubeconfig file for the management cluster using a rest.Config. This is a bit of a workaround -// since the k8s.io/client-go/tools/clientcmd/api expects to be run from a CLI context, but within a pod we don't have that. -// As a result, we have to manually fill in the fields that would normally be present in ~/.kube/config. This seems to work for now. -func constructInClusterKubeconfig(ctx context.Context, restConfig *rest.Config, namespace string) *clientcmdapi.Config { - log := ctrl.LoggerFrom(ctx) - - log.V(2).Info("Constructing kubeconfig file from rest.Config") - - clusterName := "management-cluster" - userName := "default-user" - contextName := "default-context" - clusters := make(map[string]*clientcmdapi.Cluster) - clusters[clusterName] = &clientcmdapi.Cluster{ - Server: restConfig.Host, - // Used in regular kubeconfigs. - CertificateAuthorityData: restConfig.CAData, - // Used in in-cluster configs. - CertificateAuthority: restConfig.CAFile, - } - - contexts := make(map[string]*clientcmdapi.Context) - contexts[contextName] = &clientcmdapi.Context{ - Cluster: clusterName, - Namespace: namespace, - AuthInfo: userName, - } - - authInfos := make(map[string]*clientcmdapi.AuthInfo) - authInfos[userName] = &clientcmdapi.AuthInfo{ - Token: restConfig.BearerToken, - ClientCertificateData: restConfig.TLSClientConfig.CertData, - ClientKeyData: restConfig.TLSClientConfig.KeyData, - } - - return &clientcmdapi.Config{ - Kind: "Config", - APIVersion: "v1", - Clusters: clusters, - Contexts: contexts, - CurrentContext: contextName, - AuthInfos: authInfos, - } -} - -// writeInClusterKubeconfigToFile writes the clientcmdapi.Config to a kubeconfig file. -func writeInClusterKubeconfigToFile(ctx context.Context, filePath string, clientConfig clientcmdapi.Config) error { - log := ctrl.LoggerFrom(ctx) - - dir := filepath.Dir(filePath) - if _, err := os.Stat(dir); errors.Is(err, os.ErrNotExist) { - err := os.Mkdir(dir, os.ModePerm) - if err != nil { - return errors.Wrapf(err, "failed to create directory %s", dir) - } - } - - log.V(2).Info("Writing kubeconfig to location", "location", filePath) - if err := clientcmd.WriteToFile(clientConfig, filePath); err != nil { - return err - } - - return nil -} diff --git a/internal/mocks/doc.go b/internal/mocks/doc.go index 8f954721..8f5579de 100644 --- a/internal/mocks/doc.go +++ b/internal/mocks/doc.go @@ -17,7 +17,5 @@ limitations under the License. // Run go generate to regenerate this mock. // //go:generate ../../hack/tools/bin/mockgen -destination helm_client_mock.go -package mocks -source ../helm_client.go Client -//go:generate ../../hack/tools/bin/mockgen -destination kubeconfig_mock.go -package mocks -source ../kubeconfig.go Getter //go:generate /usr/bin/env bash -c "cat ../../hack/boilerplate/boilerplate.generatego.txt helm_client_mock.go > _helm_client_mock.go && mv _helm_client_mock.go helm_client_mock.go" -//go:generate /usr/bin/env bash -c "cat ../../hack/boilerplate/boilerplate.generatego.txt kubeconfig_mock.go > _kubeconfig_mock.go && mv _kubeconfig_mock.go kubeconfig_mock.go" package mocks diff --git a/internal/mocks/helm_client_mock.go b/internal/mocks/helm_client_mock.go index 9740dfeb..5ed6559b 100644 --- a/internal/mocks/helm_client_mock.go +++ b/internal/mocks/helm_client_mock.go @@ -30,6 +30,7 @@ import ( gomock "go.uber.org/mock/gomock" release "helm.sh/helm/v3/pkg/release" + rest "k8s.io/client-go/rest" v1alpha1 "sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1" ) @@ -57,46 +58,46 @@ func (m *MockClient) EXPECT() *MockClientMockRecorder { } // GetHelmRelease mocks base method. -func (m *MockClient) GetHelmRelease(ctx context.Context, kubeconfig string, spec v1alpha1.HelmReleaseProxySpec) (*release.Release, error) { +func (m *MockClient) GetHelmRelease(ctx context.Context, restConfig *rest.Config, spec v1alpha1.HelmReleaseProxySpec) (*release.Release, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetHelmRelease", ctx, kubeconfig, spec) + ret := m.ctrl.Call(m, "GetHelmRelease", ctx, restConfig, spec) ret0, _ := ret[0].(*release.Release) ret1, _ := ret[1].(error) return ret0, ret1 } // GetHelmRelease indicates an expected call of GetHelmRelease. -func (mr *MockClientMockRecorder) GetHelmRelease(ctx, kubeconfig, spec any) *gomock.Call { +func (mr *MockClientMockRecorder) GetHelmRelease(ctx, restConfig, spec any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHelmRelease", reflect.TypeOf((*MockClient)(nil).GetHelmRelease), ctx, kubeconfig, spec) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetHelmRelease", reflect.TypeOf((*MockClient)(nil).GetHelmRelease), ctx, restConfig, spec) } // InstallOrUpgradeHelmRelease mocks base method. -func (m *MockClient) InstallOrUpgradeHelmRelease(ctx context.Context, kubeconfig, credentialsPath, caFilePath string, spec v1alpha1.HelmReleaseProxySpec) (*release.Release, error) { +func (m *MockClient) InstallOrUpgradeHelmRelease(ctx context.Context, restConfig *rest.Config, credentialsPath, caFilePath string, spec v1alpha1.HelmReleaseProxySpec) (*release.Release, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InstallOrUpgradeHelmRelease", ctx, kubeconfig, credentialsPath, caFilePath, spec) + ret := m.ctrl.Call(m, "InstallOrUpgradeHelmRelease", ctx, restConfig, credentialsPath, caFilePath, spec) ret0, _ := ret[0].(*release.Release) ret1, _ := ret[1].(error) return ret0, ret1 } // InstallOrUpgradeHelmRelease indicates an expected call of InstallOrUpgradeHelmRelease. -func (mr *MockClientMockRecorder) InstallOrUpgradeHelmRelease(ctx, kubeconfig, credentialsPath, caFilePath, spec any) *gomock.Call { +func (mr *MockClientMockRecorder) InstallOrUpgradeHelmRelease(ctx, restConfig, credentialsPath, caFilePath, spec any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InstallOrUpgradeHelmRelease", reflect.TypeOf((*MockClient)(nil).InstallOrUpgradeHelmRelease), ctx, kubeconfig, credentialsPath, caFilePath, spec) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InstallOrUpgradeHelmRelease", reflect.TypeOf((*MockClient)(nil).InstallOrUpgradeHelmRelease), ctx, restConfig, credentialsPath, caFilePath, spec) } // UninstallHelmRelease mocks base method. -func (m *MockClient) UninstallHelmRelease(ctx context.Context, kubeconfig string, spec v1alpha1.HelmReleaseProxySpec) (*release.UninstallReleaseResponse, error) { +func (m *MockClient) UninstallHelmRelease(ctx context.Context, restConfig *rest.Config, spec v1alpha1.HelmReleaseProxySpec) (*release.UninstallReleaseResponse, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UninstallHelmRelease", ctx, kubeconfig, spec) + ret := m.ctrl.Call(m, "UninstallHelmRelease", ctx, restConfig, spec) ret0, _ := ret[0].(*release.UninstallReleaseResponse) ret1, _ := ret[1].(error) return ret0, ret1 } // UninstallHelmRelease indicates an expected call of UninstallHelmRelease. -func (mr *MockClientMockRecorder) UninstallHelmRelease(ctx, kubeconfig, spec any) *gomock.Call { +func (mr *MockClientMockRecorder) UninstallHelmRelease(ctx, restConfig, spec any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UninstallHelmRelease", reflect.TypeOf((*MockClient)(nil).UninstallHelmRelease), ctx, kubeconfig, spec) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UninstallHelmRelease", reflect.TypeOf((*MockClient)(nil).UninstallHelmRelease), ctx, restConfig, spec) } diff --git a/internal/mocks/kubeconfig_mock.go b/internal/mocks/kubeconfig_mock.go deleted file mode 100644 index 1db35745..00000000 --- a/internal/mocks/kubeconfig_mock.go +++ /dev/null @@ -1,71 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -// Code generated by MockGen. DO NOT EDIT. -// Source: ../kubeconfig.go -// -// Generated by this command: -// -// mockgen -destination kubeconfig_mock.go -package mocks -source ../kubeconfig.go Getter -// - -// Package mocks is a generated GoMock package. -package mocks - -import ( - context "context" - reflect "reflect" - - gomock "go.uber.org/mock/gomock" - client "sigs.k8s.io/controller-runtime/pkg/client" -) - -// MockGetter is a mock of Getter interface. -type MockGetter struct { - ctrl *gomock.Controller - recorder *MockGetterMockRecorder -} - -// MockGetterMockRecorder is the mock recorder for MockGetter. -type MockGetterMockRecorder struct { - mock *MockGetter -} - -// NewMockGetter creates a new mock instance. -func NewMockGetter(ctrl *gomock.Controller) *MockGetter { - mock := &MockGetter{ctrl: ctrl} - mock.recorder = &MockGetterMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockGetter) EXPECT() *MockGetterMockRecorder { - return m.recorder -} - -// GetClusterKubeconfig mocks base method. -func (m *MockGetter) GetClusterKubeconfig(ctx context.Context, clusterKey client.ObjectKey) (string, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetClusterKubeconfig", ctx, clusterKey) - ret0, _ := ret[0].(string) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetClusterKubeconfig indicates an expected call of GetClusterKubeconfig. -func (mr *MockGetterMockRecorder) GetClusterKubeconfig(ctx, clusterKey any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetClusterKubeconfig", reflect.TypeOf((*MockGetter)(nil).GetClusterKubeconfig), ctx, clusterKey) -} diff --git a/main.go b/main.go index 6d13c144..ce35424b 100644 --- a/main.go +++ b/main.go @@ -194,7 +194,6 @@ func main() { if err = (&releasecontroller.HelmReleaseProxyReconciler{ Client: mgr.GetClient(), Scheme: scheme, - KubeconfigGetter: &internal.KubeconfigGetter{}, HelmClient: &internal.HelmClient{}, WatchFilterValue: watchFilterValue, }).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: helmReleaseProxyConcurrency}); err != nil {