Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 6437542

Browse files
committed
Verify -> Validate and use result.ErrorOrNil where appropriate
1 parent 1d29b20 commit 6437542

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

pkg/tarmak/cluster/cluster.go

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func NewFromConfig(environment interfaces.Environment, conf *clusterv1alpha1.Clu
7373
}
7474

7575
// setup instance pools
76-
var result error
76+
var result *multierror.Error
7777
for pos, _ := range cluster.conf.InstancePools {
7878
instancePool := cluster.conf.InstancePools[pos]
7979
// create instance pools
@@ -85,7 +85,7 @@ func NewFromConfig(environment interfaces.Environment, conf *clusterv1alpha1.Clu
8585
cluster.instancePools = append(cluster.instancePools, pool)
8686
}
8787

88-
return cluster, result
88+
return cluster, result.ErrorOrNil()
8989
}
9090

9191
func (c *Cluster) InstancePools() []interfaces.InstancePool {
@@ -120,7 +120,9 @@ func (c *Cluster) InstancePoolsMap() (instancePoolsMap map[string][]*clusterv1al
120120
}
121121

122122
// validate hub instancePool types
123-
func validateHubTypes(poolMap map[string][]*clusterv1alpha1.InstancePool, clusterType string) (result error) {
123+
func validateHubTypes(poolMap map[string][]*clusterv1alpha1.InstancePool, clusterType string) error {
124+
var result *multierror.Error
125+
124126
if len(poolMap[clusterv1alpha1.InstancePoolTypeBastion]) != 1 {
125127
result = multierror.Append(result, fmt.Errorf("a hub needs to have exactly one '%s' server pool", clusterv1alpha1.InstancePoolTypeBastion))
126128
}
@@ -129,11 +131,13 @@ func validateHubTypes(poolMap map[string][]*clusterv1alpha1.InstancePool, cluste
129131
result = multierror.Append(result, fmt.Errorf("a hub needs to have exactly one '%s' server pool", clusterv1alpha1.InstancePoolTypeVault))
130132
}
131133

132-
return result
134+
return result.ErrorOrNil()
133135
}
134136

135137
// validate cluster instancePool types
136-
func validateClusterTypes(poolMap map[string][]*clusterv1alpha1.InstancePool, clusterType string) (result error) {
138+
func validateClusterTypes(poolMap map[string][]*clusterv1alpha1.InstancePool, clusterType string) error {
139+
var result *multierror.Error
140+
137141
if len(poolMap[clusterv1alpha1.InstancePoolTypeEtcd]) != 1 {
138142
result = multierror.Append(result, fmt.Errorf("a %s needs to have exactly one '%s' server pool", clusterType, clusterv1alpha1.InstancePoolTypeEtcd))
139143
}
@@ -142,27 +146,30 @@ func validateClusterTypes(poolMap map[string][]*clusterv1alpha1.InstancePool, cl
142146
result = multierror.Append(result, fmt.Errorf("a %s needs to have more than one '%s' server pool", clusterType, clusterv1alpha1.InstancePoolTypeMaster))
143147
}
144148

145-
return result
149+
return result.ErrorOrNil()
146150
}
147151

148152
// validate server pools
149-
func (c *Cluster) validateInstancePools() (result error) {
153+
func (c *Cluster) validateInstancePools() error {
154+
var result *multierror.Error
155+
150156
for _, instancePool := range c.InstancePools() {
151157
err := instancePool.Validate()
152158
if err != nil {
153159
result = multierror.Append(result, err)
154160
}
155161
}
156-
return result
157-
}
158162

159-
// Verify cluster
160-
func (c *Cluster) Verify() (result error) {
161-
return c.VerifyInstancePools()
163+
if err := c.Environment().Provider().ValidateInstanceTypes(c.InstancePools()); err != nil {
164+
result = multierror.Append(result, err)
165+
}
166+
167+
return result.ErrorOrNil()
162168
}
163169

164-
// Verify instance pools
165-
func (c *Cluster) VerifyInstancePools() (result error) {
170+
// Verify cluster
171+
func (c *Cluster) Verify() error {
172+
// Verify instance pools
166173
imageIDs, err := c.ImageIDs()
167174
if err != nil {
168175
return fmt.Errorf("error getting image IDs: %s]", err)
@@ -175,10 +182,13 @@ func (c *Cluster) VerifyInstancePools() (result error) {
175182
return fmt.Errorf("error getting the image ID of %s", instancePool.TFName())
176183
}
177184
}
185+
178186
return nil
179187
}
180188

181-
func (c *Cluster) Validate() (result error) {
189+
func (c *Cluster) Validate() error {
190+
var result *multierror.Error
191+
182192
// validate instance pools
183193
if err := c.validateInstancePools(); err != nil {
184194
result = multierror.Append(result, err)
@@ -203,7 +213,7 @@ func (c *Cluster) Validate() (result error) {
203213
}
204214
}
205215

206-
return result
216+
return result.ErrorOrNil()
207217
}
208218

209219
// validate network configuration
@@ -228,7 +238,7 @@ func (c *Cluster) validateNetwork() (result error) {
228238
}
229239

230240
// validate logging configuration
231-
func (c *Cluster) validateLoggingSinks() (result error) {
241+
func (c *Cluster) validateLoggingSinks() error {
232242

233243
if c.Config().LoggingSinks != nil {
234244
for index, loggingSink := range c.Config().LoggingSinks {
@@ -250,15 +260,17 @@ func (c *Cluster) validateLoggingSinks() (result error) {
250260
}
251261

252262
// Validate APIServer
253-
func (c *Cluster) validateAPIServer() (result error) {
263+
func (c *Cluster) validateAPIServer() error {
264+
var result *multierror.Error
265+
254266
for _, cidr := range c.Config().Kubernetes.APIServer.AllowCIDRs {
255267
_, _, err := net.ParseCIDR(cidr)
256268
if err != nil {
257269
result = multierror.Append(result, fmt.Errorf("%s is not a valid CIDR format", cidr))
258270
}
259271
}
260272

261-
return result
273+
return result.ErrorOrNil()
262274
}
263275

264276
// Determine if this Cluster is a cluster or hub, single or multi environment

pkg/tarmak/interfaces/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ type Provider interface {
127127
AskEnvironmentLocation(Initialize) (string, error)
128128
AskInstancePoolZones(Initialize) (zones []string, err error)
129129
UploadConfiguration(Cluster, io.ReadSeeker) error
130-
VerifyInstanceTypes(intstancePools []InstancePool) error
130+
ValidateInstanceTypes(intstancePools []InstancePool) error
131131
}
132132

133133
type Tarmak interface {

pkg/tarmak/provider/amazon/amazon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func (a *Amazon) vaultSession() (*session.Session, error) {
505505
return sess, nil
506506
}
507507

508-
func (a *Amazon) VerifyInstanceTypes(instancePools []interfaces.InstancePool) error {
508+
func (a *Amazon) ValidateInstanceTypes(instancePools []interfaces.InstancePool) error {
509509
var result *multierror.Error
510510

511511
svc, err := a.EC2()

0 commit comments

Comments
 (0)