From dcc2d2c9c284614ef6afd5fe38c67e961794551d Mon Sep 17 00:00:00 2001 From: zwinnerman-fleetdm Date: Thu, 13 Jul 2023 20:51:16 -0400 Subject: [PATCH 1/2] Scale down and delete cronjob for expired instances --- .../sandbox/JITProvisioner/ingress_destroyer/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/infrastructure/sandbox/JITProvisioner/ingress_destroyer/main.go b/infrastructure/sandbox/JITProvisioner/ingress_destroyer/main.go index 15556a5d749..0c4fc2fe60c 100644 --- a/infrastructure/sandbox/JITProvisioner/ingress_destroyer/main.go +++ b/infrastructure/sandbox/JITProvisioner/ingress_destroyer/main.go @@ -66,14 +66,18 @@ func deleteIngress(id, name, ddbTable string) { log.Fatal(err) } - /* + // Delete the cronjob so we don't spam the database for stuff that's not running + _, err = clientset.BatchV1().CronJob("default").ApplyScale(context.Background(), id, v1.DeleteOptions{}) + if err != nil { + log.Fatal(err) + } + // Scale it down to save money time.sleep(60) _, err = clientset.AppsV1().Deployments("default").ApplyScale(context.Background(), id, &autoscaling.ScaleApplyConfiguration{Spec: &autoscaling.ScaleSpecApplyConfiguration{Replicas: new(int32)}}, v1.ApplyOptions{}) if err != nil { log.Fatal(err) } - */ svc := dynamodb.New(sess) err = updateFleetInstanceState(id, ddbTable, svc) From 21a10a5e60b6dfba3561ac0fbade738d0b2d7948 Mon Sep 17 00:00:00 2001 From: zwinnerman-fleetdm Date: Thu, 13 Jul 2023 20:55:23 -0400 Subject: [PATCH 2/2] fixup --- .../sandbox/JITProvisioner/ingress_destroyer/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/infrastructure/sandbox/JITProvisioner/ingress_destroyer/main.go b/infrastructure/sandbox/JITProvisioner/ingress_destroyer/main.go index 0c4fc2fe60c..cb4ab9fca44 100644 --- a/infrastructure/sandbox/JITProvisioner/ingress_destroyer/main.go +++ b/infrastructure/sandbox/JITProvisioner/ingress_destroyer/main.go @@ -6,13 +6,13 @@ import ( "log" "os" "os/exec" - //"time" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/dynamodb" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - //autoscaling "k8s.io/client-go/applyconfigurations/autoscaling/v1" + autoscaling "k8s.io/client-go/applyconfigurations/autoscaling/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" ) @@ -67,13 +67,13 @@ func deleteIngress(id, name, ddbTable string) { } // Delete the cronjob so we don't spam the database for stuff that's not running - _, err = clientset.BatchV1().CronJob("default").ApplyScale(context.Background(), id, v1.DeleteOptions{}) + err = clientset.BatchV1().CronJobs("default").Delete(context.Background(), id, v1.DeleteOptions{}) if err != nil { log.Fatal(err) } // Scale it down to save money - time.sleep(60) + time.Sleep(60) _, err = clientset.AppsV1().Deployments("default").ApplyScale(context.Background(), id, &autoscaling.ScaleApplyConfiguration{Spec: &autoscaling.ScaleSpecApplyConfiguration{Replicas: new(int32)}}, v1.ApplyOptions{}) if err != nil { log.Fatal(err)