|
3 | 3 | nodetypeNodeSelector, |
4 | 4 | runPodTolerations, |
5 | 5 | runnerSecurityContext, |
| 6 | + withReservedSourcePorts, |
6 | 7 | withRunnerSeccompProfile, |
7 | 8 | withNodeSelector, |
8 | 9 | } from "./kubernetesPodSpec.js"; |
@@ -155,6 +156,51 @@ describe("withRunnerSeccompProfile", () => { |
155 | 156 | }); |
156 | 157 | }); |
157 | 158 |
|
| 159 | +describe("withReservedSourcePorts", () => { |
| 160 | + const reserved = { name: "net.ipv4.ip_local_reserved_ports", value: "50080,50081" }; |
| 161 | + |
| 162 | + it("leaves the spec untouched when unset", () => { |
| 163 | + for (const ports of [undefined, ""]) { |
| 164 | + expect(withReservedSourcePorts(basePodSpec, ports)).toBe(basePodSpec); |
| 165 | + } |
| 166 | + }); |
| 167 | + |
| 168 | + it("adds the sysctl and keeps the rest of the security context", () => { |
| 169 | + expect(withReservedSourcePorts(basePodSpec, "50080,50081")).toEqual({ |
| 170 | + ...basePodSpec, |
| 171 | + securityContext: { ...basePodSpec.securityContext, sysctls: [reserved] }, |
| 172 | + }); |
| 173 | + }); |
| 174 | + |
| 175 | + it("adds a security context when the spec has none", () => { |
| 176 | + expect(withReservedSourcePorts({ restartPolicy: "Never" }, "50080,50081")).toEqual({ |
| 177 | + restartPolicy: "Never", |
| 178 | + securityContext: { sysctls: [reserved] }, |
| 179 | + }); |
| 180 | + }); |
| 181 | + |
| 182 | + it("preserves existing sysctls", () => { |
| 183 | + const existing = { name: "net.ipv4.ip_local_port_range", value: "32768 60999" }; |
| 184 | + const podSpec = { ...basePodSpec, securityContext: { sysctls: [existing] } }; |
| 185 | + |
| 186 | + expect(withReservedSourcePorts(podSpec, "50080,50081").securityContext?.sysctls).toEqual([ |
| 187 | + existing, |
| 188 | + reserved, |
| 189 | + ]); |
| 190 | + }); |
| 191 | + |
| 192 | + it("replaces an existing value rather than duplicating the name", () => { |
| 193 | + const podSpec = { |
| 194 | + ...basePodSpec, |
| 195 | + securityContext: { sysctls: [{ ...reserved, value: "40000" }] }, |
| 196 | + }; |
| 197 | + |
| 198 | + expect(withReservedSourcePorts(podSpec, "50080,50081").securityContext?.sysctls).toEqual([ |
| 199 | + reserved, |
| 200 | + ]); |
| 201 | + }); |
| 202 | +}); |
| 203 | + |
158 | 204 | describe("runnerSecurityContext", () => { |
159 | 205 | it("sets nothing when off", () => { |
160 | 206 | expect(runnerSecurityContext("off", 1000, "node-24")).toBeUndefined(); |
|
0 commit comments