|
@@ -52,6 +52,9 @@ type Reconciler struct {
|
|
|
ControllerClass string
|
|
ControllerClass string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// Reconcile implements the main reconciliation loop
|
|
|
|
|
+// for watched objects (ExternalSecret, ClusterSecretStore and SecretStore),
|
|
|
|
|
+// and updates/creates a Kubernetes secret based on them.
|
|
|
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
|
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
|
|
log := r.Log.WithValues("ExternalSecret", req.NamespacedName)
|
|
log := r.Log.WithValues("ExternalSecret", req.NamespacedName)
|
|
|
|
|
|
|
@@ -164,6 +167,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
|
|
|
}, nil
|
|
}, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// shouldProcessStore returns true if the store should be processed.
|
|
|
func shouldProcessStore(store esv1alpha1.GenericStore, class string) bool {
|
|
func shouldProcessStore(store esv1alpha1.GenericStore, class string) bool {
|
|
|
if store.GetSpec().Controller == "" || store.GetSpec().Controller == class {
|
|
if store.GetSpec().Controller == "" || store.GetSpec().Controller == class {
|
|
|
return true
|
|
return true
|
|
@@ -191,12 +195,14 @@ func mergeTemplate(secret *corev1.Secret, externalSecret esv1alpha1.ExternalSecr
|
|
|
mergeMap(secret.ObjectMeta.Annotations, externalSecret.Spec.Target.Template.Metadata.Annotations)
|
|
mergeMap(secret.ObjectMeta.Annotations, externalSecret.Spec.Target.Template.Metadata.Annotations)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// mergeMap performs a deep clone from src to dest.
|
|
|
func mergeMap(dest, src map[string]string) {
|
|
func mergeMap(dest, src map[string]string) {
|
|
|
for k, v := range src {
|
|
for k, v := range src {
|
|
|
dest[k] = v
|
|
dest[k] = v
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// getStore returns the store with the provided ExternalSecret.
|
|
|
func (r *Reconciler) getStore(ctx context.Context, externalSecret *esv1alpha1.ExternalSecret) (esv1alpha1.GenericStore, error) {
|
|
func (r *Reconciler) getStore(ctx context.Context, externalSecret *esv1alpha1.ExternalSecret) (esv1alpha1.GenericStore, error) {
|
|
|
ref := types.NamespacedName{
|
|
ref := types.NamespacedName{
|
|
|
Name: externalSecret.Spec.SecretStoreRef.Name,
|
|
Name: externalSecret.Spec.SecretStoreRef.Name,
|
|
@@ -222,6 +228,7 @@ func (r *Reconciler) getStore(ctx context.Context, externalSecret *esv1alpha1.Ex
|
|
|
return &store, nil
|
|
return &store, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// getProviderSecretData returns the provider's secret data with the provided ExternalSecret.
|
|
|
func (r *Reconciler) getProviderSecretData(ctx context.Context, providerClient provider.SecretsClient, externalSecret *esv1alpha1.ExternalSecret) (map[string][]byte, error) {
|
|
func (r *Reconciler) getProviderSecretData(ctx context.Context, providerClient provider.SecretsClient, externalSecret *esv1alpha1.ExternalSecret) (map[string][]byte, error) {
|
|
|
providerData := make(map[string][]byte)
|
|
providerData := make(map[string][]byte)
|
|
|
|
|
|
|
@@ -246,6 +253,7 @@ func (r *Reconciler) getProviderSecretData(ctx context.Context, providerClient p
|
|
|
return providerData, nil
|
|
return providerData, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// SetupWithManager returns a new controller builder that will be started by the provided Manager.
|
|
|
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
|
|
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
|
|
|
return ctrl.NewControllerManagedBy(mgr).
|
|
return ctrl.NewControllerManagedBy(mgr).
|
|
|
For(&esv1alpha1.ExternalSecret{}).
|
|
For(&esv1alpha1.ExternalSecret{}).
|