Skip to content

Commit 8ef99a6

Browse files
authored
Merge pull request #3033 from olucasfreitas/OCM-17465
OCM-17465 | fix: created verification to when subnets are not set on proxy
2 parents 3cf3412 + 3c01b40 commit 8ef99a6

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

cmd/create/cluster/cmd.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,28 +2262,31 @@ func run(cmd *cobra.Command, _ []string) {
22622262
var subnets []ec2types.Subnet
22632263
mapSubnetIDToSubnet := make(map[string]aws.Subnet)
22642264
if useExistingVPC || subnetsProvided {
2265-
initialSubnets, err := getInitialValidSubnets(awsClient, subnetIDs, r.Reporter)
2266-
if err != nil {
2267-
r.Reporter.Errorf("Failed to get the list of subnets: %s", err)
2268-
os.Exit(1)
2265+
var initialSubnets []ec2types.Subnet
2266+
if len(subnetIDs) > 0 || subnetsProvided {
2267+
initialSubnets, err = getInitialValidSubnets(awsClient, subnetIDs, r.Reporter)
2268+
if err != nil {
2269+
_ = r.Reporter.Errorf("Failed to get the list of subnets: %s", err)
2270+
os.Exit(1)
2271+
}
22692272
}
22702273
if subnetsProvided {
22712274
useExistingVPC = true
22722275
}
22732276
_, machineNetwork, err := net.ParseCIDR(machineCIDR.String())
22742277
if err != nil {
2275-
r.Reporter.Errorf("Unable to parse machine CIDR")
2278+
_ = r.Reporter.Errorf("Unable to parse machine CIDR")
22762279
os.Exit(1)
22772280
}
22782281
_, serviceNetwork, err := net.ParseCIDR(serviceCIDR.String())
22792282
if err != nil {
2280-
r.Reporter.Errorf("Unable to parse service CIDR")
2283+
_ = r.Reporter.Errorf("Unable to parse service CIDR")
22812284
os.Exit(1)
22822285
}
22832286
var filterError error
22842287
subnets, filterError = filterCidrRangeSubnets(initialSubnets, machineNetwork, serviceNetwork, r)
22852288
if filterError != nil {
2286-
r.Reporter.Errorf("%s", filterError)
2289+
_ = r.Reporter.Errorf("%s", filterError)
22872290
os.Exit(1)
22882291
}
22892292

@@ -2295,7 +2298,7 @@ func run(cmd *cobra.Command, _ []string) {
22952298
if len(subnets) == 0 {
22962299
r.Reporter.Warnf("No subnets found in current region that are valid for the chosen CIDR ranges")
22972300
if isHostedCP {
2298-
r.Reporter.Errorf(
2301+
_ = r.Reporter.Errorf(
22992302
"All Hosted Control Plane clusters need a pre-configured VPC. Please check: %s",
23002303
createVpcForHcpDoc,
23012304
)
@@ -2316,7 +2319,7 @@ func run(cmd *cobra.Command, _ []string) {
23162319
for _, subnetArg := range subnetIDs {
23172320
// Check if subnet is in the excluded list of public subnets
23182321
if slices.Contains(excludedPublicSubnets, subnetArg) {
2319-
r.Reporter.Errorf("Cluster is set as private, cannot use public '%s'",
2322+
_ = r.Reporter.Errorf("Cluster is set as private, cannot use public '%s'",
23202323
subnetArg)
23212324
os.Exit(1)
23222325
}
@@ -2325,7 +2328,7 @@ func run(cmd *cobra.Command, _ []string) {
23252328
if !slices.ContainsFunc(subnets, func(subnet ec2types.Subnet) bool {
23262329
return awssdk.ToString(subnet.SubnetId) == subnetArg
23272330
}) {
2328-
r.Reporter.Errorf("Could not find the following subnet provided in region '%s': %s",
2331+
_ = r.Reporter.Errorf("Could not find the following subnet provided in region '%s': %s",
23292332
r.AWSClient.GetRegion(), subnetArg)
23302333
os.Exit(1)
23312334
}

tests/e2e/test_rosacli_cluster.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,30 @@ var _ = Describe("Edit cluster validation should", labels.Feature.Cluster, func(
693693
"ERR: node-drain-grace-period flag is not supported to hosted clusters"))
694694
})
695695

696+
It("should not use existing subnets when proxy set without subnet-ids - [id:45509]", labels.Medium, labels.Runtime.Day1Negative,
697+
func() {
698+
By("Create a cluster with proxy settings but without subnet-ids")
699+
clusterName := "cl-45509"
700+
output, err := clusterService.CreateDryRun(clusterName,
701+
"--http-proxy", "http://example.com",
702+
"--https-proxy", "https://example.com",
703+
"--no-proxy", "example.com",
704+
)
705+
706+
By("Should show warning about no subnets found and not error about subnet count")
707+
// The error should NOT be about subnet count mismatch
708+
Expect(output.String()).ShouldNot(ContainSubstring("The number of subnets for a 'single AZ' 'cluster' should be"))
709+
// It should show the proper warning or error about needing subnets for proxy configuration
710+
if err != nil {
711+
Expect(output.String()).Should(
712+
Or(
713+
ContainSubstring("No subnets found in current region that are valid for the chosen CIDR ranges"),
714+
ContainSubstring("Expected valid subnet IDs"),
715+
ContainSubstring("subnet"),
716+
))
717+
}
718+
})
719+
696720
It("can validate cluster proxy well - [id:46310]", labels.Medium, labels.Runtime.Day2, labels.FedRAMP,
697721
func() {
698722
By("Load the original cluster config")

0 commit comments

Comments
 (0)