From 797aec55287cff947bf6d6faaa71ac0d368abec5 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Tue, 21 Jul 2020 12:39:52 +0300 Subject: [PATCH] Add create/delete HelmRelease e2e tests --- .github/workflows/e2e.yaml | 14 ++++++++++++++ cmd/tk/create_helmrelease.go | 10 +++++++++- docs/cmd/tk_create_helmrelease.md | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 524c5693..2e4ec61e 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -91,6 +91,20 @@ jobs: - name: tk delete source git run: | ./bin/tk delete source git podinfo --silent + - name: tk create source helm + run: | + ./bin/tk create source helm podinfo \ + --url https://stefanprodan.github.io/podinfo + - name: tk create hr + run: | + ./bin/tk create hr podinfo \ + --target-namespace=default \ + --source=podinfo \ + --chart-name=podinfo \ + --chart-version=">4.0.0 <5.0.0" + - name: tk delete hr + run: | + ./bin/tk delete hr podinfo --silent - name: tk check run: | ./bin/tk check diff --git a/cmd/tk/create_helmrelease.go b/cmd/tk/create_helmrelease.go index fd10e2cd..076d5cc0 100644 --- a/cmd/tk/create_helmrelease.go +++ b/cmd/tk/create_helmrelease.go @@ -25,6 +25,7 @@ import ( corev1 "k8s.io/api/core/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/api/errors" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" @@ -43,6 +44,7 @@ var createHelmReleaseCmd = &cobra.Command{ Example: ` # Create a HelmRelease from a source tk create hr podinfo \ --interval=10m \ + --release-name=podinfo \ --target-namespace=default \ --source=podinfo \ --chart-name=podinfo \ @@ -69,6 +71,7 @@ var createHelmReleaseCmd = &cobra.Command{ } var ( + hrName string hrSource string hrDependsOn []string hrChartName string @@ -78,6 +81,7 @@ var ( ) func init() { + createHelmReleaseCmd.Flags().StringVar(&hrName, "release-name", "", "name used for the Helm release, defaults to a composition of '-'") createHelmReleaseCmd.Flags().StringVar(&hrSource, "source", "", "HelmRepository name") createHelmReleaseCmd.Flags().StringVar(&hrChartName, "chart-name", "", "Helm chart name") createHelmReleaseCmd.Flags().StringVar(&hrChartVersion, "chart-version", "", "Helm chart version, accepts semver range") @@ -121,7 +125,8 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error { Namespace: namespace, }, Spec: helmv2.HelmReleaseSpec{ - DependsOn: hrDependsOn, + ReleaseName: hrName, + DependsOn: hrDependsOn, Interval: metav1.Duration{ Duration: interval, }, @@ -255,6 +260,9 @@ func isHelmChartReady(ctx context.Context, kubeClient client.Client, name, names err := kubeClient.Get(ctx, namespacedName, &helmChart) if err != nil { + if apierrors.IsNotFound(err) { + return false, nil + } return false, err } diff --git a/docs/cmd/tk_create_helmrelease.md b/docs/cmd/tk_create_helmrelease.md index 9c295f60..1ed082e0 100644 --- a/docs/cmd/tk_create_helmrelease.md +++ b/docs/cmd/tk_create_helmrelease.md @@ -16,6 +16,7 @@ tk create helmrelease [name] [flags] # Create a HelmRelease from a source tk create hr podinfo \ --interval=10m \ + --release-name=podinfo \ --target-namespace=default \ --source=podinfo \ --chart-name=podinfo \ @@ -47,6 +48,7 @@ tk create helmrelease [name] [flags] --chart-version string Helm chart version, accepts semver range --depends-on stringArray HelmReleases that must be ready before this release can be installed -h, --help help for helmrelease + --release-name string name used for the Helm release, defaults to a composition of '-' --source string HelmRepository name --target-namespace string namespace to install this release, defaults to the HelmRelease namespace --values string local path to the values.yaml file