empeira 0.1.0.pre.alpha.8 → 0.1.0.pre.alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/docs/architecture.md +3 -0
- data/docs/configuration.md +3 -1
- data/docs/development.md +17 -8
- data/docs/networking.md +2 -2
- data/docs/troubleshooting.md +8 -1
- data/lib/empeira/build.json +3 -3
- data/lib/empeira/build_info.rb +6 -2
- data/lib/empeira/cli/base.rb +1 -1
- data/lib/empeira/cli/completion.rb +1 -0
- data/lib/empeira/cli/config.rb +3 -1
- data/lib/empeira/cli/main.rb +3 -1
- data/lib/empeira/cli/node.rb +2 -0
- data/lib/empeira/cli/proxy.rb +2 -0
- data/lib/empeira/completion/catalog.rb +4 -3
- data/lib/empeira/configuration/loader.rb +1 -1
- data/lib/empeira/configuration/network_redirects.rb +2 -0
- data/lib/empeira/configuration/server_mounts.rb +3 -2
- data/lib/empeira/control_plane/controller.rb +43 -24
- data/lib/empeira/control_plane/health.rb +28 -3
- data/lib/empeira/control_plane/plan.rb +3 -3
- data/lib/empeira/control_plane/storage.rb +2 -0
- data/lib/empeira/infrastructure/cleanup.rb +1 -1
- data/lib/empeira/infrastructure/service.rb +9 -6
- data/lib/empeira/infrastructure/store.rb +1 -1
- data/lib/empeira/network/peer/channel.rb +7 -0
- data/lib/empeira/network/peer/channel_server.rb +4 -0
- data/lib/empeira/node/agent_configuration.rb +29 -0
- data/lib/empeira/node/container_preparation.rb +2 -6
- data/lib/empeira/node/external_fact.rb +2 -0
- data/lib/empeira/node/interactive_tools.rb +13 -2
- data/lib/empeira/node/runtime_proxy.rb +7 -2
- data/lib/empeira/node/vm_preparation.rb +2 -8
- data/lib/empeira/runtime/agent_helper.rb +0 -2
- data/lib/empeira/runtime/container.rb +6 -0
- data/lib/empeira/runtime/diagnostic_execution.rb +0 -2
- data/lib/empeira/runtime/mount_probe.rb +41 -33
- data/lib/empeira/runtime/services.rb +0 -2
- data/lib/empeira/runtime/update_helper.rb +0 -2
- data/lib/empeira/runtime/workspace_network.rb +35 -7
- data/lib/empeira/server/environment_configuration.rb +4 -2
- data/lib/empeira/updates/modules.rb +2 -1
- data/lib/empeira/vm/guest.rb +2 -0
- data/lib/empeira/vm/guest_channel.rb +3 -0
- data/lib/empeira/vm/guest_shell.rb +2 -0
- data/lib/empeira/vm/guest_upload.rb +3 -0
- data/lib/empeira.rb +288 -210
- data/resources/network/channel.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2edb62b459e9ba324ef4e0da81a724610a8fd6ea189bf1b0a6c8b2e61f08732b
|
|
4
|
+
data.tar.gz: 98316c0807498c44d6a7a342f2e38b0cd7d48a91cde12b4e8bb73dc79b093c07
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5ef6e66a7411c0e292c976554e30679227899f2ffff40af78d9b3ee1d95e8fdb7695ce0a046bfd80b5994438cae2a624381321c9e3068634d3e9654e54da093f
|
|
7
|
+
data.tar.gz: c5fab03eac331d133930d174666ae6439ca433e499254a9024f237b16ed5a123b4f840084489283208ebbfa4ae536b53a06a6d88b0dd08b5d067cef12f0a1244
|
data/README.md
CHANGED
|
@@ -109,6 +109,9 @@ empeira node destroy host1
|
|
|
109
109
|
empeira destroy
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
+
`status` reports observed resources. Use `empeira status --verify` when diagnosing
|
|
113
|
+
live gateway firewall or Docker bridge drift.
|
|
114
|
+
|
|
112
115
|
`destroy` permanently removes the workspace's owned nodes, CA and database data.
|
|
113
116
|
The control repository, module directory and shared image caches are preserved.
|
|
114
117
|
Destroy works independently of release requirements and guest management versions.
|
data/docs/architecture.md
CHANGED
|
@@ -223,6 +223,9 @@ proxy, browser and additional infrastructure services. Readiness probes test rea
|
|
|
223
223
|
DNS, server, SQL and PuppetDB responses. Shared naming and peer backends preserve
|
|
224
224
|
container/VM connectivity and isolation. Network capabilities and isolation must
|
|
225
225
|
be verifiable; there is no host-network or software-emulation fallback.
|
|
226
|
+
PostgreSQL and the configuration server start before waiting for database readiness.
|
|
227
|
+
Database role/extension initialization is recorded against the retained volume and
|
|
228
|
+
SQL revision; unchanged starts reuse it. Live service readiness remains checked.
|
|
226
229
|
See [networking](networking.md) for the privilege and trust boundaries.
|
|
227
230
|
|
|
228
231
|
`browser` validates existing infrastructure and reconciles only Chromium and its
|
data/docs/configuration.md
CHANGED
|
@@ -260,7 +260,9 @@ directories; broken source symlinks, control characters and commas are rejected.
|
|
|
260
260
|
Targets must be absolute, are normalized, and cannot contain `..` segments or
|
|
261
261
|
control characters/commas. `/` itself and system paths `/dev`, `/proc` and `/sys`
|
|
262
262
|
cannot be mounted. Source data trees must not contain sockets, devices or other
|
|
263
|
-
special files.
|
|
263
|
+
special files. `config validate` and the `up` preflight check these trees without
|
|
264
|
+
following nested directory symlinks. Other commands validate mount paths and
|
|
265
|
+
structure without recursively scanning data that they do not mount.
|
|
264
266
|
|
|
265
267
|
Mounts are read-only unless explicitly configured with `readonly: false`. Writable
|
|
266
268
|
mounts allow the server to change host data, subject to host filesystem permissions.
|
data/docs/development.md
CHANGED
|
@@ -24,6 +24,11 @@ To reproduce a CI test job, activate the corresponding Ruby, install the locked
|
|
|
24
24
|
bundle and run `bundle exec rspec --exclude-pattern 'spec/integration/**/*_spec.rb'`.
|
|
25
25
|
Runtime and VM compatibility remain separate manual gates.
|
|
26
26
|
|
|
27
|
+
Mark examples that need only temporary files with `:files_only`; they retain an
|
|
28
|
+
isolated home but skip Git initialization and the project marker. Project behavior
|
|
29
|
+
continues to use a real isolated Git repository. Syntax checks compile all Ruby
|
|
30
|
+
sources in one process per CI job, without executing guest helpers.
|
|
31
|
+
|
|
27
32
|
Addon tests (`spec/addon_*_spec.rb`) use the existing loopback Git fixture,
|
|
28
33
|
concurrent CLI subprocesses, a real PTY and the generated Bash completion. They
|
|
29
34
|
exercise branches, tags and commit refs without external Git services or container
|
|
@@ -378,19 +383,23 @@ and `dry_run` (default true). Dispatch it from `main`; a prerelease tag must mat
|
|
|
378
383
|
its channel, for example `v0.1.0-alpha.1`. Other branches and existing tags/releases
|
|
379
384
|
are rejected. Quality and real Docker/OpenVox gates must pass before the build.
|
|
380
385
|
|
|
381
|
-
For GitHub integrations that cannot dispatch Actions directly,
|
|
382
|
-
|
|
386
|
+
For GitHub integrations that cannot dispatch Actions directly, the repository owner
|
|
387
|
+
(`c8m6`, numeric account ID 35730763) can open an issue titled
|
|
388
|
+
`Release request: v0.1.0-alpha.1` with a plain JSON body containing exactly:
|
|
383
389
|
|
|
384
390
|
```json
|
|
385
391
|
{"tag":"v0.1.0-alpha.1","channel":"alpha","dry_run":true}
|
|
386
392
|
```
|
|
387
393
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
+
The owner-only issue-opened dispatcher runs from the default branch and calls the
|
|
395
|
+
same manual release workflow on `main`. Comments, edits, contributor issues and
|
|
396
|
+
ordinary pushes cannot trigger releases. Title, tag, channel, boolean and owner
|
|
397
|
+
identity are validated before dispatch. Keep `dry_run: true` for validation;
|
|
398
|
+
open a new explicitly approved publish request with `dry_run: false` to publish.
|
|
399
|
+
The existing release gates and duplicate-tag checks remain mandatory. The issue
|
|
400
|
+
is an audit record, not a release or proof that publication succeeded. Check the
|
|
401
|
+
downstream Manual release run and both distribution destinations. The former
|
|
402
|
+
committed JSON request is no longer a release trigger.
|
|
394
403
|
|
|
395
404
|
The build uses the existing `rake build_info` task in a temporary source staging
|
|
396
405
|
directory, builds an installable gem, and checks its contents, license, normalized
|
data/docs/networking.md
CHANGED
|
@@ -131,7 +131,7 @@ HTTP Host or TLS SNI. DNS changes require another `up`.
|
|
|
131
131
|
Reconciliation installs DROP before applying complete rules. Removed grants also
|
|
132
132
|
revoke existing connections. DNS or firewall failure leaves egress blocked/stopped,
|
|
133
133
|
never on unrestricted provider NAT. Policy edits preserve node/gateway identities;
|
|
134
|
-
`status` checks actual rules and forwarding, and `up` repairs drift.
|
|
134
|
+
`status --verify` checks actual rules and forwarding, and `up` repairs drift.
|
|
135
135
|
|
|
136
136
|
CoreDNS alone receives TCP/UDP 53 to its selected resolvers. Proxies alone receive
|
|
137
137
|
TCP 80/443 and enforce their destination allowlists. Normal proxy allow rules apply
|
|
@@ -215,7 +215,7 @@ the complete filter. Mapping changes therefore revoke old connections, including
|
|
|
215
215
|
previous connections to the original external destination. This also interrupts
|
|
216
216
|
other connections passing through that gateway; clients must reconnect. Identical
|
|
217
217
|
NAT on repeated `up` preserves connection state. Any apply/capability failure leaves
|
|
218
|
-
the gateway blocked/stopped. `status` checks complete filter/NAT rules and forwarding.
|
|
218
|
+
the gateway blocked/stopped. `status --verify` checks complete filter/NAT rules and forwarding.
|
|
219
219
|
No host conntrack, foreign firewall or target container configuration is changed.
|
|
220
220
|
|
|
221
221
|
The same helper runs in the Linux engine for Docker, rootless Podman, Docker Desktop
|
data/docs/troubleshooting.md
CHANGED
|
@@ -351,7 +351,14 @@ metadata failures never fall back to a full pull.
|
|
|
351
351
|
|
|
352
352
|
## Workspace gateway and direct egress
|
|
353
353
|
|
|
354
|
-
`status` reports
|
|
354
|
+
`status` reports observed service state and network membership without starting
|
|
355
|
+
diagnostic helpers. Use `empeira status --verify` to check live gateway firewall,
|
|
356
|
+
forwarding and Docker bridge rules. Application readiness is checked by `up`.
|
|
357
|
+
Running services describe observed state; only `Network policy: verified` confirms
|
|
358
|
+
the live policy checks passed. Missing bridge preparation remains unverified until
|
|
359
|
+
`up` reconciles it. A failed policy check marks infrastructure degraded without
|
|
360
|
+
changing the observed running state of its services.
|
|
361
|
+
An absent or unsafe runtime network cannot receive a verified policy result.
|
|
355
362
|
After an egress edit or DNS change, run `empeira up`; nodes keep their identities.
|
|
356
363
|
A failed hostname lookup leaves egress blocked. Check the host/corporate resolver
|
|
357
364
|
and every A record first. An IPv6-only destination is unsupported, not silently allowed.
|
data/lib/empeira/build.json
CHANGED
data/lib/empeira/build_info.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'json'
|
|
4
3
|
require_relative 'version_requirement'
|
|
5
4
|
|
|
6
5
|
module Empeira
|
|
@@ -9,7 +8,12 @@ module Empeira
|
|
|
9
8
|
attr_reader :version, :revision, :build_time
|
|
10
9
|
|
|
11
10
|
def self.load(path: METADATA_PATH)
|
|
12
|
-
data = File.file?(path)
|
|
11
|
+
data = if File.file?(path)
|
|
12
|
+
require 'json'
|
|
13
|
+
JSON.parse(File.read(path))
|
|
14
|
+
else
|
|
15
|
+
{}
|
|
16
|
+
end
|
|
13
17
|
new(**data.transform_keys(&:to_sym))
|
|
14
18
|
end
|
|
15
19
|
|
data/lib/empeira/cli/base.rb
CHANGED
|
@@ -7,7 +7,7 @@ module Empeira
|
|
|
7
7
|
module CLI
|
|
8
8
|
class Base < Thor
|
|
9
9
|
check_unknown_options!
|
|
10
|
-
class_option :container_engine, type: :string, enum:
|
|
10
|
+
class_option :container_engine, type: :string, enum: Empeira::Runtime.registry.names,
|
|
11
11
|
desc: 'Override runtime.container_engine'
|
|
12
12
|
|
|
13
13
|
def self.exit_on_failure?
|
data/lib/empeira/cli/config.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'base'
|
|
4
|
+
|
|
3
5
|
module Empeira
|
|
4
6
|
module CLI
|
|
5
7
|
class Config < Base
|
|
@@ -14,7 +16,7 @@ module Empeira
|
|
|
14
16
|
|
|
15
17
|
desc 'validate', 'Validate the effective configuration'
|
|
16
18
|
def validate
|
|
17
|
-
application.context.
|
|
19
|
+
ControlPlane::Plan.new(context: application.context).validate_server_mounts!
|
|
18
20
|
say 'Configuration is valid.'
|
|
19
21
|
end
|
|
20
22
|
end
|
data/lib/empeira/cli/main.rb
CHANGED
|
@@ -40,6 +40,7 @@ module Empeira
|
|
|
40
40
|
option :verbose, type: :boolean, desc: 'Include revision and build time'
|
|
41
41
|
map '--version' => :version
|
|
42
42
|
def version
|
|
43
|
+
require 'json' if options[:verbose]
|
|
43
44
|
info = BuildInfo.load
|
|
44
45
|
say(options[:verbose] ? JSON.pretty_generate(info.to_h) : "Empeira #{info.version}")
|
|
45
46
|
end
|
|
@@ -54,8 +55,9 @@ module Empeira
|
|
|
54
55
|
subcommand 'completion', Completion
|
|
55
56
|
|
|
56
57
|
desc 'status', 'Inspect workspace infrastructure without changing state'
|
|
58
|
+
option :verify, type: :boolean, default: false, desc: 'Also verify live gateway and bridge policy'
|
|
57
59
|
def status
|
|
58
|
-
application.infrastructure.status.each { |key, value| say "#{key}: #{value}" }
|
|
60
|
+
application.infrastructure.status(verify: options[:verify]).each { |key, value| say "#{key}: #{value}" }
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
desc 'up', 'Ensure isolated workspace infrastructure'
|
data/lib/empeira/cli/node.rb
CHANGED
data/lib/empeira/cli/proxy.rb
CHANGED
|
@@ -16,7 +16,8 @@ module Empeira
|
|
|
16
16
|
['config'] => %w[help show validate],
|
|
17
17
|
['node'] => %w[help run start stop destroy list exec shell console ssh puppet logs],
|
|
18
18
|
['completion'] => %w[help bash],
|
|
19
|
-
['version'] => ['--verbose']
|
|
19
|
+
['version'] => ['--verbose'],
|
|
20
|
+
['status'] => ['--verify']
|
|
20
21
|
}.tap { |commands| Immutable.deep_freeze(commands) }
|
|
21
22
|
GLOBAL_OPTIONS = %w[--container-engine --help].freeze
|
|
22
23
|
NODE_OPTIONS = %w[--provider --os --version --memory --cpus].freeze
|
|
@@ -104,7 +105,7 @@ module Empeira
|
|
|
104
105
|
end
|
|
105
106
|
|
|
106
107
|
def values(option, context)
|
|
107
|
-
return
|
|
108
|
+
return Empeira::Runtime.registry.names if option == '--container-engine'
|
|
108
109
|
return Empeira::Node.registry.names if option == '--provider' && context == %w[node run]
|
|
109
110
|
return node_values(option) if %w[--os --version].include?(option) && context == %w[node run]
|
|
110
111
|
return [] if VALUE_OPTIONS.include?(option)
|
|
@@ -123,7 +124,7 @@ module Empeira
|
|
|
123
124
|
end
|
|
124
125
|
|
|
125
126
|
def completion_application
|
|
126
|
-
Application.new
|
|
127
|
+
@completion_application ||= Application.new
|
|
127
128
|
end
|
|
128
129
|
|
|
129
130
|
def recovery_node_names
|
|
@@ -47,7 +47,7 @@ module Empeira
|
|
|
47
47
|
HieraMounts.new(config: data.fetch('hiera'), project: @project_path,
|
|
48
48
|
environment: data.dig('server', 'environment'))
|
|
49
49
|
Eyaml.new(config: data.fetch('eyaml'), project: @project_path).mounts
|
|
50
|
-
ServerMounts.new(entries: data.dig('server', 'mounts'), project: @project_path)
|
|
50
|
+
ServerMounts.new(entries: data.dig('server', 'mounts'), project: @project_path, verify_tree: false)
|
|
51
51
|
data
|
|
52
52
|
end
|
|
53
53
|
|
|
@@ -54,8 +54,9 @@ module Empeira
|
|
|
54
54
|
|
|
55
55
|
attr_reader :entries
|
|
56
56
|
|
|
57
|
-
def initialize(entries:, project:)
|
|
57
|
+
def initialize(entries:, project:, verify_tree: true)
|
|
58
58
|
self.class.validate!(entries)
|
|
59
|
+
@verify_tree = verify_tree
|
|
59
60
|
@entries = entries.each_with_index.map do |entry, index|
|
|
60
61
|
{ 'source' => resolve(entry.fetch('source'), project, index),
|
|
61
62
|
'target' => Pathname(entry.fetch('target')).cleanpath.to_s,
|
|
@@ -79,7 +80,7 @@ module Empeira
|
|
|
79
80
|
raise ConfigurationError, "server.mounts[#{index}].source must resolve to a regular file or data directory"
|
|
80
81
|
end
|
|
81
82
|
|
|
82
|
-
verify_data_tree!(source, index) if source.directory?
|
|
83
|
+
verify_data_tree!(source, index) if @verify_tree && source.directory?
|
|
83
84
|
source.to_s
|
|
84
85
|
rescue SystemCallError
|
|
85
86
|
raise ConfigurationError, "server.mounts[#{index}].source must exist and allow canonical resolution",
|
|
@@ -34,8 +34,10 @@ module Empeira
|
|
|
34
34
|
prepare_network_services
|
|
35
35
|
@plan.environment.prepare
|
|
36
36
|
@progress.stage(45, 'Starting PostgreSQL...')
|
|
37
|
-
|
|
37
|
+
reconcile('postgres') if @plan.database?
|
|
38
38
|
@progress.stage(60, 'Starting configuration server...')
|
|
39
|
+
reconcile('server')
|
|
40
|
+
prepare_postgres
|
|
39
41
|
prepare_server
|
|
40
42
|
prepare_puppetdb
|
|
41
43
|
@plan.additional_services.each_key { |key| reconcile(key) }
|
|
@@ -141,15 +143,13 @@ module Empeira
|
|
|
141
143
|
cleanup_files
|
|
142
144
|
end
|
|
143
145
|
|
|
144
|
-
|
|
145
|
-
def status(state: @store.load)
|
|
146
|
+
def status(state: @store.load, verify: false)
|
|
146
147
|
load_state(state)
|
|
147
148
|
definitions = service_keys.to_h { |key| [key, identity(key)] }
|
|
148
149
|
expected = @inventory.fetch('services').transform_values { |record| record['id'] }
|
|
149
150
|
@observed = @runtime.inspect_services(definitions, expected_ids: expected)
|
|
150
151
|
report = @observed.to_h { |key, resource| [key.capitalize, readiness(key, resource)] }
|
|
151
|
-
report.merge(summary(report))
|
|
152
|
-
report.values.all? { |value| value == 'running' } ? 'healthy' : 'unhealthy')
|
|
152
|
+
report.merge(summary(report, verify: verify))
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
def browser_url
|
|
@@ -287,12 +287,28 @@ module Empeira
|
|
|
287
287
|
@plan.definitions.keys | @inventory.fetch('services').keys
|
|
288
288
|
end
|
|
289
289
|
|
|
290
|
-
def summary(report)
|
|
291
|
-
|
|
290
|
+
def summary(report, verify:)
|
|
291
|
+
running = report.values.all? { |value| value == 'running' }
|
|
292
|
+
{ 'Control plane' => running ? 'running' : 'degraded',
|
|
292
293
|
'Readiness' => 'not checked; empeira up verifies readiness',
|
|
294
|
+
'Workspace network' => running ? 'running' : 'unhealthy',
|
|
295
|
+
'Network policy' => gateway_policy_status(report, verify: verify),
|
|
293
296
|
'Persistent volumes' => @inventory.fetch('volumes').size.to_s }
|
|
294
297
|
end
|
|
295
298
|
|
|
299
|
+
def gateway_policy_status(report, verify:)
|
|
300
|
+
return 'not checked; use empeira status --verify' unless verify
|
|
301
|
+
return 'unverified; gateway is not running' unless report['Gateway'] == 'running'
|
|
302
|
+
return 'unverified; workspace bridge preparation not recorded' unless @inventory['bridge_prepared']
|
|
303
|
+
|
|
304
|
+
reconcile_bridge('check')
|
|
305
|
+
result = @runtime.service_exec(@observed.fetch('gateway'), [Network::Gateway::EXECUTABLE, 'check',
|
|
306
|
+
'/empeira-gateway/gateway.json'], timeout: 3)
|
|
307
|
+
result.success? ? 'verified' : 'unverified; firewall/routing reconcile required'
|
|
308
|
+
rescue Providers::ExecutionError
|
|
309
|
+
'unverified; workspace bridge attachment reconcile required'
|
|
310
|
+
end
|
|
311
|
+
|
|
296
312
|
def readiness(key, resource)
|
|
297
313
|
return 'missing' unless resource
|
|
298
314
|
|
|
@@ -300,20 +316,9 @@ module Empeira
|
|
|
300
316
|
definition = @plan.definitions[key]
|
|
301
317
|
return 'stale' if definition && resource.dig('labels', 'io.empeira.definition') != definition.fingerprint
|
|
302
318
|
|
|
303
|
-
return gateway_readiness(resource) if key == 'gateway' && resource['state'] == 'running'
|
|
304
|
-
|
|
305
319
|
resource['state']
|
|
306
320
|
end
|
|
307
321
|
|
|
308
|
-
def gateway_readiness(resource)
|
|
309
|
-
reconcile_bridge('check') if @inventory['bridge_prepared']
|
|
310
|
-
result = @runtime.service_exec(resource, [Network::Gateway::EXECUTABLE, 'check',
|
|
311
|
-
'/empeira-gateway/gateway.json'], timeout: 3)
|
|
312
|
-
result.success? ? 'running' : 'unhealthy; firewall/routing reconcile required'
|
|
313
|
-
rescue Providers::ExecutionError
|
|
314
|
-
'unhealthy; workspace bridge attachment reconcile required'
|
|
315
|
-
end
|
|
316
|
-
|
|
317
322
|
def check_images(definitions: @plan.definitions)
|
|
318
323
|
@desired_images = {}
|
|
319
324
|
@runtime.with_local_images do
|
|
@@ -329,16 +334,27 @@ module Empeira
|
|
|
329
334
|
def prepare_postgres
|
|
330
335
|
return unless @plan.database?
|
|
331
336
|
|
|
332
|
-
reconcile('postgres')
|
|
333
337
|
@health.wait('postgres', @observed)
|
|
338
|
+
checkpoint = database_setup_checkpoint
|
|
339
|
+
return if @inventory['database_setup'] == checkpoint && @health.postgres_initialized
|
|
340
|
+
|
|
341
|
+
save if @inventory.delete('database_setup')
|
|
334
342
|
result = @runtime.service_exec(@observed.fetch('postgres'),
|
|
335
|
-
['psql', '-U', 'postgres', '-d', 'puppetdb', '-v', 'ON_ERROR_STOP=1',
|
|
343
|
+
['psql', '-X', '-U', 'postgres', '-d', 'puppetdb', '-v', 'ON_ERROR_STOP=1',
|
|
336
344
|
'-f', '/empeira/setup.sql'])
|
|
337
345
|
raise Error, 'PostgreSQL roles and pg_trgm initialization failed' unless result.success?
|
|
346
|
+
|
|
347
|
+
@changed = true
|
|
348
|
+
@inventory['database_setup'] = checkpoint
|
|
349
|
+
save
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
def database_setup_checkpoint
|
|
353
|
+
{ 'id' => @inventory.fetch('volumes').fetch(@plan.volume('postgres-data').key).fetch('id'),
|
|
354
|
+
'fingerprint' => Digest::SHA256.file(@plan.files.path('database-setup.sql')).hexdigest }
|
|
338
355
|
end
|
|
339
356
|
|
|
340
357
|
def prepare_server
|
|
341
|
-
reconcile('server')
|
|
342
358
|
refresh_eyaml_keys if @plan.eyaml_staged?
|
|
343
359
|
Runtime::MountProbe.new(runtime: @runtime).verify(@observed.fetch('server'),
|
|
344
360
|
[@plan.repository_mounts, @plan.eyaml_mounts,
|
|
@@ -630,7 +646,6 @@ module Empeira
|
|
|
630
646
|
def reconcile_proxy
|
|
631
647
|
return unless @plan.proxy?
|
|
632
648
|
|
|
633
|
-
ensure_egress
|
|
634
649
|
reconcile('proxy')
|
|
635
650
|
end
|
|
636
651
|
|
|
@@ -645,7 +660,7 @@ module Empeira
|
|
|
645
660
|
end
|
|
646
661
|
|
|
647
662
|
def lockdown_existing_gateway
|
|
648
|
-
resource =
|
|
663
|
+
resource = service_resource(identity('gateway'), expected_id: recorded('gateway'))
|
|
649
664
|
return unless resource && resource['state'] == 'running'
|
|
650
665
|
|
|
651
666
|
lockdown_gateway(resource)
|
|
@@ -714,7 +729,9 @@ module Empeira
|
|
|
714
729
|
|
|
715
730
|
def record_gateway_policy
|
|
716
731
|
fingerprint = Infrastructure::Definition.fingerprint(@gateway_plan)
|
|
717
|
-
|
|
732
|
+
return if @inventory['gateway_policy'] == fingerprint
|
|
733
|
+
|
|
734
|
+
@changed = true
|
|
718
735
|
@inventory['gateway_policy'] = fingerprint
|
|
719
736
|
save
|
|
720
737
|
end
|
|
@@ -743,6 +760,8 @@ module Empeira
|
|
|
743
760
|
resource = @runtime.create_network(definition: egress).resource
|
|
744
761
|
@changed = true
|
|
745
762
|
end
|
|
763
|
+
return if @inventory['egress'] == resource.id
|
|
764
|
+
|
|
746
765
|
@inventory['egress'] = resource.id
|
|
747
766
|
save
|
|
748
767
|
end
|
|
@@ -2,8 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
module Empeira
|
|
4
4
|
module ControlPlane
|
|
5
|
+
# rubocop:disable-next Metrics/ClassLength -- Readiness and setup share one native PostgreSQL probe.
|
|
5
6
|
class Health
|
|
6
7
|
RUBY = '/opt/puppetlabs/puppet/bin/ruby'
|
|
8
|
+
POSTGRES_SETUP = <<~SQL
|
|
9
|
+
SELECT (SELECT count(*) FROM pg_roles WHERE rolname IN ('puppetdb', 'puppetdb_read')) = 2
|
|
10
|
+
AND EXISTS (SELECT FROM pg_extension WHERE extname = 'pg_trgm')
|
|
11
|
+
AND EXISTS (SELECT FROM pg_database d JOIN pg_roles r ON r.oid = d.datdba
|
|
12
|
+
WHERE d.datname = current_database() AND r.rolname = 'puppetdb');
|
|
13
|
+
SQL
|
|
14
|
+
|
|
15
|
+
attr_reader :postgres_initialized
|
|
7
16
|
|
|
8
17
|
def initialize(runtime:, plan:)
|
|
9
18
|
@runtime = runtime
|
|
@@ -12,17 +21,20 @@ module Empeira
|
|
|
12
21
|
|
|
13
22
|
def wait(key, resources)
|
|
14
23
|
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @plan.config.dig('server', 'timeout')
|
|
24
|
+
interval = 0.25
|
|
15
25
|
loop do
|
|
16
26
|
return if ready?(key, resources)
|
|
17
27
|
|
|
18
28
|
verify_proxy_running!(resources) if key == 'proxy'
|
|
19
|
-
|
|
29
|
+
remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
30
|
+
if remaining <= 0
|
|
20
31
|
raise Error,
|
|
21
32
|
"#{key} did not become ready within server.timeout; inspect empeira status and owned service logs\n" \
|
|
22
33
|
"#{@failure}"
|
|
23
34
|
end
|
|
24
35
|
|
|
25
|
-
sleep
|
|
36
|
+
sleep [interval, remaining].min
|
|
37
|
+
interval = [interval * 2, 2].min
|
|
26
38
|
end
|
|
27
39
|
end
|
|
28
40
|
|
|
@@ -34,7 +46,7 @@ module Empeira
|
|
|
34
46
|
case key
|
|
35
47
|
when 'server' then check(resource, [*tls_curl, 'https://server.empeira.internal:8140/status/v1/simple'],
|
|
36
48
|
'running')
|
|
37
|
-
when 'postgres' then
|
|
49
|
+
when 'postgres' then postgres_ready?(resource)
|
|
38
50
|
when 'puppetdb-backend'
|
|
39
51
|
check(resources['server'], [*http_curl, 'http://puppetdb-backend.empeira.internal:8080/pdb/query/v4/nodes'])
|
|
40
52
|
when 'puppetdb' then puppetdb_ready?(resources['server'])
|
|
@@ -54,6 +66,19 @@ module Empeira
|
|
|
54
66
|
|
|
55
67
|
private
|
|
56
68
|
|
|
69
|
+
def postgres_ready?(resource)
|
|
70
|
+
@postgres_initialized = false
|
|
71
|
+
result = @runtime.service_exec(resource, ['psql', '-X', '-U', 'postgres', '-d', 'puppetdb',
|
|
72
|
+
'-v', 'ON_ERROR_STOP=1', '-Atc', POSTGRES_SETUP])
|
|
73
|
+
@postgres_initialized = result.success? && result.stdout.strip == 't'
|
|
74
|
+
return true if result.success? && %w[t f].include?(result.stdout.strip)
|
|
75
|
+
|
|
76
|
+
@failure = Execution::Diagnostics.native(result, operation: 'Probe PostgreSQL setup', tool: 'psql')
|
|
77
|
+
false
|
|
78
|
+
rescue Empeira::ExecutionError
|
|
79
|
+
false
|
|
80
|
+
end
|
|
81
|
+
|
|
57
82
|
def verify_proxy_running!(resources)
|
|
58
83
|
resource = @runtime.inspect_service(@plan.definitions.fetch('proxy'),
|
|
59
84
|
expected_id: resources.fetch('proxy').fetch('id'))
|
|
@@ -136,13 +136,13 @@ module Empeira
|
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
def project_server_mounts
|
|
139
|
-
@project_server_mounts ||= validate_server_mounts!
|
|
139
|
+
@project_server_mounts ||= validate_server_mounts!(verify_tree: false)
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
# rubocop:disable-next Metrics/AbcSize -- Compare resolved data mounts with the actual managed definition.
|
|
143
|
-
def validate_server_mounts!
|
|
143
|
+
def validate_server_mounts!(verify_tree: true)
|
|
144
144
|
resolved = Configuration::ServerMounts.new(entries: config.dig('server', 'mounts'),
|
|
145
|
-
project: context.project.path)
|
|
145
|
+
project: context.project.path, verify_tree: verify_tree)
|
|
146
146
|
targets = managed_server_mounts.map { |mount| mount.split(',').find { |field| field.start_with?('dst=') }[4..] }
|
|
147
147
|
resolved.verify_targets!(targets)
|
|
148
148
|
@project_server_mounts = resolved.entries.map do |entry|
|
|
@@ -312,7 +312,7 @@ module Empeira
|
|
|
312
312
|
unknown = @state.fetch('resources').keys - ['network']
|
|
313
313
|
@errors << "Unrecognized resource groups retained: #{unknown.join(', ')}" unless unknown.empty?
|
|
314
314
|
known_plane = %w[services volumes egress bridge_prepared bridge_image stopped environment_cache
|
|
315
|
-
gateway_policy proxy_reload dns_definition]
|
|
315
|
+
gateway_policy proxy_reload dns_definition database_setup]
|
|
316
316
|
unknown = plane.keys - known_plane
|
|
317
317
|
@errors << "Unrecognized control-plane fields retained: #{unknown.join(', ')}" unless unknown.empty?
|
|
318
318
|
return unless @state.key?('vm_gateway')
|
|
@@ -75,14 +75,14 @@ module Empeira
|
|
|
75
75
|
Cleanup.new(context: @context, runner: @runner, runtimes: @runtimes, progress: @progress).destroy
|
|
76
76
|
end
|
|
77
77
|
|
|
78
|
-
def status
|
|
78
|
+
def status(verify: false)
|
|
79
79
|
status = Status.new(context: @context, build_info: @build_info, definition: definition)
|
|
80
80
|
state = @store.load
|
|
81
81
|
status.record(state)
|
|
82
82
|
runtime = runtime_for(state&.fetch('runtime') || @context.container_engine)
|
|
83
83
|
runtime.check_available!
|
|
84
84
|
status.observe(observe(runtime, state))
|
|
85
|
-
health_report(status, runtime, state)
|
|
85
|
+
health_report(status, runtime, state, verify: verify)
|
|
86
86
|
rescue Error => e
|
|
87
87
|
status.report.merge('Infrastructure' => 'unknown', 'Diagnostic' => e.message)
|
|
88
88
|
end
|
|
@@ -119,9 +119,12 @@ module Empeira
|
|
|
119
119
|
raise Error, 'Nodes exist; destroy them before empeira down, or use empeira destroy for complete removal'
|
|
120
120
|
end
|
|
121
121
|
|
|
122
|
-
def health_report(status, runtime, state)
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
def health_report(status, runtime, state, verify:)
|
|
123
|
+
policy_check = verify && status.report['Network'] == 'isolated'
|
|
124
|
+
report = status.report.merge(control_plane(runtime).status(state: state, verify: policy_check))
|
|
125
|
+
report['Network policy'] = 'unverified; workspace network isolation not verified' if verify && !policy_check
|
|
126
|
+
if report['Infrastructure'] == 'up' &&
|
|
127
|
+
(report['Control plane'] == 'degraded' || /\Aunverified/.match?(report['Network policy']))
|
|
125
128
|
report['Infrastructure'] = 'degraded'
|
|
126
129
|
end
|
|
127
130
|
report
|
|
@@ -144,7 +147,7 @@ module Empeira
|
|
|
144
147
|
else
|
|
145
148
|
runtime.create_network(definition: definition.network)
|
|
146
149
|
end
|
|
147
|
-
persist(state, result.resource)
|
|
150
|
+
persist(state, result.resource) unless resource
|
|
148
151
|
result
|
|
149
152
|
end
|
|
150
153
|
|
|
@@ -232,7 +232,7 @@ module Empeira
|
|
|
232
232
|
end
|
|
233
233
|
|
|
234
234
|
def valid_plane_checkpoints?(plane)
|
|
235
|
-
%w[proxy_reload dns_definition].all? { |key| valid_proxy_reload?(plane[key]) }
|
|
235
|
+
%w[proxy_reload dns_definition database_setup].all? { |key| valid_proxy_reload?(plane[key]) }
|
|
236
236
|
end
|
|
237
237
|
|
|
238
238
|
def valid_proxy_reload?(checkpoint)
|