Add namespace for config map and secret generators

This commit is contained in:
luktom
2018-12-05 11:18:57 +01:00
parent 8a8331bf57
commit 6ad5d9f55b
8 changed files with 72 additions and 0 deletions

View File

@@ -94,6 +94,13 @@ secretGenerator:
tls.crt: "cat secret/tls.cert"
tls.key: "cat secret/tls.key"
type: "kubernetes.io/tls"
- name: app-tls-namespaced
# you can define a namespace to generate secret in, defaults to: "default"
namspace: apps
commands:
tls.crt: "cat secret/tls.cert"
tls.key: "cat secret/tls.key"
type: "kubernetes.io/tls"
- name: downloaded_secret
# timeoutSeconds specifies the number of seconds to
# wait for the commands below. It defaults to 5 seconds.

View File

@@ -49,6 +49,7 @@ func (f *ConfigMapFactory) makeFreshConfigMap(
cm.APIVersion = "v1"
cm.Kind = "ConfigMap"
cm.Name = args.Name
cm.Namespace = args.Namespace
cm.Data = map[string]string{}
return cm
}

View File

@@ -52,6 +52,7 @@ func (f *SecretFactory) makeFreshSecret(args *types.SecretArgs) *corev1.Secret {
s.APIVersion = "v1"
s.Kind = "Secret"
s.Name = args.Name
s.Namespace = args.Namespace
s.Type = corev1.SecretType(args.Type)
if s.Type == "" {
s.Type = corev1.SecretTypeOpaque

View File

@@ -0,0 +1,33 @@
apiVersion: v1
data:
altGreeting: Good Morning from default namespace!
enableRisky: "false"
kind: ConfigMap
metadata:
name: the-map-4959m5tm6c
---
apiVersion: v1
data:
altGreeting: Good Morning from non-default namespace!
enableRisky: "false"
kind: ConfigMap
metadata:
name: the-non-default-namespace-map-b6h49k7mt8
namespace: non-default
---
apiVersion: v1
data:
password.txt: dmVyeSRlY3JldA==
kind: Secret
metadata:
name: the-secret-cfbmct72tb
type: Opaque
---
apiVersion: v1
data:
password.txt: dmVyeSRlY3JldA==
kind: Secret
metadata:
name: the-non-default-namespace-secret-255294gd9d
namespace: non-default
type: Opaque

View File

@@ -0,0 +1,19 @@
configMapGenerator:
- name: the-non-default-namespace-map
namespace: non-default
literals:
- altGreeting=Good Morning from non-default namespace!
- enableRisky="false"
- name: the-map
literals:
- altGreeting=Good Morning from default namespace!
- enableRisky="false"
secretGenerator:
- name: the-non-default-namespace-secret
namespace: non-default
commands:
password.txt: "cat password.txt"
- name: the-secret
commands:
password.txt: "cat password.txt"

View File

@@ -0,0 +1 @@
very$ecret

View File

@@ -0,0 +1,4 @@
description: generators-namespace
args: []
filename: testdata/testcase-generators-namespace/in
expectedStdout: testdata/testcase-generators-namespace/expected.yaml

View File

@@ -153,6 +153,9 @@ type ConfigMapArgs struct {
// hash(content of configmap).
Name string `json:"name,omitempty" yaml:"name,omitempty"`
// Namespace for the configmap, optional
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
// behavior of configmap, must be one of create, merge and replace
// 'create': create a new one;
// 'replace': replace the existing one;
@@ -170,6 +173,9 @@ type SecretArgs struct {
// hash(content of secret).
Name string `json:"name,omitempty" yaml:"name,omitempty"`
// Namespace for the secret, optional
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
// behavior of secretGenerator, must be one of create, merge and replace
// 'create': create a new one;
// 'replace': replace the existing one;