Skip to content

Commit

Permalink
Rename "delete" pod methods to "evict" to clarify.
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed Feb 6, 2025
1 parent eafea28 commit b3d37ba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cmd/traffic/cmd/manager/mutator/service_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (c *configWatcher) updateSvc(ctx context.Context, svc *core.Service, trustU
ac = acn.AgentConfig()
c.Store(acn)
dlog.Debugf(ctx, "deleting pods with config mismatch for %s %s.%s", ac.WorkloadKind, ac.WorkloadName, ac.Namespace)
err = c.DeletePodsWithConfigMismatch(ctx, acn)
err = c.EvictPodsWithAgentConfigMismatch(ctx, acn)
if err != nil {
dlog.Error(ctx, err)
}
Expand Down
41 changes: 20 additions & 21 deletions cmd/traffic/cmd/manager/mutator/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"slices"
"sync"
"sync/atomic"
"time"

Expand Down Expand Up @@ -41,9 +40,9 @@ type Map interface {
DeleteMapsAndRolloutAll(context.Context)
IsInactive(podID types.UID) bool
Inactivate(podID types.UID)
DeletePodsWithConfig(ctx context.Context, wl k8sapi.Workload) error
DeletePodsWithConfigMismatch(ctx context.Context, scx agentconfig.SidecarExt) error
DeleteAllPodsWithConfig(ctx context.Context, namespace string) error
EvictPodWithAgentConfig(ctx context.Context, wl k8sapi.Workload) error
EvictPodsWithAgentConfigMismatch(ctx context.Context, scx agentconfig.SidecarExt) error
EvictAllPodsWithAgentConfig(ctx context.Context, namespace string) error

RegenerateAgentMaps(ctx context.Context, s string) error

Expand Down Expand Up @@ -135,7 +134,7 @@ func (c *configWatcher) regenerateAgentMaps(ctx context.Context, ns string, gc a
}
if newSce == nil || !cmp.Equal(newSce, sce, dbpCmp) {
go func() {
deletePod(ctx, pod)
evictPod(ctx, pod)
}()
}
}
Expand Down Expand Up @@ -498,13 +497,13 @@ func (c *configWatcher) deleteMapsAndRolloutNS(ctx context.Context, ns string, i
}
iwc.cancel()

err := c.DeleteAllPodsWithConfig(ctx, ns)
err := c.EvictAllPodsWithAgentConfig(ctx, ns)
if err != nil {
dlog.Errorf(ctx, "unable to delete agents in namespace %s: %v", ns, err)
}
}

func (c *configWatcher) DeletePodsWithConfigMismatch(ctx context.Context, scx agentconfig.SidecarExt) error {
func (c *configWatcher) EvictPodsWithAgentConfigMismatch(ctx context.Context, scx agentconfig.SidecarExt) error {
ac := scx.AgentConfig()
pods, err := podList(ctx, ac.WorkloadKind, ac.AgentName, ac.Namespace)
if err != nil {
Expand All @@ -516,47 +515,47 @@ func (c *configWatcher) DeletePodsWithConfigMismatch(ctx context.Context, scx ag
}

for _, pod := range pods {
err = c.DeleteIfMismatch(ctx, pod, cfgJSON)
err = c.evictPodWithAgentConfigMismatch(ctx, pod, cfgJSON)
if err != nil {
return err
}
}
return nil
}

func (c *configWatcher) DeletePodsWithConfig(ctx context.Context, wl k8sapi.Workload) error {
func (c *configWatcher) EvictPodWithAgentConfig(ctx context.Context, wl k8sapi.Workload) error {
pods, err := podList(ctx, wl.GetKind(), wl.GetName(), wl.GetNamespace())
if err != nil {
return err
}

for _, pod := range pods {
err = c.DeleteIfMismatch(ctx, pod, "")
err = c.evictPodWithAgentConfigMismatch(ctx, pod, "")
if err != nil {
return err
}
}
return nil
}

func (c *configWatcher) DeleteAllPodsWithConfig(ctx context.Context, namespace string) error {
func (c *configWatcher) EvictAllPodsWithAgentConfig(ctx context.Context, namespace string) error {
c.agentConfigs.Delete(namespace)
pods, err := podList(ctx, "", "", namespace)
if err != nil {
return err
}
for _, pod := range pods {
err = c.DeleteIfMismatch(ctx, pod, "")
err = c.evictPodWithAgentConfigMismatch(ctx, pod, "")
if err != nil {
return err
}
}
return nil
}

func (c *configWatcher) DeleteIfMismatch(ctx context.Context, pod *core.Pod, cfgJSON string) error {
func (c *configWatcher) evictPodWithAgentConfigMismatch(ctx context.Context, pod *core.Pod, cfgJSON string) error {
podID := pod.UID
if c.IsDeleted(podID) {
if c.isEvicted(podID) {
dlog.Debugf(ctx, "Skipping pod %s because it is already deleted", pod.Name)
return nil
}
Expand All @@ -575,13 +574,13 @@ func (c *configWatcher) DeleteIfMismatch(ctx context.Context, pod *core.Pod, cfg
dlog.Debugf(ctx, "Skipping pod %s because it was deleted by another goroutine", pod.Name)
return v, false
}
deletePod(ctx, pod)
evictPod(ctx, pod)
return inactivation{Time: time.Now(), deleted: true}, false
})
return err
}

func deletePod(ctx context.Context, pod *core.Pod) {
func evictPod(ctx context.Context, pod *core.Pod) {
dlog.Debugf(ctx, "Evicting pod %s", pod.Name)
err := k8sapi.GetK8sInterface(ctx).CoreV1().Pods(pod.Namespace).EvictV1(ctx, &v1.Eviction{
ObjectMeta: meta.ObjectMeta{Name: pod.Name, Namespace: pod.Namespace},
Expand All @@ -597,16 +596,16 @@ func (c *configWatcher) Inactivate(podID types.UID) {
})
}

func (c *configWatcher) IsDeleted(podID types.UID) bool {
v, ok := c.inactivePods.Load(podID)
return ok && v.deleted
}

func (c *configWatcher) IsInactive(podID types.UID) bool {
_, ok := c.inactivePods.Load(podID)
return ok
}

func (c *configWatcher) isEvicted(podID types.UID) bool {
v, ok := c.inactivePods.Load(podID)
return ok && v.deleted
}

func podIsRunning(pod *core.Pod) bool {
switch pod.Status.Phase {
case core.PodPending, core.PodRunning:
Expand Down
4 changes: 2 additions & 2 deletions cmd/traffic/cmd/manager/mutator/workload_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ func (c *configWatcher) updateWorkload(ctx context.Context, wl, oldWl k8sapi.Wor
c.Store(scx)
ac := scx.AgentConfig()
dlog.Debugf(ctx, "deleting pods with config mismatch for %s %s.%s", ac.WorkloadKind, ac.WorkloadName, ac.Namespace)
err = c.DeletePodsWithConfigMismatch(ctx, scx)
err = c.EvictPodsWithAgentConfigMismatch(ctx, scx)
if err != nil {
dlog.Error(ctx, err)
}
case "false", "disabled":
c.Delete(wl.GetName(), wl.GetNamespace())
err := c.DeletePodsWithConfig(ctx, wl)
err := c.EvictPodWithAgentConfig(ctx, wl)
if err != nil {
dlog.Error(ctx, err)
}
Expand Down

0 comments on commit b3d37ba

Please sign in to comment.