Skip to content

Commit 5f982e7

Browse files
committed
Fix the failing Proxy test cases - precedence for proxy env vars from olm and openshift proxy CR were broken
1 parent c61fff5 commit 5f982e7

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

pkg/controller/external_secrets/utils.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,29 @@ func (r *Reconciler) IsCertManagerInstalled() bool {
125125
return ok
126126
}
127127

128+
// hasProxyURLs reports whether a ProxyConfig carries at least one proxy URL
129+
// (HTTPProxy, HTTPSProxy, or NoProxy). Control-plane fields like
130+
// NetworkPolicyProvisioning are intentionally excluded — they configure
131+
// operator behavior, not proxy endpoints.
132+
func hasProxyURLs(p *operatorv1alpha1.ProxyConfig) bool {
133+
return p != nil && (p.HTTPProxy != "" || p.HTTPSProxy != "" || p.NoProxy != "")
134+
}
135+
128136
// getProxyConfiguration returns the proxy configuration based on precedence.
129137
// The precedence order is: ExternalSecretsConfig > ExternalSecretsManager > OLM environment variables.
138+
// Only proxy URL fields (HTTPProxy, HTTPSProxy, NoProxy) participate in the
139+
// precedence decision; a ProxyConfig that carries only control-plane fields
140+
// (e.g. NetworkPolicyProvisioning) is treated as empty and falls through to the
141+
// next source. After resolving the URLs, any NetworkPolicyProvisioning value set
142+
// on the ExternalSecretsConfig CR is merged into the result so that administrators
143+
// can control network-policy management independently of where the proxy URLs originate.
130144
func (r *Reconciler) getProxyConfiguration(esc *operatorv1alpha1.ExternalSecretsConfig) (*operatorv1alpha1.ProxyConfig, error) {
131145
var proxyConfig *operatorv1alpha1.ProxyConfig
132146

133-
// Check ExternalSecretsConfig first
134147
switch {
135-
case esc.Spec.ApplicationConfig.Proxy != nil:
148+
case hasProxyURLs(esc.Spec.ApplicationConfig.Proxy):
136149
proxyConfig = esc.Spec.ApplicationConfig.Proxy
137-
case r.esm.Spec.GlobalConfig != nil && r.esm.Spec.GlobalConfig.Proxy != nil:
138-
// Check ExternalSecretsManager second
150+
case r.esm.Spec.GlobalConfig != nil && hasProxyURLs(r.esm.Spec.GlobalConfig.Proxy):
139151
proxyConfig = r.esm.Spec.GlobalConfig.Proxy
140152
default:
141153
// Fall back to OLM environment variables
@@ -153,6 +165,15 @@ func (r *Reconciler) getProxyConfiguration(esc *operatorv1alpha1.ExternalSecrets
153165
}
154166
}
155167

168+
// Merge NetworkPolicyProvisioning from the CR even when proxy URLs came
169+
// from a lower-priority source, so administrators can control network-policy
170+
// management independently.
171+
if crProxy := esc.Spec.ApplicationConfig.Proxy; crProxy != nil && proxyConfig != nil {
172+
if crProxy.NetworkPolicyProvisioning != "" {
173+
proxyConfig.NetworkPolicyProvisioning = crProxy.NetworkPolicyProvisioning
174+
}
175+
}
176+
156177
if proxyConfig != nil {
157178
if err := validateProxy(proxyConfig.HTTPProxy); err != nil {
158179
return nil, fmt.Errorf("failed to validate HTTP proxy: %w", err)

test/e2e/e2e_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ const (
8383
const (
8484
userNPPrefix = "eso-user-"
8585
npProxyEgressPolicyName = "eso-sys-allow-proxy-egress"
86-
managedByLabel = "app.kubernetes.io/managed-by"
87-
partOfLabel = "app.kubernetes.io/part-of"
88-
managedByValue = "external-secrets-operator"
86+
managedByLabel = "app.kubernetes.io/managed-by"
87+
partOfLabel = "app.kubernetes.io/part-of"
88+
managedByValue = "external-secrets-operator"
8989
)
9090

9191
var expectedStaticNPNames = []string{
@@ -1020,7 +1020,7 @@ var _ = Describe("External Secrets Operator End-to-End test scenarios", Ordered,
10201020
Expect(err).NotTo(HaveOccurred(), "should set proxy config with Unmanaged provisioning")
10211021

10221022
By("Verifying proxy egress policy is not created")
1023-
Consistently(func(g Gomega) {
1023+
Eventually(func(g Gomega) {
10241024
_, err := clientset.NetworkingV1().NetworkPolicies(operandNamespace).Get(ctx, npProxyEgressPolicyName, metav1.GetOptions{})
10251025
g.Expect(err).To(HaveOccurred(), "proxy egress policy should not exist when provisioning is Unmanaged")
10261026
}, 30*time.Second, 5*time.Second).Should(Succeed())

0 commit comments

Comments
 (0)