Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit 408afce

Browse files
authored
Merge pull request #254 from mochizuki875/fix_241
Do not propagate Helm release Secrets
2 parents 3b24ea1 + 951e524 commit 408afce

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

docs/user-guide/concepts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ objects from being propagated by HNC.
377377
* *Planned for HNC v1.0+:* Any objects with the label
378378
`cattle.io/creator:norman`, which are [inserted by Rancher to support
379379
Projects](https://rancher.com/docs/rancher/v2.6/en/system-tools/#remove))
380+
* *Planned for future version:* Secrets with type `helm.sh/release.v1`, which is auto-created in the namespaces where their respective Helm releases are deployed to.
380381

381382
<a name="admin"/>
382383

internal/integtest/helpers.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,17 @@ func MakeObjectWithLabels(ctx context.Context, resource string, nsName,
327327
createdObjects = append(createdObjects, inst)
328328
}
329329

330+
// MakeSecrettWithType creates an empty Secret with type given kind in a specific namespace.
331+
func MakeSecrettWithType(ctx context.Context, nsName, name, scType string) {
332+
inst := &unstructured.Unstructured{}
333+
inst.SetGroupVersionKind(GVKs["secrets"])
334+
inst.SetNamespace(nsName)
335+
inst.SetName(name)
336+
inst.UnstructuredContent()["type"] = scType
337+
ExpectWithOffset(1, K8sClient.Create(ctx, inst)).Should(Succeed())
338+
createdObjects = append(createdObjects, inst)
339+
}
340+
330341
// UpdateObjectWithAnnotations gets an object given it's kind, nsName and name, adds the annotation
331342
// and updates this object
332343
func UpdateObjectWithAnnotations(ctx context.Context, resource, nsName, name string, a map[string]string) {

internal/objects/reconciler_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,17 @@ var _ = Describe("Basic propagation", func() {
435435
Eventually(HasObject(ctx, "configmaps", barName, "kube-root-ca.crt")).Should(BeFalse())
436436
})
437437

438+
It("should not propagate builtin exclusions by Secret Type", func() {
439+
SetParent(ctx, barName, fooName)
440+
MakeSecrettWithType(ctx, fooName, "gets-propagated", "Opaque")
441+
MakeSecrettWithType(ctx, fooName, "helm-secret", "helm.sh/release.v1")
442+
AddToHNCConfig(ctx, "", "secrets", api.Propagate)
443+
444+
// We expect normal secrets to be propagated, but builtin exclusions not to be.
445+
Eventually(HasObject(ctx, "secrets", barName, "gets-propagated")).Should(BeTrue())
446+
Eventually(HasObject(ctx, "secrets", barName, "helm-secret")).Should(BeFalse())
447+
})
448+
438449
It("should not propagate builtin exclusions by labels", func() {
439450
SetParent(ctx, barName, fooName)
440451
MakeObjectWithLabels(ctx, "roles", fooName, "role-with-labels-blocked", map[string]string{"cattle.io/creator": "norman"})

internal/selectors/selectors.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,22 @@ var exclusionByAnnotations = []ExclusionByAnnotationsSpec{
222222
{Key: "openshift.io/description"},
223223
}
224224

225+
// scExclusionsByType are known (Helm) type of Secret which are excluded from propagation.
226+
var scExclusionsByType = []string{"helm.sh/release.v1"}
227+
225228
// isExcluded returns true to indicate that this object is excluded from being propagated
226229
func isExcluded(inst *unstructured.Unstructured) (bool, error) {
227230
name := inst.GetName()
228231
kind := inst.GetKind()
229232
group := inst.GroupVersionKind().Group
233+
234+
// exclusion by Secret type
235+
for _, excludedSecretType := range scExclusionsByType {
236+
if group == "" && kind == "Secret" && inst.UnstructuredContent()["type"] == excludedSecretType {
237+
return true, nil
238+
}
239+
}
240+
230241
// exclusion by name
231242
for _, excludedResourceName := range cmExclusionsByName {
232243
if group == "" && kind == "ConfigMap" && name == excludedResourceName {

0 commit comments

Comments
 (0)