diff --git a/api/v1beta1/grafanafolder_types.go b/api/v1beta1/grafanafolder_types.go
index bc72c57c8..54b104580 100644
--- a/api/v1beta1/grafanafolder_types.go
+++ b/api/v1beta1/grafanafolder_types.go
@@ -55,6 +55,8 @@ type GrafanaFolderStatus struct {
Hash string `json:"hash,omitempty"`
// The folder instanceSelector can't find matching grafana instances
NoMatchingInstances bool `json:"NoMatchingInstances,omitempty"`
+ // Last time the folder was resynced
+ LastResync metav1.Time `json:"lastResync,omitempty"`
}
//+kubebuilder:object:root=true
@@ -133,3 +135,8 @@ func (in *GrafanaFolder) GetResyncPeriod() time.Duration {
return duration
}
+
+func (in *GrafanaFolder) ResyncPeriodHasElapsed() bool {
+ deadline := in.Status.LastResync.Add(in.GetResyncPeriod())
+ return time.Now().After(deadline)
+}
diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go
index fe1cda1e6..e11390322 100644
--- a/api/v1beta1/zz_generated.deepcopy.go
+++ b/api/v1beta1/zz_generated.deepcopy.go
@@ -794,7 +794,7 @@ func (in *GrafanaFolder) DeepCopyInto(out *GrafanaFolder) {
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
in.Spec.DeepCopyInto(&out.Spec)
- out.Status = in.Status
+ in.Status.DeepCopyInto(&out.Status)
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GrafanaFolder.
@@ -875,6 +875,7 @@ func (in *GrafanaFolderSpec) DeepCopy() *GrafanaFolderSpec {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *GrafanaFolderStatus) DeepCopyInto(out *GrafanaFolderStatus) {
*out = *in
+ in.LastResync.DeepCopyInto(&out.LastResync)
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GrafanaFolderStatus.
diff --git a/config/crd/bases/grafana.integreatly.org_grafanafolders.yaml b/config/crd/bases/grafana.integreatly.org_grafanafolders.yaml
index cc942ce44..84492be82 100644
--- a/config/crd/bases/grafana.integreatly.org_grafanafolders.yaml
+++ b/config/crd/bases/grafana.integreatly.org_grafanafolders.yaml
@@ -75,6 +75,9 @@ spec:
type: boolean
hash:
type: string
+ lastResync:
+ format: date-time
+ type: string
type: object
type: object
served: true
diff --git a/config/grafana.integreatly.org_grafanafolders.yaml b/config/grafana.integreatly.org_grafanafolders.yaml
index 6eed112fc..de178ef10 100644
--- a/config/grafana.integreatly.org_grafanafolders.yaml
+++ b/config/grafana.integreatly.org_grafanafolders.yaml
@@ -115,6 +115,10 @@ spec:
of cluster Important: Run "make" to regenerate code after modifying
this file'
type: string
+ lastResync:
+ description: Last time the folder was resynced
+ format: date-time
+ type: string
type: object
type: object
served: true
diff --git a/controllers/grafanafolder_controller.go b/controllers/grafanafolder_controller.go
index 025579120..b8a3b9cc1 100644
--- a/controllers/grafanafolder_controller.go
+++ b/controllers/grafanafolder_controller.go
@@ -28,6 +28,7 @@ import (
"github.com/grafana-operator/grafana-operator/v5/controllers/metrics"
grapi "github.com/grafana/grafana-api-golang-client"
"k8s.io/apimachinery/pkg/api/errors"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/grafana-operator/grafana-operator/v5/api/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
@@ -202,7 +203,10 @@ func (r *GrafanaFolderReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{RequeueAfter: RequeueDelay}, nil
}
- return ctrl.Result{RequeueAfter: folder.GetResyncPeriod()}, nil
+ if folder.ResyncPeriodHasElapsed() {
+ folder.Status.LastResync = metav1.Time{Time: time.Now()}
+ }
+ return ctrl.Result{RequeueAfter: folder.GetResyncPeriod()}, r.UpdateStatus(ctx, folder)
}
// SetupWithManager sets up the controller with the Manager.
@@ -343,7 +347,7 @@ func (r *GrafanaFolderReconciler) onFolderCreated(ctx context.Context, grafana *
}
}
- return r.UpdateStatus(ctx, cr)
+ return nil
}
func (r *GrafanaFolderReconciler) UpdateStatus(ctx context.Context, cr *v1beta1.GrafanaFolder) error {
diff --git a/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanafolders.yaml b/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanafolders.yaml
index cc942ce44..84492be82 100644
--- a/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanafolders.yaml
+++ b/deploy/helm/grafana-operator/crds/grafana.integreatly.org_grafanafolders.yaml
@@ -75,6 +75,9 @@ spec:
type: boolean
hash:
type: string
+ lastResync:
+ format: date-time
+ type: string
type: object
type: object
served: true
diff --git a/deploy/kustomize/base/crds.yaml b/deploy/kustomize/base/crds.yaml
index 8c65ad0b3..c1f026bcd 100644
--- a/deploy/kustomize/base/crds.yaml
+++ b/deploy/kustomize/base/crds.yaml
@@ -639,6 +639,10 @@ spec:
of cluster Important: Run "make" to regenerate code after modifying
this file'
type: string
+ lastResync:
+ description: Last time the folder was resynced
+ format: date-time
+ type: string
type: object
type: object
served: true
diff --git a/docs/docs/api.md b/docs/docs/api.md
index e1f1a05b2..ffbb618bf 100644
--- a/docs/docs/api.md
+++ b/docs/docs/api.md
@@ -1506,6 +1506,15 @@ GrafanaFolderStatus defines the observed state of GrafanaFolder
INSERT ADDITIONAL STATUS FIELD - define observed state of cluster Important: Run "make" to regenerate code after modifying this file