Skip to content

Commit

Permalink
Don't skip evicting pods with same name but in different namespace (#746
Browse files Browse the repository at this point in the history
)

* Don't skip evicting pods with same name but in different namespace

* Make --pod-namespace optional
  • Loading branch information
johngmyers authored Dec 22, 2022
1 parent ca72045 commit 01f4844
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
dryRunConfigKey = "DRY_RUN"
nodeNameConfigKey = "NODE_NAME"
podNameConfigKey = "POD_NAME"
podNamespaceConfigKey = "NAMESPACE"
kubernetesServiceHostConfigKey = "KUBERNETES_SERVICE_HOST"
kubernetesServicePortConfigKey = "KUBERNETES_SERVICE_PORT"
deleteLocalDataConfigKey = "DELETE_LOCAL_DATA"
Expand Down Expand Up @@ -114,6 +115,7 @@ type Config struct {
DryRun bool
NodeName string
PodName string
PodNamespace string
MetadataURL string
IgnoreDaemonSets bool
DeleteLocalData bool
Expand Down Expand Up @@ -173,6 +175,7 @@ func ParseCliArgs() (config Config, err error) {
flag.BoolVar(&config.DryRun, "dry-run", getBoolEnv(dryRunConfigKey, false), "If true, only log if a node would be drained")
flag.StringVar(&config.NodeName, "node-name", getEnv(nodeNameConfigKey, ""), "The kubernetes node name")
flag.StringVar(&config.PodName, "pod-name", getEnv(podNameConfigKey, ""), "The kubernetes pod name")
flag.StringVar(&config.PodNamespace, "pod-namespace", getEnv(podNamespaceConfigKey, ""), "The kubernetes pod namespace")
flag.StringVar(&config.MetadataURL, "metadata-url", getEnv(instanceMetadataURLConfigKey, defaultInstanceMetadataURL), "The URL of EC2 instance metadata. This shouldn't need to be changed unless you are testing.")
flag.BoolVar(&config.IgnoreDaemonSets, "ignore-daemon-sets", getBoolEnv(ignoreDaemonSetsConfigKey, true), "If true, ignore daemon sets and drain other pods when a spot interrupt is received.")
flag.BoolVar(&config.DeleteLocalData, "delete-local-data", getBoolEnv(deleteLocalDataConfigKey, true), "If true, do not drain pods that are using local node storage in emptyDir")
Expand Down Expand Up @@ -285,6 +288,7 @@ func (c Config) PrintJsonConfigArgs() {
Bool("dry_run", c.DryRun).
Str("node_name", c.NodeName).
Str("pod_name", c.PodName).
Str("pod_namespace", c.PodNamespace).
Str("metadata_url", c.MetadataURL).
Str("kubernetes_service_host", c.KubernetesServiceHost).
Str("kubernetes_service_port", c.KubernetesServicePort).
Expand Down Expand Up @@ -331,6 +335,7 @@ func (c Config) PrintHumanConfigArgs() {
"\tdry-run: %t,\n"+
"\tnode-name: %s,\n"+
"\tpod-name: %s,\n"+
"\tpod-namespace: %s,\n"+
"\tmetadata-url: %s,\n"+
"\tkubernetes-service-host: %s,\n"+
"\tkubernetes-service-port: %s,\n"+
Expand Down Expand Up @@ -368,6 +373,7 @@ func (c Config) PrintHumanConfigArgs() {
c.DryRun,
c.NodeName,
c.PodName,
c.PodNamespace,
c.MetadataURL,
c.KubernetesServiceHost,
c.KubernetesServicePort,
Expand Down
6 changes: 3 additions & 3 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func getDrainHelper(nthConfig config.Config) (*drain.Helper, error) {
Force: true,
GracePeriodSeconds: nthConfig.PodTerminationGracePeriod,
IgnoreAllDaemonSets: nthConfig.IgnoreDaemonSets,
AdditionalFilters: []drain.PodFilter{filterPodForDeletion(nthConfig.PodName)},
AdditionalFilters: []drain.PodFilter{filterPodForDeletion(nthConfig.PodName, nthConfig.PodNamespace)},
DeleteEmptyDirData: nthConfig.DeleteLocalData,
Timeout: time.Duration(nthConfig.NodeTerminationGracePeriod) * time.Second,
Out: log.Logger,
Expand Down Expand Up @@ -819,9 +819,9 @@ func getUptimeFunc(uptimeFile string) uptime.UptimeFuncType {
return uptime.Uptime
}

func filterPodForDeletion(podName string) func(pod corev1.Pod) drain.PodDeleteStatus {
func filterPodForDeletion(podName, podNamespace string) func(pod corev1.Pod) drain.PodDeleteStatus {
return func(pod corev1.Pod) drain.PodDeleteStatus {
if pod.Name == podName {
if pod.Name == podName && (pod.Namespace == podNamespace || podNamespace == "") {
return drain.MakePodDeleteStatusSkip()
}
return drain.MakePodDeleteStatusOkay()
Expand Down

0 comments on commit 01f4844

Please sign in to comment.