Skip to content

Commit

Permalink
feat: add LastResync to GrafanaFolder
Browse files Browse the repository at this point in the history
  • Loading branch information
JameelB committed Jul 19, 2023
1 parent cd7ec75 commit 2108f95
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 3 deletions.
7 changes: 7 additions & 0 deletions api/v1beta1/grafanafolder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions config/crd/bases/grafana.integreatly.org_grafanafolders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ spec:
type: boolean
hash:
type: string
lastResync:
format: date-time
type: string
type: object
type: object
served: true
Expand Down
4 changes: 4 additions & 0 deletions config/grafana.integreatly.org_grafanafolders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions controllers/grafanafolder_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ spec:
type: boolean
hash:
type: string
lastResync:
format: date-time
type: string
type: object
type: object
served: true
Expand Down
4 changes: 4 additions & 0 deletions deploy/kustomize/base/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions docs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>lastResync</b></td>
<td>string</td>
<td>
Last time the folder was resynced<br/>
<br/>
<i>Format</i>: date-time<br/>
</td>
<td>false</td>
</tr></tbody>
</table>

Expand Down

0 comments on commit 2108f95

Please sign in to comment.