From edcba80c7ffa66155f13c81c97b48e6f1ac49a15 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Fri, 21 Jun 2024 09:15:59 +0530 Subject: [PATCH 1/9] bump(ksctl)!: to release v1.2.3 Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- cli/cmd/addNodesHAAws.go | 6 ++-- cli/cmd/addNodesHAAzure.go | 6 ++-- cli/cmd/addNodesHACivo.go | 6 ++-- cli/cmd/credentials.go | 6 ++-- cli/cmd/deleteNodesHAAws.go | 6 ++-- cli/cmd/deleteNodesHAAzure.go | 6 ++-- cli/cmd/deleteNodesHACivo.go | 6 ++-- cli/cmd/featureFlags.go | 2 +- cli/cmd/flags.go | 1 + cli/cmd/getCluster.go | 4 +-- cli/cmd/infoCluster.go | 66 +++++++++++++++++++++++++++++++++++ cli/cmd/root.go | 2 +- cli/cmd/switchCluster.go | 4 +-- cli/cmd/utils.go | 25 ++++++------- go.mod | 15 ++++---- go.sum | 36 +++++++++---------- logger/general_logging.go | 56 ++++++++++------------------- 17 files changed, 150 insertions(+), 103 deletions(-) create mode 100644 cli/cmd/infoCluster.go diff --git a/cli/cmd/addNodesHAAws.go b/cli/cmd/addNodesHAAws.go index 3e58a9d..98681f1 100644 --- a/cli/cmd/addNodesHAAws.go +++ b/cli/cmd/addNodesHAAws.go @@ -39,7 +39,7 @@ ksctl create ha-aws add-nodes -n demo -r ap-south-1 -s store-local --noWP 3 --no cli.Client.Metadata.StateLocation = consts.KsctlStore(storage) if err := createApproval(ctx, log, cmd.Flags().Lookup("yes").Changed); err != nil { - log.Error(ctx, "createApproval", "Reason", err) + log.Error("createApproval", "Reason", err) os.Exit(1) } @@ -49,13 +49,13 @@ ksctl create ha-aws add-nodes -n demo -r ap-south-1 -s store-local --noWP 3 --no &cli.Client, ) if err != nil { - log.Error(ctx, "Failed to init manager", "Reason", err) + log.Error("Failed to init manager", "Reason", err) os.Exit(1) } err = m.AddWorkerPlaneNodes() if err != nil { - log.Error(ctx, "Failed to scale up", "Reason", err) + log.Error("Failed to scale up", "Reason", err) os.Exit(1) } log.Success(ctx, "Scale up successful") diff --git a/cli/cmd/addNodesHAAzure.go b/cli/cmd/addNodesHAAzure.go index a29b51e..ed04fff 100644 --- a/cli/cmd/addNodesHAAzure.go +++ b/cli/cmd/addNodesHAAzure.go @@ -39,7 +39,7 @@ ksctl create ha-azure add-nodes -n demo -r eastus -s store-local --noWP 3 --node cli.Client.Metadata.StateLocation = consts.KsctlStore(storage) if err := createApproval(ctx, log, cmd.Flags().Lookup("yes").Changed); err != nil { - log.Error(ctx, "createApproval", "Reason", err) + log.Error("createApproval", "Reason", err) os.Exit(1) } @@ -49,13 +49,13 @@ ksctl create ha-azure add-nodes -n demo -r eastus -s store-local --noWP 3 --node &cli.Client, ) if err != nil { - log.Error(ctx, "Failed to init manager", "Reason", err) + log.Error("Failed to init manager", "Reason", err) os.Exit(1) } err = m.AddWorkerPlaneNodes() if err != nil { - log.Error(ctx, "Failed to scale up", "Reason", err) + log.Error("Failed to scale up", "Reason", err) os.Exit(1) } log.Success(ctx, "Scale up successful") diff --git a/cli/cmd/addNodesHACivo.go b/cli/cmd/addNodesHACivo.go index c7ee589..8d8ac28 100644 --- a/cli/cmd/addNodesHACivo.go +++ b/cli/cmd/addNodesHACivo.go @@ -39,7 +39,7 @@ ksctl create ha-civo add-nodes -n demo -r LON1 -s store-local --noWP 3 --nodeSiz cli.Client.Metadata.StateLocation = consts.KsctlStore(storage) if err := createApproval(ctx, log, cmd.Flags().Lookup("yes").Changed); err != nil { - log.Error(ctx, "createApproval", "Reason", err) + log.Error("createApproval", "Reason", err) os.Exit(1) } @@ -49,13 +49,13 @@ ksctl create ha-civo add-nodes -n demo -r LON1 -s store-local --noWP 3 --nodeSiz &cli.Client, ) if err != nil { - log.Error(ctx, "Failed to init manager", "Reason", err) + log.Error("Failed to init manager", "Reason", err) os.Exit(1) } err = m.AddWorkerPlaneNodes() if err != nil { - log.Error(ctx, "Failed to scale up", "Reason", err) + log.Error("Failed to scale up", "Reason", err) os.Exit(1) } log.Success(ctx, "Scale up successful") diff --git a/cli/cmd/credentials.go b/cli/cmd/credentials.go index 638dacb..62909cd 100644 --- a/cli/cmd/credentials.go +++ b/cli/cmd/credentials.go @@ -40,7 +40,7 @@ var credCmd = &cobra.Command{ if provider, ok := cloud[choice]; ok { cli.Client.Metadata.Provider = consts.KsctlCloud(provider) } else { - log.Error(ctx, "invalid provider") + log.Error("invalid provider") } m, err := controllers.NewManagerClusterKsctl( ctx, @@ -48,12 +48,12 @@ var credCmd = &cobra.Command{ &cli.Client, ) if err != nil { - log.Error(ctx, "Failed to initialize", "Reason", err) + log.Error("Failed to initialize", "Reason", err) os.Exit(1) } if err := m.Credentials(); err != nil { - log.Error(ctx, "Failed to added the credential", "Reason", err) + log.Error("Failed to added the credential", "Reason", err) os.Exit(1) } log.Success(ctx, "Credentials added successfully") diff --git a/cli/cmd/deleteNodesHAAws.go b/cli/cmd/deleteNodesHAAws.go index 74878e0..6df83a0 100644 --- a/cli/cmd/deleteNodesHAAws.go +++ b/cli/cmd/deleteNodesHAAws.go @@ -36,7 +36,7 @@ ksctl delete ha-aws del-nodes -n demo -r us-east-1 -s store-local --noWP 1 --boo cli.Client.Metadata.StateLocation = consts.KsctlStore(storage) if err := deleteApproval(ctx, log, cmd.Flags().Lookup("yes").Changed); err != nil { - log.Error(ctx, "deleteApproval", "Reason", err) + log.Error("deleteApproval", "Reason", err) os.Exit(1) } @@ -46,13 +46,13 @@ ksctl delete ha-aws del-nodes -n demo -r us-east-1 -s store-local --noWP 1 --boo &cli.Client, ) if err != nil { - log.Error(ctx, "Failed to init manager", "Reason", err) + log.Error("Failed to init manager", "Reason", err) os.Exit(1) } err = m.DelWorkerPlaneNodes() if err != nil { - log.Error(ctx, "Failed to scale down", "Reason", err) + log.Error("Failed to scale down", "Reason", err) os.Exit(1) } log.Success(ctx, "Scale down successful") diff --git a/cli/cmd/deleteNodesHAAzure.go b/cli/cmd/deleteNodesHAAzure.go index 477b16d..d8d11a4 100644 --- a/cli/cmd/deleteNodesHAAzure.go +++ b/cli/cmd/deleteNodesHAAzure.go @@ -36,7 +36,7 @@ ksctl delete ha-azure del-nodes -n demo -r eastus -s store-local --noWP 1 --boot cli.Client.Metadata.StateLocation = consts.KsctlStore(storage) if err := deleteApproval(ctx, log, cmd.Flags().Lookup("yes").Changed); err != nil { - log.Error(ctx, "deleteApproval", "Reason", err) + log.Error("deleteApproval", "Reason", err) os.Exit(1) } @@ -46,13 +46,13 @@ ksctl delete ha-azure del-nodes -n demo -r eastus -s store-local --noWP 1 --boot &cli.Client, ) if err != nil { - log.Error(ctx, "Failed to init manager", "Reason", err) + log.Error("Failed to init manager", "Reason", err) os.Exit(1) } err = m.DelWorkerPlaneNodes() if err != nil { - log.Error(ctx, "Failed to scale down", "Reason", err) + log.Error("Failed to scale down", "Reason", err) os.Exit(1) } log.Success(ctx, "Scale down successful") diff --git a/cli/cmd/deleteNodesHACivo.go b/cli/cmd/deleteNodesHACivo.go index 18219f3..55b245a 100644 --- a/cli/cmd/deleteNodesHACivo.go +++ b/cli/cmd/deleteNodesHACivo.go @@ -34,7 +34,7 @@ ksctl delete ha-civo del-nodes -n demo -r LON1 -s store-local --noWP 1 --bootstr cli.Client.Metadata.StateLocation = consts.KsctlStore(storage) if err := deleteApproval(ctx, log, cmd.Flags().Lookup("yes").Changed); err != nil { - log.Error(ctx, "deleteApproval", "Reason", err) + log.Error("deleteApproval", "Reason", err) os.Exit(1) } @@ -44,13 +44,13 @@ ksctl delete ha-civo del-nodes -n demo -r LON1 -s store-local --noWP 1 --bootstr &cli.Client, ) if err != nil { - log.Error(ctx, "Failed to init manager", "Reason", err) + log.Error("Failed to init manager", "Reason", err) os.Exit(1) } err = m.DelWorkerPlaneNodes() if err != nil { - log.Error(ctx, "Failed to scale down", "Reason", err) + log.Error("Failed to scale down", "Reason", err) os.Exit(1) } log.Success(ctx, "Scale down successful") diff --git a/cli/cmd/featureFlags.go b/cli/cmd/featureFlags.go index 45fe716..9422700 100644 --- a/cli/cmd/featureFlags.go +++ b/cli/cmd/featureFlags.go @@ -20,7 +20,7 @@ func featureFlag(f *cobra.Command) { func SetRequiredFeatureFlags(ctx context.Context, log types.LoggerFactory, cmd *cobra.Command) { rawFeatures, err := cmd.Flags().GetString("feature-flags") if err != nil { - log.Error(ctx, "Error in setting feature flags", "Reason", err) + log.Error("Error in setting feature flags", "Reason", err) return } features := strings.Split(rawFeatures, ",") diff --git a/cli/cmd/flags.go b/cli/cmd/flags.go index 8fcebd2..528ecda 100644 --- a/cli/cmd/flags.go +++ b/cli/cmd/flags.go @@ -30,6 +30,7 @@ func verboseFlags() { getClusterCmd.Flags().IntP("verbose", "v", 0, msgVerbose) switchCluster.Flags().IntP("verbose", "v", 0, msgVerbose) + infoClusterCmd.Flags().IntP("verbose", "v", 0, msgVerbose) createClusterAzure.Flags().BoolP("yes", "y", true, msgApproval) createClusterCivo.Flags().BoolP("yes", "y", true, msgApproval) diff --git a/cli/cmd/getCluster.go b/cli/cmd/getCluster.go index 360be73..ca61c97 100644 --- a/cli/cmd/getCluster.go +++ b/cli/cmd/getCluster.go @@ -43,13 +43,13 @@ ksctl get-clusters `, &cli.Client, ) if err != nil { - log.Error(ctx, "failed to init", "Reason", err) + log.Error("failed to init", "Reason", err) os.Exit(1) } err = m.GetCluster() if err != nil { - log.Error(ctx, "Get cluster failed", "Reason", err) + log.Error("Get cluster failed", "Reason", err) os.Exit(1) } log.Success(ctx, "Get cluster successfull") diff --git a/cli/cmd/infoCluster.go b/cli/cmd/infoCluster.go new file mode 100644 index 0000000..c3575a0 --- /dev/null +++ b/cli/cmd/infoCluster.go @@ -0,0 +1,66 @@ +package cmd + +import ( + "os" + + "github.com/ksctl/cli/logger" + "github.com/ksctl/ksctl/pkg/controllers" + "github.com/ksctl/ksctl/pkg/types" + + "github.com/ksctl/ksctl/pkg/helpers/consts" + + "github.com/spf13/cobra" +) + +var infoClusterCmd = &cobra.Command{ + Use: "info-cluster", + Aliases: []string{"info"}, + Example: ` +ksctl info --provider azure --name demo --region eastus --storage store-local +`, + Short: "Use to info cluster", + Long: `It is used to detailed data for a given cluster`, + Run: func(cmd *cobra.Command, args []string) { + verbosity, _ := cmd.Flags().GetInt("verbose") + var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout) + + if len(storage) == 0 { + storage = string(consts.StoreLocal) + } + + SetRequiredFeatureFlags(ctx, log, cmd) + cli.Client.Metadata.ClusterName = clusterName + cli.Client.Metadata.Region = region + cli.Client.Metadata.Provider = consts.KsctlCloud(provider) + cli.Client.Metadata.StateLocation = consts.KsctlStore(storage) + + m, err := controllers.NewManagerClusterKsctl( + ctx, + log, + &cli.Client, + ) + if err != nil { + log.Error("failed to init", "Reason", err) + os.Exit(1) + } + + err = m.GetCluster() + if err != nil { + log.Error("info cluster failed", "Reason", err) + os.Exit(1) + } + log.Success(ctx, "Get cluster successfull") + }, +} + +func init() { + RootCmd.AddCommand(infoClusterCmd) + storageFlag(infoClusterCmd) + clusterNameFlag(infoClusterCmd) + regionFlag(infoClusterCmd) + + infoClusterCmd.Flags().StringVarP(&provider, "provider", "p", "", "Provider") + infoClusterCmd.MarkFlagRequired("name") + infoClusterCmd.MarkFlagRequired("region") + infoClusterCmd.MarkFlagRequired("provider") +} diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 6ee3fcb..6853988 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -97,7 +97,7 @@ func Execute() { defer logCli.Print(ctx, "Time Took", "time", time.Since(timer).String()) if err != nil { - logCli.Error(ctx, "Initialization of cli failed", "Reason", err) + logCli.Error("Initialization of cli failed", "Reason", err) os.Exit(1) } } diff --git a/cli/cmd/switchCluster.go b/cli/cmd/switchCluster.go index 6c049d8..0797f39 100644 --- a/cli/cmd/switchCluster.go +++ b/cli/cmd/switchCluster.go @@ -71,12 +71,12 @@ ksctl switch-context -s external-store-mongodb -p civo -n -r Date: Fri, 21 Jun 2024 09:32:58 +0530 Subject: [PATCH 2/9] fixed the failing results Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- cli/cmd/infoCluster.go | 5 ++--- cli/cmd/root.go | 2 +- logger/general_logging.go | 10 +++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cli/cmd/infoCluster.go b/cli/cmd/infoCluster.go index c3575a0..5cfb3b4 100644 --- a/cli/cmd/infoCluster.go +++ b/cli/cmd/infoCluster.go @@ -44,12 +44,12 @@ ksctl info --provider azure --name demo --region eastus --storage store-local os.Exit(1) } - err = m.GetCluster() + _, err = m.InfoCluster() if err != nil { log.Error("info cluster failed", "Reason", err) os.Exit(1) } - log.Success(ctx, "Get cluster successfull") + log.Success(ctx, "info cluster successfull") }, } @@ -61,6 +61,5 @@ func init() { infoClusterCmd.Flags().StringVarP(&provider, "provider", "p", "", "Provider") infoClusterCmd.MarkFlagRequired("name") - infoClusterCmd.MarkFlagRequired("region") infoClusterCmd.MarkFlagRequired("provider") } diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 6853988..b0a81b4 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -72,7 +72,7 @@ func Execute() { "cli", ) ctx = context.WithValue( - ctx, "USERID", "cli", + ctx, consts.KsctlContextUserID, "cli", ) if _, ok := os.LookupEnv("KSCTL_FAKE_FLAG_ENABLED"); ok { ctx = context.WithValue( diff --git a/logger/general_logging.go b/logger/general_logging.go index dcf4e43..fcd9f00 100644 --- a/logger/general_logging.go +++ b/logger/general_logging.go @@ -2,6 +2,7 @@ package logger import ( "context" + "encoding/json" "fmt" "io" "math" @@ -11,7 +12,6 @@ import ( box "github.com/Delta456/box-cli-maker/v2" "github.com/fatih/color" - "github.com/gookit/goutil/dump" cloudController "github.com/ksctl/ksctl/pkg/types/controllers/cloud" "github.com/rodaine/table" @@ -180,7 +180,7 @@ func (l *GeneralLog) Table(ctx context.Context, op consts.LogClusterDetail, data columnFmt := color.New(color.FgYellow).SprintfFunc() if op == consts.LoggingGetClusters { - tbl := table.New("ClusterName", "Region", "ClusterType", "CloudProvider", "BootStrap", "NoOfWorkerPlaneNodes", "NoOfControlPlaneNodes", "NoOfEtcdNodes", "NoOfCloudManagedNodes") + tbl := table.New("ClusterName", "Region", "ClusterType", "CloudProvider", "BootStrap", "WorkerPlaneNodes", "ControlPlaneNodes", "EtcdNodes", "CloudManagedNodes") tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt) for _, row := range data { @@ -195,7 +195,11 @@ func (l *GeneralLog) Table(ctx context.Context, op consts.LogClusterDetail, data tbl.Print() } else if op == consts.LoggingInfoCluster { - dump.Println(data) + a, err := json.MarshalIndent(data[0], "", " ") + if err != nil { + panic(err) + } + l.Box(ctx, "Cluster Data", string(a)) } } From a9bee9e41cb9a9a99f4389fb8bd18045e85ccb65 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:00:21 +0530 Subject: [PATCH 3/9] updated the logging unit test Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- logger/logger_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/logger/logger_test.go b/logger/logger_test.go index 856a364..fe76c1a 100644 --- a/logger/logger_test.go +++ b/logger/logger_test.go @@ -47,7 +47,7 @@ func TestPrinters(t *testing.T) { }) t.Run("Error", func(t *testing.T) { - gL.Error(dummyCtx, "FAKE", "type", "error") + gL.Error("FAKE", "type", "error") }) t.Run("Debug", func(t *testing.T) { @@ -64,6 +64,7 @@ func TestPrinters(t *testing.T) { t.Run("Table", func(t *testing.T) { gL.Table(dummyCtx, + consts.LoggingGetClusters, []cloud.AllClusterData{ { Name: "fake-demo", @@ -72,7 +73,7 @@ func TestPrinters(t *testing.T) { }, }) - gL.Table(dummyCtx, nil) + gL.Table(dummyCtx, consts.LoggingGetClusters, nil) }) t.Run("Box", func(t *testing.T) { From b228a41f736516ff9ac9c99b81bdcf11aa90886c Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:14:17 +0530 Subject: [PATCH 4/9] updated the new mock testing Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- .github/workflows/test-mock.yml | 26 ++++++++++++++++++--- Makefile | 21 ++++++++++++++++- cli/cmd/infoCluster.go | 28 ++++++++++++++++++++++- scripts/builder-mock.ps1 | 40 +++++++++++++++++++++++++++++++++ scripts/builder-mock.sh | 16 +++++++++++++ 5 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 scripts/builder-mock.ps1 create mode 100755 scripts/builder-mock.sh diff --git a/.github/workflows/test-mock.yml b/.github/workflows/test-mock.yml index 4c211d7..ae0e3fd 100644 --- a/.github/workflows/test-mock.yml +++ b/.github/workflows/test-mock.yml @@ -51,21 +51,21 @@ jobs: run: | Set-PSDebug -Trace 2 cd .\scripts - .\builder.ps1 + .\builder-mock.ps1 echo "KSCTL_BIN=$env:LOCALAPPDATA\ksctl\ksctl.exe" >> $env:GITHUB_ENV - name: build ksctl linux if: ${{ matrix.os == 'ubuntu-latest' }} run: | set -x - make install_linux + make install_linux_mock echo "KSCTL_BIN=ksctl" >> "${GITHUB_ENV}" - name: build ksctl macos if: ${{ matrix.os == 'macos-latest' }} run: | set -x - make install_macos_intel + make install_macos_intel_mock echo "KSCTL_BIN=ksctl" >> "${GITHUB_ENV}" - name: version @@ -76,29 +76,48 @@ jobs: run: | ${{ env.KSCTL_BIN }} create civo -n demo -r LON1 --nodeSizeMP "g4s.kube.small" --version 1.27.1 --verbose -1 -s store-local --yes + ${{ env.KSCTL_BIN }} info -p civo -n demo -r LON1 --verbose -1 -s store-local + ${{env.KSCTL_BIN}} create ha-civo -n ha-demo-k3s --nodeSizeDS "fake.small" --version 1.27.1 --nodeSizeLB "fake.small" --nodeSizeCP "fake.small" --nodeSizeWP "fake.small" -s store-local -r LON1 --verbose -1 --yes --bootstrap k3s + ${{env.KSCTL_BIN}} info -p ha-civo -n ha-demo-k3s -s store-local -r LON1 --verbose -1 + ${{env.KSCTL_BIN}} create ha-civo -n ha-demo-kubeadm --nodeSizeDS "fake.small" --version 1.28 --nodeSizeLB "fake.small" --nodeSizeCP "fake.small" --nodeSizeWP "fake.small" -s store-local -r LON1 --verbose -1 --yes --bootstrap kubeadm + ${{env.KSCTL_BIN}} info ha-civo -n ha-demo-kubeadm -s store-local -r LON1 --verbose -1 + - name: azure create run: | ${{env.KSCTL_BIN}} create azure -n demo -r fake --nodeSizeMP "fake" -s store-local --version 1.27.1 --verbose -1 --yes + ${{env.KSCTL_BIN}} info -p azure -n demo -r fake -s store-local --verbose -1 + ${{env.KSCTL_BIN}} create ha-azure -n ha-demo-k3s --nodeSizeDS "fake" --version 1.27.1 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s store-local --yes --bootstrap k3s + ${{env.KSCTL_BIN}} info -p ha-azure -n ha-demo-k3s -r fake -s store-local --verbose -1 + ${{env.KSCTL_BIN}} create ha-azure -n ha-demo-kubeadm --nodeSizeDS "fake" --version 1.28 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s store-local --yes --bootstrap kubeadm + ${{env.KSCTL_BIN}} info -p ha-azure -n ha-demo-kubeadm -r fake -s store-local --verbose -1 + - name: aws create run: | # ${{env.KSCTL_BIN}} create aws -n demo -r fake --nodeSizeMP "fake" --version 1.27.1 -s store-local --verbose -1 --yes + #${{env.KSCTL_BIN}} info -p aws -n demo -r fake -s store-local --verbose -1 + ${{env.KSCTL_BIN}} create ha-aws -n ha-demo-k3s --nodeSizeDS "fake" --version 1.27.1 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s store-local --yes --bootstrap k3s + ${{env.KSCTL_BIN}} info -p ha-aws -n ha-demo-k3s -r fake -s store-local --verbose -1 + ${{env.KSCTL_BIN}} create ha-aws -n ha-demo-kubeadm --nodeSizeDS "fake" --version 1.28 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s store-local --yes --bootstrap kubeadm + ${{env.KSCTL_BIN}} info -p ha-aws -n ha-demo-kubeadm -r fake -s store-local --verbose -1 + - name: local create run: | ${{env.KSCTL_BIN}} create local -n demolocal --version 1.27.1 --verbose -1 -s store-local --yes + ${{env.KSCTL_BIN}} info -p local -n demolocal -s store-local --verbose -1 - name: local create mongodb @@ -113,6 +132,7 @@ jobs: mongo export MONGODB_URI="mongodb://root:1234@127.0.0.1:27017" ${{env.KSCTL_BIN}} create local -n demolocal-extmongo -s external-store-mongodb --verbose -1 --yes + ${{env.KSCTL_BIN}} info -p local -n demolocal-extmongo -s external-store-mongodb --verbose -1 - name: civo get run: | diff --git a/Makefile b/Makefile index b895590..dd57b01 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,25 @@ gen-docs: ## Generates docs ##@ Install (Dev) + +.PHONY: install_linux_mock +install_linux_mock: ## Install ksctl + @echo "Started to Install ksctl" + cd scripts && \ + env GOOS=${GOOS_LINUX} GOARCH=${GOARCH_LINUX} ./builder-mock.sh + +.PHONY: install_macos_mock +install_macos_mock: ## Install ksctl on macos m1,m2,.. + @echo "Started to Install ksctl" + cd scripts && \ + env GOOS=${GOOS_MACOS} GOARCH=${GOARCH_MACOS} ./builder-mock.sh + +.PHONY: install_macos_intel_mock +install_macos_intel_mock: ## Install ksctl on macos intel + @echo "Started to Install ksctl" + cd scripts && \ + env GOOS=${GOOS_MACOS} GOARCH=${GOARCH_MACOS_INTEL} ./builder-mock.sh + .PHONY: install_linux install_linux: ## Install ksctl @echo "Started to Install ksctl" @@ -85,4 +104,4 @@ echo "Downloading $${package}" ;\ GOBIN=$(LOCALBIN) go install $${package} ;\ mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\ } -endef \ No newline at end of file +endef diff --git a/cli/cmd/infoCluster.go b/cli/cmd/infoCluster.go index 5cfb3b4..60991a0 100644 --- a/cli/cmd/infoCluster.go +++ b/cli/cmd/infoCluster.go @@ -17,6 +17,7 @@ var infoClusterCmd = &cobra.Command{ Aliases: []string{"info"}, Example: ` ksctl info --provider azure --name demo --region eastus --storage store-local +ksctl info -p ha-azure -n ha-demo-kubeadm -r eastus -s store-local --verbose -1 `, Short: "Use to info cluster", Long: `It is used to detailed data for a given cluster`, @@ -31,9 +32,34 @@ ksctl info --provider azure --name demo --region eastus --storage store-local SetRequiredFeatureFlags(ctx, log, cmd) cli.Client.Metadata.ClusterName = clusterName cli.Client.Metadata.Region = region - cli.Client.Metadata.Provider = consts.KsctlCloud(provider) cli.Client.Metadata.StateLocation = consts.KsctlStore(storage) + switch provider { + case string(consts.CloudLocal): + cli.Client.Metadata.Provider = consts.CloudLocal + + case string(consts.ClusterTypeHa) + "-" + string(consts.CloudCivo): + cli.Client.Metadata.Provider = consts.CloudCivo + cli.Client.Metadata.IsHA = true + + case string(consts.CloudCivo): + cli.Client.Metadata.Provider = consts.CloudCivo + + case string(consts.ClusterTypeHa) + "-" + string(consts.CloudAzure): + cli.Client.Metadata.Provider = consts.CloudAzure + cli.Client.Metadata.IsHA = true + + case string(consts.ClusterTypeHa) + "-" + string(consts.CloudAws): + cli.Client.Metadata.Provider = consts.CloudAws + cli.Client.Metadata.IsHA = true + + case string(consts.CloudAzure): + cli.Client.Metadata.Provider = consts.CloudAzure + default: + log.Error("invalid provider specified", "provider", provider) + os.Exit(1) + } + m, err := controllers.NewManagerClusterKsctl( ctx, log, diff --git a/scripts/builder-mock.ps1 b/scripts/builder-mock.ps1 new file mode 100644 index 0000000..c0e7132 --- /dev/null +++ b/scripts/builder-mock.ps1 @@ -0,0 +1,40 @@ +#Requires -Version 5 + +$erroractionpreference = 'stop' # quit if anything goes wrong + +if (($PSVersionTable.PSVersion.Major) -lt 5) { + Write-Output "PowerShell 5 or later is required to run Ksctl." + Write-Output "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" + break +} + +Write-Host "Welcome to Installation" -ForegroundColor DarkGreen + +$env:GOOS = 'windows' +$env:GOARCH = 'amd64' +Set-Location .\.. + +Set-Location .\cli\ + +go build -tags testing-civo,testing-azure,testing-aws,testing-local -v -o ksctl.exe . + +#Move-Item ksctl.exe $env:USERPROFILE\.ksctl\ + +$localAppDataPath = $env:LOCALAPPDATA +$ksctl = Join-Path "$localAppDataPath" 'ksctl' + +Write-Information "Path of AppDataPath $ksctl" + +New-Item -ItemType Directory -Force -Path $ksctl | Out-Null + +Copy-Item ksctl.exe -Destination "$ksctl/" -Force | Out-Null + +Remove-Item ksctl.exe + +Set-Location ..\.. | Out-Null + +Write-Host "[V] Finished Installation" -ForegroundColor DarkGreen +Write-Host "" +Write-Host "To run ksctl globally, please follow these steps:" -ForegroundColor Cyan +Write-Host "" +Write-Host " 1. Run the following command as administrator: ``setx PATH `"`$env:path;$ksctl`" -m``" diff --git a/scripts/builder-mock.sh b/scripts/builder-mock.sh new file mode 100755 index 0000000..7196ea1 --- /dev/null +++ b/scripts/builder-mock.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +cd .. || echo -e "\033[1;31mUnable to cd into ksctl root\033[0m\n" + +# Get the binary from the source code +cd cli || echo -e "\033[1;31mPath couldn't be found\033[0m\n" +# Check if sudo access +go get -d +go build -tags testing-civo,testing-azure,testing-aws,testing-local -v -o ksctl . +chmod +x ksctl + +sudo mv -v ksctl /usr/local/bin/ksctl + +echo -e "\033[1;32mINSTALL COMPLETE\033[0m\n" + +cd - || echo -e "\033[1;31mFailed to move to previous directory\033[0m\n" From 2c2bc67858f51e7ace154089280cb73630a83f35 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:16:03 +0530 Subject: [PATCH 5/9] updated the build tags Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- scripts/builder-mock.ps1 | 2 +- scripts/builder-mock.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/builder-mock.ps1 b/scripts/builder-mock.ps1 index c0e7132..30cbef5 100644 --- a/scripts/builder-mock.ps1 +++ b/scripts/builder-mock.ps1 @@ -16,7 +16,7 @@ Set-Location .\.. Set-Location .\cli\ -go build -tags testing-civo,testing-azure,testing-aws,testing-local -v -o ksctl.exe . +go build -tags testing_civo,testing_azure,testing_aws,testing_local -v -o ksctl.exe . #Move-Item ksctl.exe $env:USERPROFILE\.ksctl\ diff --git a/scripts/builder-mock.sh b/scripts/builder-mock.sh index 7196ea1..ba9c4d8 100755 --- a/scripts/builder-mock.sh +++ b/scripts/builder-mock.sh @@ -6,7 +6,7 @@ cd .. || echo -e "\033[1;31mUnable to cd into ksctl root\033[0m\n" cd cli || echo -e "\033[1;31mPath couldn't be found\033[0m\n" # Check if sudo access go get -d -go build -tags testing-civo,testing-azure,testing-aws,testing-local -v -o ksctl . +go build -tags testing_civo,testing_azure,testing_aws,testing_local -v -o ksctl . chmod +x ksctl sudo mv -v ksctl /usr/local/bin/ksctl From 19dcd241ebf02fdc72c43ba0acc57a408d244816 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Fri, 21 Jun 2024 17:07:10 +0530 Subject: [PATCH 6/9] Update .github/workflows/test-mock.yml --- .github/workflows/test-mock.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-mock.yml b/.github/workflows/test-mock.yml index ae0e3fd..d47d9ef 100644 --- a/.github/workflows/test-mock.yml +++ b/.github/workflows/test-mock.yml @@ -84,7 +84,7 @@ jobs: ${{env.KSCTL_BIN}} create ha-civo -n ha-demo-kubeadm --nodeSizeDS "fake.small" --version 1.28 --nodeSizeLB "fake.small" --nodeSizeCP "fake.small" --nodeSizeWP "fake.small" -s store-local -r LON1 --verbose -1 --yes --bootstrap kubeadm - ${{env.KSCTL_BIN}} info ha-civo -n ha-demo-kubeadm -s store-local -r LON1 --verbose -1 + ${{env.KSCTL_BIN}} info -p ha-civo -n ha-demo-kubeadm -s store-local -r LON1 --verbose -1 - name: azure create run: | From 6ef80145b4bbeef1dc19657fd2f2a3027e519701 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Fri, 21 Jun 2024 20:06:31 +0530 Subject: [PATCH 7/9] updated the aws new fake region Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- .github/workflows/test-mock.yml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test-mock.yml b/.github/workflows/test-mock.yml index d47d9ef..addc6d4 100644 --- a/.github/workflows/test-mock.yml +++ b/.github/workflows/test-mock.yml @@ -102,17 +102,17 @@ jobs: - name: aws create run: | - # ${{env.KSCTL_BIN}} create aws -n demo -r fake --nodeSizeMP "fake" --version 1.27.1 -s store-local --verbose -1 --yes + # ${{env.KSCTL_BIN}} create aws -n demo -r fake-region --nodeSizeMP "fake" --version 1.27.1 -s store-local --verbose -1 --yes - #${{env.KSCTL_BIN}} info -p aws -n demo -r fake -s store-local --verbose -1 + #${{env.KSCTL_BIN}} info -p aws -n demo -r fake-region -s store-local --verbose -1 - ${{env.KSCTL_BIN}} create ha-aws -n ha-demo-k3s --nodeSizeDS "fake" --version 1.27.1 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s store-local --yes --bootstrap k3s + ${{env.KSCTL_BIN}} create ha-aws -n ha-demo-k3s --nodeSizeDS "fake" --version 1.27.1 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake-region --verbose -1 -s store-local --yes --bootstrap k3s - ${{env.KSCTL_BIN}} info -p ha-aws -n ha-demo-k3s -r fake -s store-local --verbose -1 + ${{env.KSCTL_BIN}} info -p ha-aws -n ha-demo-k3s -r fake-region -s store-local --verbose -1 - ${{env.KSCTL_BIN}} create ha-aws -n ha-demo-kubeadm --nodeSizeDS "fake" --version 1.28 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s store-local --yes --bootstrap kubeadm + ${{env.KSCTL_BIN}} create ha-aws -n ha-demo-kubeadm --nodeSizeDS "fake" --version 1.28 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake-region --verbose -1 -s store-local --yes --bootstrap kubeadm - ${{env.KSCTL_BIN}} info -p ha-aws -n ha-demo-kubeadm -r fake -s store-local --verbose -1 + ${{env.KSCTL_BIN}} info -p ha-aws -n ha-demo-kubeadm -r fake-region -s store-local --verbose -1 - name: local create run: | @@ -173,9 +173,9 @@ jobs: - name: aws switch run: | - # ${{env.KSCTL_BIN}} switch -p aws -n demo -s store-local -r fake - ${{env.KSCTL_BIN}} switch -p ha-aws -n ha-demo-k3s -s store-local -r fake - ${{env.KSCTL_BIN}} switch -p ha-aws -n ha-demo-kubeadm -s store-local -r fake + # ${{env.KSCTL_BIN}} switch -p aws -n demo -s store-local -r fake-region + ${{env.KSCTL_BIN}} switch -p ha-aws -n ha-demo-k3s -s store-local -r fake-region + ${{env.KSCTL_BIN}} switch -p ha-aws -n ha-demo-kubeadm -s store-local -r fake-region - name: azure switch run: | @@ -216,13 +216,13 @@ jobs: - name: aws scale up and down run: | - ${{env.KSCTL_BIN}} delete ha-aws del-nodes -n ha-demo-k3s --noWP 0 -r fake -s store-local --yes -v -1 --bootstrap k3s + ${{env.KSCTL_BIN}} delete ha-aws del-nodes -n ha-demo-k3s --noWP 0 -r fake-region -s store-local --yes -v -1 --bootstrap k3s - ${{env.KSCTL_BIN}} create ha-aws add-nodes -n ha-demo-k3s --noWP 1 --version 1.27.1 --nodeSizeWP "fake" -s store-local -r fake -v -1 --yes --bootstrap k3s + ${{env.KSCTL_BIN}} create ha-aws add-nodes -n ha-demo-k3s --noWP 1 --version 1.27.1 --nodeSizeWP "fake" -s store-local -r fake-region -v -1 --yes --bootstrap k3s - ${{env.KSCTL_BIN}} delete ha-aws del-nodes -n ha-demo-kubeadm --noWP 0 -r fake -s store-local --yes -v -1 --bootstrap kubeadm + ${{env.KSCTL_BIN}} delete ha-aws del-nodes -n ha-demo-kubeadm --noWP 0 -r fake-region -s store-local --yes -v -1 --bootstrap kubeadm - ${{env.KSCTL_BIN}} create ha-aws add-nodes -n ha-demo-kubeadm --noWP 1 --version 1.28 --nodeSizeWP "fake" -s store-local -r fake -v -1 --yes --bootstrap kubeadm + ${{env.KSCTL_BIN}} create ha-aws add-nodes -n ha-demo-kubeadm --noWP 1 --version 1.28 --nodeSizeWP "fake" -s store-local -r fake-region -v -1 --yes --bootstrap kubeadm - name: civo delete run: | @@ -238,9 +238,9 @@ jobs: - name: aws delete run: | - # ${{env.KSCTL_BIN}} delete aws -n demo -r fake -s store-local -v -1 --yes - ${{env.KSCTL_BIN}} delete ha-aws -n ha-demo-k3s -r fake -s store-local -v -1 --yes - ${{env.KSCTL_BIN}} delete ha-aws -n ha-demo-kubeadm -r fake -s store-local -v -1 --yes + # ${{env.KSCTL_BIN}} delete aws -n demo -r fake-region -s store-local -v -1 --yes + ${{env.KSCTL_BIN}} delete ha-aws -n ha-demo-k3s -r fake-region -s store-local -v -1 --yes + ${{env.KSCTL_BIN}} delete ha-aws -n ha-demo-kubeadm -r fake-region -s store-local -v -1 --yes - name: local delete run: | From b1439fab9433f1297c0a852b2dfce264ab07fcf5 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Fri, 21 Jun 2024 21:15:17 +0530 Subject: [PATCH 8/9] updated the mock test Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- .github/workflows/test-mock.yml | 98 ++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/.github/workflows/test-mock.yml b/.github/workflows/test-mock.yml index addc6d4..c5d3d58 100644 --- a/.github/workflows/test-mock.yml +++ b/.github/workflows/test-mock.yml @@ -21,6 +21,61 @@ on: branches: [ main ] jobs: + ksctl-cli-mongodb-driver: + runs-on: ubuntu-latest + if: | + ( + github.event.label.name == 'pr/lgtm' || + contains(github.event.pull_request.labels.*.name, 'pr/lgtm') + ) || ( + github.event_name == 'push' && + github.ref == 'refs/heads/main' + ) + env: + MONGODB_URI: "mongodb://root:1234@127.0.0.1:27017" + steps: + - name: Checkout + uses: actions/checkout@v4.1.4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.22.3 + + - name: build ksctl linux + run: | + set -x + make install_linux + echo "KSCTL_BIN=ksctl" >> "${GITHUB_ENV}" + + - name: local version + run: | + ${{ env.KSCTL_BIN }} version + + - name: local create + run: | + docker run -d \ + --name mongodb \ + -p 27017:27017 \ + -e MONGO_INITDB_ROOT_USERNAME=root \ + -e MONGO_INITDB_ROOT_PASSWORD=1234 \ + mongo + ${{env.KSCTL_BIN}} create local -n demolocal-extmongo -s external-store-mongodb --verbose -1 --yes + ${{env.KSCTL_BIN}} info -p local -n demolocal-extmongo -s external-store-mongodb --verbose -1 + + - name: local get + run: | + ${{env.KSCTL_BIN}} get -s external-store-mongodb + + - name: local switch + run: | + ${{env.KSCTL_BIN}} switch -p local -n demolocal-extmongo -s external-store-mongodb + + - name: local delete + run: | + ${{env.KSCTL_BIN}} delete local -n demolocal-extmongo -v -1 -s external-store-mongodb --yes + + ksctl-cli: strategy: matrix: @@ -119,21 +174,6 @@ jobs: ${{env.KSCTL_BIN}} create local -n demolocal --version 1.27.1 --verbose -1 -s store-local --yes ${{env.KSCTL_BIN}} info -p local -n demolocal -s store-local --verbose -1 - - - name: local create mongodb - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - unset KSCTL_FAKE_FLAG_ENABLED - docker run -d \ - --name mongodb \ - -p 27017:27017 \ - -e MONGO_INITDB_ROOT_USERNAME=root \ - -e MONGO_INITDB_ROOT_PASSWORD=1234 \ - mongo - export MONGODB_URI="mongodb://root:1234@127.0.0.1:27017" - ${{env.KSCTL_BIN}} create local -n demolocal-extmongo -s external-store-mongodb --verbose -1 --yes - ${{env.KSCTL_BIN}} info -p local -n demolocal-extmongo -s external-store-mongodb --verbose -1 - - name: civo get run: | ${{env.KSCTL_BIN}} get -s store-local -p civo @@ -146,25 +186,10 @@ jobs: run: | ${{env.KSCTL_BIN}} get -s store-local -p aws - - name: local get mongo - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - unset KSCTL_FAKE_FLAG_ENABLED - export MONGODB_URI="mongodb://root:1234@127.0.0.1:27017" - ${{env.KSCTL_BIN}} get -p local -s external-store-mongodb - - name: get all run: | ${{env.KSCTL_BIN}} get -s store-local - - - name: all mongodb - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - unset KSCTL_FAKE_FLAG_ENABLED - export MONGODB_URI="mongodb://root:1234@127.0.0.1:27017" - ${{env.KSCTL_BIN}} get -s external-store-mongodb - - name: civo switch run: | ${{env.KSCTL_BIN}} switch -p civo -n demo -s store-local -r LON1 @@ -187,13 +212,6 @@ jobs: run: | ${{env.KSCTL_BIN}} switch -p local -n demolocal -s store-local - - name: local switch mongodb - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - unset KSCTL_FAKE_FLAG_ENABLED - export MONGODB_URI="mongodb://root:1234@127.0.0.1:27017" - ${{env.KSCTL_BIN}} switch -p local -n demolocal-extmongo -s external-store-mongodb - - name: civo scale up and down run: | ${{env.KSCTL_BIN}} delete ha-civo del-nodes -n ha-demo-k3s --noWP 0 -r LON1 -s store-local --yes -v -1 --bootstrap k3s @@ -246,10 +264,4 @@ jobs: run: | ${{env.KSCTL_BIN}} delete local -n demolocal -s store-local -v -1 --yes - - name: local delete mongodb - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - unset KSCTL_FAKE_FLAG_ENABLED - export MONGODB_URI="mongodb://root:1234@127.0.0.1:27017" - ${{env.KSCTL_BIN}} delete local -n demolocal-extmongo -v -1 -s external-store-mongodb --yes From 647c8321d0c70f06fb55d20c54d5070bc2f502dd Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Fri, 21 Jun 2024 22:23:31 +0530 Subject: [PATCH 9/9] added verbose logging Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- .github/workflows/test-mock.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-mock.yml b/.github/workflows/test-mock.yml index c5d3d58..d53f7a7 100644 --- a/.github/workflows/test-mock.yml +++ b/.github/workflows/test-mock.yml @@ -69,7 +69,7 @@ jobs: - name: local switch run: | - ${{env.KSCTL_BIN}} switch -p local -n demolocal-extmongo -s external-store-mongodb + ${{env.KSCTL_BIN}} switch -p local -v -1 -n demolocal-extmongo -s external-store-mongodb - name: local delete run: |