Skip to content

Commit

Permalink
Added hubsize annotation (#687)
Browse files Browse the repository at this point in the history
* Added hubsize annotation

Signed-off-by: Nathaniel Graham <[email protected]>

* Added unit test for getHubSize

Signed-off-by: Nathaniel Graham <[email protected]>

* removed duplicate test case

Signed-off-by: Nathaniel Graham <[email protected]>

---------

Signed-off-by: Nathaniel Graham <[email protected]>
  • Loading branch information
ngraham20 authored May 3, 2024
1 parent 0899a7f commit 60796cb
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 36 deletions.
56 changes: 28 additions & 28 deletions api/v1/multiclusterengine_methods_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v1_test

import (
"encoding/json"
"testing"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -174,30 +173,31 @@ func TestGetLegacyServiceMonitorName(t *testing.T) {
}
}

func TestHubSizeMarshal(t *testing.T) {
tests := []struct {
name string
yamlstring string
want api.HubSize
}{
{
name: "Marshals when setting hubSize to Large",
yamlstring: `{"hubSize": "Large"}`,
want: api.Large,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var out api.MultiClusterEngineSpec
t.Logf("spec before marshal: %v\n", out)
err := json.Unmarshal([]byte([]byte(tt.yamlstring)), &out)
t.Logf("spec after marshal: %v\n", out)
if err != nil {
t.Errorf("Unable to unmarshal yaml string: %v. %v", tt.yamlstring, err)
}
if out.HubSize != tt.want {
t.Errorf("Hubsize not desired. HubSize: %v, want: %v", out.HubSize, tt.want)
}
})
}
}
// TODO: put this back later
// func TestHubSizeMarshal(t *testing.T) {
// tests := []struct {
// name string
// yamlstring string
// want api.HubSize
// }{
// {
// name: "Marshals when setting hubSize to Large",
// yamlstring: `{"hubSize": "Large"}`,
// want: api.Large,
// },
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// var out api.MultiClusterEngineSpec
// t.Logf("spec before marshal: %v\n", out)
// err := json.Unmarshal([]byte([]byte(tt.yamlstring)), &out)
// t.Logf("spec after marshal: %v\n", out)
// if err != nil {
// t.Errorf("Unable to unmarshal yaml string: %v. %v", tt.yamlstring, err)
// }
// if out.HubSize != tt.want {
// t.Errorf("Hubsize not desired. HubSize: %v, want: %v", out.HubSize, tt.want)
// }
// })
// }
// }
15 changes: 8 additions & 7 deletions api/v1/multiclusterengine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ type MultiClusterEngineSpec struct {
// Set the nodeselectors
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// The resource allocation bucket for this hub to use.
// Small, Medium, Large, XLarge]. Defaults to Small if not specified.
//+kubebuilder:validation:Enum:=Small;Medium;Large;XLarge
//+kubebuilder:default:=Small
//+kubebuilder:validation:Type:=string
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Hub Size",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:hidden"}
HubSize HubSize `json:"hubSize,omitempty"`
// TODO: put this back later
// // The resource allocation bucket for this hub to use.
// // Small, Medium, Large, XLarge]. Defaults to Small if not specified.
// //+kubebuilder:validation:Enum:=Small;Medium;Large;XLarge
// //+kubebuilder:default:=Small
// //+kubebuilder:validation:Type:=string
// //+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Hub Size",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:hidden"}
// HubSize HubSize `json:"hubSize,omitempty"`

// Override pull secret for accessing MultiClusterEngine operand and endpoint images
//+operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Image Pull Secret",xDescriptors={"urn:alm:descriptor:io.kubernetes:Secret","urn:alm:descriptor:com.tectonic.ui:advanced"}
Expand Down
6 changes: 5 additions & 1 deletion pkg/rendering/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,11 @@ func injectValuesOverrides(values *Values, backplaneConfig *v1.MultiClusterEngin

values.Global.Namespace = backplaneConfig.Spec.TargetNamespace

values.Global.HubSize = backplaneConfig.Spec.HubSize
// TODO: remove this after backplaneConfig.Spec.HubSize is back
values.Global.HubSize = utils.GetHubSize(backplaneConfig)

// TODO: put this back later
// values.Global.HubSize = backplaneConfig.Spec.HubSize

values.Global.PullSecret = backplaneConfig.Spec.ImagePullSecret

Expand Down
17 changes: 17 additions & 0 deletions pkg/utils/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ var (
containing resource template overrides.
*/
AnnotationTemplateOverridesCM = "installer.multicluster.openshift.io/template-override-configmap"

/*
AnnotationHubSize is an annotation used in multiclusterhub to specify a hub size that can be
used by other components. MCE can use this standalone or inherit it from MCH
*/
AnnotationHubSize = "installer.multicluster.openshift.io/hub-size"
)

/*
Expand All @@ -73,6 +79,17 @@ func IsPaused(instance *backplanev1.MultiClusterEngine) bool {
return IsAnnotationTrue(instance, AnnotationMCEPause) || IsAnnotationTrue(instance, DeprecatedAnnotationMCEPause)
}

/*
GetHubSize gets the current hubsize, returning "Small" as default if the annotation is not found.
*/
func GetHubSize(instance *backplanev1.MultiClusterEngine) backplanev1.HubSize {
hubsize := getAnnotation(instance, AnnotationHubSize)
if hubsize != "" {
return backplanev1.HubSize(hubsize)
}
return backplanev1.Small
}

/*
IsAnnotationTrue checks if a specific annotation key in the given instance is set to "true".
*/
Expand Down
65 changes: 65 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,71 @@ func Test_deduplicate(t *testing.T) {
}
}

func TestGetHubSize(t *testing.T) {
tests := []struct {
name string
mce *backplanev1.MultiClusterEngine
want backplanev1.HubSize
}{
{
name: "get default",
mce: &backplanev1.MultiClusterEngine{},
want: backplanev1.Small,
},
{
name: "set hubsize Small",
mce: &backplanev1.MultiClusterEngine{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
AnnotationHubSize: "Small",
},
},
},
want: backplanev1.Small,
},
{
name: "set hubsize Medium",
mce: &backplanev1.MultiClusterEngine{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
AnnotationHubSize: "Medium",
},
},
},
want: backplanev1.Medium,
},
{
name: "set hubsize Large",
mce: &backplanev1.MultiClusterEngine{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
AnnotationHubSize: "Large",
},
},
},
want: backplanev1.Large,
},
{
name: "set hubsize XLarge",
mce: &backplanev1.MultiClusterEngine{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
AnnotationHubSize: "XLarge",
},
},
},
want: backplanev1.XLarge,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetHubSize(tt.mce); got != tt.want {
t.Errorf("GetHubSize() = %v, want %v", got, tt.want)
}
})
}
}

func TestGetHubType(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit 60796cb

Please sign in to comment.