From e3e6d4f637474637d0837585e4f7e9edbff00156 Mon Sep 17 00:00:00 2001 From: Liqian Luo <13264318+circy9@users.noreply.github.com> Date: Wed, 7 Sep 2022 18:08:06 -0700 Subject: [PATCH 1/2] fix bad kubebuilder annotation --- apis/v1alpha1/internalmembercluster_types.go | 4 ++-- config/crd/bases/fleet.azure.com_internalmemberclusters.yaml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apis/v1alpha1/internalmembercluster_types.go b/apis/v1alpha1/internalmembercluster_types.go index 2ef806454..6ba336176 100644 --- a/apis/v1alpha1/internalmembercluster_types.go +++ b/apis/v1alpha1/internalmembercluster_types.go @@ -38,8 +38,8 @@ type InternalMemberClusterSpec struct { State ClusterState `json:"state"` // +kubebuilder:default=60 - // +kubebuilder:validation:Minimum:1 - // +kubebuilder:validation:Maximum:600 + // +kubebuilder:validation:Minimum=1 + // +kubebuilder:validation:Maximum=600 // How often (in seconds) for the member cluster to send a heartbeat to the hub cluster. Default: 60 seconds. Min: 1 second. Max: 10 minutes. // +optional diff --git a/config/crd/bases/fleet.azure.com_internalmemberclusters.yaml b/config/crd/bases/fleet.azure.com_internalmemberclusters.yaml index 2660cad5e..92daafdaa 100644 --- a/config/crd/bases/fleet.azure.com_internalmemberclusters.yaml +++ b/config/crd/bases/fleet.azure.com_internalmemberclusters.yaml @@ -51,6 +51,8 @@ spec: a heartbeat to the hub cluster. Default: 60 seconds. Min: 1 second. Max: 10 minutes.' format: int32 + maximum: 600 + minimum: 1 type: integer state: description: 'The desired state of the member cluster. Possible values: From 675a3000cd7dd1258514e302681b03039b6a4cea Mon Sep 17 00:00:00 2001 From: Liqian Luo <13264318+circy9@users.noreply.github.com> Date: Wed, 7 Sep 2022 19:28:46 -0700 Subject: [PATCH 2/2] fix failed tests --- .../member_controller_integration_test.go | 2 +- pkg/utils/common.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/controllers/internalmembercluster/member_controller_integration_test.go b/pkg/controllers/internalmembercluster/member_controller_integration_test.go index fab125128..78b376e48 100644 --- a/pkg/controllers/internalmembercluster/member_controller_integration_test.go +++ b/pkg/controllers/internalmembercluster/member_controller_integration_test.go @@ -33,7 +33,7 @@ var _ = Describe("Test Internal Member Cluster Controller", func() { BeforeEach(func() { ctx = context.Background() - HBPeriod = int(utils.RandSecureInt(1000)) + HBPeriod = int(utils.RandSecureInt(600)) memberClusterName = "rand-" + strings.ToLower(utils.RandStr()) + "-mc" memberClusterNamespace = "fleet-" + memberClusterName memberClusterNamespacedName = types.NamespacedName{ diff --git a/pkg/utils/common.go b/pkg/utils/common.go index 9813fb6ef..4a57e15c3 100644 --- a/pkg/utils/common.go +++ b/pkg/utils/common.go @@ -8,7 +8,6 @@ package utils import ( "crypto/rand" "fmt" - "log" "math/big" "strings" "time" @@ -130,12 +129,17 @@ var ( } ) +// RandSecureInt returns a uniform random value in [1, max] or panic. +// Only use this in tests. func RandSecureInt(limit int64) int64 { + if limit <= 0 { + panic("limit <= 0") + } nBig, err := rand.Int(rand.Reader, big.NewInt(limit)) if err != nil { - log.Println(err) + panic(err) } - return nBig.Int64() + return nBig.Int64() + 1 } func RandStr() string {