Skip to content

Commit

Permalink
Fix worker SG assocation when custom vpc is used
Browse files Browse the repository at this point in the history
Signed-off-by: Aswin Suryanarayanan <[email protected]>
  • Loading branch information
aswinsuryan authored and tpantelis committed Sep 26, 2024
1 parent da4efa4 commit f935ffc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/aws/gw-machineset.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ spec:
- filters:
- name: tag:Name
values:
- {{.InfraID}}-worker-sg
- {{.NodeSG}}
- {{.SecurityGroup}}
subnet:
filters:
Expand Down
20 changes: 20 additions & 0 deletions pkg/aws/ocpgwdeployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ type machineSetConfig struct {
Region string
SecurityGroup string
PublicSubnet string
NodeSG string
}

func (d *ocpGatewayDeployer) findAMIID(vpcID string) (string, error) {
Expand Down Expand Up @@ -277,6 +278,25 @@ func (d *ocpGatewayDeployer) loadGatewayYAML(gatewaySecurityGroup, amiID string,
PublicSubnet: extractName(publicSubnet.Tags),
}

if id, exists := d.aws.cloudConfig[WorkerSecurityGroupIDKey]; exists {
if workerGroupIDStr, ok := id.(string); ok && workerGroupIDStr != "" {
workerSecurityGroup, err := d.aws.getSecurityGroupByID(workerGroupIDStr)
if err != nil {
return nil, errors.Wrapf(err, "error finding the worker security group with ID %s", workerGroupIDStr)
}

if workerSecurityGroup.GroupName == nil {
return nil, errors.Errorf("security group with ID %s has no group name", workerGroupIDStr)
}

tplVars.NodeSG = *workerSecurityGroup.GroupName
} else {
return nil, errors.New("worker Security Group ID must be a valid non-empty string")
}
} else {
tplVars.NodeSG = d.aws.infraID + d.aws.nodeSGSuffix
}

err = tpl.Execute(&buf, tplVars)
if err != nil {
return nil, errors.Wrap(err, "error executing the template")
Expand Down

0 comments on commit f935ffc

Please sign in to comment.