diff --git a/BUILD.bazel b/BUILD.bazel index a956abe5d5d..ae589aab32a 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -93,6 +93,7 @@ filegroup( "//test/e2e:all-srcs", "//test/integration:all-srcs", "//test/internal/apiserver:all-srcs", + "//test/internal/util:all-srcs", "//test/unit/coreclients:all-srcs", "//test/unit/discovery:all-srcs", "//test/unit/gen:all-srcs", diff --git a/cmd/ctl/pkg/install/install.go b/cmd/ctl/pkg/install/install.go index 3f33027e470..b3d09b4e470 100644 --- a/cmd/ctl/pkg/install/install.go +++ b/cmd/ctl/pkg/install/install.go @@ -47,6 +47,7 @@ type InstallOptions struct { ChartName string DryRun bool + Wait bool genericclioptions.IOStreams } @@ -120,7 +121,7 @@ func NewCmdInstall(ctx context.Context, ioStreams genericclioptions.IOStreams, f SilenceErrors: true, } - addInstallUninstallFlags(cmd.Flags(), &options.client.Timeout, &options.client.Wait) + addInstallUninstallFlags(cmd.Flags(), &options.client.Timeout, &options.Wait) addInstallFlags(cmd.Flags(), options.client) addValueOptionsFlags(cmd.Flags(), options.valueOpts) addChartPathOptionsFlags(cmd.Flags(), &options.client.ChartPathOptions) @@ -229,12 +230,11 @@ func (o *InstallOptions) runInstall(ctx context.Context) (*release.Release, erro // Install chart o.client.DryRun = false // Apply DryRun cli flags o.client.ClientOnly = false // Perform install against cluster - // 'Atomic=True' means that if part of the install fails, all resource installs are reverted; - // Helm supports 3 diffent combinations of the (Atomic, Wait) boolean couple: - // (False, False), (False, True) or (True, True) - // For simplicity, we want do not support Waiting without the Atomic option (False, True), - // this allows this cli to use a single --wait=(True|False) flag - o.client.Atomic = o.client.Wait + + o.client.Wait = o.Wait // Wait for resources to be ready + o.client.Atomic = o.Wait // If part of the install fails (& we are waiting), all resource installs are reverted; + o.client.DisableHooks = !o.Wait // Disable hooks if wait is disabled + chartValues[installCRDsFlagName] = false // Do not render CRDs, as this might cause problems when uninstalling using helm return o.client.Run(chart, chartValues) diff --git a/test/integration/ctl/BUILD.bazel b/test/integration/ctl/BUILD.bazel index b8e3d76db62..d8f4f5ad65c 100644 --- a/test/integration/ctl/BUILD.bazel +++ b/test/integration/ctl/BUILD.bazel @@ -8,7 +8,9 @@ go_test( "ctl_renew_test.go", "ctl_status_certificate_test.go", ], - data = glob(["testdata/**"]), + data = glob(["testdata/**"]) + [ + "//deploy/charts/cert-manager:cert-manager.tgz", + ], embed = [":go_default_library"], deps = [ "//cmd/ctl/pkg/convert:go_default_library", @@ -59,6 +61,7 @@ go_library( deps = [ "//cmd/ctl/cmd:go_default_library", "//test/integration/ctl/install_framework:go_default_library", + "//test/internal/util:go_default_library", "@com_github_sergi_go_diff//diffmatchpatch:go_default_library", ], ) diff --git a/test/integration/ctl/ctl_install.go b/test/integration/ctl/ctl_install.go index 1ea2b00c68d..80d6c75dc8a 100644 --- a/test/integration/ctl/ctl_install.go +++ b/test/integration/ctl/ctl_install.go @@ -29,6 +29,7 @@ import ( "github.com/jetstack/cert-manager/cmd/ctl/cmd" "github.com/jetstack/cert-manager/test/integration/ctl/install_framework" + "github.com/jetstack/cert-manager/test/internal/util" ) func TestCtlInstall(t *testing.T) { @@ -98,10 +99,12 @@ func executeCommandAndCheckOutput( stdin := bytes.NewBufferString("") stdout := bytes.NewBufferString("") + chartPath := util.GetTestPath("deploy", "charts", "cert-manager", "cert-manager.tgz") cmd := cmd.NewCertManagerCtlCommand(ctx, stdin, stdout, stdout) cmd.SetArgs(append([]string{ fmt.Sprintf("--kubeconfig=%s", kubeConfig), "--wait=false", + fmt.Sprintf("--chart-name=%s", chartPath), "x", "install", }, inputArgs...)) diff --git a/test/internal/apiserver/BUILD.bazel b/test/internal/apiserver/BUILD.bazel index aa2e944fe2d..5750e8b6be9 100644 --- a/test/internal/apiserver/BUILD.bazel +++ b/test/internal/apiserver/BUILD.bazel @@ -4,11 +4,14 @@ go_library( name = "go_default_library", srcs = [ "apiserver.go", - "paths.go", + "envs.go", ], importpath = "github.com/jetstack/cert-manager/test/internal/apiserver", visibility = ["//test:__subpackages__"], - deps = ["@io_k8s_sigs_controller_runtime//pkg/envtest:go_default_library"], + deps = [ + "//test/internal/util:go_default_library", + "@io_k8s_sigs_controller_runtime//pkg/envtest:go_default_library", + ], ) filegroup( diff --git a/test/internal/apiserver/paths.go b/test/internal/apiserver/envs.go similarity index 91% rename from test/internal/apiserver/paths.go rename to test/internal/apiserver/envs.go index 14731c8d50d..ecf9355e4ef 100644 --- a/test/internal/apiserver/paths.go +++ b/test/internal/apiserver/envs.go @@ -20,7 +20,8 @@ import ( "fmt" "os" "os/exec" - "path/filepath" + + "github.com/jetstack/cert-manager/test/internal/util" ) // setEnvTestEnv configures environment variables for controller-runtime's @@ -44,7 +45,7 @@ Either re-run this test or set the %s environment variable.`, bin, key)) } func getPath(name string, path ...string) (string, error) { - bazelPath := filepath.Join(append([]string{os.Getenv("RUNFILES_DIR"), "com_github_jetstack_cert_manager"}, path...)...) + bazelPath := util.GetTestPath(path...) p, err := exec.LookPath(bazelPath) if err == nil { return p, nil diff --git a/test/internal/util/BUILD.bazel b/test/internal/util/BUILD.bazel new file mode 100644 index 00000000000..3254053b540 --- /dev/null +++ b/test/internal/util/BUILD.bazel @@ -0,0 +1,22 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["paths.go"], + importpath = "github.com/jetstack/cert-manager/test/internal/util", + visibility = ["//test:__subpackages__"], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/test/internal/util/paths.go b/test/internal/util/paths.go new file mode 100644 index 00000000000..30af6dca9c0 --- /dev/null +++ b/test/internal/util/paths.go @@ -0,0 +1,26 @@ +/* +Copyright 2021 The cert-manager Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "os" + "path/filepath" +) + +func GetTestPath(path ...string) string { + return filepath.Join(append([]string{os.Getenv("RUNFILES_DIR"), "com_github_jetstack_cert_manager"}, path...)...) +}