Skip to content

Commit cba99ad

Browse files
authored
chore: refine the sharding action (#9982)
1 parent 2a26105 commit cba99ad

22 files changed

+1575
-565
lines changed

apis/apps/v1/cluster_types.go

Lines changed: 93 additions & 1 deletion
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.
@@ -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: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,6 @@ type ComponentSpec struct {
348348

349349
// Specifies custom actions that can be performed on the Component.
350350
//
351-
// Each custom action defines a specific operation that can be executed,
352-
// will be merged with ComponentLifecycleActions defined in referenced ComponentDefinition.
353-
//
354351
// +optional
355352
CustomActions []CustomAction `json:"customActions,omitempty"`
356353
}

apis/apps/v1/shardingdefinition_types.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ 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
//
@@ -175,12 +175,15 @@ type ShardingLifecycleActions struct {
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
@@ -233,12 +236,14 @@ type ShardingTLS struct {
233236
type ShardingAction struct {
234237
Action `json:",inline"`
235238

236-
// Defines the criteria used to select the target Shard(s) for executing the Action.
237-
// It allows for precise control over which Shard(s) the Action should run in.
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.
238241
//
239-
// For shardAdd or shardRemove, the Action will be executed in the Shard where the Action is triggered.
240-
// For other actions, you can choose to execute the action randomly on one shard or on all shards,
241-
// if not specified, a shard is randomly selected by default.
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.
242247
//
243248
// This field cannot be updated.
244249
//

apis/apps/v1/zz_generated.deepcopy.go

Lines changed: 56 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/apps.kubeblocks.io_clusters.yaml

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18037,21 +18037,21 @@ spec:
1803718037
type: string
1803818038
shardings:
1803918039
additionalProperties:
18040-
description: ClusterComponentStatus records Component status.
18040+
description: ClusterShardingStatus records a sharding status.
1804118041
properties:
1804218042
message:
1804318043
additionalProperties:
1804418044
type: string
18045-
description: Records detailed information about the Component
18045+
description: Records detailed information about the sharding
1804618046
in its current phase.
1804718047
type: object
1804818048
observedGeneration:
18049-
description: Indicates the most recent generation of the component
18049+
description: Indicates the most recent generation of the sharding
1805018050
state observed.
1805118051
format: int64
1805218052
type: integer
1805318053
phase:
18054-
description: Specifies the current state of the Component.
18054+
description: Specifies the current state of the sharding.
1805518055
enum:
1805618056
- Creating
1805718057
- Deleting
@@ -18062,9 +18062,70 @@ spec:
1806218062
- Stopped
1806318063
- Failed
1806418064
type: string
18065+
postProvision:
18066+
description: PostProvision records the status of the sharding
18067+
post-provision action.
18068+
properties:
18069+
completionTime:
18070+
description: CompletionTime records the time when the action
18071+
reached a terminal state (Succeeded, Failed, or Skipped).
18072+
format: date-time
18073+
type: string
18074+
message:
18075+
description: Message is a human-readable message providing
18076+
details about the current phase.
18077+
type: string
18078+
phase:
18079+
description: Phase is the current phase of the lifecycle
18080+
action.
18081+
enum:
18082+
- Pending
18083+
- Running
18084+
- Succeeded
18085+
- Failed
18086+
- Skipped
18087+
type: string
18088+
startTime:
18089+
description: StartTime records the time when the action
18090+
started execution.
18091+
format: date-time
18092+
type: string
18093+
type: object
18094+
preTerminate:
18095+
description: PreTerminate records the status of the sharding
18096+
pre-terminate action.
18097+
properties:
18098+
completionTime:
18099+
description: CompletionTime records the time when the action
18100+
reached a terminal state (Succeeded, Failed, or Skipped).
18101+
format: date-time
18102+
type: string
18103+
message:
18104+
description: Message is a human-readable message providing
18105+
details about the current phase.
18106+
type: string
18107+
phase:
18108+
description: Phase is the current phase of the lifecycle
18109+
action.
18110+
enum:
18111+
- Pending
18112+
- Running
18113+
- Succeeded
18114+
- Failed
18115+
- Skipped
18116+
type: string
18117+
startTime:
18118+
description: StartTime records the time when the action
18119+
started execution.
18120+
format: date-time
18121+
type: string
18122+
type: object
18123+
shardingDef:
18124+
description: Records the name of the sharding definition used.
18125+
type: string
1806518126
upToDate:
18066-
description: Indicates whether the component state observed
18067-
is up-to-date with the desired state.
18127+
description: Indicates whether the sharding state observed is
18128+
up-to-date with the desired state.
1806818129
type: boolean
1806918130
type: object
1807018131
description: Records the current status information of all shardings

config/crd/bases/apps.kubeblocks.io_components.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,8 @@ spec:
619619
type: object
620620
type: array
621621
customActions:
622-
description: |-
623-
Specifies custom actions that can be performed on the Component.
624-
625-
626-
Each custom action defines a specific operation that can be executed,
627-
will be merged with ComponentLifecycleActions defined in referenced ComponentDefinition.
622+
description: Specifies custom actions that can be performed on the
623+
Component.
628624
items:
629625
properties:
630626
action:

0 commit comments

Comments
 (0)