Skip to content

Commit

Permalink
Chore(Internal): Switch all resources to use status struct with commo…
Browse files Browse the repository at this point in the history
…n fields (#1766)

* feat: Define GrafanaCommonStatus struct

* refactor: Embed GrafanaCommonStatus into all crds

* docs: Generate
  • Loading branch information
Baarsgaard authored Dec 21, 2024
1 parent fba3d9d commit 2cb3951
Show file tree
Hide file tree
Showing 22 changed files with 437 additions and 199 deletions.
10 changes: 10 additions & 0 deletions api/v1beta1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// WARN Run `make` on all file changes

type ValueFrom struct {
TargetPath string `json:"targetPath"`
ValueFrom ValueFromSource `json:"valueFrom"`
Expand Down Expand Up @@ -49,3 +51,11 @@ type CommonResource interface {
AllowCrossNamespace() bool
ResyncPeriodHasElapsed() bool
}

// The most recent observed state of a Grafana resource
type GrafanaCommonStatus struct {
// Results when synchonizing resource with Grafana instances
Conditions []metav1.Condition `json:"conditions,omitempty"`
// Last time the resource was synchronized with Grafana instances
LastResync metav1.Time `json:"lastResync,omitempty"`
}
9 changes: 2 additions & 7 deletions api/v1beta1/grafanaalertrulegroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ type AlertQuery struct {
RelativeTimeRange *models.RelativeTimeRange `json:"relativeTimeRange,omitempty"`
}

// GrafanaAlertRuleGroupStatus defines the observed state of GrafanaAlertRuleGroup
type GrafanaAlertRuleGroupStatus struct {
Conditions []metav1.Condition `json:"conditions"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand All @@ -131,8 +126,8 @@ type GrafanaAlertRuleGroup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec GrafanaAlertRuleGroupSpec `json:"spec,omitempty"`
Status GrafanaAlertRuleGroupStatus `json:"status,omitempty"`
Spec GrafanaAlertRuleGroupSpec `json:"spec,omitempty"`
Status GrafanaCommonStatus `json:"status,omitempty"`
}

// GroupName returns the name of alert rule group.
Expand Down
11 changes: 2 additions & 9 deletions api/v1beta1/grafanacontactpoint_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,6 @@ type GrafanaContactPointSpec struct {
Type string `json:"type,omitempty"`
}

// GrafanaContactPointStatus defines the observed state of GrafanaContactPoint
type GrafanaContactPointStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Conditions []metav1.Condition `json:"conditions"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand All @@ -65,8 +58,8 @@ type GrafanaContactPoint struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec GrafanaContactPointSpec `json:"spec,omitempty"`
Status GrafanaContactPointStatus `json:"status,omitempty"`
Spec GrafanaContactPointSpec `json:"spec,omitempty"`
Status GrafanaCommonStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
10 changes: 4 additions & 6 deletions api/v1beta1/grafanadashboard_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,15 @@ type GrafanaComDashboardReference struct {

// GrafanaDashboardStatus defines the observed state of GrafanaDashboard
type GrafanaDashboardStatus struct {
GrafanaCommonStatus `json:",inline"`

ContentCache []byte `json:"contentCache,omitempty"`
ContentTimestamp metav1.Time `json:"contentTimestamp,omitempty"`
ContentUrl string `json:"contentUrl,omitempty"`
Hash string `json:"hash,omitempty"`
// The dashboard instanceSelector can't find matching grafana instances
NoMatchingInstances bool `json:"NoMatchingInstances,omitempty"`
// Last time the dashboard was resynced
LastResync metav1.Time `json:"lastResync,omitempty"`
UID string `json:"uid,omitempty"`

Conditions []metav1.Condition `json:"conditions,omitempty"`
NoMatchingInstances bool `json:"NoMatchingInstances,omitempty"`
UID string `json:"uid,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
8 changes: 4 additions & 4 deletions api/v1beta1/grafanadatasource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ type GrafanaDatasourceSpec struct {

// GrafanaDatasourceStatus defines the observed state of GrafanaDatasource
type GrafanaDatasourceStatus struct {
GrafanaCommonStatus `json:",inline"`

Hash string `json:"hash,omitempty"`
LastMessage string `json:"lastMessage,omitempty"`
// The datasource instanceSelector can't find matching grafana instances
NoMatchingInstances bool `json:"NoMatchingInstances,omitempty"`
// Last time the datasource was resynced
LastResync metav1.Time `json:"lastResync,omitempty"`
UID string `json:"uid,omitempty"`
NoMatchingInstances bool `json:"NoMatchingInstances,omitempty"`
UID string `json:"uid,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
7 changes: 2 additions & 5 deletions api/v1beta1/grafanafolder_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,11 @@ type GrafanaFolderSpec struct {

// GrafanaFolderStatus defines the observed state of GrafanaFolder
type GrafanaFolderStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
GrafanaCommonStatus `json:",inline"`

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"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
9 changes: 2 additions & 7 deletions api/v1beta1/grafananotificationpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ func (r *Route) ToModelRoute() *models.Route {
return out
}

// GrafanaNotificationPolicyStatus defines the observed state of GrafanaNotificationPolicy
type GrafanaNotificationPolicyStatus struct {
Conditions []metav1.Condition `json:"conditions"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand All @@ -140,8 +135,8 @@ type GrafanaNotificationPolicy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec GrafanaNotificationPolicySpec `json:"spec,omitempty"`
Status GrafanaNotificationPolicyStatus `json:"status,omitempty"`
Spec GrafanaNotificationPolicySpec `json:"spec,omitempty"`
Status GrafanaCommonStatus `json:"status,omitempty"`
}

func (np *GrafanaNotificationPolicy) NamespacedResource() string {
Expand Down
109 changes: 26 additions & 83 deletions api/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ spec:
rule: ((!has(oldSelf.editable) && !has(self.editable)) || (has(oldSelf.editable)
&& has(self.editable)))
status:
description: GrafanaAlertRuleGroupStatus defines the observed state of
GrafanaAlertRuleGroup
description: The most recent observed state of a Grafana resource
properties:
conditions:
description: Results when synchonizing resource with Grafana instances
items:
description: Condition contains details for one aspect of the current
state of this API Resource.
Expand Down Expand Up @@ -307,8 +307,11 @@ spec:
- type
type: object
type: array
required:
- conditions
lastResync:
description: Last time the resource was synchronized with Grafana
instances
format: date-time
type: string
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,10 @@ spec:
rule: ((!has(oldSelf.uid) && !has(self.uid)) || (has(oldSelf.uid) &&
has(self.uid)))
status:
description: GrafanaContactPointStatus defines the observed state of GrafanaContactPoint
description: The most recent observed state of a Grafana resource
properties:
conditions:
description: |-
INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Important: Run "make" to regenerate code after modifying this file
description: Results when synchonizing resource with Grafana instances
items:
description: Condition contains details for one aspect of the current
state of this API Resource.
Expand Down Expand Up @@ -278,8 +276,11 @@ spec:
- type
type: object
type: array
required:
- conditions
lastResync:
description: Last time the resource was synchronized with Grafana
instances
format: date-time
type: string
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ spec:
instances
type: boolean
conditions:
description: Results when synchonizing resource with Grafana instances
items:
description: Condition contains details for one aspect of the current
state of this API Resource.
Expand Down Expand Up @@ -483,7 +484,8 @@ spec:
hash:
type: string
lastResync:
description: Last time the dashboard was resynced
description: Last time the resource was synchronized with Grafana
instances
format: date-time
type: string
uid:
Expand Down
Loading

0 comments on commit 2cb3951

Please sign in to comment.