|
7 | 7 | . "github.com/onsi/gomega"
|
8 | 8 | authn "k8s.io/api/authentication/v1"
|
9 | 9 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
| 10 | + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" |
10 | 11 | "k8s.io/apimachinery/pkg/runtime/schema"
|
11 | 12 | "sigs.k8s.io/controller-runtime/pkg/log/zap"
|
12 | 13 |
|
@@ -158,6 +159,58 @@ func TestChangeParentWithConflict(t *testing.T) {
|
158 | 159 | }
|
159 | 160 | }
|
160 | 161 |
|
| 162 | +func TestConflictItemWithPropagateNoneLabel(t *testing.T) { |
| 163 | + f := foresttest.Create("-a-c") // a <- b; c <- d |
| 164 | + gvk := schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Secret"} |
| 165 | + or := &reconcilers.ObjectReconciler{ |
| 166 | + GVK: gvk, |
| 167 | + Mode: api.Propagate, |
| 168 | + } |
| 169 | + f.AddTypeSyncer(or) |
| 170 | + |
| 171 | + // Create conflict secret annotated with propagate none as true |
| 172 | + inst := &unstructured.Unstructured{} |
| 173 | + inst.SetName("conflict") |
| 174 | + inst.SetNamespace("a") |
| 175 | + inst.SetGroupVersionKind(gvk) |
| 176 | + inst.SetAnnotations(map[string]string{api.AnnotationNoneSelector: "true"}) |
| 177 | + f.Get("a").SetSourceObject(inst) |
| 178 | + // Create secret with the same name in namespace 'b' and 'd' |
| 179 | + createSecret("conflict", "c", f) |
| 180 | + createSecret("conflict", "d", f) |
| 181 | + |
| 182 | + h := &Hierarchy{Forest: f} |
| 183 | + l := zap.New() |
| 184 | + tests := []struct { |
| 185 | + name string |
| 186 | + nnm string |
| 187 | + pnm string |
| 188 | + fail bool |
| 189 | + }{ |
| 190 | + {name: "ok: no conflict as parent secret is propagate none", nnm: "c", pnm: "a"}, |
| 191 | + {name: "conflict secret in parent (child secret is propagate none)", nnm: "a", pnm: "d", fail: true}, |
| 192 | + } |
| 193 | + |
| 194 | + for _, tc := range tests { |
| 195 | + t.Run(tc.name, func(t *testing.T) { |
| 196 | + // Setup |
| 197 | + g := NewWithT(t) |
| 198 | + hc := &api.HierarchyConfiguration{Spec: api.HierarchyConfigurationSpec{Parent: tc.pnm}} |
| 199 | + hc.ObjectMeta.Name = api.Singleton |
| 200 | + hc.ObjectMeta.Namespace = tc.nnm |
| 201 | + req := &request{hc: hc} |
| 202 | + |
| 203 | + // Test |
| 204 | + got := h.handle(context.Background(), l, req) |
| 205 | + |
| 206 | + // Report |
| 207 | + logResult(t, got.AdmissionResponse.Result) |
| 208 | + g.Expect(got.AdmissionResponse.Allowed).ShouldNot(Equal(tc.fail)) |
| 209 | + }) |
| 210 | + } |
| 211 | + |
| 212 | +} |
| 213 | + |
161 | 214 | func TestAuthz(t *testing.T) {
|
162 | 215 | tests := []struct {
|
163 | 216 | name string
|
|
0 commit comments