-
Notifications
You must be signed in to change notification settings - Fork 11
feat: initial catalog #363
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| /* | ||
| Copyright 2025. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // ConcurrencyPolicy describes how the schedule treats overlapping builds. | ||
| // +kubebuilder:validation:Enum=Allow;Forbid;Replace | ||
| type ConcurrencyPolicy string | ||
|
|
||
| // ConcurrencyPolicy values. | ||
| const ( | ||
| AllowConcurrent ConcurrencyPolicy = "Allow" | ||
| ForbidConcurrent ConcurrencyPolicy = "Forbid" | ||
| ReplaceConcurrent ConcurrencyPolicy = "Replace" | ||
| ) | ||
|
|
||
| // ScheduledImageBuildSpec defines the desired state of ScheduledImageBuild | ||
| // +kubebuilder:validation:XValidation:rule="!has(self.matrix) || !has(self.matrix.distros) || size(self.matrix.distros) == 0 || has(self.imageBuildTemplate.spec.aib)",message="matrix distros requires aib in imageBuildTemplate" | ||
| // +kubebuilder:validation:XValidation:rule="!has(self.matrix) || !has(self.matrix.targets) || size(self.matrix.targets) == 0 || has(self.imageBuildTemplate.spec.aib)",message="matrix targets requires aib in imageBuildTemplate" | ||
| type ScheduledImageBuildSpec struct { | ||
| // Schedule is a cron expression defining when builds should run (5-field standard format). | ||
| // Examples: "0 2 * * *" (daily at 2am), "0 */6 * * *" (every 6 hours) | ||
| // +kubebuilder:validation:Required | ||
| // +kubebuilder:validation:MinLength=9 | ||
| // +kubebuilder:validation:Pattern=`^([-0-9*/,]+\s+){4}[-0-9*/,]+$` | ||
| Schedule string `json:"schedule"` | ||
|
|
||
| // Suspend tells the controller to suspend subsequent executions. | ||
| // Existing running builds will not be affected. | ||
| // +optional | ||
| Suspend *bool `json:"suspend,omitempty"` | ||
|
|
||
| // ConcurrencyPolicy specifies how to treat concurrent builds. | ||
| // +kubebuilder:default=Forbid | ||
| // +optional | ||
| ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy,omitempty"` | ||
|
|
||
| // StartingDeadlineSeconds is the deadline in seconds for starting a build | ||
| // if it misses its scheduled time. Missed builds beyond this window are skipped. | ||
| // +kubebuilder:validation:Minimum=0 | ||
| // +optional | ||
| StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds,omitempty"` | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // SuccessfulBuildsHistoryLimit is the number of successful finished builds to retain. | ||
| // +kubebuilder:default=3 | ||
| // +kubebuilder:validation:Minimum=0 | ||
| // +optional | ||
| SuccessfulBuildsHistoryLimit *int32 `json:"successfulBuildsHistoryLimit,omitempty"` | ||
|
|
||
| // FailedBuildsHistoryLimit is the number of failed finished builds to retain. | ||
| // +kubebuilder:default=1 | ||
| // +kubebuilder:validation:Minimum=0 | ||
| // +optional | ||
| FailedBuildsHistoryLimit *int32 `json:"failedBuildsHistoryLimit,omitempty"` | ||
|
|
||
| // ImageBuildTemplate is the template for creating ImageBuild CRs. | ||
| // +kubebuilder:validation:Required | ||
| ImageBuildTemplate ImageBuildTemplateSpec `json:"imageBuildTemplate"` | ||
|
|
||
| // Matrix defines a build matrix that creates multiple ImageBuilds per schedule tick. | ||
| // Each tick creates one ImageBuild for each combination of the specified dimensions, | ||
| // overriding the corresponding fields in the imageBuildTemplate. | ||
| // +optional | ||
| Matrix *BuildMatrix `json:"matrix,omitempty"` | ||
|
|
||
| // PublishToCatalog configures automatic publishing of completed builds to the catalog. | ||
| // +optional | ||
| PublishToCatalog *PublishToCatalogSpec `json:"publishToCatalog,omitempty"` | ||
| } | ||
|
|
||
| // ImageBuildTemplateSpec describes the ImageBuild that will be created on each schedule tick. | ||
| type ImageBuildTemplateSpec struct { | ||
| // Metadata contains labels and annotations to apply to created ImageBuilds. | ||
| // +optional | ||
| Metadata ScheduledBuildMetadata `json:"metadata,omitempty"` | ||
|
|
||
| // Spec is the ImageBuildSpec used as the template for child ImageBuilds. | ||
| // +kubebuilder:validation:Required | ||
| Spec ImageBuildSpec `json:"spec"` | ||
| } | ||
|
|
||
| // ScheduledBuildMetadata contains metadata to apply to child ImageBuilds. | ||
| type ScheduledBuildMetadata struct { | ||
| // Labels to set on created ImageBuilds. | ||
| // +optional | ||
| Labels map[string]string `json:"labels,omitempty"` | ||
|
|
||
| // Annotations to set on created ImageBuilds. | ||
| // +optional | ||
| Annotations map[string]string `json:"annotations,omitempty"` | ||
| } | ||
|
|
||
| // BuildMatrix defines multiple configurations to build on each schedule tick. | ||
| // Each dimension list overrides the corresponding scalar field in the template spec. | ||
| // The cross-product of all dimensions determines how many ImageBuilds are created per tick. | ||
| type BuildMatrix struct { | ||
| // Architectures lists target architectures to build for. | ||
| // Each value overrides imageBuildTemplate.spec.architecture. | ||
| // +optional | ||
| // +kubebuilder:validation:MaxItems=4 | ||
| Architectures []string `json:"architectures,omitempty"` | ||
|
|
||
| // Distros lists distributions to build for. | ||
| // Each value overrides imageBuildTemplate.spec.aib.distro. | ||
| // +optional | ||
| // +kubebuilder:validation:MaxItems=4 | ||
| Distros []string `json:"distros,omitempty"` | ||
|
|
||
| // Targets lists hardware targets to build for. | ||
| // Each value overrides imageBuildTemplate.spec.aib.target. | ||
| // +optional | ||
| // +kubebuilder:validation:MaxItems=4 | ||
| Targets []string `json:"targets,omitempty"` | ||
| } | ||
|
|
||
| // PublishToCatalogSpec configures automatic catalog publishing for completed builds. | ||
| type PublishToCatalogSpec struct { | ||
| // Enabled controls whether completed builds are automatically published to the catalog. | ||
| Enabled bool `json:"enabled"` | ||
|
|
||
| // Tags are category tags to apply to the CatalogImage. | ||
| // +optional | ||
| Tags []string `json:"tags,omitempty"` | ||
|
|
||
| // AuthSecretRef references a secret containing registry credentials | ||
| // for verifying the published image. | ||
| // +optional | ||
| AuthSecretRef *AuthSecretReference `json:"authSecretRef,omitempty"` | ||
| } | ||
|
|
||
| // ScheduledImageBuildPhase represents the current state of the schedule. | ||
| // +kubebuilder:validation:Enum=Active;Suspended | ||
| type ScheduledImageBuildPhase string | ||
|
|
||
| // ScheduledImageBuildPhase values. | ||
| const ( | ||
| ScheduledImageBuildPhaseActive ScheduledImageBuildPhase = "Active" | ||
| ScheduledImageBuildPhaseSuspended ScheduledImageBuildPhase = "Suspended" | ||
| ) | ||
|
|
||
| // ScheduledImageBuildStatus defines the observed state of ScheduledImageBuild | ||
| type ScheduledImageBuildStatus struct { | ||
| // ObservedGeneration is the most recent generation observed by the controller. | ||
| // +optional | ||
| ObservedGeneration int64 `json:"observedGeneration,omitempty"` | ||
|
|
||
| // Phase represents the current state of the schedule. | ||
| // +optional | ||
| Phase ScheduledImageBuildPhase `json:"phase,omitempty"` | ||
|
|
||
| // LastScheduleTime is when the last build was created. | ||
| // +optional | ||
| LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"` | ||
|
|
||
| // LastSuccessfulTime is when the last build completed successfully. | ||
| // +optional | ||
| LastSuccessfulTime *metav1.Time `json:"lastSuccessfulTime,omitempty"` | ||
|
|
||
| // LastFailedTime is when the last build failed. | ||
| // +optional | ||
| LastFailedTime *metav1.Time `json:"lastFailedTime,omitempty"` | ||
|
|
||
| // Active is a list of currently running ImageBuild references. | ||
| // +optional | ||
| Active []corev1.ObjectReference `json:"active,omitempty"` | ||
|
|
||
| // Conditions represent the latest available observations. | ||
| // +optional | ||
| Conditions []metav1.Condition `json:"conditions,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
| // +kubebuilder:subresource:status | ||
| // +kubebuilder:printcolumn:name="Schedule",type=string,JSONPath=`.spec.schedule`,priority=0 | ||
| // +kubebuilder:printcolumn:name="Suspend",type=boolean,JSONPath=`.spec.suspend`,priority=0 | ||
| // +kubebuilder:printcolumn:name="Last Schedule",type=date,JSONPath=`.status.lastScheduleTime`,priority=0 | ||
| // +kubebuilder:printcolumn:name="Last Success",type=date,JSONPath=`.status.lastSuccessfulTime`,priority=0 | ||
| // +kubebuilder:printcolumn:name="Last Failure",type=date,JSONPath=`.status.lastFailedTime`,priority=0 | ||
| // +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,priority=0 | ||
|
|
||
| // ScheduledImageBuild defines a cron schedule for creating ImageBuild CRs | ||
| // with optional automatic publishing to the catalog. | ||
| type ScheduledImageBuild struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
|
||
| Spec ScheduledImageBuildSpec `json:"spec,omitempty"` | ||
| Status ScheduledImageBuildStatus `json:"status,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
| // ScheduledImageBuildList contains a list of ScheduledImageBuild | ||
| type ScheduledImageBuildList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitempty"` | ||
| Items []ScheduledImageBuild `json:"items"` | ||
| } | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(&ScheduledImageBuild{}, &ScheduledImageBuildList{}) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| "regexp" | ||
| "testing" | ||
| ) | ||
|
|
||
| // cronPattern mirrors the Pattern marker on ScheduledImageBuildSpec.Schedule. | ||
| var cronPattern = regexp.MustCompile(`^([-0-9*/,]+\s+){4}[-0-9*/,]+$`) | ||
|
|
||
| func TestScheduleCronPattern(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| input string | ||
| isValid bool | ||
| }{ | ||
| // valid expressions | ||
| {name: "daily at 2am", input: "0 2 * * *", isValid: true}, | ||
| {name: "every 6 hours", input: "0 */6 * * *", isValid: true}, | ||
| {name: "weekdays at midnight", input: "0 0 * * 1-5", isValid: true}, | ||
| {name: "every 15 minutes", input: "*/15 * * * *", isValid: true}, | ||
| {name: "specific day and time", input: "30 4 1,15 * *", isValid: true}, | ||
| {name: "complex range", input: "0 0-6/2 * * 0,6", isValid: true}, | ||
| {name: "all wildcards", input: "* * * * *", isValid: true}, | ||
| // invalid expressions | ||
| {name: "text input", input: "every tuesday", isValid: false}, | ||
| {name: "only 3 fields", input: "* * *", isValid: false}, | ||
| {name: "only 4 fields", input: "0 2 * *", isValid: false}, | ||
| {name: "6 fields", input: "0 2 * * * *", isValid: false}, | ||
| {name: "empty string", input: "", isValid: false}, | ||
| {name: "letters mixed", input: "0 2 * jan *", isValid: false}, | ||
| {name: "at-syntax", input: "@daily", isValid: false}, | ||
| {name: "natural language", input: "run at 2am", isValid: false}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := cronPattern.MatchString(tt.input) | ||
| if got != tt.isValid { | ||
| t.Errorf("cronPattern.MatchString(%q) = %v, want %v", tt.input, got, tt.isValid) | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: centos-automotive-suite/automotive-dev-operator
Length of output: 3360
🏁 Script executed:
Repository: centos-automotive-suite/automotive-dev-operator
Length of output: 35606
🏁 Script executed:
Repository: centos-automotive-suite/automotive-dev-operator
Length of output: 10818
🏁 Script executed:
Repository: centos-automotive-suite/automotive-dev-operator
Length of output: 9784
Use
pushSecretRefhere, notsecretRef. The push path passesImageBuildSpec.GetPushSecretRef()into the registry task, whilesecretRefis wired separately for registry-auth/flash OCI auth. These rules will reject specs that set onlypushSecretRefforexport.containerorexport.disk.oci, and they don’t enforce the credential the push flow actually uses.🤖 Prompt for AI Agents