diff --git a/internal/utils/condition_utils_test.go b/internal/utils/condition_utils_test.go new file mode 100644 index 00000000..30f5469c --- /dev/null +++ b/internal/utils/condition_utils_test.go @@ -0,0 +1,339 @@ +package utils + +import ( + "github.com/SAP/sap-btp-service-operator/api/common" + v1 "github.com/SAP/sap-btp-service-operator/api/v1" + "github.com/SAP/sap-btp-service-operator/client/sm" + smClientTypes "github.com/SAP/sap-btp-service-operator/client/sm/types" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "k8s.io/apimachinery/pkg/api/meta" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "net/http" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +var _ = Describe("Condition Utils", func() { + var resource *v1.ServiceBinding + BeforeEach(func() { + resource = getBinding() + Expect(k8sClient.Create(ctx, resource)).To(Succeed()) + }) + AfterEach(func() { + err := k8sClient.Delete(ctx, resource) + Expect(client.IgnoreNotFound(err)).ToNot(HaveOccurred()) + }) + Context("InitConditions", func() { + It("should initialize conditions and update status", func() { + err := InitConditions(ctx, k8sClient, resource) + Expect(err).ToNot(HaveOccurred()) + Expect(meta.IsStatusConditionPresentAndEqual(resource.GetConditions(), common.ConditionReady, metav1.ConditionFalse)).To(BeTrue()) + }) + }) + + Context("GetConditionReason", func() { + When("given operation type CREATE and state SUCCEEDED", func() { + It("returns expected condition reason", func() { + Expect(GetConditionReason(smClientTypes.CREATE, smClientTypes.SUCCEEDED)).To(Equal(common.Created)) + }) + }) + + When("given operation type UPDATE and state SUCCEEDED", func() { + It("returns expected condition reason", func() { + Expect(GetConditionReason(smClientTypes.UPDATE, smClientTypes.SUCCEEDED)).To(Equal(common.Updated)) + }) + }) + + When("given operation type DELETE and state SUCCEEDED", func() { + It("returns expected condition reason", func() { + expected := common.Deleted + Expect(GetConditionReason(smClientTypes.DELETE, smClientTypes.SUCCEEDED)).To(Equal(expected)) + }) + }) + + When("given operation type CREATE and state INPROGRESS", func() { + It("returns expected condition reason", func() { + Expect(GetConditionReason(smClientTypes.CREATE, smClientTypes.INPROGRESS)).To(Equal(common.CreateInProgress)) + }) + }) + + When("given operation type UPDATE and state INPROGRESS", func() { + It("returns expected condition reason", func() { + Expect(GetConditionReason(smClientTypes.UPDATE, smClientTypes.INPROGRESS)).To(Equal(common.UpdateInProgress)) + }) + }) + + When("given operation type DELETE and state INPROGRESS", func() { + It("returns expected condition reason", func() { + Expect(GetConditionReason(smClientTypes.DELETE, smClientTypes.INPROGRESS)).To(Equal(common.DeleteInProgress)) + }) + }) + + When("given operation type CREATE and state FAILED", func() { + It("returns expected condition reason", func() { + Expect(GetConditionReason(smClientTypes.CREATE, smClientTypes.FAILED)).To(Equal(common.CreateFailed)) + }) + }) + + When("given operation type UPDATE and state FAILED", func() { + It("returns expected condition reason", func() { + Expect(GetConditionReason(smClientTypes.UPDATE, smClientTypes.FAILED)).To(Equal(common.UpdateFailed)) + }) + }) + + When("given operation type DELETE and state FAILED", func() { + It("returns expected condition reason", func() { + Expect(GetConditionReason(smClientTypes.DELETE, smClientTypes.FAILED)).To(Equal(common.DeleteFailed)) + }) + }) + + When("given an unknown operation type and state SUCCEEDED", func() { + It("returns finished condition reason", func() { + Expect(GetConditionReason("unknown", smClientTypes.SUCCEEDED)).To(Equal(common.Finished)) + }) + }) + + When("given an unknown operation type and state INPROGRESS", func() { + It("returns in progress condition reason", func() { + Expect(GetConditionReason("unknown", smClientTypes.INPROGRESS)).To(Equal(common.InProgress)) + }) + }) + + When("given an unknown operation type and state FAILED", func() { + It("returns failed condition reason", func() { + Expect(GetConditionReason("unknown", smClientTypes.FAILED)).To(Equal(common.Failed)) + }) + }) + + When("given operation type CREATE and unknown state", func() { + It("returns unknown condition reason", func() { + Expect(GetConditionReason(smClientTypes.CREATE, "unknown")).To(Equal(common.Unknown)) + }) + }) + }) + + Context("SetInProgressConditions", func() { + It("should set in-progress conditions", func() { + resource = getBinding() + + SetInProgressConditions(ctx, smClientTypes.CREATE, "Pending", resource) + + // Add assertions to check the state of the resource after calling SetInProgressConditions + Expect(resource.GetConditions()).ToNot(BeEmpty()) + // Add more assertions based on your expected behavior + }) + }) + + Context("SetSuccessConditions", func() { + It("should set success conditions", func() { + operationType := smClientTypes.CREATE + resource = getBinding() + + SetSuccessConditions(operationType, resource) + + // Add assertions to check the state of the resource after calling SetSuccessConditions + Expect(resource.GetConditions()).ToNot(BeEmpty()) + Expect(resource.GetReady()).To(Equal(metav1.ConditionTrue)) + // Add more assertions based on your expected behavior + }) + }) + + Context("SetCredRotationInProgressConditions", func() { + It("should set credentials rotation in-progress conditions", func() { + reason := "RotationReason" + message := "RotationMessage" + resource = getBinding() + + SetCredRotationInProgressConditions(reason, message, resource) + + // Add assertions to check the state of the resource after calling SetCredRotationInProgressConditions + Expect(resource.GetConditions()).ToNot(BeEmpty()) + // Add more assertions based on your expected behavior + }) + }) + + Context("SetFailureConditions", func() { + It("should set failure conditions", func() { + operationType := smClientTypes.CREATE + errorMessage := "Operation failed" + SetFailureConditions(operationType, errorMessage, resource) + Expect(resource.GetConditions()).ToNot(BeEmpty()) + Expect(meta.IsStatusConditionPresentAndEqual(resource.GetConditions(), common.ConditionReady, metav1.ConditionFalse)).To(BeTrue()) + }) + }) + + Context("MarkAsNonTransientError", func() { + It("should mark as non-transient error and update status", func() { + operationType := smClientTypes.CREATE + errorMessage := "Non-transient error" + + result, err := MarkAsNonTransientError(ctx, k8sClient, operationType, errorMessage, resource) + Expect(err).ToNot(HaveOccurred()) + Expect(result).To(Equal(ctrl.Result{})) + }) + }) + + Context("MarkAsTransientError", func() { + It("should handle TooManyRequests error correctly", func() { + resource.SetConditions([]metav1.Condition{{Message: "not TooManyRequests"}}) + serviceManagerError := &sm.ServiceManagerError{StatusCode: http.StatusTooManyRequests} + result, err := MarkAsTransientError(ctx, k8sClient, smClientTypes.UPDATE, serviceManagerError, resource) + Expect(err).ToNot(BeNil()) + Expect(resource.GetConditions()[0].Message).To(ContainSubstring("not TooManyRequests")) //TooManyRequests is not reflected to status + Expect(result).To(BeEquivalentTo(ctrl.Result{})) + }) + }) + + Context("SetBlockedCondition", func() { + It("Blocked Condition Set on ServiceBinding", func() { + sb := &v1.ServiceBinding{ + Status: v1.ServiceBindingStatus{ + Conditions: []metav1.Condition{}, + }, + } + + SetBlockedCondition(ctx, "Test message", sb) + Expect(meta.FindStatusCondition(sb.Status.Conditions, common.ConditionSucceeded).Reason).To(Equal(common.Blocked)) + }) + }) + + Context("IsInProgress", func() { + It("should return true for in progress condition", func() { + resource := &v1.ServiceBinding{ + Status: v1.ServiceBindingStatus{ + Conditions: []metav1.Condition{ + { + Type: common.ConditionSucceeded, + Status: metav1.ConditionFalse, + }, + { + Type: common.ConditionFailed, + Status: metav1.ConditionFalse, + }, + }, + }, + } + + Expect(IsInProgress(resource)).To(BeTrue()) + }) + + It("should return false for failed condition", func() { + resource := &v1.ServiceBinding{ + Status: v1.ServiceBindingStatus{ + Conditions: []metav1.Condition{ + { + Type: common.ConditionSucceeded, + Status: metav1.ConditionFalse, + }, + { + Type: common.ConditionFailed, + Status: metav1.ConditionTrue, + }, + }, + }, + } + + Expect(IsInProgress(resource)).To(BeFalse()) + }) + + It("should return false for succeeded condition", func() { + resource := &v1.ServiceBinding{ + Status: v1.ServiceBindingStatus{ + Conditions: []metav1.Condition{ + { + Type: common.ConditionSucceeded, + Status: metav1.ConditionTrue, + }, + { + Type: common.ConditionFailed, + Status: metav1.ConditionFalse, + }, + }, + }, + } + + Expect(IsInProgress(resource)).To(BeFalse()) + }) + + It("should return false for empty conditions", func() { + resource := &v1.ServiceBinding{ + Status: v1.ServiceBindingStatus{ + Conditions: []metav1.Condition{}, + }, + } + + Expect(IsInProgress(resource)).To(BeFalse()) + }) + }) + + Context("IsFailed", func() { + It("Should return false when no conditions available", func() { + sb := &v1.ServiceBinding{Status: v1.ServiceBindingStatus{Conditions: []metav1.Condition{}}} + result := IsFailed(sb) + Expect(result).Should(BeFalse()) + }) + + It("Should return true when ConditionFailed is true", func() { + sb := &v1.ServiceBinding{Status: v1.ServiceBindingStatus{Conditions: []metav1.Condition{{Type: common.ConditionFailed, Status: metav1.ConditionTrue}}}} + result := IsFailed(sb) + Expect(result).Should(BeTrue()) + }) + + It("Should return false when ConditionFailed is false", func() { + sb := &v1.ServiceBinding{Status: v1.ServiceBindingStatus{Conditions: []metav1.Condition{{Type: common.ConditionFailed, Status: metav1.ConditionFalse}}}} + result := IsFailed(sb) + Expect(result).Should(BeFalse()) + }) + + It("Should return true when ConditionSucceeded is false and reason is Blocked", func() { + sb := &v1.ServiceBinding{ + Status: v1.ServiceBindingStatus{Conditions: []metav1.Condition{{Type: common.ConditionSucceeded, Status: metav1.ConditionFalse, Reason: common.Blocked}}}, + } + result := IsFailed(sb) + Expect(result).Should(BeTrue()) + }) + + It("Should return false when ConditionSucceeded is true and reason is Blocked", func() { + sb := &v1.ServiceBinding{ + Status: v1.ServiceBindingStatus{Conditions: []metav1.Condition{{Type: common.ConditionSucceeded, Status: metav1.ConditionTrue, Reason: common.Blocked}}}, + } + result := IsFailed(sb) + Expect(result).Should(BeFalse()) + }) + }) +}) + +func getBinding() *v1.ServiceBinding { + return &v1.ServiceBinding{ + TypeMeta: metav1.TypeMeta{ + APIVersion: "services.cloud.sap.com/v1", + Kind: "ServiceBinding", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "service-binding-1", + Namespace: testNamespace, + }, + Spec: v1.ServiceBindingSpec{ + ServiceInstanceName: "service-instance-1", + ExternalName: "my-service-binding-1", + Parameters: &runtime.RawExtension{Raw: []byte(`{"key":"val"}`)}, + ParametersFrom: []v1.ParametersFromSource{ + { + SecretKeyRef: &v1.SecretKeyReference{ + Name: "param-secret", + Key: "secret-parameter", + }, + }, + }, + CredRotationPolicy: &v1.CredentialsRotationPolicy{ + Enabled: true, + RotationFrequency: "1s", + RotatedBindingTTL: "1s", + }, + }, + + Status: v1.ServiceBindingStatus{}, + } +} diff --git a/internal/utils/sm_utils_test.go b/internal/utils/sm_utils_test.go index 3a90d435..dac62134 100644 --- a/internal/utils/sm_utils_test.go +++ b/internal/utils/sm_utils_test.go @@ -145,7 +145,7 @@ var _ = Describe("SM Utils", func() { } Expect(k8sClient.Create(ctx, secret)).To(Succeed()) }) - XWhen("valid", func() { + When("valid", func() { BeforeEach(func() { tlsSecret = &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ @@ -159,7 +159,7 @@ var _ = Describe("SM Utils", func() { } Expect(k8sClient.Create(ctx, tlsSecret)).To(Succeed()) }) - FIt("should succeed", func() { + It("should succeed", func() { client, err := GetSMClient(ctx, resolver, testNamespace, "") Expect(err).ToNot(HaveOccurred()) //tls: failed to find any PEM data in key input Expect(client).ToNot(BeNil()) @@ -201,40 +201,53 @@ var _ = Describe("SM Utils", func() { }) }) -const tlscrt = ` ------BEGIN CERTIFICATE----- -MIICwDCCAaigAwIBAgIUD6NjUHR/8u0wDQYJKoZIhvcNAQELBQAwEzERMA8GA1UE -AxMIb3BlbmFpMB4XDTIxMDkwNzExMjM0MVoXDTIyMDkwNzExMjM0MVowEzERMA8G -A1UEAxMIb3BlbmFpMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxTjJ -qxaMXy7GvwLReer89W14s0sLLxGtrTkt8miPjGYI8Sh1vlVLxP3aW5szXc2o21p5 -r8dC62XN1vOqVh+NR16pWzBoNh1BNe0nv2LC3rB1RcfsBz8YowNpgK4eWGYZYF+o -iU0iLQw+Z0DD8wN4XYu/1DN+v6XzG6e6UsJ/iee1msPiP8xEcs+gVGdq1+fwCIsI -OvFK6TQIu7W5PVGrh2Tkgf1ks2ICklh+55+fF5PyP4fqXKIoHY4JMDtrq1g+j22E -YIvCu0rlq+2dzhtYjviwAT/lTJtYYxP5nzPKhgo6NGLGFTOcwDIk3g/b8g3PzFHz -kym+IbZdDQIDAQABo1MwUTAdBgNVHQ4EFgQUDUxmCq2rLzKv4QG6JhWx9aXpMr0w -HwYDVR0jBBgwFo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PCtKW +ICwycby2nLYd40HJv2+G3mdR +-----END PRIVATE KEY-----` diff --git a/internal/utils/suite_test.go b/internal/utils/suite_test.go index 77442d69..aa54a034 100644 --- a/internal/utils/suite_test.go +++ b/internal/utils/suite_test.go @@ -18,6 +18,9 @@ package utils import ( "context" + v1 "github.com/SAP/sap-btp-service-operator/api/v1" + "k8s.io/client-go/rest" + "path/filepath" "testing" "time" @@ -47,6 +50,7 @@ const ( ) var ( + cfg *rest.Config ctx context.Context k8sClient client.Client testEnv *envtest.Environment @@ -65,13 +69,24 @@ var _ = BeforeSuite(func(done Done) { logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) By("bootstrapping test environment") - testEnv = &envtest.Environment{} + testEnv = &envtest.Environment{ + CRDDirectoryPaths: []string{filepath.Join("../..", "config", "crd", "bases")}, + } var err error - cfg, err := testEnv.Start() + cfg, err = testEnv.Start() Expect(err).ToNot(HaveOccurred()) Expect(cfg).ToNot(BeNil()) + err = v1.AddToScheme(scheme.Scheme) + Expect(err).NotTo(HaveOccurred()) + + // +kubebuilder:scaffold:scheme + + k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) + Expect(err).ToNot(HaveOccurred()) + Expect(k8sClient).ToNot(BeNil()) + // +kubebuilder:scaffold:scheme webhookInstallOptions := &testEnv.WebhookInstallOptions @@ -95,8 +110,8 @@ var _ = BeforeSuite(func(done Done) { }() k8sManager.GetCache().WaitForCacheSync(context.Background()) - k8sClient = k8sManager.GetClient() - Expect(k8sClient).ToNot(BeNil()) + //k8sClient = k8sManager.GetClient() + //Expect(k8sClient).ToNot(BeNil()) nsSpec := &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: testNamespace}} err = k8sClient.Create(context.Background(), nsSpec)