Skip to content

Commit 01f4844

Browse files
authored
Don't skip evicting pods with same name but in different namespace (#746)
* Don't skip evicting pods with same name but in different namespace * Make --pod-namespace optional
1 parent ca72045 commit 01f4844

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pkg/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
dryRunConfigKey = "DRY_RUN"
3131
nodeNameConfigKey = "NODE_NAME"
3232
podNameConfigKey = "POD_NAME"
33+
podNamespaceConfigKey = "NAMESPACE"
3334
kubernetesServiceHostConfigKey = "KUBERNETES_SERVICE_HOST"
3435
kubernetesServicePortConfigKey = "KUBERNETES_SERVICE_PORT"
3536
deleteLocalDataConfigKey = "DELETE_LOCAL_DATA"
@@ -114,6 +115,7 @@ type Config struct {
114115
DryRun bool
115116
NodeName string
116117
PodName string
118+
PodNamespace string
117119
MetadataURL string
118120
IgnoreDaemonSets bool
119121
DeleteLocalData bool
@@ -173,6 +175,7 @@ func ParseCliArgs() (config Config, err error) {
173175
flag.BoolVar(&config.DryRun, "dry-run", getBoolEnv(dryRunConfigKey, false), "If true, only log if a node would be drained")
174176
flag.StringVar(&config.NodeName, "node-name", getEnv(nodeNameConfigKey, ""), "The kubernetes node name")
175177
flag.StringVar(&config.PodName, "pod-name", getEnv(podNameConfigKey, ""), "The kubernetes pod name")
178+
flag.StringVar(&config.PodNamespace, "pod-namespace", getEnv(podNamespaceConfigKey, ""), "The kubernetes pod namespace")
176179
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.")
177180
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.")
178181
flag.BoolVar(&config.DeleteLocalData, "delete-local-data", getBoolEnv(deleteLocalDataConfigKey, true), "If true, do not drain pods that are using local node storage in emptyDir")
@@ -285,6 +288,7 @@ func (c Config) PrintJsonConfigArgs() {
285288
Bool("dry_run", c.DryRun).
286289
Str("node_name", c.NodeName).
287290
Str("pod_name", c.PodName).
291+
Str("pod_namespace", c.PodNamespace).
288292
Str("metadata_url", c.MetadataURL).
289293
Str("kubernetes_service_host", c.KubernetesServiceHost).
290294
Str("kubernetes_service_port", c.KubernetesServicePort).
@@ -331,6 +335,7 @@ func (c Config) PrintHumanConfigArgs() {
331335
"\tdry-run: %t,\n"+
332336
"\tnode-name: %s,\n"+
333337
"\tpod-name: %s,\n"+
338+
"\tpod-namespace: %s,\n"+
334339
"\tmetadata-url: %s,\n"+
335340
"\tkubernetes-service-host: %s,\n"+
336341
"\tkubernetes-service-port: %s,\n"+
@@ -368,6 +373,7 @@ func (c Config) PrintHumanConfigArgs() {
368373
c.DryRun,
369374
c.NodeName,
370375
c.PodName,
376+
c.PodNamespace,
371377
c.MetadataURL,
372378
c.KubernetesServiceHost,
373379
c.KubernetesServicePort,

pkg/node/node.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ func getDrainHelper(nthConfig config.Config) (*drain.Helper, error) {
634634
Force: true,
635635
GracePeriodSeconds: nthConfig.PodTerminationGracePeriod,
636636
IgnoreAllDaemonSets: nthConfig.IgnoreDaemonSets,
637-
AdditionalFilters: []drain.PodFilter{filterPodForDeletion(nthConfig.PodName)},
637+
AdditionalFilters: []drain.PodFilter{filterPodForDeletion(nthConfig.PodName, nthConfig.PodNamespace)},
638638
DeleteEmptyDirData: nthConfig.DeleteLocalData,
639639
Timeout: time.Duration(nthConfig.NodeTerminationGracePeriod) * time.Second,
640640
Out: log.Logger,
@@ -819,9 +819,9 @@ func getUptimeFunc(uptimeFile string) uptime.UptimeFuncType {
819819
return uptime.Uptime
820820
}
821821

822-
func filterPodForDeletion(podName string) func(pod corev1.Pod) drain.PodDeleteStatus {
822+
func filterPodForDeletion(podName, podNamespace string) func(pod corev1.Pod) drain.PodDeleteStatus {
823823
return func(pod corev1.Pod) drain.PodDeleteStatus {
824-
if pod.Name == podName {
824+
if pod.Name == podName && (pod.Namespace == podNamespace || podNamespace == "") {
825825
return drain.MakePodDeleteStatusSkip()
826826
}
827827
return drain.MakePodDeleteStatusOkay()

0 commit comments

Comments
 (0)