-
Notifications
You must be signed in to change notification settings - Fork 1
feat(api): Define TriageRun CRD #304
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
Open
amwarrier
wants to merge
6
commits into
main
Choose a base branch
from
codex/triage-run-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
373408f
feat(api): Define TriageRun CRD
amwarrier e81e9c2
feat(api): Support multiple TriageRun actions
amwarrier 58280cc
fix(api): use Kubernetes set semantics for actions
amwarrier 7314a42
chore(deps): tidy upgraded Go modules
amwarrier ac76a95
refactor(api): model TriageRun actions as references
amwarrier c22cc8f
fix(api): validate triage application references
amwarrier 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,219 @@ | ||
| /* | ||
| 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 v2 | ||
|
|
||
| import ( | ||
| corev1 "k8s.io/api/core/v1" | ||
| apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| // TriageRunPhase describes the execution lifecycle of a TriageRun. A | ||
| // Succeeded run means that the diagnostic command completed successfully; it | ||
| // does not mean that every diagnostic check passed. | ||
| // +kubebuilder:validation:Enum=Pending;Running;Succeeded;Failed | ||
| type TriageRunPhase string | ||
|
|
||
| const ( | ||
| TriageRunPhasePending TriageRunPhase = "Pending" | ||
| TriageRunPhaseRunning TriageRunPhase = "Running" | ||
| TriageRunPhaseSucceeded TriageRunPhase = "Succeeded" | ||
| TriageRunPhaseFailed TriageRunPhase = "Failed" | ||
| ) | ||
|
|
||
| // TriageSeverity is the verdict emitted by an individual diagnostic check. | ||
| // +kubebuilder:validation:Enum=pass;warn;fail;error | ||
| type TriageSeverity string | ||
|
|
||
| const ( | ||
| TriageSeverityPass TriageSeverity = "pass" | ||
| TriageSeverityWarn TriageSeverity = "warn" | ||
| TriageSeverityFail TriageSeverity = "fail" | ||
| TriageSeverityError TriageSeverity = "error" | ||
| ) | ||
|
|
||
| // TriageApplicationReference identifies an Application in the TriageRun's | ||
| // namespace. | ||
| type TriageApplicationReference struct { | ||
| // Name is the name of the Application to diagnose. | ||
| // +kubebuilder:validation:MinLength=1 | ||
| // +kubebuilder:validation:MaxLength=253 | ||
| // +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$` | ||
| Name string `json:"name"` | ||
| } | ||
|
|
||
| // TriageActionName identifies an action declared by an Application. | ||
| // +kubebuilder:validation:MinLength=1 | ||
| type TriageActionName string | ||
|
|
||
| // TriageActionReference selects one action declared by the referenced | ||
| // Application. Descriptive and execution metadata remain owned by the | ||
| // Application and are resolved by the controller. | ||
| type TriageActionReference struct { | ||
| // Name is the stable action name exposed by the Application. | ||
| Name TriageActionName `json:"name"` | ||
| } | ||
|
|
||
| // TriageRunSpec defines one immutable request to run one or more diagnostic | ||
| // actions for an Application. | ||
| // Creating another run requires creating another TriageRun. | ||
| // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="spec is immutable" | ||
| type TriageRunSpec struct { | ||
| // ApplicationRef identifies the Application to diagnose. Cross-namespace | ||
| // references are intentionally unsupported. | ||
| ApplicationRef TriageApplicationReference `json:"applicationRef"` | ||
|
|
||
| // Actions selects one or more triage actions declared by the referenced | ||
| // Application. Each action is executed independently. | ||
| // +kubebuilder:validation:MinItems=1 | ||
| // +listType=map | ||
| // +listMapKey=name | ||
| Actions []TriageActionReference `json:"actions"` | ||
| } | ||
|
|
||
| // TriageResolvedExecution records the concrete execution selected from the | ||
| // Application at reconciliation time. It is an audit snapshot, not user input. | ||
| type TriageResolvedExecution struct { | ||
| // ApplicationGeneration is the Application generation used to resolve this | ||
| // execution. | ||
| ApplicationGeneration int64 `json:"applicationGeneration,omitempty"` | ||
|
|
||
| // ContainerName is the application container whose image and runtime | ||
| // configuration were selected. | ||
| ContainerName string `json:"containerName,omitempty"` | ||
|
|
||
| // Image is the concrete container image used by the diagnostic Job. | ||
| Image string `json:"image,omitempty"` | ||
|
|
||
| // Command is the resolved container entrypoint. | ||
| Command []string `json:"command,omitempty"` | ||
|
|
||
| // Args are the resolved arguments passed to Command. | ||
| Args []string `json:"args,omitempty"` | ||
|
|
||
| // TimeoutSeconds is the resolved execution deadline. | ||
| TimeoutSeconds int64 `json:"timeoutSeconds,omitempty"` | ||
| } | ||
|
|
||
| // TriageRunSummary contains aggregate verdict counts for a completed run. | ||
| type TriageRunSummary struct { | ||
| Total int32 `json:"total,omitempty"` | ||
| Pass int32 `json:"pass,omitempty"` | ||
| Warn int32 `json:"warn,omitempty"` | ||
| Fail int32 `json:"fail,omitempty"` | ||
| Error int32 `json:"error,omitempty"` | ||
|
|
||
| // OverallSeverity is the most severe check verdict in the run. | ||
| OverallSeverity TriageSeverity `json:"overallSeverity,omitempty"` | ||
| } | ||
|
|
||
| // TriageCheckResult contains one structured record emitted by the diagnostic | ||
| // command. | ||
| type TriageCheckResult struct { | ||
| Name string `json:"name"` | ||
|
|
||
| // Umbrella is an optional logical grouping for related checks. | ||
| Umbrella string `json:"umbrella,omitempty"` | ||
|
|
||
| Severity TriageSeverity `json:"severity"` | ||
| Message string `json:"message,omitempty"` | ||
|
|
||
| // Evidence preserves application-defined structured evidence. | ||
| // +kubebuilder:pruning:PreserveUnknownFields | ||
| Evidence *apiextensionsv1.JSON `json:"evidence,omitempty"` | ||
|
|
||
| Remediation string `json:"remediation,omitempty"` | ||
|
|
||
| StartedAt *metav1.Time `json:"startedAt,omitempty"` | ||
| EndedAt *metav1.Time `json:"endedAt,omitempty"` | ||
|
|
||
| DurationMilliseconds int64 `json:"durationMs,omitempty"` | ||
| } | ||
|
|
||
| // TriageActionStatus records the execution and structured diagnostic output | ||
| // for one selected action. | ||
| type TriageActionStatus struct { | ||
| // Action is the selected Application action represented by this status. | ||
| Action TriageActionName `json:"action"` | ||
|
|
||
| Phase TriageRunPhase `json:"phase,omitempty"` | ||
|
|
||
| // JobRef identifies the Kubernetes Job executing this action. | ||
| JobRef *corev1.LocalObjectReference `json:"jobRef,omitempty"` | ||
|
|
||
| // ResolvedExecution is the execution snapshot selected from the referenced | ||
| // Application. | ||
| ResolvedExecution *TriageResolvedExecution `json:"resolvedExecution,omitempty"` | ||
|
|
||
| StartedAt *metav1.Time `json:"startedAt,omitempty"` | ||
| CompletedAt *metav1.Time `json:"completedAt,omitempty"` | ||
|
|
||
| Summary *TriageRunSummary `json:"summary,omitempty"` | ||
| Results []TriageCheckResult `json:"results,omitempty"` | ||
| } | ||
|
|
||
| // TriageRunStatus defines the observed execution state and diagnostic output. | ||
| type TriageRunStatus struct { | ||
| Phase TriageRunPhase `json:"phase,omitempty"` | ||
|
|
||
| ObservedGeneration int64 `json:"observedGeneration,omitempty"` | ||
|
|
||
| StartedAt *metav1.Time `json:"startedAt,omitempty"` | ||
| CompletedAt *metav1.Time `json:"completedAt,omitempty"` | ||
|
|
||
| Summary *TriageRunSummary `json:"summary,omitempty"` | ||
|
|
||
| // ActionStatuses contains one entry for every selected action. | ||
| // +listType=map | ||
| // +listMapKey=action | ||
| ActionStatuses []TriageActionStatus `json:"actionStatuses,omitempty"` | ||
|
|
||
| // Conditions represent the latest available observations of the run. | ||
| // +listType=map | ||
| // +listMapKey=type | ||
| Conditions []metav1.Condition `json:"conditions,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
| // +kubebuilder:subresource:status | ||
| // +kubebuilder:printcolumn:name="Application",type=string,JSONPath=`.spec.applicationRef.name` | ||
| // +kubebuilder:printcolumn:name="Actions",type=string,JSONPath=`.spec.actions` | ||
| // +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase` | ||
| // +kubebuilder:printcolumn:name="Severity",type=string,JSONPath=`.status.summary.overallSeverity` | ||
| // +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` | ||
|
|
||
| // TriageRun is one immutable request to diagnose an Application. | ||
| type TriageRun struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
|
||
| Spec TriageRunSpec `json:"spec"` | ||
| Status TriageRunStatus `json:"status,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
| // TriageRunList contains a list of TriageRun. | ||
| type TriageRunList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitempty"` | ||
| Items []TriageRun `json:"items"` | ||
| } | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(&TriageRun{}, &TriageRunList{}) | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.