Skip to content

Commit

Permalink
Merge pull request #11 from kubesimplify/update-to-v1.1.1-rc3
Browse files Browse the repository at this point in the history
refactor the cobra cli to meet the new ksctl core `v1.1.1-rc3`
  • Loading branch information
dipankardas011 authored Nov 16, 2023
2 parents bba42a1 + e8b8744 commit 55d23f8
Show file tree
Hide file tree
Showing 18 changed files with 287 additions and 224 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/test-mock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ jobs:
- name: civo create
run: |
ksctl create civo -n demo -r LON1 --nodeSizeMP "g4s.kube.small" -v --approve
ksctl create ha-civo -n ha-demo --nodeSizeDS "fake.small" --nodeSizeLB "fake.small" --nodeSizeCP "fake.small" --nodeSizeWP "fake.small" -r LON1 -v --approve
ksctl create civo -n demo -r LON1 --nodeSizeMP "g4s.kube.small" --verbose -1 --approve
ksctl create ha-civo -n ha-demo --nodeSizeDS "fake.small" --nodeSizeLB "fake.small" --nodeSizeCP "fake.small" --nodeSizeWP "fake.small" -r LON1 --verbose -1 --approve
- name: azure create
run: |
ksctl create azure -n demo -r fake --nodeSizeMP "fake" -v --approve
ksctl create ha-azure -n ha-demo --nodeSizeDS "fake" --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake -v --approve
ksctl create azure -n demo -r fake --nodeSizeMP "fake" --verbose -1 --approve
ksctl create ha-azure -n ha-demo --nodeSizeDS "fake" --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 --approve
- name: local create
run: |
ksctl create local -n demolocal -v --approve
ksctl create local -n demolocal --verbose -1 --approve
- name: civo get
run: |
Expand All @@ -72,25 +72,25 @@ jobs:
- name: civo scale up and down
run: |
ksctl delete ha-civo delete-nodes -n ha-demo --noWP 0 -r LON1 --approve -v
ksctl create ha-civo add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake.small" -r LON1 -v --approve
ksctl delete ha-civo delete-nodes -n ha-demo --noWP 0 -r LON1 --approve -v -1
ksctl create ha-civo add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake.small" -r LON1 -v -1 --approve
- name: azure scale up and down
run: |
ksctl delete ha-azure delete-nodes -n ha-demo --noWP 0 -r fake --approve -v
ksctl create ha-azure add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake" -r fake -v --approve
ksctl delete ha-azure delete-nodes -n ha-demo --noWP 0 -r fake --approve -v -1
ksctl create ha-azure add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake" -r fake -v -1 --approve
- name: civo delete
run: |
ksctl delete civo -n demo -r LON1 -v --approve
ksctl delete ha-civo -n ha-demo -r LON1 -v --approve
ksctl delete civo -n demo -r LON1 -v -1 --approve
ksctl delete ha-civo -n ha-demo -r LON1 -v -1 --approve
- name: azure delete
run: |
ksctl delete azure -n demo -r fake -v --approve
ksctl delete ha-azure -n ha-demo -r fake -v --approve
ksctl delete azure -n demo -r fake -v -1 --approve
ksctl delete ha-azure -n ha-demo -r fake -v -1 --approve
- name: local delete
run: |
ksctl delete local -n demolocal -v --approve
ksctl delete local -n demolocal -v -1 --approve
19 changes: 11 additions & 8 deletions cli/cmd/addNodesHAAzure.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cmd

// maintainer: Dipankar Das <dipankardas0115@gmail.com>
// authors Dipankar <dipankar@dipankar-das.com>

import (
"os"
Expand All @@ -19,9 +19,9 @@ var addMoreWorkerNodesHAAzure = &cobra.Command{
ksctl create-cluster ha-azure add-nodes <arguments to civo cloud provider>
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}
SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.Provider = consts.CloudAzure
Expand All @@ -33,17 +33,20 @@ ksctl create-cluster ha-azure add-nodes <arguments to civo cloud provider>
cli.Client.Metadata.IsHA = true
cli.Client.Metadata.K8sDistro = consts.KsctlKubernetes(distro)
cli.Client.Metadata.K8sVersion = k8sVer
cli.Client.Metadata.LogVerbosity = verbosity
cli.Client.Metadata.LogWritter = os.Stdout

if err := createApproval(cmd.Flags().Lookup("approve").Changed); err != nil {
cli.Client.Storage.Logger().Err(err.Error())
log.Error(err.Error())
os.Exit(1)
}
stat, err := controller.AddWorkerPlaneNode(&cli.Client)

err := controller.AddWorkerPlaneNode(&cli.Client)
if err != nil {
cli.Client.Storage.Logger().Err(err.Error())
log.Error("Failed to scale up", "Reason", err)
os.Exit(1)
}
cli.Client.Storage.Logger().Success(stat)
log.Success("Scale up successful")
},
}

