Skip to content

Commit 803b592

Browse files
authored
Fix review-app renderer resource ratio (#787)
1 parent 8266366 commit 803b592

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

.controlplane/templates/node-renderer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ spec:
1010
- name: node-renderer
1111
# Minimum starting point for the tutorial renderer. Keep one worker and
1212
# let capacityAI raise resources if real SSR load needs more.
13-
cpu: 50m
13+
cpu: 100m
1414
memory: 512Mi
1515
env:
1616
- name: LOG_LEVEL

bin/test-cpflow-github-flow

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ require "yaml"
1818
1919
template = File.read(".controlplane/templates/node-renderer.yml")
2020
rendered = template.gsub(/\{\{[A-Z_]+\}\}/, "template-placeholder")
21-
container = YAML.safe_load(rendered).fetch("spec").fetch("containers").fetch(0)
21+
workload = YAML.safe_load(rendered)
22+
spec = workload.fetch("spec")
23+
container = spec.fetch("containers").fetch(0)
2224
2325
expected_args = [
2426
"bash",
@@ -32,6 +34,10 @@ expected_args = [
3234
SHELL
3335
]
3436
expected_ports = [{ "number" => 3800, "protocol" => "http2" }]
37+
expected_env = [
38+
{ "name" => "LOG_LEVEL", "value" => "info" },
39+
{ "name" => "NODE_OPTIONS", "value" => "--max-old-space-size=256" },
40+
]
3541
expected_readiness_probe = {
3642
"tcpSocket" => { "port" => 3800 },
3743
"failureThreshold" => 3,
@@ -43,18 +49,52 @@ expected_liveness_probe = {
4349
"periodSeconds" => 10,
4450
"initialDelaySeconds" => 120,
4551
}
52+
expected_default_options = {
53+
"autoscaling" => { "maxScale" => 1 },
54+
"capacityAI" => true,
55+
}
56+
expected_firewall_config = {
57+
"external" => {
58+
"inboundAllowCIDR" => [],
59+
"outboundAllowCIDR" => ["0.0.0.0/0"],
60+
},
61+
"internal" => { "inboundAllowType" => "same-gvc" },
62+
}
4663
4764
failures = []
65+
failures << "workload keys changed" unless workload.keys.sort == %w[kind name spec]
66+
failures << "workload identity changed" unless workload.values_at("kind", "name") == %w[workload node-renderer]
67+
failures << "spec keys changed" unless spec.keys.sort == %w[containers defaultOptions firewallConfig identityLink type]
68+
failures << "workload type changed" unless spec.fetch("type") == "standard"
69+
failures << "container keys changed" unless container.keys.sort ==
70+
%w[args cpu env image inheritEnv livenessProbe memory name ports readinessProbe]
4871
failures << "unsupported startupProbe is present" if container.key?("startupProbe")
4972
failures << "command changed" if container.key?("command")
73+
failures << "renderer name changed" unless container.fetch("name") == "node-renderer"
74+
failures << "renderer CPU changed" unless container.fetch("cpu") == "100m"
75+
failures << "renderer memory changed" unless container.fetch("memory") == "512Mi"
76+
failures << "renderer environment changed" unless container.fetch("env") == expected_env
77+
failures << "environment inheritance changed" unless container.fetch("inheritEnv") == true
5078
failures << "args changed" unless container.fetch("args") == expected_args
5179
failures << "image changed" unless container.fetch("image") == "template-placeholder"
5280
failures << "ports changed" unless container.fetch("ports") == expected_ports
5381
failures << "readinessProbe changed" unless container.fetch("readinessProbe") == expected_readiness_probe
5482
failures << "livenessProbe grace or thresholds changed" unless container.fetch("livenessProbe") == expected_liveness_probe
83+
failures << "default autoscaling or capacityAI changed" unless spec.fetch("defaultOptions") == expected_default_options
84+
failures << "firewall configuration changed" unless spec.fetch("firewallConfig") == expected_firewall_config
85+
failures << "identity link changed" unless spec.fetch("identityLink") == "template-placeholder"
86+
87+
cpu_match = /\A(?<millicores>\d+)m\z/.match(container.fetch("cpu").to_s)
88+
memory_match = /\A(?<mebibytes>\d+)Mi\z/.match(container.fetch("memory").to_s)
89+
if cpu_match && memory_match && cpu_match[:millicores].to_i.positive?
90+
resource_ratio = memory_match[:mebibytes].to_f / cpu_match[:millicores].to_i
91+
failures << format("provider resource ratio must be strictly below 8 (got %.2f)", resource_ratio) unless resource_ratio < 8
92+
else
93+
failures << "renderer resources must use positive millicore CPU and MiB memory units"
94+
end
5595
5696
abort failures.join("\n") unless failures.empty?
57-
puts "node renderer template preserves supported probe grace and stable runtime settings"
97+
puts "node renderer template preserves provider resource ratio, supported probe grace, and stable runtime settings"
5898
RUBY
5999

60100
echo "==> parse generated GitHub Actions YAML"

0 commit comments

Comments
 (0)