Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
itaispiegel committed Aug 6, 2023
1 parent b9e24b3 commit cabe0d8
Showing 1 changed file with 19 additions and 63 deletions.
82 changes: 19 additions & 63 deletions internal/pkg/handler/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,25 @@ import (
var (
clients = kube.Clients{KubernetesClient: testclient.NewSimpleClientset()}

arsNamespace = "test-handler-" + testutil.RandSeq(5)
arsConfigmapName = "testconfigmap-handler-" + testutil.RandSeq(5)
arsSecretName = "testsecret-handler-" + testutil.RandSeq(5)
arsProjectedConfigMapName = "testprojectedconfigmap-handler-" + testutil.RandSeq(5)
arsProjectedSecretName = "testprojectedsecret-handler-" + testutil.RandSeq(5)
arsConfigmapWithInitContainer = "testconfigmapInitContainerhandler-" + testutil.RandSeq(5)
arsSecretWithInitContainer = "testsecretWithInitContainer-handler-" + testutil.RandSeq(5)
arsProjectedConfigMapWithInitContainer = "testProjectedConfigMapWithInitContainer-handler" + testutil.RandSeq(5)
arsProjectedSecretWithInitContainer = "testProjectedSecretWithInitContainer-handler" + testutil.RandSeq(5)
arsConfigmapWithInitEnv = "configmapWithInitEnv-" + testutil.RandSeq(5)
arsSecretWithInitEnv = "secretWithInitEnv-handler-" + testutil.RandSeq(5)
arsConfigmapWithEnvName = "testconfigmapWithEnv-handler-" + testutil.RandSeq(5)
arsConfigmapWithEnvFromName = "testconfigmapWithEnvFrom-handler-" + testutil.RandSeq(5)
arsSecretWithEnvName = "testsecretWithEnv-handler-" + testutil.RandSeq(5)
arsSecretWithEnvFromName = "testsecretWithEnvFrom-handler-" + testutil.RandSeq(5)
arsConfigmapWithPodAnnotations = "testconfigmapPodAnnotations-handler-" + testutil.RandSeq(5)
arsConfigmapWithBothAnnotations = "testconfigmapBothAnnotations-handler-" + testutil.RandSeq(5)
arsConfigmapAnnotated = "testconfigmapAnnotated-handler-" + testutil.RandSeq(5)
arsConfigMapWithNonAnnotatedDeployment = "testconfigmapNonAnnotatedDeployment-handler-" + testutil.RandSeq(5)
arsConfigMapWithDeploymentReloadSetToFalse = "testconfigMapWithDeploymentReloadSetToFalse-handler-" + testutil.RandSeq(5)
arsNamespace = "test-handler-" + testutil.RandSeq(5)
arsConfigmapName = "testconfigmap-handler-" + testutil.RandSeq(5)
arsSecretName = "testsecret-handler-" + testutil.RandSeq(5)
arsProjectedConfigMapName = "testprojectedconfigmap-handler-" + testutil.RandSeq(5)
arsProjectedSecretName = "testprojectedsecret-handler-" + testutil.RandSeq(5)
arsConfigmapWithInitContainer = "testconfigmapInitContainerhandler-" + testutil.RandSeq(5)
arsSecretWithInitContainer = "testsecretWithInitContainer-handler-" + testutil.RandSeq(5)
arsProjectedConfigMapWithInitContainer = "testProjectedConfigMapWithInitContainer-handler" + testutil.RandSeq(5)
arsProjectedSecretWithInitContainer = "testProjectedSecretWithInitContainer-handler" + testutil.RandSeq(5)
arsConfigmapWithInitEnv = "configmapWithInitEnv-" + testutil.RandSeq(5)
arsSecretWithInitEnv = "secretWithInitEnv-handler-" + testutil.RandSeq(5)
arsConfigmapWithEnvName = "testconfigmapWithEnv-handler-" + testutil.RandSeq(5)
arsConfigmapWithEnvFromName = "testconfigmapWithEnvFrom-handler-" + testutil.RandSeq(5)
arsSecretWithEnvName = "testsecretWithEnv-handler-" + testutil.RandSeq(5)
arsSecretWithEnvFromName = "testsecretWithEnvFrom-handler-" + testutil.RandSeq(5)
arsConfigmapWithPodAnnotations = "testconfigmapPodAnnotations-handler-" + testutil.RandSeq(5)
arsConfigmapWithBothAnnotations = "testconfigmapBothAnnotations-handler-" + testutil.RandSeq(5)
arsConfigmapAnnotated = "testconfigmapAnnotated-handler-" + testutil.RandSeq(5)
arsConfigMapWithNonAnnotatedDeployment = "testconfigmapNonAnnotatedDeployment-handler-" + testutil.RandSeq(5)

ersNamespace = "test-handler-" + testutil.RandSeq(5)
ersConfigmapName = "testconfigmap-handler-" + testutil.RandSeq(5)
Expand Down Expand Up @@ -180,11 +179,6 @@ func setupArs() {
logrus.Errorf("Error in configmap creation: %v", err)
}

_, err = testutil.CreateConfigMap(clients.KubernetesClient, arsNamespace, arsConfigMapWithDeploymentReloadSetToFalse, "www.google.com")
if err != nil {
logrus.Errorf("Error in configmap creation: %v", err)
}

// Creating Deployment with configmap
_, err = testutil.CreateDeployment(clients.KubernetesClient, arsConfigmapName, arsNamespace, true)
if err != nil {
Expand Down Expand Up @@ -280,17 +274,6 @@ func setupArs() {
logrus.Errorf("Error in Deployment with secret configmap as envFrom source creation: %v", err)
}

// Creating Deployment with envFrom source as secret
_, err = testutil.CreateDeploymentWithEnvVarSourceAndAnnotations(
clients.KubernetesClient,
arsConfigMapWithDeploymentReloadSetToFalse,
arsNamespace,
map[string]string{options.ReloaderAutoAnnotation: "false"},
)
if err != nil {
logrus.Errorf("Error in Deployment with secret configmap as envFrom source creation: %v", err)
}

// Creating Deployment with configmap and without annotations
_, err = testutil.CreateDeploymentWithEnvVarSourceAndAnnotations(clients.KubernetesClient, arsConfigMapWithNonAnnotatedDeployment, arsNamespace, map[string]string{})
if err != nil {
Expand Down Expand Up @@ -1287,33 +1270,6 @@ func TestRollingUpgradeForDeploymentWithConfigmapWithoutReloadAnnotationButWithA
}
}

func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotationAndAutoReloadAllSetToTrueNoTriggersUsingArs(t *testing.T) {
options.ReloadStrategy = constants.AnnotationsReloadStrategy
options.AutoReloadAll = true
defer func() { options.AutoReloadAll = false }()

shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, arsNamespace, arsConfigMapWithDeploymentReloadSetToFalse, "www.stakater.com")
config := getConfigWithAnnotations(constants.ConfigmapEnvVarPostfix, arsConfigMapWithDeploymentReloadSetToFalse, shaData, options.ReloaderAutoAnnotation)
deploymentFuncs := GetDeploymentRollingUpgradeFuncs()
collectors := getCollectors()

err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors, nil)
if err != nil {
t.Errorf("Rolling upgrade failed for Deployment with Configmap")
}

logrus.Infof("Verifying deployment update")
updated := testutil.VerifyResourceAnnotationUpdate(clients, config, deploymentFuncs)
time.Sleep(5 * time.Second)
if updated {
t.Errorf("Deployment was updated unexpectedly")
}

if promtestutil.ToFloat64(collectors.Reloaded.With(labelSucceeded)) > 0 {
t.Errorf("Counter was increased unexpectedly")
}
}

func TestRollingUpgradeForDeploymentWithConfigmapInProjectedVolumeUsingArs(t *testing.T) {
options.ReloadStrategy = constants.AnnotationsReloadStrategy

Expand Down

0 comments on commit cabe0d8

Please sign in to comment.