Skip to content

Commit 62487db

Browse files
committed
WIP: Adding CRD validation
Signed-off-by: Santosh Kaluskar <[email protected]>
1 parent f97bbb6 commit 62487db

10 files changed

+118
-0
lines changed

api/v1beta1/bucket_types.go

+14
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,16 @@ type BucketSpec struct {
3838
Provider string `json:"provider,omitempty"`
3939

4040
// The bucket name.
41+
// +kubebuilder:validation:MinLength=1
42+
// +kubebuilder:validation:MaxLength=63
43+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
4144
// +required
4245
BucketName string `json:"bucketName"`
4346

4447
// The bucket endpoint address.
48+
// +kubebuilder:validation:MinLength=1
49+
// +kubebuilder:validation:MaxLength=250
50+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
4551
// +required
4652
Endpoint string `json:"endpoint"`
4753

@@ -50,6 +56,8 @@ type BucketSpec struct {
5056
Insecure bool `json:"insecure,omitempty"`
5157

5258
// The bucket region.
59+
// +kubebuilder:validation:MaxLength=63
60+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
5361
// +optional
5462
Region string `json:"region,omitempty"`
5563

@@ -70,6 +78,9 @@ type BucketSpec struct {
7078
// Ignore overrides the set of excluded patterns in the .sourceignore format
7179
// (which is the same as .gitignore). If not provided, a default will be used,
7280
// consult the documentation for your version to find out what those are.
81+
// +kubebuilder:validation:MinLength=1
82+
// +kubebuilder:validation:MaxLength=63
83+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
7384
// +optional
7485
Ignore *string `json:"ignore,omitempty"`
7586

@@ -99,6 +110,8 @@ type BucketStatus struct {
99110
Conditions []metav1.Condition `json:"conditions,omitempty"`
100111

101112
// URL is the download link for the artifact output of the last Bucket sync.
113+
// +kubebuilder:validation:MaxLength=250
114+
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$"
102115
// +optional
103116
URL string `json:"url,omitempty"`
104117

@@ -206,6 +219,7 @@ type Bucket struct {
206219
metav1.TypeMeta `json:",inline"`
207220
metav1.ObjectMeta `json:"metadata,omitempty"`
208221

222+
// +kubebuilder:validation:required
209223
Spec BucketSpec `json:"spec,omitempty"`
210224
// +kubebuilder:default={"observedGeneration":-1}
211225
Status BucketStatus `json:"status,omitempty"`

api/v1beta1/gitrepository_types.go

+20
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const (
3737
// GitRepositorySpec defines the desired state of a Git repository.
3838
type GitRepositorySpec struct {
3939
// The repository URL, can be a HTTP/S or SSH address.
40+
41+
// +kubebuilder:validation:MinLength=1
42+
// +kubebuilder:validation:MaxLength=253
4043
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$"
4144
// +required
4245
URL string `json:"url"`
@@ -70,6 +73,8 @@ type GitRepositorySpec struct {
7073
// Ignore overrides the set of excluded patterns in the .sourceignore format
7174
// (which is the same as .gitignore). If not provided, a default will be used,
7275
// consult the documentation for your version to find out what those are.
76+
// +kubebuilder:validation:MaxLength=63
77+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
7378
// +optional
7479
Ignore *string `json:"ignore,omitempty"`
7580

@@ -115,29 +120,41 @@ type GitRepositoryInclude struct {
115120
GitRepositoryRef meta.LocalObjectReference `json:"repository"`
116121

117122
// The path to copy contents from, defaults to the root directory.
123+
// +kubebuilder:validation:MaxLength=253
124+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
118125
// +optional
119126
FromPath string `json:"fromPath"`
120127

121128
// The path to copy contents to, defaults to the name of the source ref.
129+
// +kubebuilder:validation:MaxLength=253
130+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
122131
// +optional
123132
ToPath string `json:"toPath"`
124133
}
125134

126135
// GitRepositoryRef defines the Git ref used for pull and checkout operations.
127136
type GitRepositoryRef struct {
128137
// The Git branch to checkout, defaults to master.
138+
// +kubebuilder:validation:MaxLength=253
139+
// +kubebuilder:validation:Pattern=`^[\-._a-zA-Z0-9]+$`
129140
// +optional
130141
Branch string `json:"branch,omitempty"`
131142

132143
// The Git tag to checkout, takes precedence over Branch.
144+
// +kubebuilder:validation:MaxLength=253
145+
// +kubebuilder:validation:Pattern=`^[\-._0-9]+$`
133146
// +optional
134147
Tag string `json:"tag,omitempty"`
135148

136149
// The Git tag semver expression, takes precedence over Tag.
150+
// +kubebuilder:validation:MaxLength=253
151+
// +kubebuilder:validation:Pattern=`^[\-._0-9]+$`
137152
// +optional
138153
SemVer string `json:"semver,omitempty"`
139154

140155
// The Git commit SHA to checkout, if specified Tag filters will be ignored.
156+
// +kubebuilder:validation:MaxLength=253
157+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$
141158
// +optional
142159
Commit string `json:"commit,omitempty"`
143160
}
@@ -164,6 +181,8 @@ type GitRepositoryStatus struct {
164181

165182
// URL is the download link for the artifact output of the last repository
166183
// sync.
184+
// +kubebuilder:validation:MaxLength=253
185+
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$"
167186
// +optional
168187
URL string `json:"url,omitempty"`
169188

@@ -279,6 +298,7 @@ type GitRepository struct {
279298
metav1.TypeMeta `json:",inline"`
280299
metav1.ObjectMeta `json:"metadata,omitempty"`
281300

301+
// +kubebuilder:validation:required
282302
Spec GitRepositorySpec `json:"spec,omitempty"`
283303
// +kubebuilder:default={"observedGeneration":-1}
284304
Status GitRepositoryStatus `json:"status,omitempty"`

api/v1beta1/helmchart_types.go

+12
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ const HelmChartKind = "HelmChart"
3030
// HelmChartSpec defines the desired state of a Helm chart.
3131
type HelmChartSpec struct {
3232
// The name or path the Helm chart is available at in the SourceRef.
33+
// +kubebuilder:validation:MinLength=1
34+
// +kubebuilder:validation:MaxLength=253
35+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
3336
// +required
3437
Chart string `json:"chart"`
3538

3639
// The chart version semver expression, ignored for charts from GitRepository
3740
// and Bucket sources. Defaults to latest when omitted.
3841
// +kubebuilder:default:=*
42+
// +kubebuilder:validation:MaxLength=63
43+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
3944
// +optional
4045
Version string `json:"version,omitempty"`
4146

@@ -92,6 +97,9 @@ const (
9297
// the typed referenced object at namespace level.
9398
type LocalHelmChartSourceReference struct {
9499
// APIVersion of the referent.
100+
// +kubebuilder:validation:MaxLength=63
101+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
102+
95103
// +optional
96104
APIVersion string `json:"apiVersion,omitempty"`
97105

@@ -102,6 +110,9 @@ type LocalHelmChartSourceReference struct {
102110
Kind string `json:"kind"`
103111

104112
// Name of the referent.
113+
// +kubebuilder:validation:MinLength=1
114+
// +kubebuilder:validation:MaxLength=63
115+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
105116
// +required
106117
Name string `json:"name"`
107118
}
@@ -248,6 +259,7 @@ type HelmChart struct {
248259
metav1.TypeMeta `json:",inline"`
249260
metav1.ObjectMeta `json:"metadata,omitempty"`
250261

262+
// +kubebuilder:validation:required
251263
Spec HelmChartSpec `json:"spec,omitempty"`
252264
// +kubebuilder:default={"observedGeneration":-1}
253265
Status HelmChartStatus `json:"status,omitempty"`

api/v1beta1/helmrepository_types.go

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const (
3535
// HelmRepositorySpec defines the reference to a Helm repository.
3636
type HelmRepositorySpec struct {
3737
// The Helm repository URL, a valid URL contains at least a protocol and host.
38+
// +kubebuilder:validation:MinLength=1
39+
// +kubebuilder:validation:MaxLength=253
40+
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$"
3841
// +required
3942
URL string `json:"url"`
4043

@@ -85,6 +88,8 @@ type HelmRepositoryStatus struct {
8588
Conditions []metav1.Condition `json:"conditions,omitempty"`
8689

8790
// URL is the download link for the last index fetched.
91+
// +kubebuilder:validation:MaxLength=253
92+
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$"
8893
// +optional
8994
URL string `json:"url,omitempty"`
9095

@@ -195,6 +200,7 @@ type HelmRepository struct {
195200
metav1.TypeMeta `json:",inline"`
196201
metav1.ObjectMeta `json:"metadata,omitempty"`
197202

203+
// +kubebuilder:validation:required
198204
Spec HelmRepositorySpec `json:"spec,omitempty"`
199205
// +kubebuilder:default={"observedGeneration":-1}
200206
Status HelmRepositoryStatus `json:"status,omitempty"`

api/v1beta2/artifact_types.go

+10
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,31 @@ type Artifact struct {
2828
// Path is the relative file path of the Artifact. It can be used to locate
2929
// the file in the root of the Artifact storage on the local file system of
3030
// the controller managing the Source.
31+
// +kubebuilder:validation:MinLength=1
32+
// +kubebuilder:validation:MaxLength=253
33+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
3134
// +required
3235
Path string `json:"path"`
3336

3437
// URL is the HTTP address of the Artifact as exposed by the controller
3538
// managing the Source. It can be used to retrieve the Artifact for
3639
// consumption, e.g. by another controller applying the Artifact contents.
40+
// +kubebuilder:validation:MinLength=1
41+
// +kubebuilder:validation:MaxLength=253
42+
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$"
3743
// +required
3844
URL string `json:"url"`
3945

4046
// Revision is a human-readable identifier traceable in the origin source
4147
// system. It can be a Git commit SHA, Git tag, a Helm chart version, etc.
48+
// +kubebuilder:validation:MaxLength=63
49+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
4250
// +optional
4351
Revision string `json:"revision"`
4452

4553
// Checksum is the SHA256 checksum of the Artifact file.
54+
// +kubebuilder:validation:MaxLength=250
55+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
4656
// +optional
4757
Checksum string `json:"checksum"`
4858

api/v1beta2/bucket_types.go

+13
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@ type BucketSpec struct {
5757
Provider string `json:"provider,omitempty"`
5858

5959
// BucketName is the name of the object storage bucket.
60+
// +kubebuilder:validation:MinLength=1
61+
// +kubebuilder:validation:MaxLength=63
62+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
6063
// +required
6164
BucketName string `json:"bucketName"`
6265

6366
// Endpoint is the object storage address the BucketName is located at.
67+
// +kubebuilder:validation:MinLength=1
68+
// +kubebuilder:validation:MaxLength=250
69+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
6470
// +required
6571
Endpoint string `json:"endpoint"`
6672

@@ -69,6 +75,8 @@ type BucketSpec struct {
6975
Insecure bool `json:"insecure,omitempty"`
7076

7177
// Region of the Endpoint where the BucketName is located in.
78+
// +kubebuilder:validation:MaxLength=63
79+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
7280
// +optional
7381
Region string `json:"region,omitempty"`
7482

@@ -89,6 +97,8 @@ type BucketSpec struct {
8997
// Ignore overrides the set of excluded patterns in the .sourceignore format
9098
// (which is the same as .gitignore). If not provided, a default will be used,
9199
// consult the documentation for your version to find out what those are.
100+
// +kubebuilder:validation:MaxLength=63
101+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
92102
// +optional
93103
Ignore *string `json:"ignore,omitempty"`
94104

@@ -117,6 +127,8 @@ type BucketStatus struct {
117127
// URL is the dynamic fetch link for the latest Artifact.
118128
// It is provided on a "best effort" basis, and using the precise
119129
// BucketStatus.Artifact data is recommended.
130+
// +kubebuilder:validation:MaxLength=253
131+
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$"
120132
// +optional
121133
URL string `json:"url,omitempty"`
122134

@@ -172,6 +184,7 @@ type Bucket struct {
172184
metav1.TypeMeta `json:",inline"`
173185
metav1.ObjectMeta `json:"metadata,omitempty"`
174186

187+
// +kubebuilder:validation:required
175188
Spec BucketSpec `json:"spec,omitempty"`
176189
// +kubebuilder:default={"observedGeneration":-1}
177190
Status BucketStatus `json:"status,omitempty"`

api/v1beta2/gitrepository_types.go

+19
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const (
4848
// Artifact for a Git repository.
4949
type GitRepositorySpec struct {
5050
// URL specifies the Git repository URL, it can be an HTTP/S or SSH address.
51+
// +kubebuilder:validation:MinLength=1
52+
// +kubebuilder:validation:MaxLength=253
5153
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$"
5254
// +required
5355
URL string `json:"url"`
@@ -83,6 +85,8 @@ type GitRepositorySpec struct {
8385
// Ignore overrides the set of excluded patterns in the .sourceignore format
8486
// (which is the same as .gitignore). If not provided, a default will be used,
8587
// consult the documentation for your version to find out what those are.
88+
// +kubebuilder:validation:MaxLength=253
89+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
8690
// +optional
8791
Ignore *string `json:"ignore,omitempty"`
8892

@@ -124,11 +128,15 @@ type GitRepositoryInclude struct {
124128

125129
// FromPath specifies the path to copy contents from, defaults to the root
126130
// of the Artifact.
131+
// +kubebuilder:validation:MaxLength=253
132+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
127133
// +optional
128134
FromPath string `json:"fromPath"`
129135

130136
// ToPath specifies the path to copy contents to, defaults to the name of
131137
// the GitRepositoryRef.
138+
// +kubebuilder:validation:MaxLength=253
139+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
132140
// +optional
133141
ToPath string `json:"toPath"`
134142
}
@@ -153,14 +161,20 @@ type GitRepositoryRef struct {
153161
//
154162
// When GitRepositorySpec.GitImplementation is set to 'go-git', a shallow
155163
// clone of the specified branch is performed.
164+
// +kubebuilder:validation:MaxLength=63
165+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
156166
// +optional
157167
Branch string `json:"branch,omitempty"`
158168

159169
// Tag to check out, takes precedence over Branch.
170+
// +kubebuilder:validation:MaxLength=253
171+
// +kubebuilder:validation:Pattern=`^[\-._0-9]+$`
160172
// +optional
161173
Tag string `json:"tag,omitempty"`
162174

163175
// SemVer tag expression to check out, takes precedence over Tag.
176+
// +kubebuilder:validation:MaxLength=63
177+
// +kubebuilder:validation:Pattern=`^[\-._0-9]+$`
164178
// +optional
165179
SemVer string `json:"semver,omitempty"`
166180

@@ -169,6 +183,8 @@ type GitRepositoryRef struct {
169183
// When GitRepositorySpec.GitImplementation is set to 'go-git', this can be
170184
// combined with Branch to shallow clone the branch, in which the commit is
171185
// expected to exist.
186+
// +kubebuilder:validation:MaxLength=250
187+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$`
172188
// +optional
173189
Commit string `json:"commit,omitempty"`
174190
}
@@ -199,6 +215,8 @@ type GitRepositoryStatus struct {
199215
// URL is the dynamic fetch link for the latest Artifact.
200216
// It is provided on a "best effort" basis, and using the precise
201217
// GitRepositoryStatus.Artifact data is recommended.
218+
// +kubebuilder:validation:MaxLength=253
219+
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$"
202220
// +optional
203221
URL string `json:"url,omitempty"`
204222

@@ -274,6 +292,7 @@ type GitRepository struct {
274292
metav1.TypeMeta `json:",inline"`
275293
metav1.ObjectMeta `json:"metadata,omitempty"`
276294

295+
// +kubebuilder:validation:required
277296
Spec GitRepositorySpec `json:"spec,omitempty"`
278297
// +kubebuilder:default={"observedGeneration":-1}
279298
Status GitRepositoryStatus `json:"status,omitempty"`

0 commit comments

Comments
 (0)