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: direct pod should be rollout #543

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Changes from 2 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
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
Loading