@@ -11,18 +11,22 @@ import (
1111 "go.uber.org/zap"
1212)
1313
14- const instanceDescription = `A ROSA cluster must have the followings
15- - 3 masters running
16- - at least 2 infras running for single-AZ, 3 infras for multi-AZ`
14+ const instanceDescription = `A ROSA cluster must have the following:
15+ - 3 control plane instances running
16+ - at least 2 infra instances running for single-AZ, 3 infra instances for multi-AZ`
1717
1818var _ Component = & Instances {}
1919
20+ type MirrosaInstancesAPIClient interface {
21+ ec2.DescribeInstancesAPIClient
22+ }
23+
2024type Instances struct {
2125 log * zap.SugaredLogger
2226 InfraName string
2327 MultiAZ bool
2428
25- Ec2Client Ec2AwsApi
29+ Ec2Client MirrosaInstancesAPIClient
2630}
2731
2832func (c * Client ) NewInstances () Instances {
@@ -61,7 +65,7 @@ func (i Instances) Validate(ctx context.Context) error {
6165 }
6266
6367 // MASTER NODES VALIDATIONS
64- i .log .Info ("validating cluster's master nodes " )
68+ i .log .Info ("validating cluster's control plane instances " )
6569 var masters []types.Instance
6670 masterPattern := fmt .Sprintf ("%s-master" , i .InfraName )
6771 for _ , v := range instances {
@@ -74,18 +78,24 @@ func (i Instances) Validate(ctx context.Context) error {
7478
7579 // Each cluster has 3 master nodes by default - immutable
7680 if len (masters ) != 3 {
77- return fmt .Errorf ("there should be 3 masters belong to the cluster" )
81+ return fmt .Errorf ("there should be 3 control plane instances, found %d" , len ( masters ) )
7882 }
7983
8084 // Check if masters are running
8185 for _ , v := range masters {
8286 if v .State .Name != types .InstanceStateNameRunning {
83- return fmt .Errorf ("found non running master instance: %s" , * v .InstanceId )
87+ return fmt .Errorf ("found non running control plane instance: %s" , * v .InstanceId )
88+ }
89+
90+ if len (v .SecurityGroups ) != 1 {
91+ return fmt .Errorf ("one security group should be attached to %s: (%s-master-sg), got %d" , * v .InstanceId , i .InfraName , len (v .SecurityGroups ))
8492 }
93+
94+ // TODO: Check if the security group is the correct one, with tag "Name: ${infra_name}-master-sg"
8595 }
8696
8797 // INFRA NODES VALIDATIONS
88- i .log .Info ("validating cluster's infra nodes " )
98+ i .log .Info ("validating cluster's infra instances " )
8999 var infraNodes []types.Instance
90100 infraPattern := fmt .Sprintf ("%s-infra" , i .InfraName )
91101 for _ , v := range instances {
@@ -97,22 +107,28 @@ func (i Instances) Validate(ctx context.Context) error {
97107 }
98108
99109 if i .MultiAZ && len (infraNodes ) < 3 {
100- return fmt .Errorf ("there should be at least 3 infra nodes for multi-AZ clusters" )
110+ return fmt .Errorf ("there should be at least 3 infra instances for multi-AZ clusters" )
101111 }
102112
103113 if ! i .MultiAZ && len (infraNodes ) < 2 {
104- return fmt .Errorf ("there should be at least 2 infra nodes for single-AZ clusters" )
114+ return fmt .Errorf ("there should be at least 2 infra instances for single-AZ clusters" )
105115 }
106116
107117 // Check if infras are running
108118 for _ , v := range infraNodes {
109119 if v .State .Name != types .InstanceStateNameRunning {
110- return fmt .Errorf ("found non running infra node : %s" , * v .InstanceId )
120+ return fmt .Errorf ("found non running infra instances : %s" , * v .InstanceId )
111121 }
122+
123+ if len (v .SecurityGroups ) != 1 {
124+ return fmt .Errorf ("one security group should be attached to %s: (%s-worker-sg), got %d" , * v .InstanceId , i .InfraName , len (v .SecurityGroups ))
125+ }
126+
127+ // TODO: Check if the security group is the correct one, with tag "Name: ${infra_name}-worker-sg"
112128 }
113129
114130 // WORKER NODES VALIDATIONS
115- i .log .Info ("validating cluster's worker nodes " )
131+ i .log .Info ("validating cluster's worker instances " )
116132 var workerNodes []types.Instance
117133 workerPattern := fmt .Sprintf ("%s-worker" , i .InfraName )
118134 for _ , v := range instances {
@@ -133,6 +149,12 @@ func (i Instances) Validate(ctx context.Context) error {
133149 if v .State .Name != types .InstanceStateNameRunning {
134150 i .log .Infof ("[error but not blocker]: found non running worker nodes: %s" , * v .InstanceId )
135151 }
152+
153+ if len (v .SecurityGroups ) != 1 {
154+ return fmt .Errorf ("one security group should be attached to %s: (%s-worker-sg), got %d" , * v .InstanceId , i .InfraName , len (v .SecurityGroups ))
155+ }
156+
157+ // TODO: Check if the security group is the correct one, with tag "Name: ${infra_name}-worker-sg"
136158 }
137159
138160 return nil
@@ -143,5 +165,5 @@ func (i Instances) Documentation() string {
143165}
144166
145167func (i Instances ) FilterValue () string {
146- return "instance validation service "
168+ return "EC2 Instance "
147169}
0 commit comments