|
| 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 | +// Resource names used in namespace validation tests |
| 30 | +const ( |
| 31 | + nsValidationSecondNamespace = "test-ns-validation-other" |
| 32 | + nsValidationAggregatorWithSecret = "aggregator-with-secret" |
| 33 | + nsValidationAggregatorNoSecret = "aggregator-without-secret" |
| 34 | + nsValidationPipeline = "test-pipeline" |
| 35 | + nsValidationSecret = "test-credentials" |
| 36 | +) |
| 37 | + |
| 38 | +// Namespace Validation tests verify that VectorPipeline is validated only against |
| 39 | +// VectorAggregator instances in the SAME namespace, not all aggregators with matching selectors. |
| 40 | +// |
| 41 | +// This is a regression test for the issue where VectorPipeline validation checked against |
| 42 | +// ALL VectorAggregators with matching label selectors, regardless of namespace. |
| 43 | +// This caused validation failures when aggregators in other namespaces were missing |
| 44 | +// required secrets/resources that only existed in the pipeline's namespace. |
| 45 | +// |
| 46 | +// Related to issue #201 - the fix for ClusterVectorPipeline selector matching did not |
| 47 | +// address the namespace isolation for namespaced VectorPipeline resources. |
| 48 | +var _ = Describe("Namespace Validation Isolation", Label(config.LabelRegression), Ordered, func() { |
| 49 | + f := framework.NewUniqueFramework("test-ns-validation") |
| 50 | + |
| 51 | + BeforeAll(func() { |
| 52 | + f.Setup() |
| 53 | + |
| 54 | + By("creating second namespace for isolation test") |
| 55 | + f.ApplyTestDataWithoutNamespaceReplacement("namespace-validation/second-namespace.yaml") |
| 56 | + |
| 57 | + // Give the namespace time to be created |
| 58 | + time.Sleep(2 * time.Second) |
| 59 | + }) |
| 60 | + |
| 61 | + AfterAll(func() { |
| 62 | + By("cleaning up VectorPipeline") |
| 63 | + f.DeleteResource("vectorpipeline", nsValidationPipeline) |
| 64 | + |
| 65 | + By("cleaning up VectorAggregators") |
| 66 | + f.DeleteResource("vectoraggregator", nsValidationAggregatorWithSecret) |
| 67 | + f.DeleteResourceInNamespace("vectoraggregator", nsValidationAggregatorNoSecret, nsValidationSecondNamespace) |
| 68 | + |
| 69 | + By("cleaning up secret") |
| 70 | + f.DeleteResource("secret", nsValidationSecret) |
| 71 | + |
| 72 | + By("cleaning up second namespace") |
| 73 | + f.DeleteClusterResource("namespace", nsValidationSecondNamespace) |
| 74 | + |
| 75 | + f.Teardown() |
| 76 | + f.PrintMetrics() |
| 77 | + }) |
| 78 | + |
| 79 | + Context("VectorPipeline with VectorAggregators in different namespaces", func() { |
| 80 | + It("should validate VectorPipeline only against VectorAggregator in the same namespace", func() { |
| 81 | + By("creating secret in main namespace") |
| 82 | + f.ApplyTestData("namespace-validation/secret.yaml") |
| 83 | + |
| 84 | + By("deploying VectorAggregator WITH secret in main namespace") |
| 85 | + f.ApplyTestData("namespace-validation/aggregator-ns1.yaml") |
| 86 | + |
| 87 | + By("deploying VectorAggregator WITHOUT secret in second namespace") |
| 88 | + // This aggregator references the same secret that does NOT exist in the second namespace |
| 89 | + // If the bug exists, the pipeline will be validated against this aggregator and fail |
| 90 | + f.ApplyTestDataWithoutNamespaceReplacement("namespace-validation/aggregator-ns2.yaml") |
| 91 | + |
| 92 | + By("waiting for aggregator in main namespace to be ready") |
| 93 | + f.WaitForDeploymentReady(nsValidationAggregatorWithSecret + "-aggregator") |
| 94 | + |
| 95 | + // Note: The aggregator in the second namespace may not become ready |
| 96 | + // because the secret doesn't exist there, but that's expected and irrelevant |
| 97 | + // for this test. What matters is that the pipeline in namespace 1 |
| 98 | + // should NOT be validated against it. |
| 99 | + |
| 100 | + By("creating VectorPipeline with matching labels in main namespace") |
| 101 | + f.ApplyTestData("namespace-validation/pipeline.yaml") |
| 102 | + |
| 103 | + By("waiting for VectorPipeline to become valid") |
| 104 | + // If the bug exists: |
| 105 | + // - Pipeline is validated against BOTH aggregators (both have matching selector) |
| 106 | + // - Validation against aggregator in second namespace FAILS (missing secret) |
| 107 | + // - Pipeline status becomes invalid |
| 108 | + // |
| 109 | + // If the bug is fixed: |
| 110 | + // - Pipeline is validated ONLY against aggregator in the same namespace |
| 111 | + // - Secret exists in main namespace |
| 112 | + // - Pipeline status becomes valid |
| 113 | + f.WaitForPipelineValid(nsValidationPipeline) |
| 114 | + |
| 115 | + By("verifying VectorPipeline has aggregator role") |
| 116 | + role := f.GetPipelineStatus(nsValidationPipeline, "role") |
| 117 | + Expect(role).To(Equal("aggregator"), "Pipeline with vector source should have aggregator role") |
| 118 | + |
| 119 | + // Note: We don't verify that the aggregator config contains the pipeline here |
| 120 | + // because that's tested in other tests. The key assertion is that validation |
| 121 | + // passes quickly (not timing out waiting for the aggregator in the other namespace). |
| 122 | + }) |
| 123 | + }) |
| 124 | +}) |
0 commit comments