mirror of
https://github.com/stakater/Reloader.git
synced 2026-08-27 14:37:17 +00:00
Simplifies test.
This commit is contained in:
@@ -39,6 +39,7 @@ var (
|
|||||||
secretWithEnvFromName = "testsecretWithEnvFrom-handler-" + testutil.RandSeq(5)
|
secretWithEnvFromName = "testsecretWithEnvFrom-handler-" + testutil.RandSeq(5)
|
||||||
configmapWithPodAnnotations = "testconfigmapPodAnnotations-handler-" + testutil.RandSeq(5)
|
configmapWithPodAnnotations = "testconfigmapPodAnnotations-handler-" + testutil.RandSeq(5)
|
||||||
configmapWithBothAnnotations = "testconfigmapBothAnnotations-handler-" + testutil.RandSeq(5)
|
configmapWithBothAnnotations = "testconfigmapBothAnnotations-handler-" + testutil.RandSeq(5)
|
||||||
|
configmapAnnotated = "testconfigmapAnnotated-handler-" + testutil.RandSeq(5)
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
@@ -229,6 +230,17 @@ func setup() {
|
|||||||
logrus.Errorf("Error in Deployment with secret configmap as envFrom source creation: %v", err)
|
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,
|
||||||
|
configmapAnnotated,
|
||||||
|
namespace,
|
||||||
|
map[string]string{"reloader.stakater.com/search": "true"},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("Error in Deployment with secret configmap as envFrom source creation: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Creating DaemonSet with configmap
|
// Creating DaemonSet with configmap
|
||||||
_, err = testutil.CreateDaemonSet(clients.KubernetesClient, configmapName, namespace, true)
|
_, err = testutil.CreateDaemonSet(clients.KubernetesClient, configmapName, namespace, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -411,6 +423,12 @@ func teardown() {
|
|||||||
logrus.Errorf("Error while deleting deployment with both annotations %v", deploymentError)
|
logrus.Errorf("Error while deleting deployment with both annotations %v", deploymentError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deleting Deployment with search annotation
|
||||||
|
deploymentError = testutil.DeleteDeployment(clients.KubernetesClient, namespace, configmapAnnotated)
|
||||||
|
if deploymentError != nil {
|
||||||
|
logrus.Errorf("Error while deleting deployment with search annotation %v", deploymentError)
|
||||||
|
}
|
||||||
|
|
||||||
// Deleting DaemonSet with configmap
|
// Deleting DaemonSet with configmap
|
||||||
daemonSetError := testutil.DeleteDaemonSet(clients.KubernetesClient, namespace, configmapName)
|
daemonSetError := testutil.DeleteDaemonSet(clients.KubernetesClient, namespace, configmapName)
|
||||||
if daemonSetError != nil {
|
if daemonSetError != nil {
|
||||||
@@ -646,30 +664,13 @@ func createConfigMap(clients *kube.Clients, namespace, name string, annotations
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotation(t *testing.T) {
|
func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotation(t *testing.T) {
|
||||||
annotatedConfigmapName := "testconfigmapAnnotated-handler"
|
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, configmapAnnotated, "www.stakater.com")
|
||||||
configmap, err := createConfigMap(&clients, namespace, annotatedConfigmapName, map[string]string{"reloader.stakater.com/match": "true"})
|
config := getConfigWithAnnotations(constants.ConfigmapEnvVarPostfix, configmapAnnotated, shaData, "")
|
||||||
if err != nil {
|
config.ResourceAnnotations = map[string]string{"reloader.stakater.com/match": "true"}
|
||||||
t.Errorf("Failed to create config map with annotation.")
|
|
||||||
}
|
|
||||||
defer clients.KubernetesClient.CoreV1().ConfigMaps(namespace).Delete(configmap.Name, &v1.DeleteOptions{})
|
|
||||||
deployment, err := testutil.CreateDeploymentWithEnvVarSourceAndAnnotations(
|
|
||||||
clients.KubernetesClient,
|
|
||||||
annotatedConfigmapName,
|
|
||||||
namespace,
|
|
||||||
map[string]string{"reloader.stakater.com/search": "true"},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Failed to create deployment with search annotation.")
|
|
||||||
}
|
|
||||||
defer clients.KubernetesClient.AppsV1().Deployments(namespace).Delete(deployment.Name, &v1.DeleteOptions{})
|
|
||||||
|
|
||||||
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, annotatedConfigmapName, "www.stakater.com")
|
|
||||||
config := getConfigWithAnnotations(constants.ConfigmapEnvVarPostfix, annotatedConfigmapName, shaData, "")
|
|
||||||
config.ResourceAnnotations = configmap.Annotations
|
|
||||||
deploymentFuncs := GetDeploymentRollingUpgradeFuncs()
|
deploymentFuncs := GetDeploymentRollingUpgradeFuncs()
|
||||||
collectors := getCollectors()
|
collectors := getCollectors()
|
||||||
|
|
||||||
err = PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
|
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Rolling upgrade failed for Deployment with Configmap")
|
t.Errorf("Rolling upgrade failed for Deployment with Configmap")
|
||||||
}
|
}
|
||||||
@@ -686,29 +687,13 @@ func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotation(t *testing.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotationNoTriggers(t *testing.T) {
|
func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotationNoTriggers(t *testing.T) {
|
||||||
annotatedConfigmapName := "testconfigmapAnnotated-handler-" + testutil.RandSeq(5)
|
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, configmapAnnotated, "www.stakater.com")
|
||||||
configmap, err := createConfigMap(&clients, namespace, annotatedConfigmapName, map[string]string{"reloader.stakater.com/match": "false"})
|
config := getConfigWithAnnotations(constants.ConfigmapEnvVarPostfix, configmapAnnotated, shaData, "")
|
||||||
if err != nil {
|
config.ResourceAnnotations = map[string]string{"reloader.stakater.com/match": "false"}
|
||||||
t.Errorf("Failed to create config map with annotation.")
|
|
||||||
}
|
|
||||||
deployment, err := testutil.CreateDeploymentWithEnvVarSourceAndAnnotations(
|
|
||||||
clients.KubernetesClient,
|
|
||||||
annotatedConfigmapName,
|
|
||||||
namespace,
|
|
||||||
map[string]string{"reloader.stakater.com/search": "true"},
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Failed to create deployment with search annotation.")
|
|
||||||
}
|
|
||||||
defer clients.KubernetesClient.AppsV1().Deployments(namespace).Delete(deployment.Name, &v1.DeleteOptions{})
|
|
||||||
|
|
||||||
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, annotatedConfigmapName, "www.stakater.com")
|
|
||||||
config := getConfigWithAnnotations(constants.ConfigmapEnvVarPostfix, annotatedConfigmapName, shaData, "")
|
|
||||||
config.ResourceAnnotations = configmap.Annotations
|
|
||||||
deploymentFuncs := GetDeploymentRollingUpgradeFuncs()
|
deploymentFuncs := GetDeploymentRollingUpgradeFuncs()
|
||||||
collectors := getCollectors()
|
collectors := getCollectors()
|
||||||
|
|
||||||
err = PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
|
err := PerformRollingUpgrade(clients, config, deploymentFuncs, collectors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Rolling upgrade failed for Deployment with Configmap")
|
t.Errorf("Rolling upgrade failed for Deployment with Configmap")
|
||||||
}
|
}
|
||||||
@@ -726,15 +711,9 @@ func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotationNoTriggers(t
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotationNotMapped(t *testing.T) {
|
func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotationNotMapped(t *testing.T) {
|
||||||
annotatedConfigmapName := "testconfigmapAnnotated-handler-" + testutil.RandSeq(5)
|
|
||||||
configmap, err := createConfigMap(&clients, namespace, annotatedConfigmapName, map[string]string{"reloader.stakater.com/match": "true"})
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Failed to create config map with annotation.")
|
|
||||||
}
|
|
||||||
defer clients.KubernetesClient.CoreV1().ConfigMaps(namespace).Delete(configmap.Name, &v1.DeleteOptions{})
|
|
||||||
deployment, err := testutil.CreateDeploymentWithEnvVarSourceAndAnnotations(
|
deployment, err := testutil.CreateDeploymentWithEnvVarSourceAndAnnotations(
|
||||||
clients.KubernetesClient,
|
clients.KubernetesClient,
|
||||||
annotatedConfigmapName+"-different",
|
configmapAnnotated+"-different",
|
||||||
namespace,
|
namespace,
|
||||||
map[string]string{"reloader.stakater.com/search": "true"},
|
map[string]string{"reloader.stakater.com/search": "true"},
|
||||||
)
|
)
|
||||||
@@ -743,9 +722,9 @@ func TestRollingUpgradeForDeploymentWithConfigmapViaSearchAnnotationNotMapped(t
|
|||||||
}
|
}
|
||||||
defer clients.KubernetesClient.AppsV1().Deployments(namespace).Delete(deployment.Name, &v1.DeleteOptions{})
|
defer clients.KubernetesClient.AppsV1().Deployments(namespace).Delete(deployment.Name, &v1.DeleteOptions{})
|
||||||
|
|
||||||
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, annotatedConfigmapName, "www.stakater.com")
|
shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, namespace, configmapAnnotated, "www.stakater.com")
|
||||||
config := getConfigWithAnnotations(constants.ConfigmapEnvVarPostfix, annotatedConfigmapName, shaData, "")
|
config := getConfigWithAnnotations(constants.ConfigmapEnvVarPostfix, configmapAnnotated, shaData, "")
|
||||||
config.ResourceAnnotations = configmap.Annotations
|
config.ResourceAnnotations = map[string]string{"reloader.stakater.com/match": "false"}
|
||||||
deploymentFuncs := GetDeploymentRollingUpgradeFuncs()
|
deploymentFuncs := GetDeploymentRollingUpgradeFuncs()
|
||||||
collectors := getCollectors()
|
collectors := getCollectors()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user