|
| 1 | +// Copyright (c) 2022 Gitpod GmbH. All rights reserved. |
| 2 | +// Licensed under the GNU Affero General Public License (AGPL). |
| 3 | +// See License-AGPL.txt in the project root for license information. |
| 4 | + |
| 5 | +package manager |
| 6 | + |
| 7 | +import ( |
| 8 | + "context" |
| 9 | + |
| 10 | + "github.com/go-logr/logr" |
| 11 | + volumesnapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" |
| 12 | + "k8s.io/apimachinery/pkg/api/errors" |
| 13 | + "k8s.io/apimachinery/pkg/runtime" |
| 14 | + "k8s.io/apimachinery/pkg/watch" |
| 15 | + ctrl "sigs.k8s.io/controller-runtime" |
| 16 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 17 | + "sigs.k8s.io/controller-runtime/pkg/reconcile" |
| 18 | +) |
| 19 | + |
| 20 | +// VolumeSnapshotReconciler reconciles a VolumeSnapshot object |
| 21 | +type VolumeSnapshotReconciler struct { |
| 22 | + client.Client |
| 23 | + Log logr.Logger |
| 24 | + Scheme *runtime.Scheme |
| 25 | + |
| 26 | + Monitor *Monitor |
| 27 | +} |
| 28 | + |
| 29 | +// Reconcile performs a reconciliation of a volume snapshot |
| 30 | +// For more details, check Reconcile and its Result here: |
| 31 | +// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile |
| 32 | +func (r *VolumeSnapshotReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { |
| 33 | + var vs volumesnapshotv1.VolumeSnapshot |
| 34 | + err := r.Client.Get(context.Background(), req.NamespacedName, &vs) |
| 35 | + if errors.IsNotFound(err) { |
| 36 | + // volume snapshot is gone - that's ok |
| 37 | + return reconcile.Result{}, nil |
| 38 | + } |
| 39 | + |
| 40 | + r.Monitor.eventpool.Add(vs.Name, watch.Event{ |
| 41 | + Type: watch.Modified, |
| 42 | + Object: &vs, |
| 43 | + }) |
| 44 | + |
| 45 | + return ctrl.Result{}, nil |
| 46 | +} |
| 47 | + |
| 48 | +// SetupWithManager sets up the controller with the Manager. |
| 49 | +func (r *VolumeSnapshotReconciler) SetupWithManager(mgr ctrl.Manager) error { |
| 50 | + return ctrl.NewControllerManagedBy(mgr). |
| 51 | + For(&volumesnapshotv1.VolumeSnapshot{}). |
| 52 | + Complete(r) |
| 53 | +} |
0 commit comments