From 1c8213e000473d6411e19d4e0bb7abcbe2f20b2d Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 14 Sep 2023 14:14:28 +0200 Subject: [PATCH 1/3] Further improvements --- pkg/bootstrap/bootstrap.go | 54 +++++++++++++++----------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/pkg/bootstrap/bootstrap.go b/pkg/bootstrap/bootstrap.go index bb809afb..7ae24a76 100644 --- a/pkg/bootstrap/bootstrap.go +++ b/pkg/bootstrap/bootstrap.go @@ -1,6 +1,7 @@ package bootstrap import ( + "os" "os/exec" "path/filepath" @@ -10,33 +11,6 @@ import ( "github.com/pluralsh/plural/pkg/utils" ) -// saveKindKubeconfig exports kind kubeconfig to file. -func saveKindKubeconfig(_ []string) error { - man, err := manifest.FetchProject() - if err != nil { - return err - } - - bootstrapPath, err := GetBootstrapPath() - if err != nil { - return err - } - - cmd := exec.Command("kind", "export", "kubeconfig", "--name", man.Cluster, - "--kubeconfig", filepath.Join(bootstrapPath, "terraform", "kube_config_cluster.yaml")) - return utils.Execute(cmd) -} - -func enableAzureOIDCIssuer(_ []string) error { - man, err := manifest.FetchProject() - if err != nil { - return err - } - - cmd := exec.Command("az", "aks", "update", "-g", man.Project, "-n", man.Cluster, "--enable-oidc-issuer") - return utils.Execute(cmd) -} - // getBootstrapSteps returns list of steps to run during cluster bootstrap. func getBootstrapSteps(runPlural ActionFunc, additionalFlags []string) ([]*Step, error) { man, err := manifest.FetchProject() @@ -49,6 +23,11 @@ func getBootstrapSteps(runPlural ActionFunc, additionalFlags []string) ([]*Step, return nil, err } + bootstrapPath, err := GetBootstrapPath() + if err != nil { + return nil, err + } + flags := append(getBootstrapFlags(man.Provider), additionalFlags...) prov, err := provider.GetProvider() @@ -97,9 +76,13 @@ func getBootstrapSteps(runPlural ActionFunc, additionalFlags []string) ([]*Step, Skip: man.Provider != api.ProviderKind, }, { - Name: "Save kubeconfig", - Execute: saveKindKubeconfig, - Skip: man.Provider != api.ProviderKind, + Name: "Save kubeconfig", + Execute: func(_ []string) error { + cmd := exec.Command("kind", "export", "kubeconfig", "--name", man.Cluster, + "--kubeconfig", filepath.Join(bootstrapPath, "terraform", "kube_config_cluster.yaml")) + return utils.Execute(cmd) + }, + Skip: man.Provider != api.ProviderKind, }, { Name: "Wait for machine pools", @@ -109,9 +92,14 @@ func getBootstrapSteps(runPlural ActionFunc, additionalFlags []string) ([]*Step, { // TODO: Once https://github.com/kubernetes-sigs/cluster-api-provider-azure/issues/2498 // will be done we can use it and remove this step. - Name: "Enable OIDC issuer", - Execute: enableAzureOIDCIssuer, - Skip: man.Provider != api.ProviderAzure, + Name: "Enable OIDC issuer", + Execute: func(_ []string) error { + cmd := exec.Command("az", "aks", "update", "-g", man.Project, "-n", man.Cluster, "--enable-oidc-issuer") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return utils.Execute(cmd) + }, + Skip: man.Provider != api.ProviderAzure, }, { Name: "Initialize kubeconfig for target cluster", From 6a4cdd083813a2f5f641fe0654130b059ddd1c9d Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 14 Sep 2023 14:45:05 +0200 Subject: [PATCH 2/3] Fix OIDC issuer step --- pkg/bootstrap/bootstrap.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pkg/bootstrap/bootstrap.go b/pkg/bootstrap/bootstrap.go index 6ac3af35..fafd613a 100644 --- a/pkg/bootstrap/bootstrap.go +++ b/pkg/bootstrap/bootstrap.go @@ -1,7 +1,6 @@ package bootstrap import ( - "os" "os/exec" "path/filepath" @@ -116,7 +115,7 @@ func getBootstrapSteps(runPlural ActionFunc, additionalFlags []string) ([]*Step, err := capi.SaveMoveBackup(options) if err != nil { - capi.RemoveStateBackup() + _ = capi.RemoveStateBackup() utils.Error("error during saving state backup: %s", err) } }, @@ -124,12 +123,9 @@ func getBootstrapSteps(runPlural ActionFunc, additionalFlags []string) ([]*Step, { // TODO: Once https://github.com/kubernetes-sigs/cluster-api-provider-azure/issues/2498 // will be done we can use it and remove this step. - Name: "Enable OIDC issuer", + Name: "ź", Execute: func(_ []string) error { - cmd := exec.Command("az", "aks", "update", "-g", man.Project, "-n", man.Cluster, "--enable-oidc-issuer") - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - return utils.Execute(cmd) + return utils.Exec("az", "aks", "update", "-g", man.Project, "-n", man.Cluster, "--enable-oidc-issuer") }, Skip: man.Provider != api.ProviderAzure, }, From 17895cfb09db7d3121daa0432a606f4f76b45709 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszczyk Date: Thu, 14 Sep 2023 14:45:21 +0200 Subject: [PATCH 3/3] Fix typo --- pkg/bootstrap/bootstrap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/bootstrap/bootstrap.go b/pkg/bootstrap/bootstrap.go index fafd613a..3e596f6b 100644 --- a/pkg/bootstrap/bootstrap.go +++ b/pkg/bootstrap/bootstrap.go @@ -123,7 +123,7 @@ func getBootstrapSteps(runPlural ActionFunc, additionalFlags []string) ([]*Step, { // TODO: Once https://github.com/kubernetes-sigs/cluster-api-provider-azure/issues/2498 // will be done we can use it and remove this step. - Name: "ź", + Name: "Enable OIDC issuer", Execute: func(_ []string) error { return utils.Exec("az", "aks", "update", "-g", man.Project, "-n", man.Cluster, "--enable-oidc-issuer") },