From 7ab6904124db56e04e2db695dc0f8e86cf51ee32 Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Tue, 24 Sep 2024 16:05:42 +0200 Subject: [PATCH] Add fake license string to allow running tests with envtest or dummy image without a valid license --- .github/workflows/ci.yaml | 2 -- .github/workflows/e2e-dummy.yaml | 1 - Makefile | 3 --- controllers/suite/clusters/suite_test.go | 4 +++- controllers/suite/common.go | 6 +++++- controllers/suite/resources/suite_test.go | 4 +++- hack/run-e2e-using-kind-dummy.sh | 3 +-- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 34b08d65..43206401 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -23,8 +23,6 @@ jobs: - shell: bash run: | make test - env: - HUMIO_E2E_LICENSE: ${{ secrets.HUMIO_E2E_LICENSE }} - name: Publish Test Report uses: mikepenz/action-junit-report@v4 if: always() # always run even if the previous step fails diff --git a/.github/workflows/e2e-dummy.yaml b/.github/workflows/e2e-dummy.yaml index 7a01a047..1c161d3a 100644 --- a/.github/workflows/e2e-dummy.yaml +++ b/.github/workflows/e2e-dummy.yaml @@ -39,7 +39,6 @@ jobs: - name: run e2e tests env: BIN_DIR: ${{ steps.bin_dir.outputs.BIN_DIR }} - HUMIO_E2E_LICENSE: ${{ secrets.HUMIO_E2E_LICENSE }} E2E_KIND_K8S_VERSION: ${{ matrix.kind-k8s-version }} E2E_LOGS_HUMIO_HOSTNAME: ${{ secrets.E2E_LOGS_HUMIO_HOSTNAME }} E2E_LOGS_HUMIO_INGEST_TOKEN: ${{ secrets.E2E_LOGS_HUMIO_INGEST_TOKEN }} diff --git a/Makefile b/Makefile index 6f7d4f97..c025c382 100644 --- a/Makefile +++ b/Makefile @@ -49,9 +49,6 @@ vet: ## Run go vet against code. go vet ./... test: manifests generate fmt vet ginkgo ## Run tests. -ifndef HUMIO_E2E_LICENSE - $(error HUMIO_E2E_LICENSE not set) -endif go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest $(SHELL) -c "\ eval \$$($(GOBIN)/setup-envtest use -p env ${TEST_K8S_VERSION}); \ diff --git a/controllers/suite/clusters/suite_test.go b/controllers/suite/clusters/suite_test.go index 727b4cf0..1be4e549 100644 --- a/controllers/suite/clusters/suite_test.go +++ b/controllers/suite/clusters/suite_test.go @@ -84,7 +84,9 @@ var _ = BeforeSuite(func() { log = zapr.NewLogger(zapLog) logf.SetLogger(log) - Expect(os.Getenv("HUMIO_E2E_LICENSE")).NotTo(BeEmpty()) + if os.Getenv("DUMMY_LOGSCALE_IMAGE") != "true" { + Expect(os.Getenv("HUMIO_E2E_LICENSE")).NotTo(BeEmpty()) + } By("bootstrapping test environment") useExistingCluster := true diff --git a/controllers/suite/common.go b/controllers/suite/common.go index 606bf2be..3acaa880 100644 --- a/controllers/suite/common.go +++ b/controllers/suite/common.go @@ -311,12 +311,16 @@ func ConstructBasicSingleNodeHumioCluster(key types.NamespacedName, useAutoCreat func CreateLicenseSecret(ctx context.Context, clusterKey types.NamespacedName, k8sClient client.Client, cluster *humiov1alpha1.HumioCluster) { UsingClusterBy(cluster.Name, fmt.Sprintf("Creating the license secret %s", cluster.Spec.License.SecretKeyRef.Name)) + licenseString := "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzUxMiJ9.eyJpc09lbSI6ZmFsc2UsImF1ZCI6Ikh1bWlvLWxpY2Vuc2UtY2hlY2siLCJzdWIiOiJIdW1pbyBFMkUgdGVzdHMiLCJ1aWQiOiJGUXNvWlM3Yk1PUldrbEtGIiwibWF4VXNlcnMiOjEwLCJhbGxvd1NBQVMiOnRydWUsIm1heENvcmVzIjoxLCJ2YWxpZFVudGlsIjoxNzQzMTY2ODAwLCJleHAiOjE3NzQ1OTMyOTcsImlzVHJpYWwiOmZhbHNlLCJpYXQiOjE2Nzk5ODUyOTcsIm1heEluZ2VzdEdiUGVyRGF5IjoxfQ.someinvalidsignature" + if os.Getenv("DUMMY_LOGSCALE_IMAGE") != "true" { + licenseString = os.Getenv("HUMIO_E2E_LICENSE") + } licenseSecret := corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("%s-license", clusterKey.Name), Namespace: clusterKey.Namespace, }, - StringData: map[string]string{"license": os.Getenv("HUMIO_E2E_LICENSE")}, + StringData: map[string]string{"license": licenseString}, Type: corev1.SecretTypeOpaque, } Expect(k8sClient.Create(ctx, &licenseSecret)).To(Succeed()) diff --git a/controllers/suite/resources/suite_test.go b/controllers/suite/resources/suite_test.go index 505272f6..5e2cdff3 100644 --- a/controllers/suite/resources/suite_test.go +++ b/controllers/suite/resources/suite_test.go @@ -90,7 +90,9 @@ var _ = BeforeSuite(func() { log = zapr.NewLogger(zapLog) logf.SetLogger(log) - Expect(os.Getenv("HUMIO_E2E_LICENSE")).NotTo(BeEmpty()) + if os.Getenv("DUMMY_LOGSCALE_IMAGE") != "true" { + Expect(os.Getenv("HUMIO_E2E_LICENSE")).NotTo(BeEmpty()) + } By("bootstrapping test environment") useExistingCluster := true diff --git a/hack/run-e2e-using-kind-dummy.sh b/hack/run-e2e-using-kind-dummy.sh index d5bfd50a..a9c36e80 100755 --- a/hack/run-e2e-using-kind-dummy.sh +++ b/hack/run-e2e-using-kind-dummy.sh @@ -10,7 +10,6 @@ trap "cleanup_kind_cluster" EXIT declare -r ginkgo_nodes=${GINKGO_NODES:-6} declare -r docker=$(which docker) -declare -r humio_e2e_license=${HUMIO_E2E_LICENSE} declare -r e2e_run_ref=${GITHUB_REF:-outside-github-$(hostname)} declare -r e2e_run_id=${GITHUB_RUN_ID:-none} declare -r e2e_run_attempt=${GITHUB_RUN_ATTEMPT:-none} @@ -48,6 +47,6 @@ if [[ $use_certmanager == "true" ]]; then fi $kubectl apply --server-side=true -k config/crd/ -$kubectl run test-pod --env="HUMIO_E2E_LICENSE=$humio_e2e_license" --env="GINKGO_NODES=$ginkgo_nodes" --env="DOCKER_USERNAME=$docker_username" --env="DOCKER_PASSWORD=$docker_password" --env="USE_CERTMANAGER=$use_certmanager" --restart=Never --image=testcontainer --image-pull-policy=Never -- sleep 86400 +$kubectl run test-pod --env="GINKGO_NODES=$ginkgo_nodes" --env="DOCKER_USERNAME=$docker_username" --env="DOCKER_PASSWORD=$docker_password" --env="USE_CERTMANAGER=$use_certmanager" --restart=Never --image=testcontainer --image-pull-policy=Never -- sleep 86400 while [[ $($kubectl get pods test-pod -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "waiting for pod" ; $kubectl describe pod test-pod ; sleep 1 ; done $kubectl exec test-pod -- hack/run-e2e-within-kind-test-pod-dummy.sh