From 7c140480a52f7f0a6dbe032b4f2b843fa4ed1a33 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Mon, 29 Apr 2024 12:25:18 +0530 Subject: [PATCH 01/12] initial version bump Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- go.mod | 17 ++++++++++++++++- go.sum | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index eda7a30..5ae69de 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ksctl/cli go 1.21.0 require ( - github.com/ksctl/ksctl v1.1.3 + github.com/ksctl/ksctl v1.1.4 github.com/spf13/cobra v1.8.0 ) @@ -29,6 +29,20 @@ require ( github.com/Microsoft/hcsshim v0.11.4 // indirect github.com/alessio/shellescape v1.4.1 // indirect github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect + github.com/aws/aws-sdk-go-v2 v1.25.0 // indirect + github.com/aws/aws-sdk-go-v2/config v1.27.0 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.17.0 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.0 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.0 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.0 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect + github.com/aws/aws-sdk-go-v2/service/ec2 v1.148.0 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.0 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.0 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.19.0 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.22.0 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.27.0 // indirect + github.com/aws/smithy-go v1.20.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chai2010/gettext-go v1.0.2 // indirect @@ -80,6 +94,7 @@ require ( github.com/huandu/xstrings v1.4.0 // indirect github.com/imdario/mergo v0.3.13 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/jmoiron/sqlx v1.3.5 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect diff --git a/go.sum b/go.sum index 8e0a77a..26fe1b0 100644 --- a/go.sum +++ b/go.sum @@ -62,6 +62,34 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 h1:4daAzAu0S6Vi7/lbWECcX0j45yZReDZ56BQsrVBOEEY= github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg= +github.com/aws/aws-sdk-go-v2 v1.25.0 h1:sv7+1JVJxOu/dD/sz/csHX7jFqmP001TIY7aytBWDSQ= +github.com/aws/aws-sdk-go-v2 v1.25.0/go.mod h1:G104G1Aho5WqF+SR3mDIobTABQzpYV0WxMsKxlMggOA= +github.com/aws/aws-sdk-go-v2/config v1.27.0 h1:J5sdGCAHuWKIXLeXiqr8II/adSvetkx0qdZwdbXXpb0= +github.com/aws/aws-sdk-go-v2/config v1.27.0/go.mod h1:cfh8v69nuSUohNFMbIISP2fhmblGmYEOKs5V53HiHnk= +github.com/aws/aws-sdk-go-v2/credentials v1.17.0 h1:lMW2x6sKBsiAJrpi1doOXqWFyEPoE886DTb1X0wb7So= +github.com/aws/aws-sdk-go-v2/credentials v1.17.0/go.mod h1:uT41FIH8cCIxOdUYIL0PYyHlL1NoneDuDSCwg5VE/5o= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.0 h1:xWCwjjvVz2ojYTP4kBKUuUh9ZrXfcAXpflhOUUeXg1k= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.0/go.mod h1:j3fACuqXg4oMTQOR2yY7m0NmJY0yBK4L4sLsRXq1Ins= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.0 h1:NPs/EqVO+ajwOoq56EfcGKa3L3ruWuazkIw1BqxwOPw= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.0/go.mod h1:D+duLy2ylgatV+yTlQ8JTuLfDD0BnFvnQRc+o6tbZ4M= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.0 h1:ks7KGMVUMoDzcxNWUlEdI+/lokMFD136EL6DWmUOV80= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.0/go.mod h1:hL6BWM/d/qz113fVitZjbXR0E+RCTU1+x+1Idyn5NgE= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.148.0 h1:7imiXQvuqyUEu6wdcn6xRjR3zIJjDuAnS2e1S3ND+C0= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.148.0/go.mod h1:ntWksNNQcXImRQMdxab74tp+H94neF/TwQJ9Ndxb04k= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.0 h1:a33HuFlO0KsveiP90IUJh8Xr/cx9US2PqkSroaLc+o8= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.0/go.mod h1:SxIkWpByiGbhbHYTo9CMTUnx2G4p4ZQMrDPcRRy//1c= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.0 h1:SHN/umDLTmFTmYfI+gkanz6da3vK8Kvj/5wkqnTHbuA= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.0/go.mod h1:l8gPU5RYGOFHJqWEpPMoRTP0VoaWQSkJdKo+hwWnnDA= +github.com/aws/aws-sdk-go-v2/service/sso v1.19.0 h1:u6OkVDxtBPnxPkZ9/63ynEe+8kHbtS5IfaC4PzVxzWM= +github.com/aws/aws-sdk-go-v2/service/sso v1.19.0/go.mod h1:YqbU3RS/pkDVu+v+Nwxvn0i1WB0HkNWEePWbmODEbbs= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.22.0 h1:6DL0qu5+315wbsAEEmzK+P9leRwNbkp+lGjPC+CEvb8= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.22.0/go.mod h1:olUAyg+FaoFaL/zFaeQQONjOZ9HXoxgvI/c7mQTYz7M= +github.com/aws/aws-sdk-go-v2/service/sts v1.27.0 h1:cjTRjh700H36MQ8M0LnDn33W3JmwC77mdxIIyPWCdpM= +github.com/aws/aws-sdk-go-v2/service/sts v1.27.0/go.mod h1:nXfOBMWPokIbOY+Gi7a1psWMSvskUCemZzI+SMB7Akc= +github.com/aws/smithy-go v1.20.0 h1:6+kZsCXZwKxZS9RfISnPc4EXlHoyAkm2hPuM8X2BrrQ= +github.com/aws/smithy-go v1.20.0/go.mod h1:uo5RKksAl4PzhqaAbjd4rLgFoq5koTsQKYuGe7dklGc= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -283,6 +311,10 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g= github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= @@ -310,8 +342,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/ksctl/ksctl v1.1.3 h1:/p+Ii0haPywRNf+yQ4+8nxcA0X2IXGCD9sUEQ2sAjwQ= -github.com/ksctl/ksctl v1.1.3/go.mod h1:S9yp+faYYZYwVsLq38c5NIuzHuLFISuwO8kAsEKY5Xc= +github.com/ksctl/ksctl v1.1.4 h1:ptPbZ46rU1Trpw5+oKgXVtQyXYrL+8kATLW+0Ud6sRs= +github.com/ksctl/ksctl v1.1.4/go.mod h1:nnzX02/62FkElM8rHvrM3W8USCOgcAtnf3p81U2FvQ4= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw= From 9b18bf20da6046a4125691c79d92a9a20b82c7a9 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:18:15 +0530 Subject: [PATCH 02/12] feat: added the aws support Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- cli/cmd/addNodesHAAws.go | 72 +++++++++++++++++++++++++++++++++++++ cli/cmd/createCluster.go | 30 ++++++++++++---- cli/cmd/deleteCluster.go | 28 +++++++++++++++ cli/cmd/deleteNodesHAAws.go | 68 +++++++++++++++++++++++++++++++++++ cli/cmd/flags.go | 14 ++++++-- cli/cmd/getCluster.go | 2 +- cli/cmd/switchCluster.go | 6 +++- cli/cmd/utils.go | 64 +++++++++++++++++++++++++++++++-- 8 files changed, 270 insertions(+), 14 deletions(-) create mode 100644 cli/cmd/addNodesHAAws.go create mode 100644 cli/cmd/deleteNodesHAAws.go diff --git a/cli/cmd/addNodesHAAws.go b/cli/cmd/addNodesHAAws.go new file mode 100644 index 0000000..0b6d75d --- /dev/null +++ b/cli/cmd/addNodesHAAws.go @@ -0,0 +1,72 @@ +package cmd + +// authors Dipankar + +import ( + "context" + "os" + + "github.com/ksctl/ksctl/pkg/helpers" + + "github.com/spf13/cobra" + + "github.com/ksctl/ksctl/pkg/helpers/consts" +) + +var addMoreWorkerNodesHAAws = &cobra.Command{ + Use: "add-nodes", + Short: "Use to add more worker nodes in HA aws k3s cluster", + Long: `It is used to add nodes to worker nodes in cluster with the given name from user. For example: + +ksctl create-cluster ha-azure add-nodes +`, + 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 + cli.Client.Metadata.Provider = consts.CloudAws + + SetDefaults(consts.CloudAws, 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.IsHA = true + 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 Initialize Storage Driver", "Reason", err) + os.Exit(1) + } + + if err := createApproval(cmd.Flags().Lookup("approve").Changed); err != nil { + log.Error(err.Error()) + os.Exit(1) + } + + err := controller.AddWorkerPlaneNode(&cli.Client) + if err != nil { + log.Error("Failed to scale up", "Reason", err) + os.Exit(1) + } + log.Success("Scale up successful") + }, +} + +func init() { + createClusterHAAws.AddCommand(addMoreWorkerNodesHAAws) + clusterNameFlag(addMoreWorkerNodesHAAws) + noOfWPFlag(addMoreWorkerNodesHAAws) + nodeSizeWPFlag(addMoreWorkerNodesHAAws) + regionFlag(addMoreWorkerNodesHAAws) + k8sVerFlag(addMoreWorkerNodesHAAws) + distroFlag(addMoreWorkerNodesHAAws) + storageFlag(addMoreWorkerNodesHAAws) + + addMoreWorkerNodesHAAws.MarkFlagRequired("name") + addMoreWorkerNodesHAAws.MarkFlagRequired("region") +} diff --git a/cli/cmd/createCluster.go b/cli/cmd/createCluster.go index 434b609..40f840a 100644 --- a/cli/cmd/createCluster.go +++ b/cli/cmd/createCluster.go @@ -23,14 +23,29 @@ ksctl create-cluster ["azure", "gcp", "aws", "local"] `, } -var createClusterAws = &cobra.Command{ +var createClusterHAAws = &cobra.Command{ Use: "aws", Short: "Use to create a EKS cluster in AWS", Long: `It is used to create cluster with the given name from user. For example: ksctl create-cluster aws `, - Run: func(cmd *cobra.Command, args []string) {}, + 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 + cli.Client.Metadata.Provider = consts.CloudAws + + SetDefaults(consts.CloudAws, consts.ClusterTypeHa) + + if err := safeInitializeStorageLoggerFactory(context.WithValue(context.Background(), "USERID", helpers.GetUserName())); err != nil { + log.Error("Failed Initialize Storage Driver", "Reason", err) + os.Exit(1) + } + createHA(cmd.Flags().Lookup("approve").Changed) + }, } var createClusterAzure = &cobra.Command{ @@ -51,7 +66,7 @@ var createClusterAzure = &cobra.Command{ SetDefaults(consts.CloudAzure, consts.ClusterTypeMang) if err := safeInitializeStorageLoggerFactory(context.WithValue(context.Background(), "USERID", helpers.GetUserName())); err != nil { - log.Error("Failed Inialize Storage Driver", "Reason", err) + log.Error("Failed Initialize Storage Driver", "Reason", err) os.Exit(1) } @@ -77,7 +92,7 @@ ksctl create-cluster civo SetDefaults(consts.CloudCivo, consts.ClusterTypeMang) if err := safeInitializeStorageLoggerFactory(context.WithValue(context.Background(), "USERID", helpers.GetUserName())); err != nil { - log.Error("Failed Inialize Storage Driver", "Reason", err) + log.Error("Failed Initialize Storage Driver", "Reason", err) os.Exit(1) } @@ -103,7 +118,7 @@ ksctl create-cluster local SetDefaults(consts.CloudLocal, consts.ClusterTypeMang) if err := safeInitializeStorageLoggerFactory(context.WithValue(context.Background(), "USERID", helpers.GetUserName())); err != nil { - log.Error("Failed Inialize Storage Driver", "Reason", err) + log.Error("Failed Initialize Storage Driver", "Reason", err) os.Exit(1) } @@ -154,7 +169,7 @@ var createClusterHAAzure = &cobra.Command{ SetDefaults(consts.CloudAzure, consts.ClusterTypeHa) if err := safeInitializeStorageLoggerFactory(context.WithValue(context.Background(), "USERID", helpers.GetUserName())); err != nil { - log.Error("Failed Inialize Storage Driver", "Reason", err) + log.Error("Failed Initialize Storage Driver", "Reason", err) os.Exit(1) } createHA(cmd.Flags().Lookup("approve").Changed) @@ -164,12 +179,12 @@ var createClusterHAAzure = &cobra.Command{ func init() { rootCmd.AddCommand(createClusterCmd) - createClusterCmd.AddCommand(createClusterAws) createClusterCmd.AddCommand(createClusterAzure) createClusterCmd.AddCommand(createClusterCivo) createClusterCmd.AddCommand(createClusterLocal) createClusterCmd.AddCommand(createClusterHACivo) createClusterCmd.AddCommand(createClusterHAAzure) + createClusterCmd.AddCommand(createClusterHAAws) createClusterAzure.MarkFlagRequired("name") createClusterCivo.MarkFlagRequired("name") @@ -177,4 +192,5 @@ func init() { createClusterLocal.MarkFlagRequired("name") createClusterHAAzure.MarkFlagRequired("name") createClusterHACivo.MarkFlagRequired("name") + createClusterHAAws.MarkFlagRequired("name") } diff --git a/cli/cmd/deleteCluster.go b/cli/cmd/deleteCluster.go index d245790..6a9dca1 100644 --- a/cli/cmd/deleteCluster.go +++ b/cli/cmd/deleteCluster.go @@ -75,6 +75,32 @@ ksctl delete-cluster civo }, } +var deleteClusterHAAws = &cobra.Command{ + Use: "ha-aws", + Short: "Use to delete a HA k3s cluster in Azure", + Long: `It is used to delete cluster with the given name from user. For example: + + ksctl delete-cluster ha-azure + `, + 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 + cli.Client.Metadata.Provider = consts.CloudAws + + SetDefaults(consts.CloudAws, consts.ClusterTypeHa) + + if err := safeInitializeStorageLoggerFactory(context.WithValue(context.Background(), "USERID", helpers.GetUserName())); err != nil { + log.Error("Failed Inialize Storage Driver", "Reason", err) + os.Exit(1) + } + + deleteHA(cmd.Flags().Lookup("approve").Changed) + }, +} + var deleteClusterHAAzure = &cobra.Command{ Use: "ha-azure", Short: "Use to delete a HA k3s cluster in Azure", @@ -161,6 +187,7 @@ func init() { deleteClusterCmd.AddCommand(deleteClusterHAAzure) deleteClusterCmd.AddCommand(deleteClusterAzure) deleteClusterCmd.AddCommand(deleteClusterLocal) + deleteClusterCmd.AddCommand(deleteClusterHAAws) deleteClusterAzure.MarkFlagRequired("name") deleteClusterAzure.MarkFlagRequired("region") @@ -170,4 +197,5 @@ func init() { deleteClusterHAAzure.MarkFlagRequired("region") deleteClusterHACivo.MarkFlagRequired("name") deleteClusterLocal.MarkFlagRequired("name") + deleteClusterHAAws.MarkFlagRequired("name") } diff --git a/cli/cmd/deleteNodesHAAws.go b/cli/cmd/deleteNodesHAAws.go new file mode 100644 index 0000000..890d0a4 --- /dev/null +++ b/cli/cmd/deleteNodesHAAws.go @@ -0,0 +1,68 @@ +package cmd + +// authors Dipankar + +import ( + "context" + "os" + + "github.com/ksctl/ksctl/pkg/helpers" + + "github.com/ksctl/ksctl/pkg/helpers/consts" + "github.com/spf13/cobra" +) + +var deleteNodesHAAws = &cobra.Command{ + Use: "delete-nodes", + Short: "Use to delete a HA aws k3s cluster", + Long: `It is used to delete cluster with the given name from user. For example: + +ksctl delete-cluster ha-azure delete-nodes +`, + 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 + cli.Client.Metadata.Provider = consts.CloudAws + cli.Client.Metadata.IsHA = true + + SetDefaults(consts.CloudAws, consts.ClusterTypeHa) + + cli.Client.Metadata.NoWP = noWP + cli.Client.Metadata.ClusterName = clusterName + cli.Client.Metadata.Region = region + cli.Client.Metadata.K8sDistro = consts.KsctlKubernetes(distro) + + if err := safeInitializeStorageLoggerFactory(context.WithValue(context.Background(), "USERID", helpers.GetUserName())); err != nil { + log.Error("Failed Initialize Storage Driver", "Reason", err) + os.Exit(1) + } + + if err := deleteApproval(cmd.Flags().Lookup("approve").Changed); err != nil { + log.Error(err.Error()) + os.Exit(1) + } + + err := controller.DelWorkerPlaneNode(&cli.Client) + if err != nil { + log.Error("Failed to scale down", "Reason", err) + os.Exit(1) + } + log.Success("Scale down successful") + }, +} + +func init() { + deleteClusterHAAws.AddCommand(deleteNodesHAAws) + + clusterNameFlag(deleteNodesHAAws) + noOfWPFlag(deleteNodesHAAws) + regionFlag(deleteNodesHAAws) + distroFlag(deleteNodesHAAws) + storageFlag(deleteNodesHAAws) + + deleteNodesHAAws.MarkFlagRequired("name") + deleteNodesHAAws.MarkFlagRequired("region") +} diff --git a/cli/cmd/flags.go b/cli/cmd/flags.go index 46f2d69..05a999f 100644 --- a/cli/cmd/flags.go +++ b/cli/cmd/flags.go @@ -7,24 +7,27 @@ func verboseFlags() { msgVerbose := "for verbose output" msgApproval := "approval to avoid showMsg" - //createClusterAws.Flags().BoolP("verbose", "v", true, "for verbose output") createClusterAzure.Flags().IntP("verbose", "v", 0, msgVerbose) createClusterCivo.Flags().IntP("verbose", "v", 0, msgVerbose) createClusterLocal.Flags().IntP("verbose", "v", 0, msgVerbose) createClusterHACivo.Flags().IntP("verbose", "v", 0, msgVerbose) createClusterHAAzure.Flags().IntP("verbose", "v", 0, msgVerbose) + createClusterHAAws.Flags().IntP("verbose", "v", 0, msgVerbose) deleteClusterAzure.Flags().IntP("verbose", "v", 0, msgVerbose) deleteClusterCivo.Flags().IntP("verbose", "v", 0, msgVerbose) deleteClusterHAAzure.Flags().IntP("verbose", "v", 0, msgVerbose) deleteClusterHACivo.Flags().IntP("verbose", "v", 0, msgVerbose) + deleteClusterHAAws.Flags().IntP("verbose", "v", 0, msgVerbose) deleteClusterLocal.Flags().IntP("verbose", "v", 0, msgVerbose) addMoreWorkerNodesHAAzure.Flags().IntP("verbose", "v", 0, msgVerbose) addMoreWorkerNodesHACivo.Flags().IntP("verbose", "v", 0, msgVerbose) + addMoreWorkerNodesHAAws.Flags().IntP("verbose", "v", 0, msgVerbose) deleteNodesHAAzure.Flags().IntP("verbose", "v", 0, msgVerbose) deleteNodesHACivo.Flags().IntP("verbose", "v", 0, msgVerbose) + deleteNodesHAAws.Flags().IntP("verbose", "v", 0, msgVerbose) getClusterCmd.Flags().IntP("verbose", "v", 0, msgVerbose) switchCluster.Flags().IntP("verbose", "v", 0, msgVerbose) @@ -34,15 +37,22 @@ func verboseFlags() { createClusterLocal.Flags().BoolP("approve", "", true, msgApproval) createClusterHACivo.Flags().BoolP("approve", "", true, msgApproval) createClusterHAAzure.Flags().BoolP("approve", "", true, msgApproval) + createClusterHAAws.Flags().BoolP("approve", "", true, msgApproval) + + deleteClusterLocal.Flags().BoolP("approve", "", true, msgApproval) deleteClusterAzure.Flags().BoolP("approve", "", true, msgApproval) deleteClusterCivo.Flags().BoolP("approve", "", true, msgApproval) deleteClusterHAAzure.Flags().BoolP("approve", "", true, msgApproval) deleteClusterHACivo.Flags().BoolP("approve", "", true, msgApproval) - deleteClusterLocal.Flags().BoolP("approve", "", true, msgApproval) + deleteClusterHAAws.Flags().BoolP("approve", "", true, msgApproval) + addMoreWorkerNodesHAAzure.Flags().BoolP("approve", "", true, msgApproval) addMoreWorkerNodesHACivo.Flags().BoolP("approve", "", true, msgApproval) + addMoreWorkerNodesHAAws.Flags().BoolP("approve", "", true, msgApproval) + deleteNodesHAAzure.Flags().BoolP("approve", "", true, msgApproval) deleteNodesHACivo.Flags().BoolP("approve", "", true, msgApproval) + deleteNodesHAAws.Flags().BoolP("approve", "", true, msgApproval) } func storageFlag(f *cobra.Command) { diff --git a/cli/cmd/getCluster.go b/cli/cmd/getCluster.go index 2b63663..8d5dadd 100644 --- a/cli/cmd/getCluster.go +++ b/cli/cmd/getCluster.go @@ -40,7 +40,7 @@ ksctl get-clusters `, } if err := safeInitializeStorageLoggerFactory(context.WithValue(context.Background(), "USERID", helpers.GetUserName())); err != nil { - log.Error("Failed Inialize Storage Driver", "Reason", err) + log.Error("Failed Initialize Storage Driver", "Reason", err) os.Exit(1) } diff --git a/cli/cmd/switchCluster.go b/cli/cmd/switchCluster.go index 0545118..4127d26 100644 --- a/cli/cmd/switchCluster.go +++ b/cli/cmd/switchCluster.go @@ -18,7 +18,7 @@ var switchCluster = &cobra.Command{ Short: "Use to switch between clusters", Long: `It is used to switch cluster with the given ClusterName from user. For example: -ksctl switch-context -p -n -r +ksctl switch-context -p -n -r `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") @@ -52,6 +52,10 @@ ksctl switch-context -p -n -r 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 } diff --git a/cli/cmd/utils.go b/cli/cmd/utils.go index 9c9a661..96fc72e 100644 --- a/cli/cmd/utils.go +++ b/cli/cmd/utils.go @@ -211,7 +211,7 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType region = "LON1" } if len(k8sVer) == 0 { - k8sVer = "1.27.1" + k8sVer = "1.28.7" } if len(storage) == 0 { storage = string(consts.StoreLocal) @@ -240,7 +240,42 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType noCP = 3 } if noDS == -1 { - noDS = 1 + noDS = 3 + } + if len(k8sVer) == 0 { + k8sVer = "1.27.1" + } + if len(distro) == 0 { + distro = string(consts.K8sK3s) + } + if len(storage) == 0 { + storage = string(consts.StoreLocal) + } + + case string(consts.CloudAws) + string(consts.ClusterTypeHa): + if len(nodeSizeCP) == 0 { + nodeSizeCP = "t2.micro" + } + if len(nodeSizeWP) == 0 { + nodeSizeWP = "t2.micro" + } + if len(nodeSizeDS) == 0 { + nodeSizeDS = "t2.micro" + } + if len(nodeSizeLB) == 0 { + nodeSizeLB = "t2.micro" + } + if len(region) == 0 { + region = "us-east-1" + } + if noWP == -1 { + noWP = 1 + } + if noCP == -1 { + noCP = 3 + } + if noDS == -1 { + noDS = 3 } if len(k8sVer) == 0 { k8sVer = "1.27.1" @@ -275,7 +310,7 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType noCP = 3 } if noDS == -1 { - noDS = 1 + noDS = 3 } if len(k8sVer) == 0 { k8sVer = "1.27.1" @@ -354,6 +389,22 @@ func argsFlags() { k8sVerFlag(createClusterHACivo) storageFlag(createClusterHACivo) + // HA Aws + clusterNameFlag(createClusterHAAws) + nodeSizeCPFlag(createClusterHAAws) + nodeSizeDSFlag(createClusterHAAws) + nodeSizeWPFlag(createClusterHAAws) + nodeSizeLBFlag(createClusterHAAws) + regionFlag(createClusterHAAws) + appsFlag(createClusterHAAws) + cniFlag(createClusterHAAws) + noOfWPFlag(createClusterHAAws) + noOfCPFlag(createClusterHAAws) + noOfDSFlag(createClusterHAAws) + distroFlag(createClusterHAAws) + k8sVerFlag(createClusterHAAws) + storageFlag(createClusterHAAws) + // HA Azure clusterNameFlag(createClusterHAAzure) nodeSizeCPFlag(createClusterHAAzure) @@ -386,6 +437,11 @@ func argsFlags() { storageFlag(deleteClusterCivo) // HA Civo + clusterNameFlag(deleteClusterHAAws) + regionFlag(deleteClusterHAAws) + storageFlag(deleteClusterHAAws) + + // HA Aws clusterNameFlag(deleteClusterHACivo) regionFlag(deleteClusterHACivo) storageFlag(deleteClusterHACivo) @@ -405,12 +461,14 @@ func AllFeatures() { featureFlag(createClusterCivo) featureFlag(createClusterHACivo) featureFlag(createClusterLocal) + featureFlag(createClusterHAAws) featureFlag(deleteClusterAzure) featureFlag(deleteClusterHAAzure) featureFlag(deleteClusterCivo) featureFlag(deleteClusterHACivo) featureFlag(deleteClusterLocal) + featureFlag(deleteClusterHAAws) featureFlag(addMoreWorkerNodesHACivo) featureFlag(addMoreWorkerNodesHAAzure) From ca742f0029ad0c1c0b7b799f66422551661b2042 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:21:17 +0530 Subject: [PATCH 03/12] removed the github workflow for stale Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- .github/workflows/stale.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .github/workflows/stale.yml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml deleted file mode 100644 index 90f4e1d..0000000 --- a/.github/workflows/stale.yml +++ /dev/null @@ -1,27 +0,0 @@ -# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time. -# -# You can adjust the behavior by modifying this file. -# For more information, see: -# https://github.com/actions/stale -name: Mark stale issues and pull requests - -on: - schedule: - - cron: '28 13 * * *' - -jobs: - stale: - - runs-on: ubuntu-latest - permissions: - issues: write - pull-requests: write - - steps: - - uses: actions/stale@v5 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'Stale issue message' - stale-pr-message: 'Stale pull request message' - stale-issue-label: 'no-issue-activity' - stale-pr-label: 'no-pr-activity' From a22b90c851e54609a56f88c15537bada4d356fe9 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:32:25 +0530 Subject: [PATCH 04/12] feat: improved the scripts for development Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- Makefile | 65 +++++++++++++++++++++++++++++++++++++++---- scripts/builder.ps1 | 14 +--------- scripts/builder.sh | 11 -------- scripts/install.ps1 | 13 +-------- scripts/install.sh | 10 ------- scripts/test-api.ps1 | 55 ------------------------------------ scripts/test-api.sh | 49 -------------------------------- scripts/uninstall.ps1 | 2 +- scripts/uninstall.sh | 5 ---- 9 files changed, 62 insertions(+), 162 deletions(-) delete mode 100644 scripts/test-api.ps1 delete mode 100755 scripts/test-api.sh diff --git a/Makefile b/Makefile index 48978aa..517bcc8 100644 --- a/Makefile +++ b/Makefile @@ -2,29 +2,82 @@ GOOS_LINUX = linux GOOS_WINDOWS = windows GOOS_MACOS = darwin -GOARCH_LINUX = amd64 -GOARCH_WINDOWS = amd64 +GOARCH_LINUX ?= amd64 +GOARCH_WINDOWS ?= amd64 GOARCH_MACOS = arm64 GOARCH_MACOS_INTEL = amd64 CURR_TIME = $(shell date +%s) -install_linux: +.PHONY: help +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "\n\033[36m _ _ _ \n | | | | | |\n | | _____ ___| |_| |\n | |/ / __|/ __| __| |\n | <\\__ \\ (__| |_| |\n |_|\\_\\___/\\___|\\__|_| \033[0m\n\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + +##@ Install (Dev) + +.PHONY: install_linux +install_linux: ## Install ksctl @echo "Started to Install ksctl" cd scripts && \ env GOOS=${GOOS_LINUX} GOARCH=${GOARCH_LINUX} ./builder.sh -install_macos: +.PHONY: install_macos +install_macos: ## Install ksctl on macos m1,m2,.. @echo "Started to Install ksctl" cd scripts && \ env GOOS=${GOOS_MACOS} GOARCH=${GOARCH_MACOS} ./builder.sh -install_macos_intel: +.PHONY: install_macos_intel +install_macos_intel: ## Install ksctl on macos intel @echo "Started to Install ksctl" cd scripts && \ env GOOS=${GOOS_MACOS} GOARCH=${GOARCH_MACOS_INTEL} ./builder.sh -uninstall: +.PHONY: uninstall +uninstall: ## Uninstall ksctl @echo "Started to Uninstall ksctl" cd scripts && \ ./uninstall.sh + +##@ Linters +.PHONY: golangci-lint +golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. +$(GOLANGCI_LINT): $(LOCALBIN) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION}) + +.PHONY: lint +lint: golangci-lint ## Run golangci-lint linter & yamllint + $(GOLANGCI_LINT) run && echo -e "\n=========\n\033[91m✔ PASSED\033[0m\n=========\n" || echo -e "\n=========\n\033[91m✖ FAILED\033[0m\n=========\n" + + +##@ Dependencies (Controller) + +## Location to install dependencies to +LOCALBIN ?= /tmp/bin +$(LOCALBIN): + mkdir -p $(LOCALBIN) + +## Tool Binaries +GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) + +## Tool Versions +GOLANGCI_LINT_VERSION ?= v1.54.2 + +.PHONY: golangci-lint +golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. +$(GOLANGCI_LINT): $(LOCALBIN) + $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION}) + +# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist +# $1 - target path with name of binary (ideally with version) +# $2 - package url which can be installed +# $3 - specific version of package +define go-install-tool +@[ -f $(1) ] || { \ +set -e; \ +package=$(2)@$(3) ;\ +echo "Downloading $${package}" ;\ +GOBIN=$(LOCALBIN) go install $${package} ;\ +mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\ +} +endef \ No newline at end of file diff --git a/scripts/builder.ps1 b/scripts/builder.ps1 index 1f6ba4e..60039b7 100644 --- a/scripts/builder.ps1 +++ b/scripts/builder.ps1 @@ -3,25 +3,13 @@ $erroractionpreference = 'stop' # quit if anything goes wrong if (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Output "PowerShell 5 or later is required to run Datree." + 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 -mkdir -Force $env:USERPROFILE\.ksctl\cred -mkdir -Force $env:USERPROFILE\.ksctl\config\civo -mkdir -Force $env:USERPROFILE\.ksctl\config\civo\ha -mkdir -Force $env:USERPROFILE\.ksctl\config\civo\managed -mkdir -Force $env:USERPROFILE\.ksctl\config\azure -mkdir -Force $env:USERPROFILE\.ksctl\config\azure\ha -mkdir -Force $env:USERPROFILE\.ksctl\config\azure\managed -mkdir -Force $env:USERPROFILE\.ksctl\config\aws\ha -mkdir -Force $env:USERPROFILE\.ksctl\config\aws\managed -mkdir -Force $env:USERPROFILE\.ksctl\config\local -mkdir -Force $env:USERPROFILE\.ksctl\config\local\managed - $env:GOOS = 'windows' $env:GOARCH = 'amd64' Set-Location .\.. diff --git a/scripts/builder.sh b/scripts/builder.sh index 9bab8b5..856c2ec 100755 --- a/scripts/builder.sh +++ b/scripts/builder.sh @@ -11,17 +11,6 @@ chmod +x ksctl sudo mv -v ksctl /usr/local/bin/ksctl -# Setup the configurations dir -mkdir -p ${HOME}/.ksctl/cred - -mkdir -p ${HOME}/.ksctl/config/civo/ha -mkdir -p ${HOME}/.ksctl/config/civo/managed -mkdir -p ${HOME}/.ksctl/config/azure/ha -mkdir -p ${HOME}/.ksctl/config/azure/managed -mkdir -p ${HOME}/.ksctl/config/aws/managed -mkdir -p ${HOME}/.ksctl/config/aws/ha -mkdir -p ${HOME}/.ksctl/config/local/managed - echo -e "\033[1;32mINSTALL COMPLETE\033[0m\n" cd - || echo -e "\033[1;31mFailed to move to previous directory\033[0m\n" diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 645372b..4c7132c 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -3,24 +3,13 @@ $erroractionpreference = 'stop' # quit if anything goes wrong if (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Output "PowerShell 5 or later is required to run Datree." + 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 -mkdir -Force $env:USERPROFILE\.ksctl\cred -mkdir -Force $env:USERPROFILE\.ksctl\config\civo -mkdir -Force $env:USERPROFILE\.ksctl\config\civo\ha -mkdir -Force $env:USERPROFILE\.ksctl\config\civo\managed -mkdir -Force $env:USERPROFILE\.ksctl\config\azure -mkdir -Force $env:USERPROFILE\.ksctl\config\azure\ha -mkdir -Force $env:USERPROFILE\.ksctl\config\azure\managed -mkdir -Force $env:USERPROFILE\.ksctl\config\aws\ha -mkdir -Force $env:USERPROFILE\.ksctl\config\aws\managed -mkdir -Force $env:USERPROFILE\.ksctl\config\local -mkdir -Force $env:USERPROFILE\.ksctl\config\local\managed Write-Host "Available Releases" -ForegroundColor Cyan diff --git a/scripts/install.sh b/scripts/install.sh index 90758fb..1c2ff1f 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -94,15 +94,5 @@ fi sudo tar -xvf ksctl-cli_${RELEASE_VERSION}_${OS}_${ARCH}.tar.gz sudo mv -v ksctl /usr/local/bin/ksctl -# Setup the configurations dir -mkdir -p ${HOME}/.ksctl/cred - -mkdir -p ${HOME}/.ksctl/config/civo/ha -mkdir -p ${HOME}/.ksctl/config/civo/managed -mkdir -p ${HOME}/.ksctl/config/azure/ha -mkdir -p ${HOME}/.ksctl/config/azure/managed -mkdir -p ${HOME}/.ksctl/config/aws/managed -mkdir -p ${HOME}/.ksctl/config/aws/ha -mkdir -p ${HOME}/.ksctl/config/local/managed echo -e "${Green}INSTALL COMPLETE${NoColor}" diff --git a/scripts/test-api.ps1 b/scripts/test-api.ps1 deleted file mode 100644 index dc95951..0000000 --- a/scripts/test-api.ps1 +++ /dev/null @@ -1,55 +0,0 @@ -#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 Datree." - Write-Output "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break -} - -Set-Location .\..\pkg\ - -Write-Output "-----------------------------------" -Write-Output "| Testing (pkg/utils)" -Write-Output "-----------------------------------" - -Set-Location utils -go test . -v && Set-Location - - -Write-Output "-----------------------------------" -Write-Output "| Testing (pkg/logger)" -Write-Output "-----------------------------------" - -Set-Location logger -go test . -v && Set-Location - - -Set-Location .\..\internal - -Write-Output "--------------------------------------------" -Write-Output "| Testing (internal/k8sdistros/k3s)" -Write-Output "--------------------------------------------" - -Set-Location k8sdistros\k3s -go test . -v && Set-Location - - -Write-Output "--------------------------------------------" -Write-Output "| Testing (internal/cloudproviders/local)" -Write-Output "--------------------------------------------" - -Set-Location cloudproviders\local -go test . -v && Set-Location - - -Write-Output "--------------------------------------------" -Write-Output "| Testing (internal/cloudproviders/civo)" -Write-Output "--------------------------------------------" - -Set-Location cloudproviders\civo -go test . -v && Set-Location - - -Write-Output "--------------------------------------------" -Write-Output "| Testing (internal/cloudproviders/azure)" -Write-Output "--------------------------------------------" - -Set-Location cloudproviders\azure -go test . -v && Set-Location - diff --git a/scripts/test-api.sh b/scripts/test-api.sh deleted file mode 100755 index 3c83edf..0000000 --- a/scripts/test-api.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh - -cd ../pkg/ || exit 1 - -echo "-----------------------------------" -echo "| Testing (pkg/utils)" -echo "-----------------------------------" - -cd utils/ -go test . -v && cd - - -echo "-----------------------------------" -echo "| Testing (pkg/logger)" -echo "-----------------------------------" - -cd logger/ -go test . -v -timeout 10s && cd - - -cd ../internal - -echo "--------------------------------------------" -echo "| Testing (internal/k8sdistros/k3s)" -echo "--------------------------------------------" - -cd k8sdistros/k3s/ -go test . -v && cd - - -echo "--------------------------------------------" -echo "| Testing (internal/cloudproviders/local)" -echo "--------------------------------------------" - -cd cloudproviders/local/ -go test . -v && cd - - - -echo "--------------------------------------------" -echo "| Testing (internal/cloudproviders/civo)" -echo "--------------------------------------------" - -cd cloudproviders/civo/ -go test . -v && cd - - -echo "--------------------------------------------" -echo "| Testing (internal/cloudproviders/azure)" -echo "--------------------------------------------" - -cd cloudproviders/azure/ -go test . -v && cd - - diff --git a/scripts/uninstall.ps1 b/scripts/uninstall.ps1 index b04151d..4e4e1aa 100644 --- a/scripts/uninstall.ps1 +++ b/scripts/uninstall.ps1 @@ -4,7 +4,7 @@ $old_erroractionpreference = $erroractionpreference $erroractionpreference = 'stop' # quit if anything goes wrong if (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Output "PowerShell 5 or later is required to run Datree." + 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 } diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh index f0809e4..80977dd 100755 --- a/scripts/uninstall.sh +++ b/scripts/uninstall.sh @@ -1,10 +1,5 @@ #!/bin/bash - sudo rm -vf /usr/local/bin/ksctl - -# Setup the ~/.kube -rm -rfv ${HOME}/.ksctl - echo -e "\033[1;32mUNINSTALL COMPLETE\033[0m\n" From 664231488e0fb1291036eb0b8a1bc071bc492439 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:40:46 +0530 Subject: [PATCH 05/12] improved the test cases for the aws Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- .github/workflows/test-mock.yml | 57 +++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-mock.yml b/.github/workflows/test-mock.yml index a7f2c20..d1fe907 100644 --- a/.github/workflows/test-mock.yml +++ b/.github/workflows/test-mock.yml @@ -51,6 +51,12 @@ jobs: .\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: aws create + working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' + run: | + # .\ksctl.exe create aws -n demo -r fake --nodeSizeMP "fake" -s local --verbose -1 --approve + .\ksctl.exe create ha-aws -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: | @@ -66,6 +72,11 @@ jobs: run: | .\ksctl.exe get -s local -p azure + - name: aws get + working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' + run: | + .\ksctl.exe get -s local -p aws + - name: get all working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' run: | @@ -77,13 +88,18 @@ jobs: .\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: aws switch + working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' + run: | + # .\ksctl.exe switch -p aws -n demo -s local -r fake + .\ksctl.exe switch -p ha-aws -n ha-demo -s local -r fake + - name: azure switch working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' run: | .\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: | @@ -96,6 +112,12 @@ jobs: .\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: aws scale up and down + working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' + run: | + .\ksctl.exe delete ha-aws delete-nodes -n ha-demo --noWP 0 -r fake -s local --approve -v -1 + .\ksctl.exe create ha-aws 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: | @@ -109,6 +131,12 @@ jobs: .\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: aws delete + working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' + run: | + # .\ksctl.exe delete aws -n demo -r fake -s local -v -1 --approve + .\ksctl.exe delete ha-aws -n ha-demo -r fake -s local -v -1 --approve + - name: local delete working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' run: | @@ -148,11 +176,17 @@ jobs: run: | 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" -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: aws create + run: | + # ksctl create aws -n demo -r fake --nodeSizeMP "fake" -s local --verbose -1 --approve + ksctl create ha-aws -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 -s local --verbose -1 --approve @@ -160,9 +194,15 @@ jobs: - name: civo get run: | ksctl get -p civo -s local + - name: azure get run: | ksctl get -p azure -s local + + - name: aws get + run: | + ksctl get -p aws -s local + - name: all run: | ksctl get -s local @@ -177,6 +217,10 @@ jobs: ksctl switch -p azure -n demo -s local -r fake ksctl switch -p ha-azure -n ha-demo -s local -r fake + - name: aws switch + run: | + # ksctl switch -p aws -n demo -s local -r fake + ksctl switch -p ha-aws -n ha-demo -s local -r fake - name: civo scale up and down run: | @@ -188,17 +232,26 @@ jobs: 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: aws scale up and down + run: | + ksctl delete ha-aws delete-nodes -n ha-demo --noWP 0 -s local -r fake --approve -v -1 + ksctl create ha-aws 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 -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 -s local -v -1 --approve ksctl delete ha-azure -n ha-demo -r fake -s local -v -1 --approve + - name: aws delete + run: | + # ksctl delete aws -n demo -r fake -s local -v -1 --approve + ksctl delete ha-aws -n ha-demo -r fake -s local -v -1 --approve + - name: local delete run: | ksctl delete local -n demolocal -v -1 -s local --approve From a40453908f511da06e824f28efb7760a911e802d Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Mon, 29 Apr 2024 18:25:38 +0530 Subject: [PATCH 06/12] some fixes to the aws Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- cli/cmd/createCluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/cmd/createCluster.go b/cli/cmd/createCluster.go index 40f840a..d91a5d9 100644 --- a/cli/cmd/createCluster.go +++ b/cli/cmd/createCluster.go @@ -24,7 +24,7 @@ ksctl create-cluster ["azure", "gcp", "aws", "local"] } var createClusterHAAws = &cobra.Command{ - Use: "aws", + Use: "ha-aws", Short: "Use to create a EKS cluster in AWS", Long: `It is used to create cluster with the given name from user. For example: From c2aeddbf96e18f3fda638dd9300d8bf3e24115f7 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Mon, 29 Apr 2024 22:23:42 +0530 Subject: [PATCH 07/12] updates: added improvements Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- cli/cmd/createCluster.go | 12 +++--- cli/cmd/deleteCluster.go | 8 ++-- cli/cmd/deleteNodesHAAws.go | 4 +- cli/cmd/deleteNodesHAAzure.go | 4 +- cli/cmd/deleteNodesHACivo.go | 4 +- cli/cmd/root.go | 12 +++++- cli/cmd/switchCluster.go | 2 +- cli/cmd/utils.go | 74 +++++++++++++++++++++++++++++------ 8 files changed, 89 insertions(+), 31 deletions(-) diff --git a/cli/cmd/createCluster.go b/cli/cmd/createCluster.go index d91a5d9..3f6d727 100644 --- a/cli/cmd/createCluster.go +++ b/cli/cmd/createCluster.go @@ -28,7 +28,7 @@ var createClusterHAAws = &cobra.Command{ Short: "Use to create a EKS cluster in AWS", Long: `It is used to create cluster with the given name from user. For example: -ksctl create-cluster aws +ksctl create-cluster ha-aws `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") @@ -53,7 +53,7 @@ var createClusterAzure = &cobra.Command{ Short: "Use to create a AKS cluster in Azure", Long: `It is used to create cluster with the given name from user. For example: - ksctl create-cluster azure + ksctl create-cluster azure `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") @@ -79,7 +79,7 @@ var createClusterCivo = &cobra.Command{ Short: "Use to create a CIVO k3s cluster", Long: `It is used to create cluster with the given name from user. For example: -ksctl create-cluster civo +ksctl create-cluster civo `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") @@ -105,7 +105,7 @@ var createClusterLocal = &cobra.Command{ Short: "Use to create a LOCAL cluster in Docker", Long: `It is used to create cluster with the given name from user. For example: -ksctl create-cluster local +ksctl create-cluster local `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") @@ -131,7 +131,7 @@ var createClusterHACivo = &cobra.Command{ Short: "Use to create a HA CIVO k3s cluster", Long: `It is used to create cluster with the given name from user. For example: -ksctl create-cluster ha-civo +ksctl create-cluster ha-civo `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") @@ -156,7 +156,7 @@ var createClusterHAAzure = &cobra.Command{ Short: "Use to create a HA k3s cluster in Azure", Long: `It is used to create cluster with the given name from user. For example: - ksctl create-cluster ha-azure + ksctl create-cluster ha-azure `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") diff --git a/cli/cmd/deleteCluster.go b/cli/cmd/deleteCluster.go index 6a9dca1..7a068d2 100644 --- a/cli/cmd/deleteCluster.go +++ b/cli/cmd/deleteCluster.go @@ -18,7 +18,7 @@ var deleteClusterCmd = &cobra.Command{ Aliases: []string{"delete"}, Long: `It is used to delete cluster of given provider. For example: -ksctl delete-cluster ["azure", "ha-", "civo", "local"] +ksctl delete-cluster ["aws","azure", "ha-", "civo", "local"] `, } @@ -80,7 +80,7 @@ var deleteClusterHAAws = &cobra.Command{ Short: "Use to delete a HA k3s cluster in Azure", Long: `It is used to delete cluster with the given name from user. For example: - ksctl delete-cluster ha-azure + ksctl delete-cluster ha-aws `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") @@ -106,7 +106,7 @@ var deleteClusterHAAzure = &cobra.Command{ Short: "Use to delete a HA k3s cluster in Azure", Long: `It is used to delete cluster with the given name from user. For example: - ksctl delete-cluster ha-azure + ksctl delete-cluster ha-azure `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") @@ -132,7 +132,7 @@ var deleteClusterHACivo = &cobra.Command{ Short: "Use to delete a HA CIVO k3s cluster", Long: `It is used to delete cluster with the given name from user. For example: -ksctl delete-cluster ha-civo +ksctl delete-cluster ha-civo `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") diff --git a/cli/cmd/deleteNodesHAAws.go b/cli/cmd/deleteNodesHAAws.go index 890d0a4..240ac6a 100644 --- a/cli/cmd/deleteNodesHAAws.go +++ b/cli/cmd/deleteNodesHAAws.go @@ -13,11 +13,11 @@ import ( ) var deleteNodesHAAws = &cobra.Command{ - Use: "delete-nodes", + Use: "del-nodes", Short: "Use to delete a HA aws k3s cluster", Long: `It is used to delete cluster with the given name from user. For example: -ksctl delete-cluster ha-azure delete-nodes +ksctl delete-cluster ha-aws delete-nodes `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") diff --git a/cli/cmd/deleteNodesHAAzure.go b/cli/cmd/deleteNodesHAAzure.go index fe2a8bf..964bd40 100644 --- a/cli/cmd/deleteNodesHAAzure.go +++ b/cli/cmd/deleteNodesHAAzure.go @@ -13,11 +13,11 @@ import ( ) var deleteNodesHAAzure = &cobra.Command{ - Use: "delete-nodes", + Use: "del-nodes", Short: "Use to delete a HA azure k3s cluster", Long: `It is used to delete cluster with the given name from user. For example: -ksctl delete-cluster ha-azure delete-nodes +ksctl delete-cluster ha-azure delete-nodes `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") diff --git a/cli/cmd/deleteNodesHACivo.go b/cli/cmd/deleteNodesHACivo.go index 7ace6fb..f6bc6a9 100644 --- a/cli/cmd/deleteNodesHACivo.go +++ b/cli/cmd/deleteNodesHACivo.go @@ -13,11 +13,11 @@ import ( ) var deleteNodesHACivo = &cobra.Command{ - Use: "delete-nodes", + Use: "del-nodes", Short: "Use to delete a HA CIVO k3s cluster", Long: `It is used to delete cluster with the given name from user. For example: -ksctl delete-cluster ha-civo delete-nodes +ksctl delete-cluster ha-civo delete-nodes `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 1c74a74..2be7a78 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -59,11 +59,19 @@ var ( var rootCmd = &cobra.Command{ Use: "ksctl", Short: "CLI tool for managing multiple K8s clusters", - Long: `CLI tool which can manage multiple K8s clusters + Long: ` + _ _ _ + | | | | | | + | | _____ ___| |_| | + | |/ / __|/ __| __| | + | <\__ \ (__| |_| | + |_|\_\___/\___|\__|_| + + CLI tool which can manage multiple K8s clusters from local clusters to cloud provider specific clusters.`, // Uncomment the following line if your bare application // has an action associated with it: - // Run: func(cmd *cobra.Command, args []string) { }, + // Run: func(cmd *cobra.Command, args []string) {}, } // Execute adds all child commands to the root command and sets flags appropriately. diff --git a/cli/cmd/switchCluster.go b/cli/cmd/switchCluster.go index 4127d26..73df37c 100644 --- a/cli/cmd/switchCluster.go +++ b/cli/cmd/switchCluster.go @@ -18,7 +18,7 @@ var switchCluster = &cobra.Command{ Short: "Use to switch between clusters", Long: `It is used to switch cluster with the given ClusterName from user. For example: -ksctl switch-context -p -n -r +ksctl switch-context -p -n -r `, Run: func(cmd *cobra.Command, args []string) { verbosity, _ := cmd.Flags().GetInt("verbose") diff --git a/cli/cmd/utils.go b/cli/cmd/utils.go index 96fc72e..3f91243 100644 --- a/cli/cmd/utils.go +++ b/cli/cmd/utils.go @@ -219,10 +219,18 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType case string(consts.CloudAzure) + string(consts.ClusterTypeHa): if len(nodeSizeCP) == 0 { - nodeSizeCP = "Standard_F2s" + if distro == string(consts.K8sKubeadm) { + nodeSizeCP = "Standard_F2s" + } else { + nodeSizeCP = "Standard_F2s" + } } if len(nodeSizeWP) == 0 { - nodeSizeWP = "Standard_F2s" + if distro == string(consts.K8sKubeadm) { + nodeSizeWP = "Standard_F4s" + } else { + nodeSizeWP = "Standard_F2s" + } } if len(nodeSizeDS) == 0 { nodeSizeDS = "Standard_F2s" @@ -234,7 +242,11 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType region = "eastus" } if noWP == -1 { - noWP = 1 + if distro == string(consts.K8sKubeadm) { + noWP = 2 + } else { + noWP = 1 + } } if noCP == -1 { noCP = 3 @@ -243,7 +255,11 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType noDS = 3 } if len(k8sVer) == 0 { - k8sVer = "1.27.1" + if distro == string(consts.K8sKubeadm) { + k8sVer = "1.30" + } else { + k8sVer = "1.29.4" + } } if len(distro) == 0 { distro = string(consts.K8sK3s) @@ -254,10 +270,18 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType case string(consts.CloudAws) + string(consts.ClusterTypeHa): if len(nodeSizeCP) == 0 { - nodeSizeCP = "t2.micro" + if distro == string(consts.K8sKubeadm) { + nodeSizeCP = "t2.medium" + } else { + nodeSizeCP = "t2.micro" + } } if len(nodeSizeWP) == 0 { - nodeSizeWP = "t2.micro" + if distro == string(consts.K8sKubeadm) { + nodeSizeWP = "t2.medium" + } else { + nodeSizeWP = "t2.micro" + } } if len(nodeSizeDS) == 0 { nodeSizeDS = "t2.micro" @@ -269,7 +293,11 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType region = "us-east-1" } if noWP == -1 { - noWP = 1 + if distro == string(consts.K8sKubeadm) { + noWP = 2 + } else { + noWP = 1 + } } if noCP == -1 { noCP = 3 @@ -278,7 +306,11 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType noDS = 3 } if len(k8sVer) == 0 { - k8sVer = "1.27.1" + if distro == string(consts.K8sKubeadm) { + k8sVer = "1.30" + } else { + k8sVer = "1.29.4" + } } if len(distro) == 0 { distro = string(consts.K8sK3s) @@ -286,13 +318,23 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType if len(storage) == 0 { storage = string(consts.StoreLocal) } + // also check for the cni plugin as in the future relase it will be required + // for installing ksctl agents into the cluster case string(consts.CloudCivo) + string(consts.ClusterTypeHa): if len(nodeSizeCP) == 0 { - nodeSizeCP = "g3.small" + if distro == string(consts.K8sKubeadm) { + nodeSizeCP = "g3.large" + } else { + nodeSizeCP = "g3.medium" + } } if len(nodeSizeWP) == 0 { - nodeSizeWP = "g3.large" + if distro == string(consts.K8sKubeadm) { + nodeSizeWP = "g3.large" + } else { + nodeSizeWP = "g3.medium" + } } if len(nodeSizeDS) == 0 { nodeSizeDS = "g3.small" @@ -304,7 +346,11 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType region = "LON1s" } if noWP == -1 { - noWP = 1 + if distro == string(consts.K8sKubeadm) { + noWP = 2 + } else { + noWP = 1 + } } if noCP == -1 { noCP = 3 @@ -313,7 +359,11 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType noDS = 3 } if len(k8sVer) == 0 { - k8sVer = "1.27.1" + if distro == string(consts.K8sKubeadm) { + k8sVer = "1.30" + } else { + k8sVer = "1.29.4" + } } if len(storage) == 0 { storage = string(consts.StoreLocal) From fcd3e6d82c7d663cfbfb3a350399449ca510ee32 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Mon, 29 Apr 2024 22:50:32 +0530 Subject: [PATCH 08/12] fix: failing k8s ver Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- cli/cmd/utils.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/cmd/utils.go b/cli/cmd/utils.go index 3f91243..ad4cbe0 100644 --- a/cli/cmd/utils.go +++ b/cli/cmd/utils.go @@ -256,7 +256,7 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType } if len(k8sVer) == 0 { if distro == string(consts.K8sKubeadm) { - k8sVer = "1.30" + k8sVer = "1.29" } else { k8sVer = "1.29.4" } @@ -307,7 +307,7 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType } if len(k8sVer) == 0 { if distro == string(consts.K8sKubeadm) { - k8sVer = "1.30" + k8sVer = "1.29" } else { k8sVer = "1.29.4" } @@ -360,7 +360,7 @@ func SetDefaults(provider consts.KsctlCloud, clusterType consts.KsctlClusterType } if len(k8sVer) == 0 { if distro == string(consts.K8sKubeadm) { - k8sVer = "1.30" + k8sVer = "1.29" } else { k8sVer = "1.29.4" } From 038c9260d64d33e24fc1ebe85634f89f499c1bdd Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Tue, 30 Apr 2024 00:04:20 +0530 Subject: [PATCH 09/12] fix: failing mock tests Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- .github/workflows/test-mock.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test-mock.yml b/.github/workflows/test-mock.yml index d1fe907..abb2789 100644 --- a/.github/workflows/test-mock.yml +++ b/.github/workflows/test-mock.yml @@ -42,25 +42,25 @@ 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 -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 + .\ksctl.exe create civo -n demo -r LON1 --nodeSizeMP "g4s.kube.small" --version 1.27.1 --verbose -1 -s local --approve + .\ksctl.exe create ha-civo -n ha-demo --nodeSizeDS "fake.small" --version 1.27.1--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" -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 + .\ksctl.exe create azure -n demo -r fake --nodeSizeMP "fake" -s local --version 1.27.1 --verbose -1 --approve + .\ksctl.exe create ha-azure -n ha-demo --nodeSizeDS "fake" --version 1.27.1 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s local --approve - name: aws create working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' run: | - # .\ksctl.exe create aws -n demo -r fake --nodeSizeMP "fake" -s local --verbose -1 --approve - .\ksctl.exe create ha-aws -n ha-demo --nodeSizeDS "fake" --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s local --approve + # .\ksctl.exe create aws -n demo -r fake --nodeSizeMP "fake" --version 1.27.1 -s local --verbose -1 --approve + .\ksctl.exe create ha-aws -n ha-demo --nodeSizeDS "fake" --version 1.27.1 --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 -s local --approve + .\ksctl.exe create local -n demolocal --version 1.27.1 --verbose -1 -s local --approve - name: civo get working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' @@ -174,18 +174,18 @@ jobs: - name: civo create run: | - 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 + ksctl create civo -n demo -r LON1 --nodeSizeMP "g4s.kube.small" --version 1.27.1 -s local --verbose -1 --approve + ksctl create ha-civo -n ha-demo --nodeSizeDS "fake.small" -s local --version 1.27.1 --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" -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 + ksctl create azure -n demo -r fake --nodeSizeMP "fake" -s local --version 1.27.1 --verbose -1 --approve + ksctl create ha-azure -n ha-demo --nodeSizeDS "fake" -s local --nodeSizeLB "fake" --version 1.27.1 --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 --approve - name: aws create run: | - # ksctl create aws -n demo -r fake --nodeSizeMP "fake" -s local --verbose -1 --approve - ksctl create ha-aws -n ha-demo --nodeSizeDS "fake" -s local --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 --approve + # ksctl create aws -n demo -r fake --nodeSizeMP "fake" -s local --version 1.27.1 --verbose -1 --approve + ksctl create ha-aws -n ha-demo --nodeSizeDS "fake" -s local --nodeSizeLB "fake" --version 1.27.1 --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 --approve - name: local create run: | @@ -260,4 +260,4 @@ jobs: 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" \ No newline at end of file + ksctl create local -n demolocal -s local123 -v -1 --approve || echo "Expected to fail :) due to invalid provider name" From 41922cd80693407dc723d0e273ddebfaa981d8bc Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Tue, 30 Apr 2024 00:11:44 +0530 Subject: [PATCH 10/12] fixed the mock test workflow Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- .github/workflows/test-mock.yml | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test-mock.yml b/.github/workflows/test-mock.yml index abb2789..ffae8b5 100644 --- a/.github/workflows/test-mock.yml +++ b/.github/workflows/test-mock.yml @@ -7,7 +7,7 @@ on: - 'scripts/**' - 'go.mod' - 'go.sum' - types: [ labeled ] + types: [ labeled, opened, synchronize, reopened ] branches: [ main ] push: paths: @@ -19,7 +19,14 @@ on: branches: [ main ] jobs: ksctl-cli-windows: - if: ${{ github.event.label.name == 'pr/lgtm' || (github.event_name == 'push' && github.ref == 'refs/heads/main') }} + 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' + ) runs-on: windows-latest env: KSCTL_FAKE_FLAG_ENABLED: "1" @@ -103,19 +110,19 @@ jobs: - 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 -s local --approve -v -1 + .\ksctl.exe delete ha-civo del-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 -s local --approve -v -1 + .\ksctl.exe delete ha-azure del-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: aws scale up and down working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' run: | - .\ksctl.exe delete ha-aws delete-nodes -n ha-demo --noWP 0 -r fake -s local --approve -v -1 + .\ksctl.exe delete ha-aws del-nodes -n ha-demo --noWP 0 -r fake -s local --approve -v -1 .\ksctl.exe create ha-aws add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake" -s local -r fake -v -1 --approve - name: civo delete @@ -224,17 +231,17 @@ jobs: - name: civo scale up and down run: | - ksctl delete ha-civo delete-nodes -n ha-demo --noWP 0 -r LON1 -s local --approve -v -1 + ksctl delete ha-civo del-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 -s local -r fake --approve -v -1 + ksctl delete ha-azure del-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: aws scale up and down run: | - ksctl delete ha-aws delete-nodes -n ha-demo --noWP 0 -s local -r fake --approve -v -1 + ksctl delete ha-aws del-nodes -n ha-demo --noWP 0 -s local -r fake --approve -v -1 ksctl create ha-aws add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake" -s local -r fake -v -1 --approve - name: civo delete From e10637423b77f22d8d77fda90d032dea4e8b51ab Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Tue, 30 Apr 2024 00:13:46 +0530 Subject: [PATCH 11/12] added missing if condition for the mock test Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- .github/workflows/test-mock.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-mock.yml b/.github/workflows/test-mock.yml index ffae8b5..03d4d8b 100644 --- a/.github/workflows/test-mock.yml +++ b/.github/workflows/test-mock.yml @@ -154,7 +154,14 @@ jobs: matrix: os: [macos-latest, ubuntu-latest] - if: ${{ github.event.label.name == 'pr/lgtm' || (github.event_name == 'push' && github.ref == 'refs/heads/main') }} + 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' + ) runs-on: ${{ matrix.os }} env: KSCTL_FAKE_FLAG_ENABLED: "1" From 81e147a9ff57b56a66d79fedaea2ce8413cc2a68 Mon Sep 17 00:00:00 2001 From: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> Date: Tue, 30 Apr 2024 00:21:14 +0530 Subject: [PATCH 12/12] patch: improved the logging for ci mock Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com> --- .github/workflows/test-mock.yml | 36 ++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-mock.yml b/.github/workflows/test-mock.yml index 03d4d8b..13d3c2d 100644 --- a/.github/workflows/test-mock.yml +++ b/.github/workflows/test-mock.yml @@ -50,7 +50,7 @@ jobs: working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' run: | .\ksctl.exe create civo -n demo -r LON1 --nodeSizeMP "g4s.kube.small" --version 1.27.1 --verbose -1 -s local --approve - .\ksctl.exe create ha-civo -n ha-demo --nodeSizeDS "fake.small" --version 1.27.1--nodeSizeLB "fake.small" --nodeSizeCP "fake.small" --nodeSizeWP "fake.small" -s local -r LON1 --verbose -1 --approve + .\ksctl.exe create ha-civo -n ha-demo --nodeSizeDS "fake.small" --version 1.27.1 --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' @@ -111,19 +111,19 @@ jobs: working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' run: | .\ksctl.exe delete ha-civo del-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 + .\ksctl.exe create ha-civo add-nodes -n ha-demo --noWP 1 --version 1.27.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 del-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 + .\ksctl.exe create ha-azure add-nodes -n ha-demo --noWP 1 --version 1.27.1 --nodeSizeWP "fake" -s local -r fake -v -1 --approve - name: aws scale up and down working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' run: | .\ksctl.exe delete ha-aws del-nodes -n ha-demo --noWP 0 -r fake -s local --approve -v -1 - .\ksctl.exe create ha-aws add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake" -s local -r fake -v -1 --approve + .\ksctl.exe create ha-aws add-nodes -n ha-demo --noWP 1 --version 1.27.1 --nodeSizeWP "fake" -s local -r fake -v -1 --approve - name: civo delete working-directory: 'C:\Users\runneradmin\AppData\Local\ksctl' @@ -165,6 +165,7 @@ jobs: runs-on: ${{ matrix.os }} env: KSCTL_FAKE_FLAG_ENABLED: "1" + PS4: '+\[\033[0;33m\](\[\033[0;36m\]${BASH_SOURCE##*/}:${LINENO}\[\033[0;33m\])\[\033[0m\] ' steps: - name: Checkout uses: actions/checkout@v3 @@ -177,101 +178,122 @@ jobs: - name: build ksctl linux if: ${{ matrix.os == 'ubuntu-latest' }} run: | + set -xe make install_linux ksctl version - name: build ksctl macos if: ${{ matrix.os == 'macos-latest' }} run: | + set -xe make install_macos_intel ksctl version - name: civo create run: | + set -xe ksctl create civo -n demo -r LON1 --nodeSizeMP "g4s.kube.small" --version 1.27.1 -s local --verbose -1 --approve ksctl create ha-civo -n ha-demo --nodeSizeDS "fake.small" -s local --version 1.27.1 --nodeSizeLB "fake.small" --nodeSizeCP "fake.small" --nodeSizeWP "fake.small" -r LON1 --verbose -1 --approve - name: azure create run: | + set -xe ksctl create azure -n demo -r fake --nodeSizeMP "fake" -s local --version 1.27.1 --verbose -1 --approve ksctl create ha-azure -n ha-demo --nodeSizeDS "fake" -s local --nodeSizeLB "fake" --version 1.27.1 --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 --approve - name: aws create run: | + set -xe # ksctl create aws -n demo -r fake --nodeSizeMP "fake" -s local --version 1.27.1 --verbose -1 --approve ksctl create ha-aws -n ha-demo --nodeSizeDS "fake" -s local --nodeSizeLB "fake" --version 1.27.1 --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 --approve - name: local create run: | + set -xe ksctl create local -n demolocal -s local --verbose -1 --approve - name: civo get run: | + set -xe ksctl get -p civo -s local - name: azure get run: | + set -xe ksctl get -p azure -s local - name: aws get run: | + set -xe ksctl get -p aws -s local - name: all run: | + set -xe ksctl get -s local - name: civo switch run: | + set -xe 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: | + set -xe ksctl switch -p azure -n demo -s local -r fake ksctl switch -p ha-azure -n ha-demo -s local -r fake - name: aws switch run: | + set -xe # ksctl switch -p aws -n demo -s local -r fake ksctl switch -p ha-aws -n ha-demo -s local -r fake - name: civo scale up and down run: | + set -xe ksctl delete ha-civo del-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 + ksctl create ha-civo add-nodes -n ha-demo --noWP 1 --version 1.27.1 --nodeSizeWP "fake.small" -s local -r LON1 -v -1 --approve - name: azure scale up and down run: | + set -xe ksctl delete ha-azure del-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 + ksctl create ha-azure add-nodes -n ha-demo --noWP 1 --version 1.27.1 --nodeSizeWP "fake" -s local -r fake -v -1 --approve - name: aws scale up and down run: | + set -xe ksctl delete ha-aws del-nodes -n ha-demo --noWP 0 -s local -r fake --approve -v -1 - ksctl create ha-aws add-nodes -n ha-demo --noWP 1 --nodeSizeWP "fake" -s local -r fake -v -1 --approve + ksctl create ha-aws add-nodes -n ha-demo --noWP 1 --version 1.27.1 --nodeSizeWP "fake" -s local -r fake -v -1 --approve - name: civo delete run: | + set -xe 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: | + set -xe 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: aws delete run: | + set -xe # ksctl delete aws -n demo -r fake -s local -v -1 --approve ksctl delete ha-aws -n ha-demo -r fake -s local -v -1 --approve - name: local delete run: | + set -xe ksctl delete local -n demolocal -v -1 -s local --approve - name: storage provider run: | + set -xe 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"