mirror of
https://github.com/stakater/Reloader.git
synced 2026-05-17 14:16:39 +00:00
feat: Initial e2e tests and migrate old ones into e2e
This commit is contained in:
106
test/e2e/flags/auto_reload_all_test.go
Normal file
106
test/e2e/flags/auto_reload_all_test.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stakater/Reloader/test/e2e/utils"
|
||||
)
|
||||
|
||||
var _ = Describe("Auto Reload All Flag Tests", func() {
|
||||
var (
|
||||
deploymentName string
|
||||
configMapName string
|
||||
autoNamespace string
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
deploymentName = utils.RandName("deploy")
|
||||
configMapName = utils.RandName("cm")
|
||||
autoNamespace = "auto-" + utils.RandName("ns")
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, autoNamespace, deploymentName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, autoNamespace, configMapName)
|
||||
})
|
||||
|
||||
Context("with autoReloadAll=true flag", func() {
|
||||
BeforeEach(func() {
|
||||
err := utils.CreateNamespace(ctx, kubeClient, autoNamespace)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = deployReloaderWithFlags(map[string]string{
|
||||
"reloader.autoReloadAll": "true",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, autoNamespace)
|
||||
})
|
||||
|
||||
It("should reload workloads without any annotations when autoReloadAll is true", func() {
|
||||
By("Creating a ConfigMap")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, autoNamespace, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment WITHOUT any Reloader annotations")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, autoNamespace, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(configMapName),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, autoNamespace, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, autoNamespace, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded (autoReloadAll=true)")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, autoNamespace, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "Deployment without annotations should reload when autoReloadAll=true")
|
||||
})
|
||||
|
||||
It("should respect auto=false annotation even when autoReloadAll is true", func() {
|
||||
By("Creating a ConfigMap")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, autoNamespace, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment with auto=false annotation")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, autoNamespace, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(configMapName),
|
||||
utils.WithAnnotations(utils.BuildAutoFalseAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, autoNamespace, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, autoNamespace, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Verifying Deployment was NOT reloaded (auto=false overrides autoReloadAll)")
|
||||
time.Sleep(utils.NegativeTestWait)
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, autoNamespace, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ShortTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeFalse(), "Deployment with auto=false should NOT reload even with autoReloadAll=true")
|
||||
})
|
||||
})
|
||||
})
|
||||
71
test/e2e/flags/flags_suite_test.go
Normal file
71
test/e2e/flags/flags_suite_test.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stakater/Reloader/test/e2e/utils"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
var (
|
||||
kubeClient kubernetes.Interface
|
||||
testNamespace string
|
||||
ctx context.Context
|
||||
testEnv *utils.TestEnvironment
|
||||
)
|
||||
|
||||
func TestFlags(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Flag-Based E2E Suite")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
var err error
|
||||
ctx = context.Background()
|
||||
|
||||
// Setup test environment (but don't deploy Reloader - tests do that with specific flags)
|
||||
testEnv, err = utils.SetupTestEnvironment(ctx, "reloader-flags")
|
||||
Expect(err).NotTo(HaveOccurred(), "Failed to setup test environment")
|
||||
|
||||
// Export for use in tests
|
||||
kubeClient = testEnv.KubeClient
|
||||
testNamespace = testEnv.Namespace
|
||||
|
||||
// Note: Unlike other suites, we don't deploy Reloader here.
|
||||
// Each test deploys with specific flag configurations.
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
if testEnv != nil {
|
||||
err := testEnv.Cleanup()
|
||||
Expect(err).NotTo(HaveOccurred(), "Failed to cleanup test environment")
|
||||
}
|
||||
|
||||
GinkgoWriter.Println("Flags E2E Suite cleanup complete")
|
||||
})
|
||||
|
||||
// deployReloaderWithFlags deploys Reloader with the specified Helm value overrides.
|
||||
// This is a convenience function for tests that need to deploy with specific flags.
|
||||
func deployReloaderWithFlags(values map[string]string) error {
|
||||
// Always include annotations strategy
|
||||
if values == nil {
|
||||
values = make(map[string]string)
|
||||
}
|
||||
if _, ok := values["reloader.reloadStrategy"]; !ok {
|
||||
values["reloader.reloadStrategy"] = "annotations"
|
||||
}
|
||||
return testEnv.DeployAndWait(values)
|
||||
}
|
||||
|
||||
// undeployReloader removes the Reloader installation.
|
||||
func undeployReloader() error {
|
||||
return utils.UndeployReloader(testNamespace, testEnv.ReleaseName)
|
||||
}
|
||||
|
||||
// waitForReloaderReady waits for the Reloader deployment to be ready.
|
||||
func waitForReloaderReady() error {
|
||||
return testEnv.WaitForReloader()
|
||||
}
|
||||
193
test/e2e/flags/ignore_resources_test.go
Normal file
193
test/e2e/flags/ignore_resources_test.go
Normal file
@@ -0,0 +1,193 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stakater/Reloader/test/e2e/utils"
|
||||
)
|
||||
|
||||
var _ = Describe("Ignore Resources Flag Tests", func() {
|
||||
var (
|
||||
deploymentName string
|
||||
configMapName string
|
||||
secretName string
|
||||
ignoreNS string
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
deploymentName = utils.RandName("deploy")
|
||||
configMapName = utils.RandName("cm")
|
||||
secretName = utils.RandName("secret")
|
||||
ignoreNS = "ignore-" + utils.RandName("ns")
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, ignoreNS, deploymentName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, ignoreNS, configMapName)
|
||||
_ = utils.DeleteSecret(ctx, kubeClient, ignoreNS, secretName)
|
||||
})
|
||||
|
||||
Context("with ignoreSecrets=true flag", func() {
|
||||
BeforeEach(func() {
|
||||
// Create test namespace
|
||||
err := utils.CreateNamespace(ctx, kubeClient, ignoreNS)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Deploy Reloader with ignoreSecrets flag
|
||||
err = deployReloaderWithFlags(map[string]string{
|
||||
"reloader.ignoreSecrets": "true",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, ignoreNS)
|
||||
})
|
||||
|
||||
It("should NOT reload when Secret changes with ignoreSecrets=true", func() {
|
||||
By("Creating a Secret")
|
||||
_, err := utils.CreateSecretFromStrings(ctx, kubeClient, ignoreNS, secretName,
|
||||
map[string]string{"password": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment with auto annotation referencing the Secret")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, ignoreNS, deploymentName,
|
||||
utils.WithSecretEnvFrom(secretName),
|
||||
utils.WithAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, ignoreNS, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the Secret")
|
||||
err = utils.UpdateSecretFromStrings(ctx, kubeClient, ignoreNS, secretName,
|
||||
map[string]string{"password": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Verifying Deployment was NOT reloaded (ignoreSecrets=true)")
|
||||
time.Sleep(utils.NegativeTestWait)
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, ignoreNS, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ShortTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeFalse(), "Deployment should NOT reload when ignoreSecrets=true")
|
||||
})
|
||||
|
||||
It("should still reload when ConfigMap changes with ignoreSecrets=true", func() {
|
||||
By("Creating a ConfigMap")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, ignoreNS, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment with auto annotation referencing the ConfigMap")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, ignoreNS, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(configMapName),
|
||||
utils.WithAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, ignoreNS, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, ignoreNS, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded (ConfigMap should still work)")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, ignoreNS, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "ConfigMap changes should still trigger reload with ignoreSecrets=true")
|
||||
})
|
||||
})
|
||||
|
||||
Context("with ignoreConfigMaps=true flag", func() {
|
||||
BeforeEach(func() {
|
||||
// Create test namespace
|
||||
err := utils.CreateNamespace(ctx, kubeClient, ignoreNS)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Deploy Reloader with ignoreConfigMaps flag
|
||||
err = deployReloaderWithFlags(map[string]string{
|
||||
"reloader.ignoreConfigMaps": "true",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, ignoreNS)
|
||||
})
|
||||
|
||||
It("should NOT reload when ConfigMap changes with ignoreConfigMaps=true", func() {
|
||||
By("Creating a ConfigMap")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, ignoreNS, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment with auto annotation referencing the ConfigMap")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, ignoreNS, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(configMapName),
|
||||
utils.WithAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, ignoreNS, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, ignoreNS, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Verifying Deployment was NOT reloaded (ignoreConfigMaps=true)")
|
||||
time.Sleep(utils.NegativeTestWait)
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, ignoreNS, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ShortTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeFalse(), "Deployment should NOT reload when ignoreConfigMaps=true")
|
||||
})
|
||||
|
||||
It("should still reload when Secret changes with ignoreConfigMaps=true", func() {
|
||||
By("Creating a Secret")
|
||||
_, err := utils.CreateSecretFromStrings(ctx, kubeClient, ignoreNS, secretName,
|
||||
map[string]string{"password": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment with auto annotation referencing the Secret")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, ignoreNS, deploymentName,
|
||||
utils.WithSecretEnvFrom(secretName),
|
||||
utils.WithAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, ignoreNS, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the Secret")
|
||||
err = utils.UpdateSecretFromStrings(ctx, kubeClient, ignoreNS, secretName,
|
||||
map[string]string{"password": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded (Secret should still work)")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, ignoreNS, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "Secret changes should still trigger reload with ignoreConfigMaps=true")
|
||||
})
|
||||
})
|
||||
})
|
||||
159
test/e2e/flags/ignored_workloads_test.go
Normal file
159
test/e2e/flags/ignored_workloads_test.go
Normal file
@@ -0,0 +1,159 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stakater/Reloader/test/e2e/utils"
|
||||
)
|
||||
|
||||
var _ = Describe("Ignored Workloads Flag Tests", func() {
|
||||
var (
|
||||
cronJobName string
|
||||
configMapName string
|
||||
ignoreNS string
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
cronJobName = utils.RandName("cj")
|
||||
configMapName = utils.RandName("cm")
|
||||
ignoreNS = "ignore-wl-" + utils.RandName("ns")
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = utils.DeleteCronJob(ctx, kubeClient, ignoreNS, cronJobName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, ignoreNS, configMapName)
|
||||
})
|
||||
|
||||
Context("with ignoreCronJobs=true flag", func() {
|
||||
BeforeEach(func() {
|
||||
// Create test namespace
|
||||
err := utils.CreateNamespace(ctx, kubeClient, ignoreNS)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Deploy Reloader with ignoreCronJobs flag
|
||||
err = deployReloaderWithFlags(map[string]string{
|
||||
"reloader.ignoreCronJobs": "true",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, ignoreNS)
|
||||
})
|
||||
|
||||
It("should NOT reload CronJobs when ignoreCronJobs=true", func() {
|
||||
By("Creating a ConfigMap")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, ignoreNS, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a CronJob with auto annotation referencing the ConfigMap")
|
||||
_, err = utils.CreateCronJob(ctx, kubeClient, ignoreNS, cronJobName,
|
||||
utils.WithCronJobConfigMapEnvFrom(configMapName),
|
||||
utils.WithCronJobAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, ignoreNS, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Verifying CronJob was NOT reloaded (ignoreCronJobs=true)")
|
||||
time.Sleep(utils.NegativeTestWait)
|
||||
reloaded, err := utils.WaitForCronJobReloaded(ctx, kubeClient, ignoreNS, cronJobName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ShortTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeFalse(), "CronJob should NOT reload when ignoreCronJobs=true")
|
||||
})
|
||||
|
||||
It("should still reload Deployments when ignoreCronJobs=true", func() {
|
||||
deploymentName := utils.RandName("deploy")
|
||||
|
||||
By("Creating a ConfigMap")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, ignoreNS, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment with auto annotation referencing the ConfigMap")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, ignoreNS, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(configMapName),
|
||||
utils.WithAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
defer func() {
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, ignoreNS, deploymentName)
|
||||
}()
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, ignoreNS, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, ignoreNS, configMapName,
|
||||
map[string]string{"key": "updated-deploy"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded (Deployment should still work)")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, ignoreNS, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "Deployment should still reload with ignoreCronJobs=true")
|
||||
})
|
||||
})
|
||||
|
||||
Context("with both ignoreCronJobs=true and ignoreJobs=true flags", func() {
|
||||
BeforeEach(func() {
|
||||
// Create test namespace
|
||||
err := utils.CreateNamespace(ctx, kubeClient, ignoreNS)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Deploy Reloader with both ignore flags
|
||||
err = deployReloaderWithFlags(map[string]string{
|
||||
"reloader.ignoreCronJobs": "true",
|
||||
"reloader.ignoreJobs": "true",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, ignoreNS)
|
||||
})
|
||||
|
||||
It("should NOT reload CronJobs when both job flags are true", func() {
|
||||
By("Creating a ConfigMap")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, ignoreNS, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a CronJob with auto annotation")
|
||||
_, err = utils.CreateCronJob(ctx, kubeClient, ignoreNS, cronJobName,
|
||||
utils.WithCronJobConfigMapEnvFrom(configMapName),
|
||||
utils.WithCronJobAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, ignoreNS, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Verifying CronJob was NOT reloaded")
|
||||
time.Sleep(utils.NegativeTestWait)
|
||||
reloaded, err := utils.WaitForCronJobReloaded(ctx, kubeClient, ignoreNS, cronJobName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ShortTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeFalse(), "CronJob should NOT reload when ignoreCronJobs=true and ignoreJobs=true")
|
||||
})
|
||||
})
|
||||
})
|
||||
114
test/e2e/flags/namespace_ignore_test.go
Normal file
114
test/e2e/flags/namespace_ignore_test.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stakater/Reloader/test/e2e/utils"
|
||||
)
|
||||
|
||||
var _ = Describe("Namespace Ignore Flag Tests", func() {
|
||||
var (
|
||||
deploymentName string
|
||||
configMapName string
|
||||
ignoredNamespace string
|
||||
watchedNamespace string
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
deploymentName = utils.RandName("deploy")
|
||||
configMapName = utils.RandName("cm")
|
||||
ignoredNamespace = "ignored-" + utils.RandName("ns")
|
||||
watchedNamespace = "watched-" + utils.RandName("ns")
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, ignoredNamespace, deploymentName)
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, watchedNamespace, deploymentName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, ignoredNamespace, configMapName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, watchedNamespace, configMapName)
|
||||
})
|
||||
|
||||
Context("with ignoreNamespaces flag", func() {
|
||||
BeforeEach(func() {
|
||||
err := utils.CreateNamespace(ctx, kubeClient, ignoredNamespace)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
err = utils.CreateNamespace(ctx, kubeClient, watchedNamespace)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = deployReloaderWithFlags(map[string]string{
|
||||
"reloader.ignoreNamespaces": ignoredNamespace,
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, ignoredNamespace)
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, watchedNamespace)
|
||||
})
|
||||
|
||||
It("should NOT reload in ignored namespace", func() {
|
||||
By("Creating a ConfigMap in the ignored namespace")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, ignoredNamespace, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment in the ignored namespace")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, ignoredNamespace, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(configMapName),
|
||||
utils.WithAnnotations(utils.BuildConfigMapReloadAnnotation(configMapName)),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, ignoredNamespace, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, ignoredNamespace, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Verifying Deployment was NOT reloaded (ignored namespace)")
|
||||
time.Sleep(utils.NegativeTestWait)
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, ignoredNamespace, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ShortTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeFalse(), "Deployment in ignored namespace should NOT be reloaded")
|
||||
})
|
||||
|
||||
It("should reload in watched (non-ignored) namespace", func() {
|
||||
By("Creating a ConfigMap in the watched namespace")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, watchedNamespace, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment in the watched namespace")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, watchedNamespace, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(configMapName),
|
||||
utils.WithAnnotations(utils.BuildConfigMapReloadAnnotation(configMapName)),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, watchedNamespace, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, watchedNamespace, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, watchedNamespace, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "Deployment in non-ignored namespace should be reloaded")
|
||||
})
|
||||
})
|
||||
})
|
||||
116
test/e2e/flags/namespace_selector_test.go
Normal file
116
test/e2e/flags/namespace_selector_test.go
Normal file
@@ -0,0 +1,116 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stakater/Reloader/test/e2e/utils"
|
||||
)
|
||||
|
||||
var _ = Describe("Namespace Selector Flag Tests", func() {
|
||||
var (
|
||||
deploymentName string
|
||||
configMapName string
|
||||
matchingNS string
|
||||
nonMatchingNS string
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
deploymentName = utils.RandName("deploy")
|
||||
configMapName = utils.RandName("cm")
|
||||
matchingNS = "match-" + utils.RandName("ns")
|
||||
nonMatchingNS = "nomatch-" + utils.RandName("ns")
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, matchingNS, deploymentName)
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, nonMatchingNS, deploymentName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, matchingNS, configMapName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, nonMatchingNS, configMapName)
|
||||
})
|
||||
|
||||
Context("with namespaceSelector flag", func() {
|
||||
BeforeEach(func() {
|
||||
err := utils.CreateNamespaceWithLabels(ctx, kubeClient, matchingNS,
|
||||
map[string]string{"env": "test"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = utils.CreateNamespace(ctx, kubeClient, nonMatchingNS)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = deployReloaderWithFlags(map[string]string{
|
||||
"reloader.namespaceSelector": "env=test",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, matchingNS)
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, nonMatchingNS)
|
||||
})
|
||||
|
||||
It("should reload workloads in matching namespaces", func() {
|
||||
By("Creating a ConfigMap in matching namespace")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, matchingNS, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment in matching namespace with auto annotation")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, matchingNS, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(configMapName),
|
||||
utils.WithAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, matchingNS, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, matchingNS, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, matchingNS, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "Deployment in matching namespace should be reloaded")
|
||||
})
|
||||
|
||||
It("should NOT reload workloads in non-matching namespaces", func() {
|
||||
By("Creating a ConfigMap in non-matching namespace")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, nonMatchingNS, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment in non-matching namespace with auto annotation")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, nonMatchingNS, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(configMapName),
|
||||
utils.WithAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, nonMatchingNS, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, nonMatchingNS, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Verifying Deployment was NOT reloaded (non-matching namespace)")
|
||||
time.Sleep(utils.NegativeTestWait)
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, nonMatchingNS, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ShortTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeFalse(), "Deployment in non-matching namespace should NOT be reloaded")
|
||||
})
|
||||
})
|
||||
})
|
||||
143
test/e2e/flags/reload_on_create_test.go
Normal file
143
test/e2e/flags/reload_on_create_test.go
Normal file
@@ -0,0 +1,143 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stakater/Reloader/test/e2e/utils"
|
||||
)
|
||||
|
||||
var _ = Describe("Reload On Create Flag Tests", func() {
|
||||
var (
|
||||
deploymentName string
|
||||
configMapName string
|
||||
createNamespace string
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
deploymentName = utils.RandName("deploy")
|
||||
configMapName = utils.RandName("cm")
|
||||
createNamespace = "create-" + utils.RandName("ns")
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, createNamespace, deploymentName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, createNamespace, configMapName)
|
||||
})
|
||||
|
||||
Context("with reloadOnCreate=true flag", func() {
|
||||
BeforeEach(func() {
|
||||
// Create test namespace
|
||||
err := utils.CreateNamespace(ctx, kubeClient, createNamespace)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Deploy Reloader with reloadOnCreate flag
|
||||
err = deployReloaderWithFlags(map[string]string{
|
||||
"reloader.reloadOnCreate": "true",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, createNamespace)
|
||||
})
|
||||
|
||||
It("should reload when a new ConfigMap is created", func() {
|
||||
By("Creating a Deployment with annotation for a ConfigMap that doesn't exist yet")
|
||||
_, err := utils.CreateDeployment(ctx, kubeClient, createNamespace, deploymentName,
|
||||
utils.WithAnnotations(utils.BuildConfigMapReloadAnnotation(configMapName)),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, createNamespace, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating the ConfigMap that the Deployment references")
|
||||
_, err = utils.CreateConfigMap(ctx, kubeClient, createNamespace, configMapName,
|
||||
map[string]string{"key": "value"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded (reloadOnCreate=true)")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, createNamespace, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "Deployment should reload when referenced ConfigMap is created")
|
||||
})
|
||||
|
||||
It("should reload when a new Secret is created", func() {
|
||||
secretName := utils.RandName("secret")
|
||||
defer func() { _ = utils.DeleteSecret(ctx, kubeClient, createNamespace, secretName) }()
|
||||
|
||||
By("Creating a Deployment with annotation for a Secret that doesn't exist yet")
|
||||
_, err := utils.CreateDeployment(ctx, kubeClient, createNamespace, deploymentName,
|
||||
utils.WithAnnotations(utils.BuildSecretReloadAnnotation(secretName)),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, createNamespace, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating the Secret that the Deployment references")
|
||||
_, err = utils.CreateSecretFromStrings(ctx, kubeClient, createNamespace, secretName,
|
||||
map[string]string{"password": "secret"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded (reloadOnCreate=true)")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, createNamespace, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "Deployment should reload when referenced Secret is created")
|
||||
})
|
||||
})
|
||||
|
||||
Context("with reloadOnCreate=false (default)", func() {
|
||||
BeforeEach(func() {
|
||||
// Create test namespace
|
||||
err := utils.CreateNamespace(ctx, kubeClient, createNamespace)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Deploy Reloader without reloadOnCreate flag (default is false)
|
||||
err = deployReloaderWithFlags(map[string]string{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, createNamespace)
|
||||
})
|
||||
|
||||
It("should NOT reload when a new ConfigMap is created (default behavior)", func() {
|
||||
By("Creating a Deployment with annotation for a ConfigMap that doesn't exist yet")
|
||||
_, err := utils.CreateDeployment(ctx, kubeClient, createNamespace, deploymentName,
|
||||
utils.WithAnnotations(utils.BuildConfigMapReloadAnnotation(configMapName)),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, createNamespace, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating the ConfigMap that the Deployment references")
|
||||
_, err = utils.CreateConfigMap(ctx, kubeClient, createNamespace, configMapName,
|
||||
map[string]string{"key": "value"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Verifying Deployment was NOT reloaded (reloadOnCreate=false)")
|
||||
time.Sleep(utils.NegativeTestWait)
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, createNamespace, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ShortTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeFalse(), "Deployment should NOT reload on create when reloadOnCreate=false")
|
||||
})
|
||||
})
|
||||
})
|
||||
154
test/e2e/flags/reload_on_delete_test.go
Normal file
154
test/e2e/flags/reload_on_delete_test.go
Normal file
@@ -0,0 +1,154 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stakater/Reloader/test/e2e/utils"
|
||||
)
|
||||
|
||||
var _ = Describe("Reload On Delete Flag Tests", func() {
|
||||
var (
|
||||
deploymentName string
|
||||
configMapName string
|
||||
deleteNamespace string
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
deploymentName = utils.RandName("deploy")
|
||||
configMapName = utils.RandName("cm")
|
||||
deleteNamespace = "delete-" + utils.RandName("ns")
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, deleteNamespace, deploymentName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, deleteNamespace, configMapName)
|
||||
})
|
||||
|
||||
Context("with reloadOnDelete=true flag", func() {
|
||||
BeforeEach(func() {
|
||||
// Create test namespace
|
||||
err := utils.CreateNamespace(ctx, kubeClient, deleteNamespace)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Deploy Reloader with reloadOnDelete flag
|
||||
err = deployReloaderWithFlags(map[string]string{
|
||||
"reloader.reloadOnDelete": "true",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, deleteNamespace)
|
||||
})
|
||||
|
||||
It("should reload when a referenced ConfigMap is deleted", func() {
|
||||
By("Creating a ConfigMap")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, deleteNamespace, configMapName,
|
||||
map[string]string{"key": "value"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment with annotation for the ConfigMap")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, deleteNamespace, deploymentName,
|
||||
utils.WithAnnotations(utils.BuildConfigMapReloadAnnotation(configMapName)),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, deleteNamespace, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Deleting the ConfigMap")
|
||||
err = utils.DeleteConfigMap(ctx, kubeClient, deleteNamespace, configMapName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded (reloadOnDelete=true)")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, deleteNamespace, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "Deployment should reload when referenced ConfigMap is deleted")
|
||||
})
|
||||
|
||||
It("should reload when a referenced Secret is deleted", func() {
|
||||
secretName := utils.RandName("secret")
|
||||
|
||||
By("Creating a Secret")
|
||||
_, err := utils.CreateSecretFromStrings(ctx, kubeClient, deleteNamespace, secretName,
|
||||
map[string]string{"password": "secret"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment with annotation for the Secret")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, deleteNamespace, deploymentName,
|
||||
utils.WithAnnotations(utils.BuildSecretReloadAnnotation(secretName)),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, deleteNamespace, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Deleting the Secret")
|
||||
err = utils.DeleteSecret(ctx, kubeClient, deleteNamespace, secretName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded (reloadOnDelete=true)")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, deleteNamespace, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "Deployment should reload when referenced Secret is deleted")
|
||||
})
|
||||
})
|
||||
|
||||
Context("with reloadOnDelete=false (default)", func() {
|
||||
BeforeEach(func() {
|
||||
// Create test namespace
|
||||
err := utils.CreateNamespace(ctx, kubeClient, deleteNamespace)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Deploy Reloader without reloadOnDelete flag (default is false)
|
||||
err = deployReloaderWithFlags(map[string]string{})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, deleteNamespace)
|
||||
})
|
||||
|
||||
It("should NOT reload when a referenced ConfigMap is deleted (default behavior)", func() {
|
||||
By("Creating a ConfigMap")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, deleteNamespace, configMapName,
|
||||
map[string]string{"key": "value"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment with annotation for the ConfigMap")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, deleteNamespace, deploymentName,
|
||||
utils.WithAnnotations(utils.BuildConfigMapReloadAnnotation(configMapName)),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, deleteNamespace, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Deleting the ConfigMap")
|
||||
err = utils.DeleteConfigMap(ctx, kubeClient, deleteNamespace, configMapName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Verifying Deployment was NOT reloaded (reloadOnDelete=false)")
|
||||
time.Sleep(utils.NegativeTestWait)
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, deleteNamespace, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ShortTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeFalse(), "Deployment should NOT reload on delete when reloadOnDelete=false")
|
||||
})
|
||||
})
|
||||
})
|
||||
114
test/e2e/flags/resource_selector_test.go
Normal file
114
test/e2e/flags/resource_selector_test.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stakater/Reloader/test/e2e/utils"
|
||||
)
|
||||
|
||||
var _ = Describe("Resource Label Selector Flag Tests", func() {
|
||||
var (
|
||||
deploymentName string
|
||||
matchingCM string
|
||||
nonMatchingCM string
|
||||
resourceNS string
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
deploymentName = utils.RandName("deploy")
|
||||
matchingCM = utils.RandName("match-cm")
|
||||
nonMatchingCM = utils.RandName("nomatch-cm")
|
||||
resourceNS = "resource-" + utils.RandName("ns")
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, resourceNS, deploymentName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, resourceNS, matchingCM)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, resourceNS, nonMatchingCM)
|
||||
})
|
||||
|
||||
Context("with resourceLabelSelector flag", func() {
|
||||
BeforeEach(func() {
|
||||
// Create test namespace
|
||||
err := utils.CreateNamespace(ctx, kubeClient, resourceNS)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Deploy Reloader with resourceLabelSelector flag
|
||||
err = deployReloaderWithFlags(map[string]string{
|
||||
"reloader.resourceLabelSelector": "reload=true",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, resourceNS)
|
||||
})
|
||||
|
||||
It("should reload when labeled ConfigMap changes", func() {
|
||||
By("Creating a ConfigMap with matching label")
|
||||
_, err := utils.CreateConfigMapWithLabels(ctx, kubeClient, resourceNS, matchingCM,
|
||||
map[string]string{"key": "initial"},
|
||||
map[string]string{"reload": "true"},
|
||||
nil) // no annotations
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment with auto annotation")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, resourceNS, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(matchingCM),
|
||||
utils.WithAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, resourceNS, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the labeled ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, resourceNS, matchingCM,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, resourceNS, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "Deployment should be reloaded when labeled ConfigMap changes")
|
||||
})
|
||||
|
||||
It("should NOT reload when unlabeled ConfigMap changes", func() {
|
||||
By("Creating a ConfigMap WITHOUT matching label")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, resourceNS, nonMatchingCM,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment with auto annotation")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, resourceNS, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(nonMatchingCM),
|
||||
utils.WithAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, resourceNS, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the unlabeled ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, resourceNS, nonMatchingCM,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Verifying Deployment was NOT reloaded (unlabeled ConfigMap)")
|
||||
time.Sleep(utils.NegativeTestWait)
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, resourceNS, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ShortTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeFalse(), "Deployment should NOT reload when unlabeled ConfigMap changes")
|
||||
})
|
||||
})
|
||||
})
|
||||
170
test/e2e/flags/watch_globally_test.go
Normal file
170
test/e2e/flags/watch_globally_test.go
Normal file
@@ -0,0 +1,170 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/stakater/Reloader/test/e2e/utils"
|
||||
)
|
||||
|
||||
var _ = Describe("Watch Globally Flag Tests", func() {
|
||||
var (
|
||||
deploymentName string
|
||||
configMapName string
|
||||
otherNS string
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
deploymentName = utils.RandName("deploy")
|
||||
configMapName = utils.RandName("cm")
|
||||
otherNS = "other-" + utils.RandName("ns")
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
// Clean up resources in both namespaces
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, testNamespace, deploymentName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, testNamespace, configMapName)
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, otherNS, deploymentName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, otherNS, configMapName)
|
||||
})
|
||||
|
||||
Context("with watchGlobally=false flag", func() {
|
||||
BeforeEach(func() {
|
||||
// Create the other namespace for testing cross-namespace behavior
|
||||
err := utils.CreateNamespace(ctx, kubeClient, otherNS)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Deploy Reloader with watchGlobally=false
|
||||
// This makes Reloader only watch resources in its own namespace (testNamespace)
|
||||
err = deployReloaderWithFlags(map[string]string{
|
||||
"reloader.watchGlobally": "false",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, otherNS)
|
||||
})
|
||||
|
||||
It("should reload workloads in Reloader's namespace when watchGlobally=false", func() {
|
||||
By("Creating a ConfigMap in Reloader's namespace")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, testNamespace, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment in Reloader's namespace with auto annotation")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, testNamespace, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(configMapName),
|
||||
utils.WithAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, testNamespace, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, testNamespace, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded (same namespace should work)")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, testNamespace, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "Deployment in Reloader's namespace should reload with watchGlobally=false")
|
||||
})
|
||||
|
||||
It("should NOT reload workloads in other namespaces when watchGlobally=false", func() {
|
||||
By("Creating a ConfigMap in another namespace")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, otherNS, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment in another namespace with auto annotation")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, otherNS, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(configMapName),
|
||||
utils.WithAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, otherNS, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap in the other namespace")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, otherNS, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Verifying Deployment was NOT reloaded (different namespace with watchGlobally=false)")
|
||||
time.Sleep(utils.NegativeTestWait)
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, otherNS, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ShortTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeFalse(), "Deployment in other namespace should NOT reload with watchGlobally=false")
|
||||
})
|
||||
})
|
||||
|
||||
Context("with watchGlobally=true flag (default)", func() {
|
||||
var globalNS string
|
||||
|
||||
BeforeEach(func() {
|
||||
globalNS = "global-" + utils.RandName("ns")
|
||||
|
||||
// Create test namespace
|
||||
err := utils.CreateNamespace(ctx, kubeClient, globalNS)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
// Deploy Reloader with watchGlobally=true (default)
|
||||
err = deployReloaderWithFlags(map[string]string{
|
||||
"reloader.watchGlobally": "true",
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
err = waitForReloaderReady()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = utils.DeleteDeployment(ctx, kubeClient, globalNS, deploymentName)
|
||||
_ = utils.DeleteConfigMap(ctx, kubeClient, globalNS, configMapName)
|
||||
_ = undeployReloader()
|
||||
_ = utils.DeleteNamespace(ctx, kubeClient, globalNS)
|
||||
})
|
||||
|
||||
It("should reload workloads in any namespace when watchGlobally=true", func() {
|
||||
By("Creating a ConfigMap in a different namespace")
|
||||
_, err := utils.CreateConfigMap(ctx, kubeClient, globalNS, configMapName,
|
||||
map[string]string{"key": "initial"}, nil)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Creating a Deployment in a different namespace with auto annotation")
|
||||
_, err = utils.CreateDeployment(ctx, kubeClient, globalNS, deploymentName,
|
||||
utils.WithConfigMapEnvFrom(configMapName),
|
||||
utils.WithAnnotations(utils.BuildAutoTrueAnnotation()),
|
||||
)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be ready")
|
||||
err = utils.WaitForDeploymentReady(ctx, kubeClient, globalNS, deploymentName, utils.DeploymentReady)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Updating the ConfigMap")
|
||||
err = utils.UpdateConfigMap(ctx, kubeClient, globalNS, configMapName,
|
||||
map[string]string{"key": "updated"})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("Waiting for Deployment to be reloaded (watchGlobally=true)")
|
||||
reloaded, err := utils.WaitForDeploymentReloaded(ctx, kubeClient, globalNS, deploymentName,
|
||||
utils.AnnotationLastReloadedFrom, utils.ReloadTimeout)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(reloaded).To(BeTrue(), "Deployment in any namespace should reload with watchGlobally=true")
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user