diff --git a/pkg/controller/cloud.go b/pkg/controller/cloud.go index 8d9958b..defe7aa 100644 --- a/pkg/controller/cloud.go +++ b/pkg/controller/cloud.go @@ -88,7 +88,7 @@ var ( func getAccountFromSettings(admin string) (userid, token string, err error) { settingsUrl := fmt.Sprintf("http://settings-service.user-space-%s/api/account", admin) - client := resty.New().SetTimeout(2 * time.Second) + client := resty.New().SetTimeout(2 * time.Second).SetRetryCount(3) req := &ProxyRequest{ Op: "getAccount", @@ -158,7 +158,11 @@ func GetAwsAccountFromCloud(ctx context.Context, client dynamic.Interface, bucke return nil, err } - httpClient := resty.New().SetTimeout(15 * time.Second).SetDebug(true) + httpClient := resty.New().SetTimeout(15 * time.Second). + SetDebug(true). + SetRetryCount(5). + SetRetryWaitTime(30 * time.Second). + SetRetryMaxWaitTime(180 * time.Second) duration := 12 * time.Hour resp, err := httpClient.R(). SetFormData(map[string]string{ diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 766d5ce..b541c68 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -2,6 +2,7 @@ package controllers import ( "context" + "fmt" "os" "os/exec" "path/filepath" @@ -42,7 +43,8 @@ func NewNodeInitController(c client.Client, schema *runtime.Scheme, config *rest nic := &NodeInitController{Client: c, scheme: schema, cron: cron.New()} schedule := os.Getenv("SCHEDULE") if schedule == "" { - schedule = "0 */8 * * *" + // random timer schedule, to avoid too much concurrent api requets + schedule = fmt.Sprintf("%d */8 * * *", time.Now().Minute()) } if isMaster, _, err := nic.isMasterNode(config); err != nil { diff --git a/pkg/controller/controller_test.go b/pkg/controller/controller_test.go new file mode 100644 index 0000000..170990e --- /dev/null +++ b/pkg/controller/controller_test.go @@ -0,0 +1,11 @@ +package controllers + +import ( + "testing" +) + +func TestRand(t *testing.T) { + + println("schedule") + +}