Skip to content

WIP: Kubernetes support #416

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 1 commit into
base: 1.x
Choose a base branch
from

Conversation

leahneukirchen
Copy link
Contributor

This is a WIP to create a Kubernetes connector and helpers for dynamic inventory.

The Kubernetes connector is modeled after the Docker connector and uses kubectl exec (and kubectl cp). Pods can be specified as @kubernetes/namespace/podname.

The dynamic inventory provides a method get_pods that can select pods by Kubernetes labels.

There are no docs or tests yet, first trying to see if this interests you. Else, I would also maintain this as an external project, but adding third-party connectors doesn't seem to be supported.

@codecov
Copy link

codecov bot commented Aug 21, 2020

Codecov Report

Merging #416 into master will decrease coverage by 1.16%.
The diff coverage is 21.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #416      +/-   ##
==========================================
- Coverage   92.73%   91.56%   -1.17%     
==========================================
  Files         105      106       +1     
  Lines        6192     6307     +115     
==========================================
+ Hits         5742     5775      +33     
- Misses        450      532      +82     
Impacted Files Coverage Δ
pyinfra/api/connectors/kubernetes.py 21.05% <21.05%> (ø)
pyinfra/api/facts.py 88.81% <0.00%> (-3.39%) ⬇️
pyinfra/api/connectors/util.py 79.31% <0.00%> (-0.69%) ⬇️
pyinfra/api/state.py 88.17% <0.00%> (-0.21%) ⬇️
pyinfra/facts/init.py 100.00% <0.00%> (ø)
pyinfra/operations/server.py 100.00% <0.00%> (ø)
pyinfra/facts/files.py 100.00% <0.00%> (+0.85%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b47eed0...b89c030. Read the comment docs.

@leahneukirchen
Copy link
Contributor Author

I don't know enough about Python 2 to fix this, please suggest.

Copy link
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leahneukirchen apologies for taking so long to get back to you on this - keen for this to be merged as an additional connector - it's never occurred to me the idea of targeting a live K8s pod.

Looks great so far, left a couple of comments!


Sidenote: it should be possible to use setuptools entrypoints such that external packages can add connectors without being part of pyinfra itself.

@leahneukirchen leahneukirchen force-pushed the kubernetes branch 2 times, most recently from 9b40b99 to 5186173 Compare September 4, 2020 09:36
@leahneukirchen
Copy link
Contributor Author

Not sure why this is failing now, seems unrelated to my PR.

@Fizzadar
Copy link
Member

Fizzadar commented Sep 6, 2020

This appears to be a linting issue now;

./pyinfra/api/connectors/kubernetes.py:64:32: C812 missing trailing comma
./pyinfra/api/connectors/kubernetes.py:69:42: C812 missing trailing comma
./pyinfra/api/connectors/kubernetes.py:75:34: C812 missing trailing comma
./pyinfra/api/connectors/kubernetes.py:216:19: C812 missing trailing comma
./pyinfra/api/connectors/kubernetes.py:219:63: Q000 Remove bad quotes

The verbose pytest output has basically buried it way up in the log - I've pushed f45ea1a to stop this happening in future!

@leahneukirchen
Copy link
Contributor Author

Argh, I ran a local copy of flake8, not the one in the venv. Thanks!

@robsonpeixoto
Copy link

Great! A suggestion is allow to pass the --context as a parameter. It's very useful when you are managing multiples clusters

@Fizzadar Fizzadar changed the base branch from current to next June 27, 2021 15:38
@Fizzadar Fizzadar force-pushed the next branch 4 times, most recently from c498185 to d899763 Compare July 21, 2021 12:48
@Fizzadar Fizzadar force-pushed the next branch 2 times, most recently from 025e1db to f5ad1f7 Compare July 31, 2021 11:37
@Fizzadar Fizzadar force-pushed the next branch 2 times, most recently from 5a9e175 to f01ba12 Compare October 15, 2021 10:07
@Fizzadar Fizzadar changed the base branch from next to current January 23, 2022 15:35
@Fizzadar Fizzadar changed the base branch from current to 1.x March 30, 2022 09:56
@Fizzadar
Copy link
Member

This is still a really cool idea but should definitely be managed as an external project. v2 & upcoming v3 both support this via setuptools entrypoints, I am going to provide an example project as part of the upcoming v3 release cycle at which point I shall link it here and close this PR.

@leahneukirchen
Copy link
Contributor Author

I'm not using k8s currently, but still think it could be useful to somebody.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants