Skip to content

Commit f4e9a82

Browse files
Merge pull request #26 from uselagoon/fix-idled-label
refactor: set idled label to false when not idled to keep label on resources
2 parents 21eedd8 + dedeb35 commit f4e9a82

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

handlers/unidler/checks.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,12 @@ func (h *Unidler) removeCodeFromIngress(ctx context.Context, ns string, opLog lo
8080
if newVals == nil || *newVals != value {
8181
mergePatch, _ := json.Marshal(map[string]interface{}{
8282
"metadata": map[string]interface{}{
83-
"labels": map[string]*string{
84-
"idling.amazee.io/idled": nil,
83+
"labels": map[string]interface{}{
84+
"idling.amazee.io/idled": "false",
8585
},
86-
"annotations": map[string]*string{
86+
"annotations": map[string]interface{}{
8787
"nginx.ingress.kubernetes.io/custom-http-errors": newVals,
8888
"idling.amazee.io/idled-at": nil,
89-
"idling.amazee.io/idled": nil,
9089
},
9190
},
9291
})

handlers/unidler/unidler.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,8 @@ func (h *Unidler) Unidle(ctx context.Context, namespace *corev1.Namespace, opLog
145145
}
146146
for _, deploy := range deployments.Items {
147147
// if the idled annotation is true
148-
av, aok := deploy.ObjectMeta.Annotations["idling.amazee.io/idled"]
149148
lv, lok := deploy.ObjectMeta.Labels["idling.amazee.io/idled"]
150-
if aok && av == "true" || lok && lv == "true" {
149+
if lok && lv == "true" {
151150
opLog.Info(fmt.Sprintf("Deployment %s - Replicas %v - %s", deploy.ObjectMeta.Name, *deploy.Spec.Replicas, namespace.Name))
152151
if *deploy.Spec.Replicas == 0 {
153152
// default to scaling to 1 replica
@@ -166,14 +165,13 @@ func (h *Unidler) Unidle(ctx context.Context, namespace *corev1.Namespace, opLog
166165
"replicas": newReplicas,
167166
},
168167
"metadata": map[string]interface{}{
169-
"labels": map[string]*string{
170-
"idling.amazee.io/idled": nil,
168+
"labels": map[string]interface{}{
169+
"idling.amazee.io/idled": "false",
171170
"idling.amazee.io/force-idled": nil,
172171
"idling.amazee.io/force-scaled": nil,
173172
},
174-
"annotations": map[string]*string{
173+
"annotations": map[string]interface{}{
175174
"idling.amazee.io/idled-at": nil,
176-
"idling.amazee.io/idled": nil,
177175
},
178176
},
179177
})

0 commit comments

Comments
 (0)