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

fix: check lifecycle actions to avoid NPE when calling actions during scale-in #8762

Merged
merged 1 commit into from
Jan 10, 2025
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
19 changes: 16 additions & 3 deletions controllers/apps/transformer_component_workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,15 @@ func (r *componentWorkloadOps) leaveMember4ScaleIn(deleteReplicas, joinedReplica
}

func (r *componentWorkloadOps) leaveMemberForPod(pod *corev1.Pod, pods []*corev1.Pod) error {
var (
synthesizedComp = r.synthesizeComp
lifecycleActions = synthesizedComp.LifecycleActions
)

trySwitchover := func(lfa lifecycle.Lifecycle, pod *corev1.Pod) error {
if lifecycleActions.Switchover == nil {
return nil
}
err := lfa.Switchover(r.reqCtx.Ctx, r.cli, nil, "")
if err != nil {
if errors.Is(err, lifecycle.ErrActionNotDefined) {
Expand All @@ -700,21 +708,26 @@ func (r *componentWorkloadOps) leaveMemberForPod(pod *corev1.Pod, pods []*corev1
}

tryMemberLeave := func(lfa lifecycle.Lifecycle, pod *corev1.Pod) error {
if lifecycleActions.MemberLeave == nil {
return nil
}
err := lfa.MemberLeave(r.reqCtx.Ctx, r.cli, nil)
if err != nil {
if errors.Is(err, lifecycle.ErrActionNotDefined) {
return nil
}
return err
}

r.reqCtx.Log.Info("successfully call leave member action for pod", "pod", pod.Name)
return nil
}

synthesizedComp := r.synthesizeComp
if lifecycleActions == nil || (lifecycleActions.Switchover == nil && lifecycleActions.MemberLeave == nil) {
return nil
}

lfa, err := lifecycle.New(synthesizedComp.Namespace, synthesizedComp.ClusterName, synthesizedComp.Name,
synthesizedComp.LifecycleActions, synthesizedComp.TemplateVars, pod, pods...)
lifecycleActions, synthesizedComp.TemplateVars, pod, pods...)
if err != nil {
return err
}
Expand Down
Loading