Skip to content

Commit e28690f

Browse files
committed
Merge branch 'main' into support/migrate-config-manager-to-kbagent
2 parents 942cb99 + fcd0f17 commit e28690f

37 files changed

+3362
-196
lines changed

apis/apps/v1/cluster_types.go

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ type ClusterStatus struct {
226226
// Records the current status information of all shardings within the Cluster.
227227
//
228228
// +optional
229-
Shardings map[string]ClusterComponentStatus `json:"shardings,omitempty"`
229+
Shardings map[string]ClusterShardingStatus `json:"shardings,omitempty"`
230230

231231
// Represents a list of detailed status of the Cluster object.
232232
// Each condition in the list provides real-time information about certain aspect of the Cluster object.
@@ -641,9 +641,9 @@ type ClusterSharding struct {
641641
// between the desired and actual number of shards.
642642
// KubeBlocks provides lifecycle management for sharding, including:
643643
//
644-
// - Executing the shardProvision Action defined in the ShardingDefinition when the number of shards increases.
644+
// - Executing the shardAdd Action defined in the ShardingDefinition when the number of shards increases.
645645
// This allows for custom actions to be performed after a new shard is provisioned.
646-
// - Executing the shardTerminate Action defined in the ShardingDefinition when the number of shards decreases.
646+
// - Executing the shardRemove Action defined in the ShardingDefinition when the number of shards decreases.
647647
// This enables custom cleanup or data migration tasks to be executed before a shard is terminated.
648648
// Resources and data associated with the corresponding Component will also be deleted.
649649
//
@@ -924,3 +924,95 @@ type ClusterComponentStatus struct {
924924
// +optional
925925
UpToDate bool `json:"upToDate,omitempty"`
926926
}
927+
928+
// ClusterShardingStatus records a sharding status.
929+
type ClusterShardingStatus struct {
930+
// Specifies the current state of the sharding.
931+
//
932+
// +optional
933+
Phase ComponentPhase `json:"phase,omitempty"`
934+
935+
// Records detailed information about the sharding in its current phase.
936+
//
937+
// +optional
938+
Message map[string]string `json:"message,omitempty"`
939+
940+
// Indicates the most recent generation of the sharding state observed.
941+
//
942+
// +optional
943+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
944+
945+
// Indicates whether the sharding state observed is up-to-date with the desired state.
946+
//
947+
// +optional
948+
UpToDate bool `json:"upToDate,omitempty"`
949+
950+
// Records the name of the sharding definition used.
951+
//
952+
// +optional
953+
ShardingDef string `json:"shardingDef,omitempty"`
954+
955+
// PostProvision records the status of the sharding post-provision action.
956+
//
957+
// +optional
958+
PostProvision *LifecycleActionStatus `json:"postProvision,omitempty"`
959+
960+
// PreTerminate records the status of the sharding pre-terminate action.
961+
//
962+
// +optional
963+
PreTerminate *LifecycleActionStatus `json:"preTerminate,omitempty"`
964+
}
965+
966+
// LifecycleActionStatus records the observed state of a lifecycle-related action.
967+
type LifecycleActionStatus struct {
968+
// Phase is the current phase of the lifecycle action.
969+
//
970+
// +optional
971+
Phase LifecycleActionPhase `json:"phase,omitempty"`
972+
973+
// Reason is a programmatic identifier indicating the reason for the current phase.
974+
// e.g., 'PreconditionNotMet' for Pending phase or 'PrerequisiteFailed' for Skipped phase.
975+
//
976+
// +optional
977+
// Reason string `json:"reason,omitempty"`
978+
979+
// Message is a human-readable message providing details about the current phase.
980+
//
981+
// +optional
982+
Message string `json:"message,omitempty"`
983+
984+
// StartTime records the time when the action started execution.
985+
//
986+
// +optional
987+
StartTime *metav1.Time `json:"startTime,omitempty"`
988+
989+
// CompletionTime records the time when the action reached a terminal state (Succeeded, Failed, or Skipped).
990+
//
991+
// +optional
992+
CompletionTime *metav1.Time `json:"completionTime,omitempty"`
993+
}
994+
995+
// LifecycleActionPhase describes the current phase of a lifecycle-related action.
996+
//
997+
// +enum
998+
// +kubebuilder:validation:Enum={Pending,Running,Succeeded,Failed,Skipped}
999+
type LifecycleActionPhase string
1000+
1001+
const (
1002+
// LifecycleActionPending indicates the action is registered and waiting to be triggered or
1003+
// waiting for its dynamic preconditions to be met.
1004+
LifecycleActionPending LifecycleActionPhase = "Pending"
1005+
1006+
// LifecycleActionRunning indicates the preconditions are met and the action is currently being executed.
1007+
LifecycleActionRunning LifecycleActionPhase = "Running"
1008+
1009+
// LifecycleActionSucceeded indicates the action has completed successfully.
1010+
LifecycleActionSucceeded LifecycleActionPhase = "Succeeded"
1011+
1012+
// LifecycleActionFailed indicates the action has failed during execution or timed out.
1013+
LifecycleActionFailed LifecycleActionPhase = "Failed"
1014+
1015+
// LifecycleActionSkipped indicates the action was intentionally bypassed.
1016+
// Usually occurs if a prerequisite action failed or a permanent condition was not met.
1017+
LifecycleActionSkipped LifecycleActionPhase = "Skipped"
1018+
)

apis/apps/v1/component_types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ type ComponentSpec struct {
345345
//
346346
// +optional
347347
EnableInstanceAPI *bool `json:"enableInstanceAPI,omitempty"`
348+
349+
// Specifies custom actions that can be performed on the Component.
350+
//
351+
// +optional
352+
CustomActions []CustomAction `json:"customActions,omitempty"`
348353
}
349354

350355
// ComponentStatus represents the observed state of a Component within the Cluster.
@@ -407,6 +412,20 @@ type Sidecar struct {
407412
SidecarDef string `json:"sidecarDef"`
408413
}
409414

415+
type CustomAction struct {
416+
// Name specifies the unique name of the custom action.
417+
//
418+
// The name will be used as the action name when invoking the action.
419+
//
420+
// +kubebuilder:validation:Required
421+
Name string `json:"name"`
422+
423+
// Specifies the action to be performed.
424+
//
425+
// +kubebuilder:validation:Required
426+
Action *Action `json:"action"`
427+
}
428+
410429
// ComponentPhase defines the phase of the Component within the .status.phase field.
411430
//
412431
// +enum

apis/apps/v1/shardingdefinition_types.go

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,39 +166,50 @@ type ShardingLifecycleActions struct {
166166
//
167167
// With `ComponentReady` being the default.
168168
//
169-
// The PostProvision Action is intended to run only once.
169+
// The PostProvision action is intended to run only once.
170170
//
171171
// Note: This field is immutable once it has been set.
172172
//
173173
// +optional
174-
PostProvision *Action `json:"postProvision,omitempty"`
174+
PostProvision *ShardingAction `json:"postProvision,omitempty"`
175175

176176
// Specifies the hook to be executed prior to terminating a sharding.
177177
//
178-
// The PreTerminate Action is intended to run only once.
178+
// The PreTerminate action is intended to run only once.
179179
//
180180
// This action is executed immediately when a terminate operation for the sharding is initiated.
181181
// The actual termination and cleanup of the sharding and its associated resources will not proceed
182182
// until the PreTerminate action has completed successfully.
183183
//
184+
// If a PostProvision action is defined, this action will only execute if PostProvision reaches
185+
// the 'Succeeded' phase. If the defined PostProvision fails, this action will be skipped.
186+
//
184187
// Note: This field is immutable once it has been set.
185188
//
186189
// +optional
187-
PreTerminate *Action `json:"preTerminate,omitempty"`
190+
PreTerminate *ShardingAction `json:"preTerminate,omitempty"`
188191

189192
// Specifies the hook to be executed after a shard added.
190193
//
194+
// The container executing this action has access to following variables:
195+
//
196+
// - KB_ADD_SHARD_NAME: The name of the shard being added.
197+
//
191198
// Note: This field is immutable once it has been set.
192199
//
193200
// +optional
194-
ShardAdd *Action `json:"shardAdd,omitempty"`
201+
ShardAdd *ShardingAction `json:"shardAdd,omitempty"`
195202

196203
// Specifies the hook to be executed prior to remove a shard.
197204
//
205+
// The container executing this action has access to following variables:
206+
//
207+
// - KB_REMOVE_SHARD_NAME: The name of the shard being removed.
208+
//
198209
// Note: This field is immutable once it has been set.
199210
//
200211
// +optional
201-
ShardRemove *Action `json:"shardRemove,omitempty"`
212+
ShardRemove *ShardingAction `json:"shardRemove,omitempty"`
202213
}
203214

204215
type ShardingSystemAccount struct {
@@ -221,3 +232,31 @@ type ShardingTLS struct {
221232
// +optional
222233
Shared *bool `json:"shared,omitempty"`
223234
}
235+
236+
type ShardingAction struct {
237+
Action `json:",inline"`
238+
239+
// Defines the criteria used to select the target shard(s) for executing the Action.
240+
// It provides precise control over which shard(s) should be targeted.
241+
//
242+
// The default selection logic (when this field is omitted) is context-dependent:
243+
// 1. Contextual Default: If the Action is triggered by or originates from a specific shard,
244+
// that shard is selected as the default target.
245+
// 2. Global Default: In other cases (where no specific shard context exists),
246+
// one shard is selected randomly by default.
247+
//
248+
// This field cannot be updated.
249+
//
250+
// +optional
251+
TargetShardSelector TargetShardSelector `json:"targetShardSelector,omitempty"`
252+
}
253+
254+
// TargetShardSelector defines how to select shard(s) to execute an Action.
255+
// +enum
256+
// +kubebuilder:validation:Enum={Any,All}
257+
type TargetShardSelector string
258+
259+
const (
260+
AnyShard TargetShardSelector = "Any"
261+
AllShards TargetShardSelector = "All"
262+
)

0 commit comments

Comments
 (0)