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,700
cilium/cilium
daemon/daemon.go
RemoveFromEndpointQueue
func (d *Daemon) RemoveFromEndpointQueue(epID uint64) { d.uniqueIDMU.Lock() if cancel, queued := d.uniqueID[epID]; queued && cancel != nil { delete(d.uniqueID, epID) cancel() } d.uniqueIDMU.Unlock() }
go
func (d *Daemon) RemoveFromEndpointQueue(epID uint64) { d.uniqueIDMU.Lock() if cancel, queued := d.uniqueID[epID]; queued && cancel != nil { delete(d.uniqueID, epID) cancel() } d.uniqueIDMU.Unlock() }
[ "func", "(", "d", "*", "Daemon", ")", "RemoveFromEndpointQueue", "(", "epID", "uint64", ")", "{", "d", ".", "uniqueIDMU", ".", "Lock", "(", ")", "\n", "if", "cancel", ",", "queued", ":=", "d", ".", "uniqueID", "[", "epID", "]", ";", "queued", "&&", "cancel", "!=", "nil", "{", "delete", "(", "d", ".", "uniqueID", ",", "epID", ")", "\n", "cancel", "(", ")", "\n", "}", "\n", "d", ".", "uniqueIDMU", ".", "Unlock", "(", ")", "\n", "}" ]
// RemoveFromEndpointQueue removes the endpoint from the "build permit" queue, // canceling the wait for the build permit if still waiting.
[ "RemoveFromEndpointQueue", "removes", "the", "endpoint", "from", "the", "build", "permit", "queue", "canceling", "the", "wait", "for", "the", "build", "permit", "if", "still", "waiting", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L307-L314
162,701
cilium/cilium
daemon/daemon.go
DebugEnabled
func (d *Daemon) DebugEnabled() bool { return option.Config.Opts.IsEnabled(option.Debug) }
go
func (d *Daemon) DebugEnabled() bool { return option.Config.Opts.IsEnabled(option.Debug) }
[ "func", "(", "d", "*", "Daemon", ")", "DebugEnabled", "(", ")", "bool", "{", "return", "option", ".", "Config", ".", "Opts", ".", "IsEnabled", "(", "option", ".", "Debug", ")", "\n", "}" ]
// DebugEnabled returns if debug mode is enabled.
[ "DebugEnabled", "returns", "if", "debug", "mode", "is", "enabled", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L322-L324
162,702
cilium/cilium
daemon/daemon.go
writePreFilterHeader
func (d *Daemon) writePreFilterHeader(dir string) error { headerPath := filepath.Join(dir, common.PreFilterHeaderFileName) log.WithField(logfields.Path, headerPath).Debug("writing configuration") f, err := os.Create(headerPath) if err != nil { return fmt.Errorf("failed to open file %s for writing: %s", headerPath, err) } defer f.Close() fw := bufio.NewWriter(f) fmt.Fprint(fw, "/*\n") fmt.Fprintf(fw, " * XDP device: %s\n", option.Config.DevicePreFilter) fmt.Fprintf(fw, " * XDP mode: %s\n", option.Config.ModePreFilter) fmt.Fprint(fw, " */\n\n") d.preFilter.WriteConfig(fw) return fw.Flush() }
go
func (d *Daemon) writePreFilterHeader(dir string) error { headerPath := filepath.Join(dir, common.PreFilterHeaderFileName) log.WithField(logfields.Path, headerPath).Debug("writing configuration") f, err := os.Create(headerPath) if err != nil { return fmt.Errorf("failed to open file %s for writing: %s", headerPath, err) } defer f.Close() fw := bufio.NewWriter(f) fmt.Fprint(fw, "/*\n") fmt.Fprintf(fw, " * XDP device: %s\n", option.Config.DevicePreFilter) fmt.Fprintf(fw, " * XDP mode: %s\n", option.Config.ModePreFilter) fmt.Fprint(fw, " */\n\n") d.preFilter.WriteConfig(fw) return fw.Flush() }
[ "func", "(", "d", "*", "Daemon", ")", "writePreFilterHeader", "(", "dir", "string", ")", "error", "{", "headerPath", ":=", "filepath", ".", "Join", "(", "dir", ",", "common", ".", "PreFilterHeaderFileName", ")", "\n", "log", ".", "WithField", "(", "logfields", ".", "Path", ",", "headerPath", ")", ".", "Debug", "(", "\"", "\"", ")", "\n", "f", ",", "err", ":=", "os", ".", "Create", "(", "headerPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "headerPath", ",", "err", ")", "\n\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n", "fw", ":=", "bufio", ".", "NewWriter", "(", "f", ")", "\n", "fmt", ".", "Fprint", "(", "fw", ",", "\"", "\\n", "\"", ")", "\n", "fmt", ".", "Fprintf", "(", "fw", ",", "\"", "\\n", "\"", ",", "option", ".", "Config", ".", "DevicePreFilter", ")", "\n", "fmt", ".", "Fprintf", "(", "fw", ",", "\"", "\\n", "\"", ",", "option", ".", "Config", ".", "ModePreFilter", ")", "\n", "fmt", ".", "Fprint", "(", "fw", ",", "\"", "\\n", "\\n", "\"", ")", "\n", "d", ".", "preFilter", ".", "WriteConfig", "(", "fw", ")", "\n", "return", "fw", ".", "Flush", "(", ")", "\n", "}" ]
// Must be called with option.Config.EnablePolicyMU locked.
[ "Must", "be", "called", "with", "option", ".", "Config", ".", "EnablePolicyMU", "locked", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L350-L366
162,703
cilium/cilium
daemon/daemon.go
createPrefixLengthCounter
func createPrefixLengthCounter() *counter.PrefixLengthCounter { prefixLengths4 := ipcachemap.IPCache.GetMaxPrefixLengths(false) prefixLengths6 := ipcachemap.IPCache.GetMaxPrefixLengths(true) counter := counter.NewPrefixLengthCounter(prefixLengths6, prefixLengths4) // This is a bit ugly, but there's not a great way to define an IPNet // without parsing strings, etc. defaultPrefixes := []*net.IPNet{ // IPv4 createIPNet(0, net.IPv4len*8), // world createIPNet(net.IPv4len*8, net.IPv4len*8), // hosts // IPv6 createIPNet(0, net.IPv6len*8), // world createIPNet(net.IPv6len*8, net.IPv6len*8), // hosts } _, err := counter.Add(defaultPrefixes) if err != nil { log.WithError(err).Fatal("Failed to create default prefix lengths") } return counter }
go
func createPrefixLengthCounter() *counter.PrefixLengthCounter { prefixLengths4 := ipcachemap.IPCache.GetMaxPrefixLengths(false) prefixLengths6 := ipcachemap.IPCache.GetMaxPrefixLengths(true) counter := counter.NewPrefixLengthCounter(prefixLengths6, prefixLengths4) // This is a bit ugly, but there's not a great way to define an IPNet // without parsing strings, etc. defaultPrefixes := []*net.IPNet{ // IPv4 createIPNet(0, net.IPv4len*8), // world createIPNet(net.IPv4len*8, net.IPv4len*8), // hosts // IPv6 createIPNet(0, net.IPv6len*8), // world createIPNet(net.IPv6len*8, net.IPv6len*8), // hosts } _, err := counter.Add(defaultPrefixes) if err != nil { log.WithError(err).Fatal("Failed to create default prefix lengths") } return counter }
[ "func", "createPrefixLengthCounter", "(", ")", "*", "counter", ".", "PrefixLengthCounter", "{", "prefixLengths4", ":=", "ipcachemap", ".", "IPCache", ".", "GetMaxPrefixLengths", "(", "false", ")", "\n", "prefixLengths6", ":=", "ipcachemap", ".", "IPCache", ".", "GetMaxPrefixLengths", "(", "true", ")", "\n", "counter", ":=", "counter", ".", "NewPrefixLengthCounter", "(", "prefixLengths6", ",", "prefixLengths4", ")", "\n\n", "// This is a bit ugly, but there's not a great way to define an IPNet", "// without parsing strings, etc.", "defaultPrefixes", ":=", "[", "]", "*", "net", ".", "IPNet", "{", "// IPv4", "createIPNet", "(", "0", ",", "net", ".", "IPv4len", "*", "8", ")", ",", "// world", "createIPNet", "(", "net", ".", "IPv4len", "*", "8", ",", "net", ".", "IPv4len", "*", "8", ")", ",", "// hosts", "// IPv6", "createIPNet", "(", "0", ",", "net", ".", "IPv6len", "*", "8", ")", ",", "// world", "createIPNet", "(", "net", ".", "IPv6len", "*", "8", ",", "net", ".", "IPv6len", "*", "8", ")", ",", "// hosts", "}", "\n", "_", ",", "err", ":=", "counter", ".", "Add", "(", "defaultPrefixes", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "WithError", "(", "err", ")", ".", "Fatal", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "counter", "\n", "}" ]
// createPrefixLengthCounter wraps around the counter library, providing // references to prefix lengths that will always be present.
[ "createPrefixLengthCounter", "wraps", "around", "the", "counter", "library", "providing", "references", "to", "prefix", "lengths", "that", "will", "always", "be", "present", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L869-L890
162,704
cilium/cilium
daemon/daemon.go
Close
func (d *Daemon) Close() { if d.policyTrigger != nil { d.policyTrigger.Shutdown() } d.nodeDiscovery.Close() }
go
func (d *Daemon) Close() { if d.policyTrigger != nil { d.policyTrigger.Shutdown() } d.nodeDiscovery.Close() }
[ "func", "(", "d", "*", "Daemon", ")", "Close", "(", ")", "{", "if", "d", ".", "policyTrigger", "!=", "nil", "{", "d", ".", "policyTrigger", ".", "Shutdown", "(", ")", "\n", "}", "\n", "d", ".", "nodeDiscovery", ".", "Close", "(", ")", "\n", "}" ]
// Close shuts down a daemon
[ "Close", "shuts", "down", "a", "daemon" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L1327-L1332
162,705
cilium/cilium
daemon/daemon.go
TriggerReloadWithoutCompile
func (d *Daemon) TriggerReloadWithoutCompile(reason string) (*sync.WaitGroup, error) { log.Debugf("BPF reload triggered from %s", reason) if err := d.compileBase(); err != nil { return nil, fmt.Errorf("Unable to recompile base programs from %s: %s", reason, err) } regenRequest := &endpoint.ExternalRegenerationMetadata{ Reason: reason, RegenerationLevel: endpoint.RegenerateWithDatapathLoad, } return endpointmanager.RegenerateAllEndpoints(d, regenRequest), nil }
go
func (d *Daemon) TriggerReloadWithoutCompile(reason string) (*sync.WaitGroup, error) { log.Debugf("BPF reload triggered from %s", reason) if err := d.compileBase(); err != nil { return nil, fmt.Errorf("Unable to recompile base programs from %s: %s", reason, err) } regenRequest := &endpoint.ExternalRegenerationMetadata{ Reason: reason, RegenerationLevel: endpoint.RegenerateWithDatapathLoad, } return endpointmanager.RegenerateAllEndpoints(d, regenRequest), nil }
[ "func", "(", "d", "*", "Daemon", ")", "TriggerReloadWithoutCompile", "(", "reason", "string", ")", "(", "*", "sync", ".", "WaitGroup", ",", "error", ")", "{", "log", ".", "Debugf", "(", "\"", "\"", ",", "reason", ")", "\n", "if", "err", ":=", "d", ".", "compileBase", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "reason", ",", "err", ")", "\n", "}", "\n\n", "regenRequest", ":=", "&", "endpoint", ".", "ExternalRegenerationMetadata", "{", "Reason", ":", "reason", ",", "RegenerationLevel", ":", "endpoint", ".", "RegenerateWithDatapathLoad", ",", "}", "\n", "return", "endpointmanager", ".", "RegenerateAllEndpoints", "(", "d", ",", "regenRequest", ")", ",", "nil", "\n", "}" ]
// TriggerReloadWithoutCompile causes all BPF programs and maps to be reloaded, // without recompiling the datapath logic for each endpoint. It first attempts // to recompile the base programs, and if this fails returns an error. If base // program load is successful, it subsequently triggers regeneration of all // endpoints and returns a waitgroup that may be used by the caller to wait for // all endpoint regeneration to complete. // // If an error is returned, then no regeneration was successful. If no error // is returned, then the base programs were successfully regenerated, but // endpoints may or may not have successfully regenerated.
[ "TriggerReloadWithoutCompile", "causes", "all", "BPF", "programs", "and", "maps", "to", "be", "reloaded", "without", "recompiling", "the", "datapath", "logic", "for", "each", "endpoint", ".", "It", "first", "attempts", "to", "recompile", "the", "base", "programs", "and", "if", "this", "fails", "returns", "an", "error", ".", "If", "base", "program", "load", "is", "successful", "it", "subsequently", "triggers", "regeneration", "of", "all", "endpoints", "and", "returns", "a", "waitgroup", "that", "may", "be", "used", "by", "the", "caller", "to", "wait", "for", "all", "endpoint", "regeneration", "to", "complete", ".", "If", "an", "error", "is", "returned", "then", "no", "regeneration", "was", "successful", ".", "If", "no", "error", "is", "returned", "then", "the", "base", "programs", "were", "successfully", "regenerated", "but", "endpoints", "may", "or", "may", "not", "have", "successfully", "regenerated", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L1372-L1383
162,706
cilium/cilium
daemon/daemon.go
listFilterIfs
func listFilterIfs(filter func(netlink.Link) int) (map[int]netlink.Link, error) { ifs, err := netlink.LinkList() if err != nil { return nil, err } vethLXCIdxs := map[int]netlink.Link{} for _, intf := range ifs { if idx := filter(intf); idx != -1 { vethLXCIdxs[idx] = intf } } return vethLXCIdxs, nil }
go
func listFilterIfs(filter func(netlink.Link) int) (map[int]netlink.Link, error) { ifs, err := netlink.LinkList() if err != nil { return nil, err } vethLXCIdxs := map[int]netlink.Link{} for _, intf := range ifs { if idx := filter(intf); idx != -1 { vethLXCIdxs[idx] = intf } } return vethLXCIdxs, nil }
[ "func", "listFilterIfs", "(", "filter", "func", "(", "netlink", ".", "Link", ")", "int", ")", "(", "map", "[", "int", "]", "netlink", ".", "Link", ",", "error", ")", "{", "ifs", ",", "err", ":=", "netlink", ".", "LinkList", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vethLXCIdxs", ":=", "map", "[", "int", "]", "netlink", ".", "Link", "{", "}", "\n", "for", "_", ",", "intf", ":=", "range", "ifs", "{", "if", "idx", ":=", "filter", "(", "intf", ")", ";", "idx", "!=", "-", "1", "{", "vethLXCIdxs", "[", "idx", "]", "=", "intf", "\n", "}", "\n", "}", "\n", "return", "vethLXCIdxs", ",", "nil", "\n", "}" ]
// listFilterIfs returns a map of interfaces based on the given filter. // The filter should take a link and, if found, return the index of that // interface, if not found return -1.
[ "listFilterIfs", "returns", "a", "map", "of", "interfaces", "based", "on", "the", "given", "filter", ".", "The", "filter", "should", "take", "a", "link", "and", "if", "found", "return", "the", "index", "of", "that", "interface", "if", "not", "found", "return", "-", "1", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L1524-L1536
162,707
cilium/cilium
daemon/daemon.go
clearCiliumVeths
func (d *Daemon) clearCiliumVeths() error { log.Info("Removing stale endpoint interfaces") leftVeths, err := listFilterIfs(func(intf netlink.Link) int { // Filter by veth and return the index of the interface. if intf.Type() == "veth" { return intf.Attrs().Index } return -1 }) if err != nil { return fmt.Errorf("unable to retrieve host network interfaces: %s", err) } for _, v := range leftVeths { peerIndex := v.Attrs().ParentIndex parentVeth, found := leftVeths[peerIndex] if found && peerIndex != 0 && strings.HasPrefix(parentVeth.Attrs().Name, "lxc") { err := netlink.LinkDel(v) if err != nil { log.WithError(err).Warningf("Unable to delete stale veth device %s", v.Attrs().Name) } } } return nil }
go
func (d *Daemon) clearCiliumVeths() error { log.Info("Removing stale endpoint interfaces") leftVeths, err := listFilterIfs(func(intf netlink.Link) int { // Filter by veth and return the index of the interface. if intf.Type() == "veth" { return intf.Attrs().Index } return -1 }) if err != nil { return fmt.Errorf("unable to retrieve host network interfaces: %s", err) } for _, v := range leftVeths { peerIndex := v.Attrs().ParentIndex parentVeth, found := leftVeths[peerIndex] if found && peerIndex != 0 && strings.HasPrefix(parentVeth.Attrs().Name, "lxc") { err := netlink.LinkDel(v) if err != nil { log.WithError(err).Warningf("Unable to delete stale veth device %s", v.Attrs().Name) } } } return nil }
[ "func", "(", "d", "*", "Daemon", ")", "clearCiliumVeths", "(", ")", "error", "{", "log", ".", "Info", "(", "\"", "\"", ")", "\n\n", "leftVeths", ",", "err", ":=", "listFilterIfs", "(", "func", "(", "intf", "netlink", ".", "Link", ")", "int", "{", "// Filter by veth and return the index of the interface.", "if", "intf", ".", "Type", "(", ")", "==", "\"", "\"", "{", "return", "intf", ".", "Attrs", "(", ")", ".", "Index", "\n", "}", "\n", "return", "-", "1", "\n", "}", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "for", "_", ",", "v", ":=", "range", "leftVeths", "{", "peerIndex", ":=", "v", ".", "Attrs", "(", ")", ".", "ParentIndex", "\n", "parentVeth", ",", "found", ":=", "leftVeths", "[", "peerIndex", "]", "\n", "if", "found", "&&", "peerIndex", "!=", "0", "&&", "strings", ".", "HasPrefix", "(", "parentVeth", ".", "Attrs", "(", ")", ".", "Name", ",", "\"", "\"", ")", "{", "err", ":=", "netlink", ".", "LinkDel", "(", "v", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "WithError", "(", "err", ")", ".", "Warningf", "(", "\"", "\"", ",", "v", ".", "Attrs", "(", ")", ".", "Name", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// clearCiliumVeths checks all veths created by cilium and removes all that // are considered a leftover from failed attempts to connect the container.
[ "clearCiliumVeths", "checks", "all", "veths", "created", "by", "cilium", "and", "removes", "all", "that", "are", "considered", "a", "leftover", "from", "failed", "attempts", "to", "connect", "the", "container", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L1540-L1566
162,708
cilium/cilium
daemon/daemon.go
numWorkerThreads
func numWorkerThreads() int { ncpu := runtime.NumCPU() minWorkerThreads := 2 if ncpu < minWorkerThreads { return minWorkerThreads } return ncpu }
go
func numWorkerThreads() int { ncpu := runtime.NumCPU() minWorkerThreads := 2 if ncpu < minWorkerThreads { return minWorkerThreads } return ncpu }
[ "func", "numWorkerThreads", "(", ")", "int", "{", "ncpu", ":=", "runtime", ".", "NumCPU", "(", ")", "\n", "minWorkerThreads", ":=", "2", "\n\n", "if", "ncpu", "<", "minWorkerThreads", "{", "return", "minWorkerThreads", "\n", "}", "\n", "return", "ncpu", "\n", "}" ]
// numWorkerThreads returns the number of worker threads with a minimum of 4.
[ "numWorkerThreads", "returns", "the", "number", "of", "worker", "threads", "with", "a", "minimum", "of", "4", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L1569-L1577
162,709
cilium/cilium
daemon/daemon.go
GetServiceList
func (d *Daemon) GetServiceList() []*models.Service { list := []*models.Service{} d.loadBalancer.BPFMapMU.RLock() defer d.loadBalancer.BPFMapMU.RUnlock() for _, v := range d.loadBalancer.SVCMap { list = append(list, v.GetModel()) } return list }
go
func (d *Daemon) GetServiceList() []*models.Service { list := []*models.Service{} d.loadBalancer.BPFMapMU.RLock() defer d.loadBalancer.BPFMapMU.RUnlock() for _, v := range d.loadBalancer.SVCMap { list = append(list, v.GetModel()) } return list }
[ "func", "(", "d", "*", "Daemon", ")", "GetServiceList", "(", ")", "[", "]", "*", "models", ".", "Service", "{", "list", ":=", "[", "]", "*", "models", ".", "Service", "{", "}", "\n\n", "d", ".", "loadBalancer", ".", "BPFMapMU", ".", "RLock", "(", ")", "\n", "defer", "d", ".", "loadBalancer", ".", "BPFMapMU", ".", "RUnlock", "(", ")", "\n\n", "for", "_", ",", "v", ":=", "range", "d", ".", "loadBalancer", ".", "SVCMap", "{", "list", "=", "append", "(", "list", ",", "v", ".", "GetModel", "(", ")", ")", "\n", "}", "\n", "return", "list", "\n", "}" ]
// GetServiceList returns list of services
[ "GetServiceList", "returns", "list", "of", "services" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L1580-L1590
162,710
cilium/cilium
daemon/daemon.go
SendNotification
func (d *Daemon) SendNotification(typ monitorAPI.AgentNotification, text string) error { if option.Config.DryMode { return nil } event := monitorAPI.AgentNotify{Type: typ, Text: text} return d.nodeMonitor.SendEvent(monitorAPI.MessageTypeAgent, event) }
go
func (d *Daemon) SendNotification(typ monitorAPI.AgentNotification, text string) error { if option.Config.DryMode { return nil } event := monitorAPI.AgentNotify{Type: typ, Text: text} return d.nodeMonitor.SendEvent(monitorAPI.MessageTypeAgent, event) }
[ "func", "(", "d", "*", "Daemon", ")", "SendNotification", "(", "typ", "monitorAPI", ".", "AgentNotification", ",", "text", "string", ")", "error", "{", "if", "option", ".", "Config", ".", "DryMode", "{", "return", "nil", "\n", "}", "\n", "event", ":=", "monitorAPI", ".", "AgentNotify", "{", "Type", ":", "typ", ",", "Text", ":", "text", "}", "\n", "return", "d", ".", "nodeMonitor", ".", "SendEvent", "(", "monitorAPI", ".", "MessageTypeAgent", ",", "event", ")", "\n", "}" ]
// SendNotification sends an agent notification to the monitor
[ "SendNotification", "sends", "an", "agent", "notification", "to", "the", "monitor" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L1593-L1599
162,711
cilium/cilium
daemon/daemon.go
NewProxyLogRecord
func (d *Daemon) NewProxyLogRecord(l *logger.LogRecord) error { return d.nodeMonitor.SendEvent(monitorAPI.MessageTypeAccessLog, l.LogRecord) }
go
func (d *Daemon) NewProxyLogRecord(l *logger.LogRecord) error { return d.nodeMonitor.SendEvent(monitorAPI.MessageTypeAccessLog, l.LogRecord) }
[ "func", "(", "d", "*", "Daemon", ")", "NewProxyLogRecord", "(", "l", "*", "logger", ".", "LogRecord", ")", "error", "{", "return", "d", ".", "nodeMonitor", ".", "SendEvent", "(", "monitorAPI", ".", "MessageTypeAccessLog", ",", "l", ".", "LogRecord", ")", "\n", "}" ]
// NewProxyLogRecord is invoked by the proxy accesslog on each new access log entry
[ "NewProxyLogRecord", "is", "invoked", "by", "the", "proxy", "accesslog", "on", "each", "new", "access", "log", "entry" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L1602-L1604
162,712
cilium/cilium
daemon/daemon.go
GetNodeSuffix
func (d *Daemon) GetNodeSuffix() string { var ip net.IP switch { case option.Config.EnableIPv4: ip = node.GetExternalIPv4() case option.Config.EnableIPv6: ip = node.GetIPv6() } if ip == nil { log.Fatal("Node IP not available yet") } return ip.String() }
go
func (d *Daemon) GetNodeSuffix() string { var ip net.IP switch { case option.Config.EnableIPv4: ip = node.GetExternalIPv4() case option.Config.EnableIPv6: ip = node.GetIPv6() } if ip == nil { log.Fatal("Node IP not available yet") } return ip.String() }
[ "func", "(", "d", "*", "Daemon", ")", "GetNodeSuffix", "(", ")", "string", "{", "var", "ip", "net", ".", "IP", "\n\n", "switch", "{", "case", "option", ".", "Config", ".", "EnableIPv4", ":", "ip", "=", "node", ".", "GetExternalIPv4", "(", ")", "\n", "case", "option", ".", "Config", ".", "EnableIPv6", ":", "ip", "=", "node", ".", "GetIPv6", "(", ")", "\n", "}", "\n\n", "if", "ip", "==", "nil", "{", "log", ".", "Fatal", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "ip", ".", "String", "(", ")", "\n", "}" ]
// GetNodeSuffix returns the suffix to be appended to kvstore keys of this // agent
[ "GetNodeSuffix", "returns", "the", "suffix", "to", "be", "appended", "to", "kvstore", "keys", "of", "this", "agent" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/daemon.go#L1608-L1623
162,713
cilium/cilium
pkg/kafka/request.go
String
func (req *RequestMessage) String() string { b, err := json.Marshal(req.request) if err != nil { return err.Error() } return fmt.Sprintf("apiKey=%d,apiVersion=%d,len=%d: %s", req.kind, req.version, len(req.rawMsg), string(b)) }
go
func (req *RequestMessage) String() string { b, err := json.Marshal(req.request) if err != nil { return err.Error() } return fmt.Sprintf("apiKey=%d,apiVersion=%d,len=%d: %s", req.kind, req.version, len(req.rawMsg), string(b)) }
[ "func", "(", "req", "*", "RequestMessage", ")", "String", "(", ")", "string", "{", "b", ",", "err", ":=", "json", ".", "Marshal", "(", "req", ".", "request", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", ".", "Error", "(", ")", "\n", "}", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "req", ".", "kind", ",", "req", ".", "version", ",", "len", "(", "req", ".", "rawMsg", ")", ",", "string", "(", "b", ")", ")", "\n", "}" ]
// String returns a human readable representation of the request message
[ "String", "returns", "a", "human", "readable", "representation", "of", "the", "request", "message" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kafka/request.go#L77-L85
162,714
cilium/cilium
pkg/kafka/request.go
GetTopics
func (req *RequestMessage) GetTopics() []string { if req.request == nil { return nil } switch val := req.request.(type) { case *proto.ProduceReq: return produceTopics(val) case *proto.FetchReq: return fetchTopics(val) case *proto.OffsetReq: return offsetTopics(val) case *proto.MetadataReq: return metadataTopics(val) case *proto.OffsetCommitReq: return offsetCommitTopics(val) case *proto.OffsetFetchReq: return offsetFetchTopics(val) } return nil }
go
func (req *RequestMessage) GetTopics() []string { if req.request == nil { return nil } switch val := req.request.(type) { case *proto.ProduceReq: return produceTopics(val) case *proto.FetchReq: return fetchTopics(val) case *proto.OffsetReq: return offsetTopics(val) case *proto.MetadataReq: return metadataTopics(val) case *proto.OffsetCommitReq: return offsetCommitTopics(val) case *proto.OffsetFetchReq: return offsetFetchTopics(val) } return nil }
[ "func", "(", "req", "*", "RequestMessage", ")", "GetTopics", "(", ")", "[", "]", "string", "{", "if", "req", ".", "request", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "switch", "val", ":=", "req", ".", "request", ".", "(", "type", ")", "{", "case", "*", "proto", ".", "ProduceReq", ":", "return", "produceTopics", "(", "val", ")", "\n", "case", "*", "proto", ".", "FetchReq", ":", "return", "fetchTopics", "(", "val", ")", "\n", "case", "*", "proto", ".", "OffsetReq", ":", "return", "offsetTopics", "(", "val", ")", "\n", "case", "*", "proto", ".", "MetadataReq", ":", "return", "metadataTopics", "(", "val", ")", "\n", "case", "*", "proto", ".", "OffsetCommitReq", ":", "return", "offsetCommitTopics", "(", "val", ")", "\n", "case", "*", "proto", ".", "OffsetFetchReq", ":", "return", "offsetFetchTopics", "(", "val", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetTopics returns the Kafka request list of topics
[ "GetTopics", "returns", "the", "Kafka", "request", "list", "of", "topics" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kafka/request.go#L88-L108
162,715
cilium/cilium
pkg/kafka/request.go
CreateResponse
func (req *RequestMessage) CreateResponse(err error) (*ResponseMessage, error) { switch val := req.request.(type) { case *proto.ProduceReq: return createProduceResponse(val, err) case *proto.FetchReq: return createFetchResponse(val, err) case *proto.OffsetReq: return createOffsetResponse(val, err) case *proto.MetadataReq: return createMetadataResponse(val, err) case *proto.ConsumerMetadataReq: return createConsumerMetadataResponse(val, err) case *proto.OffsetCommitReq: return createOffsetCommitResponse(val, err) case *proto.OffsetFetchReq: return createOffsetFetchResponse(val, err) case nil: return nil, fmt.Errorf("unsupported request API key %d", req.kind) default: // The switch cases above must correspond exactly to the switch cases // in ReadRequest. log.Panic(fmt.Sprintf("Kafka API key not handled: %d", req.kind)) } return nil, nil }
go
func (req *RequestMessage) CreateResponse(err error) (*ResponseMessage, error) { switch val := req.request.(type) { case *proto.ProduceReq: return createProduceResponse(val, err) case *proto.FetchReq: return createFetchResponse(val, err) case *proto.OffsetReq: return createOffsetResponse(val, err) case *proto.MetadataReq: return createMetadataResponse(val, err) case *proto.ConsumerMetadataReq: return createConsumerMetadataResponse(val, err) case *proto.OffsetCommitReq: return createOffsetCommitResponse(val, err) case *proto.OffsetFetchReq: return createOffsetFetchResponse(val, err) case nil: return nil, fmt.Errorf("unsupported request API key %d", req.kind) default: // The switch cases above must correspond exactly to the switch cases // in ReadRequest. log.Panic(fmt.Sprintf("Kafka API key not handled: %d", req.kind)) } return nil, nil }
[ "func", "(", "req", "*", "RequestMessage", ")", "CreateResponse", "(", "err", "error", ")", "(", "*", "ResponseMessage", ",", "error", ")", "{", "switch", "val", ":=", "req", ".", "request", ".", "(", "type", ")", "{", "case", "*", "proto", ".", "ProduceReq", ":", "return", "createProduceResponse", "(", "val", ",", "err", ")", "\n", "case", "*", "proto", ".", "FetchReq", ":", "return", "createFetchResponse", "(", "val", ",", "err", ")", "\n", "case", "*", "proto", ".", "OffsetReq", ":", "return", "createOffsetResponse", "(", "val", ",", "err", ")", "\n", "case", "*", "proto", ".", "MetadataReq", ":", "return", "createMetadataResponse", "(", "val", ",", "err", ")", "\n", "case", "*", "proto", ".", "ConsumerMetadataReq", ":", "return", "createConsumerMetadataResponse", "(", "val", ",", "err", ")", "\n", "case", "*", "proto", ".", "OffsetCommitReq", ":", "return", "createOffsetCommitResponse", "(", "val", ",", "err", ")", "\n", "case", "*", "proto", ".", "OffsetFetchReq", ":", "return", "createOffsetFetchResponse", "(", "val", ",", "err", ")", "\n", "case", "nil", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "req", ".", "kind", ")", "\n", "default", ":", "// The switch cases above must correspond exactly to the switch cases", "// in ReadRequest.", "log", ".", "Panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "req", ".", "kind", ")", ")", "\n", "}", "\n", "return", "nil", ",", "nil", "\n", "}" ]
// CreateResponse creates a response message based on the provided request // message. The response will have the specified error code set in all topics // and embedded partitions.
[ "CreateResponse", "creates", "a", "response", "message", "based", "on", "the", "provided", "request", "message", ".", "The", "response", "will", "have", "the", "specified", "error", "code", "set", "in", "all", "topics", "and", "embedded", "partitions", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kafka/request.go#L158-L182
162,716
cilium/cilium
pkg/kafka/request.go
ReadRequest
func ReadRequest(reader io.Reader) (*RequestMessage, error) { req := &RequestMessage{} var err error req.kind, req.rawMsg, err = proto.ReadReq(reader) if err != nil { return nil, err } if len(req.rawMsg) < 12 { return nil, fmt.Errorf("unexpected end of request (length < 12 bytes)") } req.version = req.extractVersion() var nilSlice []byte buf := bytes.NewBuffer(append(nilSlice, req.rawMsg...)) switch req.kind { case proto.ProduceReqKind: req.request, err = proto.ReadProduceReq(buf) case proto.FetchReqKind: req.request, err = proto.ReadFetchReq(buf) case proto.OffsetReqKind: req.request, err = proto.ReadOffsetReq(buf) case proto.MetadataReqKind: req.request, err = proto.ReadMetadataReq(buf) case proto.ConsumerMetadataReqKind: req.request, err = proto.ReadConsumerMetadataReq(buf) case proto.OffsetCommitReqKind: req.request, err = proto.ReadOffsetCommitReq(buf) case proto.OffsetFetchReqKind: req.request, err = proto.ReadOffsetFetchReq(buf) default: log.WithField(fieldRequest, req.String()).Debugf("Unknown Kafka request API key: %d", req.kind) } if err != nil { flowdebug.Log(log.WithField(fieldRequest, req.String()).WithError(err), "Ignoring Kafka message due to parse error") return nil, err } return req, nil }
go
func ReadRequest(reader io.Reader) (*RequestMessage, error) { req := &RequestMessage{} var err error req.kind, req.rawMsg, err = proto.ReadReq(reader) if err != nil { return nil, err } if len(req.rawMsg) < 12 { return nil, fmt.Errorf("unexpected end of request (length < 12 bytes)") } req.version = req.extractVersion() var nilSlice []byte buf := bytes.NewBuffer(append(nilSlice, req.rawMsg...)) switch req.kind { case proto.ProduceReqKind: req.request, err = proto.ReadProduceReq(buf) case proto.FetchReqKind: req.request, err = proto.ReadFetchReq(buf) case proto.OffsetReqKind: req.request, err = proto.ReadOffsetReq(buf) case proto.MetadataReqKind: req.request, err = proto.ReadMetadataReq(buf) case proto.ConsumerMetadataReqKind: req.request, err = proto.ReadConsumerMetadataReq(buf) case proto.OffsetCommitReqKind: req.request, err = proto.ReadOffsetCommitReq(buf) case proto.OffsetFetchReqKind: req.request, err = proto.ReadOffsetFetchReq(buf) default: log.WithField(fieldRequest, req.String()).Debugf("Unknown Kafka request API key: %d", req.kind) } if err != nil { flowdebug.Log(log.WithField(fieldRequest, req.String()).WithError(err), "Ignoring Kafka message due to parse error") return nil, err } return req, nil }
[ "func", "ReadRequest", "(", "reader", "io", ".", "Reader", ")", "(", "*", "RequestMessage", ",", "error", ")", "{", "req", ":=", "&", "RequestMessage", "{", "}", "\n", "var", "err", "error", "\n\n", "req", ".", "kind", ",", "req", ".", "rawMsg", ",", "err", "=", "proto", ".", "ReadReq", "(", "reader", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "req", ".", "rawMsg", ")", "<", "12", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "req", ".", "version", "=", "req", ".", "extractVersion", "(", ")", "\n\n", "var", "nilSlice", "[", "]", "byte", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "append", "(", "nilSlice", ",", "req", ".", "rawMsg", "...", ")", ")", "\n\n", "switch", "req", ".", "kind", "{", "case", "proto", ".", "ProduceReqKind", ":", "req", ".", "request", ",", "err", "=", "proto", ".", "ReadProduceReq", "(", "buf", ")", "\n", "case", "proto", ".", "FetchReqKind", ":", "req", ".", "request", ",", "err", "=", "proto", ".", "ReadFetchReq", "(", "buf", ")", "\n", "case", "proto", ".", "OffsetReqKind", ":", "req", ".", "request", ",", "err", "=", "proto", ".", "ReadOffsetReq", "(", "buf", ")", "\n", "case", "proto", ".", "MetadataReqKind", ":", "req", ".", "request", ",", "err", "=", "proto", ".", "ReadMetadataReq", "(", "buf", ")", "\n", "case", "proto", ".", "ConsumerMetadataReqKind", ":", "req", ".", "request", ",", "err", "=", "proto", ".", "ReadConsumerMetadataReq", "(", "buf", ")", "\n", "case", "proto", ".", "OffsetCommitReqKind", ":", "req", ".", "request", ",", "err", "=", "proto", ".", "ReadOffsetCommitReq", "(", "buf", ")", "\n", "case", "proto", ".", "OffsetFetchReqKind", ":", "req", ".", "request", ",", "err", "=", "proto", ".", "ReadOffsetFetchReq", "(", "buf", ")", "\n", "default", ":", "log", ".", "WithField", "(", "fieldRequest", ",", "req", ".", "String", "(", ")", ")", ".", "Debugf", "(", "\"", "\"", ",", "req", ".", "kind", ")", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "flowdebug", ".", "Log", "(", "log", ".", "WithField", "(", "fieldRequest", ",", "req", ".", "String", "(", ")", ")", ".", "WithError", "(", "err", ")", ",", "\"", "\"", ")", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "return", "req", ",", "nil", "\n", "}" ]
// ReadRequest will read a Kafka request from an io.Reader and return the // message or an error.
[ "ReadRequest", "will", "read", "a", "Kafka", "request", "from", "an", "io", ".", "Reader", "and", "return", "the", "message", "or", "an", "error", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kafka/request.go#L186-L229
162,717
cilium/cilium
pkg/tuple/ipv6.go
ToNetwork
func (k *TupleKey6) ToNetwork() TupleKey { n := *k n.SourcePort = byteorder.HostToNetwork(n.SourcePort).(uint16) n.DestPort = byteorder.HostToNetwork(n.DestPort).(uint16) return &n }
go
func (k *TupleKey6) ToNetwork() TupleKey { n := *k n.SourcePort = byteorder.HostToNetwork(n.SourcePort).(uint16) n.DestPort = byteorder.HostToNetwork(n.DestPort).(uint16) return &n }
[ "func", "(", "k", "*", "TupleKey6", ")", "ToNetwork", "(", ")", "TupleKey", "{", "n", ":=", "*", "k", "\n", "n", ".", "SourcePort", "=", "byteorder", ".", "HostToNetwork", "(", "n", ".", "SourcePort", ")", ".", "(", "uint16", ")", "\n", "n", ".", "DestPort", "=", "byteorder", ".", "HostToNetwork", "(", "n", ".", "DestPort", ")", ".", "(", "uint16", ")", "\n", "return", "&", "n", "\n", "}" ]
// ToNetwork converts TupleKey6 ports to network byte order.
[ "ToNetwork", "converts", "TupleKey6", "ports", "to", "network", "byte", "order", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/tuple/ipv6.go#L47-L52
162,718
cilium/cilium
pkg/tuple/ipv6.go
ToHost
func (k *TupleKey6) ToHost() TupleKey { n := *k n.SourcePort = byteorder.NetworkToHost(n.SourcePort).(uint16) n.DestPort = byteorder.NetworkToHost(n.DestPort).(uint16) return &n }
go
func (k *TupleKey6) ToHost() TupleKey { n := *k n.SourcePort = byteorder.NetworkToHost(n.SourcePort).(uint16) n.DestPort = byteorder.NetworkToHost(n.DestPort).(uint16) return &n }
[ "func", "(", "k", "*", "TupleKey6", ")", "ToHost", "(", ")", "TupleKey", "{", "n", ":=", "*", "k", "\n", "n", ".", "SourcePort", "=", "byteorder", ".", "NetworkToHost", "(", "n", ".", "SourcePort", ")", ".", "(", "uint16", ")", "\n", "n", ".", "DestPort", "=", "byteorder", ".", "NetworkToHost", "(", "n", ".", "DestPort", ")", ".", "(", "uint16", ")", "\n", "return", "&", "n", "\n", "}" ]
// ToHost converts TupleKey6 ports to network byte order.
[ "ToHost", "converts", "TupleKey6", "ports", "to", "network", "byte", "order", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/tuple/ipv6.go#L55-L60
162,719
cilium/cilium
pkg/tuple/ipv6.go
ToNetwork
func (k *TupleKey6Global) ToNetwork() TupleKey { return &TupleKey6Global{ TupleKey6: *k.TupleKey6.ToNetwork().(*TupleKey6), } }
go
func (k *TupleKey6Global) ToNetwork() TupleKey { return &TupleKey6Global{ TupleKey6: *k.TupleKey6.ToNetwork().(*TupleKey6), } }
[ "func", "(", "k", "*", "TupleKey6Global", ")", "ToNetwork", "(", ")", "TupleKey", "{", "return", "&", "TupleKey6Global", "{", "TupleKey6", ":", "*", "k", ".", "TupleKey6", ".", "ToNetwork", "(", ")", ".", "(", "*", "TupleKey6", ")", ",", "}", "\n", "}" ]
// ToNetwork converts ports to network byte order. // // This is necessary to prevent callers from implicitly converting // the TupleKey6Global type here into a local key type in the nested // TupleKey6 field.
[ "ToNetwork", "converts", "ports", "to", "network", "byte", "order", ".", "This", "is", "necessary", "to", "prevent", "callers", "from", "implicitly", "converting", "the", "TupleKey6Global", "type", "here", "into", "a", "local", "key", "type", "in", "the", "nested", "TupleKey6", "field", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/tuple/ipv6.go#L131-L135
162,720
cilium/cilium
pkg/tuple/ipv6.go
ToHost
func (k *TupleKey6Global) ToHost() TupleKey { return &TupleKey6Global{ TupleKey6: *k.TupleKey6.ToHost().(*TupleKey6), } }
go
func (k *TupleKey6Global) ToHost() TupleKey { return &TupleKey6Global{ TupleKey6: *k.TupleKey6.ToHost().(*TupleKey6), } }
[ "func", "(", "k", "*", "TupleKey6Global", ")", "ToHost", "(", ")", "TupleKey", "{", "return", "&", "TupleKey6Global", "{", "TupleKey6", ":", "*", "k", ".", "TupleKey6", ".", "ToHost", "(", ")", ".", "(", "*", "TupleKey6", ")", ",", "}", "\n", "}" ]
// ToHost converts ports to host byte order. // // This is necessary to prevent callers from implicitly converting // the TupleKey6Global type here into a local key type in the nested // TupleKey6 field.
[ "ToHost", "converts", "ports", "to", "host", "byte", "order", ".", "This", "is", "necessary", "to", "prevent", "callers", "from", "implicitly", "converting", "the", "TupleKey6Global", "type", "here", "into", "a", "local", "key", "type", "in", "the", "nested", "TupleKey6", "field", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/tuple/ipv6.go#L142-L146
162,721
cilium/cilium
pkg/datapath/linux/datapath.go
NewDatapath
func NewDatapath(config DatapathConfiguration) datapath.Datapath { dp := &linuxDatapath{ nodeAddressing: NewNodeAddressing(), config: config, } dp.node = NewNodeHandler(config, dp.nodeAddressing) return dp }
go
func NewDatapath(config DatapathConfiguration) datapath.Datapath { dp := &linuxDatapath{ nodeAddressing: NewNodeAddressing(), config: config, } dp.node = NewNodeHandler(config, dp.nodeAddressing) return dp }
[ "func", "NewDatapath", "(", "config", "DatapathConfiguration", ")", "datapath", ".", "Datapath", "{", "dp", ":=", "&", "linuxDatapath", "{", "nodeAddressing", ":", "NewNodeAddressing", "(", ")", ",", "config", ":", "config", ",", "}", "\n\n", "dp", ".", "node", "=", "NewNodeHandler", "(", "config", ",", "dp", ".", "nodeAddressing", ")", "\n\n", "return", "dp", "\n", "}" ]
// NewDatapath creates a new Linux datapath
[ "NewDatapath", "creates", "a", "new", "Linux", "datapath" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/datapath/linux/datapath.go#L38-L47
162,722
cilium/cilium
pkg/policy/api/ingress.go
GetSourceEndpointSelectors
func (i *IngressRule) GetSourceEndpointSelectors() EndpointSelectorSlice { if i.aggregatedSelectors == nil { i.SetAggregatedSelectors() } return i.aggregatedSelectors }
go
func (i *IngressRule) GetSourceEndpointSelectors() EndpointSelectorSlice { if i.aggregatedSelectors == nil { i.SetAggregatedSelectors() } return i.aggregatedSelectors }
[ "func", "(", "i", "*", "IngressRule", ")", "GetSourceEndpointSelectors", "(", ")", "EndpointSelectorSlice", "{", "if", "i", ".", "aggregatedSelectors", "==", "nil", "{", "i", ".", "SetAggregatedSelectors", "(", ")", "\n", "}", "\n", "return", "i", ".", "aggregatedSelectors", "\n", "}" ]
// GetSourceEndpointSelectors returns a slice of endpoints selectors covering // all L3 source selectors of the ingress rule
[ "GetSourceEndpointSelectors", "returns", "a", "slice", "of", "endpoints", "selectors", "covering", "all", "L3", "source", "selectors", "of", "the", "ingress", "rule" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/ingress.go#L130-L135
162,723
cilium/cilium
pkg/policy/api/ingress.go
IsLabelBased
func (i *IngressRule) IsLabelBased() bool { return len(i.FromRequires)+len(i.FromCIDR)+len(i.FromCIDRSet) == 0 }
go
func (i *IngressRule) IsLabelBased() bool { return len(i.FromRequires)+len(i.FromCIDR)+len(i.FromCIDRSet) == 0 }
[ "func", "(", "i", "*", "IngressRule", ")", "IsLabelBased", "(", ")", "bool", "{", "return", "len", "(", "i", ".", "FromRequires", ")", "+", "len", "(", "i", ".", "FromCIDR", ")", "+", "len", "(", "i", ".", "FromCIDRSet", ")", "==", "0", "\n", "}" ]
// IsLabelBased returns true whether the L3 source endpoints are selected based // on labels, i.e. either by setting FromEndpoints or FromEntities, or not // setting any From field.
[ "IsLabelBased", "returns", "true", "whether", "the", "L3", "source", "endpoints", "are", "selected", "based", "on", "labels", "i", ".", "e", ".", "either", "by", "setting", "FromEndpoints", "or", "FromEntities", "or", "not", "setting", "any", "From", "field", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/ingress.go#L140-L142
162,724
cilium/cilium
pkg/kvstore/etcd.go
Hint
func Hint(err error) error { switch err { case ctx.DeadlineExceeded: return fmt.Errorf("etcd client timeout exceeded") default: return err } }
go
func Hint(err error) error { switch err { case ctx.DeadlineExceeded: return fmt.Errorf("etcd client timeout exceeded") default: return err } }
[ "func", "Hint", "(", "err", "error", ")", "error", "{", "switch", "err", "{", "case", "ctx", ".", "DeadlineExceeded", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "default", ":", "return", "err", "\n", "}", "\n", "}" ]
// Hint tries to improve the error message displayed to te user.
[ "Hint", "tries", "to", "improve", "the", "error", "message", "displayed", "to", "te", "user", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/etcd.go#L196-L203
162,725
cilium/cilium
pkg/kvstore/etcd.go
GetLeaseID
func (e *etcdClient) GetLeaseID() client.LeaseID { e.RWMutex.RLock() l := e.session.Lease() e.RWMutex.RUnlock() return l }
go
func (e *etcdClient) GetLeaseID() client.LeaseID { e.RWMutex.RLock() l := e.session.Lease() e.RWMutex.RUnlock() return l }
[ "func", "(", "e", "*", "etcdClient", ")", "GetLeaseID", "(", ")", "client", ".", "LeaseID", "{", "e", ".", "RWMutex", ".", "RLock", "(", ")", "\n", "l", ":=", "e", ".", "session", ".", "Lease", "(", ")", "\n", "e", ".", "RWMutex", ".", "RUnlock", "(", ")", "\n", "return", "l", "\n", "}" ]
// GetLeaseID returns the current lease ID.
[ "GetLeaseID", "returns", "the", "current", "lease", "ID", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/etcd.go#L263-L268
162,726
cilium/cilium
pkg/kvstore/etcd.go
closeSession
func (e *etcdClient) closeSession(leaseID client.LeaseID) { e.RWMutex.RLock() // only mark a session as orphan if the leaseID is the same as the // session ID to avoid making any other sessions as orphan. if e.session.Lease() == leaseID { e.session.Orphan() } e.RWMutex.RUnlock() }
go
func (e *etcdClient) closeSession(leaseID client.LeaseID) { e.RWMutex.RLock() // only mark a session as orphan if the leaseID is the same as the // session ID to avoid making any other sessions as orphan. if e.session.Lease() == leaseID { e.session.Orphan() } e.RWMutex.RUnlock() }
[ "func", "(", "e", "*", "etcdClient", ")", "closeSession", "(", "leaseID", "client", ".", "LeaseID", ")", "{", "e", ".", "RWMutex", ".", "RLock", "(", ")", "\n", "// only mark a session as orphan if the leaseID is the same as the", "// session ID to avoid making any other sessions as orphan.", "if", "e", ".", "session", ".", "Lease", "(", ")", "==", "leaseID", "{", "e", ".", "session", ".", "Orphan", "(", ")", "\n", "}", "\n", "e", ".", "RWMutex", ".", "RUnlock", "(", ")", "\n", "}" ]
// closeSession closes the current session.
[ "closeSession", "closes", "the", "current", "session", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/etcd.go#L282-L290
162,727
cilium/cilium
pkg/kvstore/etcd.go
Disconnected
func (e *etcdClient) Disconnected() <-chan struct{} { <-e.firstSession e.RLock() ch := e.session.Done() e.RUnlock() return ch }
go
func (e *etcdClient) Disconnected() <-chan struct{} { <-e.firstSession e.RLock() ch := e.session.Done() e.RUnlock() return ch }
[ "func", "(", "e", "*", "etcdClient", ")", "Disconnected", "(", ")", "<-", "chan", "struct", "{", "}", "{", "<-", "e", ".", "firstSession", "\n", "e", ".", "RLock", "(", ")", "\n", "ch", ":=", "e", ".", "session", ".", "Done", "(", ")", "\n", "e", ".", "RUnlock", "(", ")", "\n", "return", "ch", "\n", "}" ]
// Disconnected closes the returned channel when the etcd client is // disconnected after being reconnected. Blocks until the etcd client is first // connected with the kvstore.
[ "Disconnected", "closes", "the", "returned", "channel", "when", "the", "etcd", "client", "is", "disconnected", "after", "being", "reconnected", ".", "Blocks", "until", "the", "etcd", "client", "is", "first", "connected", "with", "the", "kvstore", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/etcd.go#L325-L331
162,728
cilium/cilium
pkg/kvstore/etcd.go
checkMinVersion
func (e *etcdClient) checkMinVersion() error { eps := e.client.Endpoints() for _, ep := range eps { v, err := getEPVersion(e.client.Maintenance, ep, versionCheckTimeout) if err != nil { e.getLogger().WithError(Hint(err)).WithField(fieldEtcdEndpoint, ep). Warn("Unable to verify version of etcd endpoint") continue } if !minRequiredVersion.Check(v) { return fmt.Errorf("minimal etcd version not met in %q, required: %s, found: %s", ep, minRequiredVersion.String(), v.String()) } e.getLogger().WithFields(logrus.Fields{ fieldEtcdEndpoint: ep, "version": v, }).Info("Successfully verified version of etcd endpoint") } if len(eps) == 0 { e.getLogger().Warn("Minimal etcd version unknown: No etcd endpoints available") } return nil }
go
func (e *etcdClient) checkMinVersion() error { eps := e.client.Endpoints() for _, ep := range eps { v, err := getEPVersion(e.client.Maintenance, ep, versionCheckTimeout) if err != nil { e.getLogger().WithError(Hint(err)).WithField(fieldEtcdEndpoint, ep). Warn("Unable to verify version of etcd endpoint") continue } if !minRequiredVersion.Check(v) { return fmt.Errorf("minimal etcd version not met in %q, required: %s, found: %s", ep, minRequiredVersion.String(), v.String()) } e.getLogger().WithFields(logrus.Fields{ fieldEtcdEndpoint: ep, "version": v, }).Info("Successfully verified version of etcd endpoint") } if len(eps) == 0 { e.getLogger().Warn("Minimal etcd version unknown: No etcd endpoints available") } return nil }
[ "func", "(", "e", "*", "etcdClient", ")", "checkMinVersion", "(", ")", "error", "{", "eps", ":=", "e", ".", "client", ".", "Endpoints", "(", ")", "\n\n", "for", "_", ",", "ep", ":=", "range", "eps", "{", "v", ",", "err", ":=", "getEPVersion", "(", "e", ".", "client", ".", "Maintenance", ",", "ep", ",", "versionCheckTimeout", ")", "\n", "if", "err", "!=", "nil", "{", "e", ".", "getLogger", "(", ")", ".", "WithError", "(", "Hint", "(", "err", ")", ")", ".", "WithField", "(", "fieldEtcdEndpoint", ",", "ep", ")", ".", "Warn", "(", "\"", "\"", ")", "\n", "continue", "\n", "}", "\n\n", "if", "!", "minRequiredVersion", ".", "Check", "(", "v", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ep", ",", "minRequiredVersion", ".", "String", "(", ")", ",", "v", ".", "String", "(", ")", ")", "\n", "}", "\n\n", "e", ".", "getLogger", "(", ")", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "fieldEtcdEndpoint", ":", "ep", ",", "\"", "\"", ":", "v", ",", "}", ")", ".", "Info", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "len", "(", "eps", ")", "==", "0", "{", "e", ".", "getLogger", "(", ")", ".", "Warn", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// checkMinVersion checks the minimal version running on etcd cluster. This // function should be run whenever the etcd client is connected for the first // time and whenever the session is renewed.
[ "checkMinVersion", "checks", "the", "minimal", "version", "running", "on", "etcd", "cluster", ".", "This", "function", "should", "be", "run", "whenever", "the", "etcd", "client", "is", "connected", "for", "the", "first", "time", "and", "whenever", "the", "session", "is", "renewed", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/etcd.go#L474-L501
162,729
cilium/cilium
pkg/kvstore/etcd.go
Update
func (e *etcdClient) Update(ctx context.Context, key string, value []byte, lease bool) error { select { case <-e.firstSession: case <-ctx.Done(): return fmt.Errorf("update cancelled via context: %s", ctx.Err()) } if lease { duration := spanstat.Start() leaseID := e.GetLeaseID() e.limiter.Wait(ctx) _, err := e.client.Put(ctx, key, string(value), client.WithLease(leaseID)) e.checkSession(err, leaseID) increaseMetric(key, metricSet, "Update", duration.EndError(err).Total(), err) return Hint(err) } duration := spanstat.Start() e.limiter.Wait(ctx) _, err := e.client.Put(ctx, key, string(value)) increaseMetric(key, metricSet, "Update", duration.EndError(err).Total(), err) return Hint(err) }
go
func (e *etcdClient) Update(ctx context.Context, key string, value []byte, lease bool) error { select { case <-e.firstSession: case <-ctx.Done(): return fmt.Errorf("update cancelled via context: %s", ctx.Err()) } if lease { duration := spanstat.Start() leaseID := e.GetLeaseID() e.limiter.Wait(ctx) _, err := e.client.Put(ctx, key, string(value), client.WithLease(leaseID)) e.checkSession(err, leaseID) increaseMetric(key, metricSet, "Update", duration.EndError(err).Total(), err) return Hint(err) } duration := spanstat.Start() e.limiter.Wait(ctx) _, err := e.client.Put(ctx, key, string(value)) increaseMetric(key, metricSet, "Update", duration.EndError(err).Total(), err) return Hint(err) }
[ "func", "(", "e", "*", "etcdClient", ")", "Update", "(", "ctx", "context", ".", "Context", ",", "key", "string", ",", "value", "[", "]", "byte", ",", "lease", "bool", ")", "error", "{", "select", "{", "case", "<-", "e", ".", "firstSession", ":", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ctx", ".", "Err", "(", ")", ")", "\n", "}", "\n\n", "if", "lease", "{", "duration", ":=", "spanstat", ".", "Start", "(", ")", "\n", "leaseID", ":=", "e", ".", "GetLeaseID", "(", ")", "\n", "e", ".", "limiter", ".", "Wait", "(", "ctx", ")", "\n", "_", ",", "err", ":=", "e", ".", "client", ".", "Put", "(", "ctx", ",", "key", ",", "string", "(", "value", ")", ",", "client", ".", "WithLease", "(", "leaseID", ")", ")", "\n", "e", ".", "checkSession", "(", "err", ",", "leaseID", ")", "\n", "increaseMetric", "(", "key", ",", "metricSet", ",", "\"", "\"", ",", "duration", ".", "EndError", "(", "err", ")", ".", "Total", "(", ")", ",", "err", ")", "\n", "return", "Hint", "(", "err", ")", "\n", "}", "\n\n", "duration", ":=", "spanstat", ".", "Start", "(", ")", "\n", "e", ".", "limiter", ".", "Wait", "(", "ctx", ")", "\n", "_", ",", "err", ":=", "e", ".", "client", ".", "Put", "(", "ctx", ",", "key", ",", "string", "(", "value", ")", ")", "\n", "increaseMetric", "(", "key", ",", "metricSet", ",", "\"", "\"", ",", "duration", ".", "EndError", "(", "err", ")", ".", "Total", "(", ")", ",", "err", ")", "\n", "return", "Hint", "(", "err", ")", "\n", "}" ]
// Update creates or updates a key
[ "Update", "creates", "or", "updates", "a", "key" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/etcd.go#L797-L819
162,730
cilium/cilium
pkg/kvstore/etcd.go
Close
func (e *etcdClient) Close() { close(e.stopStatusChecker) <-e.firstSession if e.controllers != nil { e.controllers.RemoveAll() } e.RLock() defer e.RUnlock() e.session.Close() e.client.Close() }
go
func (e *etcdClient) Close() { close(e.stopStatusChecker) <-e.firstSession if e.controllers != nil { e.controllers.RemoveAll() } e.RLock() defer e.RUnlock() e.session.Close() e.client.Close() }
[ "func", "(", "e", "*", "etcdClient", ")", "Close", "(", ")", "{", "close", "(", "e", ".", "stopStatusChecker", ")", "\n", "<-", "e", ".", "firstSession", "\n", "if", "e", ".", "controllers", "!=", "nil", "{", "e", ".", "controllers", ".", "RemoveAll", "(", ")", "\n", "}", "\n", "e", ".", "RLock", "(", ")", "\n", "defer", "e", ".", "RUnlock", "(", ")", "\n", "e", ".", "session", ".", "Close", "(", ")", "\n", "e", ".", "client", ".", "Close", "(", ")", "\n", "}" ]
// Close closes the etcd session
[ "Close", "closes", "the", "etcd", "session" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/etcd.go#L926-L936
162,731
cilium/cilium
pkg/kvstore/etcd.go
ListAndWatch
func (e *etcdClient) ListAndWatch(name, prefix string, chanSize int) *Watcher { w := newWatcher(name, prefix, chanSize) e.getLogger().WithField(fieldWatcher, w).Debug("Starting watcher...") go e.Watch(w) return w }
go
func (e *etcdClient) ListAndWatch(name, prefix string, chanSize int) *Watcher { w := newWatcher(name, prefix, chanSize) e.getLogger().WithField(fieldWatcher, w).Debug("Starting watcher...") go e.Watch(w) return w }
[ "func", "(", "e", "*", "etcdClient", ")", "ListAndWatch", "(", "name", ",", "prefix", "string", ",", "chanSize", "int", ")", "*", "Watcher", "{", "w", ":=", "newWatcher", "(", "name", ",", "prefix", ",", "chanSize", ")", "\n\n", "e", ".", "getLogger", "(", ")", ".", "WithField", "(", "fieldWatcher", ",", "w", ")", ".", "Debug", "(", "\"", "\"", ")", "\n\n", "go", "e", ".", "Watch", "(", "w", ")", "\n\n", "return", "w", "\n", "}" ]
// ListAndWatch implements the BackendOperations.ListAndWatch using etcd
[ "ListAndWatch", "implements", "the", "BackendOperations", ".", "ListAndWatch", "using", "etcd" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/etcd.go#L954-L962
162,732
cilium/cilium
pkg/kvstore/etcd.go
IsEtcdOperator
func IsEtcdOperator(selectedBackend string, opts map[string]string, k8sNamespace string) bool { if selectedBackend != EtcdBackendName { return false } fqdnIsEtcdOperator := func(address string) bool { u, err := url.Parse(address) if err != nil { return false } // typical service name "cilium-etcd-client.kube-system.svc" names := strings.Split(u.Hostname(), ".") return len(names) >= 2 && names[0] == "cilium-etcd-client" && names[1] == k8sNamespace } fqdn := opts[addrOption] if len(fqdn) != 0 { return fqdnIsEtcdOperator(fqdn) } bm := newEtcdModule() err := bm.setConfig(opts) if err != nil { return false } etcdConfig := bm.getConfig()[EtcdOptionConfig] if len(etcdConfig) == 0 { return false } cfg, err := clientyaml.NewConfig(etcdConfig) if err != nil { log.WithError(err).Error("Unable to read etcd configuration.") return false } for _, endpoint := range cfg.Endpoints { if fqdnIsEtcdOperator(endpoint) { return true } } return false }
go
func IsEtcdOperator(selectedBackend string, opts map[string]string, k8sNamespace string) bool { if selectedBackend != EtcdBackendName { return false } fqdnIsEtcdOperator := func(address string) bool { u, err := url.Parse(address) if err != nil { return false } // typical service name "cilium-etcd-client.kube-system.svc" names := strings.Split(u.Hostname(), ".") return len(names) >= 2 && names[0] == "cilium-etcd-client" && names[1] == k8sNamespace } fqdn := opts[addrOption] if len(fqdn) != 0 { return fqdnIsEtcdOperator(fqdn) } bm := newEtcdModule() err := bm.setConfig(opts) if err != nil { return false } etcdConfig := bm.getConfig()[EtcdOptionConfig] if len(etcdConfig) == 0 { return false } cfg, err := clientyaml.NewConfig(etcdConfig) if err != nil { log.WithError(err).Error("Unable to read etcd configuration.") return false } for _, endpoint := range cfg.Endpoints { if fqdnIsEtcdOperator(endpoint) { return true } } return false }
[ "func", "IsEtcdOperator", "(", "selectedBackend", "string", ",", "opts", "map", "[", "string", "]", "string", ",", "k8sNamespace", "string", ")", "bool", "{", "if", "selectedBackend", "!=", "EtcdBackendName", "{", "return", "false", "\n", "}", "\n\n", "fqdnIsEtcdOperator", ":=", "func", "(", "address", "string", ")", "bool", "{", "u", ",", "err", ":=", "url", ".", "Parse", "(", "address", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "// typical service name \"cilium-etcd-client.kube-system.svc\"", "names", ":=", "strings", ".", "Split", "(", "u", ".", "Hostname", "(", ")", ",", "\"", "\"", ")", "\n", "return", "len", "(", "names", ")", ">=", "2", "&&", "names", "[", "0", "]", "==", "\"", "\"", "&&", "names", "[", "1", "]", "==", "k8sNamespace", "\n", "}", "\n\n", "fqdn", ":=", "opts", "[", "addrOption", "]", "\n", "if", "len", "(", "fqdn", ")", "!=", "0", "{", "return", "fqdnIsEtcdOperator", "(", "fqdn", ")", "\n", "}", "\n\n", "bm", ":=", "newEtcdModule", "(", ")", "\n", "err", ":=", "bm", ".", "setConfig", "(", "opts", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "etcdConfig", ":=", "bm", ".", "getConfig", "(", ")", "[", "EtcdOptionConfig", "]", "\n", "if", "len", "(", "etcdConfig", ")", "==", "0", "{", "return", "false", "\n", "}", "\n\n", "cfg", ",", "err", ":=", "clientyaml", ".", "NewConfig", "(", "etcdConfig", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "WithError", "(", "err", ")", ".", "Error", "(", "\"", "\"", ")", "\n", "return", "false", "\n", "}", "\n", "for", "_", ",", "endpoint", ":=", "range", "cfg", ".", "Endpoints", "{", "if", "fqdnIsEtcdOperator", "(", "endpoint", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// IsEtcdOperator returns true if the configuration is setting up an // etcd-operator and false otherwise.
[ "IsEtcdOperator", "returns", "true", "if", "the", "configuration", "is", "setting", "up", "an", "etcd", "-", "operator", "and", "false", "otherwise", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/etcd.go#L966-L1010
162,733
cilium/cilium
api/v1/server/restapi/policy/get_policy_resolve_responses.go
WithPayload
func (o *GetPolicyResolveOK) WithPayload(payload *models.PolicyTraceResult) *GetPolicyResolveOK { o.Payload = payload return o }
go
func (o *GetPolicyResolveOK) WithPayload(payload *models.PolicyTraceResult) *GetPolicyResolveOK { o.Payload = payload return o }
[ "func", "(", "o", "*", "GetPolicyResolveOK", ")", "WithPayload", "(", "payload", "*", "models", ".", "PolicyTraceResult", ")", "*", "GetPolicyResolveOK", "{", "o", ".", "Payload", "=", "payload", "\n", "return", "o", "\n", "}" ]
// WithPayload adds the payload to the get policy resolve o k response
[ "WithPayload", "adds", "the", "payload", "to", "the", "get", "policy", "resolve", "o", "k", "response" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/policy/get_policy_resolve_responses.go#L38-L41
162,734
cilium/cilium
pkg/monitor/logrecord.go
DumpInfo
func (l *LogRecordNotify) DumpInfo() { switch l.Type { case accesslog.TypeRequest: fmt.Printf("%s %s %s from %d (%s) to %d (%s), identity %d->%d, verdict %s", l.direction(), l.Type, l.l7Proto(), l.SourceEndpoint.ID, l.SourceEndpoint.Labels, l.DestinationEndpoint.ID, l.DestinationEndpoint.Labels, l.SourceEndpoint.Identity, l.DestinationEndpoint.Identity, l.Verdict) case accesslog.TypeResponse: fmt.Printf("%s %s %s to %d (%s) from %d (%s), identity %d->%d, verdict %s", l.direction(), l.Type, l.l7Proto(), l.SourceEndpoint.ID, l.SourceEndpoint.Labels, l.DestinationEndpoint.ID, l.DestinationEndpoint.Labels, l.SourceEndpoint.Identity, l.DestinationEndpoint.Identity, l.Verdict) } if http := l.HTTP; http != nil { url := "" if http.URL != nil { url = http.URL.String() } fmt.Printf(" %s %s => %d\n", http.Method, url, http.Code) } if kafka := l.Kafka; kafka != nil { fmt.Printf(" %s topic %s => %d\n", kafka.APIKey, kafka.Topic.Topic, kafka.ErrorCode) } if l.DNS != nil { types := []string{} for _, t := range l.DNS.QTypes { types = append(types, dns.TypeToString[t]) } qTypeStr := strings.Join(types, ",") switch { case l.Type == accesslog.TypeRequest: fmt.Printf(" DNS Query: %s %s", l.DNS.Query, qTypeStr) case l.Type == accesslog.TypeResponse: sourceType := "Query" if l.DNS.ObservationSource == accesslog.DNSSourceAgentPoller { sourceType = "Poll" } fmt.Printf(" DNS %s: %s %s", sourceType, l.DNS.Query, qTypeStr) ips := make([]string, 0, len(l.DNS.IPs)) for _, ip := range l.DNS.IPs { ips = append(ips, ip.String()) } fmt.Printf(" TTL: %d Answer: '%s'", l.DNS.TTL, strings.Join(ips, ",")) if len(l.DNS.CNAMEs) > 0 { fmt.Printf(" CNAMEs: %s", strings.Join(l.DNS.CNAMEs, ",")) } } fmt.Printf("\n") } if l7 := l.L7; l7 != nil { status := "" for k, v := range l7.Fields { if k == "status" { status = v } else { fmt.Printf(" %s:%s", k, v) } } if status != "" { fmt.Printf(" => status:%s", status) } fmt.Printf("\n") } }
go
func (l *LogRecordNotify) DumpInfo() { switch l.Type { case accesslog.TypeRequest: fmt.Printf("%s %s %s from %d (%s) to %d (%s), identity %d->%d, verdict %s", l.direction(), l.Type, l.l7Proto(), l.SourceEndpoint.ID, l.SourceEndpoint.Labels, l.DestinationEndpoint.ID, l.DestinationEndpoint.Labels, l.SourceEndpoint.Identity, l.DestinationEndpoint.Identity, l.Verdict) case accesslog.TypeResponse: fmt.Printf("%s %s %s to %d (%s) from %d (%s), identity %d->%d, verdict %s", l.direction(), l.Type, l.l7Proto(), l.SourceEndpoint.ID, l.SourceEndpoint.Labels, l.DestinationEndpoint.ID, l.DestinationEndpoint.Labels, l.SourceEndpoint.Identity, l.DestinationEndpoint.Identity, l.Verdict) } if http := l.HTTP; http != nil { url := "" if http.URL != nil { url = http.URL.String() } fmt.Printf(" %s %s => %d\n", http.Method, url, http.Code) } if kafka := l.Kafka; kafka != nil { fmt.Printf(" %s topic %s => %d\n", kafka.APIKey, kafka.Topic.Topic, kafka.ErrorCode) } if l.DNS != nil { types := []string{} for _, t := range l.DNS.QTypes { types = append(types, dns.TypeToString[t]) } qTypeStr := strings.Join(types, ",") switch { case l.Type == accesslog.TypeRequest: fmt.Printf(" DNS Query: %s %s", l.DNS.Query, qTypeStr) case l.Type == accesslog.TypeResponse: sourceType := "Query" if l.DNS.ObservationSource == accesslog.DNSSourceAgentPoller { sourceType = "Poll" } fmt.Printf(" DNS %s: %s %s", sourceType, l.DNS.Query, qTypeStr) ips := make([]string, 0, len(l.DNS.IPs)) for _, ip := range l.DNS.IPs { ips = append(ips, ip.String()) } fmt.Printf(" TTL: %d Answer: '%s'", l.DNS.TTL, strings.Join(ips, ",")) if len(l.DNS.CNAMEs) > 0 { fmt.Printf(" CNAMEs: %s", strings.Join(l.DNS.CNAMEs, ",")) } } fmt.Printf("\n") } if l7 := l.L7; l7 != nil { status := "" for k, v := range l7.Fields { if k == "status" { status = v } else { fmt.Printf(" %s:%s", k, v) } } if status != "" { fmt.Printf(" => status:%s", status) } fmt.Printf("\n") } }
[ "func", "(", "l", "*", "LogRecordNotify", ")", "DumpInfo", "(", ")", "{", "switch", "l", ".", "Type", "{", "case", "accesslog", ".", "TypeRequest", ":", "fmt", ".", "Printf", "(", "\"", "\"", ",", "l", ".", "direction", "(", ")", ",", "l", ".", "Type", ",", "l", ".", "l7Proto", "(", ")", ",", "l", ".", "SourceEndpoint", ".", "ID", ",", "l", ".", "SourceEndpoint", ".", "Labels", ",", "l", ".", "DestinationEndpoint", ".", "ID", ",", "l", ".", "DestinationEndpoint", ".", "Labels", ",", "l", ".", "SourceEndpoint", ".", "Identity", ",", "l", ".", "DestinationEndpoint", ".", "Identity", ",", "l", ".", "Verdict", ")", "\n\n", "case", "accesslog", ".", "TypeResponse", ":", "fmt", ".", "Printf", "(", "\"", "\"", ",", "l", ".", "direction", "(", ")", ",", "l", ".", "Type", ",", "l", ".", "l7Proto", "(", ")", ",", "l", ".", "SourceEndpoint", ".", "ID", ",", "l", ".", "SourceEndpoint", ".", "Labels", ",", "l", ".", "DestinationEndpoint", ".", "ID", ",", "l", ".", "DestinationEndpoint", ".", "Labels", ",", "l", ".", "SourceEndpoint", ".", "Identity", ",", "l", ".", "DestinationEndpoint", ".", "Identity", ",", "l", ".", "Verdict", ")", "\n", "}", "\n\n", "if", "http", ":=", "l", ".", "HTTP", ";", "http", "!=", "nil", "{", "url", ":=", "\"", "\"", "\n", "if", "http", ".", "URL", "!=", "nil", "{", "url", "=", "http", ".", "URL", ".", "String", "(", ")", "\n", "}", "\n\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "http", ".", "Method", ",", "url", ",", "http", ".", "Code", ")", "\n", "}", "\n\n", "if", "kafka", ":=", "l", ".", "Kafka", ";", "kafka", "!=", "nil", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "kafka", ".", "APIKey", ",", "kafka", ".", "Topic", ".", "Topic", ",", "kafka", ".", "ErrorCode", ")", "\n", "}", "\n\n", "if", "l", ".", "DNS", "!=", "nil", "{", "types", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "t", ":=", "range", "l", ".", "DNS", ".", "QTypes", "{", "types", "=", "append", "(", "types", ",", "dns", ".", "TypeToString", "[", "t", "]", ")", "\n", "}", "\n", "qTypeStr", ":=", "strings", ".", "Join", "(", "types", ",", "\"", "\"", ")", "\n\n", "switch", "{", "case", "l", ".", "Type", "==", "accesslog", ".", "TypeRequest", ":", "fmt", ".", "Printf", "(", "\"", "\"", ",", "l", ".", "DNS", ".", "Query", ",", "qTypeStr", ")", "\n\n", "case", "l", ".", "Type", "==", "accesslog", ".", "TypeResponse", ":", "sourceType", ":=", "\"", "\"", "\n", "if", "l", ".", "DNS", ".", "ObservationSource", "==", "accesslog", ".", "DNSSourceAgentPoller", "{", "sourceType", "=", "\"", "\"", "\n", "}", "\n\n", "fmt", ".", "Printf", "(", "\"", "\"", ",", "sourceType", ",", "l", ".", "DNS", ".", "Query", ",", "qTypeStr", ")", "\n\n", "ips", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "l", ".", "DNS", ".", "IPs", ")", ")", "\n", "for", "_", ",", "ip", ":=", "range", "l", ".", "DNS", ".", "IPs", "{", "ips", "=", "append", "(", "ips", ",", "ip", ".", "String", "(", ")", ")", "\n", "}", "\n", "fmt", ".", "Printf", "(", "\"", "\"", ",", "l", ".", "DNS", ".", "TTL", ",", "strings", ".", "Join", "(", "ips", ",", "\"", "\"", ")", ")", "\n\n", "if", "len", "(", "l", ".", "DNS", ".", "CNAMEs", ")", ">", "0", "{", "fmt", ".", "Printf", "(", "\"", "\"", ",", "strings", ".", "Join", "(", "l", ".", "DNS", ".", "CNAMEs", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "}", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ")", "\n", "}", "\n\n", "if", "l7", ":=", "l", ".", "L7", ";", "l7", "!=", "nil", "{", "status", ":=", "\"", "\"", "\n", "for", "k", ",", "v", ":=", "range", "l7", ".", "Fields", "{", "if", "k", "==", "\"", "\"", "{", "status", "=", "v", "\n", "}", "else", "{", "fmt", ".", "Printf", "(", "\"", "\"", ",", "k", ",", "v", ")", "\n", "}", "\n", "}", "\n", "if", "status", "!=", "\"", "\"", "{", "fmt", ".", "Printf", "(", "\"", "\"", ",", "status", ")", "\n", "}", "\n", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ")", "\n", "}", "\n", "}" ]
// DumpInfo dumps an access log notification
[ "DumpInfo", "dumps", "an", "access", "log", "notification" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/logrecord.go#L63-L139
162,735
cilium/cilium
pkg/monitor/logrecord.go
LogRecordNotifyToVerbose
func LogRecordNotifyToVerbose(n *LogRecordNotify) LogRecordNotifyVerbose { return LogRecordNotifyVerbose{ Type: "logRecord", ObservationPoint: n.ObservationPoint, FlowType: n.Type, L7Proto: n.l7Proto(), SrcEpID: n.SourceEndpoint.ID, SrcEpLabels: n.SourceEndpoint.Labels, SrcIdentity: n.SourceEndpoint.Identity, DstEpID: n.DestinationEndpoint.ID, DstEpLabels: n.DestinationEndpoint.Labels, DstIdentity: n.DestinationEndpoint.Identity, Verdict: n.Verdict, HTTP: n.HTTP, Kafka: n.Kafka, DNS: n.DNS, L7: n.L7, } }
go
func LogRecordNotifyToVerbose(n *LogRecordNotify) LogRecordNotifyVerbose { return LogRecordNotifyVerbose{ Type: "logRecord", ObservationPoint: n.ObservationPoint, FlowType: n.Type, L7Proto: n.l7Proto(), SrcEpID: n.SourceEndpoint.ID, SrcEpLabels: n.SourceEndpoint.Labels, SrcIdentity: n.SourceEndpoint.Identity, DstEpID: n.DestinationEndpoint.ID, DstEpLabels: n.DestinationEndpoint.Labels, DstIdentity: n.DestinationEndpoint.Identity, Verdict: n.Verdict, HTTP: n.HTTP, Kafka: n.Kafka, DNS: n.DNS, L7: n.L7, } }
[ "func", "LogRecordNotifyToVerbose", "(", "n", "*", "LogRecordNotify", ")", "LogRecordNotifyVerbose", "{", "return", "LogRecordNotifyVerbose", "{", "Type", ":", "\"", "\"", ",", "ObservationPoint", ":", "n", ".", "ObservationPoint", ",", "FlowType", ":", "n", ".", "Type", ",", "L7Proto", ":", "n", ".", "l7Proto", "(", ")", ",", "SrcEpID", ":", "n", ".", "SourceEndpoint", ".", "ID", ",", "SrcEpLabels", ":", "n", ".", "SourceEndpoint", ".", "Labels", ",", "SrcIdentity", ":", "n", ".", "SourceEndpoint", ".", "Identity", ",", "DstEpID", ":", "n", ".", "DestinationEndpoint", ".", "ID", ",", "DstEpLabels", ":", "n", ".", "DestinationEndpoint", ".", "Labels", ",", "DstIdentity", ":", "n", ".", "DestinationEndpoint", ".", "Identity", ",", "Verdict", ":", "n", ".", "Verdict", ",", "HTTP", ":", "n", ".", "HTTP", ",", "Kafka", ":", "n", ".", "Kafka", ",", "DNS", ":", "n", ".", "DNS", ",", "L7", ":", "n", ".", "L7", ",", "}", "\n", "}" ]
// LogRecordNotifyToVerbose turns LogRecordNotify into json-friendly Verbose structure
[ "LogRecordNotifyToVerbose", "turns", "LogRecordNotify", "into", "json", "-", "friendly", "Verbose", "structure" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/logrecord.go#L176-L194
162,736
cilium/cilium
api/v1/server/restapi/endpoint/delete_endpoint_id_responses.go
WithPayload
func (o *DeleteEndpointIDErrors) WithPayload(payload int64) *DeleteEndpointIDErrors { o.Payload = payload return o }
go
func (o *DeleteEndpointIDErrors) WithPayload(payload int64) *DeleteEndpointIDErrors { o.Payload = payload return o }
[ "func", "(", "o", "*", "DeleteEndpointIDErrors", ")", "WithPayload", "(", "payload", "int64", ")", "*", "DeleteEndpointIDErrors", "{", "o", ".", "Payload", "=", "payload", "\n", "return", "o", "\n", "}" ]
// WithPayload adds the payload to the delete endpoint Id errors response
[ "WithPayload", "adds", "the", "payload", "to", "the", "delete", "endpoint", "Id", "errors", "response" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/endpoint/delete_endpoint_id_responses.go#L62-L65
162,737
cilium/cilium
api/v1/server/restapi/endpoint/delete_endpoint_id_responses.go
WithPayload
func (o *DeleteEndpointIDInvalid) WithPayload(payload models.Error) *DeleteEndpointIDInvalid { o.Payload = payload return o }
go
func (o *DeleteEndpointIDInvalid) WithPayload(payload models.Error) *DeleteEndpointIDInvalid { o.Payload = payload return o }
[ "func", "(", "o", "*", "DeleteEndpointIDInvalid", ")", "WithPayload", "(", "payload", "models", ".", "Error", ")", "*", "DeleteEndpointIDInvalid", "{", "o", ".", "Payload", "=", "payload", "\n", "return", "o", "\n", "}" ]
// WithPayload adds the payload to the delete endpoint Id invalid response
[ "WithPayload", "adds", "the", "payload", "to", "the", "delete", "endpoint", "Id", "invalid", "response" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/endpoint/delete_endpoint_id_responses.go#L106-L109
162,738
cilium/cilium
pkg/kvstore/allocator/allocator.go
WithMin
func WithMin(id idpool.ID) AllocatorOption { return func(a *Allocator) { a.min = id } }
go
func WithMin(id idpool.ID) AllocatorOption { return func(a *Allocator) { a.min = id } }
[ "func", "WithMin", "(", "id", "idpool", ".", "ID", ")", "AllocatorOption", "{", "return", "func", "(", "a", "*", "Allocator", ")", "{", "a", ".", "min", "=", "id", "}", "\n", "}" ]
// WithMin sets the minimum identifier to be allocated
[ "WithMin", "sets", "the", "minimum", "identifier", "to", "be", "allocated" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L306-L308
162,739
cilium/cilium
pkg/kvstore/allocator/allocator.go
WithMax
func WithMax(id idpool.ID) AllocatorOption { return func(a *Allocator) { a.max = id } }
go
func WithMax(id idpool.ID) AllocatorOption { return func(a *Allocator) { a.max = id } }
[ "func", "WithMax", "(", "id", "idpool", ".", "ID", ")", "AllocatorOption", "{", "return", "func", "(", "a", "*", "Allocator", ")", "{", "a", ".", "max", "=", "id", "}", "\n", "}" ]
// WithMax sets the maximum identifier to be allocated
[ "WithMax", "sets", "the", "maximum", "identifier", "to", "be", "allocated" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L311-L313
162,740
cilium/cilium
pkg/kvstore/allocator/allocator.go
WithPrefixMask
func WithPrefixMask(mask idpool.ID) AllocatorOption { return func(a *Allocator) { a.prefixMask = mask } }
go
func WithPrefixMask(mask idpool.ID) AllocatorOption { return func(a *Allocator) { a.prefixMask = mask } }
[ "func", "WithPrefixMask", "(", "mask", "idpool", ".", "ID", ")", "AllocatorOption", "{", "return", "func", "(", "a", "*", "Allocator", ")", "{", "a", ".", "prefixMask", "=", "mask", "}", "\n", "}" ]
// WithPrefixMask sets the prefix used for all ID allocations. If set, the mask // will be ORed to all selected IDs prior to allocation. It is the // responsibility of the caller to ensure that the mask is not conflicting with // min..max.
[ "WithPrefixMask", "sets", "the", "prefix", "used", "for", "all", "ID", "allocations", ".", "If", "set", "the", "mask", "will", "be", "ORed", "to", "all", "selected", "IDs", "prior", "to", "allocation", ".", "It", "is", "the", "responsibility", "of", "the", "caller", "to", "ensure", "that", "the", "mask", "is", "not", "conflicting", "with", "min", "..", "max", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L319-L321
162,741
cilium/cilium
pkg/kvstore/allocator/allocator.go
Delete
func (a *Allocator) Delete() { close(a.stopGC) a.mainCache.stop() if a.events != nil { close(a.events) } }
go
func (a *Allocator) Delete() { close(a.stopGC) a.mainCache.stop() if a.events != nil { close(a.events) } }
[ "func", "(", "a", "*", "Allocator", ")", "Delete", "(", ")", "{", "close", "(", "a", ".", "stopGC", ")", "\n", "a", ".", "mainCache", ".", "stop", "(", ")", "\n\n", "if", "a", ".", "events", "!=", "nil", "{", "close", "(", "a", ".", "events", ")", "\n", "}", "\n", "}" ]
// Delete deletes an allocator and stops the garbage collector
[ "Delete", "deletes", "an", "allocator", "and", "stops", "the", "garbage", "collector" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L335-L342
162,742
cilium/cilium
pkg/kvstore/allocator/allocator.go
WaitForInitialSync
func (a *Allocator) WaitForInitialSync(ctx context.Context) error { select { case <-a.initialListDone: case <-ctx.Done(): return fmt.Errorf("identity sync with kvstore was cancelled: %s", ctx.Err()) } return nil }
go
func (a *Allocator) WaitForInitialSync(ctx context.Context) error { select { case <-a.initialListDone: case <-ctx.Done(): return fmt.Errorf("identity sync with kvstore was cancelled: %s", ctx.Err()) } return nil }
[ "func", "(", "a", "*", "Allocator", ")", "WaitForInitialSync", "(", "ctx", "context", ".", "Context", ")", "error", "{", "select", "{", "case", "<-", "a", ".", "initialListDone", ":", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ctx", ".", "Err", "(", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// WaitForInitialSync waits until the initial sync is complete
[ "WaitForInitialSync", "waits", "until", "the", "initial", "sync", "is", "complete" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L345-L353
162,743
cilium/cilium
pkg/kvstore/allocator/allocator.go
lockPath
func (a *Allocator) lockPath(ctx context.Context, key string) (*kvstore.Lock, error) { suffix := strings.TrimPrefix(key, a.basePrefix) return kvstore.LockPath(ctx, path.Join(a.lockPrefix, suffix)) }
go
func (a *Allocator) lockPath(ctx context.Context, key string) (*kvstore.Lock, error) { suffix := strings.TrimPrefix(key, a.basePrefix) return kvstore.LockPath(ctx, path.Join(a.lockPrefix, suffix)) }
[ "func", "(", "a", "*", "Allocator", ")", "lockPath", "(", "ctx", "context", ".", "Context", ",", "key", "string", ")", "(", "*", "kvstore", ".", "Lock", ",", "error", ")", "{", "suffix", ":=", "strings", ".", "TrimPrefix", "(", "key", ",", "a", ".", "basePrefix", ")", "\n", "return", "kvstore", ".", "LockPath", "(", "ctx", ",", "path", ".", "Join", "(", "a", ".", "lockPrefix", ",", "suffix", ")", ")", "\n", "}" ]
// lockPath locks a key in the scope of an allocator
[ "lockPath", "locks", "a", "key", "in", "the", "scope", "of", "an", "allocator" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L356-L359
162,744
cilium/cilium
pkg/kvstore/allocator/allocator.go
ForeachCache
func (a *Allocator) ForeachCache(cb RangeFunc) { a.mainCache.foreach(cb) a.remoteCachesMutex.RLock() for rc := range a.remoteCaches { rc.cache.foreach(cb) } a.remoteCachesMutex.RUnlock() }
go
func (a *Allocator) ForeachCache(cb RangeFunc) { a.mainCache.foreach(cb) a.remoteCachesMutex.RLock() for rc := range a.remoteCaches { rc.cache.foreach(cb) } a.remoteCachesMutex.RUnlock() }
[ "func", "(", "a", "*", "Allocator", ")", "ForeachCache", "(", "cb", "RangeFunc", ")", "{", "a", ".", "mainCache", ".", "foreach", "(", "cb", ")", "\n\n", "a", ".", "remoteCachesMutex", ".", "RLock", "(", ")", "\n", "for", "rc", ":=", "range", "a", ".", "remoteCaches", "{", "rc", ".", "cache", ".", "foreach", "(", "cb", ")", "\n", "}", "\n", "a", ".", "remoteCachesMutex", ".", "RUnlock", "(", ")", "\n", "}" ]
// ForeachCache iterates over the allocator cache and calls RangeFunc on each // cached entry
[ "ForeachCache", "iterates", "over", "the", "allocator", "cache", "and", "calls", "RangeFunc", "on", "each", "cached", "entry" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L371-L379
162,745
cilium/cilium
pkg/kvstore/allocator/allocator.go
selectAvailableID
func (a *Allocator) selectAvailableID() (idpool.ID, string, idpool.ID) { if id := a.idPool.LeaseAvailableID(); id != idpool.NoID { unmaskedID := id id |= a.prefixMask return id, id.String(), unmaskedID } return 0, "", 0 }
go
func (a *Allocator) selectAvailableID() (idpool.ID, string, idpool.ID) { if id := a.idPool.LeaseAvailableID(); id != idpool.NoID { unmaskedID := id id |= a.prefixMask return id, id.String(), unmaskedID } return 0, "", 0 }
[ "func", "(", "a", "*", "Allocator", ")", "selectAvailableID", "(", ")", "(", "idpool", ".", "ID", ",", "string", ",", "idpool", ".", "ID", ")", "{", "if", "id", ":=", "a", ".", "idPool", ".", "LeaseAvailableID", "(", ")", ";", "id", "!=", "idpool", ".", "NoID", "{", "unmaskedID", ":=", "id", "\n", "id", "|=", "a", ".", "prefixMask", "\n", "return", "id", ",", "id", ".", "String", "(", ")", ",", "unmaskedID", "\n", "}", "\n\n", "return", "0", ",", "\"", "\"", ",", "0", "\n", "}" ]
// Selects an available ID. // Returns a triple of the selected ID ORed with prefixMask, // the ID string and the originally selected ID.
[ "Selects", "an", "available", "ID", ".", "Returns", "a", "triple", "of", "the", "selected", "ID", "ORed", "with", "prefixMask", "the", "ID", "string", "and", "the", "originally", "selected", "ID", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L392-L400
162,746
cilium/cilium
pkg/kvstore/allocator/allocator.go
Allocate
func (a *Allocator) Allocate(ctx context.Context, key AllocatorKey) (idpool.ID, bool, error) { var ( err error value idpool.ID isNew bool k = key.GetKey() ) log.WithField(fieldKey, key).Info("Allocating key") select { case <-a.initialListDone: case <-ctx.Done(): return 0, false, fmt.Errorf("allocation was cancelled while waiting for initial key list to be received: %s", ctx.Err()) } // Check our list of local keys already in use and increment the // refcnt. The returned key must be released afterwards. No kvstore // operation was performed for this allocation if val := a.localKeys.use(k); val != idpool.NoID { kvstore.Trace("Reusing local id", nil, logrus.Fields{fieldID: val, fieldKey: key}) a.mainCache.insert(key, val) return val, false, nil } kvstore.Trace("Allocating from kvstore", nil, logrus.Fields{fieldKey: key}) // make a copy of the template and customize it boff := a.backoffTemplate boff.Name = key.String() for attempt := 0; attempt < maxAllocAttempts; attempt++ { // FIXME: Add non-locking variant value, isNew, err = a.lockedAllocate(ctx, key) if err == nil { a.mainCache.insert(key, value) return value, isNew, nil } scopedLog := log.WithFields(logrus.Fields{ fieldKey: key, logfields.Attempt: attempt, }) select { case <-ctx.Done(): scopedLog.WithError(ctx.Err()).Warning("Ongoing key allocation has been cancelled") return 0, false, fmt.Errorf("key allocation cancelled: %s", ctx.Err()) default: scopedLog.WithError(err).Warning("Key allocation attempt failed") } if waitErr := boff.Wait(ctx); waitErr != nil { return 0, false, waitErr } } return 0, false, err }
go
func (a *Allocator) Allocate(ctx context.Context, key AllocatorKey) (idpool.ID, bool, error) { var ( err error value idpool.ID isNew bool k = key.GetKey() ) log.WithField(fieldKey, key).Info("Allocating key") select { case <-a.initialListDone: case <-ctx.Done(): return 0, false, fmt.Errorf("allocation was cancelled while waiting for initial key list to be received: %s", ctx.Err()) } // Check our list of local keys already in use and increment the // refcnt. The returned key must be released afterwards. No kvstore // operation was performed for this allocation if val := a.localKeys.use(k); val != idpool.NoID { kvstore.Trace("Reusing local id", nil, logrus.Fields{fieldID: val, fieldKey: key}) a.mainCache.insert(key, val) return val, false, nil } kvstore.Trace("Allocating from kvstore", nil, logrus.Fields{fieldKey: key}) // make a copy of the template and customize it boff := a.backoffTemplate boff.Name = key.String() for attempt := 0; attempt < maxAllocAttempts; attempt++ { // FIXME: Add non-locking variant value, isNew, err = a.lockedAllocate(ctx, key) if err == nil { a.mainCache.insert(key, value) return value, isNew, nil } scopedLog := log.WithFields(logrus.Fields{ fieldKey: key, logfields.Attempt: attempt, }) select { case <-ctx.Done(): scopedLog.WithError(ctx.Err()).Warning("Ongoing key allocation has been cancelled") return 0, false, fmt.Errorf("key allocation cancelled: %s", ctx.Err()) default: scopedLog.WithError(err).Warning("Key allocation attempt failed") } if waitErr := boff.Wait(ctx); waitErr != nil { return 0, false, waitErr } } return 0, false, err }
[ "func", "(", "a", "*", "Allocator", ")", "Allocate", "(", "ctx", "context", ".", "Context", ",", "key", "AllocatorKey", ")", "(", "idpool", ".", "ID", ",", "bool", ",", "error", ")", "{", "var", "(", "err", "error", "\n", "value", "idpool", ".", "ID", "\n", "isNew", "bool", "\n", "k", "=", "key", ".", "GetKey", "(", ")", "\n", ")", "\n\n", "log", ".", "WithField", "(", "fieldKey", ",", "key", ")", ".", "Info", "(", "\"", "\"", ")", "\n\n", "select", "{", "case", "<-", "a", ".", "initialListDone", ":", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "0", ",", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ctx", ".", "Err", "(", ")", ")", "\n", "}", "\n\n", "// Check our list of local keys already in use and increment the", "// refcnt. The returned key must be released afterwards. No kvstore", "// operation was performed for this allocation", "if", "val", ":=", "a", ".", "localKeys", ".", "use", "(", "k", ")", ";", "val", "!=", "idpool", ".", "NoID", "{", "kvstore", ".", "Trace", "(", "\"", "\"", ",", "nil", ",", "logrus", ".", "Fields", "{", "fieldID", ":", "val", ",", "fieldKey", ":", "key", "}", ")", "\n", "a", ".", "mainCache", ".", "insert", "(", "key", ",", "val", ")", "\n", "return", "val", ",", "false", ",", "nil", "\n", "}", "\n\n", "kvstore", ".", "Trace", "(", "\"", "\"", ",", "nil", ",", "logrus", ".", "Fields", "{", "fieldKey", ":", "key", "}", ")", "\n\n", "// make a copy of the template and customize it", "boff", ":=", "a", ".", "backoffTemplate", "\n", "boff", ".", "Name", "=", "key", ".", "String", "(", ")", "\n\n", "for", "attempt", ":=", "0", ";", "attempt", "<", "maxAllocAttempts", ";", "attempt", "++", "{", "// FIXME: Add non-locking variant", "value", ",", "isNew", ",", "err", "=", "a", ".", "lockedAllocate", "(", "ctx", ",", "key", ")", "\n", "if", "err", "==", "nil", "{", "a", ".", "mainCache", ".", "insert", "(", "key", ",", "value", ")", "\n", "return", "value", ",", "isNew", ",", "nil", "\n", "}", "\n\n", "scopedLog", ":=", "log", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "fieldKey", ":", "key", ",", "logfields", ".", "Attempt", ":", "attempt", ",", "}", ")", "\n\n", "select", "{", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "scopedLog", ".", "WithError", "(", "ctx", ".", "Err", "(", ")", ")", ".", "Warning", "(", "\"", "\"", ")", "\n", "return", "0", ",", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ctx", ".", "Err", "(", ")", ")", "\n", "default", ":", "scopedLog", ".", "WithError", "(", "err", ")", ".", "Warning", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "waitErr", ":=", "boff", ".", "Wait", "(", "ctx", ")", ";", "waitErr", "!=", "nil", "{", "return", "0", ",", "false", ",", "waitErr", "\n", "}", "\n", "}", "\n\n", "return", "0", ",", "false", ",", "err", "\n", "}" ]
// Allocate will retrieve the ID for the provided key. If no ID has been // allocated for this key yet, a key will be allocated. If allocation fails, // most likely due to a parallel allocation of the same ID by another user, // allocation is re-attempted for maxAllocAttempts times. // // Returns the ID allocated to the key, if the ID had to be allocated, then // true is returned. An error is returned in case of failure.
[ "Allocate", "will", "retrieve", "the", "ID", "for", "the", "provided", "key", ".", "If", "no", "ID", "has", "been", "allocated", "for", "this", "key", "yet", "a", "key", "will", "be", "allocated", ".", "If", "allocation", "fails", "most", "likely", "due", "to", "a", "parallel", "allocation", "of", "the", "same", "ID", "by", "another", "user", "allocation", "is", "re", "-", "attempted", "for", "maxAllocAttempts", "times", ".", "Returns", "the", "ID", "allocated", "to", "the", "key", "if", "the", "ID", "had", "to", "be", "allocated", "then", "true", "is", "returned", ".", "An", "error", "is", "returned", "in", "case", "of", "failure", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L533-L591
162,747
cilium/cilium
pkg/kvstore/allocator/allocator.go
Get
func (a *Allocator) Get(ctx context.Context, key AllocatorKey) (idpool.ID, error) { if id := a.mainCache.get(key.GetKey()); id != idpool.NoID { return id, nil } return a.GetNoCache(ctx, key) }
go
func (a *Allocator) Get(ctx context.Context, key AllocatorKey) (idpool.ID, error) { if id := a.mainCache.get(key.GetKey()); id != idpool.NoID { return id, nil } return a.GetNoCache(ctx, key) }
[ "func", "(", "a", "*", "Allocator", ")", "Get", "(", "ctx", "context", ".", "Context", ",", "key", "AllocatorKey", ")", "(", "idpool", ".", "ID", ",", "error", ")", "{", "if", "id", ":=", "a", ".", "mainCache", ".", "get", "(", "key", ".", "GetKey", "(", ")", ")", ";", "id", "!=", "idpool", ".", "NoID", "{", "return", "id", ",", "nil", "\n", "}", "\n\n", "return", "a", ".", "GetNoCache", "(", "ctx", ",", "key", ")", "\n", "}" ]
// Get returns the ID which is allocated to a key. Returns an ID of NoID if no ID // has been allocated to this key yet.
[ "Get", "returns", "the", "ID", "which", "is", "allocated", "to", "a", "key", ".", "Returns", "an", "ID", "of", "NoID", "if", "no", "ID", "has", "been", "allocated", "to", "this", "key", "yet", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L595-L601
162,748
cilium/cilium
pkg/kvstore/allocator/allocator.go
GetNoCache
func (a *Allocator) GetNoCache(ctx context.Context, key AllocatorKey) (idpool.ID, error) { // GetPrefix() will choose any "first" key with the same prefix as the // specified key. In the worst case this may alternate between // returning the prefix that is specified and returning a key with a // longer prefix (even if this exact prefix already exists in the // kvstore). In that case, we will potentially allocate duplicate // identities for the same set of labels. This is not efficient, but // should have the correct identity properties. prefix := path.Join(a.valuePrefix, key.GetKey()) k, v, err := kvstore.GetPrefix(ctx, prefix) kvstore.Trace("AllocateGet", err, logrus.Fields{fieldPrefix: prefix, fieldKey: k, fieldValue: v}) if err != nil || v == nil || !prefixMatchesKey(prefix, k) { return 0, err } id, err := strconv.ParseUint(string(v), 10, 64) if err != nil { return idpool.NoID, fmt.Errorf("unable to parse value '%s': %s", v, err) } return idpool.ID(id), nil }
go
func (a *Allocator) GetNoCache(ctx context.Context, key AllocatorKey) (idpool.ID, error) { // GetPrefix() will choose any "first" key with the same prefix as the // specified key. In the worst case this may alternate between // returning the prefix that is specified and returning a key with a // longer prefix (even if this exact prefix already exists in the // kvstore). In that case, we will potentially allocate duplicate // identities for the same set of labels. This is not efficient, but // should have the correct identity properties. prefix := path.Join(a.valuePrefix, key.GetKey()) k, v, err := kvstore.GetPrefix(ctx, prefix) kvstore.Trace("AllocateGet", err, logrus.Fields{fieldPrefix: prefix, fieldKey: k, fieldValue: v}) if err != nil || v == nil || !prefixMatchesKey(prefix, k) { return 0, err } id, err := strconv.ParseUint(string(v), 10, 64) if err != nil { return idpool.NoID, fmt.Errorf("unable to parse value '%s': %s", v, err) } return idpool.ID(id), nil }
[ "func", "(", "a", "*", "Allocator", ")", "GetNoCache", "(", "ctx", "context", ".", "Context", ",", "key", "AllocatorKey", ")", "(", "idpool", ".", "ID", ",", "error", ")", "{", "// GetPrefix() will choose any \"first\" key with the same prefix as the", "// specified key. In the worst case this may alternate between", "// returning the prefix that is specified and returning a key with a", "// longer prefix (even if this exact prefix already exists in the", "// kvstore). In that case, we will potentially allocate duplicate", "// identities for the same set of labels. This is not efficient, but", "// should have the correct identity properties.", "prefix", ":=", "path", ".", "Join", "(", "a", ".", "valuePrefix", ",", "key", ".", "GetKey", "(", ")", ")", "\n", "k", ",", "v", ",", "err", ":=", "kvstore", ".", "GetPrefix", "(", "ctx", ",", "prefix", ")", "\n", "kvstore", ".", "Trace", "(", "\"", "\"", ",", "err", ",", "logrus", ".", "Fields", "{", "fieldPrefix", ":", "prefix", ",", "fieldKey", ":", "k", ",", "fieldValue", ":", "v", "}", ")", "\n", "if", "err", "!=", "nil", "||", "v", "==", "nil", "||", "!", "prefixMatchesKey", "(", "prefix", ",", "k", ")", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "id", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "string", "(", "v", ")", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "idpool", ".", "NoID", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "v", ",", "err", ")", "\n", "}", "\n\n", "return", "idpool", ".", "ID", "(", "id", ")", ",", "nil", "\n", "}" ]
// Get returns the ID which is allocated to a key in the kvstore
[ "Get", "returns", "the", "ID", "which", "is", "allocated", "to", "a", "key", "in", "the", "kvstore" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L610-L631
162,749
cilium/cilium
pkg/kvstore/allocator/allocator.go
GetByID
func (a *Allocator) GetByID(id idpool.ID) (AllocatorKey, error) { if key := a.mainCache.getByID(id); key != nil { return key, nil } v, err := kvstore.Get(path.Join(a.idPrefix, id.String())) if err != nil { return nil, err } return a.keyType.PutKey(string(v)) }
go
func (a *Allocator) GetByID(id idpool.ID) (AllocatorKey, error) { if key := a.mainCache.getByID(id); key != nil { return key, nil } v, err := kvstore.Get(path.Join(a.idPrefix, id.String())) if err != nil { return nil, err } return a.keyType.PutKey(string(v)) }
[ "func", "(", "a", "*", "Allocator", ")", "GetByID", "(", "id", "idpool", ".", "ID", ")", "(", "AllocatorKey", ",", "error", ")", "{", "if", "key", ":=", "a", ".", "mainCache", ".", "getByID", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "key", ",", "nil", "\n", "}", "\n\n", "v", ",", "err", ":=", "kvstore", ".", "Get", "(", "path", ".", "Join", "(", "a", ".", "idPrefix", ",", "id", ".", "String", "(", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "a", ".", "keyType", ".", "PutKey", "(", "string", "(", "v", ")", ")", "\n", "}" ]
// GetByID returns the key associated with an ID. Returns nil if no key is // associated with the ID.
[ "GetByID", "returns", "the", "key", "associated", "with", "an", "ID", ".", "Returns", "nil", "if", "no", "key", "is", "associated", "with", "the", "ID", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L635-L646
162,750
cilium/cilium
pkg/kvstore/allocator/allocator.go
Release
func (a *Allocator) Release(ctx context.Context, key AllocatorKey) (lastUse bool, err error) { log.WithField(fieldKey, key).Info("Releasing key") select { case <-a.initialListDone: case <-ctx.Done(): return false, fmt.Errorf("release was cancelled while waiting for initial key list to be received: %s", ctx.Err()) } k := key.GetKey() // release the key locally, if it was the last use, remove the node // specific value key to remove the global reference mark lastUse, err = a.localKeys.release(k) if err != nil { return } if lastUse { valueKey := path.Join(a.valuePrefix, k, a.suffix) if err := kvstore.Delete(valueKey); err != nil { log.WithError(err).WithFields(logrus.Fields{fieldKey: key}).Warning("Ignoring node specific ID") } // if a.lockless { // FIXME: etcd 3.3 will make it possible to do a lockless // cleanup of the ID and release it right away. For now we rely // on the GC to kick in a release unused IDs. // } } return }
go
func (a *Allocator) Release(ctx context.Context, key AllocatorKey) (lastUse bool, err error) { log.WithField(fieldKey, key).Info("Releasing key") select { case <-a.initialListDone: case <-ctx.Done(): return false, fmt.Errorf("release was cancelled while waiting for initial key list to be received: %s", ctx.Err()) } k := key.GetKey() // release the key locally, if it was the last use, remove the node // specific value key to remove the global reference mark lastUse, err = a.localKeys.release(k) if err != nil { return } if lastUse { valueKey := path.Join(a.valuePrefix, k, a.suffix) if err := kvstore.Delete(valueKey); err != nil { log.WithError(err).WithFields(logrus.Fields{fieldKey: key}).Warning("Ignoring node specific ID") } // if a.lockless { // FIXME: etcd 3.3 will make it possible to do a lockless // cleanup of the ID and release it right away. For now we rely // on the GC to kick in a release unused IDs. // } } return }
[ "func", "(", "a", "*", "Allocator", ")", "Release", "(", "ctx", "context", ".", "Context", ",", "key", "AllocatorKey", ")", "(", "lastUse", "bool", ",", "err", "error", ")", "{", "log", ".", "WithField", "(", "fieldKey", ",", "key", ")", ".", "Info", "(", "\"", "\"", ")", "\n\n", "select", "{", "case", "<-", "a", ".", "initialListDone", ":", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ctx", ".", "Err", "(", ")", ")", "\n", "}", "\n\n", "k", ":=", "key", ".", "GetKey", "(", ")", "\n", "// release the key locally, if it was the last use, remove the node", "// specific value key to remove the global reference mark", "lastUse", ",", "err", "=", "a", ".", "localKeys", ".", "release", "(", "k", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "if", "lastUse", "{", "valueKey", ":=", "path", ".", "Join", "(", "a", ".", "valuePrefix", ",", "k", ",", "a", ".", "suffix", ")", "\n", "if", "err", ":=", "kvstore", ".", "Delete", "(", "valueKey", ")", ";", "err", "!=", "nil", "{", "log", ".", "WithError", "(", "err", ")", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "fieldKey", ":", "key", "}", ")", ".", "Warning", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// if a.lockless {", "// FIXME: etcd 3.3 will make it possible to do a lockless", "// cleanup of the ID and release it right away. For now we rely", "// on the GC to kick in a release unused IDs.", "// }", "}", "\n\n", "return", "\n", "}" ]
// Release releases the use of an ID associated with the provided key. After // the last user has released the ID, the key is removed in the KVstore and // the returned lastUse value is true.
[ "Release", "releases", "the", "use", "of", "an", "ID", "associated", "with", "the", "provided", "key", ".", "After", "the", "last", "user", "has", "released", "the", "ID", "the", "key", "is", "removed", "in", "the", "KVstore", "and", "the", "returned", "lastUse", "value", "is", "true", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L651-L682
162,751
cilium/cilium
pkg/kvstore/allocator/allocator.go
RunGC
func (a *Allocator) RunGC() error { // fetch list of all /id/ keys allocated, err := kvstore.ListPrefix(a.idPrefix) if err != nil { return fmt.Errorf("list failed: %s", err) } // iterate over /id/ for key, v := range allocated { // if a.lockless { // FIXME: Add DeleteOnZeroCount support // } lock, err := a.lockPath(context.Background(), key) if err != nil { log.WithError(err).WithField(fieldKey, key).Warning("allocator garbage collector was unable to lock key") continue } // fetch list of all /value/<key> keys valueKeyPrefix := path.Join(a.valuePrefix, string(v)) uses, err := kvstore.ListPrefix(valueKeyPrefix) if err != nil { log.WithError(err).WithField(fieldPrefix, valueKeyPrefix).Warning("allocator garbage collector was unable to list keys") lock.Unlock() continue } // if ID has no user, delete it if len(uses) == 0 { scopedLog := log.WithFields(logrus.Fields{ fieldKey: key, fieldID: path.Base(key), }) if err := kvstore.Delete(key); err != nil { scopedLog.WithError(err).Warning("Unable to delete unused allocator master key") } else { scopedLog.Info("Deleted unused allocator master key") } } lock.Unlock() } return nil }
go
func (a *Allocator) RunGC() error { // fetch list of all /id/ keys allocated, err := kvstore.ListPrefix(a.idPrefix) if err != nil { return fmt.Errorf("list failed: %s", err) } // iterate over /id/ for key, v := range allocated { // if a.lockless { // FIXME: Add DeleteOnZeroCount support // } lock, err := a.lockPath(context.Background(), key) if err != nil { log.WithError(err).WithField(fieldKey, key).Warning("allocator garbage collector was unable to lock key") continue } // fetch list of all /value/<key> keys valueKeyPrefix := path.Join(a.valuePrefix, string(v)) uses, err := kvstore.ListPrefix(valueKeyPrefix) if err != nil { log.WithError(err).WithField(fieldPrefix, valueKeyPrefix).Warning("allocator garbage collector was unable to list keys") lock.Unlock() continue } // if ID has no user, delete it if len(uses) == 0 { scopedLog := log.WithFields(logrus.Fields{ fieldKey: key, fieldID: path.Base(key), }) if err := kvstore.Delete(key); err != nil { scopedLog.WithError(err).Warning("Unable to delete unused allocator master key") } else { scopedLog.Info("Deleted unused allocator master key") } } lock.Unlock() } return nil }
[ "func", "(", "a", "*", "Allocator", ")", "RunGC", "(", ")", "error", "{", "// fetch list of all /id/ keys", "allocated", ",", "err", ":=", "kvstore", ".", "ListPrefix", "(", "a", ".", "idPrefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// iterate over /id/", "for", "key", ",", "v", ":=", "range", "allocated", "{", "// if a.lockless {", "// FIXME: Add DeleteOnZeroCount support", "// }", "lock", ",", "err", ":=", "a", ".", "lockPath", "(", "context", ".", "Background", "(", ")", ",", "key", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "WithError", "(", "err", ")", ".", "WithField", "(", "fieldKey", ",", "key", ")", ".", "Warning", "(", "\"", "\"", ")", "\n", "continue", "\n", "}", "\n\n", "// fetch list of all /value/<key> keys", "valueKeyPrefix", ":=", "path", ".", "Join", "(", "a", ".", "valuePrefix", ",", "string", "(", "v", ")", ")", "\n", "uses", ",", "err", ":=", "kvstore", ".", "ListPrefix", "(", "valueKeyPrefix", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "WithError", "(", "err", ")", ".", "WithField", "(", "fieldPrefix", ",", "valueKeyPrefix", ")", ".", "Warning", "(", "\"", "\"", ")", "\n", "lock", ".", "Unlock", "(", ")", "\n", "continue", "\n", "}", "\n\n", "// if ID has no user, delete it", "if", "len", "(", "uses", ")", "==", "0", "{", "scopedLog", ":=", "log", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "fieldKey", ":", "key", ",", "fieldID", ":", "path", ".", "Base", "(", "key", ")", ",", "}", ")", "\n", "if", "err", ":=", "kvstore", ".", "Delete", "(", "key", ")", ";", "err", "!=", "nil", "{", "scopedLog", ".", "WithError", "(", "err", ")", ".", "Warning", "(", "\"", "\"", ")", "\n", "}", "else", "{", "scopedLog", ".", "Info", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "lock", ".", "Unlock", "(", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// RunGC scans the kvstore for unused master keys and removes them
[ "RunGC", "scans", "the", "kvstore", "for", "unused", "master", "keys", "and", "removes", "them" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L685-L730
162,752
cilium/cilium
pkg/kvstore/allocator/allocator.go
syncLocalKeys
func (a *Allocator) syncLocalKeys() error { // Create a local copy of all local allocations to not require to hold // any locks while performing kvstore operations. Local use can // disappear while we perform the sync but that is fine as worst case, // a master key is created for a slave key that no longer exists. The // garbage collector will remove it again. ids := a.localKeys.getVerifiedIDs() for id, value := range ids { a.recreateMasterKey(id, value, false) } return nil }
go
func (a *Allocator) syncLocalKeys() error { // Create a local copy of all local allocations to not require to hold // any locks while performing kvstore operations. Local use can // disappear while we perform the sync but that is fine as worst case, // a master key is created for a slave key that no longer exists. The // garbage collector will remove it again. ids := a.localKeys.getVerifiedIDs() for id, value := range ids { a.recreateMasterKey(id, value, false) } return nil }
[ "func", "(", "a", "*", "Allocator", ")", "syncLocalKeys", "(", ")", "error", "{", "// Create a local copy of all local allocations to not require to hold", "// any locks while performing kvstore operations. Local use can", "// disappear while we perform the sync but that is fine as worst case,", "// a master key is created for a slave key that no longer exists. The", "// garbage collector will remove it again.", "ids", ":=", "a", ".", "localKeys", ".", "getVerifiedIDs", "(", ")", "\n\n", "for", "id", ",", "value", ":=", "range", "ids", "{", "a", ".", "recreateMasterKey", "(", "id", ",", "value", ",", "false", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// syncLocalKeys checks the kvstore and verifies that a master key exists for // all locally used allocations. This will restore master keys if deleted for // some reason.
[ "syncLocalKeys", "checks", "the", "kvstore", "and", "verifies", "that", "a", "master", "key", "exists", "for", "all", "locally", "used", "allocations", ".", "This", "will", "restore", "master", "keys", "if", "deleted", "for", "some", "reason", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L771-L784
162,753
cilium/cilium
pkg/kvstore/allocator/allocator.go
Close
func (rc *RemoteCache) Close() { rc.allocator.remoteCachesMutex.Lock() delete(rc.allocator.remoteCaches, rc) rc.allocator.remoteCachesMutex.Unlock() rc.cache.stop() }
go
func (rc *RemoteCache) Close() { rc.allocator.remoteCachesMutex.Lock() delete(rc.allocator.remoteCaches, rc) rc.allocator.remoteCachesMutex.Unlock() rc.cache.stop() }
[ "func", "(", "rc", "*", "RemoteCache", ")", "Close", "(", ")", "{", "rc", ".", "allocator", ".", "remoteCachesMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "rc", ".", "allocator", ".", "remoteCaches", ",", "rc", ")", "\n", "rc", ".", "allocator", ".", "remoteCachesMutex", ".", "Unlock", "(", ")", "\n\n", "rc", ".", "cache", ".", "stop", "(", ")", "\n", "}" ]
// Close stops watching for identities in the kvstore associated with the // remote cache and will clear the local cache.
[ "Close", "stops", "watching", "for", "identities", "in", "the", "kvstore", "associated", "with", "the", "remote", "cache", "and", "will", "clear", "the", "local", "cache", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/allocator.go#L850-L856
162,754
cilium/cilium
pkg/ip/ip.go
RemoveCIDRs
func RemoveCIDRs(allowCIDRs, removeCIDRs []*net.IPNet) ([]*net.IPNet, error) { // Ensure that we iterate through the provided CIDRs in order of largest // subnet first. sort.Sort(NetsByMask(removeCIDRs)) PreLoop: // Remove CIDRs which are contained within CIDRs that we want to remove; // such CIDRs are redundant. for j, removeCIDR := range removeCIDRs { for i, removeCIDR2 := range removeCIDRs { if i == j { continue } if removeCIDR.Contains(removeCIDR2.IP) { removeCIDRs = append(removeCIDRs[:i], removeCIDRs[i+1:]...) // Re-trigger loop since we have modified the slice we are iterating over. goto PreLoop } } } for _, remove := range removeCIDRs { Loop: for i, allowCIDR := range allowCIDRs { // Don't allow comparison of different address spaces. if allowCIDR.IP.To4() != nil && remove.IP.To4() == nil || allowCIDR.IP.To4() == nil && remove.IP.To4() != nil { return nil, fmt.Errorf("cannot mix IP addresses of different IP protocol versions") } // Only remove CIDR if it is contained in the subnet we are allowing. if allowCIDR.Contains(remove.IP.Mask(remove.Mask)) { nets, err := removeCIDR(allowCIDR, remove) if err != nil { return nil, err } // Remove CIDR that we have just processed and append new CIDRs // that we computed from removing the CIDR to remove. allowCIDRs = append(allowCIDRs[:i], allowCIDRs[i+1:]...) allowCIDRs = append(allowCIDRs, nets...) goto Loop } else if remove.Contains(allowCIDR.IP.Mask(allowCIDR.Mask)) { // If a CIDR that we want to remove contains a CIDR in the list // that is allowed, then we can just remove the CIDR to allow. allowCIDRs = append(allowCIDRs[:i], allowCIDRs[i+1:]...) goto Loop } } } return allowCIDRs, nil }
go
func RemoveCIDRs(allowCIDRs, removeCIDRs []*net.IPNet) ([]*net.IPNet, error) { // Ensure that we iterate through the provided CIDRs in order of largest // subnet first. sort.Sort(NetsByMask(removeCIDRs)) PreLoop: // Remove CIDRs which are contained within CIDRs that we want to remove; // such CIDRs are redundant. for j, removeCIDR := range removeCIDRs { for i, removeCIDR2 := range removeCIDRs { if i == j { continue } if removeCIDR.Contains(removeCIDR2.IP) { removeCIDRs = append(removeCIDRs[:i], removeCIDRs[i+1:]...) // Re-trigger loop since we have modified the slice we are iterating over. goto PreLoop } } } for _, remove := range removeCIDRs { Loop: for i, allowCIDR := range allowCIDRs { // Don't allow comparison of different address spaces. if allowCIDR.IP.To4() != nil && remove.IP.To4() == nil || allowCIDR.IP.To4() == nil && remove.IP.To4() != nil { return nil, fmt.Errorf("cannot mix IP addresses of different IP protocol versions") } // Only remove CIDR if it is contained in the subnet we are allowing. if allowCIDR.Contains(remove.IP.Mask(remove.Mask)) { nets, err := removeCIDR(allowCIDR, remove) if err != nil { return nil, err } // Remove CIDR that we have just processed and append new CIDRs // that we computed from removing the CIDR to remove. allowCIDRs = append(allowCIDRs[:i], allowCIDRs[i+1:]...) allowCIDRs = append(allowCIDRs, nets...) goto Loop } else if remove.Contains(allowCIDR.IP.Mask(allowCIDR.Mask)) { // If a CIDR that we want to remove contains a CIDR in the list // that is allowed, then we can just remove the CIDR to allow. allowCIDRs = append(allowCIDRs[:i], allowCIDRs[i+1:]...) goto Loop } } } return allowCIDRs, nil }
[ "func", "RemoveCIDRs", "(", "allowCIDRs", ",", "removeCIDRs", "[", "]", "*", "net", ".", "IPNet", ")", "(", "[", "]", "*", "net", ".", "IPNet", ",", "error", ")", "{", "// Ensure that we iterate through the provided CIDRs in order of largest", "// subnet first.", "sort", ".", "Sort", "(", "NetsByMask", "(", "removeCIDRs", ")", ")", "\n\n", "PreLoop", ":", "// Remove CIDRs which are contained within CIDRs that we want to remove;", "// such CIDRs are redundant.", "for", "j", ",", "removeCIDR", ":=", "range", "removeCIDRs", "{", "for", "i", ",", "removeCIDR2", ":=", "range", "removeCIDRs", "{", "if", "i", "==", "j", "{", "continue", "\n", "}", "\n", "if", "removeCIDR", ".", "Contains", "(", "removeCIDR2", ".", "IP", ")", "{", "removeCIDRs", "=", "append", "(", "removeCIDRs", "[", ":", "i", "]", ",", "removeCIDRs", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "// Re-trigger loop since we have modified the slice we are iterating over.", "goto", "PreLoop", "\n", "}", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "remove", ":=", "range", "removeCIDRs", "{", "Loop", ":", "for", "i", ",", "allowCIDR", ":=", "range", "allowCIDRs", "{", "// Don't allow comparison of different address spaces.", "if", "allowCIDR", ".", "IP", ".", "To4", "(", ")", "!=", "nil", "&&", "remove", ".", "IP", ".", "To4", "(", ")", "==", "nil", "||", "allowCIDR", ".", "IP", ".", "To4", "(", ")", "==", "nil", "&&", "remove", ".", "IP", ".", "To4", "(", ")", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Only remove CIDR if it is contained in the subnet we are allowing.", "if", "allowCIDR", ".", "Contains", "(", "remove", ".", "IP", ".", "Mask", "(", "remove", ".", "Mask", ")", ")", "{", "nets", ",", "err", ":=", "removeCIDR", "(", "allowCIDR", ",", "remove", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Remove CIDR that we have just processed and append new CIDRs", "// that we computed from removing the CIDR to remove.", "allowCIDRs", "=", "append", "(", "allowCIDRs", "[", ":", "i", "]", ",", "allowCIDRs", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "allowCIDRs", "=", "append", "(", "allowCIDRs", ",", "nets", "...", ")", "\n", "goto", "Loop", "\n", "}", "else", "if", "remove", ".", "Contains", "(", "allowCIDR", ".", "IP", ".", "Mask", "(", "allowCIDR", ".", "Mask", ")", ")", "{", "// If a CIDR that we want to remove contains a CIDR in the list", "// that is allowed, then we can just remove the CIDR to allow.", "allowCIDRs", "=", "append", "(", "allowCIDRs", "[", ":", "i", "]", ",", "allowCIDRs", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "goto", "Loop", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "allowCIDRs", ",", "nil", "\n", "}" ]
// RemoveCIDRs removes the specified CIDRs from another set of CIDRs. If a CIDR // to remove is not contained within the CIDR, the CIDR to remove is ignored. A // slice of CIDRs is returned which contains the set of CIDRs provided minus // the set of CIDRs which were removed. Both input slices may be modified by // calling this function.
[ "RemoveCIDRs", "removes", "the", "specified", "CIDRs", "from", "another", "set", "of", "CIDRs", ".", "If", "a", "CIDR", "to", "remove", "is", "not", "contained", "within", "the", "CIDR", "the", "CIDR", "to", "remove", "is", "ignored", ".", "A", "slice", "of", "CIDRs", "is", "returned", "which", "contains", "the", "set", "of", "CIDRs", "provided", "minus", "the", "set", "of", "CIDRs", "which", "were", "removed", ".", "Both", "input", "slices", "may", "be", "modified", "by", "calling", "this", "function", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ip/ip.go#L124-L178
162,755
cilium/cilium
pkg/ip/ip.go
GetNextIP
func GetNextIP(ip net.IP) net.IP { if ip.Equal(upperIPv4) || ip.Equal(upperIPv6) { return ip } nextIP := make(net.IP, len(ip)) switch len(ip) { case net.IPv4len: ipU32 := binary.BigEndian.Uint32(ip) ipU32++ binary.BigEndian.PutUint32(nextIP, ipU32) return nextIP case net.IPv6len: ipU64 := binary.BigEndian.Uint64(ip[net.IPv6len/2:]) ipU64++ binary.BigEndian.PutUint64(nextIP[net.IPv6len/2:], ipU64) if ipU64 == 0 { ipU64 = binary.BigEndian.Uint64(ip[:net.IPv6len/2]) ipU64++ binary.BigEndian.PutUint64(nextIP[:net.IPv6len/2], ipU64) } else { copy(nextIP[:net.IPv6len/2], ip[:net.IPv6len/2]) } return nextIP default: return ip } }
go
func GetNextIP(ip net.IP) net.IP { if ip.Equal(upperIPv4) || ip.Equal(upperIPv6) { return ip } nextIP := make(net.IP, len(ip)) switch len(ip) { case net.IPv4len: ipU32 := binary.BigEndian.Uint32(ip) ipU32++ binary.BigEndian.PutUint32(nextIP, ipU32) return nextIP case net.IPv6len: ipU64 := binary.BigEndian.Uint64(ip[net.IPv6len/2:]) ipU64++ binary.BigEndian.PutUint64(nextIP[net.IPv6len/2:], ipU64) if ipU64 == 0 { ipU64 = binary.BigEndian.Uint64(ip[:net.IPv6len/2]) ipU64++ binary.BigEndian.PutUint64(nextIP[:net.IPv6len/2], ipU64) } else { copy(nextIP[:net.IPv6len/2], ip[:net.IPv6len/2]) } return nextIP default: return ip } }
[ "func", "GetNextIP", "(", "ip", "net", ".", "IP", ")", "net", ".", "IP", "{", "if", "ip", ".", "Equal", "(", "upperIPv4", ")", "||", "ip", ".", "Equal", "(", "upperIPv6", ")", "{", "return", "ip", "\n", "}", "\n\n", "nextIP", ":=", "make", "(", "net", ".", "IP", ",", "len", "(", "ip", ")", ")", "\n", "switch", "len", "(", "ip", ")", "{", "case", "net", ".", "IPv4len", ":", "ipU32", ":=", "binary", ".", "BigEndian", ".", "Uint32", "(", "ip", ")", "\n", "ipU32", "++", "\n", "binary", ".", "BigEndian", ".", "PutUint32", "(", "nextIP", ",", "ipU32", ")", "\n", "return", "nextIP", "\n", "case", "net", ".", "IPv6len", ":", "ipU64", ":=", "binary", ".", "BigEndian", ".", "Uint64", "(", "ip", "[", "net", ".", "IPv6len", "/", "2", ":", "]", ")", "\n", "ipU64", "++", "\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "nextIP", "[", "net", ".", "IPv6len", "/", "2", ":", "]", ",", "ipU64", ")", "\n", "if", "ipU64", "==", "0", "{", "ipU64", "=", "binary", ".", "BigEndian", ".", "Uint64", "(", "ip", "[", ":", "net", ".", "IPv6len", "/", "2", "]", ")", "\n", "ipU64", "++", "\n", "binary", ".", "BigEndian", ".", "PutUint64", "(", "nextIP", "[", ":", "net", ".", "IPv6len", "/", "2", "]", ",", "ipU64", ")", "\n", "}", "else", "{", "copy", "(", "nextIP", "[", ":", "net", ".", "IPv6len", "/", "2", "]", ",", "ip", "[", ":", "net", ".", "IPv6len", "/", "2", "]", ")", "\n", "}", "\n", "return", "nextIP", "\n", "default", ":", "return", "ip", "\n", "}", "\n", "}" ]
// GetNextIP returns the next IP from the given IP address. If the given IP is // the last IP of a v4 or v6 range, the same IP is returned.
[ "GetNextIP", "returns", "the", "next", "IP", "from", "the", "given", "IP", "address", ".", "If", "the", "given", "IP", "is", "the", "last", "IP", "of", "a", "v4", "or", "v6", "range", "the", "same", "IP", "is", "returned", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ip/ip.go#L342-L369
162,756
cilium/cilium
pkg/ip/ip.go
rangeToCIDRs
func rangeToCIDRs(firstIP, lastIP net.IP) []*net.IPNet { // First, create a CIDR that spans both IPs. spanningCIDR := createSpanningCIDR(netWithRange{&firstIP, &lastIP, nil}) spanningRange := ipNetToRange(spanningCIDR) firstIPSpanning := spanningRange.First lastIPSpanning := spanningRange.Last cidrList := []*net.IPNet{} // If the first IP of the spanning CIDR passes the lower bound (firstIP), // we need to split the spanning CIDR and only take the IPs that are // greater than the value which we split on, as we do not want the lesser // values since they are less than the lower-bound (firstIP). if bytes.Compare(*firstIPSpanning, firstIP) < 0 { // Split on the previous IP of the first IP so that the right list of IPs // of the partition includes the firstIP. prevFirstRangeIP := getPreviousIP(firstIP) var bitLen int if prevFirstRangeIP.To4() != nil { bitLen = ipv4BitLen } else { bitLen = ipv6BitLen } _, _, right := partitionCIDR(spanningCIDR, net.IPNet{IP: prevFirstRangeIP, Mask: net.CIDRMask(bitLen, bitLen)}) // Append all CIDRs but the first, as this CIDR includes the upper // bound of the spanning CIDR, which we still need to partition on. cidrList = append(cidrList, right...) spanningCIDR = *right[0] cidrList = cidrList[1:] } // Conversely, if the last IP of the spanning CIDR passes the upper bound // (lastIP), we need to split the spanning CIDR and only take the IPs that // are greater than the value which we split on, as we do not want the greater // values since they are greater than the upper-bound (lastIP). if bytes.Compare(*lastIPSpanning, lastIP) > 0 { // Split on the next IP of the last IP so that the left list of IPs // of the partition include the lastIP. nextFirstRangeIP := GetNextIP(lastIP) var bitLen int if nextFirstRangeIP.To4() != nil { bitLen = ipv4BitLen } else { bitLen = ipv6BitLen } left, _, _ := partitionCIDR(spanningCIDR, net.IPNet{IP: nextFirstRangeIP, Mask: net.CIDRMask(bitLen, bitLen)}) cidrList = append(cidrList, left...) } else { // Otherwise, there is no need to partition; just use add the spanning // CIDR to the list of networks. cidrList = append(cidrList, &spanningCIDR) } return cidrList }
go
func rangeToCIDRs(firstIP, lastIP net.IP) []*net.IPNet { // First, create a CIDR that spans both IPs. spanningCIDR := createSpanningCIDR(netWithRange{&firstIP, &lastIP, nil}) spanningRange := ipNetToRange(spanningCIDR) firstIPSpanning := spanningRange.First lastIPSpanning := spanningRange.Last cidrList := []*net.IPNet{} // If the first IP of the spanning CIDR passes the lower bound (firstIP), // we need to split the spanning CIDR and only take the IPs that are // greater than the value which we split on, as we do not want the lesser // values since they are less than the lower-bound (firstIP). if bytes.Compare(*firstIPSpanning, firstIP) < 0 { // Split on the previous IP of the first IP so that the right list of IPs // of the partition includes the firstIP. prevFirstRangeIP := getPreviousIP(firstIP) var bitLen int if prevFirstRangeIP.To4() != nil { bitLen = ipv4BitLen } else { bitLen = ipv6BitLen } _, _, right := partitionCIDR(spanningCIDR, net.IPNet{IP: prevFirstRangeIP, Mask: net.CIDRMask(bitLen, bitLen)}) // Append all CIDRs but the first, as this CIDR includes the upper // bound of the spanning CIDR, which we still need to partition on. cidrList = append(cidrList, right...) spanningCIDR = *right[0] cidrList = cidrList[1:] } // Conversely, if the last IP of the spanning CIDR passes the upper bound // (lastIP), we need to split the spanning CIDR and only take the IPs that // are greater than the value which we split on, as we do not want the greater // values since they are greater than the upper-bound (lastIP). if bytes.Compare(*lastIPSpanning, lastIP) > 0 { // Split on the next IP of the last IP so that the left list of IPs // of the partition include the lastIP. nextFirstRangeIP := GetNextIP(lastIP) var bitLen int if nextFirstRangeIP.To4() != nil { bitLen = ipv4BitLen } else { bitLen = ipv6BitLen } left, _, _ := partitionCIDR(spanningCIDR, net.IPNet{IP: nextFirstRangeIP, Mask: net.CIDRMask(bitLen, bitLen)}) cidrList = append(cidrList, left...) } else { // Otherwise, there is no need to partition; just use add the spanning // CIDR to the list of networks. cidrList = append(cidrList, &spanningCIDR) } return cidrList }
[ "func", "rangeToCIDRs", "(", "firstIP", ",", "lastIP", "net", ".", "IP", ")", "[", "]", "*", "net", ".", "IPNet", "{", "// First, create a CIDR that spans both IPs.", "spanningCIDR", ":=", "createSpanningCIDR", "(", "netWithRange", "{", "&", "firstIP", ",", "&", "lastIP", ",", "nil", "}", ")", "\n", "spanningRange", ":=", "ipNetToRange", "(", "spanningCIDR", ")", "\n", "firstIPSpanning", ":=", "spanningRange", ".", "First", "\n", "lastIPSpanning", ":=", "spanningRange", ".", "Last", "\n\n", "cidrList", ":=", "[", "]", "*", "net", ".", "IPNet", "{", "}", "\n\n", "// If the first IP of the spanning CIDR passes the lower bound (firstIP),", "// we need to split the spanning CIDR and only take the IPs that are", "// greater than the value which we split on, as we do not want the lesser", "// values since they are less than the lower-bound (firstIP).", "if", "bytes", ".", "Compare", "(", "*", "firstIPSpanning", ",", "firstIP", ")", "<", "0", "{", "// Split on the previous IP of the first IP so that the right list of IPs", "// of the partition includes the firstIP.", "prevFirstRangeIP", ":=", "getPreviousIP", "(", "firstIP", ")", "\n", "var", "bitLen", "int", "\n", "if", "prevFirstRangeIP", ".", "To4", "(", ")", "!=", "nil", "{", "bitLen", "=", "ipv4BitLen", "\n", "}", "else", "{", "bitLen", "=", "ipv6BitLen", "\n", "}", "\n", "_", ",", "_", ",", "right", ":=", "partitionCIDR", "(", "spanningCIDR", ",", "net", ".", "IPNet", "{", "IP", ":", "prevFirstRangeIP", ",", "Mask", ":", "net", ".", "CIDRMask", "(", "bitLen", ",", "bitLen", ")", "}", ")", "\n\n", "// Append all CIDRs but the first, as this CIDR includes the upper", "// bound of the spanning CIDR, which we still need to partition on.", "cidrList", "=", "append", "(", "cidrList", ",", "right", "...", ")", "\n", "spanningCIDR", "=", "*", "right", "[", "0", "]", "\n", "cidrList", "=", "cidrList", "[", "1", ":", "]", "\n", "}", "\n\n", "// Conversely, if the last IP of the spanning CIDR passes the upper bound", "// (lastIP), we need to split the spanning CIDR and only take the IPs that", "// are greater than the value which we split on, as we do not want the greater", "// values since they are greater than the upper-bound (lastIP).", "if", "bytes", ".", "Compare", "(", "*", "lastIPSpanning", ",", "lastIP", ")", ">", "0", "{", "// Split on the next IP of the last IP so that the left list of IPs", "// of the partition include the lastIP.", "nextFirstRangeIP", ":=", "GetNextIP", "(", "lastIP", ")", "\n", "var", "bitLen", "int", "\n", "if", "nextFirstRangeIP", ".", "To4", "(", ")", "!=", "nil", "{", "bitLen", "=", "ipv4BitLen", "\n", "}", "else", "{", "bitLen", "=", "ipv6BitLen", "\n", "}", "\n", "left", ",", "_", ",", "_", ":=", "partitionCIDR", "(", "spanningCIDR", ",", "net", ".", "IPNet", "{", "IP", ":", "nextFirstRangeIP", ",", "Mask", ":", "net", ".", "CIDRMask", "(", "bitLen", ",", "bitLen", ")", "}", ")", "\n", "cidrList", "=", "append", "(", "cidrList", ",", "left", "...", ")", "\n", "}", "else", "{", "// Otherwise, there is no need to partition; just use add the spanning", "// CIDR to the list of networks.", "cidrList", "=", "append", "(", "cidrList", ",", "&", "spanningCIDR", ")", "\n", "}", "\n", "return", "cidrList", "\n", "}" ]
// rangeToCIDRs converts the range of IPs covered by firstIP and lastIP to // a list of CIDRs that contains all of the IPs covered by the range.
[ "rangeToCIDRs", "converts", "the", "range", "of", "IPs", "covered", "by", "firstIP", "and", "lastIP", "to", "a", "list", "of", "CIDRs", "that", "contains", "all", "of", "the", "IPs", "covered", "by", "the", "range", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ip/ip.go#L527-L582
162,757
cilium/cilium
pkg/ip/ip.go
IsPublicAddr
func IsPublicAddr(ip net.IP) bool { for _, block := range privateIPBlocks { if block.Contains(ip) { return false } } return true }
go
func IsPublicAddr(ip net.IP) bool { for _, block := range privateIPBlocks { if block.Contains(ip) { return false } } return true }
[ "func", "IsPublicAddr", "(", "ip", "net", ".", "IP", ")", "bool", "{", "for", "_", ",", "block", ":=", "range", "privateIPBlocks", "{", "if", "block", ".", "Contains", "(", "ip", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// IsPublicAddr returns whether a given global IP is from // a public range.
[ "IsPublicAddr", "returns", "whether", "a", "given", "global", "IP", "is", "from", "a", "public", "range", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ip/ip.go#L763-L770
162,758
cilium/cilium
pkg/k8s/init.go
useNodeCIDR
func useNodeCIDR(n *node.Node) { if n.IPv4AllocCIDR != nil && option.Config.EnableIPv4 { node.SetIPv4AllocRange(n.IPv4AllocCIDR) } if n.IPv6AllocCIDR != nil && option.Config.EnableIPv6 { if err := node.SetIPv6NodeRange(n.IPv6AllocCIDR.IPNet); err != nil { log.WithError(err).WithFields(logrus.Fields{ logfields.Node: n.Name, logfields.V6Prefix: n.IPv6AllocCIDR, }).Warn("k8s: Can't use IPv6 CIDR range from k8s") } } }
go
func useNodeCIDR(n *node.Node) { if n.IPv4AllocCIDR != nil && option.Config.EnableIPv4 { node.SetIPv4AllocRange(n.IPv4AllocCIDR) } if n.IPv6AllocCIDR != nil && option.Config.EnableIPv6 { if err := node.SetIPv6NodeRange(n.IPv6AllocCIDR.IPNet); err != nil { log.WithError(err).WithFields(logrus.Fields{ logfields.Node: n.Name, logfields.V6Prefix: n.IPv6AllocCIDR, }).Warn("k8s: Can't use IPv6 CIDR range from k8s") } } }
[ "func", "useNodeCIDR", "(", "n", "*", "node", ".", "Node", ")", "{", "if", "n", ".", "IPv4AllocCIDR", "!=", "nil", "&&", "option", ".", "Config", ".", "EnableIPv4", "{", "node", ".", "SetIPv4AllocRange", "(", "n", ".", "IPv4AllocCIDR", ")", "\n", "}", "\n", "if", "n", ".", "IPv6AllocCIDR", "!=", "nil", "&&", "option", ".", "Config", ".", "EnableIPv6", "{", "if", "err", ":=", "node", ".", "SetIPv6NodeRange", "(", "n", ".", "IPv6AllocCIDR", ".", "IPNet", ")", ";", "err", "!=", "nil", "{", "log", ".", "WithError", "(", "err", ")", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "logfields", ".", "Node", ":", "n", ".", "Name", ",", "logfields", ".", "V6Prefix", ":", "n", ".", "IPv6AllocCIDR", ",", "}", ")", ".", "Warn", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}" ]
// useNodeCIDR sets the ipv4-range and ipv6-range values values from the // addresses defined in the given node.
[ "useNodeCIDR", "sets", "the", "ipv4", "-", "range", "and", "ipv6", "-", "range", "values", "values", "from", "the", "addresses", "defined", "in", "the", "given", "node", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/init.go#L98-L110
162,759
cilium/cilium
pkg/idpool/idpool.go
NewIDPool
func NewIDPool(minID ID, maxID ID) *IDPool { p := &IDPool{ minID: minID, maxID: maxID, } p.idCache = newIDCache(p.minID, p.maxID) return p }
go
func NewIDPool(minID ID, maxID ID) *IDPool { p := &IDPool{ minID: minID, maxID: maxID, } p.idCache = newIDCache(p.minID, p.maxID) return p }
[ "func", "NewIDPool", "(", "minID", "ID", ",", "maxID", "ID", ")", "*", "IDPool", "{", "p", ":=", "&", "IDPool", "{", "minID", ":", "minID", ",", "maxID", ":", "maxID", ",", "}", "\n\n", "p", ".", "idCache", "=", "newIDCache", "(", "p", ".", "minID", ",", "p", ".", "maxID", ")", "\n\n", "return", "p", "\n", "}" ]
// NewIDPool returns a new ID pool
[ "NewIDPool", "returns", "a", "new", "ID", "pool" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/idpool/idpool.go#L81-L90
162,760
cilium/cilium
pkg/idpool/idpool.go
LeaseAvailableID
func (p *IDPool) LeaseAvailableID() ID { p.mutex.Lock() defer p.mutex.Unlock() return p.idCache.leaseAvailableID() }
go
func (p *IDPool) LeaseAvailableID() ID { p.mutex.Lock() defer p.mutex.Unlock() return p.idCache.leaseAvailableID() }
[ "func", "(", "p", "*", "IDPool", ")", "LeaseAvailableID", "(", ")", "ID", "{", "p", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "return", "p", ".", "idCache", ".", "leaseAvailableID", "(", ")", "\n", "}" ]
// LeaseAvailableID returns an available ID at random from the pool. // Returns an ID or NoID if no there is no available ID in the pool.
[ "LeaseAvailableID", "returns", "an", "available", "ID", "at", "random", "from", "the", "pool", ".", "Returns", "an", "ID", "or", "NoID", "if", "no", "there", "is", "no", "available", "ID", "in", "the", "pool", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/idpool/idpool.go#L94-L99
162,761
cilium/cilium
pkg/idpool/idpool.go
Use
func (p *IDPool) Use(id ID) bool { p.mutex.Lock() defer p.mutex.Unlock() return p.idCache.use(id) }
go
func (p *IDPool) Use(id ID) bool { p.mutex.Lock() defer p.mutex.Unlock() return p.idCache.use(id) }
[ "func", "(", "p", "*", "IDPool", ")", "Use", "(", "id", "ID", ")", "bool", "{", "p", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "return", "p", ".", "idCache", ".", "use", "(", "id", ")", "\n", "}" ]
// Use makes a leased ID unavailable in the pool and has no effect // otherwise. Returns true if the ID was made unavailable // as a result of this call.
[ "Use", "makes", "a", "leased", "ID", "unavailable", "in", "the", "pool", "and", "has", "no", "effect", "otherwise", ".", "Returns", "true", "if", "the", "ID", "was", "made", "unavailable", "as", "a", "result", "of", "this", "call", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/idpool/idpool.go#L128-L133
162,762
cilium/cilium
pkg/idpool/idpool.go
Insert
func (p *IDPool) Insert(id ID) bool { p.mutex.Lock() defer p.mutex.Unlock() return p.idCache.insert(id) }
go
func (p *IDPool) Insert(id ID) bool { p.mutex.Lock() defer p.mutex.Unlock() return p.idCache.insert(id) }
[ "func", "(", "p", "*", "IDPool", ")", "Insert", "(", "id", "ID", ")", "bool", "{", "p", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "return", "p", ".", "idCache", ".", "insert", "(", "id", ")", "\n", "}" ]
// Insert makes an unavailable ID available in the pool // and has no effect otherwise. Returns true if the ID // was added back to the pool.
[ "Insert", "makes", "an", "unavailable", "ID", "available", "in", "the", "pool", "and", "has", "no", "effect", "otherwise", ".", "Returns", "true", "if", "the", "ID", "was", "added", "back", "to", "the", "pool", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/idpool/idpool.go#L138-L143
162,763
cilium/cilium
pkg/idpool/idpool.go
Remove
func (p *IDPool) Remove(id ID) bool { p.mutex.Lock() defer p.mutex.Unlock() return p.idCache.remove(id) }
go
func (p *IDPool) Remove(id ID) bool { p.mutex.Lock() defer p.mutex.Unlock() return p.idCache.remove(id) }
[ "func", "(", "p", "*", "IDPool", ")", "Remove", "(", "id", "ID", ")", "bool", "{", "p", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "return", "p", ".", "idCache", ".", "remove", "(", "id", ")", "\n", "}" ]
// Remove makes an ID unavailable in the pool. // Returns true if the ID was previously available in the pool.
[ "Remove", "makes", "an", "ID", "unavailable", "in", "the", "pool", ".", "Returns", "true", "if", "the", "ID", "was", "previously", "available", "in", "the", "pool", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/idpool/idpool.go#L147-L152
162,764
cilium/cilium
pkg/idpool/idpool.go
allocateID
func (c *idCache) allocateID() ID { for id := range c.ids { delete(c.ids, id) return id } return NoID }
go
func (c *idCache) allocateID() ID { for id := range c.ids { delete(c.ids, id) return id } return NoID }
[ "func", "(", "c", "*", "idCache", ")", "allocateID", "(", ")", "ID", "{", "for", "id", ":=", "range", "c", ".", "ids", "{", "delete", "(", "c", ".", "ids", ",", "id", ")", "\n", "return", "id", "\n", "}", "\n\n", "return", "NoID", "\n", "}" ]
// allocateID returns a random available ID without leasing it
[ "allocateID", "returns", "a", "random", "available", "ID", "without", "leasing", "it" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/idpool/idpool.go#L184-L191
162,765
cilium/cilium
pkg/idpool/idpool.go
leaseAvailableID
func (c *idCache) leaseAvailableID() ID { id := c.allocateID() if id == NoID { return NoID } // Mark as leased c.leased[id] = struct{}{} return id }
go
func (c *idCache) leaseAvailableID() ID { id := c.allocateID() if id == NoID { return NoID } // Mark as leased c.leased[id] = struct{}{} return id }
[ "func", "(", "c", "*", "idCache", ")", "leaseAvailableID", "(", ")", "ID", "{", "id", ":=", "c", ".", "allocateID", "(", ")", "\n", "if", "id", "==", "NoID", "{", "return", "NoID", "\n", "}", "\n\n", "// Mark as leased", "c", ".", "leased", "[", "id", "]", "=", "struct", "{", "}", "{", "}", "\n\n", "return", "id", "\n", "}" ]
// leaseAvailableID returns a random available ID.
[ "leaseAvailableID", "returns", "a", "random", "available", "ID", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/idpool/idpool.go#L194-L204
162,766
cilium/cilium
pkg/idpool/idpool.go
release
func (c *idCache) release(id ID) bool { if _, exists := c.leased[id]; !exists { return false } delete(c.leased, id) c.insert(id) return true }
go
func (c *idCache) release(id ID) bool { if _, exists := c.leased[id]; !exists { return false } delete(c.leased, id) c.insert(id) return true }
[ "func", "(", "c", "*", "idCache", ")", "release", "(", "id", "ID", ")", "bool", "{", "if", "_", ",", "exists", ":=", "c", ".", "leased", "[", "id", "]", ";", "!", "exists", "{", "return", "false", "\n", "}", "\n\n", "delete", "(", "c", ".", "leased", ",", "id", ")", "\n", "c", ".", "insert", "(", "id", ")", "\n\n", "return", "true", "\n", "}" ]
// release makes the ID available again if it is currently // leased and has no effect otherwise. Returns true if the // ID was made available as a result of this call.
[ "release", "makes", "the", "ID", "available", "again", "if", "it", "is", "currently", "leased", "and", "has", "no", "effect", "otherwise", ".", "Returns", "true", "if", "the", "ID", "was", "made", "available", "as", "a", "result", "of", "this", "call", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/idpool/idpool.go#L209-L218
162,767
cilium/cilium
pkg/idpool/idpool.go
use
func (c *idCache) use(id ID) bool { if _, exists := c.leased[id]; !exists { return false } delete(c.leased, id) return true }
go
func (c *idCache) use(id ID) bool { if _, exists := c.leased[id]; !exists { return false } delete(c.leased, id) return true }
[ "func", "(", "c", "*", "idCache", ")", "use", "(", "id", "ID", ")", "bool", "{", "if", "_", ",", "exists", ":=", "c", ".", "leased", "[", "id", "]", ";", "!", "exists", "{", "return", "false", "\n", "}", "\n\n", "delete", "(", "c", ".", "leased", ",", "id", ")", "\n", "return", "true", "\n", "}" ]
// use makes the ID unavailable if it is currently // leased and has no effect otherwise. Returns true if the // ID was made unavailable as a result of this call.
[ "use", "makes", "the", "ID", "unavailable", "if", "it", "is", "currently", "leased", "and", "has", "no", "effect", "otherwise", ".", "Returns", "true", "if", "the", "ID", "was", "made", "unavailable", "as", "a", "result", "of", "this", "call", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/idpool/idpool.go#L223-L230
162,768
cilium/cilium
pkg/idpool/idpool.go
insert
func (c *idCache) insert(id ID) bool { if _, ok := c.ids[id]; ok { return false } if _, exists := c.leased[id]; exists { return false } c.ids[id] = struct{}{} return true }
go
func (c *idCache) insert(id ID) bool { if _, ok := c.ids[id]; ok { return false } if _, exists := c.leased[id]; exists { return false } c.ids[id] = struct{}{} return true }
[ "func", "(", "c", "*", "idCache", ")", "insert", "(", "id", "ID", ")", "bool", "{", "if", "_", ",", "ok", ":=", "c", ".", "ids", "[", "id", "]", ";", "ok", "{", "return", "false", "\n", "}", "\n\n", "if", "_", ",", "exists", ":=", "c", ".", "leased", "[", "id", "]", ";", "exists", "{", "return", "false", "\n", "}", "\n\n", "c", ".", "ids", "[", "id", "]", "=", "struct", "{", "}", "{", "}", "\n", "return", "true", "\n", "}" ]
// insert adds the ID into the cache if it is currently unavailable. // Returns true if the ID was added to the cache.
[ "insert", "adds", "the", "ID", "into", "the", "cache", "if", "it", "is", "currently", "unavailable", ".", "Returns", "true", "if", "the", "ID", "was", "added", "to", "the", "cache", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/idpool/idpool.go#L234-L245
162,769
cilium/cilium
pkg/idpool/idpool.go
remove
func (c *idCache) remove(id ID) bool { delete(c.leased, id) if _, ok := c.ids[id]; ok { delete(c.ids, id) return true } return false }
go
func (c *idCache) remove(id ID) bool { delete(c.leased, id) if _, ok := c.ids[id]; ok { delete(c.ids, id) return true } return false }
[ "func", "(", "c", "*", "idCache", ")", "remove", "(", "id", "ID", ")", "bool", "{", "delete", "(", "c", ".", "leased", ",", "id", ")", "\n\n", "if", "_", ",", "ok", ":=", "c", ".", "ids", "[", "id", "]", ";", "ok", "{", "delete", "(", "c", ".", "ids", ",", "id", ")", "\n", "return", "true", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// remove removes the ID from the cache. // Returns true if the ID was available in the cache.
[ "remove", "removes", "the", "ID", "from", "the", "cache", ".", "Returns", "true", "if", "the", "ID", "was", "available", "in", "the", "cache", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/idpool/idpool.go#L249-L258
162,770
cilium/cilium
pkg/endpoint/lock.go
LockAlive
func (e *Endpoint) LockAlive() error { e.mutex.Lock() if e.IsDisconnecting() { e.mutex.Unlock() return fmt.Errorf("lock failed: endpoint is in the process of being removed") } return nil }
go
func (e *Endpoint) LockAlive() error { e.mutex.Lock() if e.IsDisconnecting() { e.mutex.Unlock() return fmt.Errorf("lock failed: endpoint is in the process of being removed") } return nil }
[ "func", "(", "e", "*", "Endpoint", ")", "LockAlive", "(", ")", "error", "{", "e", ".", "mutex", ".", "Lock", "(", ")", "\n", "if", "e", ".", "IsDisconnecting", "(", ")", "{", "e", ".", "mutex", ".", "Unlock", "(", ")", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// LockAlive returns error if endpoint was removed, locks underlying mutex otherwise
[ "LockAlive", "returns", "error", "if", "endpoint", "was", "removed", "locks", "underlying", "mutex", "otherwise" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/lock.go#L20-L27
162,771
cilium/cilium
pkg/endpoint/lock.go
RLockAlive
func (e *Endpoint) RLockAlive() error { e.mutex.RLock() if e.IsDisconnecting() { e.mutex.RUnlock() return ErrNotAlive } return nil }
go
func (e *Endpoint) RLockAlive() error { e.mutex.RLock() if e.IsDisconnecting() { e.mutex.RUnlock() return ErrNotAlive } return nil }
[ "func", "(", "e", "*", "Endpoint", ")", "RLockAlive", "(", ")", "error", "{", "e", ".", "mutex", ".", "RLock", "(", ")", "\n", "if", "e", ".", "IsDisconnecting", "(", ")", "{", "e", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "ErrNotAlive", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RLockAlive returns error if endpoint was removed, read locks underlying mutex otherwise
[ "RLockAlive", "returns", "error", "if", "endpoint", "was", "removed", "read", "locks", "underlying", "mutex", "otherwise" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/lock.go#L35-L42
162,772
cilium/cilium
pkg/endpoint/lock.go
LogDisconnectedMutexAction
func (e *Endpoint) LogDisconnectedMutexAction(err error, context string) { e.getLogger().WithError(err).Error(context) }
go
func (e *Endpoint) LogDisconnectedMutexAction(err error, context string) { e.getLogger().WithError(err).Error(context) }
[ "func", "(", "e", "*", "Endpoint", ")", "LogDisconnectedMutexAction", "(", "err", "error", ",", "context", "string", ")", "{", "e", ".", "getLogger", "(", ")", ".", "WithError", "(", "err", ")", ".", "Error", "(", "context", ")", "\n", "}" ]
// LogDisconnectedMutexAction gets the logger and logs given error with context
[ "LogDisconnectedMutexAction", "gets", "the", "logger", "and", "logs", "given", "error", "with", "context" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/lock.go#L64-L66
162,773
cilium/cilium
pkg/service/zz_generated.deepcopy.go
DeepCopy
func (in *ClusterService) DeepCopy() *ClusterService { if in == nil { return nil } out := new(ClusterService) in.DeepCopyInto(out) return out }
go
func (in *ClusterService) DeepCopy() *ClusterService { if in == nil { return nil } out := new(ClusterService) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "ClusterService", ")", "DeepCopy", "(", ")", "*", "ClusterService", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "ClusterService", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterService.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "ClusterService", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/service/zz_generated.deepcopy.go#L94-L101
162,774
cilium/cilium
pkg/identity/cache/local.go
getNextFreeNumericIdentity
func (l *localIdentityCache) getNextFreeNumericIdentity() (identity.NumericIdentity, error) { firstID := l.nextNumericIdentity for { idCandidate := l.nextNumericIdentity | identity.LocalIdentityFlag if _, ok := l.identitiesByID[idCandidate]; !ok { l.bumpNextNumericIdentity() return idCandidate, nil } l.bumpNextNumericIdentity() if l.nextNumericIdentity == firstID { return 0, fmt.Errorf("out of local identity space") } } }
go
func (l *localIdentityCache) getNextFreeNumericIdentity() (identity.NumericIdentity, error) { firstID := l.nextNumericIdentity for { idCandidate := l.nextNumericIdentity | identity.LocalIdentityFlag if _, ok := l.identitiesByID[idCandidate]; !ok { l.bumpNextNumericIdentity() return idCandidate, nil } l.bumpNextNumericIdentity() if l.nextNumericIdentity == firstID { return 0, fmt.Errorf("out of local identity space") } } }
[ "func", "(", "l", "*", "localIdentityCache", ")", "getNextFreeNumericIdentity", "(", ")", "(", "identity", ".", "NumericIdentity", ",", "error", ")", "{", "firstID", ":=", "l", ".", "nextNumericIdentity", "\n", "for", "{", "idCandidate", ":=", "l", ".", "nextNumericIdentity", "|", "identity", ".", "LocalIdentityFlag", "\n", "if", "_", ",", "ok", ":=", "l", ".", "identitiesByID", "[", "idCandidate", "]", ";", "!", "ok", "{", "l", ".", "bumpNextNumericIdentity", "(", ")", "\n", "return", "idCandidate", ",", "nil", "\n", "}", "\n\n", "l", ".", "bumpNextNumericIdentity", "(", ")", "\n", "if", "l", ".", "nextNumericIdentity", "==", "firstID", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}" ]
// getNextFreeNumericIdentity returns the next available numeric identity or an error // The l.mutex must be held
[ "getNextFreeNumericIdentity", "returns", "the", "next", "available", "numeric", "identity", "or", "an", "error", "The", "l", ".", "mutex", "must", "be", "held" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/local.go#L59-L73
162,775
cilium/cilium
pkg/identity/cache/local.go
release
func (l *localIdentityCache) release(id *identity.Identity) bool { l.mutex.Lock() defer l.mutex.Unlock() stringRepresentation := string(id.Labels.SortedList()) if id, ok := l.identitiesByLabels[stringRepresentation]; ok { switch { case id.ReferenceCount > 1: id.ReferenceCount-- return false case id.ReferenceCount == 1: // Release is only attempted once, when the reference count is // hitting the last use stringRepresentation := string(id.Labels.SortedList()) delete(l.identitiesByLabels, stringRepresentation) delete(l.identitiesByID, id.ID) if l.events != nil { l.events <- allocator.AllocatorEvent{ Typ: kvstore.EventTypeDelete, ID: idpool.ID(id.ID), } } return true } } return false }
go
func (l *localIdentityCache) release(id *identity.Identity) bool { l.mutex.Lock() defer l.mutex.Unlock() stringRepresentation := string(id.Labels.SortedList()) if id, ok := l.identitiesByLabels[stringRepresentation]; ok { switch { case id.ReferenceCount > 1: id.ReferenceCount-- return false case id.ReferenceCount == 1: // Release is only attempted once, when the reference count is // hitting the last use stringRepresentation := string(id.Labels.SortedList()) delete(l.identitiesByLabels, stringRepresentation) delete(l.identitiesByID, id.ID) if l.events != nil { l.events <- allocator.AllocatorEvent{ Typ: kvstore.EventTypeDelete, ID: idpool.ID(id.ID), } } return true } } return false }
[ "func", "(", "l", "*", "localIdentityCache", ")", "release", "(", "id", "*", "identity", ".", "Identity", ")", "bool", "{", "l", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "stringRepresentation", ":=", "string", "(", "id", ".", "Labels", ".", "SortedList", "(", ")", ")", "\n", "if", "id", ",", "ok", ":=", "l", ".", "identitiesByLabels", "[", "stringRepresentation", "]", ";", "ok", "{", "switch", "{", "case", "id", ".", "ReferenceCount", ">", "1", ":", "id", ".", "ReferenceCount", "--", "\n", "return", "false", "\n\n", "case", "id", ".", "ReferenceCount", "==", "1", ":", "// Release is only attempted once, when the reference count is", "// hitting the last use", "stringRepresentation", ":=", "string", "(", "id", ".", "Labels", ".", "SortedList", "(", ")", ")", "\n", "delete", "(", "l", ".", "identitiesByLabels", ",", "stringRepresentation", ")", "\n", "delete", "(", "l", ".", "identitiesByID", ",", "id", ".", "ID", ")", "\n\n", "if", "l", ".", "events", "!=", "nil", "{", "l", ".", "events", "<-", "allocator", ".", "AllocatorEvent", "{", "Typ", ":", "kvstore", ".", "EventTypeDelete", ",", "ID", ":", "idpool", ".", "ID", "(", "id", ".", "ID", ")", ",", "}", "\n", "}", "\n\n", "return", "true", "\n", "}", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// release releases a local identity from the cache. true is returned when the // last use of the identity has been released and the identity has been // forgotten.
[ "release", "releases", "a", "local", "identity", "from", "the", "cache", ".", "true", "is", "returned", "when", "the", "last", "use", "of", "the", "identity", "has", "been", "released", "and", "the", "identity", "has", "been", "forgotten", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/local.go#L119-L149
162,776
cilium/cilium
pkg/identity/cache/local.go
lookup
func (l *localIdentityCache) lookup(lbls labels.Labels) *identity.Identity { l.mutex.RLock() defer l.mutex.RUnlock() stringRepresentation := string(lbls.SortedList()) if id, ok := l.identitiesByLabels[stringRepresentation]; ok { return id } return nil }
go
func (l *localIdentityCache) lookup(lbls labels.Labels) *identity.Identity { l.mutex.RLock() defer l.mutex.RUnlock() stringRepresentation := string(lbls.SortedList()) if id, ok := l.identitiesByLabels[stringRepresentation]; ok { return id } return nil }
[ "func", "(", "l", "*", "localIdentityCache", ")", "lookup", "(", "lbls", "labels", ".", "Labels", ")", "*", "identity", ".", "Identity", "{", "l", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "l", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "stringRepresentation", ":=", "string", "(", "lbls", ".", "SortedList", "(", ")", ")", "\n", "if", "id", ",", "ok", ":=", "l", ".", "identitiesByLabels", "[", "stringRepresentation", "]", ";", "ok", "{", "return", "id", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// lookup searches for a local identity matching the given labels and returns // it. If found, the reference count is NOT incremented and thus release must // NOT be called.
[ "lookup", "searches", "for", "a", "local", "identity", "matching", "the", "given", "labels", "and", "returns", "it", ".", "If", "found", "the", "reference", "count", "is", "NOT", "incremented", "and", "thus", "release", "must", "NOT", "be", "called", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/local.go#L154-L164
162,777
cilium/cilium
pkg/identity/cache/local.go
lookupByID
func (l *localIdentityCache) lookupByID(id identity.NumericIdentity) *identity.Identity { l.mutex.RLock() defer l.mutex.RUnlock() if id, ok := l.identitiesByID[id]; ok { return id } return nil }
go
func (l *localIdentityCache) lookupByID(id identity.NumericIdentity) *identity.Identity { l.mutex.RLock() defer l.mutex.RUnlock() if id, ok := l.identitiesByID[id]; ok { return id } return nil }
[ "func", "(", "l", "*", "localIdentityCache", ")", "lookupByID", "(", "id", "identity", ".", "NumericIdentity", ")", "*", "identity", ".", "Identity", "{", "l", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "l", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "if", "id", ",", "ok", ":=", "l", ".", "identitiesByID", "[", "id", "]", ";", "ok", "{", "return", "id", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// lookupByID searches for a local identity matching the given ID and returns // it. If found, the reference count is NOT incremented and thus release must // NOT be called.
[ "lookupByID", "searches", "for", "a", "local", "identity", "matching", "the", "given", "ID", "and", "returns", "it", ".", "If", "found", "the", "reference", "count", "is", "NOT", "incremented", "and", "thus", "release", "must", "NOT", "be", "called", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/local.go#L169-L178
162,778
cilium/cilium
pkg/identity/cache/local.go
GetIdentities
func (l *localIdentityCache) GetIdentities() map[identity.NumericIdentity]*identity.Identity { cache := map[identity.NumericIdentity]*identity.Identity{} l.mutex.RLock() defer l.mutex.RUnlock() for key, id := range l.identitiesByID { cache[key] = id } return cache }
go
func (l *localIdentityCache) GetIdentities() map[identity.NumericIdentity]*identity.Identity { cache := map[identity.NumericIdentity]*identity.Identity{} l.mutex.RLock() defer l.mutex.RUnlock() for key, id := range l.identitiesByID { cache[key] = id } return cache }
[ "func", "(", "l", "*", "localIdentityCache", ")", "GetIdentities", "(", ")", "map", "[", "identity", ".", "NumericIdentity", "]", "*", "identity", ".", "Identity", "{", "cache", ":=", "map", "[", "identity", ".", "NumericIdentity", "]", "*", "identity", ".", "Identity", "{", "}", "\n\n", "l", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "l", ".", "mutex", ".", "RUnlock", "(", ")", "\n\n", "for", "key", ",", "id", ":=", "range", "l", ".", "identitiesByID", "{", "cache", "[", "key", "]", "=", "id", "\n", "}", "\n\n", "return", "cache", "\n", "}" ]
// GetIdentities returns all local identities
[ "GetIdentities", "returns", "all", "local", "identities" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/local.go#L181-L192
162,779
cilium/cilium
pkg/policy/api/groups.go
GetCidrSet
func (group *ToGroups) GetCidrSet() ([]CIDRRule, error) { var ips []net.IP // Get per provider CIDRSet if group.AWS != nil { callbackInterface, ok := providers.Load(AWSProvider) if !ok { return nil, fmt.Errorf("Provider %s is not registered", AWSProvider) } callback, ok := callbackInterface.(GroupProviderFunc) if !ok { return nil, fmt.Errorf("Provider callback for %s is not a valid instance", AWSProvider) } awsIPs, err := callback(group) if err != nil { return nil, fmt.Errorf( "Cannot retrieve data from %s provider: %s", AWSProvider, err) } ips = append(ips, awsIPs...) } resultIps := ip.KeepUniqueIPs(ips) return IPsToCIDRRules(resultIps), nil }
go
func (group *ToGroups) GetCidrSet() ([]CIDRRule, error) { var ips []net.IP // Get per provider CIDRSet if group.AWS != nil { callbackInterface, ok := providers.Load(AWSProvider) if !ok { return nil, fmt.Errorf("Provider %s is not registered", AWSProvider) } callback, ok := callbackInterface.(GroupProviderFunc) if !ok { return nil, fmt.Errorf("Provider callback for %s is not a valid instance", AWSProvider) } awsIPs, err := callback(group) if err != nil { return nil, fmt.Errorf( "Cannot retrieve data from %s provider: %s", AWSProvider, err) } ips = append(ips, awsIPs...) } resultIps := ip.KeepUniqueIPs(ips) return IPsToCIDRRules(resultIps), nil }
[ "func", "(", "group", "*", "ToGroups", ")", "GetCidrSet", "(", ")", "(", "[", "]", "CIDRRule", ",", "error", ")", "{", "var", "ips", "[", "]", "net", ".", "IP", "\n", "// Get per provider CIDRSet", "if", "group", ".", "AWS", "!=", "nil", "{", "callbackInterface", ",", "ok", ":=", "providers", ".", "Load", "(", "AWSProvider", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "AWSProvider", ")", "\n", "}", "\n", "callback", ",", "ok", ":=", "callbackInterface", ".", "(", "GroupProviderFunc", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "AWSProvider", ")", "\n", "}", "\n", "awsIPs", ",", "err", ":=", "callback", "(", "group", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "AWSProvider", ",", "err", ")", "\n", "}", "\n", "ips", "=", "append", "(", "ips", ",", "awsIPs", "...", ")", "\n", "}", "\n\n", "resultIps", ":=", "ip", ".", "KeepUniqueIPs", "(", "ips", ")", "\n", "return", "IPsToCIDRRules", "(", "resultIps", ")", ",", "nil", "\n", "}" ]
// GetCidrSet will return the CIDRRule for the rule using the callbacks that // are register in the platform.
[ "GetCidrSet", "will", "return", "the", "CIDRRule", "for", "the", "rule", "using", "the", "callbacks", "that", "are", "register", "in", "the", "platform", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/groups.go#L59-L83
162,780
cilium/cilium
api/v1/server/restapi/daemon/get_debuginfo_responses.go
WithPayload
func (o *GetDebuginfoOK) WithPayload(payload *models.DebugInfo) *GetDebuginfoOK { o.Payload = payload return o }
go
func (o *GetDebuginfoOK) WithPayload(payload *models.DebugInfo) *GetDebuginfoOK { o.Payload = payload return o }
[ "func", "(", "o", "*", "GetDebuginfoOK", ")", "WithPayload", "(", "payload", "*", "models", ".", "DebugInfo", ")", "*", "GetDebuginfoOK", "{", "o", ".", "Payload", "=", "payload", "\n", "return", "o", "\n", "}" ]
// WithPayload adds the payload to the get debuginfo o k response
[ "WithPayload", "adds", "the", "payload", "to", "the", "get", "debuginfo", "o", "k", "response" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/daemon/get_debuginfo_responses.go#L38-L41
162,781
cilium/cilium
api/v1/server/restapi/daemon/get_debuginfo_responses.go
WithPayload
func (o *GetDebuginfoFailure) WithPayload(payload models.Error) *GetDebuginfoFailure { o.Payload = payload return o }
go
func (o *GetDebuginfoFailure) WithPayload(payload models.Error) *GetDebuginfoFailure { o.Payload = payload return o }
[ "func", "(", "o", "*", "GetDebuginfoFailure", ")", "WithPayload", "(", "payload", "models", ".", "Error", ")", "*", "GetDebuginfoFailure", "{", "o", ".", "Payload", "=", "payload", "\n", "return", "o", "\n", "}" ]
// WithPayload adds the payload to the get debuginfo failure response
[ "WithPayload", "adds", "the", "payload", "to", "the", "get", "debuginfo", "failure", "response" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/daemon/get_debuginfo_responses.go#L82-L85
162,782
cilium/cilium
api/v1/client/policy/get_policy_parameters.go
WithTimeout
func (o *GetPolicyParams) WithTimeout(timeout time.Duration) *GetPolicyParams { o.SetTimeout(timeout) return o }
go
func (o *GetPolicyParams) WithTimeout(timeout time.Duration) *GetPolicyParams { o.SetTimeout(timeout) return o }
[ "func", "(", "o", "*", "GetPolicyParams", ")", "WithTimeout", "(", "timeout", "time", ".", "Duration", ")", "*", "GetPolicyParams", "{", "o", ".", "SetTimeout", "(", "timeout", ")", "\n", "return", "o", "\n", "}" ]
// WithTimeout adds the timeout to the get policy params
[ "WithTimeout", "adds", "the", "timeout", "to", "the", "get", "policy", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/get_policy_parameters.go#L75-L78
162,783
cilium/cilium
api/v1/client/policy/get_policy_parameters.go
WithContext
func (o *GetPolicyParams) WithContext(ctx context.Context) *GetPolicyParams { o.SetContext(ctx) return o }
go
func (o *GetPolicyParams) WithContext(ctx context.Context) *GetPolicyParams { o.SetContext(ctx) return o }
[ "func", "(", "o", "*", "GetPolicyParams", ")", "WithContext", "(", "ctx", "context", ".", "Context", ")", "*", "GetPolicyParams", "{", "o", ".", "SetContext", "(", "ctx", ")", "\n", "return", "o", "\n", "}" ]
// WithContext adds the context to the get policy params
[ "WithContext", "adds", "the", "context", "to", "the", "get", "policy", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/get_policy_parameters.go#L86-L89
162,784
cilium/cilium
api/v1/client/policy/get_policy_parameters.go
WithHTTPClient
func (o *GetPolicyParams) WithHTTPClient(client *http.Client) *GetPolicyParams { o.SetHTTPClient(client) return o }
go
func (o *GetPolicyParams) WithHTTPClient(client *http.Client) *GetPolicyParams { o.SetHTTPClient(client) return o }
[ "func", "(", "o", "*", "GetPolicyParams", ")", "WithHTTPClient", "(", "client", "*", "http", ".", "Client", ")", "*", "GetPolicyParams", "{", "o", ".", "SetHTTPClient", "(", "client", ")", "\n", "return", "o", "\n", "}" ]
// WithHTTPClient adds the HTTPClient to the get policy params
[ "WithHTTPClient", "adds", "the", "HTTPClient", "to", "the", "get", "policy", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/get_policy_parameters.go#L97-L100
162,785
cilium/cilium
api/v1/client/policy/get_policy_parameters.go
WithLabels
func (o *GetPolicyParams) WithLabels(labels models.Labels) *GetPolicyParams { o.SetLabels(labels) return o }
go
func (o *GetPolicyParams) WithLabels(labels models.Labels) *GetPolicyParams { o.SetLabels(labels) return o }
[ "func", "(", "o", "*", "GetPolicyParams", ")", "WithLabels", "(", "labels", "models", ".", "Labels", ")", "*", "GetPolicyParams", "{", "o", ".", "SetLabels", "(", "labels", ")", "\n", "return", "o", "\n", "}" ]
// WithLabels adds the labels to the get policy params
[ "WithLabels", "adds", "the", "labels", "to", "the", "get", "policy", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/get_policy_parameters.go#L108-L111
162,786
cilium/cilium
api/v1/client/endpoint/patch_endpoint_id_parameters.go
WithTimeout
func (o *PatchEndpointIDParams) WithTimeout(timeout time.Duration) *PatchEndpointIDParams { o.SetTimeout(timeout) return o }
go
func (o *PatchEndpointIDParams) WithTimeout(timeout time.Duration) *PatchEndpointIDParams { o.SetTimeout(timeout) return o }
[ "func", "(", "o", "*", "PatchEndpointIDParams", ")", "WithTimeout", "(", "timeout", "time", ".", "Duration", ")", "*", "PatchEndpointIDParams", "{", "o", ".", "SetTimeout", "(", "timeout", ")", "\n", "return", "o", "\n", "}" ]
// WithTimeout adds the timeout to the patch endpoint ID params
[ "WithTimeout", "adds", "the", "timeout", "to", "the", "patch", "endpoint", "ID", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/patch_endpoint_id_parameters.go#L92-L95
162,787
cilium/cilium
api/v1/client/endpoint/patch_endpoint_id_parameters.go
WithContext
func (o *PatchEndpointIDParams) WithContext(ctx context.Context) *PatchEndpointIDParams { o.SetContext(ctx) return o }
go
func (o *PatchEndpointIDParams) WithContext(ctx context.Context) *PatchEndpointIDParams { o.SetContext(ctx) return o }
[ "func", "(", "o", "*", "PatchEndpointIDParams", ")", "WithContext", "(", "ctx", "context", ".", "Context", ")", "*", "PatchEndpointIDParams", "{", "o", ".", "SetContext", "(", "ctx", ")", "\n", "return", "o", "\n", "}" ]
// WithContext adds the context to the patch endpoint ID params
[ "WithContext", "adds", "the", "context", "to", "the", "patch", "endpoint", "ID", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/patch_endpoint_id_parameters.go#L103-L106
162,788
cilium/cilium
api/v1/client/endpoint/patch_endpoint_id_parameters.go
WithHTTPClient
func (o *PatchEndpointIDParams) WithHTTPClient(client *http.Client) *PatchEndpointIDParams { o.SetHTTPClient(client) return o }
go
func (o *PatchEndpointIDParams) WithHTTPClient(client *http.Client) *PatchEndpointIDParams { o.SetHTTPClient(client) return o }
[ "func", "(", "o", "*", "PatchEndpointIDParams", ")", "WithHTTPClient", "(", "client", "*", "http", ".", "Client", ")", "*", "PatchEndpointIDParams", "{", "o", ".", "SetHTTPClient", "(", "client", ")", "\n", "return", "o", "\n", "}" ]
// WithHTTPClient adds the HTTPClient to the patch endpoint ID params
[ "WithHTTPClient", "adds", "the", "HTTPClient", "to", "the", "patch", "endpoint", "ID", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/patch_endpoint_id_parameters.go#L114-L117
162,789
cilium/cilium
api/v1/client/endpoint/patch_endpoint_id_parameters.go
WithEndpoint
func (o *PatchEndpointIDParams) WithEndpoint(endpoint *models.EndpointChangeRequest) *PatchEndpointIDParams { o.SetEndpoint(endpoint) return o }
go
func (o *PatchEndpointIDParams) WithEndpoint(endpoint *models.EndpointChangeRequest) *PatchEndpointIDParams { o.SetEndpoint(endpoint) return o }
[ "func", "(", "o", "*", "PatchEndpointIDParams", ")", "WithEndpoint", "(", "endpoint", "*", "models", ".", "EndpointChangeRequest", ")", "*", "PatchEndpointIDParams", "{", "o", ".", "SetEndpoint", "(", "endpoint", ")", "\n", "return", "o", "\n", "}" ]
// WithEndpoint adds the endpoint to the patch endpoint ID params
[ "WithEndpoint", "adds", "the", "endpoint", "to", "the", "patch", "endpoint", "ID", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/patch_endpoint_id_parameters.go#L125-L128
162,790
cilium/cilium
api/v1/client/endpoint/patch_endpoint_id_parameters.go
WithID
func (o *PatchEndpointIDParams) WithID(id string) *PatchEndpointIDParams { o.SetID(id) return o }
go
func (o *PatchEndpointIDParams) WithID(id string) *PatchEndpointIDParams { o.SetID(id) return o }
[ "func", "(", "o", "*", "PatchEndpointIDParams", ")", "WithID", "(", "id", "string", ")", "*", "PatchEndpointIDParams", "{", "o", ".", "SetID", "(", "id", ")", "\n", "return", "o", "\n", "}" ]
// WithID adds the id to the patch endpoint ID params
[ "WithID", "adds", "the", "id", "to", "the", "patch", "endpoint", "ID", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/patch_endpoint_id_parameters.go#L136-L139
162,791
cilium/cilium
pkg/pidfile/pidfile.go
Remove
func Remove(path string) { scopedLog := log.WithField(logfields.PIDFile, path) scopedLog.Debug("Removing pidfile") if err := os.Remove(path); err != nil && !os.IsNotExist(err) { scopedLog.WithError(err).Warning("Failed to remove pidfile") } }
go
func Remove(path string) { scopedLog := log.WithField(logfields.PIDFile, path) scopedLog.Debug("Removing pidfile") if err := os.Remove(path); err != nil && !os.IsNotExist(err) { scopedLog.WithError(err).Warning("Failed to remove pidfile") } }
[ "func", "Remove", "(", "path", "string", ")", "{", "scopedLog", ":=", "log", ".", "WithField", "(", "logfields", ".", "PIDFile", ",", "path", ")", "\n", "scopedLog", ".", "Debug", "(", "\"", "\"", ")", "\n", "if", "err", ":=", "os", ".", "Remove", "(", "path", ")", ";", "err", "!=", "nil", "&&", "!", "os", ".", "IsNotExist", "(", "err", ")", "{", "scopedLog", ".", "WithError", "(", "err", ")", ".", "Warning", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// Remove deletes the pidfile at the specified path. This does not clean up // the corresponding process, so should only be used when it is known that the // PID contained in the file at the specified path is no longer running.
[ "Remove", "deletes", "the", "pidfile", "at", "the", "specified", "path", ".", "This", "does", "not", "clean", "up", "the", "corresponding", "process", "so", "should", "only", "be", "used", "when", "it", "is", "known", "that", "the", "PID", "contained", "in", "the", "file", "at", "the", "specified", "path", "is", "no", "longer", "running", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/pidfile/pidfile.go#L41-L47
162,792
cilium/cilium
pkg/pidfile/pidfile.go
Write
func Write(path string) error { pid := os.Getpid() return write(path, pid) }
go
func Write(path string) error { pid := os.Getpid() return write(path, pid) }
[ "func", "Write", "(", "path", "string", ")", "error", "{", "pid", ":=", "os", ".", "Getpid", "(", ")", "\n", "return", "write", "(", "path", ",", "pid", ")", "\n", "}" ]
// Write the pid of the process to the specified path, and attach a cleanup // handler to the exit of the program so it's removed afterwards.
[ "Write", "the", "pid", "of", "the", "process", "to", "the", "specified", "path", "and", "attach", "a", "cleanup", "handler", "to", "the", "exit", "of", "the", "program", "so", "it", "s", "removed", "afterwards", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/pidfile/pidfile.go#L64-L67
162,793
cilium/cilium
pkg/pidfile/pidfile.go
kill
func kill(buf []byte, pidfile string) error { pidStr := strings.TrimSpace(string(buf)) pid, err := strconv.Atoi(pidStr) if err != nil { return fmt.Errorf("Failed to parse pid from %q: %s", pidStr, err) } oldProc, err := os.FindProcess(pid) if err != nil { return fmt.Errorf("Could not find process %d: %s", pid, err) } // According to the golang/pkg/os documentation: // "On Unix systems, FindProcess always succeeds and returns a Process // for the given pid, regardless of whether the process exists." // // It could return "os: process already finished", so just log it at // a low level and ignore the error. log.WithFields(logrus.Fields{ logfields.PID: pid, logfields.PIDFile: pidfile, }).Info("Killing old process") if err := oldProc.Kill(); err != nil { log.WithError(err).Debug("Ignoring process kill failure") } if err := oldProc.Release(); err != nil { return fmt.Errorf("Couldn't release process %d: %s", pid, err) } return nil }
go
func kill(buf []byte, pidfile string) error { pidStr := strings.TrimSpace(string(buf)) pid, err := strconv.Atoi(pidStr) if err != nil { return fmt.Errorf("Failed to parse pid from %q: %s", pidStr, err) } oldProc, err := os.FindProcess(pid) if err != nil { return fmt.Errorf("Could not find process %d: %s", pid, err) } // According to the golang/pkg/os documentation: // "On Unix systems, FindProcess always succeeds and returns a Process // for the given pid, regardless of whether the process exists." // // It could return "os: process already finished", so just log it at // a low level and ignore the error. log.WithFields(logrus.Fields{ logfields.PID: pid, logfields.PIDFile: pidfile, }).Info("Killing old process") if err := oldProc.Kill(); err != nil { log.WithError(err).Debug("Ignoring process kill failure") } if err := oldProc.Release(); err != nil { return fmt.Errorf("Couldn't release process %d: %s", pid, err) } return nil }
[ "func", "kill", "(", "buf", "[", "]", "byte", ",", "pidfile", "string", ")", "error", "{", "pidStr", ":=", "strings", ".", "TrimSpace", "(", "string", "(", "buf", ")", ")", "\n", "pid", ",", "err", ":=", "strconv", ".", "Atoi", "(", "pidStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "pidStr", ",", "err", ")", "\n", "}", "\n", "oldProc", ",", "err", ":=", "os", ".", "FindProcess", "(", "pid", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "pid", ",", "err", ")", "\n", "}", "\n", "// According to the golang/pkg/os documentation:", "// \"On Unix systems, FindProcess always succeeds and returns a Process", "// for the given pid, regardless of whether the process exists.\"", "//", "// It could return \"os: process already finished\", so just log it at", "// a low level and ignore the error.", "log", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "logfields", ".", "PID", ":", "pid", ",", "logfields", ".", "PIDFile", ":", "pidfile", ",", "}", ")", ".", "Info", "(", "\"", "\"", ")", "\n", "if", "err", ":=", "oldProc", ".", "Kill", "(", ")", ";", "err", "!=", "nil", "{", "log", ".", "WithError", "(", "err", ")", ".", "Debug", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "err", ":=", "oldProc", ".", "Release", "(", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "pid", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// kill parses the PID in the provided slice and attempts to kill the process // associated with that PID.
[ "kill", "parses", "the", "PID", "in", "the", "provided", "slice", "and", "attempts", "to", "kill", "the", "process", "associated", "with", "that", "PID", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/pidfile/pidfile.go#L77-L104
162,794
cilium/cilium
pkg/pidfile/pidfile.go
Kill
func Kill(pidfilePath string) error { if _, err := os.Stat(pidfilePath); os.IsNotExist(err) { return nil } pidfile, err := ioutil.ReadFile(pidfilePath) if err != nil { return err } if err := kill(pidfile, pidfilePath); err != nil { return err } return os.RemoveAll(pidfilePath) }
go
func Kill(pidfilePath string) error { if _, err := os.Stat(pidfilePath); os.IsNotExist(err) { return nil } pidfile, err := ioutil.ReadFile(pidfilePath) if err != nil { return err } if err := kill(pidfile, pidfilePath); err != nil { return err } return os.RemoveAll(pidfilePath) }
[ "func", "Kill", "(", "pidfilePath", "string", ")", "error", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "pidfilePath", ")", ";", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", "\n", "}", "\n\n", "pidfile", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "pidfilePath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "kill", "(", "pidfile", ",", "pidfilePath", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "os", ".", "RemoveAll", "(", "pidfilePath", ")", "\n", "}" ]
// Kill opens the pidfile at the specified path, attempts to read the PID and // kill the process represented by that PID. If the file doesn't exist, the // corresponding process doesn't exist, or the process is successfully killed, // returns nil. Otherwise, returns an error indicating the failure to kill the // process. // // On success, deletes the pidfile from the filesystem. Otherwise, leaves it // in place.
[ "Kill", "opens", "the", "pidfile", "at", "the", "specified", "path", "attempts", "to", "read", "the", "PID", "and", "kill", "the", "process", "represented", "by", "that", "PID", ".", "If", "the", "file", "doesn", "t", "exist", "the", "corresponding", "process", "doesn", "t", "exist", "or", "the", "process", "is", "successfully", "killed", "returns", "nil", ".", "Otherwise", "returns", "an", "error", "indicating", "the", "failure", "to", "kill", "the", "process", ".", "On", "success", "deletes", "the", "pidfile", "from", "the", "filesystem", ".", "Otherwise", "leaves", "it", "in", "place", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/pidfile/pidfile.go#L114-L129
162,795
cilium/cilium
api/v1/server/restapi/policy/get_fqdn_cache.go
NewGetFqdnCache
func NewGetFqdnCache(ctx *middleware.Context, handler GetFqdnCacheHandler) *GetFqdnCache { return &GetFqdnCache{Context: ctx, Handler: handler} }
go
func NewGetFqdnCache(ctx *middleware.Context, handler GetFqdnCacheHandler) *GetFqdnCache { return &GetFqdnCache{Context: ctx, Handler: handler} }
[ "func", "NewGetFqdnCache", "(", "ctx", "*", "middleware", ".", "Context", ",", "handler", "GetFqdnCacheHandler", ")", "*", "GetFqdnCache", "{", "return", "&", "GetFqdnCache", "{", "Context", ":", "ctx", ",", "Handler", ":", "handler", "}", "\n", "}" ]
// NewGetFqdnCache creates a new http.Handler for the get fqdn cache operation
[ "NewGetFqdnCache", "creates", "a", "new", "http", ".", "Handler", "for", "the", "get", "fqdn", "cache", "operation" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/policy/get_fqdn_cache.go#L28-L30
162,796
cilium/cilium
pkg/monitor/format/flags.go
String
func (i *Uint16Flags) String() string { pieces := make([]string, 0, len(*i)) for _, v := range *i { pieces = append(pieces, strconv.Itoa(int(v))) } return strings.Join(pieces, ", ") }
go
func (i *Uint16Flags) String() string { pieces := make([]string, 0, len(*i)) for _, v := range *i { pieces = append(pieces, strconv.Itoa(int(v))) } return strings.Join(pieces, ", ") }
[ "func", "(", "i", "*", "Uint16Flags", ")", "String", "(", ")", "string", "{", "pieces", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "*", "i", ")", ")", "\n", "for", "_", ",", "v", ":=", "range", "*", "i", "{", "pieces", "=", "append", "(", "pieces", ",", "strconv", ".", "Itoa", "(", "int", "(", "v", ")", ")", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "pieces", ",", "\"", "\"", ")", "\n", "}" ]
// String provides a human-readable string format of the received variable.
[ "String", "provides", "a", "human", "-", "readable", "string", "format", "of", "the", "received", "variable", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/format/flags.go#L30-L36
162,797
cilium/cilium
pkg/monitor/format/flags.go
Set
func (i *Uint16Flags) Set(value string) error { v, err := strconv.Atoi(value) if err != nil { return err } *i = append(*i, uint16(v)) return nil }
go
func (i *Uint16Flags) Set(value string) error { v, err := strconv.Atoi(value) if err != nil { return err } *i = append(*i, uint16(v)) return nil }
[ "func", "(", "i", "*", "Uint16Flags", ")", "Set", "(", "value", "string", ")", "error", "{", "v", ",", "err", ":=", "strconv", ".", "Atoi", "(", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "*", "i", "=", "append", "(", "*", "i", ",", "uint16", "(", "v", ")", ")", "\n", "return", "nil", "\n", "}" ]
// Set converts the specified value into an integer and appends it to the flags. // Returns an error if the value cannot be converted to a 16-bit unsigned value.
[ "Set", "converts", "the", "specified", "value", "into", "an", "integer", "and", "appends", "it", "to", "the", "flags", ".", "Returns", "an", "error", "if", "the", "value", "cannot", "be", "converted", "to", "a", "16", "-", "bit", "unsigned", "value", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/format/flags.go#L40-L47
162,798
cilium/cilium
pkg/maps/ctmap/entry.go
String
func (c *CtEntry) String() string { return fmt.Sprintf("expires=%d RxPackets=%d RxBytes=%d RxFlagsSeen=%#02x LastRxReport=%d TxPackets=%d TxBytes=%d TxFlagsSeen=%#02x LastTxReport=%d Flags=%#04x RevNAT=%d Slave=%d SourceSecurityID=%d \n", c.Lifetime, c.RxPackets, c.RxBytes, c.RxFlagsSeen, c.LastRxReport, c.TxPackets, c.TxBytes, c.TxFlagsSeen, c.LastTxReport, c.Flags, byteorder.NetworkToHost(c.RevNAT), c.Slave, c.SourceSecurityID) }
go
func (c *CtEntry) String() string { return fmt.Sprintf("expires=%d RxPackets=%d RxBytes=%d RxFlagsSeen=%#02x LastRxReport=%d TxPackets=%d TxBytes=%d TxFlagsSeen=%#02x LastTxReport=%d Flags=%#04x RevNAT=%d Slave=%d SourceSecurityID=%d \n", c.Lifetime, c.RxPackets, c.RxBytes, c.RxFlagsSeen, c.LastRxReport, c.TxPackets, c.TxBytes, c.TxFlagsSeen, c.LastTxReport, c.Flags, byteorder.NetworkToHost(c.RevNAT), c.Slave, c.SourceSecurityID) }
[ "func", "(", "c", "*", "CtEntry", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "c", ".", "Lifetime", ",", "c", ".", "RxPackets", ",", "c", ".", "RxBytes", ",", "c", ".", "RxFlagsSeen", ",", "c", ".", "LastRxReport", ",", "c", ".", "TxPackets", ",", "c", ".", "TxBytes", ",", "c", ".", "TxFlagsSeen", ",", "c", ".", "LastTxReport", ",", "c", ".", "Flags", ",", "byteorder", ".", "NetworkToHost", "(", "c", ".", "RevNAT", ")", ",", "c", ".", "Slave", ",", "c", ".", "SourceSecurityID", ")", "\n", "}" ]
// String returns the readable format
[ "String", "returns", "the", "readable", "format" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/ctmap/entry.go#L46-L61
162,799
cilium/cilium
pkg/kafka/correlation_cache.go
NewCorrelationCache
func NewCorrelationCache() *CorrelationCache { cc := &CorrelationCache{ cache: requestsCache{}, nextSequenceNumber: 1, stopGc: make(chan struct{}), } go cc.garbageCollector() return cc }
go
func NewCorrelationCache() *CorrelationCache { cc := &CorrelationCache{ cache: requestsCache{}, nextSequenceNumber: 1, stopGc: make(chan struct{}), } go cc.garbageCollector() return cc }
[ "func", "NewCorrelationCache", "(", ")", "*", "CorrelationCache", "{", "cc", ":=", "&", "CorrelationCache", "{", "cache", ":", "requestsCache", "{", "}", ",", "nextSequenceNumber", ":", "1", ",", "stopGc", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n\n", "go", "cc", ".", "garbageCollector", "(", ")", "\n\n", "return", "cc", "\n", "}" ]
// NewCorrelationCache returns a new correlation cache
[ "NewCorrelationCache", "returns", "a", "new", "correlation", "cache" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kafka/correlation_cache.go#L97-L107