Skip to content

Commit

Permalink
Fix unit test, make addon annotation constant
Browse files Browse the repository at this point in the history
Signed-off-by: Saswata Mukherjee <[email protected]>
  • Loading branch information
saswatamcode committed Dec 12, 2024
1 parent 1e32f01 commit c9b609e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -983,28 +983,28 @@ func getObservabilityAddon(c client.Client, namespace string,
found.Annotations = make(map[string]string)
}

if _, ok := found.Annotations["observability.open-cluster-management.io/addon-source"]; !ok {
found.Annotations["observability.open-cluster-management.io/addon-source"] = "mco"
if _, ok := found.Annotations[addonSourceAnnotation]; !ok {
found.Annotations[addonSourceAnnotation] = "mco"
}

if found.Annotations["observability.open-cluster-management.io/addon-source"] == "mco" {
if found.Annotations[addonSourceAnnotation] == "mco" {
addon.Spec.EnableMetrics = mco.Spec.ObservabilityAddonSpec.EnableMetrics
addon.Spec.Interval = mco.Spec.ObservabilityAddonSpec.Interval
addon.Spec.ScrapeSizeLimitBytes = mco.Spec.ObservabilityAddonSpec.ScrapeSizeLimitBytes
addon.Spec.Workers = mco.Spec.ObservabilityAddonSpec.Workers
addon.Spec.Resources = config.GetOBAResources(mco.Spec.ObservabilityAddonSpec, mco.Spec.InstanceSize)

addon.Annotations["observability.open-cluster-management.io/addon-source"] = "mco"
addon.Annotations[addonSourceAnnotation] = "mco"
}

if found.Annotations["observability.open-cluster-management.io/addon-source"] == "override" {
if found.Annotations[addonSourceAnnotation] == "override" {
addon.Spec.EnableMetrics = found.Spec.EnableMetrics
addon.Spec.Interval = found.Spec.Interval
addon.Spec.ScrapeSizeLimitBytes = found.Spec.ScrapeSizeLimitBytes
addon.Spec.Workers = found.Spec.Workers
addon.Spec.Resources = found.Spec.Resources

addon.Annotations["observability.open-cluster-management.io/addon-source"] = "override"
addon.Annotations[addonSourceAnnotation] = "override"
}

return addon, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

const (
pullSecretName = "test-pull-secret"
workSize = 13
workSize = 14
)

func init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
)

const (
obsAddonName = "observability-addon"
obsAddonFinalizer = "observability.open-cluster-management.io/addon-cleanup"
obsAddonName = "observability-addon"
obsAddonFinalizer = "observability.open-cluster-management.io/addon-cleanup"
addonSourceAnnotation = "observability.open-cluster-management.io/addon-source"
)

func deleteObsAddon(c client.Client, namespace string) error {
Expand Down Expand Up @@ -75,7 +76,7 @@ func createObsAddon(mco *mcov1beta2.MultiClusterObservability, c client.Client,
Name: obsAddonName,
Namespace: namespace,
Annotations: map[string]string{
"observability.open-cluster-management.io/addon-source": "mco",
addonSourceAnnotation: "mco",
},
Labels: map[string]string{
ownerLabelKey: ownerLabelValue,
Expand Down Expand Up @@ -112,7 +113,7 @@ func createObsAddon(mco *mcov1beta2.MultiClusterObservability, c client.Client,
}

// Check if existing addon was created by MCO
if found.Annotations != nil && found.Annotations["observability.open-cluster-management.io/addon-source"] == "mco" {
if found.Annotations != nil && found.Annotations[addonSourceAnnotation] == "mco" {
// Only update if specs are different
if found.Spec != ec.Spec {
found.Spec = ec.Spec
Expand Down

0 comments on commit c9b609e

Please sign in to comment.