Conversation
haiyanmeng
left a comment
There was a problem hiding this comment.
After an upgrade, every existing pool keeps its old substrate-<truncated>-<hash> policy, and nothing updates it anymore. NetworkPolicies combine as a union of allows. So if a later release tightens these rules (or SystemNamespace changes), the stale policy keeps admitting the old peers until the pool is deleted.
So this seems like a breaking change and needs doc update to guide users how to upgrade safely.
|
that make sense, thanks for catching! Do we just want to document a manual step for cleanup the old networkpolicy? or have controller to do the deletion of it? |
This is still before GA. So a manual cleanup should be acceptable. I am okay with either way. Will leave the decision for you and Bowei Du (@bowei) to make. |
|
I think this is ok change, but is the name collision real or theoretical? |
it hasn't been seen in practice, and an accidental collision is unlikely at normal pool counts. E.g. tried a python loop found |
41f17bf to
1b8238f
Compare
|
Added the |
|
Please get the release shepherds to merge |
A WorkerPool name can be up to 253 characters, but `ate-controller` puts it in the `ate.dev/worker-pool` label on the worker pods and the pool's NetworkPolicy. Label values are capped at 63 characters. A longer name is accepted, and then every reconcile of the pool fails, with the error only in the controller log. The CRD now rejects names longer than 63 characters at create time. Came up while reviewing agent-substrate#3130. AI use: Claude Code wrote the change, the test rows and this description. I reviewed them.
The name kept 30 characters of the pool name and 20 bits of hash, so two pools could get the same NetworkPolicy and overwrite each other's selector. Signed-off-by: Yufan Su <yufans@google.com>
Signed-off-by: Yufan Su <yufans@google.com>
Signed-off-by: Yufan Su <yufans@google.com>
Signed-off-by: Yufan Su <yufans@google.com>
1b8238f to
d957588
Compare
|
Benjamin Elder (@BenTheElder) PR is updated with DCO. PTAL, thanks! |
A WorkerPool name can be up to 253 characters, but `ate-controller` puts it in the `ate.dev/worker-pool` label on the worker pods and the pool's NetworkPolicy. Label values are capped at 63 characters. A longer name is accepted, and then every reconcile of the pool fails, with the error only in the controller log. The CRD now rejects names longer than 63 characters at create time. Came up while reviewing agent-substrate#3130. AI use: Claude Code wrote the change, the test rows and this description. I reviewed them.
…gent-substrate#3130) Fixes agent-substrate#2934 Builds on agent-substrate#2956 by @ericcurtin, with additional fixes when appling network policy. ### Why `NetworkPolicyName` kept only the first 30 characters of the pool name plus 5 hex digits of its SHA-256. Two pools in the same namespace could get the same NetworkPolicy name. The controller applies with `ForceOwnership`, so the second pool took over the first pool's policy and rewrote its pod selector. ### What changed - The name is now `resources.NetworkPolicyNamePrefix` (`substrate-`) plus the pool name. The pool name is also the `ate.dev/worker-pool` label value, which Kubernetes caps at 63 characters, so the name needs no truncation. On upgrade, each existing pool gets a second policy under the new name. The old one has the same rules and is deleted with the pool. - Before applying, the controller reads the existing policy. It refuses to take it over if another object controls it, or if nothing controls it and its `ate.dev/worker-pool` label isn't the pool's name. A refusal returns an error and emits a `NetworkPolicyConflict` Warning event on the WorkerPool. ### Upgrade The new ate-controller creates `substrate-<pool>` for each pool, but leaves the old `substrate-<truncated>-<hash>` policy in place until the pool is deleted. Policies add together, so if a later release tightens the rule, the old policy keeps admitting the old peers. If you upgrade in place, wait until the new ate-controller has created `substrate-<pool>` for each pool, then delete the old policies: ```sh kubectl get networkpolicy -A -o go-template='{{range .items}}{{$np := .}}{{range .metadata.ownerReferences}}{{if and .controller (eq .kind "WorkerPool") (ne $np.metadata.name (printf "substrate-%s" .name))}}{{$np.metadata.namespace}} {{$np.metadata.name}}{{"\n"}}{{end}}{{end}}{{end}}' | while read -r ns name; do kubectl -n "$ns" delete networkpolicy "$name"; done ``` This deletes only policies a WorkerPool controls whose name isn't `substrate-<pool>`. Run the `kubectl get` part alone first to see the list. AI use: AI-assisted (Claude Code). Code reviewed by myself. - [x] Tests pass - [ ] Docs updated (none needed) --------- Signed-off-by: Yufan Su <yufans@google.com> Co-authored-by: Eric Curtin <eric.curtin@docker.com>
Fixes #2934
Builds on #2956 by Eric Curtin (@ericcurtin), with additional fixes when appling network policy.
Why
NetworkPolicyNamekept only the first 30 characters of the pool name plus 5 hex digits of its SHA-256. Two pools in the same namespace could get the same NetworkPolicy name. The controller applies withForceOwnership, so the second pool took over the first pool's policy and rewrote its pod selector.What changed
resources.NetworkPolicyNamePrefix(substrate-) plus the pool name. The pool name is also theate.dev/worker-poollabel value, which Kubernetes caps at 63 characters, so the name needs no truncation. On upgrade, each existing pool gets a second policy under the new name. The old one has the same rules and is deleted with the pool.ate.dev/worker-poollabel isn't the pool's name. A refusal returns an error and emits aNetworkPolicyConflictWarning event on the WorkerPool.Upgrade
The new ate-controller creates
substrate-<pool>for each pool, but leaves the oldsubstrate-<truncated>-<hash>policy in place until the pool is deleted. Policies add together, so if a later release tightens the rule, the old policy keeps admitting the old peers.If you upgrade in place, wait until the new ate-controller has created
substrate-<pool>for each pool, then delete the old policies:This deletes only policies a WorkerPool controls whose name isn't
substrate-<pool>. Run thekubectl getpart alone first to see the list.AI use: AI-assisted (Claude Code). Code reviewed by myself.