Create Worker(s) before Hub and reduce the grace periods

This commit is contained in:
M. Mert Yildiran 2023-02-15 00:43:30 +03:00
parent 7312addb65
commit 384f62f94f
No known key found for this signature in database
GPG Key ID: DA5D6DCBB758A461
3 changed files with 29 additions and 32 deletions

View File

@ -409,26 +409,6 @@ func postHubStarted(ctx context.Context, kubernetesProvider *kubernetes.Provider
"/echo",
)
// Create workers
err := kubernetes.CreateWorkers(
kubernetesProvider,
state.selfServiceAccountExists,
ctx,
config.Config.SelfNamespace,
config.Config.Tap.Resources.Worker,
config.Config.ImagePullPolicy(),
config.Config.ImagePullSecrets(),
config.Config.Tap.ServiceMesh,
config.Config.Tap.Tls,
config.Config.Tap.Debug,
)
if err != nil {
log.Error().Err(err).Send()
}
// Grace period
time.Sleep(time.Second)
// Storage limit
connector.PostStorageLimitToHub(config.Config.Tap.StorageLimitBytes())
@ -443,8 +423,7 @@ func postHubStarted(ctx context.Context, kubernetesProvider *kubernetes.Provider
// Scripting
connector.PostConsts(config.Config.Scripting.Consts)
var scripts []*misc.Script
scripts, err = config.Config.Scripting.GetScripts()
scripts, err := config.Config.Scripting.GetScripts()
if err != nil {
log.Error().Err(err).Send()
}

View File

@ -24,6 +24,7 @@ type Connector struct {
const DefaultRetries = 3
const DefaultTimeout = 2 * time.Second
const DefaultSleep = 100 * time.Millisecond
func NewConnector(url string, retries int, timeout time.Duration) *Connector {
return &Connector{
@ -45,7 +46,7 @@ func (connector *Connector) TestConnection(path string) error {
break
}
retriesLeft -= 1
time.Sleep(time.Second)
time.Sleep(5 * DefaultSleep)
}
if retriesLeft == 0 {
@ -81,7 +82,7 @@ func (connector *Connector) PostWorkerPodToHub(pod *v1.Pod) {
ok = true
log.Info().Interface("worker-pod", pod).Msg("Reported worker pod to Hub:")
}
time.Sleep(time.Second)
time.Sleep(DefaultSleep)
}
}
}
@ -111,7 +112,7 @@ func (connector *Connector) PostStorageLimitToHub(limit int64) {
ok = true
log.Info().Int("limit", int(limit)).Msg("Reported storage limit to Hub:")
}
time.Sleep(time.Second)
time.Sleep(DefaultSleep)
}
}
}
@ -144,7 +145,7 @@ func (connector *Connector) PostRegexToHub(regex string, namespaces []string) {
ok = true
log.Info().Str("regex", regex).Strs("namespaces", namespaces).Msg("Reported pod regex to Hub:")
}
time.Sleep(time.Second)
time.Sleep(DefaultSleep)
}
}
}
@ -175,7 +176,7 @@ func (connector *Connector) PostLicense(license string) {
ok = true
log.Info().Str("license", license).Msg("Reported license to Hub:")
}
time.Sleep(time.Second)
time.Sleep(DefaultSleep)
}
}
}
@ -202,7 +203,7 @@ func (connector *Connector) PostConsts(consts map[string]interface{}) {
ok = true
log.Info().Interface("consts", consts).Msg("Reported constants to Hub:")
}
time.Sleep(time.Second)
time.Sleep(DefaultSleep)
}
}
}
@ -241,7 +242,7 @@ func (connector *Connector) PostScript(script *misc.Script) (index int64, err er
log.Info().Int("index", int(index)).Interface("script", script).Msg("Created script on Hub:")
}
time.Sleep(time.Second)
time.Sleep(DefaultSleep)
}
}
@ -283,7 +284,7 @@ func (connector *Connector) PutScript(script *misc.Script, index int64) (err err
ok = true
log.Info().Int("index", int(index)).Interface("script", script).Msg("Updated script on Hub:")
}
time.Sleep(time.Second)
time.Sleep(DefaultSleep)
}
}
@ -321,7 +322,7 @@ func (connector *Connector) DeleteScript(index int64) (err error) {
ok = true
log.Info().Int("index", int(index)).Msg("Deleted script on Hub:")
}
time.Sleep(time.Second)
time.Sleep(DefaultSleep)
}
return
@ -343,6 +344,6 @@ func (connector *Connector) PostScriptDone() {
ok = true
log.Info().Msg("Reported POST script done to Hub:")
}
time.Sleep(time.Second)
time.Sleep(DefaultSleep)
}
}

View File

@ -32,6 +32,23 @@ func CreateHubResources(ctx context.Context, kubernetesProvider *kubernetes.Prov
serviceAccountName = ""
}
// Create workers
err = kubernetes.CreateWorkers(
kubernetesProvider,
selfServiceAccountExists,
ctx,
config.Config.SelfNamespace,
config.Config.Tap.Resources.Worker,
config.Config.ImagePullPolicy(),
config.Config.ImagePullSecrets(),
config.Config.Tap.ServiceMesh,
config.Config.Tap.Tls,
config.Config.Tap.Debug,
)
if err != nil {
log.Error().Err(err).Send()
}
opts := &kubernetes.PodOptions{
Namespace: selfNamespace,
PodName: kubernetes.HubPodName,