Skip to content

Commit

Permalink
Merge pull request #19 from ksctl/17-enhancementstorage-provide-a-com…
Browse files Browse the repository at this point in the history
…mand-line-argument-to-choose-between-different-storage-solutions

feat: add support for storage provider in command argument
  • Loading branch information
dipankardas011 authored Feb 18, 2024
2 parents 1081db2 + dc26103 commit 5502fce
Show file tree
Hide file tree
Showing 14 changed files with 262 additions and 153 deletions.
94 changes: 50 additions & 44 deletions .github/workflows/test-mock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,77 +42,77 @@ jobs:
- name: civo create
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe create civo -n demo -r LON1 --nodeSizeMP "g4s.kube.small" --verbose -1 --approve
.\ksctl.exe create ha-civo -n ha-demo --nodeSizeDS "fake.small" --nodeSizeLB "fake.small" --nodeSizeCP "fake.small" --nodeSizeWP "fake.small" -r LON1 --verbose -1 --approve
.\ksctl.exe create civo -n demo -r LON1 --nodeSizeMP "g4s.kube.small" --verbose -1 -s local --approve
.\ksctl.exe create ha-civo -n ha-demo --nodeSizeDS "fake.small" --nodeSizeLB "fake.small" --nodeSizeCP "fake.small" --nodeSizeWP "fake.small" -s local -r LON1 --verbose -1 --approve
- name: azure create
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe create azure -n demo -r fake --nodeSizeMP "fake" --verbose -1 --approve
.\ksctl.exe create ha-azure -n ha-demo --nodeSizeDS "fake" --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 --approve
.\ksctl.exe create azure -n demo -r fake --nodeSizeMP "fake" -s local --verbose -1 --approve
.\ksctl.exe create ha-azure -n ha-demo --nodeSizeDS "fake" --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s local --approve
- name: local create
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe create local -n demolocal --verbose -1 --approve
.\ksctl.exe create local -n demolocal --verbose -1 -s local --approve
- name: civo get
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe get -p civo
.\ksctl.exe get -s local -p civo
- name: azure get
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe get -p azure
.\ksctl.exe get -s local -p azure
- name: get all
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe get
.\ksctl.exe get -s local
- name: civo switch
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe switch -p civo -n demo -r LON1
.\ksctl.exe switch -p ha-civo -n ha-demo -r LON1
.\ksctl.exe switch -p civo -n demo -s local -r LON1
.\ksctl.exe switch -p ha-civo -n ha-demo -s local -r LON1
- name: azure switch
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe switch -p azure -n demo -r fake
.\ksctl.exe switch -p ha-azure -n ha-demo -r fake
.\ksctl.exe switch -p azure -n demo -s local -r fake
.\ksctl.exe switch -p ha-azure -n ha-demo -s local -r fake
- name: civo scale up and down
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe delete ha-civo delete-nodes -n ha-demo --noWP 0 -r LON1 --approve -v -1
.\ksctl.exe create ha-civo add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake.small" -r LON1 -v -1 --approve
.\ksctl.exe delete ha-civo delete-nodes -n ha-demo --noWP 0 -r LON1 -s local --approve -v -1
.\ksctl.exe create ha-civo add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake.small" -s local -r LON1 -v -1 --approve
- name: azure scale up and down
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe delete ha-azure delete-nodes -n ha-demo --noWP 0 -r fake --approve -v -1
.\ksctl.exe create ha-azure add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake" -r fake -v -1 --approve
.\ksctl.exe delete ha-azure delete-nodes -n ha-demo --noWP 0 -r fake -s local --approve -v -1
.\ksctl.exe create ha-azure add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake" -s local -r fake -v -1 --approve
- name: civo delete
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe delete civo -n demo -r LON1 -v -1 --approve
.\ksctl.exe delete ha-civo -n ha-demo -r LON1 -v -1 --approve
.\ksctl.exe delete civo -n demo -r LON1 -s local -v -1 --approve
.\ksctl.exe delete ha-civo -n ha-demo -r LON1 -s local -v -1 --approve
- name: azure delete
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe delete azure -n demo -r fake -v -1 --approve
.\ksctl.exe delete ha-azure -n ha-demo -r fake -v -1 --approve
.\ksctl.exe delete azure -n demo -r fake -s local -v -1 --approve
.\ksctl.exe delete ha-azure -n ha-demo -r fake -s local -v -1 --approve
- name: local delete
working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl'
run: |
.\ksctl.exe delete local -n demolocal -v -1 --approve
.\ksctl.exe delete local -n demolocal -s local -v -1 --approve
ksctl-cli-unix:
strategy:
Expand Down Expand Up @@ -146,59 +146,65 @@ jobs:
- name: civo create
run: |
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
ksctl create civo -n demo -r LON1 --nodeSizeMP "g4s.kube.small" -s local --verbose -1 --approve
ksctl create ha-civo -n ha-demo --nodeSizeDS "fake.small" -s local --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" --verbose -1 --approve
ksctl create ha-azure -n ha-demo --nodeSizeDS "fake" --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 --approve
ksctl create azure -n demo -r fake --nodeSizeMP "fake" -s local --verbose -1 --approve
ksctl create ha-azure -n ha-demo --nodeSizeDS "fake" -s local --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 --approve
- name: local create
run: |
ksctl create local -n demolocal --verbose -1 --approve
ksctl create local -n demolocal -s local --verbose -1 --approve
- name: civo get
run: |
ksctl get -p civo
ksctl get -p civo -s local
- name: azure get
run: |
ksctl get -p azure
ksctl get -p azure -s local
- name: all
run: |
ksctl get
ksctl get -s local
- name: civo switch
run: |
ksctl switch -p civo -n demo -r LON1
ksctl switch -p ha-civo -n ha-demo -r LON1
ksctl switch -p civo -n demo -s local -r LON1
ksctl switch -p ha-civo -n ha-demo -s local -r LON1
- name: azure switch
run: |
ksctl switch -p azure -n demo -r fake
ksctl switch -p ha-azure -n ha-demo -r fake
ksctl switch -p azure -n demo -s local -r fake
ksctl switch -p ha-azure -n ha-demo -s local -r fake
- name: civo scale up and down
run: |
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
ksctl delete ha-civo delete-nodes -n ha-demo --noWP 0 -r LON1 -s local --approve -v -1
ksctl create ha-civo add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake.small" -s local -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 -1
ksctl create ha-azure add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake" -r fake -v -1 --approve
ksctl delete ha-azure delete-nodes -n ha-demo --noWP 0 -s local -r fake --approve -v -1
ksctl create ha-azure add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake" -s local -r fake -v -1 --approve
- name: civo delete
run: |
ksctl delete civo -n demo -r LON1 -v -1 --approve
ksctl delete ha-civo -n ha-demo -r LON1 -v -1 --approve
ksctl delete civo -n demo -r LON1 -s local -v -1 --approve
ksctl delete ha-civo -n ha-demo -r LON1 -s local -v -1 --approve
- name: azure delete
run: |
ksctl delete azure -n demo -r fake -v -1 --approve
ksctl delete ha-azure -n ha-demo -r fake -v -1 --approve
ksctl delete azure -n demo -r fake -s local -v -1 --approve
ksctl delete ha-azure -n ha-demo -r fake -s local -v -1 --approve
- name: local delete
run: |
ksctl delete local -n demolocal -v -1 --approve
ksctl delete local -n demolocal -v -1 -s local --approve
- name: storage provider
run: |
ksctl create local -n demolocal -s local -v -1 --approve
ksctl create local -n demolocal -s external-mongo -v -1 --approve || echo "Expected to fail :) due to missing env vars"
ksctl create local -n demolocal -s local123 -v -1 --approve || echo "Expected to fail :) due to invalid provider name"
19 changes: 12 additions & 7 deletions cli/cmd/addNodesHAAzure.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package cmd

