|
| 1 | +/* |
| 2 | +Copyright 2024 The KusionStack Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | +) |
| 22 | + |
| 23 | +const ( |
| 24 | + OpsActionRestart = "Restart" |
| 25 | + OpsActionReplace = "Replace" |
| 26 | +) |
| 27 | + |
| 28 | +const ( |
| 29 | + ReasonPodNotFound = "PodNotFound" |
| 30 | + ReasonContainerNotFound = "ContainerNotFound" |
| 31 | + ReasonReplacedByNewPod = "ReplacedByNewPod" |
| 32 | +) |
| 33 | + |
| 34 | +// OperationProgress indicates operation progress of pod |
| 35 | +type OperationProgress string |
| 36 | + |
| 37 | +const ( |
| 38 | + OperationProgressPending OperationProgress = "Pending" |
| 39 | + OperationProgressProcessing OperationProgress = "Processing" |
| 40 | + OperationProgressFailed OperationProgress = "Failed" |
| 41 | + OperationProgressSucceeded OperationProgress = "Succeeded" |
| 42 | +) |
| 43 | + |
| 44 | +// OperationJobSpec defines the desired state of OperationJob |
| 45 | +type OperationJobSpec struct { |
| 46 | + // Specify the operation actions including: Restart, Replace |
| 47 | + // +optional |
| 48 | + Action string `json:"action,omitempty"` |
| 49 | + |
| 50 | + // Define the operation target pods |
| 51 | + // +optional |
| 52 | + Targets []PodOpsTarget `json:"targets,omitempty"` |
| 53 | + |
| 54 | + // Partition controls the operation progress by indicating how many pods should be operated. |
| 55 | + // Defaults to nil (all pods will be updated) |
| 56 | + // +optional |
| 57 | + Partition *int32 `json:"partition,omitempty"` |
| 58 | + |
| 59 | + // OperationDelaySeconds indicates how many seconds it should delay before operating update. |
| 60 | + // +optional |
| 61 | + OperationDelaySeconds *int32 `json:"operationDelaySeconds,omitempty"` |
| 62 | + |
| 63 | + // Specify the duration in seconds relative to the startTime |
| 64 | + // that the job may be active before the system tries to terminate it |
| 65 | + // +optional |
| 66 | + ActiveDeadlineSeconds *int32 `json:"activeDeadlineSeconds,omitempty"` |
| 67 | + |
| 68 | + // Limit the lifetime of an operation that has finished execution (either Complete or Failed) |
| 69 | + // +optional |
| 70 | + TTLSecondsAfterFinished *int32 `json:"TTLSecondsAfterFinished,omitempty"` |
| 71 | +} |
| 72 | + |
| 73 | +// PodOpsTarget defines the target pods of the OperationJob |
| 74 | +type PodOpsTarget struct { |
| 75 | + // Specify the operation target pods |
| 76 | + // +optional |
| 77 | + Name string `json:"name,omitempty"` |
| 78 | + |
| 79 | + // Specify the containers to restart |
| 80 | + // +optional |
| 81 | + Containers []string `json:"containers,omitempty"` |
| 82 | +} |
| 83 | + |
| 84 | +// OperationJobStatus defines the observed state of OperationJob |
| 85 | +type OperationJobStatus struct { |
| 86 | + // ObservedGeneration is the most recent generation observed for this OperationJob. It corresponds to the |
| 87 | + // OperationJob's generation, which is updated on mutation by the API Server. |
| 88 | + // +optional |
| 89 | + ObservedGeneration int64 `json:"observedGeneration,omitempty"` |
| 90 | + |
| 91 | + // Phase indicates the of the OperationJob |
| 92 | + // +optional |
| 93 | + Progress OperationProgress `json:"progress,omitempty"` |
| 94 | + |
| 95 | + // Operation start time |
| 96 | + // +optional |
| 97 | + StartTimestamp *metav1.Time `json:"startTimestamp,omitempty"` |
| 98 | + |
| 99 | + // Operation end time |
| 100 | + // +optional |
| 101 | + EndTimestamp *metav1.Time `json:"endTimestamp,omitempty"` |
| 102 | + |
| 103 | + // Replicas of the pods involved in the OperationJob |
| 104 | + // +optional |
| 105 | + TotalPodCount int32 `json:"totalPodCount,omitempty"` |
| 106 | + |
| 107 | + // Succeeded replicas of the pods involved in the OperationJob |
| 108 | + // +optional |
| 109 | + SucceededPodCount int32 `json:"succeededPodCount,omitempty"` |
| 110 | + |
| 111 | + // failed pod count of the pods involved in the OperationJob |
| 112 | + // +optional |
| 113 | + FailedPodCount int32 `json:"failedPodCount,omitempty"` |
| 114 | + |
| 115 | + // Operation details of the target pods |
| 116 | + // +optional |
| 117 | + TargetDetails []OpsStatus `json:"targetDetails,omitempty"` |
| 118 | +} |
| 119 | + |
| 120 | +type OpsStatus struct { |
| 121 | + // name of the target pod |
| 122 | + // +optional |
| 123 | + Name string `json:"name,omitempty"` |
| 124 | + |
| 125 | + // operation progress of target pod |
| 126 | + // +optional |
| 127 | + Progress OperationProgress `json:"progress,omitempty"` |
| 128 | + |
| 129 | + // reason for current operation progress |
| 130 | + // +optional |
| 131 | + Reason string `json:"reason,omitempty"` |
| 132 | + |
| 133 | + // message displays detail of reason |
| 134 | + // +optional |
| 135 | + Message string `json:"message,omitempty"` |
| 136 | +} |
| 137 | + |
| 138 | +// +kubebuilder:object:root=true |
| 139 | +// +kubebuilder:subresource:status |
| 140 | + |
| 141 | +// +k8s:openapi-gen=true |
| 142 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 143 | +// +kubebuilder:resource:shortName=oj |
| 144 | +// +kubebuilder:subresource:status |
| 145 | +// +kubebuilder:printcolumn:name="PROGRESS",type="string",JSONPath=".status.progress" |
| 146 | +// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" |
| 147 | + |
| 148 | +// OperationJob is the Schema for the operationjobs API |
| 149 | +type OperationJob struct { |
| 150 | + metav1.TypeMeta `json:",inline"` |
| 151 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 152 | + |
| 153 | + Spec OperationJobSpec `json:"spec,omitempty"` |
| 154 | + Status OperationJobStatus `json:"status,omitempty"` |
| 155 | +} |
| 156 | + |
| 157 | +//+kubebuilder:object:root=true |
| 158 | + |
| 159 | +// OperationJobList contains a list of OperationJob |
| 160 | +type OperationJobList struct { |
| 161 | + metav1.TypeMeta `json:",inline"` |
| 162 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 163 | + Items []OperationJob `json:"items"` |
| 164 | +} |
| 165 | + |
| 166 | +func init() { |
| 167 | + SchemeBuilder.Register(&OperationJob{}, &OperationJobList{}) |
| 168 | +} |
0 commit comments