|
| 1 | +/* |
| 2 | +Copyright 2024. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package e2e |
| 18 | + |
| 19 | +import ( |
| 20 | + "time" |
| 21 | + |
| 22 | + . "github.com/onsi/ginkgo/v2" |
| 23 | + . "github.com/onsi/gomega" |
| 24 | + |
| 25 | + "github.com/kaasops/vector-operator/test/e2e/framework" |
| 26 | + "github.com/kaasops/vector-operator/test/e2e/framework/config" |
| 27 | +) |
| 28 | + |
| 29 | +const ( |
| 30 | + forceConfigCheckAgent = "force-cc-agent" |
| 31 | + forceConfigCheckPipeline = "force-cc-pipeline" |
| 32 | + forceConfigCheckClusterPipeline = "force-cc-cvp" |
| 33 | +) |
| 34 | + |
| 35 | +// Force ConfigCheck tests verify that the force-configcheck annotation |
| 36 | +// triggers configcheck even when the pipeline spec has not changed. |
| 37 | +var _ = Describe("Force ConfigCheck Annotation", Label(config.LabelSmoke, config.LabelFast), Ordered, func() { |
| 38 | + f := framework.NewUniqueFramework("test-force-configcheck") |
| 39 | + |
| 40 | + BeforeAll(func() { |
| 41 | + f.Setup() |
| 42 | + |
| 43 | + By("deploying Vector Agent") |
| 44 | + f.ApplyTestData("force-configcheck/agent.yaml") |
| 45 | + time.Sleep(5 * time.Second) |
| 46 | + }) |
| 47 | + |
| 48 | + AfterAll(func() { |
| 49 | + f.DeleteClusterResource("clustervectorpipeline", forceConfigCheckClusterPipeline) |
| 50 | + f.Teardown() |
| 51 | + f.PrintMetrics() |
| 52 | + }) |
| 53 | + |
| 54 | + Context("pipeline without annotation", func() { |
| 55 | + It("should validate pipeline normally", func() { |
| 56 | + By("creating a VectorPipeline without force-configcheck annotation") |
| 57 | + f.ApplyTestData("force-configcheck/pipeline.yaml") |
| 58 | + |
| 59 | + By("waiting for pipeline to become valid") |
| 60 | + f.WaitForPipelineValid(forceConfigCheckPipeline) |
| 61 | + |
| 62 | + By("verifying agent processes the pipeline") |
| 63 | + Eventually(func() error { |
| 64 | + return f.VerifyAgentHasPipeline(forceConfigCheckAgent, forceConfigCheckPipeline) |
| 65 | + }, config.ServiceCreateTimeout, config.DefaultPollInterval).Should(Succeed()) |
| 66 | + }) |
| 67 | + }) |
| 68 | + |
| 69 | + Context("adding force-configcheck annotation", func() { |
| 70 | + It("should re-run configcheck when annotation is added", func() { |
| 71 | + By("recording current pipeline hash") |
| 72 | + hashBefore := f.GetPipelineStatus(forceConfigCheckPipeline, "LastAppliedPipelineHash") |
| 73 | + Expect(hashBefore).NotTo(BeEmpty(), "Pipeline should have a hash after initial validation") |
| 74 | + |
| 75 | + By("applying pipeline with force-configcheck annotation set to v1") |
| 76 | + f.ApplyTestData("force-configcheck/pipeline-with-annotation.yaml") |
| 77 | + |
| 78 | + By("waiting for pipeline to become valid again") |
| 79 | + f.WaitForPipelineValid(forceConfigCheckPipeline) |
| 80 | + |
| 81 | + By("verifying pipeline hash changed due to annotation") |
| 82 | + Eventually(func() string { |
| 83 | + return f.GetPipelineStatus(forceConfigCheckPipeline, "LastAppliedPipelineHash") |
| 84 | + }, config.PipelineValidTimeout, config.DefaultPollInterval).ShouldNot(Equal(hashBefore), |
| 85 | + "Hash should change after adding force-configcheck annotation") |
| 86 | + }) |
| 87 | + }) |
| 88 | + |
| 89 | + Context("same annotation value", func() { |
| 90 | + It("should not re-run configcheck for the same annotation value", func() { |
| 91 | + By("recording current pipeline hash") |
| 92 | + hashBefore := f.GetPipelineStatus(forceConfigCheckPipeline, "LastAppliedPipelineHash") |
| 93 | + |
| 94 | + By("re-applying pipeline with same annotation value v1") |
| 95 | + f.ApplyTestData("force-configcheck/pipeline-with-annotation.yaml") |
| 96 | + |
| 97 | + By("waiting briefly for any reconciliation") |
| 98 | + time.Sleep(5 * time.Second) |
| 99 | + |
| 100 | + By("verifying hash has not changed (no configcheck re-run)") |
| 101 | + hashAfter := f.GetPipelineStatus(forceConfigCheckPipeline, "LastAppliedPipelineHash") |
| 102 | + Expect(hashAfter).To(Equal(hashBefore), |
| 103 | + "Hash should not change when annotation value is the same") |
| 104 | + }) |
| 105 | + }) |
| 106 | + |
| 107 | + Context("changed annotation value", func() { |
| 108 | + It("should re-run configcheck when annotation value changes", func() { |
| 109 | + By("recording current pipeline hash") |
| 110 | + hashBefore := f.GetPipelineStatus(forceConfigCheckPipeline, "LastAppliedPipelineHash") |
| 111 | + |
| 112 | + By("applying pipeline with changed annotation value v2") |
| 113 | + f.ApplyTestData("force-configcheck/pipeline-with-annotation-v2.yaml") |
| 114 | + |
| 115 | + By("waiting for pipeline to become valid again") |
| 116 | + f.WaitForPipelineValid(forceConfigCheckPipeline) |
| 117 | + |
| 118 | + By("verifying pipeline hash changed due to new annotation value") |
| 119 | + Eventually(func() string { |
| 120 | + return f.GetPipelineStatus(forceConfigCheckPipeline, "LastAppliedPipelineHash") |
| 121 | + }, config.PipelineValidTimeout, config.DefaultPollInterval).ShouldNot(Equal(hashBefore), |
| 122 | + "Hash should change after changing force-configcheck annotation value") |
| 123 | + }) |
| 124 | + }) |
| 125 | + |
| 126 | + Context("ClusterVectorPipeline without annotation", func() { |
| 127 | + It("should validate CVP normally", func() { |
| 128 | + By("creating a ClusterVectorPipeline without force-configcheck annotation") |
| 129 | + f.ApplyTestDataWithoutNamespaceReplacement("force-configcheck/cluster-pipeline.yaml") |
| 130 | + |
| 131 | + By("waiting for CVP to become valid") |
| 132 | + f.WaitForClusterPipelineValid(forceConfigCheckClusterPipeline) |
| 133 | + }) |
| 134 | + }) |
| 135 | + |
| 136 | + Context("ClusterVectorPipeline with annotation", func() { |
| 137 | + It("should re-run configcheck when annotation is added to CVP", func() { |
| 138 | + By("recording current CVP hash") |
| 139 | + hashBefore := f.GetClusterPipelineStatus(forceConfigCheckClusterPipeline, "LastAppliedPipelineHash") |
| 140 | + Expect(hashBefore).NotTo(BeEmpty(), "CVP should have a hash after initial validation") |
| 141 | + |
| 142 | + By("applying CVP with force-configcheck annotation set to v1") |
| 143 | + f.ApplyTestDataWithoutNamespaceReplacement("force-configcheck/cluster-pipeline-with-annotation.yaml") |
| 144 | + |
| 145 | + By("waiting for CVP to become valid again") |
| 146 | + f.WaitForClusterPipelineValid(forceConfigCheckClusterPipeline) |
| 147 | + |
| 148 | + By("verifying CVP hash changed due to annotation") |
| 149 | + Eventually(func() string { |
| 150 | + return f.GetClusterPipelineStatus(forceConfigCheckClusterPipeline, "LastAppliedPipelineHash") |
| 151 | + }, config.PipelineValidTimeout, config.DefaultPollInterval).ShouldNot(Equal(hashBefore), |
| 152 | + "CVP hash should change after adding force-configcheck annotation") |
| 153 | + }) |
| 154 | + }) |
| 155 | + |
| 156 | + Context("ClusterVectorPipeline changed annotation value", func() { |
| 157 | + It("should re-run configcheck when CVP annotation value changes", func() { |
| 158 | + By("recording current CVP hash") |
| 159 | + hashBefore := f.GetClusterPipelineStatus(forceConfigCheckClusterPipeline, "LastAppliedPipelineHash") |
| 160 | + |
| 161 | + By("applying CVP with changed annotation value v2") |
| 162 | + f.ApplyTestDataWithoutNamespaceReplacement("force-configcheck/cluster-pipeline-with-annotation-v2.yaml") |
| 163 | + |
| 164 | + By("waiting for CVP to become valid again") |
| 165 | + f.WaitForClusterPipelineValid(forceConfigCheckClusterPipeline) |
| 166 | + |
| 167 | + By("verifying CVP hash changed due to new annotation value") |
| 168 | + Eventually(func() string { |
| 169 | + return f.GetClusterPipelineStatus(forceConfigCheckClusterPipeline, "LastAppliedPipelineHash") |
| 170 | + }, config.PipelineValidTimeout, config.DefaultPollInterval).ShouldNot(Equal(hashBefore), |
| 171 | + "CVP hash should change after changing force-configcheck annotation value") |
| 172 | + }) |
| 173 | + }) |
| 174 | +}) |
0 commit comments