Skip to content

Commit

Permalink
Add test scenario with dummy images and mock client
Browse files Browse the repository at this point in the history
  • Loading branch information
SaaldjorMike committed Aug 28, 2024
1 parent 30acbb0 commit c324930
Show file tree
Hide file tree
Showing 25 changed files with 945 additions and 547 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/e2e-dummy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
on: pull_request
name: e2e-dummy
jobs:
e2e-dummy:
name: ${{ matrix.kind-k8s-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
kind-k8s-version:
- kindest/node:v1.21.14@sha256:8a4e9bb3f415d2bb81629ce33ef9c76ba514c14d707f9797a01e3216376ba093 # Not officially supported by kind 0.22.0
- kindest/node:v1.22.17@sha256:f5b2e5698c6c9d6d0adc419c0deae21a425c07d81bbf3b6a6834042f25d4fba2 # Not officially supported by kind 0.22.0
- kindest/node:v1.23.17@sha256:14d0a9a892b943866d7e6be119a06871291c517d279aedb816a4b4bc0ec0a5b3
- kindest/node:v1.24.17@sha256:bad10f9b98d54586cba05a7eaa1b61c6b90bfc4ee174fdc43a7b75ca75c95e51
- kindest/node:v1.25.16@sha256:e8b50f8e06b44bb65a93678a65a26248fae585b3d3c2a669e5ca6c90c69dc519
- kindest/node:v1.26.14@sha256:5d548739ddef37b9318c70cb977f57bf3e5015e4552be4e27e57280a8cbb8e4f
- kindest/node:v1.27.11@sha256:681253009e68069b8e01aad36a1e0fa8cf18bb0ab3e5c4069b2e65cafdd70843
- kindest/node:v1.28.7@sha256:9bc6c451a289cf96ad0bbaf33d416901de6fd632415b076ab05f5fa7e4f65c58
- kindest/node:v1.29.2@sha256:51a1434a5397193442f0be2a297b488b6c919ce8a3931be0ce822606ea5ca245
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22.2'
- name: cleanup kind
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.22.0/kind-linux-amd64
chmod +x ./kind
./kind delete cluster || true
make clean
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get temp bin dir
id: bin_dir
run: echo "BIN_DIR=$(mktemp -d --tmpdir=${{ github.workspace }})" >> $GITHUB_OUTPUT
- 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 }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
GINKGO_NODES: "12"
run: |
hack/run-e2e-using-kind-dummy.sh
- name: cleanup kind and docker files
if: always()
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.22.0/kind-linux-amd64
chmod +x ./kind
./kind delete cluster || true
make clean
4 changes: 1 addition & 3 deletions .github/workflows/preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
echo "HUMIO_CORE_DEV_TAG=$LATEST_TAG" >> $GITHUB_OUTPUT
- name: run e2e tests
env:
HUMIO_CORE_DEV_TAG: ${{ steps.docker_tag.outputs.HUMIO_CORE_DEV_TAG }}
HUMIO_OPERATOR_DEFAULT_HUMIO_CORE_IMAGE: ${{ steps.docker_tag.outputs.HUMIO_CORE_DEV_TAG }}
BIN_DIR: ${{ steps.bin_dir.outputs.BIN_DIR }}
HUMIO_E2E_LICENSE: ${{ secrets.HUMIO_E2E_LICENSE }}
E2E_KIND_K8S_VERSION: ${{ matrix.kind-k8s-version }}
Expand All @@ -58,8 +58,6 @@ jobs:
GINKGO_NODES: "6"
run: |
echo "Running operator tests against humio-core-dev:$HUMIO_CORE_DEV_TAG"
sed -i "s/humio-core:[0-9.]*/humio-core-dev:$HUMIO_CORE_DEV_TAG/g" controllers/humiocluster_defaults.go
hack/run-e2e-using-kind.sh
- name: cleanup kind
if: always()
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/stale.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'Close stale issues and PRs'
on:
schedule:
- cron: '30 1 * * *'

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
stale-pr-message: 'This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.'
close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.'
close-pr-message: 'This PR was closed because it has been stalled for 10 days with no activity.'
days-before-issue-stale: 30
days-before-pr-stale: 45
days-before-issue-close: 5
days-before-pr-close: 10
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.22 as builder
FROM golang:1.22 AS builder

ARG RELEASE_VERSION=master
ARG RELEASE_COMMIT=none
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ endif
eval \$$($(GOBIN)/setup-envtest use -p env ${TEST_K8S_VERSION}); \
export USE_CERTMANAGER=false; \
export TEST_USE_EXISTING_CLUSTER=false; \
$(GINKGO) -vv --no-color --procs 3 -output-dir=${PWD} -keep-separate-reports --junit-report=test-results-junit.xml --randomize-suites --randomize-all -timeout 10m ./... -covermode=count -coverprofile cover.out \
$(GINKGO) --label-filter=envtest -vv --no-color --procs 3 -output-dir=${PWD} -keep-separate-reports --junit-report=test-results-junit.xml --randomize-suites --randomize-all -timeout 10m ./... -covermode=count -coverprofile cover.out \
"

##@ Build
Expand Down Expand Up @@ -131,6 +131,10 @@ docker-build-helper:
cp LICENSE images/helper/
docker build --no-cache --pull -t ${IMG} ${IMG_BUILD_ARGS} images/helper

# Build the logscale dummy docker image
docker-build-dummy:
docker build --no-cache --pull -t ${IMG} ${IMG_BUILD_ARGS} images/logscale-dummy

clean:
rm controllers_*.xml || true
rm -r testbindir || true
Expand Down
22 changes: 12 additions & 10 deletions controllers/humiocluster_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ import (

"k8s.io/apimachinery/pkg/util/intstr"

"github.com/humio/humio-operator/controllers/versions"
"github.com/humio/humio-operator/pkg/helpers"

humiov1alpha1 "github.com/humio/humio-operator/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
)

const (
Image = "humio/humio-core:1.131.1"
HelperImage = "humio/humio-operator-helper:8f5ef6c7e470226e77d985f36cf39be9a100afea"
targetReplicationFactor = 2
digestPartitionsCount = 24
HumioPort = 8080
Expand Down Expand Up @@ -245,7 +244,7 @@ func (hnp *HumioNodePool) GetImage() string {
return os.Getenv("HUMIO_OPERATOR_DEFAULT_HUMIO_CORE_IMAGE")
}

return Image
return versions.DefaultHumioImageVersion()
}

func (hnp *HumioNodePool) GetImageSource() *humiov1alpha1.HumioImageSource {
Expand All @@ -261,7 +260,7 @@ func (hnp *HumioNodePool) GetHelperImage() string {
return os.Getenv("HUMIO_OPERATOR_DEFAULT_HUMIO_HELPER_IMAGE")
}

return HelperImage
return versions.DefaultHelperImageVersion()
}

func (hnp *HumioNodePool) GetImagePullSecrets() []corev1.LocalObjectReference {
Expand Down Expand Up @@ -587,20 +586,23 @@ func (hnp *HumioNodePool) GetContainerReadinessProbe() *corev1.Probe {
}

if hnp.humioNodeSpec.ContainerReadinessProbe == nil {
return &corev1.Probe{
probe := &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/api/v1/is-node-up",
Port: intstr.IntOrString{IntVal: HumioPort},
Scheme: hnp.GetProbeScheme(),
},
},
InitialDelaySeconds: 30,
PeriodSeconds: 5,
TimeoutSeconds: 5,
SuccessThreshold: 1,
FailureThreshold: 10,
PeriodSeconds: 5,
TimeoutSeconds: 5,
SuccessThreshold: 1,
FailureThreshold: 10,
}
if os.Getenv("DUMMY_LOGSCALE_IMAGE") != "true" {
probe.InitialDelaySeconds = 30
}
return probe
}
return hnp.humioNodeSpec.ContainerReadinessProbe
}
Expand Down
15 changes: 10 additions & 5 deletions controllers/humiocluster_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"errors"
"fmt"
"os"
"reflect"
"sort"
"strings"
Expand Down Expand Up @@ -479,6 +480,11 @@ func ConstructPod(hnp *HumioNodePool, humioNodeName string, attachments *podAtta
pod.Spec.Volumes = append(pod.Spec.Volumes, volume)
}

authIdx, err := kubernetes.GetContainerIndexByName(pod, AuthContainerName)
if err != nil {
return &corev1.Pod{}, err
}

if hnp.TLSEnabled() {
pod.Annotations[certHashAnnotation] = GetDesiredCertHash(hnp)
pod.Spec.Containers[humioIdx].Env = append(pod.Spec.Containers[humioIdx].Env, corev1.EnvVar{
Expand Down Expand Up @@ -528,11 +534,6 @@ func ConstructPod(hnp *HumioNodePool, humioNodeName string, attachments *podAtta
MountPath: "/var/lib/humio/tls-certificate-secret",
})

// Configuration specific to auth container
authIdx, err := kubernetes.GetContainerIndexByName(pod, AuthContainerName)
if err != nil {
return &corev1.Pod{}, err
}
// We mount in the certificate on top of default system root certs so auth container automatically uses it:
// https://golang.org/src/crypto/x509/root_linux.go
pod.Spec.Containers[authIdx].VolumeMounts = append(pod.Spec.Containers[authIdx].VolumeMounts, corev1.VolumeMount{
Expand Down Expand Up @@ -591,6 +592,10 @@ func ConstructPod(hnp *HumioNodePool, humioNodeName string, attachments *podAtta
}
pod.Spec.Containers[humioIdx].Args = containerArgs

if os.Getenv("DUMMY_LOGSCALE_IMAGE") == "true" {
pod.Spec.Containers[authIdx].Env = append(pod.Spec.Containers[authIdx].Env, corev1.EnvVar{Name: "DUMMY_LOGSCALE_IMAGE", Value: "true"})
}

return &pod, nil
}

Expand Down
Loading

0 comments on commit c324930

Please sign in to comment.