From f1fa1d9ebe2db91654b771e75ab3defe31a7ac52 Mon Sep 17 00:00:00 2001 From: Sebastian Florek Date: Thu, 28 Sep 2023 10:32:27 +0200 Subject: [PATCH 1/2] add support for external cert-manager module --- cmd/plural/deploy.go | 27 +++++++++++++++++---------- cmd/plural/plural.go | 2 +- pkg/bootstrap/common.go | 9 ++++++++- pkg/bootstrap/migrate.go | 14 +++++++++++++- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/cmd/plural/deploy.go b/cmd/plural/deploy.go index c1ab537cb..f98f9ff49 100644 --- a/cmd/plural/deploy.go +++ b/cmd/plural/deploy.go @@ -7,6 +7,10 @@ import ( "strings" "github.com/AlecAivazis/survey/v2" + "github.com/pluralsh/polly/algorithms" + "github.com/pluralsh/polly/containers" + "github.com/urfave/cli" + "github.com/pluralsh/plural/pkg/api" "github.com/pluralsh/plural/pkg/application" "github.com/pluralsh/plural/pkg/bootstrap" @@ -20,9 +24,6 @@ import ( "github.com/pluralsh/plural/pkg/utils/git" "github.com/pluralsh/plural/pkg/utils/pathing" "github.com/pluralsh/plural/pkg/wkspace" - "github.com/pluralsh/polly/algorithms" - "github.com/pluralsh/polly/containers" - "github.com/urfave/cli" ) const Bootstrap = "bootstrap" @@ -95,15 +96,21 @@ func (p *Plural) build(c *cli.Context) error { return errors.ErrorWrap(errNoGit, "Failed to scan your repo for secrets to encrypt them") } - if c.IsSet("only") { - installation, err := p.GetInstallation(c.String("only")) - if err != nil { - return api.GetErrorResponse(err, "GetInstallation") - } else if installation == nil { - return utils.HighlightError(fmt.Errorf("%s is not installed. Please install it with `plural bundle install`", c.String("only"))) + if len(c.StringSlice("only")) > 0 { + for _, inst := range c.StringSlice("only") { + installation, err := p.GetInstallation(inst) + if err != nil { + return api.GetErrorResponse(err, "GetInstallation") + } else if installation == nil { + return utils.HighlightError(fmt.Errorf("%s is not installed. Please install it with `plural bundle install`", inst)) + } + + if err := p.doBuild(installation, force); err != nil { + return err + } } - return p.doBuild(installation, force) + return nil } installations, err := p.getSortedInstallations("") diff --git a/cmd/plural/plural.go b/cmd/plural/plural.go index 305d85552..bfe550d99 100644 --- a/cmd/plural/plural.go +++ b/cmd/plural/plural.go @@ -88,7 +88,7 @@ func (p *Plural) getCommands() []cli.Command { Aliases: []string{"bld"}, Usage: "builds your workspace", Flags: []cli.Flag{ - cli.StringFlag{ + cli.StringSliceFlag{ Name: "only", Usage: "repository to (re)build", }, diff --git a/pkg/bootstrap/common.go b/pkg/bootstrap/common.go index bad081767..e9d31cf97 100644 --- a/pkg/bootstrap/common.go +++ b/pkg/bootstrap/common.go @@ -133,6 +133,7 @@ func getBootstrapFlags(prov string) []string { switch prov { case api.ProviderAWS: return []string{ + "--set", "bootstrap.cert-manager.enabled=true", "--set", "cluster-api-provider-aws.cluster-api-provider-aws.bootstrapMode=true", "--set", "bootstrap.aws-ebs-csi-driver.enabled=false", "--set", "bootstrap.aws-load-balancer-controller.enabled=false", @@ -146,12 +147,14 @@ func getBootstrapFlags(prov string) []string { } case api.ProviderAzure: return []string{ + "--set", "bootstrap.cert-manager.enabled=true", "--set", "cluster-api-cluster.cluster.azure.clusterIdentity.bootstrapMode=true", "--set", "bootstrap.external-dns.enabled=false", "--set", "plural-certmanager-webhook.enabled=false", } case api.ProviderGCP: return []string{ + "--set", "bootstrap.cert-manager.enabled=true", "--set", "bootstrap.cert-manager.serviceAccount.create=true", "--set", "cluster-api-provider-gcp.cluster-api-provider-gcp.bootstrapMode=true", "--set", "bootstrap.external-dns.enabled=false", @@ -174,12 +177,16 @@ func getKubeconfigPath() (string, error) { // GetBootstrapPath returns bootstrap repository path. func GetBootstrapPath() (string, error) { + return GetModulePath("bootstrap") +} + +func GetModulePath(module string) (string, error) { gitRootPath, err := git.Root() if err != nil { return "", err } - return pathing.SanitizeFilepath(filepath.Join(gitRootPath, "bootstrap")), nil + return pathing.SanitizeFilepath(filepath.Join(gitRootPath, module)), nil } // GetStepPath returns path from which step will be executed. diff --git a/pkg/bootstrap/migrate.go b/pkg/bootstrap/migrate.go index 6be1bbcc0..0cb70656f 100644 --- a/pkg/bootstrap/migrate.go +++ b/pkg/bootstrap/migrate.go @@ -379,9 +379,21 @@ func getMigrationSteps(runPlural ActionFunc) ([]*Step, error) { }, Retries: 2, }, + { + Name: "Install cert-manager bundle", + Args: []string{"plural", "bundle", "install", "cert-manager", fmt.Sprintf("cert-manager-%s", man.Provider)}, + TargetPath: gitRootDir, + Execute: runPlural, + }, + { + Name: "Build values", + Args: []string{"plural", "build --only", "cert-manager", "--only" , "bootstrap", "--force"}, + TargetPath: gitRootDir, + Execute: runPlural, + }, { Name: "Run deploy", - Args: []string{"plural", "deploy", "--from", "bootstrap", "--silence", "--commit", "migrate to cluster api"}, + Args: []string{"plural", "deploy", "--from", "cert-manager", "--silence", "--commit", "migrate to cluster api"}, TargetPath: gitRootDir, Execute: runPlural, }, From d524556113de82bfc1654a7a9859e53c7144c511 Mon Sep 17 00:00:00 2001 From: Sebastian Florek Date: Wed, 4 Oct 2023 12:29:30 +0200 Subject: [PATCH 2/2] fix build values --- pkg/bootstrap/migrate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/bootstrap/migrate.go b/pkg/bootstrap/migrate.go index 0cb70656f..dcc2cf740 100644 --- a/pkg/bootstrap/migrate.go +++ b/pkg/bootstrap/migrate.go @@ -387,7 +387,7 @@ func getMigrationSteps(runPlural ActionFunc) ([]*Step, error) { }, { Name: "Build values", - Args: []string{"plural", "build --only", "cert-manager", "--only" , "bootstrap", "--force"}, + Args: []string{"plural", "build", "--only", "cert-manager", "--only" , "bootstrap", "--force"}, TargetPath: gitRootDir, Execute: runPlural, },