clustersecretstore_controller.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package secretstore
  13. import (
  14. "context"
  15. "time"
  16. "github.com/go-logr/logr"
  17. apierrors "k8s.io/apimachinery/pkg/api/errors"
  18. "k8s.io/apimachinery/pkg/runtime"
  19. "k8s.io/client-go/tools/record"
  20. ctrl "sigs.k8s.io/controller-runtime"
  21. "sigs.k8s.io/controller-runtime/pkg/client"
  22. esapi "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
  23. // Loading registered providers.
  24. _ "github.com/external-secrets/external-secrets/pkg/provider/register"
  25. )
  26. // ClusterStoreReconciler reconciles a SecretStore object.
  27. type ClusterStoreReconciler struct {
  28. client.Client
  29. Log logr.Logger
  30. Scheme *runtime.Scheme
  31. ControllerClass string
  32. RequeueInterval time.Duration
  33. recorder record.EventRecorder
  34. }
  35. func (r *ClusterStoreReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
  36. log := r.Log.WithValues("clustersecretstore", req.NamespacedName)
  37. var css esapi.ClusterSecretStore
  38. err := r.Get(ctx, req.NamespacedName, &css)
  39. if apierrors.IsNotFound(err) {
  40. return ctrl.Result{}, nil
  41. } else if err != nil {
  42. log.Error(err, "unable to get ClusterSecretStore")
  43. return ctrl.Result{}, err
  44. }
  45. return reconcile(ctx, req, &css, r.Client, log, r.ControllerClass, r.recorder, r.RequeueInterval)
  46. }
  47. // SetupWithManager returns a new controller builder that will be started by the provided Manager.
  48. func (r *ClusterStoreReconciler) SetupWithManager(mgr ctrl.Manager) error {
  49. r.recorder = mgr.GetEventRecorderFor("cluster-secret-store")
  50. return ctrl.NewControllerManagedBy(mgr).
  51. For(&esapi.ClusterSecretStore{}).
  52. Complete(r)
  53. }