Skip to content

feat: adds flag to exclude nodes with specified annotation #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
7 changes: 7 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def parse_args(argv=sys.argv[1:]):
p.add_argument('--nodes', default=None, nargs='+', type=str, metavar='NODE',
help='act on the given nodes only')


p.add_argument('--exclude-nodes-with-annotation', default=None, type=str,
help='exclude nodes which has this annotation')
p.add_argument('--cordon-nodes-after', default='30d',
help='cordon nodes as old after they have been up for the given amount of time')
p.add_argument('--notify-after', default='1d',
Expand Down Expand Up @@ -252,6 +255,7 @@ def drain_node(v1, node: client.V1Node, all_pods: List[client.V1Pod], args):

def run():
args = parse_args()


try:
config.load_kube_config()
Expand All @@ -264,6 +268,8 @@ def run():
all_nodes = v1.list_node().items
if args.nodes is not None:
all_nodes = [node for node in all_nodes if node.metadata.name in args.nodes]
if args.exclude_nodes_with_annotation is not None:
all_nodes = [node for node in all_nodes if args.exclude_nodes_with_annotation not in node.metadata.annotations]

all_namespaces = v1.list_namespace().items
all_pods = [
Expand Down Expand Up @@ -293,3 +299,4 @@ def run():

if __name__ == "__main__":
run()