Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy: Ignore visibility annotation if proxy is disabled #27597

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Documentation/observability/visibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
Layer 7 Protocol Visibility
***************************

.. note::

This feature requires enabling L7 Proxy support. Without it, the visibility annotation is ignored.

While :ref:`monitor` provides introspection into datapath state, by default it
will only provide visibility into L3/L4 packet events. If :ref:`l7_policy` are
configured, one can get visibility into L7 protocols, but this requires the full
Expand Down
3 changes: 2 additions & 1 deletion daemon/cmd/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (d *Daemon) createEndpoint(ctx context.Context, owner regeneration.Owner, e
return d.errorDuringCreation(ep, fmt.Errorf("unable to insert endpoint into manager: %s", err))
}

// We need to update the the visibility policy after adding the endpoint in
// We need to update the visibility policy after adding the endpoint in
// the endpoint manager because the endpoint manager create the endpoint
// queue of the endpoint. If we execute this function before the endpoint
// manager creates the endpoint queue the operation will fail.
Expand All @@ -488,6 +488,7 @@ func (d *Daemon) createEndpoint(ctx context.Context, owner regeneration.Owner, e
value, _ := annotation.Get(p, annotation.ProxyVisibility, annotation.ProxyVisibilityAlias)
return value, nil
})

ep.UpdateBandwidthPolicy(func(ns, podName string) (bandwidthEgress string, err error) {
_, p, err := d.endpointMetadataFetcher.Fetch(ns, podName)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions install/kubernetes/cilium/templates/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
{{- end }}
{{- end }}

{{- if or .Values.ingressController.enabled .Values.gatewayAPI.enabled }}
{{- if or .Values.ingressController.enabled .Values.gatewayAPI.enabled (eq .Values.loadBalancer.l7.backend "envoy") }}
{{- if hasKey .Values "l7Proxy" }}
{{- if not .Values.l7Proxy }}
{{ fail "Ingress or Gateway API controller requires .Values.l7Proxy to be set to 'true'" }}
{{ fail "Ingress or Gateway API controller or Envoy L7 Load Balancer requires .Values.l7Proxy to be set to 'true'" }}
{{- end }}
{{- end }}
{{- end }}
Expand Down
4 changes: 2 additions & 2 deletions pkg/endpoint/bpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (e *Endpoint) GetLabelsLocked(id identity.NumericIdentity) labels.LabelArra
// problem that occurred while adding an l7 redirect for the specified policy.
// Must be called with endpoint.mutex Lock()ed.
func (e *Endpoint) addNewRedirectsFromDesiredPolicy(ingress bool, desiredRedirects map[string]bool, proxyWaitGroup *completion.WaitGroup) (error, revert.FinalizeFunc, revert.RevertFunc) {
if option.Config.DryMode || e.isProxyDisabled() {
if option.Config.DryMode || e.IsProxyDisabled() {
return nil, nil, nil
}

Expand Down Expand Up @@ -310,7 +310,7 @@ func (e *Endpoint) addVisibilityRedirects(ingress bool, desiredRedirects map[str
}
)

if e.visibilityPolicy == nil {
if e.visibilityPolicy == nil || e.IsProxyDisabled() {
return nil, finalizeList.Finalize, revertStack.Revert
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/endpoint/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ func (ev *EndpointPolicyVisibilityEvent) Handle(res chan interface{}) {
return
}
if proxyVisibility != "" {
if e.IsProxyDisabled() {
e.getLogger().
WithField(logfields.EndpointID, e.GetID()).
Warn("ignoring L7 proxy visibility policy as L7 proxy is disabled")
res <- &EndpointRegenerationResult{
err: nil,
}
return
}
e.getLogger().Debug("creating visibility policy")
nvp, err = policy.NewVisibilityPolicy(proxyVisibility)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/endpoint/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (e *Endpoint) updateNetworkPolicy(proxyWaitGroup *completion.WaitGroup) (re
return nil, nil
}

if e.isProxyDisabled() {
if e.IsProxyDisabled() {
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/endpoint/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

func (s *EndpointSuite) TestUpdateVisibilityPolicy(c *check.C) {
do := &DummyOwner{repo: policy.NewPolicyRepository(nil, nil, nil, nil)}
ep := NewEndpointWithState(do, do, testipcache.NewMockIPCache(), nil, testidentity.NewMockIdentityAllocator(nil), 12345, StateReady)
ep := NewEndpointWithState(do, do, testipcache.NewMockIPCache(), &FakeEndpointProxy{}, testidentity.NewMockIdentityAllocator(nil), 12345, StateReady)
ep.UpdateVisibilityPolicy(func(_, _ string) (string, error) {
return "", nil
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/endpoint/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func (e *Endpoint) SetProxy(p EndpointProxy) {
}

func (e *Endpoint) removeNetworkPolicy() {
if e.isProxyDisabled() {
if e.IsProxyDisabled() {
return
}
e.proxy.RemoveNetworkPolicy(e)
}

func (e *Endpoint) isProxyDisabled() bool {
func (e *Endpoint) IsProxyDisabled() bool {
return e.proxy == nil || reflect.ValueOf(e.proxy).IsNil()
}

Expand Down