Skip to content

Commit

Permalink
Merge pull request #505 from SomtochiAma/docs-apply
Browse files Browse the repository at this point in the history
Add test for varsub in secret
  • Loading branch information
stefanprodan authored Dec 2, 2021
2 parents 2fa13ce + 0d9bd5a commit 1cb35f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
18 changes: 17 additions & 1 deletion controllers/kustomization_varsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"testing"

kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/testserver"
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
Expand All @@ -31,6 +30,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
)

func TestKustomizationReconciler_Varsub(t *testing.T) {
Expand Down Expand Up @@ -58,6 +59,18 @@ metadata:
environment: ${env:=dev}
region: "${_Region}"
zone: "${zone}"
`, name),
},
{
Name: "secret.yaml",
Body: fmt.Sprintf(`---
apiVersion: v1
kind: Secret
metadata:
name: %[1]s
namespace: %[1]s
stringData:
zone: ${zone}
`, name),
},
}
Expand Down Expand Up @@ -145,6 +158,7 @@ metadata:

resultK := &kustomizev1.Kustomization{}
resultSA := &corev1.ServiceAccount{}
resultSecret := &corev1.Secret{}

t.Run("reconciles successfully", func(t *testing.T) {
g.Eventually(func() bool {
Expand All @@ -158,6 +172,7 @@ metadata:
}, timeout, interval).Should(BeTrue())

g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: id, Namespace: id}, resultSA)).Should(Succeed())
g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: id, Namespace: id}, resultSecret)).Should(Succeed())
})

t.Run("sets status", func(t *testing.T) {
Expand All @@ -170,6 +185,7 @@ metadata:
g.Expect(resultSA.Labels["environment"]).To(Equal("dev"))
g.Expect(resultSA.Labels["region"]).To(Equal("eu-central-1"))
g.Expect(resultSA.Labels["zone"]).To(Equal("az-1b"))
g.Expect(string(resultSecret.Data["zone"])).To(Equal("az-1b"))
})

t.Run("sets owner labels", func(t *testing.T) {
Expand Down
13 changes: 13 additions & 0 deletions docs/spec/v1beta2/kustomization.md
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,19 @@ spec:
name: cluster-secret-vars
```

Note that for substituting variables in a secret, `spec.stringData` field must be used i.e

```yaml
apiVersion: v1
kind: Secret
metadata:
name: secret
namespace: flux-system
type: Opaque
stringData:
token: ${token}
```

The var values which are specified in-line with `substitute`
take precedence over the ones in `substituteFrom`.

Expand Down

0 comments on commit 1cb35f5

Please sign in to comment.