-
Notifications
You must be signed in to change notification settings - Fork 626
/
argocdexport_controller.go
85 lines (68 loc) · 3 KB
/
argocdexport_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
Copyright 2019, 2021.
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 argocdexport
import (
"context"
ctrl "sigs.k8s.io/controller-runtime"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
logr "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
argoproj "github.com/argoproj-labs/argocd-operator/api/v1alpha1"
)
var log = logr.Log.WithName("controller_argocdexport")
// blank assignment to verify that ReconcileArgoCDExport implements reconcile.Reconciler
var _ reconcile.Reconciler = &ReconcileArgoCDExport{}
// ReconcileArgoCDExport reconciles a ArgoCDExport object
// TODO(update) rename to ArgoCDExportReconciler
type ReconcileArgoCDExport struct {
// This client, initialized using mgr.Client() above, is a split client
// that reads objects from the cache and writes to the apiserver
Client client.Client
Scheme *runtime.Scheme
}
//+kubebuilder:rbac:groups=argoproj.io,resources=argocdexports;argocdexports/finalizers;argocdexports/status,verbs=*
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.9.2/pkg/reconcile
func (r *ReconcileArgoCDExport) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) {
reqLogger := logr.FromContext(ctx, "Request.Namespace", request.Namespace, "Request.Name", request.Name)
reqLogger.Info("Reconciling ArgoCDExport")
// Fetch the ArgoCDExport instance
export := &argoproj.ArgoCDExport{}
err := r.Client.Get(ctx, request.NamespacedName, export)
if err != nil {
if errors.IsNotFound(err) {
// Request object not found, could have been deleted after reconcile request.
// Owned objects are automatically garbage collected. For additional cleanup logic use finalizers.
// Return and don't requeue
return reconcile.Result{}, nil
}
// Error reading the object - requeue the request.
return reconcile.Result{}, err
}
if err := r.reconcileArgoCDExportResources(export); err != nil {
// Error reconciling ArgoCDExport sub-resources - requeue the request.
return reconcile.Result{}, err
}
return reconcile.Result{}, nil
}
// SetupWithManager sets up the controller with the Manager.
func (r *ReconcileArgoCDExport) SetupWithManager(mgr ctrl.Manager) error {
bld := ctrl.NewControllerManagedBy(mgr)
setResourceWatches(bld)
return bld.Complete(r)
}