Skip to content

Commit

Permalink
fix(hatchery): check maxWorker with MaxProv (#5063)
Browse files Browse the repository at this point in the history
* fix(hatchery): check maxWorker with MaxProv

this will avoid to start many workers (in the same time) if maxProv >
maxWorker in the configuration

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Mar 17, 2020
1 parent f483fe5 commit 268c001
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 66 deletions.
14 changes: 3 additions & 11 deletions engine/hatchery/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,11 @@ func (h *HatcheryKubernetes) getStartingConfig() (*clientcmdapi.Config, error) {
func (h *HatcheryKubernetes) CheckConfiguration(cfg interface{}) error {
hconfig, ok := cfg.(HatcheryConfiguration)
if !ok {
return fmt.Errorf("Invalid configuration")
}

if hconfig.API.HTTP.URL == "" {
return fmt.Errorf("API HTTP(s) URL is mandatory")
}

if hconfig.API.Token == "" {
return fmt.Errorf("API Token URL is mandatory")
return fmt.Errorf("Invalid hatchery kubernetes configuration")
}

if hconfig.Name == "" {
return fmt.Errorf("please enter a name in your kubernetes hatchery configuration")
if err := hconfig.Check(); err != nil {
return fmt.Errorf("Invalid hatchery kubernetes configuration: %v", err)
}

if hconfig.Namespace == "" {
Expand Down
14 changes: 3 additions & 11 deletions engine/hatchery/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,17 @@ func (h *HatcheryLocal) Status(ctx context.Context) sdk.MonitoringStatus {
func (h *HatcheryLocal) CheckConfiguration(cfg interface{}) error {
hconfig, ok := cfg.(HatcheryConfiguration)
if !ok {
return fmt.Errorf("Invalid configuration")
}

if hconfig.API.HTTP.URL == "" {
return fmt.Errorf("API HTTP(s) URL is mandatory")
return fmt.Errorf("Invalid hatchery local configuration")
}

if hconfig.API.Token == "" {
return fmt.Errorf("API Token URL is mandatory")
if err := hconfig.Check(); err != nil {
return fmt.Errorf("Invalid hatchery local configuration: %v", err)
}

if hconfig.Basedir == "" {
return fmt.Errorf("Invalid basedir directory")
}

if hconfig.Name == "" {
return fmt.Errorf("please enter a name in your local hatchery configuration")
}

if ok, err := sdk.DirectoryExists(hconfig.Basedir); !ok {
return fmt.Errorf("Basedir doesn't exist")
} else if err != nil {
Expand Down
14 changes: 3 additions & 11 deletions engine/hatchery/marathon/marathon.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,11 @@ func (h *HatcheryMarathon) Status(ctx context.Context) sdk.MonitoringStatus {
func (h *HatcheryMarathon) CheckConfiguration(cfg interface{}) error {
hconfig, ok := cfg.(HatcheryConfiguration)
if !ok {
return fmt.Errorf("Invalid configuration")
}

if hconfig.API.HTTP.URL == "" {
return fmt.Errorf("API HTTP(s) URL is mandatory")
return fmt.Errorf("Invalid hatchery marathon configuration")
}

if hconfig.API.Token == "" {
return fmt.Errorf("API Token URL is mandatory")
if err := hconfig.Check(); err != nil {
return fmt.Errorf("Invalid marathon configuration: %v", err)
}

if hconfig.MarathonURL == "" {
Expand All @@ -107,10 +103,6 @@ func (h *HatcheryMarathon) CheckConfiguration(cfg interface{}) error {
return fmt.Errorf("Marathon ID Prefix is mandatory")
}

if hconfig.Name == "" {
return fmt.Errorf("please enter a name in your marathon hatchery configuration")
}

h.marathonLabels = map[string]string{}
if hconfig.MarathonLabels != "" {
array := strings.Split(hconfig.MarathonLabels, ",")
Expand Down
14 changes: 3 additions & 11 deletions engine/hatchery/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,11 @@ func (h *HatcheryOpenstack) Status(ctx context.Context) sdk.MonitoringStatus {
func (h *HatcheryOpenstack) CheckConfiguration(cfg interface{}) error {
hconfig, ok := cfg.(HatcheryConfiguration)
if !ok {
return fmt.Errorf("Invalid configuration")
}

if hconfig.API.HTTP.URL == "" {
return fmt.Errorf("API HTTP(s) URL is mandatory")
return fmt.Errorf("Invalid hatchery openstack configuration")
}

if hconfig.API.Token == "" {
return fmt.Errorf("API Token URL is mandatory")
if err := hconfig.Check(); err != nil {
return fmt.Errorf("Invalid hatchery openstack configuration: %v", err)
}

if hconfig.Tenant == "" && hconfig.Domain == "" {
Expand All @@ -125,10 +121,6 @@ func (h *HatcheryOpenstack) CheckConfiguration(cfg interface{}) error {
return fmt.Errorf("Openstack-region is mandatory")
}

if hconfig.Name == "" {
return fmt.Errorf("please enter a name in your openstack hatchery configuration")
}

if hconfig.IPRange != "" {
ips, err := IPinRanges(context.Background(), hconfig.IPRange)
if err != nil {
Expand Down
14 changes: 3 additions & 11 deletions engine/hatchery/swarm/swarm_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,11 @@ func (h *HatcherySwarm) Status(ctx context.Context) sdk.MonitoringStatus {
func (h *HatcherySwarm) CheckConfiguration(cfg interface{}) error {
hconfig, ok := cfg.(HatcheryConfiguration)
if !ok {
return fmt.Errorf("Invalid configuration")
}

if hconfig.API.HTTP.URL == "" {
return fmt.Errorf("API HTTP(s) URL is mandatory")
return fmt.Errorf("Invalid hatchery swarm configuration")
}

if hconfig.API.Token == "" {
return fmt.Errorf("API Token URL is mandatory")
if err := hconfig.Check(); err != nil {
return fmt.Errorf("Invalid hatchery swarm configuration: %v", err)
}

if hconfig.WorkerTTL <= 0 {
Expand All @@ -103,9 +99,5 @@ func (h *HatcherySwarm) CheckConfiguration(cfg interface{}) error {
return fmt.Errorf("worker-memory must be > 1")
}

if hconfig.Name == "" {
return fmt.Errorf("please enter a name in your swarm hatchery configuration")
}

return nil
}
14 changes: 3 additions & 11 deletions engine/hatchery/vsphere/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,11 @@ func (h *HatcheryVSphere) Status(ctx context.Context) sdk.MonitoringStatus {
func (h *HatcheryVSphere) CheckConfiguration(cfg interface{}) error {
hconfig, ok := cfg.(HatcheryConfiguration)
if !ok {
return fmt.Errorf("Invalid configuration")
}

if hconfig.API.HTTP.URL == "" {
return fmt.Errorf("API HTTP(s) URL is mandatory")
return fmt.Errorf("Invalid hatchery vsphere configuration")
}

if hconfig.API.Token == "" {
return fmt.Errorf("API Token URL is mandatory")
if err := hconfig.Check(); err != nil {
return fmt.Errorf("Invalid hatchery vsphere configuration: %v", err)
}

if hconfig.VSphereUser == "" {
Expand All @@ -107,10 +103,6 @@ func (h *HatcheryVSphere) CheckConfiguration(cfg interface{}) error {
return fmt.Errorf("vsphere-datacenter is mandatory")
}

if hconfig.Name == "" {
return fmt.Errorf("please enter a name in your vsphere hatchery configuration")
}

return nil
}

Expand Down
27 changes: 27 additions & 0 deletions engine/service/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"context"
"crypto/rsa"
"fmt"
"time"

"github.com/ovh/cds/sdk"
Expand Down Expand Up @@ -63,6 +64,32 @@ type HatcheryCommonConfiguration struct {
} `toml:"logOptions" comment:"Hatchery Log Configuration" json:"logOptions"`
}

func (hcc HatcheryCommonConfiguration) Check() error {
if hcc.Provision.MaxConcurrentProvisioning > hcc.Provision.MaxWorker {
return fmt.Errorf("maxConcurrentProvisioning (value: %d) cannot be less than maxWorker (value: %d) ",
hcc.Provision.MaxConcurrentProvisioning, hcc.Provision.MaxWorker)
}

if hcc.Provision.MaxConcurrentRegistering > hcc.Provision.MaxWorker {
return fmt.Errorf("maxConcurrentRegistering (value: %d) cannot be less than maxWorker (value: %d) ",
hcc.Provision.MaxConcurrentRegistering, hcc.Provision.MaxWorker)
}

if hcc.API.HTTP.URL == "" {
return fmt.Errorf("API HTTP(s) URL is mandatory")
}

if hcc.API.Token == "" {
return fmt.Errorf("API Token URL is mandatory")
}

if hcc.Name == "" {
return fmt.Errorf("please enter a name in your hatchery configuration")
}

return nil
}

// Common is the struct representing a CDS µService
type Common struct {
Client cdsclient.Interface
Expand Down

0 comments on commit 268c001

Please sign in to comment.