Skip to content

Commit

Permalink
Merge pull request #2306 from arghosh93/transit_switch_default_subnet…
Browse files Browse the repository at this point in the history
…_overlap_check

[release-4.16] OCPBUGS-41551: Add subnet overlap check for transit switch subnet
  • Loading branch information
openshift-merge-bot[bot] authored Oct 4, 2024
2 parents 90d0591 + f7c67d4 commit 52c7ebe
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go-controller/pkg/clustermanager/clustermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ var _ = ginkgo.Describe("Cluster Manager", func() {
ginkgo.Context("Transit switch port IP allocations", func() {
ginkgo.It("Interconnect enabled", func() {
config.ClusterManager.V4TransitSwitchSubnet = "100.89.0.0/16"
config.ClusterManager.V6TransitSwitchSubnet = "fd98::/64"
config.ClusterManager.V6TransitSwitchSubnet = "fd99::/64"
app.Action = func(ctx *cli.Context) error {
nodes := []v1.Node{
{
Expand Down
11 changes: 6 additions & 5 deletions go-controller/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2046,18 +2046,19 @@ func buildClusterManagerConfig(ctx *cli.Context, cli, file *config) error {

// completeClusterManagerConfig completes the ClusterManager config by parsing raw values
// into their final form.
func completeClusterManagerConfig() error {
func completeClusterManagerConfig(allSubnets *configSubnets) error {
// Validate v4 and v6 transit switch subnets
v4IP, _, err := net.ParseCIDR(ClusterManager.V4TransitSwitchSubnet)
v4IP, v4TransitCIDR, err := net.ParseCIDR(ClusterManager.V4TransitSwitchSubnet)
if err != nil || utilnet.IsIPv6(v4IP) {
return fmt.Errorf("invalid transit switch v4 subnet specified, subnet: %s: error: %v", ClusterManager.V4TransitSwitchSubnet, err)
}

v6IP, _, err := net.ParseCIDR(ClusterManager.V6TransitSwitchSubnet)
v6IP, v6TransitCIDR, err := net.ParseCIDR(ClusterManager.V6TransitSwitchSubnet)
if err != nil || !utilnet.IsIPv6(v6IP) {
return fmt.Errorf("invalid transit switch v6 subnet specified, subnet: %s: error: %v", ClusterManager.V6TransitSwitchSubnet, err)
}

allSubnets.append(configSubnetTransit, v4TransitCIDR)
allSubnets.append(configSubnetTransit, v6TransitCIDR)
return nil
}

Expand Down Expand Up @@ -2337,7 +2338,7 @@ func completeConfig() error {
return err
}

if err := completeClusterManagerConfig(); err != nil {
if err := completeClusterManagerConfig(allSubnets); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions go-controller/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,12 +1223,12 @@ enable-pprof=true
cliArgs := []string{
app.Name,
"-cluster-manager-v4-transit-switch-subnet=100.89.0.0/16",
"-cluster-manager-v6-transit-switch-subnet=fd98::/64",
"-cluster-manager-v6-transit-switch-subnet=fd99::/64",
}
err := app.Run(cliArgs)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(ClusterManager.V4TransitSwitchSubnet).To(gomega.Equal("100.89.0.0/16"))
gomega.Expect(ClusterManager.V6TransitSwitchSubnet).To(gomega.Equal("fd98::/64"))
gomega.Expect(ClusterManager.V6TransitSwitchSubnet).To(gomega.Equal("fd99::/64"))
})
It("overrides config file and defaults with CLI options (multi-master)", func() {
kubeconfigFile, _, err := createTempFile("kubeconfig")
Expand Down
3 changes: 2 additions & 1 deletion go-controller/pkg/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ const (
configSubnetService configSubnetType = "service subnet"
configSubnetHybrid configSubnetType = "hybrid overlay subnet"
configSubnetMasquerade configSubnetType = "masquerade subnet"
configSubnetTransit configSubnetType = "transit switch subnet"
)

type configSubnet struct {
Expand All @@ -191,7 +192,7 @@ func newConfigSubnets() *configSubnets {
// append adds a single subnet to cs
func (cs *configSubnets) append(subnetType configSubnetType, subnet *net.IPNet) {
cs.subnets = append(cs.subnets, configSubnet{subnetType: subnetType, subnet: subnet})
if subnetType != configSubnetJoin && subnetType != configSubnetMasquerade {
if subnetType != configSubnetJoin && subnetType != configSubnetMasquerade && subnetType != configSubnetTransit {
if utilnet.IsIPv6CIDR(subnet) {
cs.v6[subnetType] = true
} else {
Expand Down

0 comments on commit 52c7ebe

Please sign in to comment.