Skip to content

Commit

Permalink
Add fake license string to allow running tests with envtest or dummy …
Browse files Browse the repository at this point in the history
…image without a valid license
  • Loading branch information
SaaldjorMike committed Sep 24, 2024
1 parent 1369975 commit 7ab6904
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/e2e-dummy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}); \
Expand Down
4 changes: 3 additions & 1 deletion controllers/suite/clusters/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion controllers/suite/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion controllers/suite/resources/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions hack/run-e2e-using-kind-dummy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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

0 comments on commit 7ab6904

Please sign in to comment.