2022-02-07 10:42:18 +00:00
|
|
|
/*
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package secretstore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/go-logr/logr"
|
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"k8s.io/client-go/tools/record"
|
|
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
2024-11-19 11:20:05 +00:00
|
|
|
"sigs.k8s.io/controller-runtime/pkg/controller"
|
2022-02-07 10:42:18 +00:00
|
|
|
|
2022-02-08 17:07:34 +00:00
|
|
|
esapi "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
|
2023-06-05 19:26:25 +00:00
|
|
|
ctrlmetrics "github.com/external-secrets/external-secrets/pkg/controllers/metrics"
|
|
|
|
"github.com/external-secrets/external-secrets/pkg/controllers/secretstore/cssmetrics"
|
2024-04-25 09:36:11 +00:00
|
|
|
|
2022-02-07 10:42:18 +00:00
|
|
|
// Loading registered providers.
|
|
|
|
_ "github.com/external-secrets/external-secrets/pkg/provider/register"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ClusterStoreReconciler reconciles a SecretStore object.
|
|
|
|
type ClusterStoreReconciler struct {
|
|
|
|
client.Client
|
|
|
|
Log logr.Logger
|
|
|
|
Scheme *runtime.Scheme
|
|
|
|
ControllerClass string
|
|
|
|
RequeueInterval time.Duration
|
|
|
|
recorder record.EventRecorder
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ClusterStoreReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
|
|
|
log := r.Log.WithValues("clustersecretstore", req.NamespacedName)
|
2023-06-05 19:26:25 +00:00
|
|
|
|
|
|
|
resourceLabels := ctrlmetrics.RefineNonConditionMetricLabels(map[string]string{"name": req.Name, "namespace": req.Namespace})
|
|
|
|
start := time.Now()
|
|
|
|
|
|
|
|
clusterSecretStoreReconcileDuration := cssmetrics.GetGaugeVec(cssmetrics.ClusterSecretStoreReconcileDurationKey)
|
|
|
|
defer func() { clusterSecretStoreReconcileDuration.With(resourceLabels).Set(float64(time.Since(start))) }()
|
|
|
|
|
2022-02-07 10:42:18 +00:00
|
|
|
var css esapi.ClusterSecretStore
|
|
|
|
err := r.Get(ctx, req.NamespacedName, &css)
|
|
|
|
if apierrors.IsNotFound(err) {
|
2023-08-24 19:57:34 +00:00
|
|
|
cssmetrics.RemoveMetrics(req.Namespace, req.Name)
|
2022-02-07 10:42:18 +00:00
|
|
|
return ctrl.Result{}, nil
|
|
|
|
} else if err != nil {
|
|
|
|
log.Error(err, "unable to get ClusterSecretStore")
|
|
|
|
return ctrl.Result{}, err
|
|
|
|
}
|
|
|
|
|
2023-06-21 19:59:23 +00:00
|
|
|
return reconcile(ctx, req, &css, r.Client, log, r.ControllerClass, cssmetrics.GetGaugeVec, r.recorder, r.RequeueInterval)
|
2022-02-07 10:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetupWithManager returns a new controller builder that will be started by the provided Manager.
|
2024-11-19 11:20:05 +00:00
|
|
|
func (r *ClusterStoreReconciler) SetupWithManager(mgr ctrl.Manager, opts controller.Options) error {
|
2022-02-07 10:42:18 +00:00
|
|
|
r.recorder = mgr.GetEventRecorderFor("cluster-secret-store")
|
|
|
|
|
|
|
|
return ctrl.NewControllerManagedBy(mgr).
|
2024-11-19 11:20:05 +00:00
|
|
|
WithOptions(opts).
|
2022-02-07 10:42:18 +00:00
|
|
|
For(&esapi.ClusterSecretStore{}).
|
|
|
|
Complete(r)
|
|
|
|
}
|