Skip to content

Commit

Permalink
fix: direct pod should be rollout
Browse files Browse the repository at this point in the history
Signed-off-by: Aylei <rayingecho@gmail.com>
  • Loading branch information
aylei committed Aug 22, 2024
1 parent ff70c7e commit 3396226
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/controllers/cnpool/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ func (r *Actor) Sync(ctx *recon.Context[*v1alpha1.CNPool]) error {
}
totalPods += legacyReplicas
}
if err := iterateDirectLivePods(ctx, p, func(p *corev1.Pod) error {
// outdated direct pod, mark it
if p.Labels[common.InstanceLabelKey] != desired.Name {
if err := r.reclaimLegacyCNClaim(ctx, p); err != nil {
return err
}
}
return nil
}); err != nil {
return errors.Wrap(err, 0)
}

var inUse int32
var idlePods []*corev1.Pod
Expand Down Expand Up @@ -279,6 +290,27 @@ func iterateCNSetLivePods(cli recon.KubeClient, cnSet *v1alpha1.CNSet, fn func(p
return nil
}

func iterateDirectLivePods(cli recon.KubeClient, pool *v1alpha1.CNPool, fn func(p *corev1.Pod) error) error {
podList := &corev1.PodList{}
if err := cli.List(podList, client.InNamespace(pool.Namespace), client.MatchingLabels(map[string]string{
v1alpha1.PoolNameLabel: pool.Name,
v1alpha1.DirectPodLabel: "y",
})); err != nil {
return errors.Wrap(err, 0)
}
for i := range podList.Items {
p := &podList.Items[i]
if p.DeletionTimestamp != nil {
// Pod deleted, skip
continue
}
if err := fn(p); err != nil {
return err
}
}
return nil
}

func buildCNSet(p *v1alpha1.CNPool) (*v1alpha1.CNSet, error) {
csSpec := p.Spec.Template.DeepCopy()
syncCNSetSpec(p, csSpec)
Expand Down

0 comments on commit 3396226

Please sign in to comment.