kubecost / cluster-turndown

Automated turndown of Kubernetes clusters on specific schedules.
Apache License 2.0
259 stars 23 forks source link

Update K8s library versions to v0.20.4 #37

Closed michaelmdresser closed 2 years ago

michaelmdresser commented 2 years ago

I'm working on adding some functionality to cluster-controller and I want to have newer versions of the K8s libs, which means turndown also needs to be updated with the new versions.

Updating the K8s libraries necessitated regenerating the CRD code, which is what most of the effort in this PR is dedicated to. Also, calls to the K8s API had to be updated with contexts and occasionally new options structs. I used context.TODO() for all calls that now require contexts.

There's quite a bit of extra detail in commit messages and comments.

@mbolt35 I rewrote generate.sh while I was debugging, and it ended up really similar to what you already had. I'm able to avoid doing the vendor voodoo in the old generate.sh script because the code has already been generated once AND because I don't delete ./pkg/generated before running go mod vendor like the old script does. If you think I should port my findings back to the old generate script, I'm fine with doing that. Let me know and let's chat to make sure we're on the same page.

TODO: PR to follow this one updating the version of the turndown images to v1.3.0.

Testing

Got a fun, unrelated issue out of testing this: https://github.com/kubecost/cluster-turndown/issues/38

Once I removed the PDB in my cluster, testing went smoothly. Test cluster is on GKE and has a single, non-autoscaling node pool.

Pre-turndown:

+ kubectl get nodes
NAME                                   STATUS   ROLES    AGE   VERSION
gke-michael-dev-pool-5-1acb2061-7p53   Ready    <none>   39m   v1.21.6-gke.1500
gke-michael-dev-pool-5-1acb2061-jkln   Ready    <none>   39m   v1.21.6-gke.1500
gke-michael-dev-pool-5-1acb2061-ldv7   Ready    <none>   39m   v1.21.6-gke.1500
+ echo

+ kubectl get tds -A
NAME                        STATE             NEXT TURNDOWN          NEXT TURN UP
k8s-libs-test-schedule-10   ScheduleSuccess   2022-02-16T19:08:00Z   2022-02-16T19:30:00Z

Post-turndown

+ date -u --rfc-3339=seconds
2022-02-16 19:27:47+00:00
+ kubectl get tds -A
NAME                        STATE             NEXT TURNDOWN          NEXT TURN UP
k8s-libs-test-schedule-10   ScheduleSuccess   2022-02-17T19:10:31Z   2022-02-16T19:30:00Z
+ echo

+ kubectl get pod -n turndown
NAME                                READY   STATUS    RESTARTS   AGE
cluster-turndown-86c8f76664-q5qvq   1/1     Running   0          18m
+ echo

+ kubectl get nodes
NAME                                             STATUS   ROLES    AGE   VERSION
gke-michael-dev-cluster-turndown-603900b3-wwbq   Ready    <none>   18m   v1.21.6-gke.1500

Post-turnup

→ date -u --rfc-3339=seconds
2022-02-16 19:54:51+00:00

→ kubectl get nodes                                                                            NAME                                             STATUS   ROLES    AGE   VERSION
gke-michael-dev-cluster-turndown-603900b3-wwbq   Ready    <none>   45m   v1.21.6-gke.1500
gke-michael-dev-pool-5-1acb2061-7cfz             Ready    <none>   21m   v1.21.6-gke.1500
gke-michael-dev-pool-5-1acb2061-ppvb             Ready    <none>   21m   v1.21.6-gke.1500
gke-michael-dev-pool-5-1acb2061-s009             Ready    <none>   21m   v1.21.6-gke.1500