-
Notifications
You must be signed in to change notification settings - Fork 187
/
secret.go
82 lines (66 loc) · 2.33 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//go:build e2e
// +build e2e
package secret
import (
"context"
"fmt"
"github.com/Azure/secrets-store-csi-driver-provider-azure/test/e2e/framework"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
// CreateInput is the input for Create.
type CreateInput struct {
Creator framework.Creator
Name string
Namespace string
Data map[string][]byte
Labels map[string]string
}
// Create creates a Secret resource.
func Create(input CreateInput) *v1.Secret {
Expect(input.Creator).NotTo(BeNil(), "input.Creator is required for Secret.Create")
Expect(input.Name).NotTo(BeEmpty(), "input.Name is required for Secret.Create")
Expect(input.Namespace).NotTo(BeEmpty(), "input.Namespace is required for Secret.Create")
Expect(input.Data).NotTo(BeEmpty(), "input.Data is required for Secret.Create")
By(fmt.Sprintf("Creating Secret \"%s\"", input.Name))
secret := &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: input.Name,
Namespace: input.Namespace,
Labels: input.Labels,
},
Data: input.Data,
}
Expect(input.Creator.Create(context.TODO(), secret)).Should(Succeed())
return secret
}
// GetInput is the input for Get.
type GetInput struct {
Getter framework.Getter
Name string
Namespace string
}
func Get(input GetInput) *v1.Secret {
Expect(input.Getter).NotTo(BeNil(), "input.Getter is required for Secret.Get")
Expect(input.Name).NotTo(BeEmpty(), "input.Name is required for Secret.Get")
Expect(input.Namespace).NotTo(BeEmpty(), "input.Namespace is required for Secret.Get")
By(fmt.Sprintf("Getting Secret \"%s\"", input.Name))
secret := &v1.Secret{}
Expect(input.Getter.Get(context.TODO(), types.NamespacedName{Name: input.Name, Namespace: input.Namespace}, secret)).Should(Succeed())
return secret
}
// DeleteInput is the input for Delete.
type DeleteInput struct {
Deleter framework.Deleter
Secret *v1.Secret
}
// Delete deletes a Secret resource.
func Delete(input DeleteInput) {
Expect(input.Deleter).NotTo(BeNil(), "input.Deleter is required for Secret.Delete")
Expect(input.Secret).NotTo(BeNil(), "input.Secret is required for Secret.Delete")
By(fmt.Sprintf("Deleting Secret \"%s\"", input.Secret.Name))
Expect(input.Deleter.Delete(context.TODO(), input.Secret)).Should(Succeed())
}