Skip to content

Commit 0367c39

Browse files
Merge pull request openshift#7400 from shiftstack/osp_zero_workers
openstack: Test zero replicas in worker machine-pool
2 parents 32d8257 + ed2a27d commit 0367c39

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

pkg/asset/machines/openstack/machinesets.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ func MachineSets(clusterID string, config *types.InstallConfig, pool *types.Mach
4545
for idx := range machinesets {
4646
var replicaNumber int32
4747
{
48+
// The replica number is set to 3 by default when install-config does not have
49+
// any Compute machine-pool, or when the Compute machine-pool does not have the
50+
// `replicas` property. As a consequence, pool.Replicas is never nil
4851
replicas := *pool.Replicas / numberOfFailureDomains
4952
if int64(idx) < *pool.Replicas%numberOfFailureDomains {
5053
replicas++
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: v1
2+
baseDomain: shiftstack.example.com
3+
controlPlane:
4+
architecture: amd64
5+
name: master
6+
platform:
7+
openstack:
8+
type: ${COMPUTE_FLAVOR}
9+
replicas: 3
10+
compute:
11+
- name: worker
12+
platform:
13+
openstack:
14+
type: ${COMPUTE_FLAVOR}
15+
replicas: 0
16+
metadata:
17+
name: zero-workers
18+
networking:
19+
clusterNetwork:
20+
- cidr: 10.128.0.0/14
21+
hostPrefix: 23
22+
machineNetwork:
23+
- cidr: 10.0.128.0/17
24+
networkType: OVNKubernetes
25+
serviceNetwork:
26+
- 172.30.0.0/16
27+
platform:
28+
openstack:
29+
cloud: ${OS_CLOUD}
30+
externalNetwork: ${EXTERNAL_NETWORK}
31+
lbFloatingIP: ${API_FIP}
32+
pullSecret: ${PULL_SECRET}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import unittest
5+
import xmlrunner
6+
7+
import os
8+
import sys
9+
import yaml
10+
11+
ASSETS_DIR = ""
12+
13+
class ControlPlaneMachineSet(unittest.TestCase):
14+
def setUp(self):
15+
"""Parse the CPMS into a Python data structure."""
16+
with open(f'{ASSETS_DIR}/openshift/99_openshift-machine-api_master-control-plane-machine-set.yaml') as f:
17+
self.cpms = yaml.load(f, Loader=yaml.FullLoader)
18+
19+
def test_compute_zones(self):
20+
"""Assert that the OpenStack CPMS failureDomains value is empty."""
21+
self.assertNotIn("openstack", self.cpms["spec"]["template"]["machines_v1beta1_machine_openshift_io"]["failureDomains"])
22+
23+
24+
if __name__ == '__main__':
25+
ASSETS_DIR = sys.argv.pop()
26+
with open(os.environ.get('JUNIT_FILE', '/dev/null'), 'wb') as output:
27+
unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), failfast=False, buffer=False, catchbreak=False, verbosity=2)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import unittest
5+
import xmlrunner
6+
7+
import os
8+
import sys
9+
import glob
10+
import yaml
11+
12+
ASSETS_DIR = ""
13+
14+
EXPECTED_MASTER_REPLICAS = 3
15+
EXPECTED_WORKER_REPLICAS = 0
16+
17+
18+
class Machines(unittest.TestCase):
19+
def setUp(self):
20+
"""Parse the Machines into a Python data structure."""
21+
self.machines = []
22+
for machine_path in glob.glob(
23+
f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_master-machines-*.yaml'
24+
):
25+
with open(machine_path) as f:
26+
self.machines.append(yaml.load(f, Loader=yaml.FullLoader))
27+
28+
def test_total_instance_number(self):
29+
"""Assert that there are as many Machines as required ControlPlane replicas."""
30+
self.assertEqual(len(self.machines), EXPECTED_MASTER_REPLICAS)
31+
32+
33+
class Machinesets(unittest.TestCase):
34+
def setUp(self):
35+
"""Parse the MachineSets into a Python data structure."""
36+
self.machinesets = []
37+
for machineset_path in glob.glob(
38+
f'{ASSETS_DIR}/openshift/99_openshift-cluster-api_worker-machineset-*.yaml'
39+
):
40+
with open(machineset_path) as f:
41+
self.machinesets.append(yaml.load(f, Loader=yaml.FullLoader))
42+
43+
def test_total_replica_number(self):
44+
"""Assert that there is at least one MachineSet."""
45+
self.assertGreater(len(self.machinesets), 0)
46+
47+
def test_total_replica_number(self):
48+
"""Assert that replicas spread across the MachineSets add up to the expected number."""
49+
total_found = 0
50+
for machineset in self.machinesets:
51+
total_found += machineset["spec"]["replicas"]
52+
self.assertEqual(total_found, EXPECTED_WORKER_REPLICAS)
53+
54+
55+
if __name__ == '__main__':
56+
ASSETS_DIR = sys.argv.pop()
57+
with open(os.environ.get('JUNIT_FILE', '/dev/null'), 'wb') as output:
58+
unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output), failfast=False, buffer=False, catchbreak=False, verbosity=2)

0 commit comments

Comments
 (0)