Skip to content

Commit

Permalink
fix: fix bad kubebuilder annotation (Azure#270)
Browse files Browse the repository at this point in the history
* fix bad kubebuilder annotation

* fix failed tests
  • Loading branch information
circy9 authored Sep 8, 2022
1 parent d0ae29f commit a64f300
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions apis/v1alpha1/internalmembercluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/fleet.azure.com_internalmemberclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
10 changes: 7 additions & 3 deletions pkg/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package utils
import (
"crypto/rand"
"fmt"
"log"
"math/big"
"strings"
"time"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a64f300

Please sign in to comment.