|
52 | 52 | arsConfigmapWithConfigMapAutoAnnotation = "testconfigmapwithconfigmapautoannotationdeployment-handler-" + testutil.RandSeq(5)
|
53 | 53 | arsSecretWithExcludeSecretAnnotation = "testsecretwithsecretexcludeannotationdeployment-handler-" + testutil.RandSeq(5)
|
54 | 54 | arsConfigmapWithExcludeConfigMapAnnotation = "testconfigmapwithconfigmapexcludeannotationdeployment-handler-" + testutil.RandSeq(5)
|
| 55 | + arsConfigmapWithIgnoreAnnotation = "testconfigmapWithIgnoreAnnotation-handler-" + testutil.RandSeq(5) |
| 56 | + arsSecretWithIgnoreAnnotation = "testsecretWithIgnoreAnnotation-handler-" + testutil.RandSeq(5) |
55 | 57 |
|
56 | 58 | ersNamespace = "test-handler-" + testutil.RandSeq(5)
|
57 | 59 | ersConfigmapName = "testconfigmap-handler-" + testutil.RandSeq(5)
|
|
75 | 77 | ersConfigmapWithConfigMapAutoAnnotation = "testconfigmapwithconfigmapautoannotationdeployment-handler-" + testutil.RandSeq(5)
|
76 | 78 | ersSecretWithSecretExcludeAnnotation = "testsecretwithsecretexcludeannotationdeployment-handler-" + testutil.RandSeq(5)
|
77 | 79 | ersConfigmapWithConfigMapExcludeAnnotation = "testconfigmapwithconfigmapexcludeannotationdeployment-handler-" + testutil.RandSeq(5)
|
| 80 | + ersConfigmapWithIgnoreAnnotation = "testconfigmapWithIgnoreAnnotation-handler-" + testutil.RandSeq(5) |
| 81 | + ersSecretWithIgnoreAnnotation = "testsecretWithIgnoreAnnotation-handler-" + testutil.RandSeq(5) |
78 | 82 | )
|
79 | 83 |
|
80 | 84 | func TestMain(m *testing.M) {
|
@@ -215,6 +219,35 @@ func setupArs() {
|
215 | 219 | logrus.Errorf("Error in configmap creation: %v", err)
|
216 | 220 | }
|
217 | 221 |
|
| 222 | + // Creating configmap with ignore annotation |
| 223 | + _, err = testutil.CreateConfigMap(clients.KubernetesClient, arsNamespace, arsConfigmapWithIgnoreAnnotation, "www.google.com") |
| 224 | + if err != nil { |
| 225 | + logrus.Errorf("Error in configmap creation: %v", err) |
| 226 | + } |
| 227 | + // Patch with ignore annotation |
| 228 | + cmClient := clients.KubernetesClient.CoreV1().ConfigMaps(arsNamespace) |
| 229 | + patch := []byte(`{"metadata":{"annotations":{"reloader.stakater.com/ignore":"true"}}}`) |
| 230 | + _, _ = cmClient.Patch(context.TODO(), arsConfigmapWithIgnoreAnnotation, patchtypes.MergePatchType, patch, metav1.PatchOptions{}) |
| 231 | + |
| 232 | + // Creating secret with ignore annotation |
| 233 | + _, err = testutil.CreateSecret(clients.KubernetesClient, arsNamespace, arsSecretWithIgnoreAnnotation, data) |
| 234 | + if err != nil { |
| 235 | + logrus.Errorf("Error in secret creation: %v", err) |
| 236 | + } |
| 237 | + secretClient := clients.KubernetesClient.CoreV1().Secrets(arsNamespace) |
| 238 | + _, _ = secretClient.Patch(context.TODO(), arsSecretWithIgnoreAnnotation, patchtypes.MergePatchType, patch, metav1.PatchOptions{}) |
| 239 | + |
| 240 | + // Creating Deployment referencing configmap with ignore annotation |
| 241 | + _, err = testutil.CreateDeployment(clients.KubernetesClient, arsConfigmapWithIgnoreAnnotation, arsNamespace, true) |
| 242 | + if err != nil { |
| 243 | + logrus.Errorf("Error in Deployment with configmap ignore annotation creation: %v", err) |
| 244 | + } |
| 245 | + // Creating Deployment referencing secret with ignore annotation |
| 246 | + _, err = testutil.CreateDeployment(clients.KubernetesClient, arsSecretWithIgnoreAnnotation, arsNamespace, true) |
| 247 | + if err != nil { |
| 248 | + logrus.Errorf("Error in Deployment with secret ignore annotation creation: %v", err) |
| 249 | + } |
| 250 | + |
218 | 251 | // Creating Deployment with configmap
|
219 | 252 | _, err = testutil.CreateDeployment(clients.KubernetesClient, arsConfigmapName, arsNamespace, true)
|
220 | 253 | if err != nil {
|
@@ -854,6 +887,34 @@ func setupErs() {
|
854 | 887 | logrus.Errorf("Error in configmap creation: %v", err)
|
855 | 888 | }
|
856 | 889 |
|
| 890 | + // Creating configmap with ignore annotation |
| 891 | + _, err = testutil.CreateConfigMap(clients.KubernetesClient, ersNamespace, ersConfigmapWithIgnoreAnnotation, "www.google.com") |
| 892 | + if err != nil { |
| 893 | + logrus.Errorf("Error in configmap creation: %v", err) |
| 894 | + } |
| 895 | + cmClient := clients.KubernetesClient.CoreV1().ConfigMaps(ersNamespace) |
| 896 | + patch := []byte(`{"metadata":{"annotations":{"reloader.stakater.com/ignore":"true"}}}`) |
| 897 | + _, _ = cmClient.Patch(context.TODO(), ersConfigmapWithIgnoreAnnotation, patchtypes.MergePatchType, patch, metav1.PatchOptions{}) |
| 898 | + |
| 899 | + // Creating secret with ignore annotation |
| 900 | + _, err = testutil.CreateSecret(clients.KubernetesClient, ersNamespace, ersSecretWithIgnoreAnnotation, data) |
| 901 | + if err != nil { |
| 902 | + logrus.Errorf("Error in secret creation: %v", err) |
| 903 | + } |
| 904 | + secretClient := clients.KubernetesClient.CoreV1().Secrets(ersNamespace) |
| 905 | + _, _ = secretClient.Patch(context.TODO(), ersSecretWithIgnoreAnnotation, patchtypes.MergePatchType, patch, metav1.PatchOptions{}) |
| 906 | + |
| 907 | + // Creating Deployment referencing configmap with ignore annotation |
| 908 | + _, err = testutil.CreateDeployment(clients.KubernetesClient, ersConfigmapWithIgnoreAnnotation, ersNamespace, true) |
| 909 | + if err != nil { |
| 910 | + logrus.Errorf("Error in Deployment with configmap ignore annotation creation: %v", err) |
| 911 | + } |
| 912 | + // Creating Deployment referencing secret with ignore annotation |
| 913 | + _, err = testutil.CreateDeployment(clients.KubernetesClient, ersSecretWithIgnoreAnnotation, ersNamespace, true) |
| 914 | + if err != nil { |
| 915 | + logrus.Errorf("Error in Deployment with secret ignore annotation creation: %v", err) |
| 916 | + } |
| 917 | + |
857 | 918 | // Creating Deployment with configmap
|
858 | 919 | _, err = testutil.CreateDeployment(clients.KubernetesClient, ersConfigmapName, ersNamespace, true)
|
859 | 920 | if err != nil {
|
@@ -2737,6 +2798,65 @@ func TestFailedRollingUpgradeUsingArs(t *testing.T) {
|
2737 | 2798 | }
|
2738 | 2799 | }
|
2739 | 2800 |
|
| 2801 | +func TestIgnoreAnnotationNoReloadUsingArs(t *testing.T) { |
| 2802 | + options.ReloadStrategy = constants.AnnotationsReloadStrategy |
| 2803 | + envVarPostfix := constants.ConfigmapEnvVarPostfix |
| 2804 | + |
| 2805 | + shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, arsNamespace, arsConfigmapWithIgnoreAnnotation, "www.stakater.com") |
| 2806 | + config := getConfigWithAnnotations(envVarPostfix, arsConfigmapWithIgnoreAnnotation, shaData, options.ConfigmapUpdateOnChangeAnnotation, options.ConfigmapReloaderAutoAnnotation) |
| 2807 | + config.ResourceAnnotations = map[string]string{"reloader.stakater.com/ignore": "true"} |
| 2808 | + deploymentFuncs := GetDeploymentRollingUpgradeFuncs() |
| 2809 | + collectors := getCollectors() |
| 2810 | + |
| 2811 | + err := PerformAction(clients, config, deploymentFuncs, collectors, nil, invokeReloadStrategy) |
| 2812 | + if err != nil { |
| 2813 | + t.Errorf("Rolling upgrade failed for Deployment with Configmap and ignore annotation using ARS") |
| 2814 | + } |
| 2815 | + |
| 2816 | + // Ensure deployment is NOT updated |
| 2817 | + updated := testutil.VerifyResourceAnnotationUpdate(clients, config, deploymentFuncs) |
| 2818 | + if updated { |
| 2819 | + t.Errorf("Deployment was updated but should not have been") |
| 2820 | + } |
| 2821 | + |
| 2822 | + // Ensure counters remain zero |
| 2823 | + if promtestutil.ToFloat64(collectors.Reloaded.With(labelSucceeded)) != 0 { |
| 2824 | + t.Errorf("Reload counter should not have increased") |
| 2825 | + } |
| 2826 | + if promtestutil.ToFloat64(collectors.ReloadedByNamespace.With(prometheus.Labels{"success": "true", "namespace": arsNamespace})) != 0 { |
| 2827 | + t.Errorf("Reload counter by namespace should not have increased") |
| 2828 | + } |
| 2829 | +} |
| 2830 | +func TestIgnoreAnnotationNoReloadUsingErs(t *testing.T) { |
| 2831 | + options.ReloadStrategy = constants.EnvVarsReloadStrategy |
| 2832 | + envVarPostfix := constants.ConfigmapEnvVarPostfix |
| 2833 | + |
| 2834 | + shaData := testutil.ConvertResourceToSHA(testutil.ConfigmapResourceType, ersNamespace, ersConfigmapWithIgnoreAnnotation, "www.stakater.com") |
| 2835 | + config := getConfigWithAnnotations(envVarPostfix, ersConfigmapWithIgnoreAnnotation, shaData, options.ConfigmapUpdateOnChangeAnnotation, options.ConfigmapReloaderAutoAnnotation) |
| 2836 | + config.ResourceAnnotations = map[string]string{"reloader.stakater.com/ignore": "true"} |
| 2837 | + deploymentFuncs := GetDeploymentRollingUpgradeFuncs() |
| 2838 | + collectors := getCollectors() |
| 2839 | + |
| 2840 | + err := PerformAction(clients, config, deploymentFuncs, collectors, nil, invokeReloadStrategy) |
| 2841 | + if err != nil { |
| 2842 | + t.Errorf("Rolling upgrade failed for Deployment with Configmap and ignore annotation using ERS") |
| 2843 | + } |
| 2844 | + |
| 2845 | + // Ensure deployment is NOT updated |
| 2846 | + updated := testutil.VerifyResourceEnvVarUpdate(clients, config, envVarPostfix, deploymentFuncs) |
| 2847 | + if updated { |
| 2848 | + t.Errorf("Deployment was updated but should not have been (ERS)") |
| 2849 | + } |
| 2850 | + |
| 2851 | + // Ensure counters remain zero |
| 2852 | + if promtestutil.ToFloat64(collectors.Reloaded.With(labelSucceeded)) != 0 { |
| 2853 | + t.Errorf("Reload counter should not have increased (ERS)") |
| 2854 | + } |
| 2855 | + if promtestutil.ToFloat64(collectors.ReloadedByNamespace.With(prometheus.Labels{"success": "true", "namespace": ersNamespace})) != 0 { |
| 2856 | + t.Errorf("Reload counter by namespace should not have increased (ERS)") |
| 2857 | + } |
| 2858 | +} |
| 2859 | + |
2740 | 2860 | func testRollingUpgradeInvokeDeleteStrategyErs(t *testing.T, clients kube.Clients, config util.Config, upgradeFuncs callbacks.RollingUpgradeFuncs, collectors metrics.Collectors, envVarPostfix string) {
|
2741 | 2861 | err := PerformAction(clients, config, upgradeFuncs, collectors, nil, invokeDeleteStrategy)
|
2742 | 2862 | time.Sleep(5 * time.Second)
|
|
0 commit comments