|
@@ -30,9 +30,14 @@ import (
|
|
|
"github.com/external-secrets/external-secrets/pkg/provider"
|
|
"github.com/external-secrets/external-secrets/pkg/provider"
|
|
|
"github.com/external-secrets/external-secrets/pkg/provider/fake"
|
|
"github.com/external-secrets/external-secrets/pkg/provider/fake"
|
|
|
"github.com/external-secrets/external-secrets/pkg/provider/schema"
|
|
"github.com/external-secrets/external-secrets/pkg/provider/schema"
|
|
|
|
|
+
|
|
|
|
|
+ dto "github.com/prometheus/client_model/go"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-var fakeProvider *fake.Client
|
|
|
|
|
|
|
+var (
|
|
|
|
|
+ fakeProvider *fake.Client
|
|
|
|
|
+ metric dto.Metric
|
|
|
|
|
+)
|
|
|
|
|
|
|
|
var _ = Describe("ExternalSecret controller", func() {
|
|
var _ = Describe("ExternalSecret controller", func() {
|
|
|
const (
|
|
const (
|
|
@@ -63,7 +68,11 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
},
|
|
},
|
|
|
})).To(Succeed())
|
|
})).To(Succeed())
|
|
|
|
|
|
|
|
|
|
+ metric.Reset()
|
|
|
|
|
+ sync_calls_total.Reset()
|
|
|
|
|
+ sync_calls_error.Reset()
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
AfterEach(func() {
|
|
AfterEach(func() {
|
|
|
Expect(k8sClient.Delete(context.Background(), &v1.Namespace{
|
|
Expect(k8sClient.Delete(context.Background(), &v1.Namespace{
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
@@ -78,9 +87,8 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
}, client.PropagationPolicy(metav1.DeletePropagationBackground)), client.GracePeriodSeconds(0)).To(Succeed())
|
|
}, client.PropagationPolicy(metav1.DeletePropagationBackground)), client.GracePeriodSeconds(0)).To(Succeed())
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- Context("When updating ExternalSecret Status", func() {
|
|
|
|
|
|
|
+ Context("When creating an ExternalSecret", func() {
|
|
|
It("should set the condition eventually", func() {
|
|
It("should set the condition eventually", func() {
|
|
|
- By("creating an ExternalSecret")
|
|
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
es := &esv1alpha1.ExternalSecret{
|
|
es := &esv1alpha1.ExternalSecret{
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
@@ -112,11 +120,93 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
}, timeout, interval).Should(BeTrue())
|
|
}, timeout, interval).Should(BeTrue())
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ It("should increment the sync_calls_total metric", func() {
|
|
|
|
|
+ ctx := context.Background()
|
|
|
|
|
+ es := &esv1alpha1.ExternalSecret{
|
|
|
|
|
+ ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
+ Name: ExternalSecretName,
|
|
|
|
|
+ Namespace: ExternalSecretNamespace,
|
|
|
|
|
+ },
|
|
|
|
|
+ Spec: esv1alpha1.ExternalSecretSpec{
|
|
|
|
|
+ SecretStoreRef: esv1alpha1.SecretStoreRef{
|
|
|
|
|
+ Name: ExternalSecretStore,
|
|
|
|
|
+ },
|
|
|
|
|
+ Target: esv1alpha1.ExternalSecretTarget{
|
|
|
|
|
+ Name: ExternalSecretTargetSecretName,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Expect(k8sClient.Create(ctx, es)).Should(Succeed())
|
|
|
|
|
+
|
|
|
|
|
+ // When creating a new ExternalSecret, the Reconcile loop executes twice
|
|
|
|
|
+ // due the call to `controllerutil.SetControllerReference`
|
|
|
|
|
+ expectedValue := 2.0
|
|
|
|
|
+
|
|
|
|
|
+ Eventually(func() float64 {
|
|
|
|
|
+ Expect(sync_calls_total.WithLabelValues(ExternalSecretName, ExternalSecretNamespace).Write(&metric)).To(Succeed())
|
|
|
|
|
+ return metric.GetCounter().GetValue()
|
|
|
|
|
+ }, timeout, interval).Should(Equal(expectedValue))
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ Context("When updating an ExternalSecret", func() {
|
|
|
|
|
+ It("should increment the sync_calls_total metric", func() {
|
|
|
|
|
+ ctx := context.Background()
|
|
|
|
|
+ es := &esv1alpha1.ExternalSecret{
|
|
|
|
|
+ ObjectMeta: metav1.ObjectMeta{
|
|
|
|
|
+ Name: ExternalSecretName,
|
|
|
|
|
+ Namespace: ExternalSecretNamespace,
|
|
|
|
|
+ },
|
|
|
|
|
+ Spec: esv1alpha1.ExternalSecretSpec{
|
|
|
|
|
+ SecretStoreRef: esv1alpha1.SecretStoreRef{
|
|
|
|
|
+ Name: ExternalSecretStore,
|
|
|
|
|
+ },
|
|
|
|
|
+ Target: esv1alpha1.ExternalSecretTarget{
|
|
|
|
|
+ Name: ExternalSecretTargetSecretName,
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Expect(k8sClient.Create(ctx, es)).Should(Succeed())
|
|
|
|
|
+
|
|
|
|
|
+ Eventually(func() float64 {
|
|
|
|
|
+ Expect(sync_calls_total.WithLabelValues(ExternalSecretName, ExternalSecretNamespace).Write(&metric)).To(Succeed())
|
|
|
|
|
+ return metric.GetCounter().GetValue()
|
|
|
|
|
+ }, timeout, interval).Should(Equal(2.0))
|
|
|
|
|
+
|
|
|
|
|
+ createdES := &esv1alpha1.ExternalSecret{}
|
|
|
|
|
+
|
|
|
|
|
+ Eventually(func() error {
|
|
|
|
|
+ esLookupKey := types.NamespacedName{Name: ExternalSecretName, Namespace: ExternalSecretNamespace}
|
|
|
|
|
+
|
|
|
|
|
+ err := k8sClient.Get(ctx, esLookupKey, createdES)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ createdES.Spec.RefreshInterval = &metav1.Duration{Duration: 10 * time.Second}
|
|
|
|
|
+
|
|
|
|
|
+ err = k8sClient.Update(ctx, createdES)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }, timeout, interval).Should(Succeed())
|
|
|
|
|
+
|
|
|
|
|
+ // 2 from the Create() + 1 from Update()
|
|
|
|
|
+ expectedValue := 3.0
|
|
|
|
|
+
|
|
|
|
|
+ Eventually(func() float64 {
|
|
|
|
|
+ Expect(sync_calls_total.WithLabelValues(ExternalSecretName, ExternalSecretNamespace).Write(&metric)).To(Succeed())
|
|
|
|
|
+ return metric.GetCounter().GetValue()
|
|
|
|
|
+ }, timeout, interval).Should(Equal(expectedValue))
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
Context("When syncing ExternalSecret value", func() {
|
|
Context("When syncing ExternalSecret value", func() {
|
|
|
It("should set the secret value and sync labels/annotations", func() {
|
|
It("should set the secret value and sync labels/annotations", func() {
|
|
|
- By("creating an ExternalSecret")
|
|
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
const targetProp = "targetProperty"
|
|
const targetProp = "targetProperty"
|
|
|
const secretVal = "someValue"
|
|
const secretVal = "someValue"
|
|
@@ -171,7 +261,6 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
It("should refresh secret value", func() {
|
|
It("should refresh secret value", func() {
|
|
|
- By("creating an ExternalSecret")
|
|
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
const targetProp = "targetProperty"
|
|
const targetProp = "targetProperty"
|
|
|
const secretVal = "someValue"
|
|
const secretVal = "someValue"
|
|
@@ -227,7 +316,6 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
It("should fetch secrets using dataFrom", func() {
|
|
It("should fetch secrets using dataFrom", func() {
|
|
|
- By("creating an ExternalSecret")
|
|
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
const secretVal = "someValue"
|
|
const secretVal = "someValue"
|
|
|
es := &esv1alpha1.ExternalSecret{
|
|
es := &esv1alpha1.ExternalSecret{
|
|
@@ -272,7 +360,6 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
It("should set an error condition when provider errors", func() {
|
|
It("should set an error condition when provider errors", func() {
|
|
|
- By("creating an ExternalSecret")
|
|
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
const targetProp = "targetProperty"
|
|
const targetProp = "targetProperty"
|
|
|
es := &esv1alpha1.ExternalSecret{
|
|
es := &esv1alpha1.ExternalSecret{
|
|
@@ -317,10 +404,14 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
}
|
|
}
|
|
|
return true
|
|
return true
|
|
|
}, timeout, interval).Should(BeTrue())
|
|
}, timeout, interval).Should(BeTrue())
|
|
|
|
|
+
|
|
|
|
|
+ Eventually(func() float64 {
|
|
|
|
|
+ Expect(sync_calls_error.WithLabelValues(ExternalSecretName, ExternalSecretNamespace).Write(&metric)).To(Succeed())
|
|
|
|
|
+ return metric.GetCounter().GetValue()
|
|
|
|
|
+ }, timeout, interval).Should(Equal(1.0))
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
It("should set an error condition when store does not exist", func() {
|
|
It("should set an error condition when store does not exist", func() {
|
|
|
- By("creating an ExternalSecret")
|
|
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
const targetProp = "targetProperty"
|
|
const targetProp = "targetProperty"
|
|
|
es := &esv1alpha1.ExternalSecret{
|
|
es := &esv1alpha1.ExternalSecret{
|
|
@@ -364,10 +455,14 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
}
|
|
}
|
|
|
return true
|
|
return true
|
|
|
}, timeout, interval).Should(BeTrue())
|
|
}, timeout, interval).Should(BeTrue())
|
|
|
|
|
+
|
|
|
|
|
+ Eventually(func() float64 {
|
|
|
|
|
+ Expect(sync_calls_error.WithLabelValues(ExternalSecretName, ExternalSecretNamespace).Write(&metric)).To(Succeed())
|
|
|
|
|
+ return metric.GetCounter().GetValue()
|
|
|
|
|
+ }, timeout, interval).Should(Equal(1.0))
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
It("should set an error condition when store provider constructor fails", func() {
|
|
It("should set an error condition when store provider constructor fails", func() {
|
|
|
- By("creating an ExternalSecret")
|
|
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
const targetProp = "targetProperty"
|
|
const targetProp = "targetProperty"
|
|
|
es := &esv1alpha1.ExternalSecret{
|
|
es := &esv1alpha1.ExternalSecret{
|
|
@@ -415,10 +510,14 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
}
|
|
}
|
|
|
return true
|
|
return true
|
|
|
}, timeout, interval).Should(BeTrue())
|
|
}, timeout, interval).Should(BeTrue())
|
|
|
|
|
+
|
|
|
|
|
+ Eventually(func() float64 {
|
|
|
|
|
+ Expect(sync_calls_error.WithLabelValues(ExternalSecretName, ExternalSecretNamespace).Write(&metric)).To(Succeed())
|
|
|
|
|
+ return metric.GetCounter().GetValue()
|
|
|
|
|
+ }, timeout, interval).Should(Equal(1.0))
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
It("should not process stores with mismatching controller field", func() {
|
|
It("should not process stores with mismatching controller field", func() {
|
|
|
- By("creating an ExternalSecret")
|
|
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
storeName := "example-ts-foo"
|
|
storeName := "example-ts-foo"
|
|
|
Expect(k8sClient.Create(context.Background(), &esv1alpha1.SecretStore{
|
|
Expect(k8sClient.Create(context.Background(), &esv1alpha1.SecretStore{
|
|
@@ -484,7 +583,6 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
return cond == nil
|
|
return cond == nil
|
|
|
}, timeout, interval).Should(BeTrue())
|
|
}, timeout, interval).Should(BeTrue())
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|