Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Update GrafanaDatasource reconcile loop #1826

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
19 changes: 14 additions & 5 deletions api/v1beta1/grafanadatasource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ type GrafanaDatasourceSpec struct {
type GrafanaDatasourceStatus struct {
GrafanaCommonStatus `json:",inline"`

Hash string `json:"hash,omitempty"`
Hash string `json:"hash,omitempty"`
// Deprecated: Check status.conditions or operator logs
LastMessage string `json:"lastMessage,omitempty"`
// The datasource instanceSelector can't find matching grafana instances
NoMatchingInstances bool `json:"NoMatchingInstances,omitempty"`
Expand Down Expand Up @@ -146,10 +147,6 @@ func (in *GrafanaDatasource) CustomUIDOrUID() string {
return string(in.ObjectMeta.UID)
}

func (in *GrafanaDatasource) IsAllowCrossNamespaceImport() bool {
return in.Spec.AllowCrossNamespaceImport
}

func (in *GrafanaDatasourceList) Find(namespace string, name string) *GrafanaDatasource {
for _, datasource := range in.Items {
if datasource.Namespace == namespace && datasource.Name == name {
Expand All @@ -159,6 +156,18 @@ func (in *GrafanaDatasourceList) Find(namespace string, name string) *GrafanaDat
return nil
}

func (in *GrafanaDatasource) MatchLabels() *metav1.LabelSelector {
return in.Spec.InstanceSelector
}

func (in *GrafanaDatasource) MatchNamespace() string {
return in.ObjectMeta.Namespace
}

func (in *GrafanaDatasource) AllowCrossNamespace() bool {
return in.Spec.AllowCrossNamespaceImport
}

func init() {
SchemeBuilder.Register(&GrafanaDatasource{}, &GrafanaDatasourceList{})
}
24 changes: 24 additions & 0 deletions api/v1beta1/grafanadatasource_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,27 @@ var _ = Describe("Datasource type", func() {
})
})
})

var _ = Describe("Fail on field behavior changes", func() {
emptyDatasource := &GrafanaDatasource{
TypeMeta: v1.TypeMeta{
APIVersion: APIVersion,
Kind: "GrafanaDatasource",
},
ObjectMeta: v1.ObjectMeta{
Name: "test-nil-datasource",
Namespace: "default",
},
Spec: GrafanaDatasourceSpec{
GrafanaCommonSpec: GrafanaCommonSpec{
InstanceSelector: &v1.LabelSelector{},
},
Datasource: nil,
},
}

ctx := context.Background()
It("Fails creating GrafanaDatasource with undefined spec.datasource", func() {
Expect(k8sClient.Create(ctx, emptyDatasource)).To(HaveOccurred())
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ spec:
hash:
type: string
lastMessage:
description: 'Deprecated: Check status.conditions or operator logs'
type: string
lastResync:
description: Last time the resource was synchronized with Grafana
Expand Down
Loading
Loading