From c40754992aa5671a2f0a9bfdedfaaec12396feea Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 11 Mar 2020 07:44:50 +0000 Subject: [PATCH 1/6] fix: add `--no-oauth` flag to disable OAuth login for github --- pkg/envfactory/env_factory.go | 6 +++++- pkg/jxadapt/helpers.go | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/envfactory/env_factory.go b/pkg/envfactory/env_factory.go index b0b45b4..12defe8 100644 --- a/pkg/envfactory/env_factory.go +++ b/pkg/envfactory/env_factory.go @@ -29,11 +29,13 @@ type EnvFactory struct { IOFileHandles *util.IOFileHandles ScmClient *scm.Client BatchMode bool + NoOAuth bool } // AddFlags adds common CLI flags func (o *EnvFactory) AddFlags(cmd *cobra.Command) { cmd.Flags().BoolVarP(&o.BatchMode, "batch-mode", "b", false, "Enables batch mode which avoids prompting for user input") + cmd.Flags().BoolVarP(&o.NoOAuth, "no-oauth", "", false, "Disables the use of OAuth login to github.com to get a github access token") cmd.Flags().StringVarP(&o.RepoName, "repo", "", "", "the name of the development git repository to create") cmd.Flags().StringVarP(&o.GitURLOutFile, "out", "", "", "the name of the file to save with the created git URL inside") @@ -153,5 +155,7 @@ func (o *EnvFactory) PushToGit(cloneURL string, userAuth *auth.UserAuth, dir str // JXAdapter creates an adapter to the jx code func (o *EnvFactory) JXAdapter() *jxadapt.JXAdapter { - return jxadapt.NewJXAdapter(o.JXFactory, o.Gitter, o.BatchMode) + a := jxadapt.NewJXAdapter(o.JXFactory, o.Gitter, o.BatchMode) + a.NoOAuth = o.NoOAuth + return a } diff --git a/pkg/jxadapt/helpers.go b/pkg/jxadapt/helpers.go index 9b2bb59..adadf87 100644 --- a/pkg/jxadapt/helpers.go +++ b/pkg/jxadapt/helpers.go @@ -21,6 +21,7 @@ type JXAdapter struct { JXFactory jxfactory.Factory Gitter gits.Gitter BatchMode bool + NoOAuth bool gitConfig gitconfig.Context } @@ -65,7 +66,7 @@ func (a *JXAdapter) ScmClient(serverURL string, owner string, kind string) (*scm token := "" if kind == "" || kind == "github" { kind = "github" - if !a.BatchMode { + if !a.BatchMode && !a.NoOAuth { if a.gitConfig == nil { a.gitConfig = gitconfig.New() } From 1b5a472f20c776c31c054dda372728738f338886 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 11 Mar 2020 09:48:55 +0000 Subject: [PATCH 2/6] fix: add CLI to override registry --- pkg/cmd/create/create.go | 5 +++ pkg/cmd/create/create_test.go | 47 ++++++++++++++++++++---- pkg/reqhelpers/helpers.go | 69 +++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/create/create.go b/pkg/cmd/create/create.go index eaf57fa..680a7b5 100644 --- a/pkg/cmd/create/create.go +++ b/pkg/cmd/create/create.go @@ -87,6 +87,11 @@ func (o *CreateOptions) Run() error { return errors.Wrapf(err, "failed to override requirements in dir %s", dir) } + _, _, err = reqhelpers.ValidateApps(dir) + if err != nil { + return errors.Wrapf(err, "failed to validate the apps based on requirements in dir %s", dir) + } + err = o.EnvFactory.VerifyPreInstall(o.DisableVerifyPackages, dir) if err != nil { return errors.Wrapf(err, "failed to verify requirements in dir %s", dir) diff --git a/pkg/cmd/create/create_test.go b/pkg/cmd/create/create_test.go index eace776..ed9169e 100644 --- a/pkg/cmd/create/create_test.go +++ b/pkg/cmd/create/create_test.go @@ -24,7 +24,12 @@ func TestCreate(t *testing.T) { } testCases := []testCase{ { - Name: "defaultcluster", + Name: "remote", + Args: []string{"--provider", "kubernetes", "--git-server", "https://fake.com", "--git-kind", "fake", "--env-git-owner", "jstrachan", "--env-git-public", "--git-public", "--env-remote"}, + }, + { + Name: "bucketrepo", + Args: []string{"--provider", "kind", "--git-server", "https://fake.com", "--git-kind", "fake", "--env-git-owner", "jstrachan", "--env-git-public", "--git-public", "--repository", "bucketrepo"}, }, } @@ -37,7 +42,7 @@ func TestCreate(t *testing.T) { outFile, err := ioutil.TempFile("", "") require.NoError(t, err, "failed to create tempo file") outFileName := outFile.Name() - args := []string{"--provider", "kubernetes", "--cluster", tc.Name, "--git-server", "https://fake.com", "--git-kind", "fake", "--env-git-owner", "jstrachan", "--out", outFileName, "--env-git-public", "--git-public", "--env-remote"} + args := append(tc.Args, "--cluster", tc.Name, "--out", outFileName) args = append(args, tc.Args...) co.Args = args co.JXFactory = fakejxfactory.NewFakeFactory() @@ -64,6 +69,19 @@ func TestCreate(t *testing.T) { AssertHasApp(t, apps, "jenkins-x/lighthouse", appMessage) + switch tc.Name { + case "remote": + AssertHasApp(t, apps, "jenkins-x/chartmuseum", appMessage) + AssertHasApp(t, apps, "jenkins-x/nexus", appMessage) + AssertHasApp(t, apps, "repositories", appMessage) + AssertNoApp(t, apps, "jenkins-x/bucketrepo", appMessage) + + case "bucketrepo": + AssertHasApp(t, apps, "jenkins-x/bucketrepo", appMessage) + AssertHasApp(t, apps, "repositories", appMessage) + AssertNoApp(t, apps, "jenkins-x/chartmuseum", appMessage) + AssertNoApp(t, apps, "jenkins-x/nexus", appMessage) + } assert.FileExists(t, outFileName, "did not generate the Git URL file") data, err := ioutil.ReadFile(outFileName) require.NoError(t, err, "failed to load file %s", outFileName) @@ -80,14 +98,32 @@ func TestCreate(t *testing.T) { if e.Key == "dev" { assert.Equal(t, false, e.RemoteCluster, "requirements.Environments[%d].RemoteCluster for key %s", i, e.Key) } else { - assert.Equal(t, true, e.RemoteCluster, "requirements.Environments[%d].RemoteCluster for key %s", i, e.Key) + expectedRemote := tc.Name == "remote" + assert.Equal(t, expectedRemote, e.RemoteCluster, "requirements.Environments[%d].RemoteCluster for key %s", i, e.Key) } t.Logf("requirements.Environments[%d].RemoteCluster = %v for key %s ", i, e.RemoteCluster, e.Key) } } } +// AssertHasApp asserts that the given app name is in the generated apps YAML func AssertHasApp(t *testing.T, appConfig *config.AppConfig, appName string, message string) { + found, names := HasApp(t, appConfig, appName, message) + if !found { + assert.Fail(t, fmt.Sprintf("does not have the app %s for %s. Current apps are: %s", appName, message, strings.Join(names, ", "))) + } +} + +// AssertNoApp asserts that the given app name is in the generated apps YAML +func AssertNoApp(t *testing.T, appConfig *config.AppConfig, appName string, message string) { + found, names := HasApp(t, appConfig, appName, message) + if found { + assert.Fail(t, fmt.Sprintf("should not have the app %s for %s. Current apps are: %s", appName, message, strings.Join(names, ", "))) + } +} + +// HasApp tests that the app config has the given app +func HasApp(t *testing.T, appConfig *config.AppConfig, appName string, message string) (bool, []string) { found := false names := []string{} for _, app := range appConfig.Apps { @@ -97,8 +133,5 @@ func AssertHasApp(t *testing.T, appConfig *config.AppConfig, appName string, mes found = true } } - if !found { - assert.Fail(t, fmt.Sprintf("does not have the app %s for %s. Current apps are: %s", appName, message, strings.Join(names, ", "))) - } - + return found, names } diff --git a/pkg/reqhelpers/helpers.go b/pkg/reqhelpers/helpers.go index 81f0d14..1ca03e4 100644 --- a/pkg/reqhelpers/helpers.go +++ b/pkg/reqhelpers/helpers.go @@ -23,6 +23,7 @@ import ( type RequirementBools struct { AutoUpgrade, EnvironmentGitPublic, GitPublic, EnvironmentRemote, GitOps, Kaniko, Terraform bool VaultRecreateBucket, VaultDisableURLDiscover bool + Repository string } // GetDevEnvironmentConfig returns the dev environment for the given requirements or nil @@ -158,6 +159,69 @@ func OverrideRequirements(cmd *cobra.Command, args []string, dir string, outputR return nil } +// OverrideRequirements +func ValidateApps(dir string) (*config.AppConfig, string, error) { + requirements, _, err := config.LoadRequirementsConfig(dir) + if err != nil { + return nil, "", err + } + apps, appsFileName, err := config.LoadAppConfig(dir) + + modified := false + if requirements.Repository != config.RepositoryTypeNexus { + if removeApp(apps, "jenkins-x/nexus") { + modified = true + } + } + if requirements.Repository == config.RepositoryTypeBucketRepo { + if removeApp(apps, "jenkins-x/chartmuseum") { + modified = true + } + if addApp(apps, "jenkins-x/bucketrepo") { + modified = true + } + } + if modified { + err = apps.SaveConfig(appsFileName) + if err != nil { + return apps, appsFileName, errors.Wrapf(err, "failed to save modified file %s", appsFileName) + } + } + return apps, appsFileName, err +} + +func addApp(apps *config.AppConfig, chartName string) bool { + idx := -1 + for i, a := range apps.Apps { + switch a.Name { + case chartName: + return false + case "repositories": + idx = i + } + } + app := config.App{Name: chartName} + + // if we have a repositories chart lets add apps before that + if idx >= 0 { + newApps := append([]config.App{app}, apps.Apps[idx:]...) + apps.Apps = append(apps.Apps[0:idx], newApps...) + } else { + apps.Apps = append(apps.Apps, app) + } + return true +} + +func removeApp(apps *config.AppConfig, chartName string) bool { + for i, a := range apps.Apps { + if a.Name == chartName { + apps.Apps = append(apps.Apps[0:i], apps.Apps[i+1:]...) + return true + } + } + return false +} + func applyDefaults(cmd *cobra.Command, r *config.RequirementsConfig, flags *RequirementBools) error { // override boolean flags if specified if FlagChanged(cmd, "autoupgrade") { @@ -185,6 +249,10 @@ func applyDefaults(cmd *cobra.Command, r *config.RequirementsConfig, flags *Requ r.Vault.RecreateBucket = flags.VaultRecreateBucket } + if flags.Repository != "" { + r.Repository = config.RepositoryType(flags.Repository) + } + if flags.EnvironmentRemote { for i, e := range r.Environments { if e.Key == "dev" { @@ -248,6 +316,7 @@ func AddRequirementsFlagsOptions(cmd *cobra.Command, flags *RequirementBools) { cmd.Flags().BoolVarP(&flags.Terraform, "terraform", "", false, "enables or disables the use of terraform") cmd.Flags().BoolVarP(&flags.VaultRecreateBucket, "vault-recreate-bucket", "", false, "enables or disables whether to rereate the secret bucket on boot") cmd.Flags().BoolVarP(&flags.VaultDisableURLDiscover, "vault-disable-url-discover", "", false, "override the default lookup of the Vault URL, could be incluster service or external ingress") + cmd.Flags().StringVarP(&flags.Repository, "repository", "", "", "the artifact repository. Possible values are: "+strings.Join(config.RepositoryTypeValues, ", ")) } // AddRequirementsOptions add CLI flags to the requirements From e8f3a4868157d035311a6c823abb757a43c1cde2 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 11 Mar 2020 10:14:36 +0000 Subject: [PATCH 3/6] fix: add cert manager and externaldns if detected in the requirements --- pkg/cmd/create/create_test.go | 22 ++++++++++++++++++--- pkg/reqhelpers/helpers.go | 36 ++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/pkg/cmd/create/create_test.go b/pkg/cmd/create/create_test.go index ed9169e..e89990d 100644 --- a/pkg/cmd/create/create_test.go +++ b/pkg/cmd/create/create_test.go @@ -25,11 +25,19 @@ func TestCreate(t *testing.T) { testCases := []testCase{ { Name: "remote", - Args: []string{"--provider", "kubernetes", "--git-server", "https://fake.com", "--git-kind", "fake", "--env-git-owner", "jstrachan", "--env-git-public", "--git-public", "--env-remote"}, + Args: []string{"--provider", "kubernetes", "--env-git-public", "--git-public", "--env-remote"}, }, { Name: "bucketrepo", - Args: []string{"--provider", "kind", "--git-server", "https://fake.com", "--git-kind", "fake", "--env-git-owner", "jstrachan", "--env-git-public", "--git-public", "--repository", "bucketrepo"}, + Args: []string{"--provider", "kind", "--env-git-public", "--git-public", "--repository", "bucketrepo"}, + }, + { + Name: "tls", + Args: []string{"--provider", "kind", "--env-git-public", "--git-public", "--tls", "--externaldns"}, + }, + { + Name: "tls-custom-secret", + Args: []string{"--provider", "kind", "--env-git-public", "--git-public", "--tls", "--tls-secret", "my-tls-secret"}, }, } @@ -42,7 +50,7 @@ func TestCreate(t *testing.T) { outFile, err := ioutil.TempFile("", "") require.NoError(t, err, "failed to create tempo file") outFileName := outFile.Name() - args := append(tc.Args, "--cluster", tc.Name, "--out", outFileName) + args := append(tc.Args, "--git-server", "https://fake.com", "--git-kind", "fake", "--env-git-owner", "jstrachan", "--cluster", tc.Name, "--out", outFileName) args = append(args, tc.Args...) co.Args = args co.JXFactory = fakejxfactory.NewFakeFactory() @@ -81,6 +89,14 @@ func TestCreate(t *testing.T) { AssertHasApp(t, apps, "repositories", appMessage) AssertNoApp(t, apps, "jenkins-x/chartmuseum", appMessage) AssertNoApp(t, apps, "jenkins-x/nexus", appMessage) + + case "tls": + AssertHasApp(t, apps, "jetstack/cert-manager", appMessage) + AssertHasApp(t, apps, "bitnami/externaldns", appMessage) + + case "tls-custom-secret": + AssertNoApp(t, apps, "jetstack/cert-manager", appMessage) + AssertNoApp(t, apps, "bitnami/externaldns", appMessage) } assert.FileExists(t, outFileName, "did not generate the Git URL file") data, err := ioutil.ReadFile(outFileName) diff --git a/pkg/reqhelpers/helpers.go b/pkg/reqhelpers/helpers.go index 1ca03e4..37d4a0a 100644 --- a/pkg/reqhelpers/helpers.go +++ b/pkg/reqhelpers/helpers.go @@ -22,6 +22,7 @@ import ( // RequirementBools for the boolean flags we only update if specified on the CLI type RequirementBools struct { AutoUpgrade, EnvironmentGitPublic, GitPublic, EnvironmentRemote, GitOps, Kaniko, Terraform bool + ExternalDNS, TLS bool VaultRecreateBucket, VaultDisableURLDiscover bool Repository string } @@ -177,10 +178,22 @@ func ValidateApps(dir string) (*config.AppConfig, string, error) { if removeApp(apps, "jenkins-x/chartmuseum") { modified = true } - if addApp(apps, "jenkins-x/bucketrepo") { + if addApp(apps, "jenkins-x/bucketrepo", "repositories") { modified = true } } + + if shouldHaveCertManager(requirements) { + if addApp(apps, "jetstack/cert-manager", "jenkins-x/jxboot-helmfile-resources") { + modified = true + } + } + if shouldHaveExternalDNS(requirements) { + if addApp(apps, "bitnami/externaldns", "jenkins-x/jxboot-helmfile-resources") { + modified = true + } + } + if modified { err = apps.SaveConfig(appsFileName) if err != nil { @@ -190,13 +203,21 @@ func ValidateApps(dir string) (*config.AppConfig, string, error) { return apps, appsFileName, err } -func addApp(apps *config.AppConfig, chartName string) bool { +func shouldHaveCertManager(requirements *config.RequirementsConfig) bool { + return requirements.Ingress.TLS.Enabled && requirements.Ingress.TLS.SecretName == "" +} + +func shouldHaveExternalDNS(requirements *config.RequirementsConfig) bool { + return requirements.Ingress.ExternalDNS +} + +func addApp(apps *config.AppConfig, chartName string, beforeName string) bool { idx := -1 for i, a := range apps.Apps { switch a.Name { case chartName: return false - case "repositories": + case beforeName: idx = i } } @@ -230,6 +251,9 @@ func applyDefaults(cmd *cobra.Command, r *config.RequirementsConfig, flags *Requ if FlagChanged(cmd, "env-git-public") { r.Cluster.EnvironmentGitPublic = flags.EnvironmentGitPublic } + if FlagChanged(cmd, "externaldns") { + r.Ingress.ExternalDNS = flags.ExternalDNS + } if FlagChanged(cmd, "git-public") { r.Cluster.GitPublic = flags.GitPublic } @@ -248,6 +272,9 @@ func applyDefaults(cmd *cobra.Command, r *config.RequirementsConfig, flags *Requ if FlagChanged(cmd, "vault-recreate-bucket") { r.Vault.RecreateBucket = flags.VaultRecreateBucket } + if FlagChanged(cmd, "tls") { + r.Ingress.TLS.Enabled = flags.TLS + } if flags.Repository != "" { r.Repository = config.RepositoryType(flags.Repository) @@ -316,6 +343,8 @@ func AddRequirementsFlagsOptions(cmd *cobra.Command, flags *RequirementBools) { cmd.Flags().BoolVarP(&flags.Terraform, "terraform", "", false, "enables or disables the use of terraform") cmd.Flags().BoolVarP(&flags.VaultRecreateBucket, "vault-recreate-bucket", "", false, "enables or disables whether to rereate the secret bucket on boot") cmd.Flags().BoolVarP(&flags.VaultDisableURLDiscover, "vault-disable-url-discover", "", false, "override the default lookup of the Vault URL, could be incluster service or external ingress") + cmd.Flags().BoolVarP(&flags.ExternalDNS, "externaldns", "", false, "should we enable the ExternalDNS app to register DNS entries for Ingress resources") + cmd.Flags().BoolVarP(&flags.TLS, "tls", "", false, "enable TLS for Ingress") cmd.Flags().StringVarP(&flags.Repository, "repository", "", "", "the artifact repository. Possible values are: "+strings.Join(config.RepositoryTypeValues, ", ")) } @@ -343,6 +372,7 @@ func AddRequirementsOptions(cmd *cobra.Command, r *config.RequirementsConfig) { // ingress cmd.Flags().StringVarP(&r.Ingress.Domain, "domain", "d", "", "configures the domain name") cmd.Flags().StringVarP(&r.Ingress.TLS.Email, "tls-email", "", "", "the TLS email address to enable TLS on the domain") + cmd.Flags().StringVarP(&r.Ingress.TLS.SecretName, "tls-secret", "", "", "the custom Kubernetes Secret name for the TLS certificate") // storage cmd.Flags().StringVarP(&r.Storage.Logs.URL, "bucket-logs", "", "", "the bucket URL to store logs") From 0c373d18e0b0ebd4327c96d6345d64eb7c8d016c Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 11 Mar 2020 10:44:54 +0000 Subject: [PATCH 4/6] fix: upgrade to latest jx and minor refactor of code --- go.mod | 2 +- go.sum | 5 ++- pkg/cmd/upgrade/upgrade.go | 8 ++-- pkg/reqhelpers/flags.go | 85 ++++++++++++++++++++++++++++++++++++++ pkg/reqhelpers/helpers.go | 75 --------------------------------- 5 files changed, 92 insertions(+), 83 deletions(-) create mode 100644 pkg/reqhelpers/flags.go diff --git a/go.mod b/go.mod index f2c5cae..3ab9d8b 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/heptio/sonobuoy v0.16.0 github.com/jenkins-x/go-scm v1.5.76 github.com/jenkins-x/golang-jenkins v0.0.0-20180919102630-65b83ad42314 - github.com/jenkins-x/jx v0.0.0-20200310115539-b64ed22fb7af + github.com/jenkins-x/jx v0.0.0-20200311103335-37bf33594977 github.com/jetstack/cert-manager v0.5.2 github.com/knative/serving v0.7.0 github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index 4f24cfd..ba9db0e 100644 --- a/go.sum +++ b/go.sum @@ -192,6 +192,7 @@ github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55k github.com/dnaeon/go-vcr v1.0.1 h1:r8L/HqC0Hje5AXMu1ooW8oyQyOFv4GxqpL0nRP7SLLY= github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= github.com/docker/distribution v0.0.0-20170726174610-edc3ab29cdff/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v0.0.0-20171206114025-5e5fadb3c020 h1:aiKCZxnxoraZKXbM2zJj0ZI1n8eamkdK7zNxP7jlbII= github.com/docker/docker v0.0.0-20171206114025-5e5fadb3c020/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/go-connections v0.3.0 h1:3lOnM9cSzgGwx8VfK/NGOW5fLQ0GjIlCkaktF+n1M6o= github.com/docker/go-connections v0.3.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= @@ -432,8 +433,8 @@ github.com/jenkins-x/go-scm v1.5.76 h1:IMlfD8K+XieU2rvA8Sp2fz6FejhFo6JuUG/Do1SZ9 github.com/jenkins-x/go-scm v1.5.76/go.mod h1:PCT338UhP/pQ0IeEeMEf/hoLTYKcH7qjGEKd7jPkeYg= github.com/jenkins-x/golang-jenkins v0.0.0-20180919102630-65b83ad42314 h1:kyBMx/ucSV92S+umX/V6DDaPNynlFFOM9MGJWApltoU= github.com/jenkins-x/golang-jenkins v0.0.0-20180919102630-65b83ad42314/go.mod h1:C6j5HgwlHGjRU27W4XCs6jXksqYFo8OdBu+p44jqQeM= -github.com/jenkins-x/jx v0.0.0-20200310115539-b64ed22fb7af h1:0m9oO/2JTQU3C2FQ62+CLHOm+uUlAuOEiLd/Nh8EAWA= -github.com/jenkins-x/jx v0.0.0-20200310115539-b64ed22fb7af/go.mod h1:QZVsigjVZ634iK2TqkIs10yANye4JbBF2bHd3i41U8o= +github.com/jenkins-x/jx v0.0.0-20200311103335-37bf33594977 h1:pOQnxhSDmuKJOnRqBCliU+n3uuuTmMYU46Igs2/yyHY= +github.com/jenkins-x/jx v0.0.0-20200311103335-37bf33594977/go.mod h1:QZVsigjVZ634iK2TqkIs10yANye4JbBF2bHd3i41U8o= github.com/jetstack/cert-manager v0.5.2 h1:qs74mdAprZ5kcCYF3arzmEAZtbt+9HneldSJrk21tKs= github.com/jetstack/cert-manager v0.5.2/go.mod h1:nbddmhjWxYGt04bxvwVGUSeLhZ2PCyNvd7MpXdq+yWY= github.com/jinzhu/gorm v0.0.0-20170316141641-572d0a0ab1eb/go.mod h1:Vla75njaFJ8clLU1W44h34PjIkijhjHIYnZxMqCdxqo= diff --git a/pkg/cmd/upgrade/upgrade.go b/pkg/cmd/upgrade/upgrade.go index 44b4dbc..a3e069e 100644 --- a/pkg/cmd/upgrade/upgrade.go +++ b/pkg/cmd/upgrade/upgrade.go @@ -52,18 +52,16 @@ var ( // UpgradeOptions the options for upgrading a cluster type UpgradeOptions struct { envfactory.EnvFactory - NoCommit bool OverrideRequirements config.RequirementsConfig Namespace string GitCloneURL string InitialGitURL string Dir string - UsePullRequest bool - - // if we are modifing an existing git repository - gitRepositoryExisted bool branchName string + UsePullRequest bool + NoCommit bool + gitRepositoryExisted bool // if we are modifying an existing git repository } // NewCmdUpgrade creates a command object for the command diff --git a/pkg/reqhelpers/flags.go b/pkg/reqhelpers/flags.go new file mode 100644 index 0000000..e8b2319 --- /dev/null +++ b/pkg/reqhelpers/flags.go @@ -0,0 +1,85 @@ +package reqhelpers + +import ( + "fmt" + "strings" + + "github.com/jenkins-x/jx/pkg/cloud" + "github.com/jenkins-x/jx/pkg/config" + "github.com/jenkins-x/jx/pkg/gits" + "github.com/spf13/cobra" +) + +// AddRequirementsFlagsOptions add CLI options to the flags +func AddRequirementsFlagsOptions(cmd *cobra.Command, flags *RequirementBools) { + cmd.Flags().BoolVarP(&flags.AutoUpgrade, "autoupgrade", "", false, "enables or disables auto upgrades") + cmd.Flags().BoolVarP(&flags.EnvironmentRemote, "env-remote", "", false, "if enables then all other environments than dev (staging & production by default) will be configured to be in remote clusters") + cmd.Flags().BoolVarP(&flags.EnvironmentGitPublic, "env-git-public", "", false, "enables or disables whether the environment repositories should be public") + cmd.Flags().BoolVarP(&flags.GitPublic, "git-public", "", false, "enables or disables whether the project repositories should be public") + cmd.Flags().BoolVarP(&flags.GitOps, "gitops", "g", false, "enables or disables the use of gitops") + cmd.Flags().BoolVarP(&flags.Kaniko, "kaniko", "", false, "enables or disables the use of kaniko") + cmd.Flags().BoolVarP(&flags.Terraform, "terraform", "", false, "enables or disables the use of terraform") + cmd.Flags().BoolVarP(&flags.VaultRecreateBucket, "vault-recreate-bucket", "", false, "enables or disables whether to rereate the secret bucket on boot") + cmd.Flags().BoolVarP(&flags.VaultDisableURLDiscover, "vault-disable-url-discover", "", false, "override the default lookup of the Vault URL, could be incluster service or external ingress") + cmd.Flags().BoolVarP(&flags.ExternalDNS, "externaldns", "", false, "should we enable the ExternalDNS app to register DNS entries for Ingress resources") + cmd.Flags().BoolVarP(&flags.TLS, "tls", "", false, "enable TLS for Ingress") + cmd.Flags().StringVarP(&flags.Repository, "repository", "", "", "the artifact repository. Possible values are: "+strings.Join(config.RepositoryTypeValues, ", ")) +} + +// AddRequirementsOptions add CLI flags to the requirements +func AddRequirementsOptions(cmd *cobra.Command, r *config.RequirementsConfig) { + cmd.Flags().StringVarP(&r.BootConfigURL, "boot-config-url", "", "", "specify the boot configuration git URL") + + // auto upgrade + cmd.Flags().StringVarP(&r.AutoUpdate.Schedule, "autoupdate-schedule", "", "", "the cron schedule for auto upgrading your cluster") + + // cluster + cmd.Flags().StringVarP(&r.Cluster.ClusterName, "cluster", "c", "", "configures the cluster name") + cmd.Flags().StringVarP(&r.Cluster.Namespace, "namespace", "n", "", "configures the namespace to use") + cmd.Flags().StringVarP(&r.Cluster.Provider, "provider", "p", "", "configures the kubernetes provider. Supported providers: "+cloud.KubernetesProviderOptions()) + cmd.Flags().StringVarP(&r.Cluster.ProjectID, "project", "", "", "configures the Google Project ID") + cmd.Flags().StringVarP(&r.Cluster.Registry, "registry", "", "", "configures the host name of the container registry") + cmd.Flags().StringVarP(&r.Cluster.Region, "region", "r", "", "configures the cloud region") + cmd.Flags().StringVarP(&r.Cluster.Zone, "zone", "z", "", "configures the cloud zone") + + cmd.Flags().StringVarP(&r.Cluster.ExternalDNSSAName, "extdns-sa", "", "", "configures the External DNS service account name") + cmd.Flags().StringVarP(&r.Cluster.KanikoSAName, "kaniko-sa", "", "", "configures the Kaniko service account name") + + AddGitRequirementsOptions(cmd, r) + + // ingress + cmd.Flags().StringVarP(&r.Ingress.Domain, "domain", "d", "", "configures the domain name") + cmd.Flags().StringVarP(&r.Ingress.ServiceType, "service-type", "", "", "the Ingress controller Service Type such as NodePort if using on premise and you do not have a LoadBalancer service type support") + cmd.Flags().StringVarP(&r.Ingress.TLS.Email, "tls-email", "", "", "the TLS email address to enable TLS on the domain") + cmd.Flags().StringVarP(&r.Ingress.TLS.SecretName, "tls-secret", "", "", "the custom Kubernetes Secret name for the TLS certificate") + + // storage + cmd.Flags().StringVarP(&r.Storage.Logs.URL, "bucket-logs", "", "", "the bucket URL to store logs") + cmd.Flags().StringVarP(&r.Storage.Backup.URL, "bucket-backups", "", "", "the bucket URL to store backups") + cmd.Flags().StringVarP(&r.Storage.Repository.URL, "bucket-repo", "", "", "the bucket URL to store repository artifacts") + cmd.Flags().StringVarP(&r.Storage.Reports.URL, "bucket-reports", "", "", "the bucket URL to store reports. If not specified default to te logs bucket") + + // vault + cmd.Flags().StringVarP(&r.Vault.Name, "vault-name", "", "", "specify the vault name") + cmd.Flags().StringVarP(&r.Vault.Bucket, "vault-bucket", "", "", "specify the vault bucket") + cmd.Flags().StringVarP(&r.Vault.Keyring, "vault-keyring", "", "", "specify the vault key ring") + cmd.Flags().StringVarP(&r.Vault.Key, "vault-key", "", "", "specify the vault key") + cmd.Flags().StringVarP(&r.Vault.ServiceAccount, "vault-sa", "", "", "specify the vault Service Account name") + + // velero + cmd.Flags().StringVarP(&r.Velero.ServiceAccount, "velero-sa", "", "", "specify the Velero Service Account name") + cmd.Flags().StringVarP(&r.Velero.Namespace, "velero-ns", "", "", "specify the Velero Namespace") + + // version stream + cmd.Flags().StringVarP(&r.VersionStream.URL, "version-stream-url", "", "", "specify the Version Stream git URL") + cmd.Flags().StringVarP(&r.VersionStream.Ref, "version-stream-ref", "", "", "specify the Version Stream git reference (branch, tag, sha)") +} + +// AddGitRequirementsOptions adds git specific overrides to the given requirements +func AddGitRequirementsOptions(cmd *cobra.Command, r *config.RequirementsConfig) { + cmd.Flags().StringVarP(&r.Cluster.GitKind, "git-kind", "", "", fmt.Sprintf("the kind of git repository to use. Possible values: %s", strings.Join(gits.KindGits, ", "))) + cmd.Flags().StringVarP(&r.Cluster.GitName, "git-name", "", "", "the name of the git repository") + cmd.Flags().StringVarP(&r.Cluster.GitServer, "git-server", "", "", "the git server host such as https://github.com or https://gitlab.com") + cmd.Flags().StringVarP(&r.Cluster.EnvironmentGitOwner, "env-git-owner", "", "", "the git owner (organisation or user) used to own the git repositories for the environments") + cmd.Flags().StringArrayVarP(&r.Cluster.DevEnvApprovers, "approver", "", nil, "the git user names of the approvers for the environments") +} diff --git a/pkg/reqhelpers/helpers.go b/pkg/reqhelpers/helpers.go index 37d4a0a..ec6e0a3 100644 --- a/pkg/reqhelpers/helpers.go +++ b/pkg/reqhelpers/helpers.go @@ -4,11 +4,9 @@ import ( "fmt" "io/ioutil" "os" - "strings" v1 "github.com/jenkins-x/jx/pkg/apis/jenkins.io/v1" "github.com/jenkins-x/jx/pkg/client/clientset/versioned" - "github.com/jenkins-x/jx/pkg/cloud" "github.com/jenkins-x/jx/pkg/config" "github.com/jenkins-x/jx/pkg/gits" "github.com/jenkins-x/jx/pkg/kube" @@ -331,76 +329,3 @@ func defaultStorage(storage *config.StorageEntryConfig) { storage.Enabled = true } } - -// AddRequirementsFlagsOptions add CLI options to the flags -func AddRequirementsFlagsOptions(cmd *cobra.Command, flags *RequirementBools) { - cmd.Flags().BoolVarP(&flags.AutoUpgrade, "autoupgrade", "", false, "enables or disables auto upgrades") - cmd.Flags().BoolVarP(&flags.EnvironmentRemote, "env-remote", "", false, "if enables then all other environments than dev (staging & production by default) will be configured to be in remote clusters") - cmd.Flags().BoolVarP(&flags.EnvironmentGitPublic, "env-git-public", "", false, "enables or disables whether the environment repositories should be public") - cmd.Flags().BoolVarP(&flags.GitPublic, "git-public", "", false, "enables or disables whether the project repositories should be public") - cmd.Flags().BoolVarP(&flags.GitOps, "gitops", "g", false, "enables or disables the use of gitops") - cmd.Flags().BoolVarP(&flags.Kaniko, "kaniko", "", false, "enables or disables the use of kaniko") - cmd.Flags().BoolVarP(&flags.Terraform, "terraform", "", false, "enables or disables the use of terraform") - cmd.Flags().BoolVarP(&flags.VaultRecreateBucket, "vault-recreate-bucket", "", false, "enables or disables whether to rereate the secret bucket on boot") - cmd.Flags().BoolVarP(&flags.VaultDisableURLDiscover, "vault-disable-url-discover", "", false, "override the default lookup of the Vault URL, could be incluster service or external ingress") - cmd.Flags().BoolVarP(&flags.ExternalDNS, "externaldns", "", false, "should we enable the ExternalDNS app to register DNS entries for Ingress resources") - cmd.Flags().BoolVarP(&flags.TLS, "tls", "", false, "enable TLS for Ingress") - cmd.Flags().StringVarP(&flags.Repository, "repository", "", "", "the artifact repository. Possible values are: "+strings.Join(config.RepositoryTypeValues, ", ")) -} - -// AddRequirementsOptions add CLI flags to the requirements -func AddRequirementsOptions(cmd *cobra.Command, r *config.RequirementsConfig) { - cmd.Flags().StringVarP(&r.BootConfigURL, "boot-config-url", "", "", "specify the boot configuration git URL") - - // auto upgrade - cmd.Flags().StringVarP(&r.AutoUpdate.Schedule, "autoupdate-schedule", "", "", "the cron schedule for auto upgrading your cluster") - - // cluster - cmd.Flags().StringVarP(&r.Cluster.ClusterName, "cluster", "c", "", "configures the cluster name") - cmd.Flags().StringVarP(&r.Cluster.Namespace, "namespace", "n", "", "configures the namespace to use") - cmd.Flags().StringVarP(&r.Cluster.Provider, "provider", "p", "", "configures the kubernetes provider. Supported providers: "+cloud.KubernetesProviderOptions()) - cmd.Flags().StringVarP(&r.Cluster.ProjectID, "project", "", "", "configures the Google Project ID") - cmd.Flags().StringVarP(&r.Cluster.Registry, "registry", "", "", "configures the host name of the container registry") - cmd.Flags().StringVarP(&r.Cluster.Region, "region", "r", "", "configures the cloud region") - cmd.Flags().StringVarP(&r.Cluster.Zone, "zone", "z", "", "configures the cloud zone") - - cmd.Flags().StringVarP(&r.Cluster.ExternalDNSSAName, "extdns-sa", "", "", "configures the External DNS service account name") - cmd.Flags().StringVarP(&r.Cluster.KanikoSAName, "kaniko-sa", "", "", "configures the Kaniko service account name") - - AddGitRequirementsOptions(cmd, r) - - // ingress - cmd.Flags().StringVarP(&r.Ingress.Domain, "domain", "d", "", "configures the domain name") - cmd.Flags().StringVarP(&r.Ingress.TLS.Email, "tls-email", "", "", "the TLS email address to enable TLS on the domain") - cmd.Flags().StringVarP(&r.Ingress.TLS.SecretName, "tls-secret", "", "", "the custom Kubernetes Secret name for the TLS certificate") - - // storage - cmd.Flags().StringVarP(&r.Storage.Logs.URL, "bucket-logs", "", "", "the bucket URL to store logs") - cmd.Flags().StringVarP(&r.Storage.Backup.URL, "bucket-backups", "", "", "the bucket URL to store backups") - cmd.Flags().StringVarP(&r.Storage.Repository.URL, "bucket-repo", "", "", "the bucket URL to store repository artifacts") - cmd.Flags().StringVarP(&r.Storage.Reports.URL, "bucket-reports", "", "", "the bucket URL to store reports. If not specified default to te logs bucket") - - // vault - cmd.Flags().StringVarP(&r.Vault.Name, "vault-name", "", "", "specify the vault name") - cmd.Flags().StringVarP(&r.Vault.Bucket, "vault-bucket", "", "", "specify the vault bucket") - cmd.Flags().StringVarP(&r.Vault.Keyring, "vault-keyring", "", "", "specify the vault key ring") - cmd.Flags().StringVarP(&r.Vault.Key, "vault-key", "", "", "specify the vault key") - cmd.Flags().StringVarP(&r.Vault.ServiceAccount, "vault-sa", "", "", "specify the vault Service Account name") - - // velero - cmd.Flags().StringVarP(&r.Velero.ServiceAccount, "velero-sa", "", "", "specify the Velero Service Account name") - cmd.Flags().StringVarP(&r.Velero.Namespace, "velero-ns", "", "", "specify the Velero Namespace") - - // version stream - cmd.Flags().StringVarP(&r.VersionStream.URL, "version-stream-url", "", "", "specify the Version Stream git URL") - cmd.Flags().StringVarP(&r.VersionStream.Ref, "version-stream-ref", "", "", "specify the Version Stream git reference (branch, tag, sha)") -} - -// AddGitRequirementsOptions adds git specific overrides to the given requirements -func AddGitRequirementsOptions(cmd *cobra.Command, r *config.RequirementsConfig) { - cmd.Flags().StringVarP(&r.Cluster.GitKind, "git-kind", "", "", fmt.Sprintf("the kind of git repository to use. Possible values: %s", strings.Join(gits.KindGits, ", "))) - cmd.Flags().StringVarP(&r.Cluster.GitName, "git-name", "", "", "the name of the git repository") - cmd.Flags().StringVarP(&r.Cluster.GitServer, "git-server", "", "", "the git server host such as https://github.com or https://gitlab.com") - cmd.Flags().StringVarP(&r.Cluster.EnvironmentGitOwner, "env-git-owner", "", "", "the git owner (organisation or user) used to own the git repositories for the environments") - cmd.Flags().StringArrayVarP(&r.Cluster.DevEnvApprovers, "approver", "", nil, "the git user names of the approvers for the environments") -} From eb72f11574448aa3141e1e73231984d79a9cfbce Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 11 Mar 2020 12:14:44 +0000 Subject: [PATCH 5/6] fix: upgrade jx --- go.mod | 2 +- go.sum | 4 ++-- pkg/cmd/create/create_test.go | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3ab9d8b..026bcac 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/heptio/sonobuoy v0.16.0 github.com/jenkins-x/go-scm v1.5.76 github.com/jenkins-x/golang-jenkins v0.0.0-20180919102630-65b83ad42314 - github.com/jenkins-x/jx v0.0.0-20200311103335-37bf33594977 + github.com/jenkins-x/jx v0.0.0-20200311114321-719da6f179ca github.com/jetstack/cert-manager v0.5.2 github.com/knative/serving v0.7.0 github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index ba9db0e..4cc9e1b 100644 --- a/go.sum +++ b/go.sum @@ -433,8 +433,8 @@ github.com/jenkins-x/go-scm v1.5.76 h1:IMlfD8K+XieU2rvA8Sp2fz6FejhFo6JuUG/Do1SZ9 github.com/jenkins-x/go-scm v1.5.76/go.mod h1:PCT338UhP/pQ0IeEeMEf/hoLTYKcH7qjGEKd7jPkeYg= github.com/jenkins-x/golang-jenkins v0.0.0-20180919102630-65b83ad42314 h1:kyBMx/ucSV92S+umX/V6DDaPNynlFFOM9MGJWApltoU= github.com/jenkins-x/golang-jenkins v0.0.0-20180919102630-65b83ad42314/go.mod h1:C6j5HgwlHGjRU27W4XCs6jXksqYFo8OdBu+p44jqQeM= -github.com/jenkins-x/jx v0.0.0-20200311103335-37bf33594977 h1:pOQnxhSDmuKJOnRqBCliU+n3uuuTmMYU46Igs2/yyHY= -github.com/jenkins-x/jx v0.0.0-20200311103335-37bf33594977/go.mod h1:QZVsigjVZ634iK2TqkIs10yANye4JbBF2bHd3i41U8o= +github.com/jenkins-x/jx v0.0.0-20200311114321-719da6f179ca h1:nS/m/akMwuKR95E3ZVzWgqkbWStsf0tPhWELUDQ2Mn4= +github.com/jenkins-x/jx v0.0.0-20200311114321-719da6f179ca/go.mod h1:QZVsigjVZ634iK2TqkIs10yANye4JbBF2bHd3i41U8o= github.com/jetstack/cert-manager v0.5.2 h1:qs74mdAprZ5kcCYF3arzmEAZtbt+9HneldSJrk21tKs= github.com/jetstack/cert-manager v0.5.2/go.mod h1:nbddmhjWxYGt04bxvwVGUSeLhZ2PCyNvd7MpXdq+yWY= github.com/jinzhu/gorm v0.0.0-20170316141641-572d0a0ab1eb/go.mod h1:Vla75njaFJ8clLU1W44h34PjIkijhjHIYnZxMqCdxqo= diff --git a/pkg/cmd/create/create_test.go b/pkg/cmd/create/create_test.go index e89990d..8edbe03 100644 --- a/pkg/cmd/create/create_test.go +++ b/pkg/cmd/create/create_test.go @@ -119,6 +119,10 @@ func TestCreate(t *testing.T) { } t.Logf("requirements.Environments[%d].RemoteCluster = %v for key %s ", i, e.RemoteCluster, e.Key) } + + if requirements.Cluster.Provider == "kind" { + assert.Equal(t, true, requirements.Ingress.IgnoreLoadBalancer, "dev requirements.Ingress.IgnoreLoadBalancer for test %s", tc.Name) + } } } From 968875c3b574ce831d6bb997b205918d12167586 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Wed, 11 Mar 2020 12:18:23 +0000 Subject: [PATCH 6/6] chore: fix hound --- pkg/reqhelpers/helpers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/reqhelpers/helpers.go b/pkg/reqhelpers/helpers.go index ec6e0a3..75c936e 100644 --- a/pkg/reqhelpers/helpers.go +++ b/pkg/reqhelpers/helpers.go @@ -112,7 +112,7 @@ func GetRequirementsFromGit(gitURL string) (*config.RequirementsConfig, error) { return requirements, nil } -// OverrideRequirements +// OverrideRequirements allows CLI overrides func OverrideRequirements(cmd *cobra.Command, args []string, dir string, outputRequirements *config.RequirementsConfig, flags *RequirementBools) error { requirements, fileName, err := config.LoadRequirementsConfig(dir) if err != nil { @@ -158,7 +158,7 @@ func OverrideRequirements(cmd *cobra.Command, args []string, dir string, outputR return nil } -// OverrideRequirements +// ValidateApps validates the apps match the requirements func ValidateApps(dir string) (*config.AppConfig, string, error) { requirements, _, err := config.LoadRequirementsConfig(dir) if err != nil {