Skip to content

Commit

Permalink
operator: Make CRD availability timeout configurable
Browse files Browse the repository at this point in the history
This change allows to override the default 5m timeout with the
--crd-wait-timeout option.

Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
  • Loading branch information
vadorovsky authored and aanm committed Jun 26, 2020
1 parent f62bd84 commit 5dbe413
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
9 changes: 3 additions & 6 deletions operator/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (
"context"
"errors"
"fmt"
"time"

operatorOption "github.com/cilium/cilium/operator/option"

"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
Expand All @@ -30,10 +31,6 @@ import (
toolswatch "k8s.io/client-go/tools/watch"
)

const (
defaultTimeout = 5 * time.Minute
)

// waitForCRD waits for the given CRD to be available with the given context.
func waitForCRD(ctx context.Context, client clientset.Interface, name string) error {
log.Infof("Waiting for CRD %s to be available", name)
Expand Down Expand Up @@ -78,7 +75,7 @@ func waitForCRD(ctx context.Context, client clientset.Interface, name string) er
// after which cilium-agent should be ready. Returns an error when timeout
// is exceeded.
func WaitForCRD(client clientset.Interface, name string) error {
ctx, cancelFunc := context.WithTimeout(context.Background(), defaultTimeout)
ctx, cancelFunc := context.WithTimeout(context.Background(), operatorOption.Config.CRDWaitTimeout)
defer cancelFunc()
return waitForCRD(ctx, client, name)
}
2 changes: 1 addition & 1 deletion operator/crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *crdTestSuite) TestGetCRD(c *C) {
c.Assert(err, IsNil)

// Try to get existing CRD
err = WaitForCRD(client, "foo")
err = waitForCRD(context.TODO(), client, "foo")
c.Assert(err, IsNil)

// Try to get non-existing CRD
Expand Down
3 changes: 3 additions & 0 deletions operator/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,5 +285,8 @@ func init() {
flags.Duration(option.K8sHeartbeatTimeout, 30*time.Second, "Configures the timeout for api-server heartbeat, set to 0 to disable")
option.BindEnv(option.K8sHeartbeatTimeout)

flags.Duration(operatorOption.CRDWaitTimeout, 5*time.Minute, "Operator will exit if CRDs are not available within this duration upon startup")
option.BindEnv(operatorOption.CRDWaitTimeout)

viper.BindPFlags(flags)
}
7 changes: 7 additions & 0 deletions operator/option/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ const (

// AzureResourceGroup is the resource group of the nodes used for the cluster
AzureResourceGroup = "azure-resource-group"

// CRDWaitTimeout it the time after which Cilium CRDs have to be available.
CRDWaitTimeout = "crd-wait-timeout"
)

// OperatorConfig is the configuration used by the operator.
Expand Down Expand Up @@ -273,6 +276,9 @@ type OperatorConfig struct {

// AzureResourceGroup is the resource group of the nodes used for the cluster
AzureResourceGroup string

// CRDWaitTimeout it the time after which Cilium CRDs have to be available.
CRDWaitTimeout time.Duration
}

func (c *OperatorConfig) Populate() {
Expand All @@ -296,6 +302,7 @@ func (c *OperatorConfig) Populate() {
c.IPAMOperatorV4CIDR = viper.GetStringSlice(IPAMOperatorV4CIDR)
c.IPAMOperatorV6CIDR = viper.GetStringSlice(IPAMOperatorV6CIDR)
c.NodesGCInterval = viper.GetDuration(NodesGCInterval)
c.CRDWaitTimeout = viper.GetDuration(CRDWaitTimeout)

// AWS options

Expand Down

0 comments on commit 5dbe413

Please sign in to comment.