Skip to content

Commit

Permalink
OCM-6053 | feat: Day1 additional SG support for HCP
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterkepley committed Oct 1, 2024
1 parent c0ab25d commit 22ea392
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions cmd/create/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,9 +883,21 @@ func run(cmd *cobra.Command, _ []string) {

// validate flags for cluster admin
isHostedCP := args.hostedClusterEnabled
if isHostedCP && fedramp.Enabled() {
r.Reporter.Errorf("Fedramp does not currently support Hosted Control Plane clusters. Please use classic")
os.Exit(1)
if isHostedCP {
if fedramp.Enabled() {
r.Reporter.Errorf("Fedramp does not currently support Hosted Control Plane clusters. Please use classic")
os.Exit(1)
}
if cmd.Flag(securitygroups.InfraSecurityGroupFlag).Changed {
r.Reporter.Errorf("Cannot use '%s' flag with Hosted Control Plane clusters, only '%s' is "+
"supported", securitygroups.InfraSecurityGroupFlag, securitygroups.ComputeSecurityGroupFlag)
os.Exit(1)
}
if cmd.Flag(securitygroups.ControlPlaneSecurityGroupFlag).Changed {
r.Reporter.Errorf("Cannot use '%s' flag with Hosted Control Plane clusters, only '%s' is "+
"supported", securitygroups.ControlPlaneSecurityGroupFlag, securitygroups.ComputeSecurityGroupFlag)
os.Exit(1)
}
}

supportedRegions, err := r.OCMClient.GetDatabaseRegionList()
Expand Down Expand Up @@ -2571,20 +2583,23 @@ func run(cmd *cobra.Command, _ []string) {
r.Reporter.Errorf("There was a problem checking version compatibility: %v", err)
os.Exit(1)
}

additionalComputeSecurityGroupIds := args.additionalComputeSecurityGroupIds
getSecurityGroups(r, cmd, isVersionCompatibleComputeSgIds,
securitygroups.ComputeKind, useExistingVPC, isHostedCP, subnets,
securitygroups.ComputeKind, useExistingVPC, subnets,
subnetIDs, &additionalComputeSecurityGroupIds)

additionalInfraSecurityGroupIds := args.additionalInfraSecurityGroupIds
getSecurityGroups(r, cmd, isVersionCompatibleComputeSgIds,
securitygroups.InfraKind, useExistingVPC, isHostedCP, subnets,
subnetIDs, &additionalInfraSecurityGroupIds)

additionalControlPlaneSecurityGroupIds := args.additionalControlPlaneSecurityGroupIds
getSecurityGroups(r, cmd, isVersionCompatibleComputeSgIds,
securitygroups.ControlPlaneKind, useExistingVPC, isHostedCP, subnets,
subnetIDs, &additionalControlPlaneSecurityGroupIds)
if !isHostedCP {
getSecurityGroups(r, cmd, isVersionCompatibleComputeSgIds,
securitygroups.InfraKind, useExistingVPC, subnets,
subnetIDs, &additionalInfraSecurityGroupIds)

getSecurityGroups(r, cmd, isVersionCompatibleComputeSgIds,
securitygroups.ControlPlaneKind, useExistingVPC, subnets,
subnetIDs, &additionalControlPlaneSecurityGroupIds)
}

// Validate all remaining flags:
expiration, err := validateExpiration()
Expand Down Expand Up @@ -4119,7 +4134,7 @@ func outputClusterAdminDetails(r *rosa.Runtime, isClusterAdmin bool, createAdmin
}

func getSecurityGroups(r *rosa.Runtime, cmd *cobra.Command, isVersionCompatibleComputeSgIds bool,
kind string, useExistingVpc bool, isHostedCp bool, currentSubnets []ec2types.Subnet, subnetIds []string,
kind string, useExistingVpc bool, currentSubnets []ec2types.Subnet, subnetIds []string,
additionalSgIds *[]string) {
hasChangedSgIdsFlag := cmd.Flags().Changed(securitygroups.SgKindFlagMap[kind])
if hasChangedSgIdsFlag {
Expand All @@ -4128,12 +4143,6 @@ func getSecurityGroups(r *rosa.Runtime, cmd *cobra.Command, isVersionCompatibleC
securitygroups.SgKindFlagMap[kind])
os.Exit(1)
}
// HCP is still unsupported
if isHostedCp {
r.Reporter.Errorf("Parameter '%s' is not supported for Hosted Control Plane clusters",
securitygroups.SgKindFlagMap[kind])
os.Exit(1)
}
if !isVersionCompatibleComputeSgIds {
formattedVersion, err := versions.FormatMajorMinorPatch(
ocm.MinVersionForAdditionalComputeSecurityGroupIdsDay1,
Expand All @@ -4146,7 +4155,7 @@ func getSecurityGroups(r *rosa.Runtime, cmd *cobra.Command, isVersionCompatibleC
securitygroups.SgKindFlagMap[kind], formattedVersion)
os.Exit(1)
}
} else if interactive.Enabled() && isVersionCompatibleComputeSgIds && useExistingVpc && !isHostedCp {
} else if interactive.Enabled() && isVersionCompatibleComputeSgIds && useExistingVpc {
vpcId := ""
for _, subnet := range currentSubnets {
if awssdk.ToString(subnet.SubnetId) == subnetIds[0] {
Expand Down

0 comments on commit 22ea392

Please sign in to comment.