Skip to content

Commit

Permalink
don't wait for hooks in kubectl cert-manager x install test & use loc…
Browse files Browse the repository at this point in the history
…al chart for tests

Signed-off-by: Inteon <42113979+inteon@users.noreply.github.com>
  • Loading branch information
inteon committed Aug 11, 2021
1 parent 17a5066 commit e5df60d
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 12 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions cmd/ctl/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type InstallOptions struct {

ChartName string
DryRun bool
Wait bool

genericclioptions.IOStreams
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion test/integration/ctl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
],
)
3 changes: 3 additions & 0 deletions test/integration/ctl/ctl_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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...))
Expand Down
7 changes: 5 additions & 2 deletions test/internal/apiserver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions test/internal/util/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
26 changes: 26 additions & 0 deletions test/internal/util/paths.go
Original file line number Diff line number Diff line change
@@ -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...)...)
}

0 comments on commit e5df60d

Please sign in to comment.