pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

WIP: Kubernetes support

Open leahneukirchen opened this issue 4 years ago • 8 comments

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.

leahneukirchen avatar Aug 21 '20 12:08 leahneukirchen

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%) :arrow_down:
pyinfra/api/connectors/util.py 79.31% <0.00%> (-0.69%) :arrow_down:
pyinfra/api/state.py 88.17% <0.00%> (-0.21%) :arrow_down:
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%) :arrow_up:

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.

codecov[bot] avatar Aug 21 '20 12:08 codecov[bot]

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

leahneukirchen avatar Aug 21 '20 13:08 leahneukirchen

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

leahneukirchen avatar Sep 04 '20 10:09 leahneukirchen

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 https://github.com/Fizzadar/pyinfra/commit/f45ea1a1d6871969b359fe29f6f3b55adbc60cde to stop this happening in future!

Fizzadar avatar Sep 06 '20 13:09 Fizzadar

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

leahneukirchen avatar Sep 06 '20 14:09 leahneukirchen

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

robsonpeixoto avatar Oct 07 '20 14:10 robsonpeixoto

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.

Fizzadar avatar Jan 13 '24 10:01 Fizzadar

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

leahneukirchen avatar Jan 13 '24 15:01 leahneukirchen