Skip to content
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

chore: lifecycle action done annotation validation #7521

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions pkg/controller/component/action_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,36 +483,35 @@ func cleanActionJob(ctx context.Context,
dag *graph.DAG,
actionCtx *ActionContext,
jobName string) error {
if actionCtx.cluster.Annotations == nil || actionCtx.component.Annotations == nil {
return errors.New("cluster or component annotations not found")
}
// check action done annotation has been set
if !checkActionDoneAnnotationExist(actionCtx) {
return fmt.Errorf("cluster %s %s done annotation has not been set", actionCtx.cluster.Name, actionCtx.actionType)
return fmt.Errorf("component %s %s action done annotation has not been set", actionCtx.component.Name, actionCtx.actionType)
}
return job.CleanJobByNameWithDAG(ctx, cli, dag, actionCtx.cluster, jobName)
}

// checkActionDoneAnnotationExist checks if the action done annotation exists.
func checkActionDoneAnnotationExist(actionCtx *ActionContext) bool {
if actionCtx.cluster.Annotations == nil || actionCtx.component.Annotations == nil {
return false
}
var actionDoneKey string
switch actionCtx.actionType {
case PostProvisionAction:
// TODO(xingran): for backward compatibility before KubeBlocks v0.8.0, check the annotation of the cluster object first, it will be deprecated in the future
compPostStartDoneKey := fmt.Sprintf(kbCompPostStartDoneKeyPattern, actionCtx.component.Name)
_, ok := actionCtx.cluster.Annotations[compPostStartDoneKey]
if ok {
return true
if actionCtx.cluster.Annotations != nil {
compPostStartDoneKey := fmt.Sprintf(kbCompPostStartDoneKeyPattern, actionCtx.component.Name)
_, ok := actionCtx.cluster.Annotations[compPostStartDoneKey]
if ok {
return true
}
}
actionDoneKey = kbCompPostProvisionDoneKey
case PreTerminateAction:
actionDoneKey = kbCompPreTerminateDoneKey
default:
return false
}
if actionCtx.component.Annotations == nil {
return false
}
_, ok := actionCtx.component.Annotations[actionDoneKey]
return ok
}
Expand Down
Loading