-
Notifications
You must be signed in to change notification settings - Fork 190
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
WIP: Adding CRD validation #888
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,9 @@ const ( | |
// GitRepositorySpec defines the desired state of a Git repository. | ||
type GitRepositorySpec struct { | ||
// The repository URL, can be a HTTP/S or SSH address. | ||
|
||
// +kubebuilder:validation:MinLength=1 | ||
// +kubebuilder:validation:MaxLength=253 | ||
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$" | ||
// +required | ||
URL string `json:"url"` | ||
|
@@ -70,6 +73,8 @@ type GitRepositorySpec struct { | |
// Ignore overrides the set of excluded patterns in the .sourceignore format | ||
// (which is the same as .gitignore). If not provided, a default will be used, | ||
// consult the documentation for your version to find out what those are. | ||
// +kubebuilder:validation:MaxLength=63 | ||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||
// +optional | ||
Ignore *string `json:"ignore,omitempty"` | ||
|
||
|
@@ -115,29 +120,41 @@ type GitRepositoryInclude struct { | |
GitRepositoryRef meta.LocalObjectReference `json:"repository"` | ||
|
||
// The path to copy contents from, defaults to the root directory. | ||
// +kubebuilder:validation:MaxLength=253 | ||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||
// +optional | ||
FromPath string `json:"fromPath"` | ||
|
||
// The path to copy contents to, defaults to the name of the source ref. | ||
// +kubebuilder:validation:MaxLength=253 | ||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||
// +optional | ||
ToPath string `json:"toPath"` | ||
} | ||
|
||
// GitRepositoryRef defines the Git ref used for pull and checkout operations. | ||
type GitRepositoryRef struct { | ||
// The Git branch to checkout, defaults to master. | ||
// +kubebuilder:validation:MaxLength=253 | ||
// +kubebuilder:validation:Pattern=`^[\-._a-zA-Z0-9]+$` | ||
// +optional | ||
Branch string `json:"branch,omitempty"` | ||
|
||
// The Git tag to checkout, takes precedence over Branch. | ||
// +kubebuilder:validation:MaxLength=253 | ||
// +kubebuilder:validation:Pattern=`^[\-._0-9]+$` | ||
// +optional | ||
Tag string `json:"tag,omitempty"` | ||
|
||
// The Git tag semver expression, takes precedence over Tag. | ||
// +kubebuilder:validation:MaxLength=253 | ||
// +kubebuilder:validation:Pattern=`^[\-._0-9]+$` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A semver expression usually contains special characters and alpha numeric ones, see https://github.com/Masterminds/semver |
||
// +optional | ||
SemVer string `json:"semver,omitempty"` | ||
|
||
// The Git commit SHA to checkout, if specified Tag filters will be ignored. | ||
// +kubebuilder:validation:MaxLength=253 | ||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$ | ||
// +optional | ||
Commit string `json:"commit,omitempty"` | ||
} | ||
|
@@ -164,6 +181,8 @@ type GitRepositoryStatus struct { | |
|
||
// URL is the download link for the artifact output of the last repository | ||
// sync. | ||
// +kubebuilder:validation:MaxLength=253 | ||
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$" | ||
// +optional | ||
URL string `json:"url,omitempty"` | ||
|
||
|
@@ -279,6 +298,7 @@ type GitRepository struct { | |
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
// +kubebuilder:validation:required | ||
Spec GitRepositorySpec `json:"spec,omitempty"` | ||
// +kubebuilder:default={"observedGeneration":-1} | ||
Status GitRepositoryStatus `json:"status,omitempty"` | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -30,12 +30,17 @@ const HelmChartKind = "HelmChart" | |||||
// HelmChartSpec defines the desired state of a Helm chart. | ||||||
type HelmChartSpec struct { | ||||||
// The name or path the Helm chart is available at in the SourceRef. | ||||||
// +kubebuilder:validation:MinLength=1 | ||||||
// +kubebuilder:validation:MaxLength=253 | ||||||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||||||
// +required | ||||||
Chart string `json:"chart"` | ||||||
|
||||||
// The chart version semver expression, ignored for charts from GitRepository | ||||||
// and Bucket sources. Defaults to latest when omitted. | ||||||
// +kubebuilder:default:=* | ||||||
// +kubebuilder:validation:MaxLength=63 | ||||||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||||||
// +optional | ||||||
Version string `json:"version,omitempty"` | ||||||
|
||||||
|
@@ -92,6 +97,9 @@ const ( | |||||
// the typed referenced object at namespace level. | ||||||
type LocalHelmChartSourceReference struct { | ||||||
// APIVersion of the referent. | ||||||
// +kubebuilder:validation:MaxLength=63 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Please change this in all objects with APIVersion fields. |
||||||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||||||
|
||||||
// +optional | ||||||
APIVersion string `json:"apiVersion,omitempty"` | ||||||
|
||||||
|
@@ -102,6 +110,9 @@ type LocalHelmChartSourceReference struct { | |||||
Kind string `json:"kind"` | ||||||
|
||||||
// Name of the referent. | ||||||
// +kubebuilder:validation:MinLength=1 | ||||||
// +kubebuilder:validation:MaxLength=63 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Kubernetes object name max length is 253, please use this value for all fields that references a Kube object by name. |
||||||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||||||
// +required | ||||||
Name string `json:"name"` | ||||||
} | ||||||
|
@@ -248,6 +259,7 @@ type HelmChart struct { | |||||
metav1.TypeMeta `json:",inline"` | ||||||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||||||
|
||||||
// +kubebuilder:validation:required | ||||||
Spec HelmChartSpec `json:"spec,omitempty"` | ||||||
// +kubebuilder:default={"observedGeneration":-1} | ||||||
Status HelmChartStatus `json:"status,omitempty"` | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,21 +28,31 @@ type Artifact struct { | |
// Path is the relative file path of the Artifact. It can be used to locate | ||
// the file in the root of the Artifact storage on the local file system of | ||
// the controller managing the Source. | ||
// +kubebuilder:validation:MinLength=1 | ||
// +kubebuilder:validation:MaxLength=253 | ||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||
// +required | ||
Path string `json:"path"` | ||
|
||
// URL is the HTTP address of the Artifact as exposed by the controller | ||
// managing the Source. It can be used to retrieve the Artifact for | ||
// consumption, e.g. by another controller applying the Artifact contents. | ||
// +kubebuilder:validation:MinLength=1 | ||
// +kubebuilder:validation:MaxLength=253 | ||
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$" | ||
// +required | ||
URL string `json:"url"` | ||
|
||
// Revision is a human-readable identifier traceable in the origin source | ||
// system. It can be a Git commit SHA, Git tag, a Helm chart version, etc. | ||
// +kubebuilder:validation:MaxLength=63 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks Flux, we use SHA256 for OCI and for Git we append the brach name to the Git SHA. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||
// +optional | ||
Revision string `json:"revision"` | ||
|
||
// Checksum is the SHA256 checksum of the Artifact file. | ||
// +kubebuilder:validation:MaxLength=250 | ||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||
// +optional | ||
Checksum string `json:"checksum"` | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -48,6 +48,8 @@ const ( | |||||
// Artifact for a Git repository. | ||||||
type GitRepositorySpec struct { | ||||||
// URL specifies the Git repository URL, it can be an HTTP/S or SSH address. | ||||||
// +kubebuilder:validation:MinLength=1 | ||||||
// +kubebuilder:validation:MaxLength=253 | ||||||
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$" | ||||||
// +required | ||||||
URL string `json:"url"` | ||||||
|
@@ -83,6 +85,8 @@ type GitRepositorySpec struct { | |||||
// Ignore overrides the set of excluded patterns in the .sourceignore format | ||||||
// (which is the same as .gitignore). If not provided, a default will be used, | ||||||
// consult the documentation for your version to find out what those are. | ||||||
// +kubebuilder:validation:MaxLength=253 | ||||||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||||||
// +optional | ||||||
Ignore *string `json:"ignore,omitempty"` | ||||||
|
||||||
|
@@ -124,11 +128,15 @@ type GitRepositoryInclude struct { | |||||
|
||||||
// FromPath specifies the path to copy contents from, defaults to the root | ||||||
// of the Artifact. | ||||||
// +kubebuilder:validation:MaxLength=253 | ||||||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||||||
// +optional | ||||||
FromPath string `json:"fromPath"` | ||||||
|
||||||
// ToPath specifies the path to copy contents to, defaults to the name of | ||||||
// the GitRepositoryRef. | ||||||
// +kubebuilder:validation:MaxLength=253 | ||||||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||||||
// +optional | ||||||
ToPath string `json:"toPath"` | ||||||
} | ||||||
|
@@ -153,14 +161,20 @@ type GitRepositoryRef struct { | |||||
// | ||||||
// When GitRepositorySpec.GitImplementation is set to 'go-git', a shallow | ||||||
// clone of the specified branch is performed. | ||||||
// +kubebuilder:validation:MaxLength=63 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||||||
// +optional | ||||||
Branch string `json:"branch,omitempty"` | ||||||
|
||||||
// Tag to check out, takes precedence over Branch. | ||||||
// +kubebuilder:validation:MaxLength=253 | ||||||
// +kubebuilder:validation:Pattern=`^[\-._0-9]+$` | ||||||
// +optional | ||||||
Tag string `json:"tag,omitempty"` | ||||||
|
||||||
// SemVer tag expression to check out, takes precedence over Tag. | ||||||
// +kubebuilder:validation:MaxLength=63 | ||||||
// +kubebuilder:validation:Pattern=`^[\-._0-9]+$` | ||||||
// +optional | ||||||
SemVer string `json:"semver,omitempty"` | ||||||
|
||||||
|
@@ -169,6 +183,8 @@ type GitRepositoryRef struct { | |||||
// When GitRepositorySpec.GitImplementation is set to 'go-git', this can be | ||||||
// combined with Branch to shallow clone the branch, in which the commit is | ||||||
// expected to exist. | ||||||
// +kubebuilder:validation:MaxLength=250 | ||||||
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9_\-.\\\/]|\[[0-9]{1,5}\])+$` | ||||||
// +optional | ||||||
Commit string `json:"commit,omitempty"` | ||||||
} | ||||||
|
@@ -199,6 +215,8 @@ type GitRepositoryStatus struct { | |||||
// URL is the dynamic fetch link for the latest Artifact. | ||||||
// It is provided on a "best effort" basis, and using the precise | ||||||
// GitRepositoryStatus.Artifact data is recommended. | ||||||
// +kubebuilder:validation:MaxLength=253 | ||||||
// +kubebuilder:validation:Pattern="^(http|https|ssh)://.*$" | ||||||
// +optional | ||||||
URL string `json:"url,omitempty"` | ||||||
|
||||||
|
@@ -274,6 +292,7 @@ type GitRepository struct { | |||||
metav1.TypeMeta `json:",inline"` | ||||||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||||||
|
||||||
// +kubebuilder:validation:required | ||||||
Spec GitRepositorySpec `json:"spec,omitempty"` | ||||||
// +kubebuilder:default={"observedGeneration":-1} | ||||||
Status GitRepositoryStatus `json:"status,omitempty"` | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ignore field can have thousands of lines with special characters and UTF8, think of file paths written in Chinese.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Should the validation be removed from this
Igonore
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation pattern yes, the max length should be less than etcd entry max size (1MB).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that be 5000? (<5120)