Skip to content

Commit a1d05f6

Browse files
tmshortclaude
andcommitted
fix: clear proxy vars from containers removed from inject-proxy annotation
The previous fix only cleaned up stale proxy env vars when the annotation was entirely removed. If the annotation changed from "manager,sidecar" to "manager", the sidecar container kept HTTP_PROXY/HTTPS_PROXY/NO_PROXY owned by capi-operator-proxy indefinitely. Now for each workload we split containers into two groups: - Containers named in the annotation: proxy vars applied (or refreshed) - Containers in the spec but NOT in the annotation: empty env applied, removing our SSA field-manager ownership of any proxy vars we set before This covers three cases cleanly: - Annotation absent: all containers cleared (existing behaviour) - Annotation present, unchanged: annotated get vars, non-annotated get cleared (no-op if we never owned their env vars) - Annotation shrinks: dropped containers get cleared, remaining get vars Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Todd Short <tshort@redhat.com>
1 parent 228d14c commit a1d05f6

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

pkg/controllers/installer/proxy_controller.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,40 @@ func (c *ProxyController) applyToAllWorkloads(ctx context.Context, proxyVars []c
173173
var errs []error
174174

175175
for _, item := range items {
176-
var containers []string
176+
allContainers := containerNamesFromSpec(item.containers)
177+
annotation, hasAnnotation := item.podAnnotations[ProxyInjectAnnotation]
177178

178-
effectiveVars := proxyVars
179+
if !hasAnnotation {
180+
// No annotation: clear any stale proxy env vars from all containers.
181+
if err := c.applyProxyVars(ctx, item.apiVersion, item.kind, item.name, item.namespace, allContainers, nil); err != nil {
182+
errs = append(errs, err)
183+
}
179184

180-
annotation, hasAnnotation := item.podAnnotations[ProxyInjectAnnotation]
181-
if hasAnnotation {
182-
containers = containerNamesFromAnnotation(annotation)
183-
} else {
184-
// No annotation: clear any stale proxy env vars we previously owned
185-
// so that opting out removes the env vars instead of leaving them.
186-
containers = containerNamesFromSpec(item.containers)
187-
effectiveVars = nil
185+
continue
186+
}
187+
188+
// Apply proxy vars to the containers named in the annotation.
189+
targets := containerNamesFromAnnotation(annotation)
190+
if err := c.applyProxyVars(ctx, item.apiVersion, item.kind, item.name, item.namespace, targets, proxyVars); err != nil {
191+
errs = append(errs, err)
192+
}
193+
194+
// Clear proxy vars from containers that were removed from the annotation
195+
// (e.g. annotation changed from "manager,sidecar" to "manager").
196+
targetSet := make(map[string]struct{}, len(targets))
197+
for _, name := range targets {
198+
targetSet[name] = struct{}{}
199+
}
200+
201+
var stale []string
202+
203+
for _, name := range allContainers {
204+
if _, ok := targetSet[name]; !ok {
205+
stale = append(stale, name)
206+
}
188207
}
189208

190-
if err := c.applyProxyVars(ctx, item.apiVersion, item.kind, item.name, item.namespace, containers, effectiveVars); err != nil {
209+
if err := c.applyProxyVars(ctx, item.apiVersion, item.kind, item.name, item.namespace, stale, nil); err != nil {
191210
errs = append(errs, err)
192211
}
193212
}

0 commit comments

Comments
 (0)