From 5c29595cb63b6a72d29783412f1914c0ee9b830c Mon Sep 17 00:00:00 2001 From: Vandana Pathak Date: Thu, 4 May 2023 03:51:35 -0700 Subject: [PATCH] Implement packages installation APIs for cluster essential Signed-off-by: Vandana Pathak --- cluster-essentials/go.mod | 2 +- cluster-essentials/pkg/client/install.go | 10 +++++----- cluster-essentials/pkg/client/install_test.go | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cluster-essentials/go.mod b/cluster-essentials/go.mod index 9f499ed53d..500187e97d 100644 --- a/cluster-essentials/go.mod +++ b/cluster-essentials/go.mod @@ -6,7 +6,6 @@ require ( github.com/cppforlife/go-cli-ui v0.0.0-20200716203538-1e47f820817f github.com/k14s/kbld v0.32.0 github.com/otiai10/copy v1.0.2 - github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.0 github.com/vmware-tanzu/carvel-imgpkg v0.23.1 github.com/vmware-tanzu/carvel-ytt v0.40.0 @@ -69,6 +68,7 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.0.2-0.20210730191737-8e42a01fb1b7 // indirect + github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/sirupsen/logrus v1.8.1 // indirect diff --git a/cluster-essentials/pkg/client/install.go b/cluster-essentials/pkg/client/install.go index 34e4ce3160..785ae553c4 100644 --- a/cluster-essentials/pkg/client/install.go +++ b/cluster-essentials/pkg/client/install.go @@ -21,7 +21,7 @@ import ( var downloadBundles = downloadBundle var applyResourcesFromManifests = applyResourcesFromManifest -var createClientSet = createClientset +var createClientConfig = createClientconfig const defaultBundleDir = "/tmp" const defaultTimeout = 15 * time.Minute @@ -30,12 +30,12 @@ const versionAnnotation = "runtime.tanzu.vmware.com/cluster-essential-vesion" var clusterEssentialPackages = []string{"kapp-controller", "secretgen-controller"} -func createClientset(restConfig *rest.Config) (c client.Client, err error) { - clientSet, err := client.New(restConfig, client.Options{}) +func createClientconfig(restConfig *rest.Config) (c client.Client, err error) { + clientConfig, err := client.New(restConfig, client.Options{}) if err != nil { return nil, err } - return clientSet, nil + return clientConfig, nil } func validatePreInstall(ctx context.Context, clientset client.Client, upgradeVersion string) error { @@ -127,7 +127,7 @@ func Install(ctx context.Context, config *rest.Config, clusterEssentialRepo, clu return fmt.Errorf("unable to download cluster essential manifest: %w", err) } - clientSet, err := createClientSet(config) + clientSet, err := createClientConfig(config) if err != nil { return err } diff --git a/cluster-essentials/pkg/client/install_test.go b/cluster-essentials/pkg/client/install_test.go index 98fdd8c6ec..0a55cd733e 100644 --- a/cluster-essentials/pkg/client/install_test.go +++ b/cluster-essentials/pkg/client/install_test.go @@ -94,14 +94,14 @@ func Test_Install(t *testing.T) { }) t.Run("fails when unable to process downloaded cluster essential bundle ", func(t *testing.T) { downloadBundles = downloadCorruptedBundleSuccess - createClientSet = createMockClientSet + createClientConfig = createMockClientSet err := Install(ctx, config, clusterEssentialRepo, clusterEssentialVersion, 0) require.Error(t, err) require.ErrorContains(t, err, "unable to process carvel package") }) t.Run("fails when unable to load kubeconfig ", func(t *testing.T) { downloadBundles = downloadBundleSuccess - createClientSet = createMockClientSet + createClientConfig = createMockClientSet err := Install(ctx, config, clusterEssentialRepo, clusterEssentialVersion, 0) require.Error(t, err) require.ErrorContains(t, err, "failed to load kubeconfig") @@ -109,7 +109,7 @@ func Test_Install(t *testing.T) { t.Run("succeeds when API successfully able to install cluster essential packages", func(t *testing.T) { downloadBundles = downloadBundleSuccess applyResourcesFromManifests = applyResourcesFromManifestSuccess - createClientSet = createMockClientSet + createClientConfig = createMockClientSet err := Install(ctx, config, clusterEssentialRepo, clusterEssentialVersion, 0) require.NoError(t, err) })