Skip to content

Commit 8a2f7c4

Browse files
refactor: introduce constants for DefaultServicePort and ForceRefreshAnnotation in ScalityUIComponent
1 parent f13d8e2 commit 8a2f7c4

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package scalityuicomponent
2+
3+
const (
4+
// DefaultServicePort is the default port used to connect to the UI component service
5+
DefaultServicePort = 80
6+
7+
// ForceRefreshAnnotation is the annotation key to trigger a force refresh of the configuration
8+
ForceRefreshAnnotation = "ui.scality.com/force-refresh"
9+
)

internal/controller/scalityuicomponent/controller.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ import (
2222
uiv1alpha1 "github.com/scality/ui-operator/api/v1alpha1"
2323
)
2424

25-
// DefaultServicePort is the default port used to connect to the UI component service
26-
const DefaultServicePort = 80
27-
2825
// MicroAppConfig represents the structure of the micro-app-configuration file
2926
type MicroAppConfig struct {
3027
Kind string `json:"kind"`
@@ -325,7 +322,7 @@ func (r *ScalityUIComponentReconciler) processUIComponentConfig(ctx context.Cont
325322

326323
// Check for force-refresh annotation
327324
if scalityUIComponent.Annotations != nil {
328-
if val, exists := scalityUIComponent.Annotations["ui.scality.com/force-refresh"]; exists && val == "true" {
325+
if val, exists := scalityUIComponent.Annotations[ForceRefreshAnnotation]; exists && val == "true" {
329326
needsFetch = true
330327
reasons = append(reasons, "force-refresh annotation present")
331328
}
@@ -483,7 +480,7 @@ func (r *ScalityUIComponentReconciler) removeForceRefreshAnnotation(ctx context.
483480
return
484481
}
485482

486-
if _, exists := scalityUIComponent.Annotations["ui.scality.com/force-refresh"]; !exists {
483+
if _, exists := scalityUIComponent.Annotations[ForceRefreshAnnotation]; !exists {
487484
return
488485
}
489486

@@ -502,11 +499,11 @@ func (r *ScalityUIComponentReconciler) removeForceRefreshAnnotation(ctx context.
502499
return nil
503500
}
504501

505-
if _, exists := fresh.Annotations["ui.scality.com/force-refresh"]; !exists {
502+
if _, exists := fresh.Annotations[ForceRefreshAnnotation]; !exists {
506503
return nil
507504
}
508505

509-
delete(fresh.Annotations, "ui.scality.com/force-refresh")
506+
delete(fresh.Annotations, ForceRefreshAnnotation)
510507
return r.Update(ctx, fresh)
511508
})
512509

internal/controller/scalityuicomponent/controller_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ var _ = Describe("ScalityUIComponent Controller", func() {
990990
if scalityUIComponent.Annotations == nil {
991991
scalityUIComponent.Annotations = make(map[string]string)
992992
}
993-
scalityUIComponent.Annotations["ui.scality.com/force-refresh"] = "true"
993+
scalityUIComponent.Annotations[ForceRefreshAnnotation] = "true"
994994
Expect(k8sClient.Update(ctx, scalityUIComponent)).To(Succeed())
995995

996996
By("Update mock to return different config")
@@ -1011,7 +1011,7 @@ var _ = Describe("ScalityUIComponent Controller", func() {
10111011

10121012
By("Verify force-refresh annotation was removed")
10131013
Expect(k8sClient.Get(ctx, typeNamespacedName, scalityUIComponent)).To(Succeed())
1014-
_, hasAnnotation := scalityUIComponent.Annotations["ui.scality.com/force-refresh"]
1014+
_, hasAnnotation := scalityUIComponent.Annotations[ForceRefreshAnnotation]
10151015
Expect(hasAnnotation).To(BeFalse(), "force-refresh annotation should be removed after fetch")
10161016

10171017
By("Fifth reconcile - no fetch (annotation removed, image unchanged)")
@@ -1028,7 +1028,7 @@ var _ = Describe("ScalityUIComponent Controller", func() {
10281028
Name: "test-force-refresh-failure",
10291029
Namespace: "default",
10301030
Annotations: map[string]string{
1031-
"ui.scality.com/force-refresh": "true",
1031+
ForceRefreshAnnotation: "true",
10321032
},
10331033
},
10341034
Spec: uiv1alpha1.ScalityUIComponentSpec{
@@ -1075,7 +1075,7 @@ var _ = Describe("ScalityUIComponent Controller", func() {
10751075

10761076
By("Verify force-refresh annotation was NOT removed on fetch failure (only removed on parse/validation failure)")
10771077
Expect(k8sClient.Get(ctx, typeNamespacedName, scalityUIComponent)).To(Succeed())
1078-
_, hasAnnotation := scalityUIComponent.Annotations["ui.scality.com/force-refresh"]
1078+
_, hasAnnotation := scalityUIComponent.Annotations[ForceRefreshAnnotation]
10791079
Expect(hasAnnotation).To(BeTrue(), "force-refresh annotation should remain on fetch failure for retry")
10801080
})
10811081

@@ -1087,7 +1087,7 @@ var _ = Describe("ScalityUIComponent Controller", func() {
10871087
Name: "test-force-refresh-parse-fail",
10881088
Namespace: "default",
10891089
Annotations: map[string]string{
1090-
"ui.scality.com/force-refresh": "true",
1090+
ForceRefreshAnnotation: "true",
10911091
},
10921092
},
10931093
Spec: uiv1alpha1.ScalityUIComponentSpec{
@@ -1132,7 +1132,7 @@ var _ = Describe("ScalityUIComponent Controller", func() {
11321132

11331133
By("Verify force-refresh annotation was removed on parse failure")
11341134
Expect(k8sClient.Get(ctx, typeNamespacedName, scalityUIComponent)).To(Succeed())
1135-
_, hasAnnotation := scalityUIComponent.Annotations["ui.scality.com/force-refresh"]
1135+
_, hasAnnotation := scalityUIComponent.Annotations[ForceRefreshAnnotation]
11361136
Expect(hasAnnotation).To(BeFalse(), "force-refresh annotation should be removed on parse failure")
11371137
})
11381138
})

0 commit comments

Comments
 (0)