Expand Down
19 changes: 11 additions & 8 deletions cli/cmd/addNodesHACivo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cmd

// maintainer: Dipankar Das <dipankardas0115@gmail.com>
// authors Dipankar <dipankar@dipankar-das.com>

import (
"os"
Expand All @@ -19,9 +19,9 @@ var addMoreWorkerNodesHACivo = &cobra.Command{
ksctl create-cluster ha-civo add-nodes <arguments to civo cloud provider>
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}
SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.Provider = consts.CloudCivo
Expand All @@ -35,17 +35,20 @@ ksctl create-cluster ha-civo add-nodes <arguments to civo cloud provider>

cli.Client.Metadata.IsHA = true

cli.Client.Metadata.LogVerbosity = verbosity
cli.Client.Metadata.LogWritter = os.Stdout

if err := createApproval(cmd.Flags().Lookup("approve").Changed); err != nil {
cli.Client.Storage.Logger().Err(err.Error())
log.Error(err.Error())
os.Exit(1)
}

stat, err := controller.AddWorkerPlaneNode(&cli.Client)
err := controller.AddWorkerPlaneNode(&cli.Client)
if err != nil {
cli.Client.Storage.Logger().Err(err.Error())
log.Error("Failed to scale up", "Reason", err)
os.Exit(1)
}
cli.Client.Storage.Logger().Success(stat)
log.Success("Scale up successful")
},
}

Expand Down
37 changes: 21 additions & 16 deletions cli/cmd/createCluster.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cmd

// maintainer: Dipankar Das <dipankardas0115@gmail.com>
// authors Dipankar Das <dipankardas0115@gmail.com>

