Skip to content

Commit 1256631

Browse files
Merge pull request #9579 from eggfoobar/fix-infra-topology-default
OCPEDGE-1513: Fixed topology logic for 2-node installs and added unit tests
2 parents 84affa9 + 401d212 commit 1256631

File tree

2 files changed

+153
-2
lines changed

2 files changed

+153
-2
lines changed

pkg/asset/manifests/topologies.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func determineTopologies(installConfig *types.InstallConfig) (controlPlaneTopolo
1616
if controlPlaneReplicas == 2 {
1717
controlPlaneTopology = configv1.DualReplicaTopologyMode
1818

19-
if ptr.Deref(installConfig.Arbiter.Replicas, 0) != 0 {
19+
if installConfig.Arbiter != nil && ptr.Deref(installConfig.Arbiter.Replicas, 0) != 0 {
2020
controlPlaneTopology = configv1.HighlyAvailableArbiterMode
2121
}
2222
} else if controlPlaneReplicas < 3 {
@@ -30,7 +30,14 @@ func determineTopologies(installConfig *types.InstallConfig) (controlPlaneTopolo
3030

3131
switch numOfWorkers {
3232
case 0:
33-
infrastructureTopology = controlPlaneTopology
33+
// Two node deployments with 0 workers mean that the control plane nodes are treated as workers
34+
// in that situation we have decided that it is appropriate to set the infrastructureTopology to HA.
35+
// All other configuration for different worker count are respected with the original intention.
36+
if controlPlaneReplicas == 2 {
37+
infrastructureTopology = configv1.HighlyAvailableTopologyMode
38+
} else {
39+
infrastructureTopology = controlPlaneTopology
40+
}
3441
case 1:
3542
infrastructureTopology = configv1.SingleReplicaTopologyMode
3643
default:
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package manifests
2+
3+
import (
4+
"testing"
5+
6+
"k8s.io/utils/ptr"
7+
8+
configv1 "github.com/openshift/api/config/v1"
9+
"github.com/openshift/installer/pkg/types"
10+
)
11+
12+
func Test_DetermineTopologies(t *testing.T) {
13+
testCases := []struct {
14+
desc string
15+
installConfig *types.InstallConfig
16+
expectedControlPlane configv1.TopologyMode
17+
expectedInfra configv1.TopologyMode
18+
}{
19+
{
20+
desc: "should default to HA for both infra and control plane when 3 control replicas",
21+
installConfig: &types.InstallConfig{
22+
ControlPlane: &types.MachinePool{
23+
Replicas: ptr.To[int64](3),
24+
},
25+
Compute: []types.MachinePool{},
26+
},
27+
expectedControlPlane: configv1.HighlyAvailableTopologyMode,
28+
expectedInfra: configv1.HighlyAvailableTopologyMode,
29+
},
30+
{
31+
desc: "should default to Single for both infra and control plane when 1 control replicas",
32+
installConfig: &types.InstallConfig{
33+
ControlPlane: &types.MachinePool{
34+
Replicas: ptr.To[int64](1),
35+
},
36+
Compute: []types.MachinePool{},
37+
},
38+
expectedControlPlane: configv1.SingleReplicaTopologyMode,
39+
expectedInfra: configv1.SingleReplicaTopologyMode,
40+
},
41+
{
42+
desc: "should default infra to HA and controlPlane to Single for 1 control replicas and 3 worker replicas",
43+
installConfig: &types.InstallConfig{
44+
ControlPlane: &types.MachinePool{
45+
Replicas: ptr.To[int64](1),
46+
},
47+
Compute: []types.MachinePool{
48+
{
49+
Replicas: ptr.To[int64](3),
50+
},
51+
},
52+
},
53+
expectedControlPlane: configv1.SingleReplicaTopologyMode,
54+
expectedInfra: configv1.HighlyAvailableTopologyMode,
55+
},
56+
{
57+
desc: "should default infra to Single and controlPlane to Single for 1 control replicas and 1 worker replicas",
58+
installConfig: &types.InstallConfig{
59+
ControlPlane: &types.MachinePool{
60+
Replicas: ptr.To[int64](1),
61+
},
62+
Compute: []types.MachinePool{
63+
{
64+
Replicas: ptr.To[int64](1),
65+
},
66+
},
67+
},
68+
expectedControlPlane: configv1.SingleReplicaTopologyMode,
69+
expectedInfra: configv1.SingleReplicaTopologyMode,
70+
},
71+
{
72+
desc: "should default infra to HA and controlPlane to DualReplica for 2 control replicas",
73+
installConfig: &types.InstallConfig{
74+
ControlPlane: &types.MachinePool{
75+
Replicas: ptr.To[int64](2),
76+
},
77+
Compute: []types.MachinePool{},
78+
},
79+
expectedControlPlane: configv1.DualReplicaTopologyMode,
80+
expectedInfra: configv1.HighlyAvailableTopologyMode,
81+
},
82+
{
83+
desc: "should default infra to HA and controlPlane to Arbiter for 2 control replicas and 1 arbiter",
84+
installConfig: &types.InstallConfig{
85+
Arbiter: &types.MachinePool{
86+
Replicas: ptr.To[int64](1),
87+
},
88+
ControlPlane: &types.MachinePool{
89+
Replicas: ptr.To[int64](2),
90+
},
91+
Compute: []types.MachinePool{},
92+
},
93+
expectedControlPlane: configv1.HighlyAvailableArbiterMode,
94+
expectedInfra: configv1.HighlyAvailableTopologyMode,
95+
},
96+
}
97+
for _, tc := range testCases {
98+
t.Run(tc.desc, func(t *testing.T) {
99+
controlPlane, infra := determineTopologies(tc.installConfig)
100+
if controlPlane != tc.expectedControlPlane {
101+
t.Fatalf("expected control plane topology to be %s but got %s", tc.expectedControlPlane, controlPlane)
102+
}
103+
if infra != tc.expectedInfra {
104+
t.Fatalf("expected infra topology to be %s but got %s", tc.expectedInfra, infra)
105+
}
106+
})
107+
}
108+
}
109+
110+
func Test_DetermineCPUPartitioning(t *testing.T) {
111+
testCases := []struct {
112+
desc string
113+
installConfig *types.InstallConfig
114+
expectedPartitioningMode configv1.CPUPartitioningMode
115+
}{
116+
{
117+
desc: "should return AllNodes",
118+
installConfig: &types.InstallConfig{
119+
CPUPartitioning: types.CPUPartitioningAllNodes,
120+
},
121+
expectedPartitioningMode: configv1.CPUPartitioningAllNodes,
122+
},
123+
{
124+
desc: "should return None",
125+
installConfig: &types.InstallConfig{
126+
CPUPartitioning: types.CPUPartitioningNone,
127+
},
128+
expectedPartitioningMode: configv1.CPUPartitioningNone,
129+
},
130+
{
131+
desc: "should default to None",
132+
installConfig: &types.InstallConfig{},
133+
expectedPartitioningMode: configv1.CPUPartitioningNone,
134+
},
135+
}
136+
for _, tc := range testCases {
137+
t.Run(tc.desc, func(t *testing.T) {
138+
mode := determineCPUPartitioning(tc.installConfig)
139+
if mode != tc.expectedPartitioningMode {
140+
t.Fatalf("expected cpu partitioning mode to be %s but got %s", tc.expectedPartitioningMode, mode)
141+
}
142+
})
143+
}
144+
}

0 commit comments

Comments
 (0)