import (
"context"
"github.com/ksctl/ksctl/pkg/helpers"
"os"

control_pkg "github.com/ksctl/ksctl/pkg/controllers"
"github.com/ksctl/ksctl/pkg/helpers"

"github.com/spf13/cobra"

"github.com/ksctl/ksctl/pkg/helpers/consts"
Expand All @@ -22,15 +22,14 @@ ksctl create-cluster ha-azure add-nodes <arguments to civo cloud provider>
`,
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
SetRequiredFeatureFlags(cmd)

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

if err := control_pkg.InitializeStorageFactory(context.WithValue(context.Background(), "USERID", helpers.GetUserName()), &cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}
SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.Provider = consts.CloudAzure

SetDefaults(consts.CloudAzure, consts.ClusterTypeHa)

cli.Client.Metadata.NoWP = noWP
cli.Client.Metadata.WorkerPlaneNodeType = nodeSizeWP
cli.Client.Metadata.ClusterName = clusterName
Expand All @@ -39,6 +38,11 @@ ksctl create-cluster ha-azure add-nodes <arguments to civo cloud provider>
cli.Client.Metadata.K8sDistro = consts.KsctlKubernetes(distro)
cli.Client.Metadata.K8sVersion = k8sVer

if err := safeInitializeStorageLoggerFactory(context.WithValue(context.Background(), "USERID", helpers.GetUserName())); err != nil {
log.Error("Failed Inialize Storage Driver", "Reason", err)
os.Exit(1)
}

if err := createApproval(cmd.Flags().Lookup("approve").Changed); err != nil {
log.Error(err.Error())
os.Exit(1)
Expand All @@ -61,6 +65,7 @@ func init() {
regionFlag(addMoreWorkerNodesHAAzure)
k8sVerFlag(addMoreWorkerNodesHAAzure)
distroFlag(addMoreWorkerNodesHAAzure)
storageFlag(addMoreWorkerNodesHAAzure)

addMoreWorkerNodesHAAzure.MarkFlagRequired("name")
addMoreWorkerNodesHAAzure.MarkFlagRequired("region")
Expand Down
19 changes: 11 additions & 8 deletions cli/cmd/addNodesHACivo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ package cmd

import (
"context"
"github.com/ksctl/ksctl/pkg/helpers"
"os"

control_pkg "github.com/ksctl/ksctl/pkg/controllers"
"github.com/ksctl/ksctl/pkg/helpers"

"github.com/ksctl/ksctl/pkg/helpers/consts"
"github.com/spf13/cobra"
Expand All @@ -22,24 +21,27 @@ ksctl create-cluster ha-civo add-nodes <arguments to civo cloud provider>
`,
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
SetRequiredFeatureFlags(cmd)

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

if err := control_pkg.InitializeStorageFactory(context.WithValue(context.Background(), "USERID", helpers.GetUserName()), &cli.Client); err != nil {
log.Error("Inialize Storage Driver", "Reason", err)
}
SetRequiredFeatureFlags(cmd)
cli.Client.Metadata.Provider = consts.CloudCivo

SetDefaults(consts.CloudCivo, consts.ClusterTypeHa)

cli.Client.Metadata.NoWP = noWP
cli.Client.Metadata.WorkerPlaneNodeType = nodeSizeWP
cli.Client.Metadata.ClusterName = clusterName
cli.Client.Metadata.Region = region
cli.Client.Metadata.K8sDistro = consts.KsctlKubernetes(distro)
cli.Client.Metadata.K8sVersion = k8sVer

cli.Client.Metadata.IsHA = true

if err := safeInitializeStorageLoggerFactory(context.WithValue(context.Background(), "USERID", helpers.GetUserName())); err != nil {
log.Error("Failed Inialize Storage Driver", "Reason", err)
os.Exit(1)
}

if err := createApproval(cmd.Flags().Lookup("approve").Changed); err != nil {
log.Error(err.Error())
os.Exit(1)
Expand All @@ -62,6 +64,7 @@ func init() {
regionFlag(addMoreWorkerNodesHACivo)
k8sVerFlag(addMoreWorkerNodesHACivo)
distroFlag(addMoreWorkerNodesHACivo)
storageFlag(addMoreWorkerNodesHACivo)

addMoreWorkerNodesHACivo.MarkFlagRequired("name")
addMoreWorkerNodesHACivo.MarkFlagRequired("region")
Expand Down
Loading

0 comments on commit 5502fce

Please sign in to comment.