import (
control_pkg "github.com/kubesimplify/ksctl/pkg/controllers"
Expand Down Expand Up @@ -38,10 +38,11 @@ var createClusterAzure = &cobra.Command{
ksctl create-cluster azure <arguments to civo cloud provider>
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}
cli.Client.Metadata.LogVerbosity = verbosity
SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.Provider = consts.CloudAzure
SetDefaults(consts.CloudAzure, consts.ClusterTypeMang)
Expand All @@ -57,11 +58,12 @@ var createClusterCivo = &cobra.Command{
ksctl create-cluster civo <arguments to civo cloud provider>
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}

cli.Client.Metadata.LogVerbosity = verbosity
SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.Provider = consts.CloudCivo
SetDefaults(consts.CloudCivo, consts.ClusterTypeMang)
Expand All @@ -77,11 +79,12 @@ var createClusterLocal = &cobra.Command{
ksctl create-cluster local <arguments to civo cloud provider>
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}

cli.Client.Metadata.LogVerbosity = verbosity
SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.Provider = consts.CloudLocal
SetDefaults(consts.CloudLocal, consts.ClusterTypeMang)
Expand All @@ -97,12 +100,13 @@ var createClusterHACivo = &cobra.Command{
ksctl create-cluster ha-civo <arguments to civo cloud provider>
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}
SetRequiredFeatureFlags(cmd)

cli.Client.Metadata.LogVerbosity = verbosity
cli.Client.Metadata.Provider = consts.CloudCivo
SetDefaults(consts.CloudCivo, consts.ClusterTypeHa)
createHA(cmd.Flags().Lookup("approve").Changed)
Expand All @@ -117,11 +121,12 @@ var createClusterHAAzure = &cobra.Command{
ksctl create-cluster ha-azure <arguments to civo cloud provider>
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}
SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.LogVerbosity = verbosity
cli.Client.Metadata.Provider = consts.CloudAzure
SetDefaults(consts.CloudAzure, consts.ClusterTypeHa)
createHA(cmd.Flags().Lookup("approve").Changed)
Expand Down
29 changes: 15 additions & 14 deletions cli/cmd/credentials.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// maintainer: Dipankar Das <dipankardas0115@gmail.com>

// authors Dipankar <dipankar@dipankar-das.com>
package cmd

import (
"fmt"
"os"

control_pkg "github.com/kubesimplify/ksctl/pkg/controllers"
. "github.com/kubesimplify/ksctl/pkg/utils/consts"
"github.com/kubesimplify/ksctl/pkg/utils/consts"
"github.com/spf13/cobra"
)

Expand All @@ -17,13 +17,13 @@ var credCmd = &cobra.Command{
Long: `login to your cloud provider credentials
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}
SetRequiredFeatureFlags(cmd)

fmt.Println(`
log.Print(`
1> AWS (EKS)
2> Azure (AKS)
3> Civo (K3s)
Expand All @@ -36,17 +36,18 @@ var credCmd = &cobra.Command{
panic(err.Error())
}
if provider, ok := cloud[choice]; ok {
cli.Client.Metadata.Provider = KsctlCloud(provider)
cli.Client.Metadata.Provider = consts.KsctlCloud(provider)
} else {
cli.Client.Storage.Logger().Err("invalid provider")
log.Error("invalid provider")
}
cli.Client.Metadata.LogVerbosity = verbosity
cli.Client.Metadata.LogWritter = os.Stdout

stat, err := controller.Credentials(&cli.Client)
if err != nil {
cli.Client.Storage.Logger().Err(err.Error())
return
if err := controller.Credentials(&cli.Client); err != nil {
log.Error("Failed to added the credential", "Reason", err)
os.Exit(1)
}
cli.Client.Storage.Logger().Success(stat)
log.Success("Credentials added successfully")
},
}

Expand Down
37 changes: 21 additions & 16 deletions cli/cmd/deleteCluster.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cmd

// maintainer: Dipankar Das <dipankardas0115@gmail.com>
// authors Dipankar Das <dipankardas0115@gmail.com>

import (
control_pkg "github.com/kubesimplify/ksctl/pkg/controllers"
Expand All @@ -27,13 +27,14 @@ var deleteClusterAzure = &cobra.Command{
ksctl create-cluster azure <arguments to civo cloud provider>
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}

SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.Provider = consts.CloudAzure
cli.Client.Metadata.LogVerbosity = verbosity
SetDefaults(consts.CloudAzure, consts.ClusterTypeMang)

deleteManaged(cmd.Flags().Lookup("approve").Changed)
Expand All @@ -48,13 +49,14 @@ var deleteClusterCivo = &cobra.Command{
ksctl delete-cluster civo
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}

SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.Provider = consts.CloudCivo
cli.Client.Metadata.LogVerbosity = verbosity
SetDefaults(consts.CloudCivo, consts.ClusterTypeMang)

deleteManaged(cmd.Flags().Lookup("approve").Changed)
Expand All @@ -70,13 +72,14 @@ var deleteClusterHAAzure = &cobra.Command{
ksctl delete-cluster ha-azure <arguments to civo cloud provider>
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}

SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.Provider = consts.CloudAzure
cli.Client.Metadata.LogVerbosity = verbosity
SetDefaults(consts.CloudAzure, consts.ClusterTypeHa)

deleteHA(cmd.Flags().Lookup("approve").Changed)
Expand All @@ -91,13 +94,14 @@ var deleteClusterHACivo = &cobra.Command{
ksctl delete-cluster ha-civo <arguments to civo cloud provider>
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}

SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.Provider = consts.CloudCivo
cli.Client.Metadata.LogVerbosity = verbosity
SetDefaults(consts.CloudCivo, consts.ClusterTypeHa)

deleteHA(cmd.Flags().Lookup("approve").Changed)
Expand All @@ -112,13 +116,14 @@ var deleteClusterLocal = &cobra.Command{
ksctl delete-cluster local <arguments to local/Docker provider>
`,
Run: func(cmd *cobra.Command, args []string) {
isSet := cmd.Flags().Lookup("verbose").Changed
if _, err := control_pkg.InitializeStorageFactory(&cli.Client, isSet); err != nil {
panic(err)
verbosity, _ := cmd.Flags().GetInt("verbose")
if err := control_pkg.InitializeStorageFactory(&cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}

SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.Provider = consts.CloudLocal
cli.Client.Metadata.LogVerbosity = verbosity
SetDefaults(consts.CloudLocal, consts.ClusterTypeMang)

deleteManaged(cmd.Flags().Lookup("approve").Changed)
Expand Down
Loading

0 comments on commit 55d23f8

Please sign in to comment.