Skip to content

Commit

Permalink
endpoint: Add GetRealizedPolicyRuleLabelsForKey
Browse files Browse the repository at this point in the history
This function allows callers to get the list of policies which caused a
certain policy map entry to be added for a given endpoint.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
  • Loading branch information
gandro authored and aanm committed Mar 18, 2020
1 parent 92937c1 commit a62c369
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/endpoint/policy.go
Expand Up @@ -751,3 +751,23 @@ func (e *Endpoint) UpdateVisibilityPolicy(annoCB AnnotationsResolverCB) {
}
<-ch
}

// GetRealizedPolicyRuleLabelsForKey returns the list of policy rule labels
// which match a given flow key (in host byte-order). The returned
// LabelArrayList must not be modified. This function is exported to be
// accessed by code outside of the Cilium code base (e.g. Hubble).
func (e *Endpoint) GetRealizedPolicyRuleLabelsForKey(key policy.Key) (
derivedFrom labels.LabelArrayList,
revision uint64,
ok bool,
) {
e.mutex.RLock()
defer e.mutex.RUnlock()

entry, ok := e.realizedPolicy.PolicyMapState[key]
if !ok {
return nil, 0, false
}

return entry.DerivedFromRules, e.policyRevision, true
}

0 comments on commit a62c369

Please sign in to comment.