-
Notifications
You must be signed in to change notification settings - Fork 15
/
btpoperator_controller_provisioning_test.go
79 lines (69 loc) · 3.37 KB
/
btpoperator_controller_provisioning_test.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
package controllers
import (
"context"
"github.com/kyma-project/btp-manager/api/v1alpha1"
"github.com/kyma-project/btp-manager/internal/conditions"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var _ = Describe("BTP Operator controller - provisioning", func() {
var cr *v1alpha1.BtpOperator
BeforeEach(func() {
GinkgoWriter.Println("--- PROCESS:", GinkgoParallelProcess(), "---")
ctx = context.Background()
cr = createDefaultBtpOperator()
cr.SetLabels(map[string]string{forceDeleteLabelKey: "true"})
Eventually(func() error { return k8sClient.Create(ctx, cr) }).WithTimeout(k8sOpsTimeout).WithPolling(k8sOpsPollingInterval).Should(Succeed())
})
AfterEach(func() {
cr = &v1alpha1.BtpOperator{}
Expect(k8sClient.Get(ctx, client.ObjectKey{Namespace: defaultNamespace, Name: btpOperatorName}, cr)).Should(Succeed())
Expect(k8sClient.Delete(ctx, cr)).Should(Succeed())
Eventually(updateCh).Should(Receive(matchDeleted()))
Expect(isCrNotFound()).To(BeTrue())
})
When("The required Secret is missing", func() {
It("should return warning while getting the required Secret", func() {
Eventually(updateCh).Should(Receive(matchReadyCondition(v1alpha1.StateProcessing, metav1.ConditionFalse, conditions.Initialized)))
Eventually(updateCh).Should(Receive(matchReadyCondition(v1alpha1.StateWarning, metav1.ConditionFalse, conditions.MissingSecret)))
})
})
Describe("The required Secret exists", func() {
AfterEach(func() {
deleteSecret := &corev1.Secret{}
Expect(k8sClient.Get(ctx, client.ObjectKey{Namespace: kymaNamespace, Name: SecretName}, deleteSecret)).To(Succeed())
Expect(k8sClient.Delete(ctx, deleteSecret)).To(Succeed())
Eventually(updateCh).Should(Receive(matchReadyCondition(v1alpha1.StateWarning, metav1.ConditionFalse, conditions.MissingSecret)))
})
When("the required Secret does not have all required keys", func() {
It("should return error while verifying keys", func() {
secret, err := createSecretWithoutKeys()
Expect(err).To(BeNil())
Expect(k8sClient.Create(ctx, secret)).To(Succeed())
Eventually(updateCh).Should(Receive(matchReadyCondition(v1alpha1.StateWarning, metav1.ConditionFalse, conditions.InvalidSecret)))
})
})
When("the required Secret's keys do not have all values", func() {
It("should return error while verifying values", func() {
secret, err := createSecretWithoutValues()
Expect(err).To(BeNil())
Expect(k8sClient.Create(ctx, secret)).To(Succeed())
Eventually(updateCh).Should(Receive(matchReadyCondition(v1alpha1.StateWarning, metav1.ConditionFalse, conditions.InvalidSecret)))
})
})
When("the required Secret is correct", func() {
It("should install chart successfully", func() {
secret, err := createCorrectSecretFromYaml()
Expect(err).To(BeNil())
Expect(k8sClient.Patch(ctx, secret, client.Apply, client.ForceOwnership, client.FieldOwner(operatorName))).To(Succeed())
Eventually(updateCh).Should(Receive(matchReadyCondition(v1alpha1.StateReady, metav1.ConditionTrue, conditions.ReconcileSucceeded)))
btpServiceOperatorDeployment := &appsv1.Deployment{}
Expect(k8sClient.Get(ctx, client.ObjectKey{Name: DeploymentName, Namespace: kymaNamespace}, btpServiceOperatorDeployment)).To(Succeed())
})
})
})
})