Skip to content

Commit 0fc62ab

Browse files
authored
fix: apply duration validation to all resync periods (#1505)
1 parent e0d3ad8 commit 0fc62ab

23 files changed

+8166
-12316
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ endif
9797
manifests: yq controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
9898
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook paths="./..." crd:maxDescLen=0,generateEmbeddedObjectMeta=false output:crd:artifacts:config=config/crd/bases
9999
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook paths="./..." crd:maxDescLen=0,generateEmbeddedObjectMeta=false output:crd:artifacts:config=deploy/helm/grafana-operator/crds
100+
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook paths="./..." crd output:crd:artifacts:config=config/
100101
yq -i '(select(.kind == "Deployment") | .spec.template.spec.containers[0].env[] | select (.name == "RELATED_IMAGE_GRAFANA")).value="$(GRAFANA_IMAGE):$(GRAFANA_VERSION)"' config/manager/manager.yaml
101102

102103
.PHONY: kustomize-crd
103104
kustomize-crd: kustomize manifests
104-
$(KUSTOMIZE) build config/ -o deploy/kustomize/base/crds.yaml
105+
$(KUSTOMIZE) build config/crd -o deploy/kustomize/base/crds.yaml
105106

106107
# Generate API reference documentation
107108
api-docs: gen-crd-api-reference-docs kustomize

api/v1beta1/grafanadashboard_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ type GrafanaDashboardSpec struct {
9494

9595
// how often the dashboard is refreshed, defaults to 5m if not set
9696
// +optional
97+
// +kubebuilder:validation:Type=string
98+
// +kubebuilder:validation:Format=duration
99+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
100+
// +kubebuilder:default="5m"
97101
ResyncPeriod string `json:"resyncPeriod,omitempty"`
98102

99103
// maps required data sources to existing ones

api/v1beta1/grafanadatasource_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ type GrafanaDatasourceSpec struct {
7575

7676
// how often the datasource is refreshed, defaults to 5m if not set
7777
// +optional
78+
// +kubebuilder:validation:Type=string
79+
// +kubebuilder:validation:Format=duration
80+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
81+
// +kubebuilder:default="5m"
7882
ResyncPeriod string `json:"resyncPeriod,omitempty"`
7983

8084
// allow to import this resources from an operator in a different namespace

api/v1beta1/grafanafolder_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ type GrafanaFolderSpec struct {
4545

4646
// how often the folder is synced, defaults to 5m if not set
4747
// +optional
48+
// +kubebuilder:validation:Type=string
49+
// +kubebuilder:validation:Format=duration
50+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
51+
// +kubebuilder:default="5m"
4852
ResyncPeriod string `json:"resyncPeriod,omitempty"`
4953
}
5054

bundle/manifests/grafana-operator.clusterserviceversion.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ metadata:
210210
capabilities: Basic Install
211211
categories: Monitoring
212212
containerImage: ghcr.io/grafana/grafana-operator@sha256:97561cef949b58f55ec67d133c02ac205e2ec3fb77388aeb868dacfcebad0752
213-
createdAt: "2024-04-19T08:44:59Z"
213+
createdAt: "2024-04-23T12:57:39Z"
214214
description: Deploys and manages Grafana instances, dashboards and data sources
215215
operators.operatorframework.io/builder: operator-sdk-v1.32.0
216216
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3

bundle/manifests/grafana.integreatly.org_grafanadashboards.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ spec:
202202
type: object
203203
type: array
204204
resyncPeriod:
205+
default: 5m
206+
format: duration
207+
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
205208
type: string
206209
url:
207210
type: string

bundle/manifests/grafana.integreatly.org_grafanadatasources.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ spec:
110110
type: object
111111
type: array
112112
resyncPeriod:
113+
default: 5m
114+
format: duration
115+
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
113116
type: string
114117
valuesFrom:
115118
items:

bundle/manifests/grafana.integreatly.org_grafanafolders.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ spec:
6262
permissions:
6363
type: string
6464
resyncPeriod:
65+
default: 5m
66+
format: duration
67+
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
6568
type: string
6669
title:
6770
type: string

config/crd/bases/grafana.integreatly.org_grafanadashboards.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ spec:
202202
type: object
203203
type: array
204204
resyncPeriod:
205+
default: 5m
206+
format: duration
207+
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
205208
type: string
206209
url:
207210
type: string

config/crd/bases/grafana.integreatly.org_grafanadatasources.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ spec:
110110
type: object
111111
type: array
112112
resyncPeriod:
113+
default: 5m
114+
format: duration
115+
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
113116
type: string
114117
valuesFrom:
115118
items:

config/crd/bases/grafana.integreatly.org_grafanafolders.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ spec:
6262
permissions:
6363
type: string
6464
resyncPeriod:
65+
default: 5m
66+
format: duration
67+
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
6568
type: string
6669
title:
6770
type: string

config/grafana.integreatly.org_grafanaalertrulegroups.yaml

+62-56
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.12.0
6+
controller-gen.kubebuilder.io/version: v0.14.0
77
name: grafanaalertrulegroups.grafana.integreatly.org
88
spec:
99
group: grafana.integreatly.org
@@ -21,14 +21,19 @@ spec:
2121
API
2222
properties:
2323
apiVersion:
24-
description: 'APIVersion defines the versioned schema of this representation
25-
of an object. Servers should convert recognized schemas to the latest
26-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
24+
description: |-
25+
APIVersion defines the versioned schema of this representation of an object.
26+
Servers should convert recognized schemas to the latest internal value, and
27+
may reject unrecognized values.
28+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
2729
type: string
2830
kind:
29-
description: 'Kind is a string value representing the REST resource this
30-
object represents. Servers may infer this from the endpoint the client
31-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
31+
description: |-
32+
Kind is a string value representing the REST resource this object represents.
33+
Servers may infer this from the endpoint the client submits requests to.
34+
Cannot be updated.
35+
In CamelCase.
36+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
3237
type: string
3338
metadata:
3439
type: object
@@ -41,8 +46,9 @@ spec:
4146
description: Match GrafanaFolders CRs to infer the uid
4247
type: string
4348
folderUID:
44-
description: UID of the folder containing this rule group Overrides
45-
the FolderSelector
49+
description: |-
50+
UID of the folder containing this rule group
51+
Overrides the FolderSelector
4652
type: string
4753
instanceSelector:
4854
description: selects Grafanas for import
@@ -51,24 +57,24 @@ spec:
5157
description: matchExpressions is a list of label selector requirements.
5258
The requirements are ANDed.
5359
items:
54-
description: A label selector requirement is a selector that
55-
contains values, a key, and an operator that relates the key
56-
and values.
60+
description: |-
61+
A label selector requirement is a selector that contains values, a key, and an operator that
62+
relates the key and values.
5763
properties:
5864
key:
5965
description: key is the label key that the selector applies
6066
to.
6167
type: string
6268
operator:
63-
description: operator represents a key's relationship to
64-
a set of values. Valid operators are In, NotIn, Exists
65-
and DoesNotExist.
69+
description: |-
70+
operator represents a key's relationship to a set of values.
71+
Valid operators are In, NotIn, Exists and DoesNotExist.
6672
type: string
6773
values:
68-
description: values is an array of string values. If the
69-
operator is In or NotIn, the values array must be non-empty.
70-
If the operator is Exists or DoesNotExist, the values
71-
array must be empty. This array is replaced during a strategic
74+
description: |-
75+
values is an array of string values. If the operator is In or NotIn,
76+
the values array must be non-empty. If the operator is Exists or DoesNotExist,
77+
the values array must be empty. This array is replaced during a strategic
7278
merge patch.
7379
items:
7480
type: string
@@ -81,11 +87,10 @@ spec:
8187
matchLabels:
8288
additionalProperties:
8389
type: string
84-
description: matchLabels is a map of {key,value} pairs. A single
85-
{key,value} in the matchLabels map is equivalent to an element
86-
of matchExpressions, whose key field is "key", the operator
87-
is "In", and the values array contains only "value". The requirements
88-
are ANDed.
90+
description: |-
91+
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
92+
map is equivalent to an element of matchExpressions, whose key field is "key", the
93+
operator is "In", and the values array contains only "value". The requirements are ANDed.
8994
type: object
9095
type: object
9196
x-kubernetes-map-type: atomic
@@ -122,9 +127,9 @@ spec:
122127
above properties as well as custom properties.
123128
x-kubernetes-preserve-unknown-fields: true
124129
queryType:
125-
description: QueryType is an optional identifier for the
126-
type of query. It can be used to distinguish different
127-
types of queries.
130+
description: |-
131+
QueryType is an optional identifier for the type of query.
132+
It can be used to distinguish different types of queries.
128133
type: string
129134
refId:
130135
description: RefID is the unique identifier of the query,
@@ -200,42 +205,42 @@ spec:
200205
conditions:
201206
items:
202207
description: "Condition contains details for one aspect of the current
203-
state of this API Resource. --- This struct is intended for direct
204-
use as an array at the field path .status.conditions. For example,
205-
\n type FooStatus struct{ // Represents the observations of a
206-
foo's current state. // Known .status.conditions.type are: \"Available\",
207-
\"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge
208-
// +listType=map // +listMapKey=type Conditions []metav1.Condition
209-
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
210-
protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
208+
state of this API Resource.\n---\nThis struct is intended for
209+
direct use as an array at the field path .status.conditions. For
210+
example,\n\n\n\ttype FooStatus struct{\n\t // Represents the
211+
observations of a foo's current state.\n\t // Known .status.conditions.type
212+
are: \"Available\", \"Progressing\", and \"Degraded\"\n\t //
213+
+patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t
214+
\ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\"
215+
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t
216+
\ // other fields\n\t}"
211217
properties:
212218
lastTransitionTime:
213-
description: lastTransitionTime is the last time the condition
214-
transitioned from one status to another. This should be when
215-
the underlying condition changed. If that is not known, then
216-
using the time when the API field changed is acceptable.
219+
description: |-
220+
lastTransitionTime is the last time the condition transitioned from one status to another.
221+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
217222
format: date-time
218223
type: string
219224
message:
220-
description: message is a human readable message indicating
221-
details about the transition. This may be an empty string.
225+
description: |-
226+
message is a human readable message indicating details about the transition.
227+
This may be an empty string.
222228
maxLength: 32768
223229
type: string
224230
observedGeneration:
225-
description: observedGeneration represents the .metadata.generation
226-
that the condition was set based upon. For instance, if .metadata.generation
227-
is currently 12, but the .status.conditions[x].observedGeneration
228-
is 9, the condition is out of date with respect to the current
229-
state of the instance.
231+
description: |-
232+
observedGeneration represents the .metadata.generation that the condition was set based upon.
233+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
234+
with respect to the current state of the instance.
230235
format: int64
231236
minimum: 0
232237
type: integer
233238
reason:
234-
description: reason contains a programmatic identifier indicating
235-
the reason for the condition's last transition. Producers
236-
of specific condition types may define expected values and
237-
meanings for this field, and whether the values are considered
238-
a guaranteed API. The value should be a CamelCase string.
239+
description: |-
240+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
241+
Producers of specific condition types may define expected values and meanings for this field,
242+
and whether the values are considered a guaranteed API.
243+
The value should be a CamelCase string.
239244
This field may not be empty.
240245
maxLength: 1024
241246
minLength: 1
@@ -249,11 +254,12 @@ spec:
249254
- Unknown
250255
type: string
251256
type:
252-
description: type of condition in CamelCase or in foo.example.com/CamelCase.
253-
--- Many .condition.type values are consistent across resources
254-
like Available, but because arbitrary conditions can be useful
255-
(see .node.status.conditions), the ability to deconflict is
256-
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
257+
description: |-
258+
type of condition in CamelCase or in foo.example.com/CamelCase.
259+
---
260+
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
261+
useful (see .node.status.conditions), the ability to deconflict is important.
262+
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
257263
maxLength: 316
258264
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
259265
type: string

0 commit comments

Comments
 (0)