|
|
@@ -169,6 +169,9 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
Name: PushSecretStore,
|
|
|
Namespace: PushSecretNamespace,
|
|
|
},
|
|
|
+ TypeMeta: metav1.TypeMeta{
|
|
|
+ Kind: "SecretStore",
|
|
|
+ },
|
|
|
Spec: v1beta1.SecretStoreSpec{
|
|
|
Provider: &v1beta1.SecretStoreProvider{
|
|
|
Fake: &v1beta1.FakeProvider{
|
|
|
@@ -186,15 +189,72 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
return nil
|
|
|
}
|
|
|
tc.assert = func(ps *v1alpha1.PushSecret, secret *v1.Secret) bool {
|
|
|
- secretValue := secret.Data["key"]
|
|
|
- providerValue := fakeProvider.SetSecretArgs[ps.Spec.Data[0].Match.RemoteRef.RemoteKey].Value
|
|
|
- expected := v1alpha1.PushSecretStatusCondition{
|
|
|
- Type: v1alpha1.PushSecretReady,
|
|
|
- Status: v1.ConditionTrue,
|
|
|
- Reason: v1alpha1.ReasonSynced,
|
|
|
- Message: "PushSecret synced successfully",
|
|
|
- }
|
|
|
- return bytes.Equal(secretValue, providerValue) && checkCondition(ps.Status, expected)
|
|
|
+ Eventually(func() bool {
|
|
|
+ By("checking if Provider value got updated")
|
|
|
+ secretValue := secret.Data["key"]
|
|
|
+ providerValue, ok := fakeProvider.SetSecretArgs[ps.Spec.Data[0].Match.RemoteRef.RemoteKey]
|
|
|
+ if !ok {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ got := providerValue.Value
|
|
|
+ return bytes.Equal(got, secretValue)
|
|
|
+ }, time.Second*10, time.Second).Should(BeTrue())
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // if target Secret name is not specified it should use the ExternalSecret name.
|
|
|
+ syncAndDeleteSuccessfully := func(tc *testCase) {
|
|
|
+ fakeProvider.SetSecretFn = func() error {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ tc.pushsecret = &v1alpha1.PushSecret{
|
|
|
+ ObjectMeta: metav1.ObjectMeta{
|
|
|
+ Name: PushSecretName,
|
|
|
+ Namespace: PushSecretNamespace,
|
|
|
+ },
|
|
|
+ Spec: v1alpha1.PushSecretSpec{
|
|
|
+ DeletionPolicy: v1alpha1.PushSecretDeletionPolicyDelete,
|
|
|
+ SecretStoreRefs: []v1alpha1.PushSecretStoreRef{
|
|
|
+ {
|
|
|
+ Name: PushSecretStore,
|
|
|
+ Kind: "SecretStore",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ Selector: v1alpha1.PushSecretSelector{
|
|
|
+ Secret: v1alpha1.PushSecretSecret{
|
|
|
+ Name: SecretName,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ Data: []v1alpha1.PushSecretData{
|
|
|
+ {
|
|
|
+ Match: v1alpha1.PushSecretMatch{
|
|
|
+ SecretKey: "key",
|
|
|
+ RemoteRef: v1alpha1.PushSecretRemoteRef{
|
|
|
+ RemoteKey: "path/to/key",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+ tc.assert = func(ps *v1alpha1.PushSecret, secret *v1.Secret) bool {
|
|
|
+ ps.Spec.Data[0].Match.RemoteRef.RemoteKey = "different-key"
|
|
|
+ updatedPS := &v1alpha1.PushSecret{}
|
|
|
+ Expect(k8sClient.Update(context.Background(), ps, &client.UpdateOptions{})).Should(Succeed())
|
|
|
+ Eventually(func() bool {
|
|
|
+ psKey := types.NamespacedName{Name: PushSecretName, Namespace: PushSecretNamespace}
|
|
|
+ By("checking if Provider value got updated")
|
|
|
+ err := k8sClient.Get(context.Background(), psKey, updatedPS)
|
|
|
+ if err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ key, ok := updatedPS.Status.SyncedPushSecrets[fmt.Sprintf("SecretStore/%v", PushSecretStore)]["different-key"]
|
|
|
+ if !ok {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return key.Match.SecretKey == "key"
|
|
|
+ }, time.Second*10, time.Second).Should(BeTrue())
|
|
|
+ return true
|
|
|
}
|
|
|
}
|
|
|
// if target Secret name is not specified it should use the ExternalSecret name.
|
|
|
@@ -236,6 +296,9 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
},
|
|
|
}
|
|
|
tc.store = &v1beta1.SecretStore{
|
|
|
+ TypeMeta: metav1.TypeMeta{
|
|
|
+ Kind: "SecretStore",
|
|
|
+ },
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
Name: PushSecretStore,
|
|
|
Namespace: PushSecretNamespace,
|
|
|
@@ -268,6 +331,9 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
return nil
|
|
|
}
|
|
|
tc.store = &v1beta1.ClusterSecretStore{
|
|
|
+ TypeMeta: metav1.TypeMeta{
|
|
|
+ Kind: "ClusterSecretStore",
|
|
|
+ },
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
Name: PushSecretStore,
|
|
|
},
|
|
|
@@ -483,6 +549,7 @@ var _ = Describe("ExternalSecret controller", func() {
|
|
|
// this must be optional so we can test faulty es configuration
|
|
|
},
|
|
|
Entry("should sync", syncSuccessfully),
|
|
|
+ Entry("should delete if DeletionPolicy=Delete", syncAndDeleteSuccessfully),
|
|
|
Entry("should sync to stores matching labels", syncMatchingLabels),
|
|
|
Entry("should sync with ClusterStore", syncWithClusterStore),
|
|
|
Entry("should sync with ClusterStore matching labels", syncWithClusterStoreMatchingLabels),
|