-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00b4029
commit 61146f8
Showing
7 changed files
with
160 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package keda | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
utils "github.com/Tchoupinax/k8s-labels-migrator/utils" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/dynamic" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
// https://keda.sh/docs/2.13/concepts/scaling-deployments | ||
|
||
func PauseScaledObject( | ||
crdClient *dynamic.DynamicClient, | ||
clientset *kubernetes.Clientset, | ||
deploymentName string, | ||
namespace string, | ||
) { | ||
crdGVR := schema.GroupVersionResource{ | ||
Group: "keda.sh", | ||
Version: "v1alpha1", | ||
Resource: "scaledobjects", | ||
} | ||
kedaScaledObject, _ := crdClient.Resource(crdGVR).Namespace(namespace).Get(context.TODO(), deploymentName, v1.GetOptions{}) | ||
if kedaScaledObject != nil { | ||
utils.LogInfo("Keda Scaled Object detected") | ||
// Add the annotation "autoscaling.keda.sh/paused" | ||
kedaScaledObject.Object["metadata"].(map[string]interface{})["annotations"].(map[string]interface{})["autoscaling.keda.sh/paused"] = "true" | ||
crdClient.Resource(crdGVR).Namespace(namespace).Update(context.TODO(), kedaScaledObject, v1.UpdateOptions{}) | ||
utils.LogSuccess("Keda object paused ⏸️") | ||
utils.LogBlocking("Waiting randomly 5 seconds to ensure keda controller registered the update") | ||
for range 5 { | ||
Check failure on line 36 in resources/keda.go GitHub Actions / lint
|
||
utils.LogBlockingDot() | ||
time.Sleep(1 * time.Second) | ||
} | ||
fmt.Println() | ||
} else { | ||
utils.LogInfo("Any Keda Scaled Object detected") | ||
} | ||
} | ||
|
||
func ResumeScaledObject( | ||
crdClient *dynamic.DynamicClient, | ||
clientset *kubernetes.Clientset, | ||
deploymentName string, | ||
namespace string, | ||
) { | ||
crdGVR := schema.GroupVersionResource{ | ||
Group: "keda.sh", | ||
Version: "v1alpha1", | ||
Resource: "scaledobjects", | ||
} | ||
kedaScaledObject, _ := crdClient.Resource(crdGVR).Namespace(namespace).Get(context.TODO(), deploymentName, v1.GetOptions{}) | ||
if kedaScaledObject != nil { | ||
utils.LogInfo("Keda Scaled Object detected") | ||
delete( | ||
kedaScaledObject.Object["metadata"].(map[string]interface{})["annotations"].(map[string]interface{}), | ||
"autoscaling.keda.sh/paused", | ||
) | ||
utils.LogSuccess("Keda object resumed ▶️") | ||
crdClient.Resource(crdGVR).Namespace(namespace).Update(context.TODO(), kedaScaledObject, v1.UpdateOptions{}) | ||
} else { | ||
utils.LogInfo("Any Keda Scaled Object detected") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.