fix(deploy): correct service selection and recovery validation
ci / Workflows (pull_request) Successful in 6s
ci / Shell (pull_request) Successful in 16s
ci / Python and tests (pull_request) Successful in 6s
ci / Compose (pull_request) Successful in 12s
ci / Formatting (pull_request) Successful in 15s
ci / Dockerfiles (pull_request) Successful in 4s
ci / YAML (pull_request) Successful in 19s
ci / Kubernetes (pull_request) Successful in 7s
ci / image-plan (pull_request) Skipped
ci / Image (${{ matrix.name }}) (pull_request) Skipped
ci / build (pull_request) Skipped
ci / Workflows (pull_request) Successful in 6s
ci / Shell (pull_request) Successful in 16s
ci / Python and tests (pull_request) Successful in 6s
ci / Compose (pull_request) Successful in 12s
ci / Formatting (pull_request) Successful in 15s
ci / Dockerfiles (pull_request) Successful in 4s
ci / YAML (pull_request) Successful in 19s
ci / Kubernetes (pull_request) Successful in 7s
ci / image-plan (pull_request) Skipped
ci / Image (${{ matrix.name }}) (pull_request) Skipped
ci / build (pull_request) Skipped
This commit is contained in:
1 parent
4c7c53e0f2
commit
c4cbd87590
7 files changed
+272
-18
No files matched your search
+94
-3
@@ -128,6 +128,23 @@ class SelectionTests(unittest.TestCase):
|
||||
self.assertEqual(result['selected']['k8s'], ['one'])
|
||||
self.assertEqual(result['helm'], [])
|
||||
|
||||
def test_nested_service_change_and_owned_image_are_selected(self):
|
||||
directory = self.repo / 'vpn/xui/k8s'
|
||||
directory.mkdir(parents=True)
|
||||
(directory / 'active').touch()
|
||||
image = next(iter(release()['images']))
|
||||
(directory / 'app.yaml').write_text('image: ' + image + ':main\n')
|
||||
baseline_sha = self.commit()
|
||||
baseline = planner.make_plan(self.repo, self.repo, release(baseline_sha), None, 'full', [])
|
||||
(directory / 'app.yaml').write_text('image: ' + image + ':prod\n')
|
||||
result = planner.make_plan(self.repo, self.repo, release(self.commit()), baseline, 'changed', [])
|
||||
self.assertEqual(result['selected']['k8s'], ['vpn/xui'])
|
||||
baseline = result
|
||||
updated = release(result['sha'])
|
||||
updated['images'][image] = 'sha256:' + 'e' * 64
|
||||
result = planner.make_plan(self.repo, self.repo, updated, baseline, 'changed', [])
|
||||
self.assertEqual(result['selected']['k8s'], ['vpn/xui'])
|
||||
|
||||
def test_failed_intermediate_deploy_does_not_lose_changes(self):
|
||||
(self.repo / 'one/k8s/app.yaml').write_text('kind: StatefulSet\n')
|
||||
self.commit() # This commit failed deploy: baseline must remain initial.
|
||||
@@ -162,7 +179,8 @@ class ComposeConfigurationTests(unittest.TestCase):
|
||||
source = run / 'source'
|
||||
config_repo = root / 'persistent'
|
||||
(source / 'headscale').mkdir(parents=True)
|
||||
config_repo.mkdir()
|
||||
(config_repo / 'headscale').mkdir(parents=True)
|
||||
(config_repo / 'headscale/compose.yaml').touch()
|
||||
(run / 'release.json').write_text(json.dumps(release()))
|
||||
old = 'busybox@sha256:' + 'd' * 64
|
||||
new = 'busybox@sha256:' + 'e' * 64
|
||||
@@ -180,19 +198,41 @@ class ComposeConfigurationTests(unittest.TestCase):
|
||||
'volumes': {'data': {'name': 'headscale_data'}},
|
||||
}
|
||||
|
||||
previous_config = json.loads(json.dumps(config))
|
||||
previous_config['services']['app']['command'] = ['old-command']
|
||||
previous_config['services']['app']['environment'] = {'VALUE': 'old'}
|
||||
previous_config['services']['removed'] = {'image': 'busybox:latest'}
|
||||
config['services']['app']['command'] = ['new-command']
|
||||
config['services']['app']['environment'] = {'VALUE': 'new'}
|
||||
config['services']['added'] = {'image': 'busybox:latest'}
|
||||
|
||||
def fake_output(*args, **kwargs):
|
||||
if args[:2] == ('docker', 'compose'):
|
||||
self.assertEqual(kwargs['cwd'], config_repo)
|
||||
self.assertIn(str(config_repo / 'headscale'), args)
|
||||
return json.dumps(config)
|
||||
if '--hash' in args:
|
||||
return 'app matching-hash'
|
||||
return json.dumps(
|
||||
previous_config if str(config_repo / 'headscale/compose.yaml') in args else config
|
||||
)
|
||||
if args[:2] == ('docker', 'ps'):
|
||||
return 'container'
|
||||
if args[:2] == ('docker', 'inspect'):
|
||||
if 'com.docker.compose.config-hash' in args[-1]:
|
||||
return 'matching-hash'
|
||||
return 'sha256:' + 'f' * 64
|
||||
return json.dumps([old])
|
||||
|
||||
with (
|
||||
patch.dict(os.environ, {'CONFIG_REPO': str(config_repo), 'REPO': str(source), 'RUN_DIR': str(run)}),
|
||||
patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
'CONFIG_REPO': str(config_repo),
|
||||
'REPO': str(source),
|
||||
'RUN_DIR': str(run),
|
||||
'HOMELAB_STATE': str(root / 'state'),
|
||||
},
|
||||
),
|
||||
patch.object(compose_module, 'output', side_effect=fake_output),
|
||||
patch.object(compose_module, 'resolve', return_value=new),
|
||||
):
|
||||
@@ -204,6 +244,57 @@ class ComposeConfigurationTests(unittest.TestCase):
|
||||
self.assertEqual(pinned['services']['app']['volumes'], config['services']['app']['volumes'])
|
||||
self.assertEqual(pinned['services']['app']['image'], new)
|
||||
self.assertEqual(before['services']['app']['image'], old)
|
||||
self.assertEqual(before['services']['app']['command'], ['old-command'])
|
||||
self.assertEqual(before['services']['app']['environment'], {'VALUE': 'old'})
|
||||
self.assertIn('removed', before['services'])
|
||||
self.assertNotIn('added', before['services'])
|
||||
|
||||
def mismatched_output(*args, **kwargs):
|
||||
if args[:2] == ('docker', 'inspect') and 'com.docker.compose.config-hash' in args[-1]:
|
||||
return 'different-hash'
|
||||
return fake_output(*args, **kwargs)
|
||||
|
||||
with (
|
||||
patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
'CONFIG_REPO': str(config_repo),
|
||||
'REPO': str(source),
|
||||
'RUN_DIR': str(run),
|
||||
'HOMELAB_STATE': str(root / 'state'),
|
||||
},
|
||||
),
|
||||
patch.object(compose_module, 'output', side_effect=mismatched_output),
|
||||
patch.object(compose_module, 'resolve', return_value=new),
|
||||
self.assertRaisesRegex(ValueError, 'differs from running config'),
|
||||
):
|
||||
compose_module.prepare(source / 'headscale/compose.yaml')
|
||||
state = root / 'state'
|
||||
with patch.object(controller, 'STATE', state):
|
||||
state.mkdir()
|
||||
(run / 'status.json').write_text('{"state": "running", "stages": {}}')
|
||||
with patch.object(controller, 'retain_completed'):
|
||||
controller.finish_success(run, {})
|
||||
self.assertEqual(json.loads((state / 'compose-configs/headscale.json').read_text()), pinned)
|
||||
# A stale persistent checkout must not replace the successful baseline.
|
||||
with (
|
||||
patch.dict(
|
||||
os.environ,
|
||||
{
|
||||
'CONFIG_REPO': str(config_repo),
|
||||
'REPO': str(source),
|
||||
'RUN_DIR': str(run),
|
||||
'HOMELAB_STATE': str(state),
|
||||
},
|
||||
),
|
||||
patch.object(compose_module, 'output', side_effect=fake_output),
|
||||
patch.object(compose_module, 'resolve', return_value=new),
|
||||
):
|
||||
compose_module.prepare(source / 'headscale/compose.yaml')
|
||||
before = json.loads((run / 'compose-before/headscale.json').read_text())
|
||||
self.assertEqual(before['services']['app']['command'], ['new-command'])
|
||||
self.assertIn('added', before['services'])
|
||||
self.assertNotIn('removed', before['services'])
|
||||
self.assertEqual((run / 'compose/headscale.json').stat().st_mode & 0o777, 0o600)
|
||||
|
||||
def test_registry_index_and_single_image_descriptors(self):
|
||||
|
||||
Reference in new issue
Block a user