Skip to content

Commit

Permalink
refactor: set idled label to false when not idled to keep label on re…
Browse files Browse the repository at this point in the history
…sources
  • Loading branch information
shreddedbacon committed Apr 26, 2024
1 parent c856d24 commit 4d6d7ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
7 changes: 3 additions & 4 deletions handlers/unidler/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@ func (h *Unidler) removeCodeFromIngress(ctx context.Context, ns string, opLog lo
if newVals == nil || *newVals != value {
mergePatch, _ := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]*string{
"idling.amazee.io/idled": nil,
"labels": map[string]interface{}{
"idling.amazee.io/idled": "false",
},
"annotations": map[string]*string{
"annotations": map[string]interface{}{
"nginx.ingress.kubernetes.io/custom-http-errors": newVals,
"idling.amazee.io/idled-at": nil,
"idling.amazee.io/idled": nil,
},
},
})
Expand Down
10 changes: 4 additions & 6 deletions handlers/unidler/unidler.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,8 @@ func (h *Unidler) Unidle(ctx context.Context, namespace *corev1.Namespace, opLog
}
for _, deploy := range deployments.Items {
// if the idled annotation is true
av, aok := deploy.ObjectMeta.Annotations["idling.amazee.io/idled"]
lv, lok := deploy.ObjectMeta.Labels["idling.amazee.io/idled"]
if aok && av == "true" || lok && lv == "true" {
if lok && lv == "true" {
opLog.Info(fmt.Sprintf("Deployment %s - Replicas %v - %s", deploy.ObjectMeta.Name, *deploy.Spec.Replicas, namespace.Name))
if *deploy.Spec.Replicas == 0 {
// default to scaling to 1 replica
Expand All @@ -166,14 +165,13 @@ func (h *Unidler) Unidle(ctx context.Context, namespace *corev1.Namespace, opLog
"replicas": newReplicas,
},
"metadata": map[string]interface{}{
"labels": map[string]*string{
"idling.amazee.io/idled": nil,
"labels": map[string]interface{}{
"idling.amazee.io/idled": "false",
"idling.amazee.io/force-idled": nil,
"idling.amazee.io/force-scaled": nil,
},
"annotations": map[string]*string{
"annotations": map[string]interface{}{
"idling.amazee.io/idled-at": nil,
"idling.amazee.io/idled": nil,
},
},
})
Expand Down

0 comments on commit 4d6d7ff

Please sign in to comment.