Hi all, At the moment I have a cronjob that makes...
# kubernetes
n
Hi all, At the moment I have a cronjob that makes a snapshot every x minutes of a given pvc in a namespace. It does this by using a new image using the Pulumi cli image as a base image and adds a small Pulumi project that makes a new snapshot and deletes the previous one every-time it runs. Now this is all working fine, but there is one small issue. I need the value
Snapshot Handle
from the volumesnapshotcontent resource that is generated automatically when making a new snapshot. Because it's generated automatically it is not a pulumi resource, so as far as I know I can't get that value using pulumi. I wanted to use pulumi for it so I can save it as a stackreference and use it in different places in my infrastructure. I tried using query-kubernetes, because I can get the name of this volumesnapshotcontent from the volumesnapshot itself, but this package does not support crd's. Anyone an idea on how I could achieve this? (I thought of using a kubectl container to get it, but I would prefer to keep it all pulumi)
c
you could talk to the kubernetes api directly using your language of choice
put the code with your pulumi stack and then import the resource if neeeded
n
How can u talk to the kubernetes api directly using pulumi?
c
Pulumi allows you to execute any piece of code - even code that doesn't use it's API directly ``````
Example: https://www.pulumi.com/blog/deploying-mysql-schemas-using-dynamic-providers/ This example uses the
mysql-connector-python
module, it's referred to in requirements You can use any upstream code base and/or build your own that can be called when running your stack
n
Okay thanks, will take a look at dynamic providers!
c
If you're using python check out https://github.com/kubernetes-client/python
actually looks like there's one for each language
n
This can work really well for my purpose. I use typescript so the javascript version should fit me well. Then it won't be completely pulumi, but I can at-least write it in the same project. And also looks easier then using the dynamic providers.
Btw using the kubernets client was the way to go. I was able to get the information I needed like so:
Copy code
const k8sApi = kc.makeApiClient(CustomObjectsApi);
const volumeSnapshotContents = await k8sApi.listClusterCustomObject("<http://snapshot.storage.k8s.io|snapshot.storage.k8s.io>","v1","volumesnapshotcontents");