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

Commit aef26b5

Browse files
committed
Refactor validate and verify
Make sure that validate and verify are present on cluster, environment and provider. This streamlines the use of both validate and verify as central calling point instead of all different methods.
1 parent e34d13c commit aef26b5

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

pkg/tarmak/cluster/cluster.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,7 @@ func NewFromConfig(environment interfaces.Environment, conf *clusterv1alpha1.Clu
5454
log: environment.Log().WithField("cluster", conf.Name),
5555
}
5656

57-
// validate instance pools
58-
if err := cluster.validateInstancePools(); err != nil {
59-
return nil, err
60-
}
61-
62-
// validate network setup
63-
if err := cluster.validateNetwork(); err != nil {
64-
return nil, err
65-
}
66-
67-
//validate logging
68-
if err := cluster.validateLoggingSinks(); err != nil {
57+
if err := cluster.Validate(); err != nil {
6958
return nil, err
7059
}
7160

@@ -184,6 +173,25 @@ func (c *Cluster) VerifyInstancePools() (result error) {
184173
return nil
185174
}
186175

176+
func (c *Cluster) Validate() (result error) {
177+
// validate instance pools
178+
if err := c.validateInstancePools(); err != nil {
179+
result = multierror.Append(result, err)
180+
}
181+
182+
// validate network setup
183+
if err := c.validateNetwork(); err != nil {
184+
result = multierror.Append(result, err)
185+
}
186+
187+
//validate logging
188+
if err := c.validateLoggingSinks(); err != nil {
189+
result = multierror.Append(result, err)
190+
}
191+
192+
return result
193+
}
194+
187195
// validate network configuration
188196
func (c *Cluster) validateNetwork() (result error) {
189197
// make the choice between deploying into existing VPC or creating a new one
@@ -305,10 +313,6 @@ func (c *Cluster) APITunnel() interfaces.Tunnel {
305313
)
306314
}
307315

308-
func (c *Cluster) Validate() error {
309-
return nil
310-
}
311-
312316
func (c *Cluster) Environment() interfaces.Environment {
313317
return c.environment
314318
}

pkg/tarmak/environment/environment.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ func (e *Environment) Validate() error {
286286
return result
287287
}
288288

289+
func (e *Environment) Verify() (result error) {
290+
return result
291+
}
292+
289293
func (e *Environment) WingTunnel() interfaces.Tunnel {
290294
return e.Tarmak().SSH().Tunnel(
291295
"bastion",

pkg/tarmak/interfaces/interfaces.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type Cluster interface {
2121
Variables() map[string]interface{}
2222
Environment() Environment
2323
Name() string
24-
Validate() error
2524
NetworkCIDR() *net.IPNet
2625
RemoteState() string
2726

@@ -53,6 +52,8 @@ type Cluster interface {
5352
UploadConfiguration() error
5453
// Verify the cluster (these contain more expensive calls like AWS calls
5554
Verify() error
55+
// Validate the cluster (these contain less expensive local calls)
56+
Validate() error
5657

5758
// This state is either destroy or apply
5859
GetState() string
@@ -70,6 +71,9 @@ type Environment interface {
7071
Location() string // this returns the location of the environment (e.g. the region)
7172
Variables() map[string]interface{}
7273
Provider() Provider
74+
// Verify the cluster (these contain more expensive calls like AWS calls
75+
Verify() error
76+
// Validate the cluster (these contain less expensive local calls)
7377
Validate() error
7478
Name() string
7579
HubName() string
@@ -102,6 +106,9 @@ type Provider interface {
102106
Name() string
103107
Parameters() map[string]string
104108
Region() string
109+
// Verify the cluster (these contain more expensive calls like AWS calls
110+
Verify() error
111+
// Validate the cluster (these contain less expensive local calls)
105112
Validate() error
106113
Reset() // reset all caches within the provider
107114
RemoteStateBucketName() string

pkg/tarmak/provider/amazon/amazon.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ func (a *Amazon) Validate() error {
356356

357357
}
358358

359+
func (a *Amazon) Verify() (result error) {
360+
return result
361+
}
362+
359363
func (a *Amazon) getAvailablityZoneByRegion() (zones []string, err error) {
360364
svc, err := a.EC2()
361365
if err != nil {

0 commit comments

Comments
 (0)