Skip to content

Commit

Permalink
fix staticcheck error
Browse files Browse the repository at this point in the history
  • Loading branch information
free6om committed Apr 25, 2024
1 parent b6d02ca commit 4e6346a
Showing 1 changed file with 0 additions and 62 deletions.
62 changes: 0 additions & 62 deletions controllers/apps/transformer_component_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"strings"
"time"

"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -451,67 +450,6 @@ func (r *componentStatusHandler) updateComponentStatus(phaseTransitionMsg string
return nil
}

// updatePrimaryIndex updates the primary pod index to the pod annotations.
// TODO: the need to update primary info is because some database engines currently require external specification of the primary node.
// Based on the specified primary node, the primary-secondary relationship can be established during startup. Examples of such engines include primary-secondary Redis.
// In the future, there is a need for a better design to replace this kind of workaround.
func (r *componentStatusHandler) updatePrimaryIndex() error {
// TODO(xingran): consider if there are alternative ways to determine whether it is necessary to specify primary info in the Controller
if r.synthesizeComp.RoleArbitrator == nil || *r.synthesizeComp.RoleArbitrator != appsv1alpha1.LorryRoleArbitrator {
return nil
}
podList, err := component.ListPodOwnedByComponent(r.reqCtx.Ctx, r.cli, r.cluster.Namespace,
constant.GetComponentWellKnownLabels(r.cluster.Name, r.synthesizeComp.Name), inDataContext4C())
if err != nil {
return err
}
if len(podList) == 0 {
return nil
}
slices.SortFunc(podList, func(a, b *corev1.Pod) bool {
return a.GetName() < b.GetName()
})
primaryPods := make([]string, 0)
emptyRolePods := make([]string, 0)
for _, pod := range podList {
role, ok := pod.Labels[constant.RoleLabelKey]
if !ok || role == "" {
emptyRolePods = append(emptyRolePods, pod.Name)
continue
}
if role == constant.Primary {
primaryPods = append(primaryPods, pod.Name)
}
}
primaryPodName, err := func() (string, error) {
switch {
// if the workload is newly created, and the role label is not set, we set the pod with index=0 as the primary by default.
case len(emptyRolePods) == len(podList):
return podList[0].Name, nil
case len(primaryPods) != 1:
return "", fmt.Errorf("the number of primary pod is not equal to 1, primary pods: %v, emptyRole pods: %v", primaryPods, emptyRolePods)
default:
return primaryPods[0], nil
}
}()
if err != nil {
return err
}
graphCli := model.NewGraphClient(r.cli)
for _, pod := range podList {
if pod.Annotations == nil {
pod.Annotations = map[string]string{}
}
pi, ok := pod.Annotations[constant.PrimaryAnnotationKey]
if !ok || pi != primaryPodName {
origPod := pod.DeepCopy()
pod.Annotations[constant.PrimaryAnnotationKey] = primaryPodName
graphCli.Do(r.dag, origPod, pod, model.ActionUpdatePtr(), nil, inDataContext4G())
}
}
return nil
}

// newComponentStatusHandler creates a new componentStatusHandler
func newComponentStatusHandler(reqCtx intctrlutil.RequestCtx,
cli client.Client,
Expand Down

0 comments on commit 4e6346a

Please sign in to comment.