Skip to content

Commit 268c001

Browse files
authored
fix(hatchery): check maxWorker with MaxProv (#5063)
* 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 <yvonnick.esnault@corp.ovh.com>
1 parent f483fe5 commit 268c001

File tree

7 files changed

+45
-66
lines changed

7 files changed

+45
-66
lines changed

engine/hatchery/kubernetes/kubernetes.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,11 @@ func (h *HatcheryKubernetes) getStartingConfig() (*clientcmdapi.Config, error) {
183183
func (h *HatcheryKubernetes) CheckConfiguration(cfg interface{}) error {
184184
hconfig, ok := cfg.(HatcheryConfiguration)
185185
if !ok {
186-
return fmt.Errorf("Invalid configuration")
187-
}
188-
189-
if hconfig.API.HTTP.URL == "" {
190-
return fmt.Errorf("API HTTP(s) URL is mandatory")
191-
}
192-
193-
if hconfig.API.Token == "" {
194-
return fmt.Errorf("API Token URL is mandatory")
186+
return fmt.Errorf("Invalid hatchery kubernetes configuration")
195187
}
196188

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

201193
if hconfig.Namespace == "" {

engine/hatchery/local/local.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,17 @@ func (h *HatcheryLocal) Status(ctx context.Context) sdk.MonitoringStatus {
9393
func (h *HatcheryLocal) CheckConfiguration(cfg interface{}) error {
9494
hconfig, ok := cfg.(HatcheryConfiguration)
9595
if !ok {
96-
return fmt.Errorf("Invalid configuration")
97-
}
98-
99-
if hconfig.API.HTTP.URL == "" {
100-
return fmt.Errorf("API HTTP(s) URL is mandatory")
96+
return fmt.Errorf("Invalid hatchery local configuration")
10197
}
10298

103-
if hconfig.API.Token == "" {
104-
return fmt.Errorf("API Token URL is mandatory")
99+
if err := hconfig.Check(); err != nil {
100+
return fmt.Errorf("Invalid hatchery local configuration: %v", err)
105101
}
106102

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

111-
if hconfig.Name == "" {
112-
return fmt.Errorf("please enter a name in your local hatchery configuration")
113-
}
114-
115107
if ok, err := sdk.DirectoryExists(hconfig.Basedir); !ok {
116108
return fmt.Errorf("Basedir doesn't exist")
117109
} else if err != nil {

engine/hatchery/marathon/marathon.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,11 @@ func (h *HatcheryMarathon) Status(ctx context.Context) sdk.MonitoringStatus {
8888
func (h *HatcheryMarathon) CheckConfiguration(cfg interface{}) error {
8989
hconfig, ok := cfg.(HatcheryConfiguration)
9090
if !ok {
91-
return fmt.Errorf("Invalid configuration")
92-
}
93-
94-
if hconfig.API.HTTP.URL == "" {
95-
return fmt.Errorf("API HTTP(s) URL is mandatory")
91+
return fmt.Errorf("Invalid hatchery marathon configuration")
9692
}
9793

98-
if hconfig.API.Token == "" {
99-
return fmt.Errorf("API Token URL is mandatory")
94+
if err := hconfig.Check(); err != nil {
95+
return fmt.Errorf("Invalid marathon configuration: %v", err)
10096
}
10197

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

110-
if hconfig.Name == "" {
111-
return fmt.Errorf("please enter a name in your marathon hatchery configuration")
112-
}
113-
114106
h.marathonLabels = map[string]string{}
115107
if hconfig.MarathonLabels != "" {
116108
array := strings.Split(hconfig.MarathonLabels, ",")

engine/hatchery/openstack/openstack.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,11 @@ func (h *HatcheryOpenstack) Status(ctx context.Context) sdk.MonitoringStatus {
9494
func (h *HatcheryOpenstack) CheckConfiguration(cfg interface{}) error {
9595
hconfig, ok := cfg.(HatcheryConfiguration)
9696
if !ok {
97-
return fmt.Errorf("Invalid configuration")
98-
}
99-
100-
if hconfig.API.HTTP.URL == "" {
101-
return fmt.Errorf("API HTTP(s) URL is mandatory")
97+
return fmt.Errorf("Invalid hatchery openstack configuration")
10298
}
10399

104-
if hconfig.API.Token == "" {
105-
return fmt.Errorf("API Token URL is mandatory")
100+
if err := hconfig.Check(); err != nil {
101+
return fmt.Errorf("Invalid hatchery openstack configuration: %v", err)
106102
}
107103

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

128-
if hconfig.Name == "" {
129-
return fmt.Errorf("please enter a name in your openstack hatchery configuration")
130-
}
131-
132124
if hconfig.IPRange != "" {
133125
ips, err := IPinRanges(context.Background(), hconfig.IPRange)
134126
if err != nil {

engine/hatchery/swarm/swarm_conf.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,11 @@ func (h *HatcherySwarm) Status(ctx context.Context) sdk.MonitoringStatus {
8585
func (h *HatcherySwarm) CheckConfiguration(cfg interface{}) error {
8686
hconfig, ok := cfg.(HatcheryConfiguration)
8787
if !ok {
88-
return fmt.Errorf("Invalid configuration")
89-
}
90-
91-
if hconfig.API.HTTP.URL == "" {
92-
return fmt.Errorf("API HTTP(s) URL is mandatory")
88+
return fmt.Errorf("Invalid hatchery swarm configuration")
9389
}
9490

95-
if hconfig.API.Token == "" {
96-
return fmt.Errorf("API Token URL is mandatory")
91+
if err := hconfig.Check(); err != nil {
92+
return fmt.Errorf("Invalid hatchery swarm configuration: %v", err)
9793
}
9894

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

106-
if hconfig.Name == "" {
107-
return fmt.Errorf("please enter a name in your swarm hatchery configuration")
108-
}
109-
110102
return nil
111103
}

engine/hatchery/vsphere/vsphere.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,11 @@ func (h *HatcheryVSphere) Status(ctx context.Context) sdk.MonitoringStatus {
8080
func (h *HatcheryVSphere) CheckConfiguration(cfg interface{}) error {
8181
hconfig, ok := cfg.(HatcheryConfiguration)
8282
if !ok {
83-
return fmt.Errorf("Invalid configuration")
84-
}
85-
86-
if hconfig.API.HTTP.URL == "" {
87-
return fmt.Errorf("API HTTP(s) URL is mandatory")
83+
return fmt.Errorf("Invalid hatchery vsphere configuration")
8884
}
8985

90-
if hconfig.API.Token == "" {
91-
return fmt.Errorf("API Token URL is mandatory")
86+
if err := hconfig.Check(); err != nil {
87+
return fmt.Errorf("Invalid hatchery vsphere configuration: %v", err)
9288
}
9389

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

110-
if hconfig.Name == "" {
111-
return fmt.Errorf("please enter a name in your vsphere hatchery configuration")
112-
}
113-
114106
return nil
115107
}
116108

engine/service/types.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package service
33
import (
44
"context"
55
"crypto/rsa"
6+
"fmt"
67
"time"
78

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

67+
func (hcc HatcheryCommonConfiguration) Check() error {
68+
if hcc.Provision.MaxConcurrentProvisioning > hcc.Provision.MaxWorker {
69+
return fmt.Errorf("maxConcurrentProvisioning (value: %d) cannot be less than maxWorker (value: %d) ",
70+
hcc.Provision.MaxConcurrentProvisioning, hcc.Provision.MaxWorker)
71+
}
72+
73+
if hcc.Provision.MaxConcurrentRegistering > hcc.Provision.MaxWorker {
74+
return fmt.Errorf("maxConcurrentRegistering (value: %d) cannot be less than maxWorker (value: %d) ",
75+
hcc.Provision.MaxConcurrentRegistering, hcc.Provision.MaxWorker)
76+
}
77+
78+
if hcc.API.HTTP.URL == "" {
79+
return fmt.Errorf("API HTTP(s) URL is mandatory")
80+
}
81+
82+
if hcc.API.Token == "" {
83+
return fmt.Errorf("API Token URL is mandatory")
84+
}
85+
86+
if hcc.Name == "" {
87+
return fmt.Errorf("please enter a name in your hatchery configuration")
88+
}
89+
90+
return nil
91+
}
92+
6693
// Common is the struct representing a CDS µService
6794
type Common struct {
6895
Client cdsclient.Interface

0 commit comments

Comments
 (0)