/
secret.go
62 lines (49 loc) · 1.47 KB
/
secret.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package kubernetes
import (
"github.com/rosskirkpat/revvy/pkg/client"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
//go:generate stub-gen -api CoreV1 -type Secret
// SecretBuilder tracks the options set for a secret.
type SecretBuilder struct {
Name string
Namespace string
Data map[string][]byte
StringData map[string]string
}
// CreateSecret creates a secret.
// Additional parameters can be added to this call.
// The creation is started by calling 'Do'.
func CreateSecret(name string) SecretBuilder {
return SecretBuilder{
Name: name,
}
}
// WithNamespace sets the namespace in which the secret will be created.
func (builder SecretBuilder) WithNamespace(namespace string) SecretBuilder {
builder.Namespace = namespace
return builder
}
// WithData sets the data the secret should hold.
func (builder SecretBuilder) WithData(data map[string][]byte) SecretBuilder {
builder.Data = data
return builder
}
// WithStringData sets the data the secret should hold as string
func (builder SecretBuilder) WithStringData(data map[string]string) SecretBuilder {
builder.StringData = data
return builder
}
// Do creates the secret in the cluster.
func (builder SecretBuilder) Do(client client.Client) (Secret, error) {
secret := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: builder.Name,
Namespace: builder.Namespace,
},
Data: builder.Data,
StringData: builder.StringData,
}
return NewSecret(client, secret)
}