id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
162,900 | cilium/cilium | pkg/k8s/annotate.go | AnnotateNode | func (k8sCli K8sClient) AnnotateNode(nodeName string, v4CIDR, v6CIDR *cidr.CIDR, v4HealthIP, v6HealthIP, v4CiliumHostIP, v6CiliumHostIP net.IP) error {
scopedLog := log.WithFields(logrus.Fields{
logfields.NodeName: nodeName,
logfields.V4Prefix: v4CIDR,
logfields.V6Prefix: v6CIDR,
logfields.V4HealthIP: v4HealthIP,
logfields.V6HealthIP: v6HealthIP,
logfields.V4CiliumHostIP: v4CiliumHostIP,
logfields.V6CiliumHostIP: v6CiliumHostIP,
})
scopedLog.Debug("Updating node annotations with node CIDRs")
go func(c kubernetes.Interface, nodeName string, v4CIDR, v6CIDR *cidr.CIDR, v4HealthIP, v6HealthIP, v4CiliumHostIP, v6CiliumHostIP net.IP) {
var node *v1.Node
var err error
for n := 1; n <= maxUpdateRetries; n++ {
if node == nil {
node, err = GetNode(c, nodeName)
if errors.IsNotFound(err) {
err = ErrNilNode
}
}
if err == nil && node != nil {
node, err = updateNodeAnnotation(c, node, v4CIDR, v6CIDR, v4HealthIP, v6HealthIP, v4CiliumHostIP, v6CiliumHostIP)
}
switch {
case err == nil:
return
case errors.IsConflict(err):
scopedLog.WithFields(logrus.Fields{
fieldRetry: n,
fieldMaxRetry: maxUpdateRetries,
}).WithError(err).Debugf("Unable to update node resource with annotation")
default:
scopedLog.WithFields(logrus.Fields{
fieldRetry: n,
fieldMaxRetry: maxUpdateRetries,
}).WithError(err).Warn("Unable to update node resource with annotation")
}
time.Sleep(time.Duration(n) * time.Second)
}
}(k8sCli, nodeName, v4CIDR, v6CIDR, v4HealthIP, v6HealthIP, v4CiliumHostIP, v6CiliumHostIP)
return nil
} | go | func (k8sCli K8sClient) AnnotateNode(nodeName string, v4CIDR, v6CIDR *cidr.CIDR, v4HealthIP, v6HealthIP, v4CiliumHostIP, v6CiliumHostIP net.IP) error {
scopedLog := log.WithFields(logrus.Fields{
logfields.NodeName: nodeName,
logfields.V4Prefix: v4CIDR,
logfields.V6Prefix: v6CIDR,
logfields.V4HealthIP: v4HealthIP,
logfields.V6HealthIP: v6HealthIP,
logfields.V4CiliumHostIP: v4CiliumHostIP,
logfields.V6CiliumHostIP: v6CiliumHostIP,
})
scopedLog.Debug("Updating node annotations with node CIDRs")
go func(c kubernetes.Interface, nodeName string, v4CIDR, v6CIDR *cidr.CIDR, v4HealthIP, v6HealthIP, v4CiliumHostIP, v6CiliumHostIP net.IP) {
var node *v1.Node
var err error
for n := 1; n <= maxUpdateRetries; n++ {
if node == nil {
node, err = GetNode(c, nodeName)
if errors.IsNotFound(err) {
err = ErrNilNode
}
}
if err == nil && node != nil {
node, err = updateNodeAnnotation(c, node, v4CIDR, v6CIDR, v4HealthIP, v6HealthIP, v4CiliumHostIP, v6CiliumHostIP)
}
switch {
case err == nil:
return
case errors.IsConflict(err):
scopedLog.WithFields(logrus.Fields{
fieldRetry: n,
fieldMaxRetry: maxUpdateRetries,
}).WithError(err).Debugf("Unable to update node resource with annotation")
default:
scopedLog.WithFields(logrus.Fields{
fieldRetry: n,
fieldMaxRetry: maxUpdateRetries,
}).WithError(err).Warn("Unable to update node resource with annotation")
}
time.Sleep(time.Duration(n) * time.Second)
}
}(k8sCli, nodeName, v4CIDR, v6CIDR, v4HealthIP, v6HealthIP, v4CiliumHostIP, v6CiliumHostIP)
return nil
} | [
"func",
"(",
"k8sCli",
"K8sClient",
")",
"AnnotateNode",
"(",
"nodeName",
"string",
",",
"v4CIDR",
",",
"v6CIDR",
"*",
"cidr",
".",
"CIDR",
",",
"v4HealthIP",
",",
"v6HealthIP",
",",
"v4CiliumHostIP",
",",
"v6CiliumHostIP",
"net",
".",
"IP",
")",
"error",
"{",
"scopedLog",
":=",
"log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"NodeName",
":",
"nodeName",
",",
"logfields",
".",
"V4Prefix",
":",
"v4CIDR",
",",
"logfields",
".",
"V6Prefix",
":",
"v6CIDR",
",",
"logfields",
".",
"V4HealthIP",
":",
"v4HealthIP",
",",
"logfields",
".",
"V6HealthIP",
":",
"v6HealthIP",
",",
"logfields",
".",
"V4CiliumHostIP",
":",
"v4CiliumHostIP",
",",
"logfields",
".",
"V6CiliumHostIP",
":",
"v6CiliumHostIP",
",",
"}",
")",
"\n",
"scopedLog",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"go",
"func",
"(",
"c",
"kubernetes",
".",
"Interface",
",",
"nodeName",
"string",
",",
"v4CIDR",
",",
"v6CIDR",
"*",
"cidr",
".",
"CIDR",
",",
"v4HealthIP",
",",
"v6HealthIP",
",",
"v4CiliumHostIP",
",",
"v6CiliumHostIP",
"net",
".",
"IP",
")",
"{",
"var",
"node",
"*",
"v1",
".",
"Node",
"\n",
"var",
"err",
"error",
"\n\n",
"for",
"n",
":=",
"1",
";",
"n",
"<=",
"maxUpdateRetries",
";",
"n",
"++",
"{",
"if",
"node",
"==",
"nil",
"{",
"node",
",",
"err",
"=",
"GetNode",
"(",
"c",
",",
"nodeName",
")",
"\n",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"err",
"=",
"ErrNilNode",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
"==",
"nil",
"&&",
"node",
"!=",
"nil",
"{",
"node",
",",
"err",
"=",
"updateNodeAnnotation",
"(",
"c",
",",
"node",
",",
"v4CIDR",
",",
"v6CIDR",
",",
"v4HealthIP",
",",
"v6HealthIP",
",",
"v4CiliumHostIP",
",",
"v6CiliumHostIP",
")",
"\n",
"}",
"\n\n",
"switch",
"{",
"case",
"err",
"==",
"nil",
":",
"return",
"\n",
"case",
"errors",
".",
"IsConflict",
"(",
"err",
")",
":",
"scopedLog",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"fieldRetry",
":",
"n",
",",
"fieldMaxRetry",
":",
"maxUpdateRetries",
",",
"}",
")",
".",
"WithError",
"(",
"err",
")",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"scopedLog",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"fieldRetry",
":",
"n",
",",
"fieldMaxRetry",
":",
"maxUpdateRetries",
",",
"}",
")",
".",
"WithError",
"(",
"err",
")",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"time",
".",
"Duration",
"(",
"n",
")",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"}",
"(",
"k8sCli",
",",
"nodeName",
",",
"v4CIDR",
",",
"v6CIDR",
",",
"v4HealthIP",
",",
"v6HealthIP",
",",
"v4CiliumHostIP",
",",
"v6CiliumHostIP",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // AnnotateNode writes v4 and v6 CIDRs and health IPs in the given k8s node name.
// In case of failure while updating the node, this function while spawn a go
// routine to retry the node update indefinitely. | [
"AnnotateNode",
"writes",
"v4",
"and",
"v6",
"CIDRs",
"and",
"health",
"IPs",
"in",
"the",
"given",
"k8s",
"node",
"name",
".",
"In",
"case",
"of",
"failure",
"while",
"updating",
"the",
"node",
"this",
"function",
"while",
"spawn",
"a",
"go",
"routine",
"to",
"retry",
"the",
"node",
"update",
"indefinitely",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/annotate.go#L86-L134 |
162,901 | cilium/cilium | api/v1/models/endpoint_health_status.go | Validate | func (m EndpointHealthStatus) Validate(formats strfmt.Registry) error {
var res []error
// value enum
if err := m.validateEndpointHealthStatusEnum("", "body", m); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | go | func (m EndpointHealthStatus) Validate(formats strfmt.Registry) error {
var res []error
// value enum
if err := m.validateEndpointHealthStatusEnum("", "body", m); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | [
"func",
"(",
"m",
"EndpointHealthStatus",
")",
"Validate",
"(",
"formats",
"strfmt",
".",
"Registry",
")",
"error",
"{",
"var",
"res",
"[",
"]",
"error",
"\n\n",
"// value enum",
"if",
"err",
":=",
"m",
".",
"validateEndpointHealthStatusEnum",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"m",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"res",
")",
">",
"0",
"{",
"return",
"errors",
".",
"CompositeValidationError",
"(",
"res",
"...",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate validates this endpoint health status | [
"Validate",
"validates",
"this",
"endpoint",
"health",
"status"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/models/endpoint_health_status.go#L64-L76 |
162,902 | cilium/cilium | pkg/proxy/kafka.go | createKafkaRedirect | func createKafkaRedirect(r *Redirect, conf kafkaConfiguration, endpointInfoRegistry logger.EndpointInfoRegistry) (RedirectImplementation, error) {
redir := &kafkaRedirect{
redirect: r,
conf: conf,
endpointInfoRegistry: endpointInfoRegistry,
}
if redir.conf.lookupSrcID == nil {
redir.conf.lookupSrcID = lookupSrcID
}
// must register with the proxy port for unit tests (no IP_TRANSPARENT)
dstPort := r.dstPort
if conf.testMode {
dstPort = r.listener.proxyPort
}
key := mapKey(dstPort, r.listener.ingress, uint16(r.endpointID))
log.WithField(logfields.EndpointID, r.endpointID).Debugf(
"Registering %s with port: %d, ingress: %v",
r.listener.name, dstPort, r.listener.ingress)
mutex.Lock()
if _, ok := kafkaRedirects[key]; ok {
mutex.Unlock()
panic("Kafka redirect already exists for the given dst port and endpoint ID")
}
kafkaRedirects[key] = redir
// Start a listener if not already running
listener := kafkaListeners[r.listener.proxyPort]
if listener == nil {
marker := 0
if !conf.testMode {
marker = linux_defaults.GetMagicProxyMark(r.listener.ingress, 0)
}
// Listen needs to be in the synchronous part of this function to ensure that
// the proxy port is never refusing connections.
socket, err := listenSocket(fmt.Sprintf(":%d", r.listener.proxyPort), marker, !conf.testMode)
if err != nil {
delete(kafkaRedirects, key)
mutex.Unlock()
return nil, err
}
listener = &kafkaListener{
socket: socket,
proxyPort: r.listener.proxyPort,
endpointInfoRegistry: endpointInfoRegistry,
ingress: r.listener.ingress,
transparent: !conf.testMode,
count: 0,
}
go listener.Listen()
kafkaListeners[r.listener.proxyPort] = listener
}
listener.count++
redir.listener = listener
mutex.Unlock()
return redir, nil
} | go | func createKafkaRedirect(r *Redirect, conf kafkaConfiguration, endpointInfoRegistry logger.EndpointInfoRegistry) (RedirectImplementation, error) {
redir := &kafkaRedirect{
redirect: r,
conf: conf,
endpointInfoRegistry: endpointInfoRegistry,
}
if redir.conf.lookupSrcID == nil {
redir.conf.lookupSrcID = lookupSrcID
}
// must register with the proxy port for unit tests (no IP_TRANSPARENT)
dstPort := r.dstPort
if conf.testMode {
dstPort = r.listener.proxyPort
}
key := mapKey(dstPort, r.listener.ingress, uint16(r.endpointID))
log.WithField(logfields.EndpointID, r.endpointID).Debugf(
"Registering %s with port: %d, ingress: %v",
r.listener.name, dstPort, r.listener.ingress)
mutex.Lock()
if _, ok := kafkaRedirects[key]; ok {
mutex.Unlock()
panic("Kafka redirect already exists for the given dst port and endpoint ID")
}
kafkaRedirects[key] = redir
// Start a listener if not already running
listener := kafkaListeners[r.listener.proxyPort]
if listener == nil {
marker := 0
if !conf.testMode {
marker = linux_defaults.GetMagicProxyMark(r.listener.ingress, 0)
}
// Listen needs to be in the synchronous part of this function to ensure that
// the proxy port is never refusing connections.
socket, err := listenSocket(fmt.Sprintf(":%d", r.listener.proxyPort), marker, !conf.testMode)
if err != nil {
delete(kafkaRedirects, key)
mutex.Unlock()
return nil, err
}
listener = &kafkaListener{
socket: socket,
proxyPort: r.listener.proxyPort,
endpointInfoRegistry: endpointInfoRegistry,
ingress: r.listener.ingress,
transparent: !conf.testMode,
count: 0,
}
go listener.Listen()
kafkaListeners[r.listener.proxyPort] = listener
}
listener.count++
redir.listener = listener
mutex.Unlock()
return redir, nil
} | [
"func",
"createKafkaRedirect",
"(",
"r",
"*",
"Redirect",
",",
"conf",
"kafkaConfiguration",
",",
"endpointInfoRegistry",
"logger",
".",
"EndpointInfoRegistry",
")",
"(",
"RedirectImplementation",
",",
"error",
")",
"{",
"redir",
":=",
"&",
"kafkaRedirect",
"{",
"redirect",
":",
"r",
",",
"conf",
":",
"conf",
",",
"endpointInfoRegistry",
":",
"endpointInfoRegistry",
",",
"}",
"\n\n",
"if",
"redir",
".",
"conf",
".",
"lookupSrcID",
"==",
"nil",
"{",
"redir",
".",
"conf",
".",
"lookupSrcID",
"=",
"lookupSrcID",
"\n",
"}",
"\n\n",
"// must register with the proxy port for unit tests (no IP_TRANSPARENT)",
"dstPort",
":=",
"r",
".",
"dstPort",
"\n",
"if",
"conf",
".",
"testMode",
"{",
"dstPort",
"=",
"r",
".",
"listener",
".",
"proxyPort",
"\n",
"}",
"\n",
"key",
":=",
"mapKey",
"(",
"dstPort",
",",
"r",
".",
"listener",
".",
"ingress",
",",
"uint16",
"(",
"r",
".",
"endpointID",
")",
")",
"\n",
"log",
".",
"WithField",
"(",
"logfields",
".",
"EndpointID",
",",
"r",
".",
"endpointID",
")",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"r",
".",
"listener",
".",
"name",
",",
"dstPort",
",",
"r",
".",
"listener",
".",
"ingress",
")",
"\n",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"kafkaRedirects",
"[",
"key",
"]",
";",
"ok",
"{",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"kafkaRedirects",
"[",
"key",
"]",
"=",
"redir",
"\n\n",
"// Start a listener if not already running",
"listener",
":=",
"kafkaListeners",
"[",
"r",
".",
"listener",
".",
"proxyPort",
"]",
"\n",
"if",
"listener",
"==",
"nil",
"{",
"marker",
":=",
"0",
"\n",
"if",
"!",
"conf",
".",
"testMode",
"{",
"marker",
"=",
"linux_defaults",
".",
"GetMagicProxyMark",
"(",
"r",
".",
"listener",
".",
"ingress",
",",
"0",
")",
"\n",
"}",
"\n\n",
"// Listen needs to be in the synchronous part of this function to ensure that",
"// the proxy port is never refusing connections.",
"socket",
",",
"err",
":=",
"listenSocket",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"r",
".",
"listener",
".",
"proxyPort",
")",
",",
"marker",
",",
"!",
"conf",
".",
"testMode",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"delete",
"(",
"kafkaRedirects",
",",
"key",
")",
"\n",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"listener",
"=",
"&",
"kafkaListener",
"{",
"socket",
":",
"socket",
",",
"proxyPort",
":",
"r",
".",
"listener",
".",
"proxyPort",
",",
"endpointInfoRegistry",
":",
"endpointInfoRegistry",
",",
"ingress",
":",
"r",
".",
"listener",
".",
"ingress",
",",
"transparent",
":",
"!",
"conf",
".",
"testMode",
",",
"count",
":",
"0",
",",
"}",
"\n\n",
"go",
"listener",
".",
"Listen",
"(",
")",
"\n\n",
"kafkaListeners",
"[",
"r",
".",
"listener",
".",
"proxyPort",
"]",
"=",
"listener",
"\n",
"}",
"\n",
"listener",
".",
"count",
"++",
"\n",
"redir",
".",
"listener",
"=",
"listener",
"\n",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"redir",
",",
"nil",
"\n",
"}"
] | // createKafkaRedirect creates a redirect to the kafka proxy. The redirect structure passed
// in is safe to access for reading and writing. | [
"createKafkaRedirect",
"creates",
"a",
"redirect",
"to",
"the",
"kafka",
"proxy",
".",
"The",
"redirect",
"structure",
"passed",
"in",
"is",
"safe",
"to",
"access",
"for",
"reading",
"and",
"writing",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/proxy/kafka.go#L141-L202 |
162,903 | cilium/cilium | pkg/proxy/kafka.go | canAccess | func (k *kafkaRedirect) canAccess(req *kafka.RequestMessage, srcIdentity identity.NumericIdentity) bool {
var id *identity.Identity
if srcIdentity != 0 {
id = cache.LookupIdentityByID(srcIdentity)
if id == nil {
log.WithFields(logrus.Fields{
logfields.Request: req.String(),
logfields.Identity: srcIdentity,
}).Warn("Unable to resolve identity to labels")
}
}
scopedLog := log.WithFields(logrus.Fields{
logfields.Request: req.String(),
logfields.Identity: id,
})
k.redirect.mutex.RLock()
rules := k.redirect.rules.GetRelevantRules(id)
k.redirect.mutex.RUnlock()
if rules.Kafka == nil {
flowdebug.Log(scopedLog, "No Kafka rules matching identity, rejecting")
return false
}
b, err := json.Marshal(rules.Kafka)
if err != nil {
flowdebug.Log(scopedLog, "Error marshalling kafka rules to apply")
return false
} else {
flowdebug.Log(scopedLog.WithField("rule", string(b)), "Applying rule")
}
return req.MatchesRule(rules.Kafka)
} | go | func (k *kafkaRedirect) canAccess(req *kafka.RequestMessage, srcIdentity identity.NumericIdentity) bool {
var id *identity.Identity
if srcIdentity != 0 {
id = cache.LookupIdentityByID(srcIdentity)
if id == nil {
log.WithFields(logrus.Fields{
logfields.Request: req.String(),
logfields.Identity: srcIdentity,
}).Warn("Unable to resolve identity to labels")
}
}
scopedLog := log.WithFields(logrus.Fields{
logfields.Request: req.String(),
logfields.Identity: id,
})
k.redirect.mutex.RLock()
rules := k.redirect.rules.GetRelevantRules(id)
k.redirect.mutex.RUnlock()
if rules.Kafka == nil {
flowdebug.Log(scopedLog, "No Kafka rules matching identity, rejecting")
return false
}
b, err := json.Marshal(rules.Kafka)
if err != nil {
flowdebug.Log(scopedLog, "Error marshalling kafka rules to apply")
return false
} else {
flowdebug.Log(scopedLog.WithField("rule", string(b)), "Applying rule")
}
return req.MatchesRule(rules.Kafka)
} | [
"func",
"(",
"k",
"*",
"kafkaRedirect",
")",
"canAccess",
"(",
"req",
"*",
"kafka",
".",
"RequestMessage",
",",
"srcIdentity",
"identity",
".",
"NumericIdentity",
")",
"bool",
"{",
"var",
"id",
"*",
"identity",
".",
"Identity",
"\n\n",
"if",
"srcIdentity",
"!=",
"0",
"{",
"id",
"=",
"cache",
".",
"LookupIdentityByID",
"(",
"srcIdentity",
")",
"\n",
"if",
"id",
"==",
"nil",
"{",
"log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"Request",
":",
"req",
".",
"String",
"(",
")",
",",
"logfields",
".",
"Identity",
":",
"srcIdentity",
",",
"}",
")",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"scopedLog",
":=",
"log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"Request",
":",
"req",
".",
"String",
"(",
")",
",",
"logfields",
".",
"Identity",
":",
"id",
",",
"}",
")",
"\n\n",
"k",
".",
"redirect",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"rules",
":=",
"k",
".",
"redirect",
".",
"rules",
".",
"GetRelevantRules",
"(",
"id",
")",
"\n",
"k",
".",
"redirect",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"rules",
".",
"Kafka",
"==",
"nil",
"{",
"flowdebug",
".",
"Log",
"(",
"scopedLog",
",",
"\"",
"\"",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"rules",
".",
"Kafka",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"flowdebug",
".",
"Log",
"(",
"scopedLog",
",",
"\"",
"\"",
")",
"\n",
"return",
"false",
"\n",
"}",
"else",
"{",
"flowdebug",
".",
"Log",
"(",
"scopedLog",
".",
"WithField",
"(",
"\"",
"\"",
",",
"string",
"(",
"b",
")",
")",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"req",
".",
"MatchesRule",
"(",
"rules",
".",
"Kafka",
")",
"\n",
"}"
] | // canAccess determines if the kafka message req sent by identity is allowed to
// be forwarded according to the rules configured on kafkaRedirect | [
"canAccess",
"determines",
"if",
"the",
"kafka",
"message",
"req",
"sent",
"by",
"identity",
"is",
"allowed",
"to",
"be",
"forwarded",
"according",
"to",
"the",
"rules",
"configured",
"on",
"kafkaRedirect"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/proxy/kafka.go#L206-L242 |
162,904 | cilium/cilium | pkg/proxy/kafka.go | log | func (l *kafkaLogRecord) log(verdict accesslog.FlowVerdict, code int, info string) {
l.ApplyTags(logger.LogTags.Verdict(verdict, info))
l.Kafka.ErrorCode = code
// Log multiple entries for multiple Kafka topics in a single request.
for _, t := range l.topics {
l.Kafka.Topic.Topic = t
l.Log()
}
// Update stats for the endpoint.
// Count only one request.
ingress := l.ObservationPoint == accesslog.Ingress
var port uint16
if ingress {
port = l.DestinationEndpoint.Port
} else {
port = l.SourceEndpoint.Port
}
if port == 0 {
// Something went wrong when identifying the endpoints.
// Ignore in order to avoid polluting the stats.
return
}
request := l.Type == accesslog.TypeRequest
l.localEndpoint.UpdateProxyStatistics("kafka", port, ingress, request, l.Verdict)
} | go | func (l *kafkaLogRecord) log(verdict accesslog.FlowVerdict, code int, info string) {
l.ApplyTags(logger.LogTags.Verdict(verdict, info))
l.Kafka.ErrorCode = code
// Log multiple entries for multiple Kafka topics in a single request.
for _, t := range l.topics {
l.Kafka.Topic.Topic = t
l.Log()
}
// Update stats for the endpoint.
// Count only one request.
ingress := l.ObservationPoint == accesslog.Ingress
var port uint16
if ingress {
port = l.DestinationEndpoint.Port
} else {
port = l.SourceEndpoint.Port
}
if port == 0 {
// Something went wrong when identifying the endpoints.
// Ignore in order to avoid polluting the stats.
return
}
request := l.Type == accesslog.TypeRequest
l.localEndpoint.UpdateProxyStatistics("kafka", port, ingress, request, l.Verdict)
} | [
"func",
"(",
"l",
"*",
"kafkaLogRecord",
")",
"log",
"(",
"verdict",
"accesslog",
".",
"FlowVerdict",
",",
"code",
"int",
",",
"info",
"string",
")",
"{",
"l",
".",
"ApplyTags",
"(",
"logger",
".",
"LogTags",
".",
"Verdict",
"(",
"verdict",
",",
"info",
")",
")",
"\n",
"l",
".",
"Kafka",
".",
"ErrorCode",
"=",
"code",
"\n\n",
"// Log multiple entries for multiple Kafka topics in a single request.",
"for",
"_",
",",
"t",
":=",
"range",
"l",
".",
"topics",
"{",
"l",
".",
"Kafka",
".",
"Topic",
".",
"Topic",
"=",
"t",
"\n",
"l",
".",
"Log",
"(",
")",
"\n",
"}",
"\n\n",
"// Update stats for the endpoint.",
"// Count only one request.",
"ingress",
":=",
"l",
".",
"ObservationPoint",
"==",
"accesslog",
".",
"Ingress",
"\n",
"var",
"port",
"uint16",
"\n",
"if",
"ingress",
"{",
"port",
"=",
"l",
".",
"DestinationEndpoint",
".",
"Port",
"\n",
"}",
"else",
"{",
"port",
"=",
"l",
".",
"SourceEndpoint",
".",
"Port",
"\n",
"}",
"\n",
"if",
"port",
"==",
"0",
"{",
"// Something went wrong when identifying the endpoints.",
"// Ignore in order to avoid polluting the stats.",
"return",
"\n",
"}",
"\n",
"request",
":=",
"l",
".",
"Type",
"==",
"accesslog",
".",
"TypeRequest",
"\n",
"l",
".",
"localEndpoint",
".",
"UpdateProxyStatistics",
"(",
"\"",
"\"",
",",
"port",
",",
"ingress",
",",
"request",
",",
"l",
".",
"Verdict",
")",
"\n\n",
"}"
] | // log Kafka log records | [
"log",
"Kafka",
"log",
"records"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/proxy/kafka.go#L293-L320 |
162,905 | cilium/cilium | pkg/proxy/dns.go | UpdateRules | func (dr *dnsRedirect) UpdateRules(wg *completion.WaitGroup, l4 *policy.L4Filter) (revert.RevertFunc, error) {
oldRules := dr.currentRules
err := dr.setRules(wg, dr.redirect.rules)
revertFunc := func() error {
return dr.setRules(nil, oldRules)
}
return revertFunc, err
} | go | func (dr *dnsRedirect) UpdateRules(wg *completion.WaitGroup, l4 *policy.L4Filter) (revert.RevertFunc, error) {
oldRules := dr.currentRules
err := dr.setRules(wg, dr.redirect.rules)
revertFunc := func() error {
return dr.setRules(nil, oldRules)
}
return revertFunc, err
} | [
"func",
"(",
"dr",
"*",
"dnsRedirect",
")",
"UpdateRules",
"(",
"wg",
"*",
"completion",
".",
"WaitGroup",
",",
"l4",
"*",
"policy",
".",
"L4Filter",
")",
"(",
"revert",
".",
"RevertFunc",
",",
"error",
")",
"{",
"oldRules",
":=",
"dr",
".",
"currentRules",
"\n",
"err",
":=",
"dr",
".",
"setRules",
"(",
"wg",
",",
"dr",
".",
"redirect",
".",
"rules",
")",
"\n",
"revertFunc",
":=",
"func",
"(",
")",
"error",
"{",
"return",
"dr",
".",
"setRules",
"(",
"nil",
",",
"oldRules",
")",
"\n",
"}",
"\n",
"return",
"revertFunc",
",",
"err",
"\n",
"}"
] | // UpdateRules atomically replaces the proxy rules in effect for this redirect.
// It is not aware of revision number and doesn't account for out-of-order
// calls to UpdateRules or the returned RevertFunc. | [
"UpdateRules",
"atomically",
"replaces",
"the",
"proxy",
"rules",
"in",
"effect",
"for",
"this",
"redirect",
".",
"It",
"is",
"not",
"aware",
"of",
"revision",
"number",
"and",
"doesn",
"t",
"account",
"for",
"out",
"-",
"of",
"-",
"order",
"calls",
"to",
"UpdateRules",
"or",
"the",
"returned",
"RevertFunc",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/proxy/dns.go#L97-L104 |
162,906 | cilium/cilium | pkg/proxy/dns.go | createDNSRedirect | func createDNSRedirect(r *Redirect, conf dnsConfiguration, endpointInfoRegistry logger.EndpointInfoRegistry) (RedirectImplementation, error) {
dr := &dnsRedirect{
redirect: r,
conf: conf,
endpointInfoRegistry: endpointInfoRegistry,
}
log.WithFields(logrus.Fields{
"dnsRedirect": dr,
"conf": conf,
}).Debug("Creating DNS Proxy redirect")
return dr, dr.setRules(nil, r.rules)
} | go | func createDNSRedirect(r *Redirect, conf dnsConfiguration, endpointInfoRegistry logger.EndpointInfoRegistry) (RedirectImplementation, error) {
dr := &dnsRedirect{
redirect: r,
conf: conf,
endpointInfoRegistry: endpointInfoRegistry,
}
log.WithFields(logrus.Fields{
"dnsRedirect": dr,
"conf": conf,
}).Debug("Creating DNS Proxy redirect")
return dr, dr.setRules(nil, r.rules)
} | [
"func",
"createDNSRedirect",
"(",
"r",
"*",
"Redirect",
",",
"conf",
"dnsConfiguration",
",",
"endpointInfoRegistry",
"logger",
".",
"EndpointInfoRegistry",
")",
"(",
"RedirectImplementation",
",",
"error",
")",
"{",
"dr",
":=",
"&",
"dnsRedirect",
"{",
"redirect",
":",
"r",
",",
"conf",
":",
"conf",
",",
"endpointInfoRegistry",
":",
"endpointInfoRegistry",
",",
"}",
"\n\n",
"log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"dr",
",",
"\"",
"\"",
":",
"conf",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"return",
"dr",
",",
"dr",
".",
"setRules",
"(",
"nil",
",",
"r",
".",
"rules",
")",
"\n",
"}"
] | // creatednsRedirect creates a redirect to the dns proxy. The redirect structure passed
// in is safe to access for reading and writing. | [
"creatednsRedirect",
"creates",
"a",
"redirect",
"to",
"the",
"dns",
"proxy",
".",
"The",
"redirect",
"structure",
"passed",
"in",
"is",
"safe",
"to",
"access",
"for",
"reading",
"and",
"writing",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/proxy/dns.go#L125-L138 |
162,907 | cilium/cilium | pkg/version/version.go | FromString | func FromString(versionString string) CiliumVersion {
// string to parse: "0.13.90 a722bdb 2018-01-09T22:32:37+01:00 go version go1.9 linux/amd64"
fields := strings.Split(versionString, " ")
if len(fields) != 7 {
return CiliumVersion{}
}
cver := CiliumVersion{
Version: fields[0],
Revision: fields[1],
AuthorDate: fields[2],
GoRuntimeVersion: fields[5],
Arch: fields[6],
}
return cver
} | go | func FromString(versionString string) CiliumVersion {
// string to parse: "0.13.90 a722bdb 2018-01-09T22:32:37+01:00 go version go1.9 linux/amd64"
fields := strings.Split(versionString, " ")
if len(fields) != 7 {
return CiliumVersion{}
}
cver := CiliumVersion{
Version: fields[0],
Revision: fields[1],
AuthorDate: fields[2],
GoRuntimeVersion: fields[5],
Arch: fields[6],
}
return cver
} | [
"func",
"FromString",
"(",
"versionString",
"string",
")",
"CiliumVersion",
"{",
"// string to parse: \"0.13.90 a722bdb 2018-01-09T22:32:37+01:00 go version go1.9 linux/amd64\"",
"fields",
":=",
"strings",
".",
"Split",
"(",
"versionString",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"fields",
")",
"!=",
"7",
"{",
"return",
"CiliumVersion",
"{",
"}",
"\n",
"}",
"\n\n",
"cver",
":=",
"CiliumVersion",
"{",
"Version",
":",
"fields",
"[",
"0",
"]",
",",
"Revision",
":",
"fields",
"[",
"1",
"]",
",",
"AuthorDate",
":",
"fields",
"[",
"2",
"]",
",",
"GoRuntimeVersion",
":",
"fields",
"[",
"5",
"]",
",",
"Arch",
":",
"fields",
"[",
"6",
"]",
",",
"}",
"\n",
"return",
"cver",
"\n",
"}"
] | // FromString converts a version string into struct | [
"FromString",
"converts",
"a",
"version",
"string",
"into",
"struct"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/version/version.go#L41-L56 |
162,908 | cilium/cilium | pkg/version/version.go | Base64 | func Base64() (string, error) {
jsonBytes, err := json.Marshal(Version)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(jsonBytes), nil
} | go | func Base64() (string, error) {
jsonBytes, err := json.Marshal(Version)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(jsonBytes), nil
} | [
"func",
"Base64",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"jsonBytes",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"Version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"jsonBytes",
")",
",",
"nil",
"\n",
"}"
] | // Base64 returns the version in a base64 format. | [
"Base64",
"returns",
"the",
"version",
"in",
"a",
"base64",
"format",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/version/version.go#L64-L70 |
162,909 | cilium/cilium | pkg/k8s/client/clientset/versioned/typed/cilium.io/v2/fake/fake_ciliumnetworkpolicy.go | Get | func (c *FakeCiliumNetworkPolicies) Get(name string, options v1.GetOptions) (result *v2.CiliumNetworkPolicy, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(ciliumnetworkpoliciesResource, c.ns, name), &v2.CiliumNetworkPolicy{})
if obj == nil {
return nil, err
}
return obj.(*v2.CiliumNetworkPolicy), err
} | go | func (c *FakeCiliumNetworkPolicies) Get(name string, options v1.GetOptions) (result *v2.CiliumNetworkPolicy, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(ciliumnetworkpoliciesResource, c.ns, name), &v2.CiliumNetworkPolicy{})
if obj == nil {
return nil, err
}
return obj.(*v2.CiliumNetworkPolicy), err
} | [
"func",
"(",
"c",
"*",
"FakeCiliumNetworkPolicies",
")",
"Get",
"(",
"name",
"string",
",",
"options",
"v1",
".",
"GetOptions",
")",
"(",
"result",
"*",
"v2",
".",
"CiliumNetworkPolicy",
",",
"err",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewGetAction",
"(",
"ciliumnetworkpoliciesResource",
",",
"c",
".",
"ns",
",",
"name",
")",
",",
"&",
"v2",
".",
"CiliumNetworkPolicy",
"{",
"}",
")",
"\n\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"obj",
".",
"(",
"*",
"v2",
".",
"CiliumNetworkPolicy",
")",
",",
"err",
"\n",
"}"
] | // Get takes name of the ciliumNetworkPolicy, and returns the corresponding ciliumNetworkPolicy object, and an error if there is any. | [
"Get",
"takes",
"name",
"of",
"the",
"ciliumNetworkPolicy",
"and",
"returns",
"the",
"corresponding",
"ciliumNetworkPolicy",
"object",
"and",
"an",
"error",
"if",
"there",
"is",
"any",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2/fake/fake_ciliumnetworkpolicy.go#L40-L48 |
162,910 | cilium/cilium | pkg/k8s/client/clientset/versioned/typed/cilium.io/v2/fake/fake_ciliumnetworkpolicy.go | List | func (c *FakeCiliumNetworkPolicies) List(opts v1.ListOptions) (result *v2.CiliumNetworkPolicyList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(ciliumnetworkpoliciesResource, ciliumnetworkpoliciesKind, c.ns, opts), &v2.CiliumNetworkPolicyList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v2.CiliumNetworkPolicyList{ListMeta: obj.(*v2.CiliumNetworkPolicyList).ListMeta}
for _, item := range obj.(*v2.CiliumNetworkPolicyList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
} | go | func (c *FakeCiliumNetworkPolicies) List(opts v1.ListOptions) (result *v2.CiliumNetworkPolicyList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(ciliumnetworkpoliciesResource, ciliumnetworkpoliciesKind, c.ns, opts), &v2.CiliumNetworkPolicyList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v2.CiliumNetworkPolicyList{ListMeta: obj.(*v2.CiliumNetworkPolicyList).ListMeta}
for _, item := range obj.(*v2.CiliumNetworkPolicyList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
} | [
"func",
"(",
"c",
"*",
"FakeCiliumNetworkPolicies",
")",
"List",
"(",
"opts",
"v1",
".",
"ListOptions",
")",
"(",
"result",
"*",
"v2",
".",
"CiliumNetworkPolicyList",
",",
"err",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewListAction",
"(",
"ciliumnetworkpoliciesResource",
",",
"ciliumnetworkpoliciesKind",
",",
"c",
".",
"ns",
",",
"opts",
")",
",",
"&",
"v2",
".",
"CiliumNetworkPolicyList",
"{",
"}",
")",
"\n\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"label",
",",
"_",
",",
"_",
":=",
"testing",
".",
"ExtractFromListOptions",
"(",
"opts",
")",
"\n",
"if",
"label",
"==",
"nil",
"{",
"label",
"=",
"labels",
".",
"Everything",
"(",
")",
"\n",
"}",
"\n",
"list",
":=",
"&",
"v2",
".",
"CiliumNetworkPolicyList",
"{",
"ListMeta",
":",
"obj",
".",
"(",
"*",
"v2",
".",
"CiliumNetworkPolicyList",
")",
".",
"ListMeta",
"}",
"\n",
"for",
"_",
",",
"item",
":=",
"range",
"obj",
".",
"(",
"*",
"v2",
".",
"CiliumNetworkPolicyList",
")",
".",
"Items",
"{",
"if",
"label",
".",
"Matches",
"(",
"labels",
".",
"Set",
"(",
"item",
".",
"Labels",
")",
")",
"{",
"list",
".",
"Items",
"=",
"append",
"(",
"list",
".",
"Items",
",",
"item",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"list",
",",
"err",
"\n",
"}"
] | // List takes label and field selectors, and returns the list of CiliumNetworkPolicies that match those selectors. | [
"List",
"takes",
"label",
"and",
"field",
"selectors",
"and",
"returns",
"the",
"list",
"of",
"CiliumNetworkPolicies",
"that",
"match",
"those",
"selectors",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2/fake/fake_ciliumnetworkpolicy.go#L51-L70 |
162,911 | cilium/cilium | pkg/k8s/client/clientset/versioned/typed/cilium.io/v2/fake/fake_ciliumnetworkpolicy.go | Watch | func (c *FakeCiliumNetworkPolicies) Watch(opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(ciliumnetworkpoliciesResource, c.ns, opts))
} | go | func (c *FakeCiliumNetworkPolicies) Watch(opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(ciliumnetworkpoliciesResource, c.ns, opts))
} | [
"func",
"(",
"c",
"*",
"FakeCiliumNetworkPolicies",
")",
"Watch",
"(",
"opts",
"v1",
".",
"ListOptions",
")",
"(",
"watch",
".",
"Interface",
",",
"error",
")",
"{",
"return",
"c",
".",
"Fake",
".",
"InvokesWatch",
"(",
"testing",
".",
"NewWatchAction",
"(",
"ciliumnetworkpoliciesResource",
",",
"c",
".",
"ns",
",",
"opts",
")",
")",
"\n\n",
"}"
] | // Watch returns a watch.Interface that watches the requested ciliumNetworkPolicies. | [
"Watch",
"returns",
"a",
"watch",
".",
"Interface",
"that",
"watches",
"the",
"requested",
"ciliumNetworkPolicies",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2/fake/fake_ciliumnetworkpolicy.go#L73-L77 |
162,912 | cilium/cilium | pkg/k8s/client/clientset/versioned/typed/cilium.io/v2/fake/fake_ciliumnetworkpolicy.go | Delete | func (c *FakeCiliumNetworkPolicies) Delete(name string, options *v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteAction(ciliumnetworkpoliciesResource, c.ns, name), &v2.CiliumNetworkPolicy{})
return err
} | go | func (c *FakeCiliumNetworkPolicies) Delete(name string, options *v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteAction(ciliumnetworkpoliciesResource, c.ns, name), &v2.CiliumNetworkPolicy{})
return err
} | [
"func",
"(",
"c",
"*",
"FakeCiliumNetworkPolicies",
")",
"Delete",
"(",
"name",
"string",
",",
"options",
"*",
"v1",
".",
"DeleteOptions",
")",
"error",
"{",
"_",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewDeleteAction",
"(",
"ciliumnetworkpoliciesResource",
",",
"c",
".",
"ns",
",",
"name",
")",
",",
"&",
"v2",
".",
"CiliumNetworkPolicy",
"{",
"}",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Delete takes name of the ciliumNetworkPolicy and deletes it. Returns an error if one occurs. | [
"Delete",
"takes",
"name",
"of",
"the",
"ciliumNetworkPolicy",
"and",
"deletes",
"it",
".",
"Returns",
"an",
"error",
"if",
"one",
"occurs",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2/fake/fake_ciliumnetworkpolicy.go#L114-L119 |
162,913 | cilium/cilium | pkg/k8s/client/clientset/versioned/typed/cilium.io/v2/fake/fake_ciliumnetworkpolicy.go | Patch | func (c *FakeCiliumNetworkPolicies) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v2.CiliumNetworkPolicy, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(ciliumnetworkpoliciesResource, c.ns, name, pt, data, subresources...), &v2.CiliumNetworkPolicy{})
if obj == nil {
return nil, err
}
return obj.(*v2.CiliumNetworkPolicy), err
} | go | func (c *FakeCiliumNetworkPolicies) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v2.CiliumNetworkPolicy, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(ciliumnetworkpoliciesResource, c.ns, name, pt, data, subresources...), &v2.CiliumNetworkPolicy{})
if obj == nil {
return nil, err
}
return obj.(*v2.CiliumNetworkPolicy), err
} | [
"func",
"(",
"c",
"*",
"FakeCiliumNetworkPolicies",
")",
"Patch",
"(",
"name",
"string",
",",
"pt",
"types",
".",
"PatchType",
",",
"data",
"[",
"]",
"byte",
",",
"subresources",
"...",
"string",
")",
"(",
"result",
"*",
"v2",
".",
"CiliumNetworkPolicy",
",",
"err",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewPatchSubresourceAction",
"(",
"ciliumnetworkpoliciesResource",
",",
"c",
".",
"ns",
",",
"name",
",",
"pt",
",",
"data",
",",
"subresources",
"...",
")",
",",
"&",
"v2",
".",
"CiliumNetworkPolicy",
"{",
"}",
")",
"\n\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"obj",
".",
"(",
"*",
"v2",
".",
"CiliumNetworkPolicy",
")",
",",
"err",
"\n",
"}"
] | // Patch applies the patch and returns the patched ciliumNetworkPolicy. | [
"Patch",
"applies",
"the",
"patch",
"and",
"returns",
"the",
"patched",
"ciliumNetworkPolicy",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2/fake/fake_ciliumnetworkpolicy.go#L130-L138 |
162,914 | cilium/cilium | api/v1/server/restapi/endpoint/patch_endpoint_id_config_responses.go | WithPayload | func (o *PatchEndpointIDConfigFailed) WithPayload(payload models.Error) *PatchEndpointIDConfigFailed {
o.Payload = payload
return o
} | go | func (o *PatchEndpointIDConfigFailed) WithPayload(payload models.Error) *PatchEndpointIDConfigFailed {
o.Payload = payload
return o
} | [
"func",
"(",
"o",
"*",
"PatchEndpointIDConfigFailed",
")",
"WithPayload",
"(",
"payload",
"models",
".",
"Error",
")",
"*",
"PatchEndpointIDConfigFailed",
"{",
"o",
".",
"Payload",
"=",
"payload",
"\n",
"return",
"o",
"\n",
"}"
] | // WithPayload adds the payload to the patch endpoint Id config failed response | [
"WithPayload",
"adds",
"the",
"payload",
"to",
"the",
"patch",
"endpoint",
"Id",
"config",
"failed",
"response"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/endpoint/patch_endpoint_id_config_responses.go#L110-L113 |
162,915 | cilium/cilium | proxylib/memcached/parser.go | Matches | func (rule *Rule) Matches(data interface{}) bool {
log.Debugf("memcache checking rule %v", *rule)
packetMeta, ok := data.(meta.MemcacheMeta)
if !ok {
log.Debugf("Wrong type supplied to Rule.Matches")
return false
}
if rule.empty {
return true
}
if packetMeta.IsBinary() {
if !rule.matchOpcode(packetMeta.Opcode) {
return false
}
} else {
if !rule.matchCommand(packetMeta.Command) {
return false
}
}
if len(rule.keyExact) > 0 {
for _, key := range packetMeta.Keys {
if !bytes.Equal(rule.keyExact, key) {
return false
}
}
return true
}
if len(rule.keyPrefix) > 0 {
for _, key := range packetMeta.Keys {
if !bytes.HasPrefix(key, rule.keyPrefix) {
return false
}
}
return true
}
if rule.regex != nil {
for _, key := range packetMeta.Keys {
if !rule.regex.Match(key) {
return false
}
}
return true
}
log.Debugf("No key rule specified, accepted by command match")
return true
} | go | func (rule *Rule) Matches(data interface{}) bool {
log.Debugf("memcache checking rule %v", *rule)
packetMeta, ok := data.(meta.MemcacheMeta)
if !ok {
log.Debugf("Wrong type supplied to Rule.Matches")
return false
}
if rule.empty {
return true
}
if packetMeta.IsBinary() {
if !rule.matchOpcode(packetMeta.Opcode) {
return false
}
} else {
if !rule.matchCommand(packetMeta.Command) {
return false
}
}
if len(rule.keyExact) > 0 {
for _, key := range packetMeta.Keys {
if !bytes.Equal(rule.keyExact, key) {
return false
}
}
return true
}
if len(rule.keyPrefix) > 0 {
for _, key := range packetMeta.Keys {
if !bytes.HasPrefix(key, rule.keyPrefix) {
return false
}
}
return true
}
if rule.regex != nil {
for _, key := range packetMeta.Keys {
if !rule.regex.Match(key) {
return false
}
}
return true
}
log.Debugf("No key rule specified, accepted by command match")
return true
} | [
"func",
"(",
"rule",
"*",
"Rule",
")",
"Matches",
"(",
"data",
"interface",
"{",
"}",
")",
"bool",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"*",
"rule",
")",
"\n\n",
"packetMeta",
",",
"ok",
":=",
"data",
".",
"(",
"meta",
".",
"MemcacheMeta",
")",
"\n\n",
"if",
"!",
"ok",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"rule",
".",
"empty",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"packetMeta",
".",
"IsBinary",
"(",
")",
"{",
"if",
"!",
"rule",
".",
"matchOpcode",
"(",
"packetMeta",
".",
"Opcode",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"!",
"rule",
".",
"matchCommand",
"(",
"packetMeta",
".",
"Command",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"rule",
".",
"keyExact",
")",
">",
"0",
"{",
"for",
"_",
",",
"key",
":=",
"range",
"packetMeta",
".",
"Keys",
"{",
"if",
"!",
"bytes",
".",
"Equal",
"(",
"rule",
".",
"keyExact",
",",
"key",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"rule",
".",
"keyPrefix",
")",
">",
"0",
"{",
"for",
"_",
",",
"key",
":=",
"range",
"packetMeta",
".",
"Keys",
"{",
"if",
"!",
"bytes",
".",
"HasPrefix",
"(",
"key",
",",
"rule",
".",
"keyPrefix",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"rule",
".",
"regex",
"!=",
"nil",
"{",
"for",
"_",
",",
"key",
":=",
"range",
"packetMeta",
".",
"Keys",
"{",
"if",
"!",
"rule",
".",
"regex",
".",
"Match",
"(",
"key",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
"\n\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"true",
"\n",
"}"
] | // Matches returns true if the Rule matches | [
"Matches",
"returns",
"true",
"if",
"the",
"Rule",
"matches"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/proxylib/memcached/parser.go#L47-L100 |
162,916 | cilium/cilium | proxylib/memcached/parser.go | L7RuleParser | func L7RuleParser(rule *cilium.PortNetworkPolicyRule) []proxylib.L7NetworkPolicyRule {
var rules []proxylib.L7NetworkPolicyRule
l7Rules := rule.GetL7Rules()
if l7Rules == nil {
return rules
}
for _, l7Rule := range l7Rules.GetL7Rules() {
var br Rule
var commandFound = false
for k, v := range l7Rule.Rule {
switch k {
case "command":
br.commands, commandFound = MemcacheOpCodeMap[v]
case "keyExact":
br.keyExact = []byte(v)
case "keyPrefix":
br.keyPrefix = []byte(v)
case "keyRegex":
br.regex = regexp.MustCompile(v)
default:
proxylib.ParseError(fmt.Sprintf("Unsupported key: %s", k), rule)
}
}
if !commandFound {
if len(br.keyExact) > 0 || len(br.keyPrefix) > 0 || br.regex != nil {
proxylib.ParseError("command not specified but key was provided", rule)
} else {
br.empty = true
}
}
log.Debugf("Parsed Rule pair: %v", br)
rules = append(rules, &br)
}
return rules
} | go | func L7RuleParser(rule *cilium.PortNetworkPolicyRule) []proxylib.L7NetworkPolicyRule {
var rules []proxylib.L7NetworkPolicyRule
l7Rules := rule.GetL7Rules()
if l7Rules == nil {
return rules
}
for _, l7Rule := range l7Rules.GetL7Rules() {
var br Rule
var commandFound = false
for k, v := range l7Rule.Rule {
switch k {
case "command":
br.commands, commandFound = MemcacheOpCodeMap[v]
case "keyExact":
br.keyExact = []byte(v)
case "keyPrefix":
br.keyPrefix = []byte(v)
case "keyRegex":
br.regex = regexp.MustCompile(v)
default:
proxylib.ParseError(fmt.Sprintf("Unsupported key: %s", k), rule)
}
}
if !commandFound {
if len(br.keyExact) > 0 || len(br.keyPrefix) > 0 || br.regex != nil {
proxylib.ParseError("command not specified but key was provided", rule)
} else {
br.empty = true
}
}
log.Debugf("Parsed Rule pair: %v", br)
rules = append(rules, &br)
}
return rules
} | [
"func",
"L7RuleParser",
"(",
"rule",
"*",
"cilium",
".",
"PortNetworkPolicyRule",
")",
"[",
"]",
"proxylib",
".",
"L7NetworkPolicyRule",
"{",
"var",
"rules",
"[",
"]",
"proxylib",
".",
"L7NetworkPolicyRule",
"\n",
"l7Rules",
":=",
"rule",
".",
"GetL7Rules",
"(",
")",
"\n",
"if",
"l7Rules",
"==",
"nil",
"{",
"return",
"rules",
"\n",
"}",
"\n",
"for",
"_",
",",
"l7Rule",
":=",
"range",
"l7Rules",
".",
"GetL7Rules",
"(",
")",
"{",
"var",
"br",
"Rule",
"\n",
"var",
"commandFound",
"=",
"false",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"l7Rule",
".",
"Rule",
"{",
"switch",
"k",
"{",
"case",
"\"",
"\"",
":",
"br",
".",
"commands",
",",
"commandFound",
"=",
"MemcacheOpCodeMap",
"[",
"v",
"]",
"\n",
"case",
"\"",
"\"",
":",
"br",
".",
"keyExact",
"=",
"[",
"]",
"byte",
"(",
"v",
")",
"\n",
"case",
"\"",
"\"",
":",
"br",
".",
"keyPrefix",
"=",
"[",
"]",
"byte",
"(",
"v",
")",
"\n",
"case",
"\"",
"\"",
":",
"br",
".",
"regex",
"=",
"regexp",
".",
"MustCompile",
"(",
"v",
")",
"\n",
"default",
":",
"proxylib",
".",
"ParseError",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"k",
")",
",",
"rule",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"commandFound",
"{",
"if",
"len",
"(",
"br",
".",
"keyExact",
")",
">",
"0",
"||",
"len",
"(",
"br",
".",
"keyPrefix",
")",
">",
"0",
"||",
"br",
".",
"regex",
"!=",
"nil",
"{",
"proxylib",
".",
"ParseError",
"(",
"\"",
"\"",
",",
"rule",
")",
"\n",
"}",
"else",
"{",
"br",
".",
"empty",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"br",
")",
"\n",
"rules",
"=",
"append",
"(",
"rules",
",",
"&",
"br",
")",
"\n",
"}",
"\n",
"return",
"rules",
"\n",
"}"
] | // L7RuleParser parses protobuf L7 rules to and array of Rule
// May panic | [
"L7RuleParser",
"parses",
"protobuf",
"L7",
"rules",
"to",
"and",
"array",
"of",
"Rule",
"May",
"panic"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/proxylib/memcached/parser.go#L114-L148 |
162,917 | cilium/cilium | proxylib/memcached/parser.go | OnData | func (p *Parser) OnData(reply, endStream bool, dataBuffers [][]byte) (proxylib.OpType, int) {
if p.parser == nil {
var magicByte byte
if len(dataBuffers) > 0 && len(dataBuffers[0]) > 0 {
magicByte = dataBuffers[0][0]
} else {
return proxylib.NOP, 0
}
if magicByte >= 128 {
p.parser = binary.ParserFactoryInstance.Create(p.connection)
} else {
p.parser = text.ParserFactoryInstance.Create(p.connection)
}
}
return p.parser.OnData(reply, endStream, dataBuffers)
} | go | func (p *Parser) OnData(reply, endStream bool, dataBuffers [][]byte) (proxylib.OpType, int) {
if p.parser == nil {
var magicByte byte
if len(dataBuffers) > 0 && len(dataBuffers[0]) > 0 {
magicByte = dataBuffers[0][0]
} else {
return proxylib.NOP, 0
}
if magicByte >= 128 {
p.parser = binary.ParserFactoryInstance.Create(p.connection)
} else {
p.parser = text.ParserFactoryInstance.Create(p.connection)
}
}
return p.parser.OnData(reply, endStream, dataBuffers)
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"OnData",
"(",
"reply",
",",
"endStream",
"bool",
",",
"dataBuffers",
"[",
"]",
"[",
"]",
"byte",
")",
"(",
"proxylib",
".",
"OpType",
",",
"int",
")",
"{",
"if",
"p",
".",
"parser",
"==",
"nil",
"{",
"var",
"magicByte",
"byte",
"\n",
"if",
"len",
"(",
"dataBuffers",
")",
">",
"0",
"&&",
"len",
"(",
"dataBuffers",
"[",
"0",
"]",
")",
">",
"0",
"{",
"magicByte",
"=",
"dataBuffers",
"[",
"0",
"]",
"[",
"0",
"]",
"\n",
"}",
"else",
"{",
"return",
"proxylib",
".",
"NOP",
",",
"0",
"\n",
"}",
"\n\n",
"if",
"magicByte",
">=",
"128",
"{",
"p",
".",
"parser",
"=",
"binary",
".",
"ParserFactoryInstance",
".",
"Create",
"(",
"p",
".",
"connection",
")",
"\n",
"}",
"else",
"{",
"p",
".",
"parser",
"=",
"text",
".",
"ParserFactoryInstance",
".",
"Create",
"(",
"p",
".",
"connection",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"p",
".",
"parser",
".",
"OnData",
"(",
"reply",
",",
"endStream",
",",
"dataBuffers",
")",
"\n",
"}"
] | // OnData parses memcached data | [
"OnData",
"parses",
"memcached",
"data"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/proxylib/memcached/parser.go#L186-L202 |
162,918 | cilium/cilium | pkg/workloads/runtimes.go | registerWorkload | func registerWorkload(name WorkloadRuntimeType, module workloadModule) {
if _, ok := registeredWorkloads[name]; ok {
log.Panicf("workload with name '%s' already registered", name)
}
registeredWorkloads[name] = module
} | go | func registerWorkload(name WorkloadRuntimeType, module workloadModule) {
if _, ok := registeredWorkloads[name]; ok {
log.Panicf("workload with name '%s' already registered", name)
}
registeredWorkloads[name] = module
} | [
"func",
"registerWorkload",
"(",
"name",
"WorkloadRuntimeType",
",",
"module",
"workloadModule",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"registeredWorkloads",
"[",
"name",
"]",
";",
"ok",
"{",
"log",
".",
"Panicf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"registeredWorkloads",
"[",
"name",
"]",
"=",
"module",
"\n",
"}"
] | // registerWorkload must be called by container runtimes to register themselves | [
"registerWorkload",
"must",
"be",
"called",
"by",
"container",
"runtimes",
"to",
"register",
"themselves"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/workloads/runtimes.go#L122-L128 |
162,919 | cilium/cilium | pkg/workloads/runtimes.go | getWorkload | func getWorkload(name WorkloadRuntimeType) workloadModule {
if workload, ok := registeredWorkloads[name]; ok {
return workload
}
return nil
} | go | func getWorkload(name WorkloadRuntimeType) workloadModule {
if workload, ok := registeredWorkloads[name]; ok {
return workload
}
return nil
} | [
"func",
"getWorkload",
"(",
"name",
"WorkloadRuntimeType",
")",
"workloadModule",
"{",
"if",
"workload",
",",
"ok",
":=",
"registeredWorkloads",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"workload",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // getWorkload finds a registered workload by name | [
"getWorkload",
"finds",
"a",
"registered",
"workload",
"by",
"name"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/workloads/runtimes.go#L131-L137 |
162,920 | cilium/cilium | pkg/workloads/runtimes.go | GetRuntimeDefaultOpt | func GetRuntimeDefaultOpt(crt WorkloadRuntimeType, opt string) string {
opts, ok := registeredWorkloads[crt]
if !ok {
return ""
}
return opts.getConfig()[opt]
} | go | func GetRuntimeDefaultOpt(crt WorkloadRuntimeType, opt string) string {
opts, ok := registeredWorkloads[crt]
if !ok {
return ""
}
return opts.getConfig()[opt]
} | [
"func",
"GetRuntimeDefaultOpt",
"(",
"crt",
"WorkloadRuntimeType",
",",
"opt",
"string",
")",
"string",
"{",
"opts",
",",
"ok",
":=",
"registeredWorkloads",
"[",
"crt",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"opts",
".",
"getConfig",
"(",
")",
"[",
"opt",
"]",
"\n",
"}"
] | // GetRuntimeDefaultOpt returns the default options for the given container
// runtime. | [
"GetRuntimeDefaultOpt",
"returns",
"the",
"default",
"options",
"for",
"the",
"given",
"container",
"runtime",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/workloads/runtimes.go#L141-L147 |
162,921 | cilium/cilium | pkg/workloads/runtimes.go | GetRuntimeOptions | func GetRuntimeOptions() string {
var crtStr []string
crs := make([]string, 0, len(registeredWorkloads))
for k := range registeredWorkloads {
crs = append(crs, string(k))
}
sort.Strings(crs)
for _, cr := range crs {
rb := registeredWorkloads[WorkloadRuntimeType(cr)]
cfg := rb.getConfig()
keys := make([]string, 0, len(cfg))
for k := range cfg {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
crtStr = append(crtStr, fmt.Sprintf("%s=%s", k, cfg[k]))
}
}
return strings.Join(crtStr, ",")
} | go | func GetRuntimeOptions() string {
var crtStr []string
crs := make([]string, 0, len(registeredWorkloads))
for k := range registeredWorkloads {
crs = append(crs, string(k))
}
sort.Strings(crs)
for _, cr := range crs {
rb := registeredWorkloads[WorkloadRuntimeType(cr)]
cfg := rb.getConfig()
keys := make([]string, 0, len(cfg))
for k := range cfg {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
crtStr = append(crtStr, fmt.Sprintf("%s=%s", k, cfg[k]))
}
}
return strings.Join(crtStr, ",")
} | [
"func",
"GetRuntimeOptions",
"(",
")",
"string",
"{",
"var",
"crtStr",
"[",
"]",
"string",
"\n\n",
"crs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"registeredWorkloads",
")",
")",
"\n",
"for",
"k",
":=",
"range",
"registeredWorkloads",
"{",
"crs",
"=",
"append",
"(",
"crs",
",",
"string",
"(",
"k",
")",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"crs",
")",
"\n\n",
"for",
"_",
",",
"cr",
":=",
"range",
"crs",
"{",
"rb",
":=",
"registeredWorkloads",
"[",
"WorkloadRuntimeType",
"(",
"cr",
")",
"]",
"\n",
"cfg",
":=",
"rb",
".",
"getConfig",
"(",
")",
"\n",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"cfg",
")",
")",
"\n",
"for",
"k",
":=",
"range",
"cfg",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"keys",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"keys",
"{",
"crtStr",
"=",
"append",
"(",
"crtStr",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"k",
",",
"cfg",
"[",
"k",
"]",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"crtStr",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // GetRuntimeOptions returns a string representation of the container runtimes
// stored and the list of options for each container runtime. | [
"GetRuntimeOptions",
"returns",
"a",
"string",
"representation",
"of",
"the",
"container",
"runtimes",
"stored",
"and",
"the",
"list",
"of",
"options",
"for",
"each",
"container",
"runtime",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/workloads/runtimes.go#L151-L173 |
162,922 | cilium/cilium | pkg/workloads/runtimes.go | GetDefaultEPOptsStringWithPrefix | func GetDefaultEPOptsStringWithPrefix(prefix string) string {
strs := make([]string, 0, len(registeredWorkloads))
crs := make([]string, 0, len(registeredWorkloads))
for k := range registeredWorkloads {
crs = append(crs, string(k))
}
sort.Strings(crs)
for _, cr := range crs {
v := registeredWorkloads[WorkloadRuntimeType(cr)].getConfig()
strs = append(strs, fmt.Sprintf("%s%s=%s", prefix, cr, v[EpOpt]))
}
return strings.Join(strs, ", ")
} | go | func GetDefaultEPOptsStringWithPrefix(prefix string) string {
strs := make([]string, 0, len(registeredWorkloads))
crs := make([]string, 0, len(registeredWorkloads))
for k := range registeredWorkloads {
crs = append(crs, string(k))
}
sort.Strings(crs)
for _, cr := range crs {
v := registeredWorkloads[WorkloadRuntimeType(cr)].getConfig()
strs = append(strs, fmt.Sprintf("%s%s=%s", prefix, cr, v[EpOpt]))
}
return strings.Join(strs, ", ")
} | [
"func",
"GetDefaultEPOptsStringWithPrefix",
"(",
"prefix",
"string",
")",
"string",
"{",
"strs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"registeredWorkloads",
")",
")",
"\n",
"crs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"registeredWorkloads",
")",
")",
"\n\n",
"for",
"k",
":=",
"range",
"registeredWorkloads",
"{",
"crs",
"=",
"append",
"(",
"crs",
",",
"string",
"(",
"k",
")",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"crs",
")",
"\n\n",
"for",
"_",
",",
"cr",
":=",
"range",
"crs",
"{",
"v",
":=",
"registeredWorkloads",
"[",
"WorkloadRuntimeType",
"(",
"cr",
")",
"]",
".",
"getConfig",
"(",
")",
"\n",
"strs",
"=",
"append",
"(",
"strs",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"prefix",
",",
"cr",
",",
"v",
"[",
"EpOpt",
"]",
")",
")",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"Join",
"(",
"strs",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // GetDefaultEPOptsStringWithPrefix returns the defaults options for each
// runtime with the given prefix. | [
"GetDefaultEPOptsStringWithPrefix",
"returns",
"the",
"defaults",
"options",
"for",
"each",
"runtime",
"with",
"the",
"given",
"prefix",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/workloads/runtimes.go#L177-L192 |
162,923 | cilium/cilium | pkg/policy/api/entity.go | Matches | func (e Entity) Matches(ctx labels.LabelArray) bool {
if selectors, ok := EntitySelectorMapping[e]; ok {
return selectors.Matches(ctx)
}
return false
} | go | func (e Entity) Matches(ctx labels.LabelArray) bool {
if selectors, ok := EntitySelectorMapping[e]; ok {
return selectors.Matches(ctx)
}
return false
} | [
"func",
"(",
"e",
"Entity",
")",
"Matches",
"(",
"ctx",
"labels",
".",
"LabelArray",
")",
"bool",
"{",
"if",
"selectors",
",",
"ok",
":=",
"EntitySelectorMapping",
"[",
"e",
"]",
";",
"ok",
"{",
"return",
"selectors",
".",
"Matches",
"(",
"ctx",
")",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // Matches returns true if the entity matches the labels | [
"Matches",
"returns",
"true",
"if",
"the",
"entity",
"matches",
"the",
"labels"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/entity.go#L85-L91 |
162,924 | cilium/cilium | pkg/policy/api/entity.go | Matches | func (s EntitySlice) Matches(ctx labels.LabelArray) bool {
for _, entity := range s {
if entity.Matches(ctx) {
return true
}
}
return false
} | go | func (s EntitySlice) Matches(ctx labels.LabelArray) bool {
for _, entity := range s {
if entity.Matches(ctx) {
return true
}
}
return false
} | [
"func",
"(",
"s",
"EntitySlice",
")",
"Matches",
"(",
"ctx",
"labels",
".",
"LabelArray",
")",
"bool",
"{",
"for",
"_",
",",
"entity",
":=",
"range",
"s",
"{",
"if",
"entity",
".",
"Matches",
"(",
"ctx",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] | // Matches returns true if any of the entities in the slice match the labels | [
"Matches",
"returns",
"true",
"if",
"any",
"of",
"the",
"entities",
"in",
"the",
"slice",
"match",
"the",
"labels"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/entity.go#L94-L102 |
162,925 | cilium/cilium | pkg/policy/api/entity.go | GetAsEndpointSelectors | func (s EntitySlice) GetAsEndpointSelectors() EndpointSelectorSlice {
slice := EndpointSelectorSlice{}
for _, e := range s {
if selector, ok := EntitySelectorMapping[e]; ok {
slice = append(slice, selector...)
}
}
return slice
} | go | func (s EntitySlice) GetAsEndpointSelectors() EndpointSelectorSlice {
slice := EndpointSelectorSlice{}
for _, e := range s {
if selector, ok := EntitySelectorMapping[e]; ok {
slice = append(slice, selector...)
}
}
return slice
} | [
"func",
"(",
"s",
"EntitySlice",
")",
"GetAsEndpointSelectors",
"(",
")",
"EndpointSelectorSlice",
"{",
"slice",
":=",
"EndpointSelectorSlice",
"{",
"}",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"s",
"{",
"if",
"selector",
",",
"ok",
":=",
"EntitySelectorMapping",
"[",
"e",
"]",
";",
"ok",
"{",
"slice",
"=",
"append",
"(",
"slice",
",",
"selector",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"slice",
"\n",
"}"
] | // GetAsEndpointSelectors returns the provided entity slice as a slice of
// endpoint selectors | [
"GetAsEndpointSelectors",
"returns",
"the",
"provided",
"entity",
"slice",
"as",
"a",
"slice",
"of",
"endpoint",
"selectors"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/entity.go#L106-L115 |
162,926 | cilium/cilium | pkg/policy/api/entity.go | InitEntities | func InitEntities(clusterName string) {
EntitySelectorMapping[EntityCluster] = EndpointSelectorSlice{
endpointSelectorHost,
endpointSelectorInit,
endpointSelectorUnmanaged,
NewESFromLabels(labels.NewLabel(k8sapi.PolicyLabelCluster, clusterName, labels.LabelSourceK8s)),
}
} | go | func InitEntities(clusterName string) {
EntitySelectorMapping[EntityCluster] = EndpointSelectorSlice{
endpointSelectorHost,
endpointSelectorInit,
endpointSelectorUnmanaged,
NewESFromLabels(labels.NewLabel(k8sapi.PolicyLabelCluster, clusterName, labels.LabelSourceK8s)),
}
} | [
"func",
"InitEntities",
"(",
"clusterName",
"string",
")",
"{",
"EntitySelectorMapping",
"[",
"EntityCluster",
"]",
"=",
"EndpointSelectorSlice",
"{",
"endpointSelectorHost",
",",
"endpointSelectorInit",
",",
"endpointSelectorUnmanaged",
",",
"NewESFromLabels",
"(",
"labels",
".",
"NewLabel",
"(",
"k8sapi",
".",
"PolicyLabelCluster",
",",
"clusterName",
",",
"labels",
".",
"LabelSourceK8s",
")",
")",
",",
"}",
"\n",
"}"
] | // InitEntities is called to initialize the policy API layer | [
"InitEntities",
"is",
"called",
"to",
"initialize",
"the",
"policy",
"API",
"layer"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/entity.go#L118-L125 |
162,927 | cilium/cilium | pkg/proxy/proxy.go | getProxyPort | func getProxyPort(l7Type policy.L7ParserType, ingress bool) *ProxyPort {
portType := l7Type
switch l7Type {
case policy.ParserTypeDNS, policy.ParserTypeKafka, policy.ParserTypeHTTP:
default:
// "Unknown" parsers are assumed to be Proxylib (TCP) parsers, which
// is registered with an empty string.
portType = ""
}
// proxyPorts is small enough to not bother indexing it.
for i := range proxyPorts {
if proxyPorts[i].parserType == portType && proxyPorts[i].ingress == ingress {
return &proxyPorts[i]
}
}
return nil
} | go | func getProxyPort(l7Type policy.L7ParserType, ingress bool) *ProxyPort {
portType := l7Type
switch l7Type {
case policy.ParserTypeDNS, policy.ParserTypeKafka, policy.ParserTypeHTTP:
default:
// "Unknown" parsers are assumed to be Proxylib (TCP) parsers, which
// is registered with an empty string.
portType = ""
}
// proxyPorts is small enough to not bother indexing it.
for i := range proxyPorts {
if proxyPorts[i].parserType == portType && proxyPorts[i].ingress == ingress {
return &proxyPorts[i]
}
}
return nil
} | [
"func",
"getProxyPort",
"(",
"l7Type",
"policy",
".",
"L7ParserType",
",",
"ingress",
"bool",
")",
"*",
"ProxyPort",
"{",
"portType",
":=",
"l7Type",
"\n",
"switch",
"l7Type",
"{",
"case",
"policy",
".",
"ParserTypeDNS",
",",
"policy",
".",
"ParserTypeKafka",
",",
"policy",
".",
"ParserTypeHTTP",
":",
"default",
":",
"// \"Unknown\" parsers are assumed to be Proxylib (TCP) parsers, which",
"// is registered with an empty string.",
"portType",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"// proxyPorts is small enough to not bother indexing it.",
"for",
"i",
":=",
"range",
"proxyPorts",
"{",
"if",
"proxyPorts",
"[",
"i",
"]",
".",
"parserType",
"==",
"portType",
"&&",
"proxyPorts",
"[",
"i",
"]",
".",
"ingress",
"==",
"ingress",
"{",
"return",
"&",
"proxyPorts",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // mutex need not be held, as this only refers to immutable members in the static slice. | [
"mutex",
"need",
"not",
"be",
"held",
"as",
"this",
"only",
"refers",
"to",
"immutable",
"members",
"in",
"the",
"static",
"slice",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/proxy/proxy.go#L315-L331 |
162,928 | cilium/cilium | pkg/proxy/proxy.go | ReinstallRules | func (p *Proxy) ReinstallRules() {
proxyPortsMutex.Lock()
defer proxyPortsMutex.Unlock()
for _, pp := range proxyPorts {
if pp.rulesPort > 0 {
// This should always succeed if we have managed to start-up properly
err := p.datapathUpdater.InstallProxyRules(pp.rulesPort, pp.ingress, pp.name)
if err != nil {
proxyPortsMutex.Unlock()
panic(fmt.Sprintf("Can't install proxy rules for %s: %s", pp.name, err))
}
}
}
} | go | func (p *Proxy) ReinstallRules() {
proxyPortsMutex.Lock()
defer proxyPortsMutex.Unlock()
for _, pp := range proxyPorts {
if pp.rulesPort > 0 {
// This should always succeed if we have managed to start-up properly
err := p.datapathUpdater.InstallProxyRules(pp.rulesPort, pp.ingress, pp.name)
if err != nil {
proxyPortsMutex.Unlock()
panic(fmt.Sprintf("Can't install proxy rules for %s: %s", pp.name, err))
}
}
}
} | [
"func",
"(",
"p",
"*",
"Proxy",
")",
"ReinstallRules",
"(",
")",
"{",
"proxyPortsMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"proxyPortsMutex",
".",
"Unlock",
"(",
")",
"\n",
"for",
"_",
",",
"pp",
":=",
"range",
"proxyPorts",
"{",
"if",
"pp",
".",
"rulesPort",
">",
"0",
"{",
"// This should always succeed if we have managed to start-up properly",
"err",
":=",
"p",
".",
"datapathUpdater",
".",
"InstallProxyRules",
"(",
"pp",
".",
"rulesPort",
",",
"pp",
".",
"ingress",
",",
"pp",
".",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"proxyPortsMutex",
".",
"Unlock",
"(",
")",
"\n",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pp",
".",
"name",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // ReinstallRules is called by daemon reconfiguration to re-install proxy ports rules that
// were removed during the removal of all Cilium rules. | [
"ReinstallRules",
"is",
"called",
"by",
"daemon",
"reconfiguration",
"to",
"re",
"-",
"install",
"proxy",
"ports",
"rules",
"that",
"were",
"removed",
"during",
"the",
"removal",
"of",
"all",
"Cilium",
"rules",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/proxy/proxy.go#L375-L388 |
162,929 | cilium/cilium | pkg/proxy/proxy.go | RemoveRedirect | func (p *Proxy) RemoveRedirect(id string, wg *completion.WaitGroup) (error, revert.FinalizeFunc, revert.RevertFunc) {
p.mutex.Lock()
defer func() {
p.UpdateRedirectMetrics()
p.mutex.Unlock()
}()
return p.removeRedirect(id, wg)
} | go | func (p *Proxy) RemoveRedirect(id string, wg *completion.WaitGroup) (error, revert.FinalizeFunc, revert.RevertFunc) {
p.mutex.Lock()
defer func() {
p.UpdateRedirectMetrics()
p.mutex.Unlock()
}()
return p.removeRedirect(id, wg)
} | [
"func",
"(",
"p",
"*",
"Proxy",
")",
"RemoveRedirect",
"(",
"id",
"string",
",",
"wg",
"*",
"completion",
".",
"WaitGroup",
")",
"(",
"error",
",",
"revert",
".",
"FinalizeFunc",
",",
"revert",
".",
"RevertFunc",
")",
"{",
"p",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"p",
".",
"UpdateRedirectMetrics",
"(",
")",
"\n",
"p",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"return",
"p",
".",
"removeRedirect",
"(",
"id",
",",
"wg",
")",
"\n",
"}"
] | // RemoveRedirect removes an existing redirect. | [
"RemoveRedirect",
"removes",
"an",
"existing",
"redirect",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/proxy/proxy.go#L544-L551 |
162,930 | cilium/cilium | pkg/proxy/proxy.go | removeRedirect | func (p *Proxy) removeRedirect(id string, wg *completion.WaitGroup) (err error, finalizeFunc revert.FinalizeFunc, revertFunc revert.RevertFunc) {
log.WithField(fieldProxyRedirectID, id).
Debug("Removing proxy redirect")
r, ok := p.redirects[id]
if !ok {
return fmt.Errorf("unable to find redirect %s", id), nil, nil
}
delete(p.redirects, id)
implFinalizeFunc, implRevertFunc := r.implementation.Close(wg)
// Delay the release and reuse of the port number so it is guaranteed to be
// safe to listen on the port again. This can't be reverted, so do it in a
// FinalizeFunc.
proxyPort := r.listener.proxyPort
listenerName := r.listener.name
finalizeFunc = func() {
// break GC loop (implementation may point back to 'r')
r.implementation = nil
if implFinalizeFunc != nil {
implFinalizeFunc()
}
go func() {
time.Sleep(portReuseDelay)
proxyPortsMutex.Lock()
err := p.releaseProxyPort(listenerName)
proxyPortsMutex.Unlock()
if err != nil {
log.WithField(fieldProxyRedirectID, id).WithError(err).Warningf("Releasing proxy port %d failed", proxyPort)
}
}()
}
revertFunc = func() error {
if implRevertFunc != nil {
return implRevertFunc()
}
p.mutex.Lock()
p.redirects[id] = r
p.mutex.Unlock()
return nil
}
return
} | go | func (p *Proxy) removeRedirect(id string, wg *completion.WaitGroup) (err error, finalizeFunc revert.FinalizeFunc, revertFunc revert.RevertFunc) {
log.WithField(fieldProxyRedirectID, id).
Debug("Removing proxy redirect")
r, ok := p.redirects[id]
if !ok {
return fmt.Errorf("unable to find redirect %s", id), nil, nil
}
delete(p.redirects, id)
implFinalizeFunc, implRevertFunc := r.implementation.Close(wg)
// Delay the release and reuse of the port number so it is guaranteed to be
// safe to listen on the port again. This can't be reverted, so do it in a
// FinalizeFunc.
proxyPort := r.listener.proxyPort
listenerName := r.listener.name
finalizeFunc = func() {
// break GC loop (implementation may point back to 'r')
r.implementation = nil
if implFinalizeFunc != nil {
implFinalizeFunc()
}
go func() {
time.Sleep(portReuseDelay)
proxyPortsMutex.Lock()
err := p.releaseProxyPort(listenerName)
proxyPortsMutex.Unlock()
if err != nil {
log.WithField(fieldProxyRedirectID, id).WithError(err).Warningf("Releasing proxy port %d failed", proxyPort)
}
}()
}
revertFunc = func() error {
if implRevertFunc != nil {
return implRevertFunc()
}
p.mutex.Lock()
p.redirects[id] = r
p.mutex.Unlock()
return nil
}
return
} | [
"func",
"(",
"p",
"*",
"Proxy",
")",
"removeRedirect",
"(",
"id",
"string",
",",
"wg",
"*",
"completion",
".",
"WaitGroup",
")",
"(",
"err",
"error",
",",
"finalizeFunc",
"revert",
".",
"FinalizeFunc",
",",
"revertFunc",
"revert",
".",
"RevertFunc",
")",
"{",
"log",
".",
"WithField",
"(",
"fieldProxyRedirectID",
",",
"id",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"r",
",",
"ok",
":=",
"p",
".",
"redirects",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
")",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"delete",
"(",
"p",
".",
"redirects",
",",
"id",
")",
"\n\n",
"implFinalizeFunc",
",",
"implRevertFunc",
":=",
"r",
".",
"implementation",
".",
"Close",
"(",
"wg",
")",
"\n\n",
"// Delay the release and reuse of the port number so it is guaranteed to be",
"// safe to listen on the port again. This can't be reverted, so do it in a",
"// FinalizeFunc.",
"proxyPort",
":=",
"r",
".",
"listener",
".",
"proxyPort",
"\n",
"listenerName",
":=",
"r",
".",
"listener",
".",
"name",
"\n\n",
"finalizeFunc",
"=",
"func",
"(",
")",
"{",
"// break GC loop (implementation may point back to 'r')",
"r",
".",
"implementation",
"=",
"nil",
"\n\n",
"if",
"implFinalizeFunc",
"!=",
"nil",
"{",
"implFinalizeFunc",
"(",
")",
"\n",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"time",
".",
"Sleep",
"(",
"portReuseDelay",
")",
"\n\n",
"proxyPortsMutex",
".",
"Lock",
"(",
")",
"\n",
"err",
":=",
"p",
".",
"releaseProxyPort",
"(",
"listenerName",
")",
"\n",
"proxyPortsMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithField",
"(",
"fieldProxyRedirectID",
",",
"id",
")",
".",
"WithError",
"(",
"err",
")",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"proxyPort",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n\n",
"revertFunc",
"=",
"func",
"(",
")",
"error",
"{",
"if",
"implRevertFunc",
"!=",
"nil",
"{",
"return",
"implRevertFunc",
"(",
")",
"\n",
"}",
"\n\n",
"p",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"p",
".",
"redirects",
"[",
"id",
"]",
"=",
"r",
"\n",
"p",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // removeRedirect removes an existing redirect. p.mutex must be held
// p.mutex must NOT be held when the returned finalize and revert functions are called! | [
"removeRedirect",
"removes",
"an",
"existing",
"redirect",
".",
"p",
".",
"mutex",
"must",
"be",
"held",
"p",
".",
"mutex",
"must",
"NOT",
"be",
"held",
"when",
"the",
"returned",
"finalize",
"and",
"revert",
"functions",
"are",
"called!"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/proxy/proxy.go#L555-L606 |
162,931 | cilium/cilium | pkg/proxy/proxy.go | GetStatusModel | func (p *Proxy) GetStatusModel() *models.ProxyStatus {
p.mutex.RLock()
defer p.mutex.RUnlock()
return &models.ProxyStatus{
IP: node.GetInternalIPv4().String(),
PortRange: fmt.Sprintf("%d-%d", p.rangeMin, p.rangeMax),
}
} | go | func (p *Proxy) GetStatusModel() *models.ProxyStatus {
p.mutex.RLock()
defer p.mutex.RUnlock()
return &models.ProxyStatus{
IP: node.GetInternalIPv4().String(),
PortRange: fmt.Sprintf("%d-%d", p.rangeMin, p.rangeMax),
}
} | [
"func",
"(",
"p",
"*",
"Proxy",
")",
"GetStatusModel",
"(",
")",
"*",
"models",
".",
"ProxyStatus",
"{",
"p",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"p",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"&",
"models",
".",
"ProxyStatus",
"{",
"IP",
":",
"node",
".",
"GetInternalIPv4",
"(",
")",
".",
"String",
"(",
")",
",",
"PortRange",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"rangeMin",
",",
"p",
".",
"rangeMax",
")",
",",
"}",
"\n",
"}"
] | // GetStatusModel returns the proxy status as API model | [
"GetStatusModel",
"returns",
"the",
"proxy",
"status",
"as",
"API",
"model"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/proxy/proxy.go#L616-L624 |
162,932 | cilium/cilium | pkg/proxy/proxy.go | UpdateRedirectMetrics | func (p *Proxy) UpdateRedirectMetrics() {
result := map[string]int{}
for _, redirect := range p.redirects {
result[string(redirect.listener.parserType)]++
}
for proto, count := range result {
metrics.ProxyRedirects.WithLabelValues(proto).Set(float64(count))
}
} | go | func (p *Proxy) UpdateRedirectMetrics() {
result := map[string]int{}
for _, redirect := range p.redirects {
result[string(redirect.listener.parserType)]++
}
for proto, count := range result {
metrics.ProxyRedirects.WithLabelValues(proto).Set(float64(count))
}
} | [
"func",
"(",
"p",
"*",
"Proxy",
")",
"UpdateRedirectMetrics",
"(",
")",
"{",
"result",
":=",
"map",
"[",
"string",
"]",
"int",
"{",
"}",
"\n",
"for",
"_",
",",
"redirect",
":=",
"range",
"p",
".",
"redirects",
"{",
"result",
"[",
"string",
"(",
"redirect",
".",
"listener",
".",
"parserType",
")",
"]",
"++",
"\n",
"}",
"\n",
"for",
"proto",
",",
"count",
":=",
"range",
"result",
"{",
"metrics",
".",
"ProxyRedirects",
".",
"WithLabelValues",
"(",
"proto",
")",
".",
"Set",
"(",
"float64",
"(",
"count",
")",
")",
"\n",
"}",
"\n",
"}"
] | // UpdateRedirectMetrics updates the redirect metrics per application protocol
// in Prometheus. Lock needs to be held to call this function. | [
"UpdateRedirectMetrics",
"updates",
"the",
"redirect",
"metrics",
"per",
"application",
"protocol",
"in",
"Prometheus",
".",
"Lock",
"needs",
"to",
"be",
"held",
"to",
"call",
"this",
"function",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/proxy/proxy.go#L628-L636 |
162,933 | cilium/cilium | api/v1/server/restapi/endpoint/patch_endpoint_id_labels_responses.go | WithPayload | func (o *PatchEndpointIDLabelsUpdateFailed) WithPayload(payload models.Error) *PatchEndpointIDLabelsUpdateFailed {
o.Payload = payload
return o
} | go | func (o *PatchEndpointIDLabelsUpdateFailed) WithPayload(payload models.Error) *PatchEndpointIDLabelsUpdateFailed {
o.Payload = payload
return o
} | [
"func",
"(",
"o",
"*",
"PatchEndpointIDLabelsUpdateFailed",
")",
"WithPayload",
"(",
"payload",
"models",
".",
"Error",
")",
"*",
"PatchEndpointIDLabelsUpdateFailed",
"{",
"o",
".",
"Payload",
"=",
"payload",
"\n",
"return",
"o",
"\n",
"}"
] | // WithPayload adds the payload to the patch endpoint Id labels update failed response | [
"WithPayload",
"adds",
"the",
"payload",
"to",
"the",
"patch",
"endpoint",
"Id",
"labels",
"update",
"failed",
"response"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/endpoint/patch_endpoint_id_labels_responses.go#L86-L89 |
162,934 | cilium/cilium | pkg/k8s/version/version.go | Version | func Version() *go_version.Version {
cached.mutex.RLock()
c := cached.version
cached.mutex.RUnlock()
return c
} | go | func Version() *go_version.Version {
cached.mutex.RLock()
c := cached.version
cached.mutex.RUnlock()
return c
} | [
"func",
"Version",
"(",
")",
"*",
"go_version",
".",
"Version",
"{",
"cached",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"c",
":=",
"cached",
".",
"version",
"\n",
"cached",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // Version returns the version of the Kubernetes apiserver | [
"Version",
"returns",
"the",
"version",
"of",
"the",
"Kubernetes",
"apiserver"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/version/version.go#L62-L67 |
162,935 | cilium/cilium | pkg/k8s/version/version.go | Capabilities | func Capabilities() ServerCapabilities {
cached.mutex.RLock()
c := cached.capabilities
cached.mutex.RUnlock()
return c
} | go | func Capabilities() ServerCapabilities {
cached.mutex.RLock()
c := cached.capabilities
cached.mutex.RUnlock()
return c
} | [
"func",
"Capabilities",
"(",
")",
"ServerCapabilities",
"{",
"cached",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"c",
":=",
"cached",
".",
"capabilities",
"\n",
"cached",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // Capabilities returns the capabilities of the Kubernetes apiserver | [
"Capabilities",
"returns",
"the",
"capabilities",
"of",
"the",
"Kubernetes",
"apiserver"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/version/version.go#L70-L75 |
162,936 | cilium/cilium | pkg/k8s/version/version.go | Force | func Force(version string) error {
ver, err := go_version.NewVersion(version)
if err != nil {
return err
}
updateVersion(ver)
return nil
} | go | func Force(version string) error {
ver, err := go_version.NewVersion(version)
if err != nil {
return err
}
updateVersion(ver)
return nil
} | [
"func",
"Force",
"(",
"version",
"string",
")",
"error",
"{",
"ver",
",",
"err",
":=",
"go_version",
".",
"NewVersion",
"(",
"version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"updateVersion",
"(",
"ver",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Force forces the use of a specific version | [
"Force",
"forces",
"the",
"use",
"of",
"a",
"specific",
"version"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/version/version.go#L89-L96 |
162,937 | cilium/cilium | pkg/k8s/version/version.go | Update | func Update(client kubernetes.Interface) error {
sv, err := client.Discovery().ServerVersion()
if err != nil {
return err
}
// Try GitVersion first. In case of error fallback to MajorMinor
if sv.GitVersion != "" {
// This is a string like "v1.9.0"
ver, err := go_version.NewVersion(sv.GitVersion)
if err == nil {
updateVersion(ver)
return nil
}
}
if sv.Major != "" && sv.Minor != "" {
ver, err := go_version.NewVersion(fmt.Sprintf("%s.%s", sv.Major, sv.Minor))
if err == nil {
updateVersion(ver)
return nil
}
}
if err != nil {
return fmt.Errorf("cannot parse k8s server version from %+v: %s", sv, err)
}
return fmt.Errorf("cannot parse k8s server version from %+v", sv)
} | go | func Update(client kubernetes.Interface) error {
sv, err := client.Discovery().ServerVersion()
if err != nil {
return err
}
// Try GitVersion first. In case of error fallback to MajorMinor
if sv.GitVersion != "" {
// This is a string like "v1.9.0"
ver, err := go_version.NewVersion(sv.GitVersion)
if err == nil {
updateVersion(ver)
return nil
}
}
if sv.Major != "" && sv.Minor != "" {
ver, err := go_version.NewVersion(fmt.Sprintf("%s.%s", sv.Major, sv.Minor))
if err == nil {
updateVersion(ver)
return nil
}
}
if err != nil {
return fmt.Errorf("cannot parse k8s server version from %+v: %s", sv, err)
}
return fmt.Errorf("cannot parse k8s server version from %+v", sv)
} | [
"func",
"Update",
"(",
"client",
"kubernetes",
".",
"Interface",
")",
"error",
"{",
"sv",
",",
"err",
":=",
"client",
".",
"Discovery",
"(",
")",
".",
"ServerVersion",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Try GitVersion first. In case of error fallback to MajorMinor",
"if",
"sv",
".",
"GitVersion",
"!=",
"\"",
"\"",
"{",
"// This is a string like \"v1.9.0\"",
"ver",
",",
"err",
":=",
"go_version",
".",
"NewVersion",
"(",
"sv",
".",
"GitVersion",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"updateVersion",
"(",
"ver",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"sv",
".",
"Major",
"!=",
"\"",
"\"",
"&&",
"sv",
".",
"Minor",
"!=",
"\"",
"\"",
"{",
"ver",
",",
"err",
":=",
"go_version",
".",
"NewVersion",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sv",
".",
"Major",
",",
"sv",
".",
"Minor",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"updateVersion",
"(",
"ver",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sv",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sv",
")",
"\n",
"}"
] | // Update retrieves the version of the Kubernetes apiserver and derives the
// capabilities. This function must be called after connectivity to the
// apiserver has been established. | [
"Update",
"retrieves",
"the",
"version",
"of",
"the",
"Kubernetes",
"apiserver",
"and",
"derives",
"the",
"capabilities",
".",
"This",
"function",
"must",
"be",
"called",
"after",
"connectivity",
"to",
"the",
"apiserver",
"has",
"been",
"established",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/version/version.go#L101-L129 |
162,938 | cilium/cilium | api/v1/server/restapi/endpoint/get_endpoint_id.go | NewGetEndpointID | func NewGetEndpointID(ctx *middleware.Context, handler GetEndpointIDHandler) *GetEndpointID {
return &GetEndpointID{Context: ctx, Handler: handler}
} | go | func NewGetEndpointID(ctx *middleware.Context, handler GetEndpointIDHandler) *GetEndpointID {
return &GetEndpointID{Context: ctx, Handler: handler}
} | [
"func",
"NewGetEndpointID",
"(",
"ctx",
"*",
"middleware",
".",
"Context",
",",
"handler",
"GetEndpointIDHandler",
")",
"*",
"GetEndpointID",
"{",
"return",
"&",
"GetEndpointID",
"{",
"Context",
":",
"ctx",
",",
"Handler",
":",
"handler",
"}",
"\n",
"}"
] | // NewGetEndpointID creates a new http.Handler for the get endpoint ID operation | [
"NewGetEndpointID",
"creates",
"a",
"new",
"http",
".",
"Handler",
"for",
"the",
"get",
"endpoint",
"ID",
"operation"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/endpoint/get_endpoint_id.go#L28-L30 |
162,939 | cilium/cilium | pkg/endpoint/log.go | getLogger | func (e *Endpoint) getLogger() *logrus.Entry {
v := atomic.LoadPointer(&e.logger)
return (*logrus.Entry)(v)
} | go | func (e *Endpoint) getLogger() *logrus.Entry {
v := atomic.LoadPointer(&e.logger)
return (*logrus.Entry)(v)
} | [
"func",
"(",
"e",
"*",
"Endpoint",
")",
"getLogger",
"(",
")",
"*",
"logrus",
".",
"Entry",
"{",
"v",
":=",
"atomic",
".",
"LoadPointer",
"(",
"&",
"e",
".",
"logger",
")",
"\n",
"return",
"(",
"*",
"logrus",
".",
"Entry",
")",
"(",
"v",
")",
"\n",
"}"
] | // getLogger returns a logrus object with EndpointID, ContainerID and the Endpoint
// revision fields. | [
"getLogger",
"returns",
"a",
"logrus",
"object",
"with",
"EndpointID",
"ContainerID",
"and",
"the",
"Endpoint",
"revision",
"fields",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/log.go#L39-L42 |
162,940 | cilium/cilium | pkg/endpoint/log.go | Logger | func (e *Endpoint) Logger(subsystem string) *logrus.Entry {
if e == nil {
return log.WithField(logfields.LogSubsys, subsystem)
}
return e.getLogger().WithField(logfields.LogSubsys, subsystem)
} | go | func (e *Endpoint) Logger(subsystem string) *logrus.Entry {
if e == nil {
return log.WithField(logfields.LogSubsys, subsystem)
}
return e.getLogger().WithField(logfields.LogSubsys, subsystem)
} | [
"func",
"(",
"e",
"*",
"Endpoint",
")",
"Logger",
"(",
"subsystem",
"string",
")",
"*",
"logrus",
".",
"Entry",
"{",
"if",
"e",
"==",
"nil",
"{",
"return",
"log",
".",
"WithField",
"(",
"logfields",
".",
"LogSubsys",
",",
"subsystem",
")",
"\n",
"}",
"\n\n",
"return",
"e",
".",
"getLogger",
"(",
")",
".",
"WithField",
"(",
"logfields",
".",
"LogSubsys",
",",
"subsystem",
")",
"\n",
"}"
] | // Logger returns a logrus object with EndpointID, ContainerID and the Endpoint
// revision fields. The caller must specify their subsystem. | [
"Logger",
"returns",
"a",
"logrus",
"object",
"with",
"EndpointID",
"ContainerID",
"and",
"the",
"Endpoint",
"revision",
"fields",
".",
"The",
"caller",
"must",
"specify",
"their",
"subsystem",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/log.go#L46-L52 |
162,941 | cilium/cilium | api/v1/models/backend_address.go | Validate | func (m *BackendAddress) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateIP(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | go | func (m *BackendAddress) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateIP(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | [
"func",
"(",
"m",
"*",
"BackendAddress",
")",
"Validate",
"(",
"formats",
"strfmt",
".",
"Registry",
")",
"error",
"{",
"var",
"res",
"[",
"]",
"error",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateIP",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"res",
")",
">",
"0",
"{",
"return",
"errors",
".",
"CompositeValidationError",
"(",
"res",
"...",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate validates this backend address | [
"Validate",
"validates",
"this",
"backend",
"address"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/models/backend_address.go#L32-L43 |
162,942 | cilium/cilium | pkg/k8s/node.go | ParseNodeAddressType | func ParseNodeAddressType(k8sAddress v1.NodeAddressType) (addressing.AddressType, error) {
var err error
convertedAddr := addressing.AddressType(k8sAddress)
switch convertedAddr {
case addressing.NodeExternalDNS, addressing.NodeExternalIP, addressing.NodeHostName, addressing.NodeInternalIP, addressing.NodeInternalDNS:
default:
err = fmt.Errorf("invalid Kubernetes NodeAddressType %s", convertedAddr)
}
return convertedAddr, err
} | go | func ParseNodeAddressType(k8sAddress v1.NodeAddressType) (addressing.AddressType, error) {
var err error
convertedAddr := addressing.AddressType(k8sAddress)
switch convertedAddr {
case addressing.NodeExternalDNS, addressing.NodeExternalIP, addressing.NodeHostName, addressing.NodeInternalIP, addressing.NodeInternalDNS:
default:
err = fmt.Errorf("invalid Kubernetes NodeAddressType %s", convertedAddr)
}
return convertedAddr, err
} | [
"func",
"ParseNodeAddressType",
"(",
"k8sAddress",
"v1",
".",
"NodeAddressType",
")",
"(",
"addressing",
".",
"AddressType",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"convertedAddr",
":=",
"addressing",
".",
"AddressType",
"(",
"k8sAddress",
")",
"\n\n",
"switch",
"convertedAddr",
"{",
"case",
"addressing",
".",
"NodeExternalDNS",
",",
"addressing",
".",
"NodeExternalIP",
",",
"addressing",
".",
"NodeHostName",
",",
"addressing",
".",
"NodeInternalIP",
",",
"addressing",
".",
"NodeInternalDNS",
":",
"default",
":",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"convertedAddr",
")",
"\n",
"}",
"\n",
"return",
"convertedAddr",
",",
"err",
"\n",
"}"
] | // ParseNodeAddressType converts a Kubernetes NodeAddressType to a Cilium
// NodeAddressType. If the Kubernetes NodeAddressType does not have a
// corresponding Cilium AddressType, returns an error. | [
"ParseNodeAddressType",
"converts",
"a",
"Kubernetes",
"NodeAddressType",
"to",
"a",
"Cilium",
"NodeAddressType",
".",
"If",
"the",
"Kubernetes",
"NodeAddressType",
"does",
"not",
"have",
"a",
"corresponding",
"Cilium",
"AddressType",
"returns",
"an",
"error",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/node.go#L38-L49 |
162,943 | cilium/cilium | pkg/k8s/node.go | GetNode | func GetNode(c kubernetes.Interface, nodeName string) (*v1.Node, error) {
// Try to retrieve node's cidr and addresses from k8s's configuration
return c.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})
} | go | func GetNode(c kubernetes.Interface, nodeName string) (*v1.Node, error) {
// Try to retrieve node's cidr and addresses from k8s's configuration
return c.CoreV1().Nodes().Get(nodeName, metav1.GetOptions{})
} | [
"func",
"GetNode",
"(",
"c",
"kubernetes",
".",
"Interface",
",",
"nodeName",
"string",
")",
"(",
"*",
"v1",
".",
"Node",
",",
"error",
")",
"{",
"// Try to retrieve node's cidr and addresses from k8s's configuration",
"return",
"c",
".",
"CoreV1",
"(",
")",
".",
"Nodes",
"(",
")",
".",
"Get",
"(",
"nodeName",
",",
"metav1",
".",
"GetOptions",
"{",
"}",
")",
"\n",
"}"
] | // GetNode returns the kubernetes nodeName's node information from the
// kubernetes api server | [
"GetNode",
"returns",
"the",
"kubernetes",
"nodeName",
"s",
"node",
"information",
"from",
"the",
"kubernetes",
"api",
"server"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/node.go#L183-L186 |
162,944 | cilium/cilium | pkg/endpoint/id/id.go | NewIPPrefixID | func NewIPPrefixID(ip net.IP) string {
if ip.To4() != nil {
return NewID(IPv4Prefix, ip.String())
}
return NewID(IPv6Prefix, ip.String())
} | go | func NewIPPrefixID(ip net.IP) string {
if ip.To4() != nil {
return NewID(IPv4Prefix, ip.String())
}
return NewID(IPv6Prefix, ip.String())
} | [
"func",
"NewIPPrefixID",
"(",
"ip",
"net",
".",
"IP",
")",
"string",
"{",
"if",
"ip",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"return",
"NewID",
"(",
"IPv4Prefix",
",",
"ip",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"NewID",
"(",
"IPv6Prefix",
",",
"ip",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // NewIPPrefixID returns an identifier based on the IP address specified | [
"NewIPPrefixID",
"returns",
"an",
"identifier",
"based",
"on",
"the",
"IP",
"address",
"specified"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/id/id.go#L81-L87 |
162,945 | cilium/cilium | pkg/endpoint/id/id.go | splitID | func splitID(id string) (PrefixType, string) {
if idx := strings.Index(id, ":"); idx > -1 {
return PrefixType(id[:idx]), id[idx+1:]
}
// default prefix
return CiliumLocalIdPrefix, id
} | go | func splitID(id string) (PrefixType, string) {
if idx := strings.Index(id, ":"); idx > -1 {
return PrefixType(id[:idx]), id[idx+1:]
}
// default prefix
return CiliumLocalIdPrefix, id
} | [
"func",
"splitID",
"(",
"id",
"string",
")",
"(",
"PrefixType",
",",
"string",
")",
"{",
"if",
"idx",
":=",
"strings",
".",
"Index",
"(",
"id",
",",
"\"",
"\"",
")",
";",
"idx",
">",
"-",
"1",
"{",
"return",
"PrefixType",
"(",
"id",
"[",
":",
"idx",
"]",
")",
",",
"id",
"[",
"idx",
"+",
"1",
":",
"]",
"\n",
"}",
"\n\n",
"// default prefix",
"return",
"CiliumLocalIdPrefix",
",",
"id",
"\n",
"}"
] | // splitID splits ID into prefix and id. No validation is performed on prefix. | [
"splitID",
"splits",
"ID",
"into",
"prefix",
"and",
"id",
".",
"No",
"validation",
"is",
"performed",
"on",
"prefix",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/id/id.go#L90-L97 |
162,946 | cilium/cilium | pkg/endpoint/id/id.go | ParseCiliumID | func ParseCiliumID(id string) (int64, error) {
prefix, id := splitID(id)
if prefix != CiliumLocalIdPrefix {
return 0, fmt.Errorf("not a cilium identifier")
}
n, err := strconv.ParseInt(id, 0, 64)
if err != nil {
return 0, fmt.Errorf("invalid numeric cilium id: %s", err)
}
return n, nil
} | go | func ParseCiliumID(id string) (int64, error) {
prefix, id := splitID(id)
if prefix != CiliumLocalIdPrefix {
return 0, fmt.Errorf("not a cilium identifier")
}
n, err := strconv.ParseInt(id, 0, 64)
if err != nil {
return 0, fmt.Errorf("invalid numeric cilium id: %s", err)
}
return n, nil
} | [
"func",
"ParseCiliumID",
"(",
"id",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"prefix",
",",
"id",
":=",
"splitID",
"(",
"id",
")",
"\n",
"if",
"prefix",
"!=",
"CiliumLocalIdPrefix",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"n",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"id",
",",
"0",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"n",
",",
"nil",
"\n",
"}"
] | // ParseCiliumID parses id as cilium endpoint id and returns numeric portion. | [
"ParseCiliumID",
"parses",
"id",
"as",
"cilium",
"endpoint",
"id",
"and",
"returns",
"numeric",
"portion",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/id/id.go#L100-L110 |
162,947 | cilium/cilium | api/v1/models/service_spec.go | Validate | func (m *ServiceSpec) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateBackendAddresses(formats); err != nil {
res = append(res, err)
}
if err := m.validateFlags(formats); err != nil {
res = append(res, err)
}
if err := m.validateFrontendAddress(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | go | func (m *ServiceSpec) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateBackendAddresses(formats); err != nil {
res = append(res, err)
}
if err := m.validateFlags(formats); err != nil {
res = append(res, err)
}
if err := m.validateFrontendAddress(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | [
"func",
"(",
"m",
"*",
"ServiceSpec",
")",
"Validate",
"(",
"formats",
"strfmt",
".",
"Registry",
")",
"error",
"{",
"var",
"res",
"[",
"]",
"error",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateBackendAddresses",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateFlags",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateFrontendAddress",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"res",
")",
">",
"0",
"{",
"return",
"errors",
".",
"CompositeValidationError",
"(",
"res",
"...",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate validates this service spec | [
"Validate",
"validates",
"this",
"service",
"spec"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/models/service_spec.go#L37-L56 |
162,948 | cilium/cilium | api/v1/models/node_element.go | Validate | func (m *NodeElement) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateHealthEndpointAddress(formats); err != nil {
res = append(res, err)
}
if err := m.validatePrimaryAddress(formats); err != nil {
res = append(res, err)
}
if err := m.validateSecondaryAddresses(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | go | func (m *NodeElement) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateHealthEndpointAddress(formats); err != nil {
res = append(res, err)
}
if err := m.validatePrimaryAddress(formats); err != nil {
res = append(res, err)
}
if err := m.validateSecondaryAddresses(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | [
"func",
"(",
"m",
"*",
"NodeElement",
")",
"Validate",
"(",
"formats",
"strfmt",
".",
"Registry",
")",
"error",
"{",
"var",
"res",
"[",
"]",
"error",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateHealthEndpointAddress",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validatePrimaryAddress",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateSecondaryAddresses",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"res",
")",
">",
"0",
"{",
"return",
"errors",
".",
"CompositeValidationError",
"(",
"res",
"...",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate validates this node element | [
"Validate",
"validates",
"this",
"node",
"element"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/models/node_element.go#L38-L57 |
162,949 | cilium/cilium | pkg/maps/lbmap/types.go | l3n4Addr2ServiceKey | func l3n4Addr2ServiceKey(l3n4Addr loadbalancer.L3n4AddrID) ServiceKey {
log.WithField(logfields.L3n4AddrID, l3n4Addr).Debug("converting L3n4Addr to ServiceKey")
if l3n4Addr.IsIPv6() {
return NewService6Key(l3n4Addr.IP, l3n4Addr.Port, 0)
}
return NewService4Key(l3n4Addr.IP, l3n4Addr.Port, 0)
} | go | func l3n4Addr2ServiceKey(l3n4Addr loadbalancer.L3n4AddrID) ServiceKey {
log.WithField(logfields.L3n4AddrID, l3n4Addr).Debug("converting L3n4Addr to ServiceKey")
if l3n4Addr.IsIPv6() {
return NewService6Key(l3n4Addr.IP, l3n4Addr.Port, 0)
}
return NewService4Key(l3n4Addr.IP, l3n4Addr.Port, 0)
} | [
"func",
"l3n4Addr2ServiceKey",
"(",
"l3n4Addr",
"loadbalancer",
".",
"L3n4AddrID",
")",
"ServiceKey",
"{",
"log",
".",
"WithField",
"(",
"logfields",
".",
"L3n4AddrID",
",",
"l3n4Addr",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"if",
"l3n4Addr",
".",
"IsIPv6",
"(",
")",
"{",
"return",
"NewService6Key",
"(",
"l3n4Addr",
".",
"IP",
",",
"l3n4Addr",
".",
"Port",
",",
"0",
")",
"\n",
"}",
"\n",
"return",
"NewService4Key",
"(",
"l3n4Addr",
".",
"IP",
",",
"l3n4Addr",
".",
"Port",
",",
"0",
")",
"\n",
"}"
] | // l3n4Addr2ServiceKey converts the given l3n4Addr to a ServiceKey with the slave ID
// set to 0. | [
"l3n4Addr2ServiceKey",
"converts",
"the",
"given",
"l3n4Addr",
"to",
"a",
"ServiceKey",
"with",
"the",
"slave",
"ID",
"set",
"to",
"0",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lbmap/types.go#L274-L280 |
162,950 | cilium/cilium | pkg/maps/lbmap/types.go | LBSVC2ServiceKeynValue | func LBSVC2ServiceKeynValue(svc loadbalancer.LBSVC) (ServiceKey, []ServiceValue, error) {
log.WithFields(logrus.Fields{
"lbFrontend": svc.FE.String(),
"lbBackend": svc.BES,
}).Debug("converting Cilium load-balancer service (frontend -> backend(s)) into BPF service")
fe := l3n4Addr2ServiceKey(svc.FE)
// Create a list of ServiceValues so we know everything is safe to put in the lb
// map
besValues := []ServiceValue{}
for _, be := range svc.BES {
beValue := fe.NewValue().(ServiceValue)
if err := beValue.SetAddress(be.IP); err != nil {
return nil, nil, err
}
beValue.SetPort(be.Port)
beValue.SetRevNat(int(svc.FE.ID))
beValue.SetWeight(be.Weight)
besValues = append(besValues, beValue)
log.WithFields(logrus.Fields{
"lbFrontend": fe,
"lbBackend": beValue,
}).Debug("associating frontend -> backend")
}
log.WithFields(logrus.Fields{
"lbFrontend": svc.FE.String(),
"lbBackend": svc.BES,
logfields.ServiceID: fe,
logfields.Object: logfields.Repr(besValues),
}).Debug("converted LBSVC (frontend -> backend(s)), to Service Key and Value")
return fe, besValues, nil
} | go | func LBSVC2ServiceKeynValue(svc loadbalancer.LBSVC) (ServiceKey, []ServiceValue, error) {
log.WithFields(logrus.Fields{
"lbFrontend": svc.FE.String(),
"lbBackend": svc.BES,
}).Debug("converting Cilium load-balancer service (frontend -> backend(s)) into BPF service")
fe := l3n4Addr2ServiceKey(svc.FE)
// Create a list of ServiceValues so we know everything is safe to put in the lb
// map
besValues := []ServiceValue{}
for _, be := range svc.BES {
beValue := fe.NewValue().(ServiceValue)
if err := beValue.SetAddress(be.IP); err != nil {
return nil, nil, err
}
beValue.SetPort(be.Port)
beValue.SetRevNat(int(svc.FE.ID))
beValue.SetWeight(be.Weight)
besValues = append(besValues, beValue)
log.WithFields(logrus.Fields{
"lbFrontend": fe,
"lbBackend": beValue,
}).Debug("associating frontend -> backend")
}
log.WithFields(logrus.Fields{
"lbFrontend": svc.FE.String(),
"lbBackend": svc.BES,
logfields.ServiceID: fe,
logfields.Object: logfields.Repr(besValues),
}).Debug("converted LBSVC (frontend -> backend(s)), to Service Key and Value")
return fe, besValues, nil
} | [
"func",
"LBSVC2ServiceKeynValue",
"(",
"svc",
"loadbalancer",
".",
"LBSVC",
")",
"(",
"ServiceKey",
",",
"[",
"]",
"ServiceValue",
",",
"error",
")",
"{",
"log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"svc",
".",
"FE",
".",
"String",
"(",
")",
",",
"\"",
"\"",
":",
"svc",
".",
"BES",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"fe",
":=",
"l3n4Addr2ServiceKey",
"(",
"svc",
".",
"FE",
")",
"\n\n",
"// Create a list of ServiceValues so we know everything is safe to put in the lb",
"// map",
"besValues",
":=",
"[",
"]",
"ServiceValue",
"{",
"}",
"\n",
"for",
"_",
",",
"be",
":=",
"range",
"svc",
".",
"BES",
"{",
"beValue",
":=",
"fe",
".",
"NewValue",
"(",
")",
".",
"(",
"ServiceValue",
")",
"\n",
"if",
"err",
":=",
"beValue",
".",
"SetAddress",
"(",
"be",
".",
"IP",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"beValue",
".",
"SetPort",
"(",
"be",
".",
"Port",
")",
"\n",
"beValue",
".",
"SetRevNat",
"(",
"int",
"(",
"svc",
".",
"FE",
".",
"ID",
")",
")",
"\n",
"beValue",
".",
"SetWeight",
"(",
"be",
".",
"Weight",
")",
"\n\n",
"besValues",
"=",
"append",
"(",
"besValues",
",",
"beValue",
")",
"\n",
"log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"fe",
",",
"\"",
"\"",
":",
"beValue",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"svc",
".",
"FE",
".",
"String",
"(",
")",
",",
"\"",
"\"",
":",
"svc",
".",
"BES",
",",
"logfields",
".",
"ServiceID",
":",
"fe",
",",
"logfields",
".",
"Object",
":",
"logfields",
".",
"Repr",
"(",
"besValues",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"fe",
",",
"besValues",
",",
"nil",
"\n",
"}"
] | // LBSVC2ServiceKeynValue transforms the SVC Cilium type into a bpf SVC type. | [
"LBSVC2ServiceKeynValue",
"transforms",
"the",
"SVC",
"Cilium",
"type",
"into",
"a",
"bpf",
"SVC",
"type",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lbmap/types.go#L283-L315 |
162,951 | cilium/cilium | pkg/maps/lbmap/types.go | L3n4Addr2RevNatKeynValue | func L3n4Addr2RevNatKeynValue(svcID loadbalancer.ServiceID, feL3n4Addr loadbalancer.L3n4Addr) (RevNatKey, RevNatValue) {
if feL3n4Addr.IsIPv6() {
return NewRevNat6Key(uint16(svcID)), NewRevNat6Value(feL3n4Addr.IP, feL3n4Addr.Port)
}
return NewRevNat4Key(uint16(svcID)), NewRevNat4Value(feL3n4Addr.IP, feL3n4Addr.Port)
} | go | func L3n4Addr2RevNatKeynValue(svcID loadbalancer.ServiceID, feL3n4Addr loadbalancer.L3n4Addr) (RevNatKey, RevNatValue) {
if feL3n4Addr.IsIPv6() {
return NewRevNat6Key(uint16(svcID)), NewRevNat6Value(feL3n4Addr.IP, feL3n4Addr.Port)
}
return NewRevNat4Key(uint16(svcID)), NewRevNat4Value(feL3n4Addr.IP, feL3n4Addr.Port)
} | [
"func",
"L3n4Addr2RevNatKeynValue",
"(",
"svcID",
"loadbalancer",
".",
"ServiceID",
",",
"feL3n4Addr",
"loadbalancer",
".",
"L3n4Addr",
")",
"(",
"RevNatKey",
",",
"RevNatValue",
")",
"{",
"if",
"feL3n4Addr",
".",
"IsIPv6",
"(",
")",
"{",
"return",
"NewRevNat6Key",
"(",
"uint16",
"(",
"svcID",
")",
")",
",",
"NewRevNat6Value",
"(",
"feL3n4Addr",
".",
"IP",
",",
"feL3n4Addr",
".",
"Port",
")",
"\n",
"}",
"\n",
"return",
"NewRevNat4Key",
"(",
"uint16",
"(",
"svcID",
")",
")",
",",
"NewRevNat4Value",
"(",
"feL3n4Addr",
".",
"IP",
",",
"feL3n4Addr",
".",
"Port",
")",
"\n",
"}"
] | // L3n4Addr2RevNatKeynValue converts the given L3n4Addr to a RevNatKey and RevNatValue. | [
"L3n4Addr2RevNatKeynValue",
"converts",
"the",
"given",
"L3n4Addr",
"to",
"a",
"RevNatKey",
"and",
"RevNatValue",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lbmap/types.go#L318-L323 |
162,952 | cilium/cilium | pkg/maps/lbmap/types.go | serviceKeynValue2FEnBE | func serviceKeynValue2FEnBE(svcKey ServiceKey, svcValue ServiceValue) (*loadbalancer.L3n4AddrID, *loadbalancer.LBBackEnd) {
var (
beIP net.IP
svcID loadbalancer.ID
bePort uint16
beWeight uint16
)
log.WithFields(logrus.Fields{
logfields.ServiceID: svcKey,
logfields.Object: logfields.Repr(svcValue),
}).Debug("converting ServiceKey and ServiceValue to frontend and backend")
if svcKey.IsIPv6() {
svc6Val := svcValue.(*Service6Value)
svcID = loadbalancer.ID(svc6Val.RevNat)
beIP = svc6Val.Address.IP()
bePort = svc6Val.Port
beWeight = svc6Val.Weight
} else {
svc4Val := svcValue.(*Service4Value)
svcID = loadbalancer.ID(svc4Val.RevNat)
beIP = svc4Val.Address.IP()
bePort = svc4Val.Port
beWeight = svc4Val.Weight
}
feL3n4Addr := serviceKey2L3n4Addr(svcKey)
beLBBackEnd := loadbalancer.NewLBBackEnd(0, loadbalancer.NONE, beIP, bePort, beWeight)
feL3n4AddrID := &loadbalancer.L3n4AddrID{
L3n4Addr: *feL3n4Addr,
ID: svcID,
}
return feL3n4AddrID, beLBBackEnd
} | go | func serviceKeynValue2FEnBE(svcKey ServiceKey, svcValue ServiceValue) (*loadbalancer.L3n4AddrID, *loadbalancer.LBBackEnd) {
var (
beIP net.IP
svcID loadbalancer.ID
bePort uint16
beWeight uint16
)
log.WithFields(logrus.Fields{
logfields.ServiceID: svcKey,
logfields.Object: logfields.Repr(svcValue),
}).Debug("converting ServiceKey and ServiceValue to frontend and backend")
if svcKey.IsIPv6() {
svc6Val := svcValue.(*Service6Value)
svcID = loadbalancer.ID(svc6Val.RevNat)
beIP = svc6Val.Address.IP()
bePort = svc6Val.Port
beWeight = svc6Val.Weight
} else {
svc4Val := svcValue.(*Service4Value)
svcID = loadbalancer.ID(svc4Val.RevNat)
beIP = svc4Val.Address.IP()
bePort = svc4Val.Port
beWeight = svc4Val.Weight
}
feL3n4Addr := serviceKey2L3n4Addr(svcKey)
beLBBackEnd := loadbalancer.NewLBBackEnd(0, loadbalancer.NONE, beIP, bePort, beWeight)
feL3n4AddrID := &loadbalancer.L3n4AddrID{
L3n4Addr: *feL3n4Addr,
ID: svcID,
}
return feL3n4AddrID, beLBBackEnd
} | [
"func",
"serviceKeynValue2FEnBE",
"(",
"svcKey",
"ServiceKey",
",",
"svcValue",
"ServiceValue",
")",
"(",
"*",
"loadbalancer",
".",
"L3n4AddrID",
",",
"*",
"loadbalancer",
".",
"LBBackEnd",
")",
"{",
"var",
"(",
"beIP",
"net",
".",
"IP",
"\n",
"svcID",
"loadbalancer",
".",
"ID",
"\n",
"bePort",
"uint16",
"\n",
"beWeight",
"uint16",
"\n",
")",
"\n\n",
"log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"ServiceID",
":",
"svcKey",
",",
"logfields",
".",
"Object",
":",
"logfields",
".",
"Repr",
"(",
"svcValue",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"svcKey",
".",
"IsIPv6",
"(",
")",
"{",
"svc6Val",
":=",
"svcValue",
".",
"(",
"*",
"Service6Value",
")",
"\n",
"svcID",
"=",
"loadbalancer",
".",
"ID",
"(",
"svc6Val",
".",
"RevNat",
")",
"\n",
"beIP",
"=",
"svc6Val",
".",
"Address",
".",
"IP",
"(",
")",
"\n",
"bePort",
"=",
"svc6Val",
".",
"Port",
"\n",
"beWeight",
"=",
"svc6Val",
".",
"Weight",
"\n",
"}",
"else",
"{",
"svc4Val",
":=",
"svcValue",
".",
"(",
"*",
"Service4Value",
")",
"\n",
"svcID",
"=",
"loadbalancer",
".",
"ID",
"(",
"svc4Val",
".",
"RevNat",
")",
"\n",
"beIP",
"=",
"svc4Val",
".",
"Address",
".",
"IP",
"(",
")",
"\n",
"bePort",
"=",
"svc4Val",
".",
"Port",
"\n",
"beWeight",
"=",
"svc4Val",
".",
"Weight",
"\n",
"}",
"\n\n",
"feL3n4Addr",
":=",
"serviceKey2L3n4Addr",
"(",
"svcKey",
")",
"\n",
"beLBBackEnd",
":=",
"loadbalancer",
".",
"NewLBBackEnd",
"(",
"0",
",",
"loadbalancer",
".",
"NONE",
",",
"beIP",
",",
"bePort",
",",
"beWeight",
")",
"\n\n",
"feL3n4AddrID",
":=",
"&",
"loadbalancer",
".",
"L3n4AddrID",
"{",
"L3n4Addr",
":",
"*",
"feL3n4Addr",
",",
"ID",
":",
"svcID",
",",
"}",
"\n\n",
"return",
"feL3n4AddrID",
",",
"beLBBackEnd",
"\n",
"}"
] | // serviceKeynValue2FEnBE converts the given svcKey and svcValue to a frontend in the
// form of L3n4AddrID and backend in the form of L3n4Addr. | [
"serviceKeynValue2FEnBE",
"converts",
"the",
"given",
"svcKey",
"and",
"svcValue",
"to",
"a",
"frontend",
"in",
"the",
"form",
"of",
"L3n4AddrID",
"and",
"backend",
"in",
"the",
"form",
"of",
"L3n4Addr",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lbmap/types.go#L346-L382 |
162,953 | cilium/cilium | pkg/maps/lbmap/types.go | revNat6Value2L3n4Addr | func revNat6Value2L3n4Addr(revNATV *RevNat6Value) *loadbalancer.L3n4Addr {
return loadbalancer.NewL3n4Addr(loadbalancer.NONE, revNATV.Address.IP(), revNATV.Port)
} | go | func revNat6Value2L3n4Addr(revNATV *RevNat6Value) *loadbalancer.L3n4Addr {
return loadbalancer.NewL3n4Addr(loadbalancer.NONE, revNATV.Address.IP(), revNATV.Port)
} | [
"func",
"revNat6Value2L3n4Addr",
"(",
"revNATV",
"*",
"RevNat6Value",
")",
"*",
"loadbalancer",
".",
"L3n4Addr",
"{",
"return",
"loadbalancer",
".",
"NewL3n4Addr",
"(",
"loadbalancer",
".",
"NONE",
",",
"revNATV",
".",
"Address",
".",
"IP",
"(",
")",
",",
"revNATV",
".",
"Port",
")",
"\n",
"}"
] | // RevNat6Value2L3n4Addr converts the given RevNat6Value to a L3n4Addr. | [
"RevNat6Value2L3n4Addr",
"converts",
"the",
"given",
"RevNat6Value",
"to",
"a",
"L3n4Addr",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lbmap/types.go#L402-L404 |
162,954 | cilium/cilium | pkg/maps/lbmap/types.go | revNat4Value2L3n4Addr | func revNat4Value2L3n4Addr(revNATV *RevNat4Value) *loadbalancer.L3n4Addr {
return loadbalancer.NewL3n4Addr(loadbalancer.NONE, revNATV.Address.IP(), revNATV.Port)
} | go | func revNat4Value2L3n4Addr(revNATV *RevNat4Value) *loadbalancer.L3n4Addr {
return loadbalancer.NewL3n4Addr(loadbalancer.NONE, revNATV.Address.IP(), revNATV.Port)
} | [
"func",
"revNat4Value2L3n4Addr",
"(",
"revNATV",
"*",
"RevNat4Value",
")",
"*",
"loadbalancer",
".",
"L3n4Addr",
"{",
"return",
"loadbalancer",
".",
"NewL3n4Addr",
"(",
"loadbalancer",
".",
"NONE",
",",
"revNATV",
".",
"Address",
".",
"IP",
"(",
")",
",",
"revNATV",
".",
"Port",
")",
"\n",
"}"
] | // revNat4Value2L3n4Addr converts the given RevNat4Value to a L3n4Addr. | [
"revNat4Value2L3n4Addr",
"converts",
"the",
"given",
"RevNat4Value",
"to",
"a",
"L3n4Addr",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lbmap/types.go#L407-L409 |
162,955 | cilium/cilium | pkg/maps/lbmap/types.go | revNatValue2L3n4AddrID | func revNatValue2L3n4AddrID(revNATKey RevNatKey, revNATValue RevNatValue) *loadbalancer.L3n4AddrID {
var (
svcID loadbalancer.ID
be *loadbalancer.L3n4Addr
)
if revNATKey.IsIPv6() {
revNat6Key := revNATKey.(*RevNat6Key)
svcID = loadbalancer.ID(revNat6Key.Key)
revNat6Value := revNATValue.(*RevNat6Value)
be = revNat6Value2L3n4Addr(revNat6Value)
} else {
revNat4Key := revNATKey.(*RevNat4Key)
svcID = loadbalancer.ID(revNat4Key.Key)
revNat4Value := revNATValue.(*RevNat4Value)
be = revNat4Value2L3n4Addr(revNat4Value)
}
return &loadbalancer.L3n4AddrID{L3n4Addr: *be, ID: svcID}
} | go | func revNatValue2L3n4AddrID(revNATKey RevNatKey, revNATValue RevNatValue) *loadbalancer.L3n4AddrID {
var (
svcID loadbalancer.ID
be *loadbalancer.L3n4Addr
)
if revNATKey.IsIPv6() {
revNat6Key := revNATKey.(*RevNat6Key)
svcID = loadbalancer.ID(revNat6Key.Key)
revNat6Value := revNATValue.(*RevNat6Value)
be = revNat6Value2L3n4Addr(revNat6Value)
} else {
revNat4Key := revNATKey.(*RevNat4Key)
svcID = loadbalancer.ID(revNat4Key.Key)
revNat4Value := revNATValue.(*RevNat4Value)
be = revNat4Value2L3n4Addr(revNat4Value)
}
return &loadbalancer.L3n4AddrID{L3n4Addr: *be, ID: svcID}
} | [
"func",
"revNatValue2L3n4AddrID",
"(",
"revNATKey",
"RevNatKey",
",",
"revNATValue",
"RevNatValue",
")",
"*",
"loadbalancer",
".",
"L3n4AddrID",
"{",
"var",
"(",
"svcID",
"loadbalancer",
".",
"ID",
"\n",
"be",
"*",
"loadbalancer",
".",
"L3n4Addr",
"\n",
")",
"\n",
"if",
"revNATKey",
".",
"IsIPv6",
"(",
")",
"{",
"revNat6Key",
":=",
"revNATKey",
".",
"(",
"*",
"RevNat6Key",
")",
"\n",
"svcID",
"=",
"loadbalancer",
".",
"ID",
"(",
"revNat6Key",
".",
"Key",
")",
"\n\n",
"revNat6Value",
":=",
"revNATValue",
".",
"(",
"*",
"RevNat6Value",
")",
"\n",
"be",
"=",
"revNat6Value2L3n4Addr",
"(",
"revNat6Value",
")",
"\n",
"}",
"else",
"{",
"revNat4Key",
":=",
"revNATKey",
".",
"(",
"*",
"RevNat4Key",
")",
"\n",
"svcID",
"=",
"loadbalancer",
".",
"ID",
"(",
"revNat4Key",
".",
"Key",
")",
"\n\n",
"revNat4Value",
":=",
"revNATValue",
".",
"(",
"*",
"RevNat4Value",
")",
"\n",
"be",
"=",
"revNat4Value2L3n4Addr",
"(",
"revNat4Value",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"loadbalancer",
".",
"L3n4AddrID",
"{",
"L3n4Addr",
":",
"*",
"be",
",",
"ID",
":",
"svcID",
"}",
"\n",
"}"
] | // revNatValue2L3n4AddrID converts the given RevNatKey and RevNatValue to a L3n4AddrID. | [
"revNatValue2L3n4AddrID",
"converts",
"the",
"given",
"RevNatKey",
"and",
"RevNatValue",
"to",
"a",
"L3n4AddrID",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lbmap/types.go#L412-L432 |
162,956 | cilium/cilium | pkg/maps/lbmap/types.go | LBSVC2ServiceKeynValuenBackendV2 | func LBSVC2ServiceKeynValuenBackendV2(svc *loadbalancer.LBSVC) (ServiceKeyV2, []ServiceValueV2, []Backend, error) {
log.WithFields(logrus.Fields{
"lbFrontend": svc.FE.String(),
"lbBackend": svc.BES,
}).Debug("converting Cilium load-balancer service (frontend -> backend(s)) into BPF service v2")
svcKey := l3n4Addr2ServiceKeyV2(svc.FE)
backends := []Backend{}
svcValues := []ServiceValueV2{}
for _, be := range svc.BES {
svcValue := svcKey.NewValue().(ServiceValueV2)
backend, err := lbBackEnd2Backend(be)
if err != nil {
return nil, nil, nil, err
}
svcValue.SetRevNat(int(svc.FE.ID))
svcValue.SetWeight(be.Weight)
svcValue.SetBackendID(loadbalancer.BackendID(be.ID))
backends = append(backends, backend)
svcValues = append(svcValues, svcValue)
log.WithFields(logrus.Fields{
"lbFrontend": svcKey,
"lbBackend": svcValue,
}).Debug("associating frontend -> backend")
}
log.WithFields(logrus.Fields{
"lbFrontend": svc.FE.String(),
"lbBackend": svc.BES,
logfields.ServiceID: svcKey,
logfields.Object: logfields.Repr(svcValues),
}).Debug("converted LBSVC (frontend -> backend(s)), to ServiceKeyV2, ServiceValueV2 and Backend")
return svcKey, svcValues, backends, nil
} | go | func LBSVC2ServiceKeynValuenBackendV2(svc *loadbalancer.LBSVC) (ServiceKeyV2, []ServiceValueV2, []Backend, error) {
log.WithFields(logrus.Fields{
"lbFrontend": svc.FE.String(),
"lbBackend": svc.BES,
}).Debug("converting Cilium load-balancer service (frontend -> backend(s)) into BPF service v2")
svcKey := l3n4Addr2ServiceKeyV2(svc.FE)
backends := []Backend{}
svcValues := []ServiceValueV2{}
for _, be := range svc.BES {
svcValue := svcKey.NewValue().(ServiceValueV2)
backend, err := lbBackEnd2Backend(be)
if err != nil {
return nil, nil, nil, err
}
svcValue.SetRevNat(int(svc.FE.ID))
svcValue.SetWeight(be.Weight)
svcValue.SetBackendID(loadbalancer.BackendID(be.ID))
backends = append(backends, backend)
svcValues = append(svcValues, svcValue)
log.WithFields(logrus.Fields{
"lbFrontend": svcKey,
"lbBackend": svcValue,
}).Debug("associating frontend -> backend")
}
log.WithFields(logrus.Fields{
"lbFrontend": svc.FE.String(),
"lbBackend": svc.BES,
logfields.ServiceID: svcKey,
logfields.Object: logfields.Repr(svcValues),
}).Debug("converted LBSVC (frontend -> backend(s)), to ServiceKeyV2, ServiceValueV2 and Backend")
return svcKey, svcValues, backends, nil
} | [
"func",
"LBSVC2ServiceKeynValuenBackendV2",
"(",
"svc",
"*",
"loadbalancer",
".",
"LBSVC",
")",
"(",
"ServiceKeyV2",
",",
"[",
"]",
"ServiceValueV2",
",",
"[",
"]",
"Backend",
",",
"error",
")",
"{",
"log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"svc",
".",
"FE",
".",
"String",
"(",
")",
",",
"\"",
"\"",
":",
"svc",
".",
"BES",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"svcKey",
":=",
"l3n4Addr2ServiceKeyV2",
"(",
"svc",
".",
"FE",
")",
"\n\n",
"backends",
":=",
"[",
"]",
"Backend",
"{",
"}",
"\n",
"svcValues",
":=",
"[",
"]",
"ServiceValueV2",
"{",
"}",
"\n",
"for",
"_",
",",
"be",
":=",
"range",
"svc",
".",
"BES",
"{",
"svcValue",
":=",
"svcKey",
".",
"NewValue",
"(",
")",
".",
"(",
"ServiceValueV2",
")",
"\n",
"backend",
",",
"err",
":=",
"lbBackEnd2Backend",
"(",
"be",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"svcValue",
".",
"SetRevNat",
"(",
"int",
"(",
"svc",
".",
"FE",
".",
"ID",
")",
")",
"\n",
"svcValue",
".",
"SetWeight",
"(",
"be",
".",
"Weight",
")",
"\n",
"svcValue",
".",
"SetBackendID",
"(",
"loadbalancer",
".",
"BackendID",
"(",
"be",
".",
"ID",
")",
")",
"\n\n",
"backends",
"=",
"append",
"(",
"backends",
",",
"backend",
")",
"\n",
"svcValues",
"=",
"append",
"(",
"svcValues",
",",
"svcValue",
")",
"\n",
"log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"svcKey",
",",
"\"",
"\"",
":",
"svcValue",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"log",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"svc",
".",
"FE",
".",
"String",
"(",
")",
",",
"\"",
"\"",
":",
"svc",
".",
"BES",
",",
"logfields",
".",
"ServiceID",
":",
"svcKey",
",",
"logfields",
".",
"Object",
":",
"logfields",
".",
"Repr",
"(",
"svcValues",
")",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"svcKey",
",",
"svcValues",
",",
"backends",
",",
"nil",
"\n",
"}"
] | // LBSVC2ServiceKeynValuenBackendValueV2 transforms the SVC Cilium type into a bpf SVC v2 type. | [
"LBSVC2ServiceKeynValuenBackendValueV2",
"transforms",
"the",
"SVC",
"Cilium",
"type",
"into",
"a",
"bpf",
"SVC",
"v2",
"type",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lbmap/types.go#L435-L469 |
162,957 | cilium/cilium | pkg/policy/l3.go | GetDefaultPrefixLengths | func GetDefaultPrefixLengths() (s6 []int, s4 []int) {
// These *must* be in the order of longest prefix to shortest, as the
// LPM implementation on older kernels depends on this ordering.
s6 = []int{net.IPv6len * 8, 0}
s4 = []int{net.IPv4len * 8, 0}
return
} | go | func GetDefaultPrefixLengths() (s6 []int, s4 []int) {
// These *must* be in the order of longest prefix to shortest, as the
// LPM implementation on older kernels depends on this ordering.
s6 = []int{net.IPv6len * 8, 0}
s4 = []int{net.IPv4len * 8, 0}
return
} | [
"func",
"GetDefaultPrefixLengths",
"(",
")",
"(",
"s6",
"[",
"]",
"int",
",",
"s4",
"[",
"]",
"int",
")",
"{",
"// These *must* be in the order of longest prefix to shortest, as the",
"// LPM implementation on older kernels depends on this ordering.",
"s6",
"=",
"[",
"]",
"int",
"{",
"net",
".",
"IPv6len",
"*",
"8",
",",
"0",
"}",
"\n",
"s4",
"=",
"[",
"]",
"int",
"{",
"net",
".",
"IPv4len",
"*",
"8",
",",
"0",
"}",
"\n",
"return",
"\n",
"}"
] | // GetDefaultPrefixLengths returns the set of prefix lengths for handling
// CIDRs that are unconditionally mapped to identities, ie for the reserved
// identities 'host', 'world'. | [
"GetDefaultPrefixLengths",
"returns",
"the",
"set",
"of",
"prefix",
"lengths",
"for",
"handling",
"CIDRs",
"that",
"are",
"unconditionally",
"mapped",
"to",
"identities",
"ie",
"for",
"the",
"reserved",
"identities",
"host",
"world",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/l3.go#L50-L56 |
162,958 | cilium/cilium | pkg/policy/l3.go | Insert | func (m *CIDRPolicyMap) Insert(cidr string, ruleLabels labels.LabelArray) int {
_, ipnet, err := net.ParseCIDR(cidr)
if err != nil {
var mask net.IPMask
ip := net.ParseIP(cidr)
// Use default CIDR mask for the address if the bits in the address
// after the mask are all zeroes.
ip4 := ip.To4()
if ip4 == nil {
mask = net.CIDRMask(128, 128)
} else { // IPv4
ip = ip4
mask = ip.DefaultMask() // IP address class based mask (/8, /16, or /24)
if !ip.Equal(ip.Mask(mask)) {
// IPv4 with non-zeroes after the subnetwork, use full mask.
mask = net.CIDRMask(32, 32)
}
}
ipnet = &net.IPNet{IP: ip, Mask: mask}
}
ones, _ := ipnet.Mask.Size()
key := ipnet.IP.String() + "/" + strconv.Itoa(ones)
if _, found := m.Map[key]; !found {
m.Map[key] = &CIDRPolicyMapRule{Prefix: *ipnet, DerivedFromRules: labels.LabelArrayList{ruleLabels}}
if ipnet.IP.To4() == nil {
m.IPv6PrefixCount[ones]++
} else {
m.IPv4PrefixCount[ones]++
}
return 1
} else {
m.Map[key].DerivedFromRules = append(m.Map[key].DerivedFromRules, ruleLabels)
}
return 0
} | go | func (m *CIDRPolicyMap) Insert(cidr string, ruleLabels labels.LabelArray) int {
_, ipnet, err := net.ParseCIDR(cidr)
if err != nil {
var mask net.IPMask
ip := net.ParseIP(cidr)
// Use default CIDR mask for the address if the bits in the address
// after the mask are all zeroes.
ip4 := ip.To4()
if ip4 == nil {
mask = net.CIDRMask(128, 128)
} else { // IPv4
ip = ip4
mask = ip.DefaultMask() // IP address class based mask (/8, /16, or /24)
if !ip.Equal(ip.Mask(mask)) {
// IPv4 with non-zeroes after the subnetwork, use full mask.
mask = net.CIDRMask(32, 32)
}
}
ipnet = &net.IPNet{IP: ip, Mask: mask}
}
ones, _ := ipnet.Mask.Size()
key := ipnet.IP.String() + "/" + strconv.Itoa(ones)
if _, found := m.Map[key]; !found {
m.Map[key] = &CIDRPolicyMapRule{Prefix: *ipnet, DerivedFromRules: labels.LabelArrayList{ruleLabels}}
if ipnet.IP.To4() == nil {
m.IPv6PrefixCount[ones]++
} else {
m.IPv4PrefixCount[ones]++
}
return 1
} else {
m.Map[key].DerivedFromRules = append(m.Map[key].DerivedFromRules, ruleLabels)
}
return 0
} | [
"func",
"(",
"m",
"*",
"CIDRPolicyMap",
")",
"Insert",
"(",
"cidr",
"string",
",",
"ruleLabels",
"labels",
".",
"LabelArray",
")",
"int",
"{",
"_",
",",
"ipnet",
",",
"err",
":=",
"net",
".",
"ParseCIDR",
"(",
"cidr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"var",
"mask",
"net",
".",
"IPMask",
"\n",
"ip",
":=",
"net",
".",
"ParseIP",
"(",
"cidr",
")",
"\n",
"// Use default CIDR mask for the address if the bits in the address",
"// after the mask are all zeroes.",
"ip4",
":=",
"ip",
".",
"To4",
"(",
")",
"\n",
"if",
"ip4",
"==",
"nil",
"{",
"mask",
"=",
"net",
".",
"CIDRMask",
"(",
"128",
",",
"128",
")",
"\n",
"}",
"else",
"{",
"// IPv4",
"ip",
"=",
"ip4",
"\n",
"mask",
"=",
"ip",
".",
"DefaultMask",
"(",
")",
"// IP address class based mask (/8, /16, or /24)",
"\n",
"if",
"!",
"ip",
".",
"Equal",
"(",
"ip",
".",
"Mask",
"(",
"mask",
")",
")",
"{",
"// IPv4 with non-zeroes after the subnetwork, use full mask.",
"mask",
"=",
"net",
".",
"CIDRMask",
"(",
"32",
",",
"32",
")",
"\n",
"}",
"\n",
"}",
"\n",
"ipnet",
"=",
"&",
"net",
".",
"IPNet",
"{",
"IP",
":",
"ip",
",",
"Mask",
":",
"mask",
"}",
"\n",
"}",
"\n\n",
"ones",
",",
"_",
":=",
"ipnet",
".",
"Mask",
".",
"Size",
"(",
")",
"\n\n",
"key",
":=",
"ipnet",
".",
"IP",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
"ones",
")",
"\n",
"if",
"_",
",",
"found",
":=",
"m",
".",
"Map",
"[",
"key",
"]",
";",
"!",
"found",
"{",
"m",
".",
"Map",
"[",
"key",
"]",
"=",
"&",
"CIDRPolicyMapRule",
"{",
"Prefix",
":",
"*",
"ipnet",
",",
"DerivedFromRules",
":",
"labels",
".",
"LabelArrayList",
"{",
"ruleLabels",
"}",
"}",
"\n",
"if",
"ipnet",
".",
"IP",
".",
"To4",
"(",
")",
"==",
"nil",
"{",
"m",
".",
"IPv6PrefixCount",
"[",
"ones",
"]",
"++",
"\n",
"}",
"else",
"{",
"m",
".",
"IPv4PrefixCount",
"[",
"ones",
"]",
"++",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"}",
"else",
"{",
"m",
".",
"Map",
"[",
"key",
"]",
".",
"DerivedFromRules",
"=",
"append",
"(",
"m",
".",
"Map",
"[",
"key",
"]",
".",
"DerivedFromRules",
",",
"ruleLabels",
")",
"\n",
"}",
"\n\n",
"return",
"0",
"\n",
"}"
] | // Insert places 'cidr' and its corresponding rule labels into map 'm'. Returns
// `1` if `cidr` is added to the map, `0` otherwise. | [
"Insert",
"places",
"cidr",
"and",
"its",
"corresponding",
"rule",
"labels",
"into",
"map",
"m",
".",
"Returns",
"1",
"if",
"cidr",
"is",
"added",
"to",
"the",
"map",
"0",
"otherwise",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/l3.go#L60-L97 |
162,959 | cilium/cilium | pkg/policy/l3.go | NewCIDRPolicy | func NewCIDRPolicy() (policy *CIDRPolicy) {
policy = &CIDRPolicy{
Ingress: CIDRPolicyMap{
Map: make(map[string]*CIDRPolicyMapRule),
IPv6PrefixCount: make(map[int]int),
IPv4PrefixCount: make(map[int]int),
},
Egress: CIDRPolicyMap{
Map: make(map[string]*CIDRPolicyMapRule),
IPv6PrefixCount: make(map[int]int),
IPv4PrefixCount: make(map[int]int),
},
}
// Add a default reference to the default {host, cluster, world} prefix
// to ensure that ToBPFData() always serializes these lengths for LPM.
s6, s4 := GetDefaultPrefixLengths()
for _, i := range s6 {
policy.Egress.IPv6PrefixCount[i] = 0
policy.Ingress.IPv6PrefixCount[i] = 0
}
for _, i := range s4 {
policy.Egress.IPv4PrefixCount[i] = 0
policy.Ingress.IPv4PrefixCount[i] = 0
}
return
} | go | func NewCIDRPolicy() (policy *CIDRPolicy) {
policy = &CIDRPolicy{
Ingress: CIDRPolicyMap{
Map: make(map[string]*CIDRPolicyMapRule),
IPv6PrefixCount: make(map[int]int),
IPv4PrefixCount: make(map[int]int),
},
Egress: CIDRPolicyMap{
Map: make(map[string]*CIDRPolicyMapRule),
IPv6PrefixCount: make(map[int]int),
IPv4PrefixCount: make(map[int]int),
},
}
// Add a default reference to the default {host, cluster, world} prefix
// to ensure that ToBPFData() always serializes these lengths for LPM.
s6, s4 := GetDefaultPrefixLengths()
for _, i := range s6 {
policy.Egress.IPv6PrefixCount[i] = 0
policy.Ingress.IPv6PrefixCount[i] = 0
}
for _, i := range s4 {
policy.Egress.IPv4PrefixCount[i] = 0
policy.Ingress.IPv4PrefixCount[i] = 0
}
return
} | [
"func",
"NewCIDRPolicy",
"(",
")",
"(",
"policy",
"*",
"CIDRPolicy",
")",
"{",
"policy",
"=",
"&",
"CIDRPolicy",
"{",
"Ingress",
":",
"CIDRPolicyMap",
"{",
"Map",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"CIDRPolicyMapRule",
")",
",",
"IPv6PrefixCount",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"int",
")",
",",
"IPv4PrefixCount",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"int",
")",
",",
"}",
",",
"Egress",
":",
"CIDRPolicyMap",
"{",
"Map",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"CIDRPolicyMapRule",
")",
",",
"IPv6PrefixCount",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"int",
")",
",",
"IPv4PrefixCount",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"int",
")",
",",
"}",
",",
"}",
"\n",
"// Add a default reference to the default {host, cluster, world} prefix",
"// to ensure that ToBPFData() always serializes these lengths for LPM.",
"s6",
",",
"s4",
":=",
"GetDefaultPrefixLengths",
"(",
")",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"s6",
"{",
"policy",
".",
"Egress",
".",
"IPv6PrefixCount",
"[",
"i",
"]",
"=",
"0",
"\n",
"policy",
".",
"Ingress",
".",
"IPv6PrefixCount",
"[",
"i",
"]",
"=",
"0",
"\n",
"}",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"s4",
"{",
"policy",
".",
"Egress",
".",
"IPv4PrefixCount",
"[",
"i",
"]",
"=",
"0",
"\n",
"policy",
".",
"Ingress",
".",
"IPv4PrefixCount",
"[",
"i",
"]",
"=",
"0",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // NewCIDRPolicy creates a new CIDRPolicy. | [
"NewCIDRPolicy",
"creates",
"a",
"new",
"CIDRPolicy",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/l3.go#L111-L136 |
162,960 | cilium/cilium | pkg/policy/l3.go | GetModel | func (cp *CIDRPolicy) GetModel() *models.CIDRPolicy {
if cp == nil {
return nil
}
ingress := []*models.PolicyRule{}
for _, v := range cp.Ingress.Map {
ingress = append(ingress, &models.PolicyRule{
Rule: v.Prefix.String(),
DerivedFromRules: v.DerivedFromRules.GetModel(),
})
}
egress := []*models.PolicyRule{}
for _, v := range cp.Egress.Map {
egress = append(egress, &models.PolicyRule{
Rule: v.Prefix.String(),
DerivedFromRules: v.DerivedFromRules.GetModel(),
})
}
return &models.CIDRPolicy{
Ingress: ingress,
Egress: egress,
}
} | go | func (cp *CIDRPolicy) GetModel() *models.CIDRPolicy {
if cp == nil {
return nil
}
ingress := []*models.PolicyRule{}
for _, v := range cp.Ingress.Map {
ingress = append(ingress, &models.PolicyRule{
Rule: v.Prefix.String(),
DerivedFromRules: v.DerivedFromRules.GetModel(),
})
}
egress := []*models.PolicyRule{}
for _, v := range cp.Egress.Map {
egress = append(egress, &models.PolicyRule{
Rule: v.Prefix.String(),
DerivedFromRules: v.DerivedFromRules.GetModel(),
})
}
return &models.CIDRPolicy{
Ingress: ingress,
Egress: egress,
}
} | [
"func",
"(",
"cp",
"*",
"CIDRPolicy",
")",
"GetModel",
"(",
")",
"*",
"models",
".",
"CIDRPolicy",
"{",
"if",
"cp",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"ingress",
":=",
"[",
"]",
"*",
"models",
".",
"PolicyRule",
"{",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"cp",
".",
"Ingress",
".",
"Map",
"{",
"ingress",
"=",
"append",
"(",
"ingress",
",",
"&",
"models",
".",
"PolicyRule",
"{",
"Rule",
":",
"v",
".",
"Prefix",
".",
"String",
"(",
")",
",",
"DerivedFromRules",
":",
"v",
".",
"DerivedFromRules",
".",
"GetModel",
"(",
")",
",",
"}",
")",
"\n",
"}",
"\n\n",
"egress",
":=",
"[",
"]",
"*",
"models",
".",
"PolicyRule",
"{",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"cp",
".",
"Egress",
".",
"Map",
"{",
"egress",
"=",
"append",
"(",
"egress",
",",
"&",
"models",
".",
"PolicyRule",
"{",
"Rule",
":",
"v",
".",
"Prefix",
".",
"String",
"(",
")",
",",
"DerivedFromRules",
":",
"v",
".",
"DerivedFromRules",
".",
"GetModel",
"(",
")",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"models",
".",
"CIDRPolicy",
"{",
"Ingress",
":",
"ingress",
",",
"Egress",
":",
"egress",
",",
"}",
"\n",
"}"
] | // GetModel returns the API model representation of the CIDRPolicy. | [
"GetModel",
"returns",
"the",
"API",
"model",
"representation",
"of",
"the",
"CIDRPolicy",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/l3.go#L172-L197 |
162,961 | cilium/cilium | pkg/policy/l3.go | Validate | func (cp *CIDRPolicy) Validate() error {
if cp == nil {
return nil
}
if l := len(cp.Ingress.IPv6PrefixCount); l > api.MaxCIDRPrefixLengths {
return fmt.Errorf("too many ingress CIDR prefix lengths %d/%d", l, api.MaxCIDRPrefixLengths)
}
return nil
} | go | func (cp *CIDRPolicy) Validate() error {
if cp == nil {
return nil
}
if l := len(cp.Ingress.IPv6PrefixCount); l > api.MaxCIDRPrefixLengths {
return fmt.Errorf("too many ingress CIDR prefix lengths %d/%d", l, api.MaxCIDRPrefixLengths)
}
return nil
} | [
"func",
"(",
"cp",
"*",
"CIDRPolicy",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"cp",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"l",
":=",
"len",
"(",
"cp",
".",
"Ingress",
".",
"IPv6PrefixCount",
")",
";",
"l",
">",
"api",
".",
"MaxCIDRPrefixLengths",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"l",
",",
"api",
".",
"MaxCIDRPrefixLengths",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate returns error if the CIDR policy might lead to code generation failure | [
"Validate",
"returns",
"error",
"if",
"the",
"CIDR",
"policy",
"might",
"lead",
"to",
"code",
"generation",
"failure"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/l3.go#L200-L208 |
162,962 | cilium/cilium | api/v1/server/restapi/policy/delete_policy_responses.go | WithPayload | func (o *DeletePolicyOK) WithPayload(payload *models.Policy) *DeletePolicyOK {
o.Payload = payload
return o
} | go | func (o *DeletePolicyOK) WithPayload(payload *models.Policy) *DeletePolicyOK {
o.Payload = payload
return o
} | [
"func",
"(",
"o",
"*",
"DeletePolicyOK",
")",
"WithPayload",
"(",
"payload",
"*",
"models",
".",
"Policy",
")",
"*",
"DeletePolicyOK",
"{",
"o",
".",
"Payload",
"=",
"payload",
"\n",
"return",
"o",
"\n",
"}"
] | // WithPayload adds the payload to the delete policy o k response | [
"WithPayload",
"adds",
"the",
"payload",
"to",
"the",
"delete",
"policy",
"o",
"k",
"response"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/policy/delete_policy_responses.go#L38-L41 |
162,963 | cilium/cilium | api/v1/server/restapi/policy/delete_policy_responses.go | WithPayload | func (o *DeletePolicyInvalid) WithPayload(payload models.Error) *DeletePolicyInvalid {
o.Payload = payload
return o
} | go | func (o *DeletePolicyInvalid) WithPayload(payload models.Error) *DeletePolicyInvalid {
o.Payload = payload
return o
} | [
"func",
"(",
"o",
"*",
"DeletePolicyInvalid",
")",
"WithPayload",
"(",
"payload",
"models",
".",
"Error",
")",
"*",
"DeletePolicyInvalid",
"{",
"o",
".",
"Payload",
"=",
"payload",
"\n",
"return",
"o",
"\n",
"}"
] | // WithPayload adds the payload to the delete policy invalid response | [
"WithPayload",
"adds",
"the",
"payload",
"to",
"the",
"delete",
"policy",
"invalid",
"response"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/policy/delete_policy_responses.go#L82-L85 |
162,964 | cilium/cilium | api/v1/server/restapi/policy/delete_policy_responses.go | WithPayload | func (o *DeletePolicyFailure) WithPayload(payload models.Error) *DeletePolicyFailure {
o.Payload = payload
return o
} | go | func (o *DeletePolicyFailure) WithPayload(payload models.Error) *DeletePolicyFailure {
o.Payload = payload
return o
} | [
"func",
"(",
"o",
"*",
"DeletePolicyFailure",
")",
"WithPayload",
"(",
"payload",
"models",
".",
"Error",
")",
"*",
"DeletePolicyFailure",
"{",
"o",
".",
"Payload",
"=",
"payload",
"\n",
"return",
"o",
"\n",
"}"
] | // WithPayload adds the payload to the delete policy failure response | [
"WithPayload",
"adds",
"the",
"payload",
"to",
"the",
"delete",
"policy",
"failure",
"response"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/policy/delete_policy_responses.go#L148-L151 |
162,965 | cilium/cilium | pkg/maps/lxcmap/lxcmap.go | String | func (v *EndpointInfo) String() string {
if v.Flags&EndpointFlagHost != 0 {
return fmt.Sprintf("(localhost)")
}
return fmt.Sprintf("id=%-5d flags=0x%04X ifindex=%-3d mac=%s nodemac=%s",
v.LxcID,
v.Flags,
v.IfIndex,
v.MAC,
v.NodeMAC,
)
} | go | func (v *EndpointInfo) String() string {
if v.Flags&EndpointFlagHost != 0 {
return fmt.Sprintf("(localhost)")
}
return fmt.Sprintf("id=%-5d flags=0x%04X ifindex=%-3d mac=%s nodemac=%s",
v.LxcID,
v.Flags,
v.IfIndex,
v.MAC,
v.NodeMAC,
)
} | [
"func",
"(",
"v",
"*",
"EndpointInfo",
")",
"String",
"(",
")",
"string",
"{",
"if",
"v",
".",
"Flags",
"&",
"EndpointFlagHost",
"!=",
"0",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"v",
".",
"LxcID",
",",
"v",
".",
"Flags",
",",
"v",
".",
"IfIndex",
",",
"v",
".",
"MAC",
",",
"v",
".",
"NodeMAC",
",",
")",
"\n",
"}"
] | // String returns the human readable representation of an EndpointInfo | [
"String",
"returns",
"the",
"human",
"readable",
"representation",
"of",
"an",
"EndpointInfo"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lxcmap/lxcmap.go#L141-L153 |
162,966 | cilium/cilium | pkg/maps/lxcmap/lxcmap.go | WriteEndpoint | func WriteEndpoint(f EndpointFrontend) error {
info, err := f.GetBPFValue()
if err != nil {
return err
}
// FIXME: Revert on failure
for _, v := range f.GetBPFKeys() {
if err := LXCMap.Update(v, info); err != nil {
return err
}
}
return nil
} | go | func WriteEndpoint(f EndpointFrontend) error {
info, err := f.GetBPFValue()
if err != nil {
return err
}
// FIXME: Revert on failure
for _, v := range f.GetBPFKeys() {
if err := LXCMap.Update(v, info); err != nil {
return err
}
}
return nil
} | [
"func",
"WriteEndpoint",
"(",
"f",
"EndpointFrontend",
")",
"error",
"{",
"info",
",",
"err",
":=",
"f",
".",
"GetBPFValue",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// FIXME: Revert on failure",
"for",
"_",
",",
"v",
":=",
"range",
"f",
".",
"GetBPFKeys",
"(",
")",
"{",
"if",
"err",
":=",
"LXCMap",
".",
"Update",
"(",
"v",
",",
"info",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // WriteEndpoint updates the BPF map with the endpoint information and links
// the endpoint information to all keys provided. | [
"WriteEndpoint",
"updates",
"the",
"BPF",
"map",
"with",
"the",
"endpoint",
"information",
"and",
"links",
"the",
"endpoint",
"information",
"to",
"all",
"keys",
"provided",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lxcmap/lxcmap.go#L157-L171 |
162,967 | cilium/cilium | pkg/maps/lxcmap/lxcmap.go | AddHostEntry | func AddHostEntry(ip net.IP) error {
key := NewEndpointKey(ip)
ep := &EndpointInfo{Flags: EndpointFlagHost}
return LXCMap.Update(key, ep)
} | go | func AddHostEntry(ip net.IP) error {
key := NewEndpointKey(ip)
ep := &EndpointInfo{Flags: EndpointFlagHost}
return LXCMap.Update(key, ep)
} | [
"func",
"AddHostEntry",
"(",
"ip",
"net",
".",
"IP",
")",
"error",
"{",
"key",
":=",
"NewEndpointKey",
"(",
"ip",
")",
"\n",
"ep",
":=",
"&",
"EndpointInfo",
"{",
"Flags",
":",
"EndpointFlagHost",
"}",
"\n",
"return",
"LXCMap",
".",
"Update",
"(",
"key",
",",
"ep",
")",
"\n",
"}"
] | // AddHostEntry adds a special endpoint which represents the local host | [
"AddHostEntry",
"adds",
"a",
"special",
"endpoint",
"which",
"represents",
"the",
"local",
"host"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lxcmap/lxcmap.go#L174-L178 |
162,968 | cilium/cilium | pkg/maps/lxcmap/lxcmap.go | SyncHostEntry | func SyncHostEntry(ip net.IP) (bool, error) {
key := NewEndpointKey(ip)
value, err := LXCMap.Lookup(key)
if err != nil || value.(*EndpointInfo).Flags&EndpointFlagHost == 0 {
err = AddHostEntry(ip)
if err == nil {
return true, nil
}
}
return false, err
} | go | func SyncHostEntry(ip net.IP) (bool, error) {
key := NewEndpointKey(ip)
value, err := LXCMap.Lookup(key)
if err != nil || value.(*EndpointInfo).Flags&EndpointFlagHost == 0 {
err = AddHostEntry(ip)
if err == nil {
return true, nil
}
}
return false, err
} | [
"func",
"SyncHostEntry",
"(",
"ip",
"net",
".",
"IP",
")",
"(",
"bool",
",",
"error",
")",
"{",
"key",
":=",
"NewEndpointKey",
"(",
"ip",
")",
"\n",
"value",
",",
"err",
":=",
"LXCMap",
".",
"Lookup",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"value",
".",
"(",
"*",
"EndpointInfo",
")",
".",
"Flags",
"&",
"EndpointFlagHost",
"==",
"0",
"{",
"err",
"=",
"AddHostEntry",
"(",
"ip",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
",",
"err",
"\n",
"}"
] | // SyncHostEntry checks if a host entry exists in the lxcmap and adds one if needed.
// Returns boolean indicating if a new entry was added and an error. | [
"SyncHostEntry",
"checks",
"if",
"a",
"host",
"entry",
"exists",
"in",
"the",
"lxcmap",
"and",
"adds",
"one",
"if",
"needed",
".",
"Returns",
"boolean",
"indicating",
"if",
"a",
"new",
"entry",
"was",
"added",
"and",
"an",
"error",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lxcmap/lxcmap.go#L182-L192 |
162,969 | cilium/cilium | pkg/maps/lxcmap/lxcmap.go | DeleteElement | func DeleteElement(f EndpointFrontend) []error {
var errors []error
for _, k := range f.GetBPFKeys() {
if err := LXCMap.Delete(k); err != nil {
errors = append(errors, fmt.Errorf("Unable to delete key %v from %s: %s", k, bpf.MapPath(MapName), err))
}
}
return errors
} | go | func DeleteElement(f EndpointFrontend) []error {
var errors []error
for _, k := range f.GetBPFKeys() {
if err := LXCMap.Delete(k); err != nil {
errors = append(errors, fmt.Errorf("Unable to delete key %v from %s: %s", k, bpf.MapPath(MapName), err))
}
}
return errors
} | [
"func",
"DeleteElement",
"(",
"f",
"EndpointFrontend",
")",
"[",
"]",
"error",
"{",
"var",
"errors",
"[",
"]",
"error",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"f",
".",
"GetBPFKeys",
"(",
")",
"{",
"if",
"err",
":=",
"LXCMap",
".",
"Delete",
"(",
"k",
")",
";",
"err",
"!=",
"nil",
"{",
"errors",
"=",
"append",
"(",
"errors",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"k",
",",
"bpf",
".",
"MapPath",
"(",
"MapName",
")",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"errors",
"\n",
"}"
] | // DeleteElement deletes the endpoint using all keys which represent the
// endpoint. It returns the number of errors encountered during deletion. | [
"DeleteElement",
"deletes",
"the",
"endpoint",
"using",
"all",
"keys",
"which",
"represent",
"the",
"endpoint",
".",
"It",
"returns",
"the",
"number",
"of",
"errors",
"encountered",
"during",
"deletion",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lxcmap/lxcmap.go#L201-L210 |
162,970 | cilium/cilium | pkg/maps/lxcmap/lxcmap.go | DumpToMap | func DumpToMap() (map[string]*EndpointInfo, error) {
m := map[string]*EndpointInfo{}
callback := func(key bpf.MapKey, value bpf.MapValue) {
if info, ok := value.(*EndpointInfo); ok {
if endpointKey, ok := key.(*EndpointKey); ok {
m[endpointKey.ToIP().String()] = info
}
}
}
if err := LXCMap.DumpWithCallback(callback); err != nil {
return nil, fmt.Errorf("unable to read BPF endpoint list: %s", err)
}
return m, nil
} | go | func DumpToMap() (map[string]*EndpointInfo, error) {
m := map[string]*EndpointInfo{}
callback := func(key bpf.MapKey, value bpf.MapValue) {
if info, ok := value.(*EndpointInfo); ok {
if endpointKey, ok := key.(*EndpointKey); ok {
m[endpointKey.ToIP().String()] = info
}
}
}
if err := LXCMap.DumpWithCallback(callback); err != nil {
return nil, fmt.Errorf("unable to read BPF endpoint list: %s", err)
}
return m, nil
} | [
"func",
"DumpToMap",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"EndpointInfo",
",",
"error",
")",
"{",
"m",
":=",
"map",
"[",
"string",
"]",
"*",
"EndpointInfo",
"{",
"}",
"\n",
"callback",
":=",
"func",
"(",
"key",
"bpf",
".",
"MapKey",
",",
"value",
"bpf",
".",
"MapValue",
")",
"{",
"if",
"info",
",",
"ok",
":=",
"value",
".",
"(",
"*",
"EndpointInfo",
")",
";",
"ok",
"{",
"if",
"endpointKey",
",",
"ok",
":=",
"key",
".",
"(",
"*",
"EndpointKey",
")",
";",
"ok",
"{",
"m",
"[",
"endpointKey",
".",
"ToIP",
"(",
")",
".",
"String",
"(",
")",
"]",
"=",
"info",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"LXCMap",
".",
"DumpWithCallback",
"(",
"callback",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] | // DumpToMap dumps the contents of the lxcmap into a map and returns it | [
"DumpToMap",
"dumps",
"the",
"contents",
"of",
"the",
"lxcmap",
"into",
"a",
"map",
"and",
"returns",
"it"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/lxcmap/lxcmap.go#L213-L228 |
162,971 | cilium/cilium | api/v1/server/restapi/daemon/patch_config.go | NewPatchConfig | func NewPatchConfig(ctx *middleware.Context, handler PatchConfigHandler) *PatchConfig {
return &PatchConfig{Context: ctx, Handler: handler}
} | go | func NewPatchConfig(ctx *middleware.Context, handler PatchConfigHandler) *PatchConfig {
return &PatchConfig{Context: ctx, Handler: handler}
} | [
"func",
"NewPatchConfig",
"(",
"ctx",
"*",
"middleware",
".",
"Context",
",",
"handler",
"PatchConfigHandler",
")",
"*",
"PatchConfig",
"{",
"return",
"&",
"PatchConfig",
"{",
"Context",
":",
"ctx",
",",
"Handler",
":",
"handler",
"}",
"\n",
"}"
] | // NewPatchConfig creates a new http.Handler for the patch config operation | [
"NewPatchConfig",
"creates",
"a",
"new",
"http",
".",
"Handler",
"for",
"the",
"patch",
"config",
"operation"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/daemon/patch_config.go#L28-L30 |
162,972 | cilium/cilium | pkg/k8s/client/clientset/versioned/typed/cilium.io/v2/ciliumnetworkpolicy.go | newCiliumNetworkPolicies | func newCiliumNetworkPolicies(c *CiliumV2Client, namespace string) *ciliumNetworkPolicies {
return &ciliumNetworkPolicies{
client: c.RESTClient(),
ns: namespace,
}
} | go | func newCiliumNetworkPolicies(c *CiliumV2Client, namespace string) *ciliumNetworkPolicies {
return &ciliumNetworkPolicies{
client: c.RESTClient(),
ns: namespace,
}
} | [
"func",
"newCiliumNetworkPolicies",
"(",
"c",
"*",
"CiliumV2Client",
",",
"namespace",
"string",
")",
"*",
"ciliumNetworkPolicies",
"{",
"return",
"&",
"ciliumNetworkPolicies",
"{",
"client",
":",
"c",
".",
"RESTClient",
"(",
")",
",",
"ns",
":",
"namespace",
",",
"}",
"\n",
"}"
] | // newCiliumNetworkPolicies returns a CiliumNetworkPolicies | [
"newCiliumNetworkPolicies",
"returns",
"a",
"CiliumNetworkPolicies"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2/ciliumnetworkpolicy.go#L57-L62 |
162,973 | cilium/cilium | api/v1/client/policy/delete_fqdn_cache_parameters.go | WithTimeout | func (o *DeleteFqdnCacheParams) WithTimeout(timeout time.Duration) *DeleteFqdnCacheParams {
o.SetTimeout(timeout)
return o
} | go | func (o *DeleteFqdnCacheParams) WithTimeout(timeout time.Duration) *DeleteFqdnCacheParams {
o.SetTimeout(timeout)
return o
} | [
"func",
"(",
"o",
"*",
"DeleteFqdnCacheParams",
")",
"WithTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"*",
"DeleteFqdnCacheParams",
"{",
"o",
".",
"SetTimeout",
"(",
"timeout",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithTimeout adds the timeout to the delete fqdn cache params | [
"WithTimeout",
"adds",
"the",
"timeout",
"to",
"the",
"delete",
"fqdn",
"cache",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/delete_fqdn_cache_parameters.go#L76-L79 |
162,974 | cilium/cilium | api/v1/client/policy/delete_fqdn_cache_parameters.go | WithContext | func (o *DeleteFqdnCacheParams) WithContext(ctx context.Context) *DeleteFqdnCacheParams {
o.SetContext(ctx)
return o
} | go | func (o *DeleteFqdnCacheParams) WithContext(ctx context.Context) *DeleteFqdnCacheParams {
o.SetContext(ctx)
return o
} | [
"func",
"(",
"o",
"*",
"DeleteFqdnCacheParams",
")",
"WithContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"*",
"DeleteFqdnCacheParams",
"{",
"o",
".",
"SetContext",
"(",
"ctx",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithContext adds the context to the delete fqdn cache params | [
"WithContext",
"adds",
"the",
"context",
"to",
"the",
"delete",
"fqdn",
"cache",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/delete_fqdn_cache_parameters.go#L87-L90 |
162,975 | cilium/cilium | api/v1/client/policy/delete_fqdn_cache_parameters.go | WithHTTPClient | func (o *DeleteFqdnCacheParams) WithHTTPClient(client *http.Client) *DeleteFqdnCacheParams {
o.SetHTTPClient(client)
return o
} | go | func (o *DeleteFqdnCacheParams) WithHTTPClient(client *http.Client) *DeleteFqdnCacheParams {
o.SetHTTPClient(client)
return o
} | [
"func",
"(",
"o",
"*",
"DeleteFqdnCacheParams",
")",
"WithHTTPClient",
"(",
"client",
"*",
"http",
".",
"Client",
")",
"*",
"DeleteFqdnCacheParams",
"{",
"o",
".",
"SetHTTPClient",
"(",
"client",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithHTTPClient adds the HTTPClient to the delete fqdn cache params | [
"WithHTTPClient",
"adds",
"the",
"HTTPClient",
"to",
"the",
"delete",
"fqdn",
"cache",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/delete_fqdn_cache_parameters.go#L98-L101 |
162,976 | cilium/cilium | api/v1/client/policy/delete_fqdn_cache_parameters.go | WithMatchpattern | func (o *DeleteFqdnCacheParams) WithMatchpattern(matchpattern *string) *DeleteFqdnCacheParams {
o.SetMatchpattern(matchpattern)
return o
} | go | func (o *DeleteFqdnCacheParams) WithMatchpattern(matchpattern *string) *DeleteFqdnCacheParams {
o.SetMatchpattern(matchpattern)
return o
} | [
"func",
"(",
"o",
"*",
"DeleteFqdnCacheParams",
")",
"WithMatchpattern",
"(",
"matchpattern",
"*",
"string",
")",
"*",
"DeleteFqdnCacheParams",
"{",
"o",
".",
"SetMatchpattern",
"(",
"matchpattern",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithMatchpattern adds the matchpattern to the delete fqdn cache params | [
"WithMatchpattern",
"adds",
"the",
"matchpattern",
"to",
"the",
"delete",
"fqdn",
"cache",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/delete_fqdn_cache_parameters.go#L109-L112 |
162,977 | cilium/cilium | api/v1/client/endpoint/delete_endpoint_id_parameters.go | WithTimeout | func (o *DeleteEndpointIDParams) WithTimeout(timeout time.Duration) *DeleteEndpointIDParams {
o.SetTimeout(timeout)
return o
} | go | func (o *DeleteEndpointIDParams) WithTimeout(timeout time.Duration) *DeleteEndpointIDParams {
o.SetTimeout(timeout)
return o
} | [
"func",
"(",
"o",
"*",
"DeleteEndpointIDParams",
")",
"WithTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"*",
"DeleteEndpointIDParams",
"{",
"o",
".",
"SetTimeout",
"(",
"timeout",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithTimeout adds the timeout to the delete endpoint ID params | [
"WithTimeout",
"adds",
"the",
"timeout",
"to",
"the",
"delete",
"endpoint",
"ID",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/delete_endpoint_id_parameters.go#L88-L91 |
162,978 | cilium/cilium | api/v1/client/endpoint/delete_endpoint_id_parameters.go | WithContext | func (o *DeleteEndpointIDParams) WithContext(ctx context.Context) *DeleteEndpointIDParams {
o.SetContext(ctx)
return o
} | go | func (o *DeleteEndpointIDParams) WithContext(ctx context.Context) *DeleteEndpointIDParams {
o.SetContext(ctx)
return o
} | [
"func",
"(",
"o",
"*",
"DeleteEndpointIDParams",
")",
"WithContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"*",
"DeleteEndpointIDParams",
"{",
"o",
".",
"SetContext",
"(",
"ctx",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithContext adds the context to the delete endpoint ID params | [
"WithContext",
"adds",
"the",
"context",
"to",
"the",
"delete",
"endpoint",
"ID",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/delete_endpoint_id_parameters.go#L99-L102 |
162,979 | cilium/cilium | api/v1/client/endpoint/delete_endpoint_id_parameters.go | WithHTTPClient | func (o *DeleteEndpointIDParams) WithHTTPClient(client *http.Client) *DeleteEndpointIDParams {
o.SetHTTPClient(client)
return o
} | go | func (o *DeleteEndpointIDParams) WithHTTPClient(client *http.Client) *DeleteEndpointIDParams {
o.SetHTTPClient(client)
return o
} | [
"func",
"(",
"o",
"*",
"DeleteEndpointIDParams",
")",
"WithHTTPClient",
"(",
"client",
"*",
"http",
".",
"Client",
")",
"*",
"DeleteEndpointIDParams",
"{",
"o",
".",
"SetHTTPClient",
"(",
"client",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithHTTPClient adds the HTTPClient to the delete endpoint ID params | [
"WithHTTPClient",
"adds",
"the",
"HTTPClient",
"to",
"the",
"delete",
"endpoint",
"ID",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/delete_endpoint_id_parameters.go#L110-L113 |
162,980 | cilium/cilium | api/v1/client/endpoint/delete_endpoint_id_parameters.go | WithID | func (o *DeleteEndpointIDParams) WithID(id string) *DeleteEndpointIDParams {
o.SetID(id)
return o
} | go | func (o *DeleteEndpointIDParams) WithID(id string) *DeleteEndpointIDParams {
o.SetID(id)
return o
} | [
"func",
"(",
"o",
"*",
"DeleteEndpointIDParams",
")",
"WithID",
"(",
"id",
"string",
")",
"*",
"DeleteEndpointIDParams",
"{",
"o",
".",
"SetID",
"(",
"id",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithID adds the id to the delete endpoint ID params | [
"WithID",
"adds",
"the",
"id",
"to",
"the",
"delete",
"endpoint",
"ID",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/delete_endpoint_id_parameters.go#L121-L124 |
162,981 | cilium/cilium | api/v1/models/cluster_status.go | Validate | func (m *ClusterStatus) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCiliumHealth(formats); err != nil {
res = append(res, err)
}
if err := m.validateNodes(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | go | func (m *ClusterStatus) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCiliumHealth(formats); err != nil {
res = append(res, err)
}
if err := m.validateNodes(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | [
"func",
"(",
"m",
"*",
"ClusterStatus",
")",
"Validate",
"(",
"formats",
"strfmt",
".",
"Registry",
")",
"error",
"{",
"var",
"res",
"[",
"]",
"error",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateCiliumHealth",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateNodes",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"res",
")",
">",
"0",
"{",
"return",
"errors",
".",
"CompositeValidationError",
"(",
"res",
"...",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate validates this cluster status | [
"Validate",
"validates",
"this",
"cluster",
"status"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/models/cluster_status.go#L33-L48 |
162,982 | cilium/cilium | pkg/maps/ctmap/types.go | String | func (m MapType) String() string {
switch m {
case MapTypeIPv4TCPLocal:
return "Local IPv4 TCP CT map"
case MapTypeIPv6TCPLocal:
return "Local IPv6 TCP CT map"
case MapTypeIPv4TCPGlobal:
return "Global IPv4 TCP CT map"
case MapTypeIPv6TCPGlobal:
return "Global IPv6 TCP CT map"
case MapTypeIPv4AnyLocal:
return "Local IPv4 non-TCP CT map"
case MapTypeIPv6AnyLocal:
return "Local IPv6 non-TCP CT map"
case MapTypeIPv4AnyGlobal:
return "Global IPv4 non-TCP CT map"
case MapTypeIPv6AnyGlobal:
return "Global IPv6 non-TCP CT map"
}
return fmt.Sprintf("Unknown (%d)", int(m))
} | go | func (m MapType) String() string {
switch m {
case MapTypeIPv4TCPLocal:
return "Local IPv4 TCP CT map"
case MapTypeIPv6TCPLocal:
return "Local IPv6 TCP CT map"
case MapTypeIPv4TCPGlobal:
return "Global IPv4 TCP CT map"
case MapTypeIPv6TCPGlobal:
return "Global IPv6 TCP CT map"
case MapTypeIPv4AnyLocal:
return "Local IPv4 non-TCP CT map"
case MapTypeIPv6AnyLocal:
return "Local IPv6 non-TCP CT map"
case MapTypeIPv4AnyGlobal:
return "Global IPv4 non-TCP CT map"
case MapTypeIPv6AnyGlobal:
return "Global IPv6 non-TCP CT map"
}
return fmt.Sprintf("Unknown (%d)", int(m))
} | [
"func",
"(",
"m",
"MapType",
")",
"String",
"(",
")",
"string",
"{",
"switch",
"m",
"{",
"case",
"MapTypeIPv4TCPLocal",
":",
"return",
"\"",
"\"",
"\n",
"case",
"MapTypeIPv6TCPLocal",
":",
"return",
"\"",
"\"",
"\n",
"case",
"MapTypeIPv4TCPGlobal",
":",
"return",
"\"",
"\"",
"\n",
"case",
"MapTypeIPv6TCPGlobal",
":",
"return",
"\"",
"\"",
"\n",
"case",
"MapTypeIPv4AnyLocal",
":",
"return",
"\"",
"\"",
"\n",
"case",
"MapTypeIPv6AnyLocal",
":",
"return",
"\"",
"\"",
"\n",
"case",
"MapTypeIPv4AnyGlobal",
":",
"return",
"\"",
"\"",
"\n",
"case",
"MapTypeIPv6AnyGlobal",
":",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"int",
"(",
"m",
")",
")",
"\n",
"}"
] | // String renders the map type into a user-readable string. | [
"String",
"renders",
"the",
"map",
"type",
"into",
"a",
"user",
"-",
"readable",
"string",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/ctmap/types.go#L42-L62 |
162,983 | cilium/cilium | pkg/endpoint/proxystats.go | sortProxyStats | func sortProxyStats(proxyStats []*models.ProxyStatistics) {
sort.Slice(proxyStats, func(i, j int) bool {
s1, s2 := proxyStats[i], proxyStats[j]
switch {
case s1.Port < s2.Port:
return true
case s1.Port > s2.Port:
return false
}
switch {
case s1.Location < s2.Location:
return true
case s1.Location > s2.Location:
return false
}
switch {
case s1.Protocol < s2.Protocol:
return true
case s1.Protocol > s2.Protocol:
return false
}
switch {
case s1.AllocatedProxyPort < s2.AllocatedProxyPort:
return true
case s1.AllocatedProxyPort > s2.AllocatedProxyPort:
return false
}
return false
})
} | go | func sortProxyStats(proxyStats []*models.ProxyStatistics) {
sort.Slice(proxyStats, func(i, j int) bool {
s1, s2 := proxyStats[i], proxyStats[j]
switch {
case s1.Port < s2.Port:
return true
case s1.Port > s2.Port:
return false
}
switch {
case s1.Location < s2.Location:
return true
case s1.Location > s2.Location:
return false
}
switch {
case s1.Protocol < s2.Protocol:
return true
case s1.Protocol > s2.Protocol:
return false
}
switch {
case s1.AllocatedProxyPort < s2.AllocatedProxyPort:
return true
case s1.AllocatedProxyPort > s2.AllocatedProxyPort:
return false
}
return false
})
} | [
"func",
"sortProxyStats",
"(",
"proxyStats",
"[",
"]",
"*",
"models",
".",
"ProxyStatistics",
")",
"{",
"sort",
".",
"Slice",
"(",
"proxyStats",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"s1",
",",
"s2",
":=",
"proxyStats",
"[",
"i",
"]",
",",
"proxyStats",
"[",
"j",
"]",
"\n",
"switch",
"{",
"case",
"s1",
".",
"Port",
"<",
"s2",
".",
"Port",
":",
"return",
"true",
"\n",
"case",
"s1",
".",
"Port",
">",
"s2",
".",
"Port",
":",
"return",
"false",
"\n",
"}",
"\n",
"switch",
"{",
"case",
"s1",
".",
"Location",
"<",
"s2",
".",
"Location",
":",
"return",
"true",
"\n",
"case",
"s1",
".",
"Location",
">",
"s2",
".",
"Location",
":",
"return",
"false",
"\n",
"}",
"\n",
"switch",
"{",
"case",
"s1",
".",
"Protocol",
"<",
"s2",
".",
"Protocol",
":",
"return",
"true",
"\n",
"case",
"s1",
".",
"Protocol",
">",
"s2",
".",
"Protocol",
":",
"return",
"false",
"\n",
"}",
"\n",
"switch",
"{",
"case",
"s1",
".",
"AllocatedProxyPort",
"<",
"s2",
".",
"AllocatedProxyPort",
":",
"return",
"true",
"\n",
"case",
"s1",
".",
"AllocatedProxyPort",
">",
"s2",
".",
"AllocatedProxyPort",
":",
"return",
"false",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"}"
] | // sortProxyStats sorts the given slice of ProxyStatistics. | [
"sortProxyStats",
"sorts",
"the",
"given",
"slice",
"of",
"ProxyStatistics",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/proxystats.go#L24-L53 |
162,984 | cilium/cilium | pkg/labels/oplabels.go | NewOpLabels | func NewOpLabels() OpLabels {
return OpLabels{
Custom: Labels{},
Disabled: Labels{},
OrchestrationIdentity: Labels{},
OrchestrationInfo: Labels{},
}
} | go | func NewOpLabels() OpLabels {
return OpLabels{
Custom: Labels{},
Disabled: Labels{},
OrchestrationIdentity: Labels{},
OrchestrationInfo: Labels{},
}
} | [
"func",
"NewOpLabels",
"(",
")",
"OpLabels",
"{",
"return",
"OpLabels",
"{",
"Custom",
":",
"Labels",
"{",
"}",
",",
"Disabled",
":",
"Labels",
"{",
"}",
",",
"OrchestrationIdentity",
":",
"Labels",
"{",
"}",
",",
"OrchestrationInfo",
":",
"Labels",
"{",
"}",
",",
"}",
"\n",
"}"
] | // NewOpLabels creates new initialized OpLabels | [
"NewOpLabels",
"creates",
"new",
"initialized",
"OpLabels"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/labels/oplabels.go#L48-L55 |
162,985 | cilium/cilium | pkg/labels/oplabels.go | IdentityLabels | func (o *OpLabels) IdentityLabels() Labels {
enabled := make(Labels, len(o.Custom)+len(o.OrchestrationIdentity))
for k, v := range o.Custom {
enabled[k] = v
}
for k, v := range o.OrchestrationIdentity {
enabled[k] = v
}
return enabled
} | go | func (o *OpLabels) IdentityLabels() Labels {
enabled := make(Labels, len(o.Custom)+len(o.OrchestrationIdentity))
for k, v := range o.Custom {
enabled[k] = v
}
for k, v := range o.OrchestrationIdentity {
enabled[k] = v
}
return enabled
} | [
"func",
"(",
"o",
"*",
"OpLabels",
")",
"IdentityLabels",
"(",
")",
"Labels",
"{",
"enabled",
":=",
"make",
"(",
"Labels",
",",
"len",
"(",
"o",
".",
"Custom",
")",
"+",
"len",
"(",
"o",
".",
"OrchestrationIdentity",
")",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"o",
".",
"Custom",
"{",
"enabled",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"o",
".",
"OrchestrationIdentity",
"{",
"enabled",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"return",
"enabled",
"\n",
"}"
] | // IdentityLabels returns map of labels that are used when determining a
// security identity. | [
"IdentityLabels",
"returns",
"map",
"of",
"labels",
"that",
"are",
"used",
"when",
"determining",
"a",
"security",
"identity",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/labels/oplabels.go#L85-L97 |
162,986 | cilium/cilium | pkg/labels/oplabels.go | GetIdentityLabel | func (o *OpLabels) GetIdentityLabel(key string) (l Label, found bool) {
l, found = o.OrchestrationIdentity[key]
if !found {
l, found = o.Custom[key]
}
return l, found
} | go | func (o *OpLabels) GetIdentityLabel(key string) (l Label, found bool) {
l, found = o.OrchestrationIdentity[key]
if !found {
l, found = o.Custom[key]
}
return l, found
} | [
"func",
"(",
"o",
"*",
"OpLabels",
")",
"GetIdentityLabel",
"(",
"key",
"string",
")",
"(",
"l",
"Label",
",",
"found",
"bool",
")",
"{",
"l",
",",
"found",
"=",
"o",
".",
"OrchestrationIdentity",
"[",
"key",
"]",
"\n",
"if",
"!",
"found",
"{",
"l",
",",
"found",
"=",
"o",
".",
"Custom",
"[",
"key",
"]",
"\n",
"}",
"\n",
"return",
"l",
",",
"found",
"\n",
"}"
] | // GetIdentityLabel returns the value of the given Key from all IdentityLabels. | [
"GetIdentityLabel",
"returns",
"the",
"value",
"of",
"the",
"given",
"Key",
"from",
"all",
"IdentityLabels",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/labels/oplabels.go#L100-L106 |
162,987 | cilium/cilium | pkg/labels/oplabels.go | AllLabels | func (o *OpLabels) AllLabels() Labels {
all := make(Labels, len(o.Custom)+len(o.OrchestrationInfo)+len(o.OrchestrationIdentity)+len(o.Disabled))
for k, v := range o.Custom {
all[k] = v
}
for k, v := range o.Disabled {
all[k] = v
}
for k, v := range o.OrchestrationIdentity {
all[k] = v
}
for k, v := range o.OrchestrationInfo {
all[k] = v
}
return all
} | go | func (o *OpLabels) AllLabels() Labels {
all := make(Labels, len(o.Custom)+len(o.OrchestrationInfo)+len(o.OrchestrationIdentity)+len(o.Disabled))
for k, v := range o.Custom {
all[k] = v
}
for k, v := range o.Disabled {
all[k] = v
}
for k, v := range o.OrchestrationIdentity {
all[k] = v
}
for k, v := range o.OrchestrationInfo {
all[k] = v
}
return all
} | [
"func",
"(",
"o",
"*",
"OpLabels",
")",
"AllLabels",
"(",
")",
"Labels",
"{",
"all",
":=",
"make",
"(",
"Labels",
",",
"len",
"(",
"o",
".",
"Custom",
")",
"+",
"len",
"(",
"o",
".",
"OrchestrationInfo",
")",
"+",
"len",
"(",
"o",
".",
"OrchestrationIdentity",
")",
"+",
"len",
"(",
"o",
".",
"Disabled",
")",
")",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"o",
".",
"Custom",
"{",
"all",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"o",
".",
"Disabled",
"{",
"all",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"o",
".",
"OrchestrationIdentity",
"{",
"all",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"o",
".",
"OrchestrationInfo",
"{",
"all",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"all",
"\n",
"}"
] | // AllLabels returns all Labels within the provided OpLabels. | [
"AllLabels",
"returns",
"all",
"Labels",
"within",
"the",
"provided",
"OpLabels",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/labels/oplabels.go#L109-L128 |
162,988 | cilium/cilium | pkg/labels/oplabels.go | upsertLabel | func (l Labels) upsertLabel(label Label) bool {
oldLabel, found := l[label.Key]
if found {
// Key is the same, check if Value and Source are also the same
if label.Value == oldLabel.Value && label.Source == oldLabel.Source {
return false // No change
}
}
// Insert or replace old label
l[label.Key] = label
return true
} | go | func (l Labels) upsertLabel(label Label) bool {
oldLabel, found := l[label.Key]
if found {
// Key is the same, check if Value and Source are also the same
if label.Value == oldLabel.Value && label.Source == oldLabel.Source {
return false // No change
}
}
// Insert or replace old label
l[label.Key] = label
return true
} | [
"func",
"(",
"l",
"Labels",
")",
"upsertLabel",
"(",
"label",
"Label",
")",
"bool",
"{",
"oldLabel",
",",
"found",
":=",
"l",
"[",
"label",
".",
"Key",
"]",
"\n",
"if",
"found",
"{",
"// Key is the same, check if Value and Source are also the same",
"if",
"label",
".",
"Value",
"==",
"oldLabel",
".",
"Value",
"&&",
"label",
".",
"Source",
"==",
"oldLabel",
".",
"Source",
"{",
"return",
"false",
"// No change",
"\n",
"}",
"\n",
"}",
"\n",
"// Insert or replace old label",
"l",
"[",
"label",
".",
"Key",
"]",
"=",
"label",
"\n",
"return",
"true",
"\n",
"}"
] | // upsertLabel updates or inserts 'label' in 'l', but only if exactly the same label
// was not already in 'l'. Returns 'true' if a label was added, or an old label was
// updated, 'false' otherwise. | [
"upsertLabel",
"updates",
"or",
"inserts",
"label",
"in",
"l",
"but",
"only",
"if",
"exactly",
"the",
"same",
"label",
"was",
"not",
"already",
"in",
"l",
".",
"Returns",
"true",
"if",
"a",
"label",
"was",
"added",
"or",
"an",
"old",
"label",
"was",
"updated",
"false",
"otherwise",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/labels/oplabels.go#L215-L226 |
162,989 | cilium/cilium | pkg/labels/oplabels.go | deleteUnMarked | func (l Labels) deleteUnMarked(marks keepMarks) bool {
deleted := false
for k := range l {
if _, keep := marks[k]; !keep {
delete(l, k)
deleted = true
}
}
return deleted
} | go | func (l Labels) deleteUnMarked(marks keepMarks) bool {
deleted := false
for k := range l {
if _, keep := marks[k]; !keep {
delete(l, k)
deleted = true
}
}
return deleted
} | [
"func",
"(",
"l",
"Labels",
")",
"deleteUnMarked",
"(",
"marks",
"keepMarks",
")",
"bool",
"{",
"deleted",
":=",
"false",
"\n",
"for",
"k",
":=",
"range",
"l",
"{",
"if",
"_",
",",
"keep",
":=",
"marks",
"[",
"k",
"]",
";",
"!",
"keep",
"{",
"delete",
"(",
"l",
",",
"k",
")",
"\n",
"deleted",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"deleted",
"\n",
"}"
] | // deleteUnMarked deletes the labels which have not been marked for keeping.
// Returns true if any of them were deleted. | [
"deleteUnMarked",
"deletes",
"the",
"labels",
"which",
"have",
"not",
"been",
"marked",
"for",
"keeping",
".",
"Returns",
"true",
"if",
"any",
"of",
"them",
"were",
"deleted",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/labels/oplabels.go#L230-L240 |
162,990 | cilium/cilium | pkg/k8s/client/listers/cilium.io/v2/ciliumendpoint.go | List | func (s *ciliumEndpointLister) List(selector labels.Selector) (ret []*v2.CiliumEndpoint, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v2.CiliumEndpoint))
})
return ret, err
} | go | func (s *ciliumEndpointLister) List(selector labels.Selector) (ret []*v2.CiliumEndpoint, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v2.CiliumEndpoint))
})
return ret, err
} | [
"func",
"(",
"s",
"*",
"ciliumEndpointLister",
")",
"List",
"(",
"selector",
"labels",
".",
"Selector",
")",
"(",
"ret",
"[",
"]",
"*",
"v2",
".",
"CiliumEndpoint",
",",
"err",
"error",
")",
"{",
"err",
"=",
"cache",
".",
"ListAll",
"(",
"s",
".",
"indexer",
",",
"selector",
",",
"func",
"(",
"m",
"interface",
"{",
"}",
")",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"m",
".",
"(",
"*",
"v2",
".",
"CiliumEndpoint",
")",
")",
"\n",
"}",
")",
"\n",
"return",
"ret",
",",
"err",
"\n",
"}"
] | // List lists all CiliumEndpoints in the indexer. | [
"List",
"lists",
"all",
"CiliumEndpoints",
"in",
"the",
"indexer",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/listers/cilium.io/v2/ciliumendpoint.go#L46-L51 |
162,991 | cilium/cilium | pkg/k8s/client/listers/cilium.io/v2/ciliumendpoint.go | CiliumEndpoints | func (s *ciliumEndpointLister) CiliumEndpoints(namespace string) CiliumEndpointNamespaceLister {
return ciliumEndpointNamespaceLister{indexer: s.indexer, namespace: namespace}
} | go | func (s *ciliumEndpointLister) CiliumEndpoints(namespace string) CiliumEndpointNamespaceLister {
return ciliumEndpointNamespaceLister{indexer: s.indexer, namespace: namespace}
} | [
"func",
"(",
"s",
"*",
"ciliumEndpointLister",
")",
"CiliumEndpoints",
"(",
"namespace",
"string",
")",
"CiliumEndpointNamespaceLister",
"{",
"return",
"ciliumEndpointNamespaceLister",
"{",
"indexer",
":",
"s",
".",
"indexer",
",",
"namespace",
":",
"namespace",
"}",
"\n",
"}"
] | // CiliumEndpoints returns an object that can list and get CiliumEndpoints. | [
"CiliumEndpoints",
"returns",
"an",
"object",
"that",
"can",
"list",
"and",
"get",
"CiliumEndpoints",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/listers/cilium.io/v2/ciliumendpoint.go#L54-L56 |
162,992 | cilium/cilium | pkg/k8s/client/listers/cilium.io/v2/ciliumendpoint.go | List | func (s ciliumEndpointNamespaceLister) List(selector labels.Selector) (ret []*v2.CiliumEndpoint, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v2.CiliumEndpoint))
})
return ret, err
} | go | func (s ciliumEndpointNamespaceLister) List(selector labels.Selector) (ret []*v2.CiliumEndpoint, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v2.CiliumEndpoint))
})
return ret, err
} | [
"func",
"(",
"s",
"ciliumEndpointNamespaceLister",
")",
"List",
"(",
"selector",
"labels",
".",
"Selector",
")",
"(",
"ret",
"[",
"]",
"*",
"v2",
".",
"CiliumEndpoint",
",",
"err",
"error",
")",
"{",
"err",
"=",
"cache",
".",
"ListAllByNamespace",
"(",
"s",
".",
"indexer",
",",
"s",
".",
"namespace",
",",
"selector",
",",
"func",
"(",
"m",
"interface",
"{",
"}",
")",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"m",
".",
"(",
"*",
"v2",
".",
"CiliumEndpoint",
")",
")",
"\n",
"}",
")",
"\n",
"return",
"ret",
",",
"err",
"\n",
"}"
] | // List lists all CiliumEndpoints in the indexer for a given namespace. | [
"List",
"lists",
"all",
"CiliumEndpoints",
"in",
"the",
"indexer",
"for",
"a",
"given",
"namespace",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/listers/cilium.io/v2/ciliumendpoint.go#L75-L80 |
162,993 | cilium/cilium | pkg/k8s/client/listers/cilium.io/v2/ciliumendpoint.go | Get | func (s ciliumEndpointNamespaceLister) Get(name string) (*v2.CiliumEndpoint, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v2.Resource("ciliumendpoint"), name)
}
return obj.(*v2.CiliumEndpoint), nil
} | go | func (s ciliumEndpointNamespaceLister) Get(name string) (*v2.CiliumEndpoint, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v2.Resource("ciliumendpoint"), name)
}
return obj.(*v2.CiliumEndpoint), nil
} | [
"func",
"(",
"s",
"ciliumEndpointNamespaceLister",
")",
"Get",
"(",
"name",
"string",
")",
"(",
"*",
"v2",
".",
"CiliumEndpoint",
",",
"error",
")",
"{",
"obj",
",",
"exists",
",",
"err",
":=",
"s",
".",
"indexer",
".",
"GetByKey",
"(",
"s",
".",
"namespace",
"+",
"\"",
"\"",
"+",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"exists",
"{",
"return",
"nil",
",",
"errors",
".",
"NewNotFound",
"(",
"v2",
".",
"Resource",
"(",
"\"",
"\"",
")",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"obj",
".",
"(",
"*",
"v2",
".",
"CiliumEndpoint",
")",
",",
"nil",
"\n",
"}"
] | // Get retrieves the CiliumEndpoint from the indexer for a given namespace and name. | [
"Get",
"retrieves",
"the",
"CiliumEndpoint",
"from",
"the",
"indexer",
"for",
"a",
"given",
"namespace",
"and",
"name",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/listers/cilium.io/v2/ciliumendpoint.go#L83-L92 |
162,994 | cilium/cilium | pkg/endpoint/sort.go | OrderEndpointModelAsc | func OrderEndpointModelAsc(eps []*models.Endpoint) {
sort.Slice(eps, func(i, j int) bool { return eps[i].ID < eps[j].ID })
} | go | func OrderEndpointModelAsc(eps []*models.Endpoint) {
sort.Slice(eps, func(i, j int) bool { return eps[i].ID < eps[j].ID })
} | [
"func",
"OrderEndpointModelAsc",
"(",
"eps",
"[",
"]",
"*",
"models",
".",
"Endpoint",
")",
"{",
"sort",
".",
"Slice",
"(",
"eps",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"eps",
"[",
"i",
"]",
".",
"ID",
"<",
"eps",
"[",
"j",
"]",
".",
"ID",
"}",
")",
"\n",
"}"
] | // OrderEndpointModelAsc orders the slice of Endpoint in ascending ID order. | [
"OrderEndpointModelAsc",
"orders",
"the",
"slice",
"of",
"Endpoint",
"in",
"ascending",
"ID",
"order",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/sort.go#L24-L26 |
162,995 | cilium/cilium | pkg/endpoint/sort.go | OrderEndpointAsc | func OrderEndpointAsc(eps []*Endpoint) {
sort.Slice(eps, func(i, j int) bool { return eps[i].ID < eps[j].ID })
} | go | func OrderEndpointAsc(eps []*Endpoint) {
sort.Slice(eps, func(i, j int) bool { return eps[i].ID < eps[j].ID })
} | [
"func",
"OrderEndpointAsc",
"(",
"eps",
"[",
"]",
"*",
"Endpoint",
")",
"{",
"sort",
".",
"Slice",
"(",
"eps",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"eps",
"[",
"i",
"]",
".",
"ID",
"<",
"eps",
"[",
"j",
"]",
".",
"ID",
"}",
")",
"\n",
"}"
] | // OrderEndpointAsc orders the slice of Endpoint in ascending ID order. | [
"OrderEndpointAsc",
"orders",
"the",
"slice",
"of",
"Endpoint",
"in",
"ascending",
"ID",
"order",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/sort.go#L29-L31 |
162,996 | cilium/cilium | pkg/maps/ctmap/ctmap.go | DumpEntries | func (m *Map) DumpEntries() (string, error) {
var buffer bytes.Buffer
cb := func(k bpf.MapKey, v bpf.MapValue) {
key := k.(tuple.TupleKey)
if !key.ToHost().Dump(&buffer, true) {
return
}
value := v.(*CtEntry)
buffer.WriteString(value.String())
}
// DumpWithCallback() must be called before buffer.String().
err := m.DumpWithCallback(cb)
return buffer.String(), err
} | go | func (m *Map) DumpEntries() (string, error) {
var buffer bytes.Buffer
cb := func(k bpf.MapKey, v bpf.MapValue) {
key := k.(tuple.TupleKey)
if !key.ToHost().Dump(&buffer, true) {
return
}
value := v.(*CtEntry)
buffer.WriteString(value.String())
}
// DumpWithCallback() must be called before buffer.String().
err := m.DumpWithCallback(cb)
return buffer.String(), err
} | [
"func",
"(",
"m",
"*",
"Map",
")",
"DumpEntries",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n\n",
"cb",
":=",
"func",
"(",
"k",
"bpf",
".",
"MapKey",
",",
"v",
"bpf",
".",
"MapValue",
")",
"{",
"key",
":=",
"k",
".",
"(",
"tuple",
".",
"TupleKey",
")",
"\n",
"if",
"!",
"key",
".",
"ToHost",
"(",
")",
".",
"Dump",
"(",
"&",
"buffer",
",",
"true",
")",
"{",
"return",
"\n",
"}",
"\n",
"value",
":=",
"v",
".",
"(",
"*",
"CtEntry",
")",
"\n",
"buffer",
".",
"WriteString",
"(",
"value",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"// DumpWithCallback() must be called before buffer.String().",
"err",
":=",
"m",
".",
"DumpWithCallback",
"(",
"cb",
")",
"\n",
"return",
"buffer",
".",
"String",
"(",
")",
",",
"err",
"\n",
"}"
] | // ToString iterates through Map m and writes the values of the ct entries in m
// to a string. | [
"ToString",
"iterates",
"through",
"Map",
"m",
"and",
"writes",
"the",
"values",
"of",
"the",
"ct",
"entries",
"in",
"m",
"to",
"a",
"string",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/ctmap/ctmap.go#L183-L197 |
162,997 | cilium/cilium | pkg/maps/ctmap/ctmap.go | NewMap | func NewMap(mapName string, mapType MapType) *Map {
result := &Map{
Map: *bpf.NewMap(mapName,
bpf.MapTypeLRUHash,
mapInfo[mapType].keySize,
int(unsafe.Sizeof(CtEntry{})),
mapInfo[mapType].maxEntries,
0, 0,
mapInfo[mapType].parser,
),
mapType: mapType,
define: mapInfo[mapType].bpfDefine,
}
return result
} | go | func NewMap(mapName string, mapType MapType) *Map {
result := &Map{
Map: *bpf.NewMap(mapName,
bpf.MapTypeLRUHash,
mapInfo[mapType].keySize,
int(unsafe.Sizeof(CtEntry{})),
mapInfo[mapType].maxEntries,
0, 0,
mapInfo[mapType].parser,
),
mapType: mapType,
define: mapInfo[mapType].bpfDefine,
}
return result
} | [
"func",
"NewMap",
"(",
"mapName",
"string",
",",
"mapType",
"MapType",
")",
"*",
"Map",
"{",
"result",
":=",
"&",
"Map",
"{",
"Map",
":",
"*",
"bpf",
".",
"NewMap",
"(",
"mapName",
",",
"bpf",
".",
"MapTypeLRUHash",
",",
"mapInfo",
"[",
"mapType",
"]",
".",
"keySize",
",",
"int",
"(",
"unsafe",
".",
"Sizeof",
"(",
"CtEntry",
"{",
"}",
")",
")",
",",
"mapInfo",
"[",
"mapType",
"]",
".",
"maxEntries",
",",
"0",
",",
"0",
",",
"mapInfo",
"[",
"mapType",
"]",
".",
"parser",
",",
")",
",",
"mapType",
":",
"mapType",
",",
"define",
":",
"mapInfo",
"[",
"mapType",
"]",
".",
"bpfDefine",
",",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // NewMap creates a new CT map of the specified type with the specified name. | [
"NewMap",
"creates",
"a",
"new",
"CT",
"map",
"of",
"the",
"specified",
"type",
"with",
"the",
"specified",
"name",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/ctmap/ctmap.go#L218-L232 |
162,998 | cilium/cilium | pkg/maps/ctmap/ctmap.go | doGC6 | func doGC6(m *Map, filter *GCFilter) gcStats {
natMap := mapInfo[m.mapType].natMap
stats := statStartGc(m)
defer stats.finish()
err := natMap.Open()
if err == nil {
defer natMap.Close()
} else {
natMap = nil
}
filterCallback := func(key bpf.MapKey, value bpf.MapValue) {
currentKey := key.(*tuple.TupleKey6Global)
entry := value.(*CtEntry)
// In CT entries, the source address of the conntrack entry (`SourceAddr`) is
// the destination of the packet received, therefore it's the packet's
// destination IP
action := filter.doFiltering(currentKey.DestAddr.IP(), currentKey.SourceAddr.IP(), currentKey.SourcePort,
uint8(currentKey.NextHeader), currentKey.Flags, entry)
switch action {
case deleteEntry:
err := purgeCtEntry6(m, currentKey, natMap)
if err != nil {
log.WithError(err).WithField(logfields.Key, currentKey.String()).Error("Unable to delete CT entry")
} else {
stats.deleted++
}
default:
stats.aliveEntries++
}
}
stats.dumpError = m.DumpReliablyWithCallback(filterCallback, stats.DumpStats)
return stats
} | go | func doGC6(m *Map, filter *GCFilter) gcStats {
natMap := mapInfo[m.mapType].natMap
stats := statStartGc(m)
defer stats.finish()
err := natMap.Open()
if err == nil {
defer natMap.Close()
} else {
natMap = nil
}
filterCallback := func(key bpf.MapKey, value bpf.MapValue) {
currentKey := key.(*tuple.TupleKey6Global)
entry := value.(*CtEntry)
// In CT entries, the source address of the conntrack entry (`SourceAddr`) is
// the destination of the packet received, therefore it's the packet's
// destination IP
action := filter.doFiltering(currentKey.DestAddr.IP(), currentKey.SourceAddr.IP(), currentKey.SourcePort,
uint8(currentKey.NextHeader), currentKey.Flags, entry)
switch action {
case deleteEntry:
err := purgeCtEntry6(m, currentKey, natMap)
if err != nil {
log.WithError(err).WithField(logfields.Key, currentKey.String()).Error("Unable to delete CT entry")
} else {
stats.deleted++
}
default:
stats.aliveEntries++
}
}
stats.dumpError = m.DumpReliablyWithCallback(filterCallback, stats.DumpStats)
return stats
} | [
"func",
"doGC6",
"(",
"m",
"*",
"Map",
",",
"filter",
"*",
"GCFilter",
")",
"gcStats",
"{",
"natMap",
":=",
"mapInfo",
"[",
"m",
".",
"mapType",
"]",
".",
"natMap",
"\n",
"stats",
":=",
"statStartGc",
"(",
"m",
")",
"\n",
"defer",
"stats",
".",
"finish",
"(",
")",
"\n\n",
"err",
":=",
"natMap",
".",
"Open",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"defer",
"natMap",
".",
"Close",
"(",
")",
"\n",
"}",
"else",
"{",
"natMap",
"=",
"nil",
"\n",
"}",
"\n\n",
"filterCallback",
":=",
"func",
"(",
"key",
"bpf",
".",
"MapKey",
",",
"value",
"bpf",
".",
"MapValue",
")",
"{",
"currentKey",
":=",
"key",
".",
"(",
"*",
"tuple",
".",
"TupleKey6Global",
")",
"\n",
"entry",
":=",
"value",
".",
"(",
"*",
"CtEntry",
")",
"\n\n",
"// In CT entries, the source address of the conntrack entry (`SourceAddr`) is",
"// the destination of the packet received, therefore it's the packet's",
"// destination IP",
"action",
":=",
"filter",
".",
"doFiltering",
"(",
"currentKey",
".",
"DestAddr",
".",
"IP",
"(",
")",
",",
"currentKey",
".",
"SourceAddr",
".",
"IP",
"(",
")",
",",
"currentKey",
".",
"SourcePort",
",",
"uint8",
"(",
"currentKey",
".",
"NextHeader",
")",
",",
"currentKey",
".",
"Flags",
",",
"entry",
")",
"\n\n",
"switch",
"action",
"{",
"case",
"deleteEntry",
":",
"err",
":=",
"purgeCtEntry6",
"(",
"m",
",",
"currentKey",
",",
"natMap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithError",
"(",
"err",
")",
".",
"WithField",
"(",
"logfields",
".",
"Key",
",",
"currentKey",
".",
"String",
"(",
")",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"{",
"stats",
".",
"deleted",
"++",
"\n",
"}",
"\n",
"default",
":",
"stats",
".",
"aliveEntries",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"stats",
".",
"dumpError",
"=",
"m",
".",
"DumpReliablyWithCallback",
"(",
"filterCallback",
",",
"stats",
".",
"DumpStats",
")",
"\n\n",
"return",
"stats",
"\n",
"}"
] | // doGC6 iterates through a CTv6 map and drops entries based on the given
// filter. | [
"doGC6",
"iterates",
"through",
"a",
"CTv6",
"map",
"and",
"drops",
"entries",
"based",
"on",
"the",
"given",
"filter",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/ctmap/ctmap.go#L244-L281 |
162,999 | cilium/cilium | pkg/maps/ctmap/ctmap.go | GC | func GC(m *Map, filter *GCFilter) int {
if filter.RemoveExpired {
t, _ := bpf.GetMtime()
tsec := t / 1000000000
filter.Time = uint32(tsec)
}
return doGC(m, filter)
} | go | func GC(m *Map, filter *GCFilter) int {
if filter.RemoveExpired {
t, _ := bpf.GetMtime()
tsec := t / 1000000000
filter.Time = uint32(tsec)
}
return doGC(m, filter)
} | [
"func",
"GC",
"(",
"m",
"*",
"Map",
",",
"filter",
"*",
"GCFilter",
")",
"int",
"{",
"if",
"filter",
".",
"RemoveExpired",
"{",
"t",
",",
"_",
":=",
"bpf",
".",
"GetMtime",
"(",
")",
"\n",
"tsec",
":=",
"t",
"/",
"1000000000",
"\n",
"filter",
".",
"Time",
"=",
"uint32",
"(",
"tsec",
")",
"\n",
"}",
"\n\n",
"return",
"doGC",
"(",
"m",
",",
"filter",
")",
"\n",
"}"
] | // GC runs garbage collection for map m with name mapType with the given filter.
// It returns how many items were deleted from m. | [
"GC",
"runs",
"garbage",
"collection",
"for",
"map",
"m",
"with",
"name",
"mapType",
"with",
"the",
"given",
"filter",
".",
"It",
"returns",
"how",
"many",
"items",
"were",
"deleted",
"from",
"m",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/ctmap/ctmap.go#L368-L376 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.