Skip to content
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

WIP: Kubernetes support #416

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.

pyinfra/api/inventories/kubernetes.py Outdated Show resolved Hide resolved
pyinfra/api/inventories/kubernetes.py Outdated Show resolved Hide resolved
@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 Fizzadar added this to v1.2 -Q4 2020 in The Roadmap Sep 4, 2020
@Fizzadar Fizzadar moved this from v1.2 -Q4 2020 to v1.3 - Q1 2021 in The Roadmap Sep 4, 2020
@Fizzadar Fizzadar moved this from v1.3 - Q1 2021 to v1.2 -Q4 2020 in The Roadmap Sep 4, 2020
@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!

@Fizzadar Fizzadar moved this from v1.2.x -Q4 2020 to v2 - 20201 in The Roadmap Sep 18, 2020
@Fizzadar Fizzadar removed this from v2 - 20201 in The Roadmap Sep 18, 2020
@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
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.

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

Successfully merging this pull request may close these issues.

None yet

3 participants