Skip to content

Commit

Permalink
Wait for global before ready during test
Browse files Browse the repository at this point in the history
  • Loading branch information
SaaldjorMike committed May 3, 2024
1 parent 8d8a778 commit b424265
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion controllers/suite/clusters/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var _ = BeforeSuite(func() {
useExistingCluster := true
testProcessNamespace = fmt.Sprintf("e2e-clusters-%d", GinkgoParallelProcess())
if os.Getenv("TEST_USE_EXISTING_CLUSTER") == "true" {
testTimeout = time.Second * 300
testTimeout = time.Second * 900
testEnv = &envtest.Environment{
UseExistingCluster: &useExistingCluster,
}
Expand Down
49 changes: 49 additions & 0 deletions controllers/suite/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (
dockerPasswordEnvVar = "DOCKER_PASSWORD"
// DockerRegistryCredentialsSecretName is the name of the k8s secret containing the registry credentials
DockerRegistryCredentialsSecretName = "regcred"

sidecarWaitForGlobalImageVersion = "alpine:20240329"
)

const TestInterval = time.Second * 1
Expand Down Expand Up @@ -173,6 +175,8 @@ func CleanupCluster(ctx context.Context, k8sClient client.Client, hc *humiov1alp

func ConstructBasicNodeSpecForHumioCluster(key types.NamespacedName) humiov1alpha1.HumioNodeSpec {
storageClassNameStandard := "standard"
userID := int64(65534)

nodeSpec := humiov1alpha1.HumioNodeSpec{
Image: controllers.Image,
ExtraKafkaConfigs: "security.protocol=PLAINTEXT",
Expand All @@ -198,6 +202,51 @@ func ConstructBasicNodeSpecForHumioCluster(key types.NamespacedName) humiov1alph
},
},
},
SidecarContainers: []corev1.Container{
{
Name: "wait-for-global-snapshot-on-disk",
Image: sidecarWaitForGlobalImageVersion,
Command: []string{"/bin/sh"},
Args: []string{
"-c",
"trap 'exit 0' 15; while true; do sleep 100 & wait $!; done",
},
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{
"/bin/sh",
"-c",
"ls /mnt/global*.json",
},
},
},
InitialDelaySeconds: 5,
TimeoutSeconds: 5,
PeriodSeconds: 10,
SuccessThreshold: 1,
FailureThreshold: 100,
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "humio-data",
MountPath: "/mnt",
ReadOnly: true,
},
},
SecurityContext: &corev1.SecurityContext{
Privileged: helpers.BoolPtr(false),
AllowPrivilegeEscalation: helpers.BoolPtr(false),
ReadOnlyRootFilesystem: helpers.BoolPtr(true),
RunAsUser: &userID,
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{
"ALL",
},
},
},
},
},
EnvironmentVariables: []corev1.EnvVar{
{
Name: "ZOOKEEPER_URL",
Expand Down
2 changes: 1 addition & 1 deletion hack/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ wait_for_pod() {
preload_container_images() {
# Extract humio images and tags from go source
DEFAULT_IMAGE=$(grep '^\s*Image\s*=' controllers/humiocluster_defaults.go | cut -d '"' -f 2)
PRE_UPDATE_IMAGES=$(grep 'Version\s* = ' controllers/suite/clusters/humiocluster_controller_test.go | grep -v oldUnsupportedHumioVersion | grep -v 1.x.x | cut -d '"' -f 2 | sort -u)
PRE_UPDATE_IMAGES=$(grep -R 'Version\s* = ' controllers/suite | grep -v oldUnsupportedHumioVersion | grep -v 1.x.x | cut -d '"' -f 2 | sort -u)

# Preload default image used by tests
$docker pull $DEFAULT_IMAGE
Expand Down

0 comments on commit b424265

Please sign in to comment.