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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
docker/swarmkit | manager/state/raft/storage/walwrap.go | Open | func (wc walCryptor) Open(dirpath string, snap walpb.Snapshot) (WAL, error) {
w, err := wal.Open(dirpath, snap)
if err != nil {
return nil, err
}
return &wrappedWAL{
WAL: w,
encrypter: wc.encrypter,
decrypter: wc.decrypter,
}, nil
} | go | func (wc walCryptor) Open(dirpath string, snap walpb.Snapshot) (WAL, error) {
w, err := wal.Open(dirpath, snap)
if err != nil {
return nil, err
}
return &wrappedWAL{
WAL: w,
encrypter: wc.encrypter,
decrypter: wc.decrypter,
}, nil
} | [
"func",
"(",
"wc",
"walCryptor",
")",
"Open",
"(",
"dirpath",
"string",
",",
"snap",
"walpb",
".",
"Snapshot",
")",
"(",
"WAL",
",",
"error",
")",
"{",
"w",
",",
"err",
":=",
"wal",
".",
"Open",
"(",
"dirpath",
",",
"snap",
")",
"\n",
"if",
"err"... | // Open returns a new WAL object with the given encrypters and decrypters. | [
"Open",
"returns",
"a",
"new",
"WAL",
"object",
"with",
"the",
"given",
"encrypters",
"and",
"decrypters",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/storage/walwrap.go#L118-L128 | train |
docker/swarmkit | manager/state/raft/storage/walwrap.go | ReadRepairWAL | func ReadRepairWAL(
ctx context.Context,
walDir string,
walsnap walpb.Snapshot,
factory WALFactory,
) (WAL, WALData, error) {
var (
reader WAL
metadata []byte
st raftpb.HardState
ents []raftpb.Entry
err error
)
repaired := false
for {
if reader, err = factory.Open(walDir, walsnap); ... | go | func ReadRepairWAL(
ctx context.Context,
walDir string,
walsnap walpb.Snapshot,
factory WALFactory,
) (WAL, WALData, error) {
var (
reader WAL
metadata []byte
st raftpb.HardState
ents []raftpb.Entry
err error
)
repaired := false
for {
if reader, err = factory.Open(walDir, walsnap); ... | [
"func",
"ReadRepairWAL",
"(",
"ctx",
"context",
".",
"Context",
",",
"walDir",
"string",
",",
"walsnap",
"walpb",
".",
"Snapshot",
",",
"factory",
"WALFactory",
",",
")",
"(",
"WAL",
",",
"WALData",
",",
"error",
")",
"{",
"var",
"(",
"reader",
"WAL",
... | // ReadRepairWAL opens a WAL for reading, and attempts to read it. If we can't read it, attempts to repair
// and read again. | [
"ReadRepairWAL",
"opens",
"a",
"WAL",
"for",
"reading",
"and",
"attempts",
"to",
"read",
"it",
".",
"If",
"we",
"can",
"t",
"read",
"it",
"attempts",
"to",
"repair",
"and",
"read",
"again",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/raft/storage/walwrap.go#L152-L195 | train |
docker/swarmkit | agent/exec/controller.go | Publish | func (fn LogPublisherFunc) Publish(ctx context.Context, message api.LogMessage) error {
return fn(ctx, message)
} | go | func (fn LogPublisherFunc) Publish(ctx context.Context, message api.LogMessage) error {
return fn(ctx, message)
} | [
"func",
"(",
"fn",
"LogPublisherFunc",
")",
"Publish",
"(",
"ctx",
"context",
".",
"Context",
",",
"message",
"api",
".",
"LogMessage",
")",
"error",
"{",
"return",
"fn",
"(",
"ctx",
",",
"message",
")",
"\n",
"}"
] | // Publish calls the wrapped function. | [
"Publish",
"calls",
"the",
"wrapped",
"function",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/exec/controller.go#L66-L68 | train |
docker/swarmkit | agent/exec/controller.go | Resolve | func Resolve(ctx context.Context, task *api.Task, executor Executor) (Controller, *api.TaskStatus, error) {
status := task.Status.Copy()
defer func() {
logStateChange(ctx, task.DesiredState, task.Status.State, status.State)
}()
ctlr, err := executor.Controller(task)
// depending on the tasks state, a failed c... | go | func Resolve(ctx context.Context, task *api.Task, executor Executor) (Controller, *api.TaskStatus, error) {
status := task.Status.Copy()
defer func() {
logStateChange(ctx, task.DesiredState, task.Status.State, status.State)
}()
ctlr, err := executor.Controller(task)
// depending on the tasks state, a failed c... | [
"func",
"Resolve",
"(",
"ctx",
"context",
".",
"Context",
",",
"task",
"*",
"api",
".",
"Task",
",",
"executor",
"Executor",
")",
"(",
"Controller",
",",
"*",
"api",
".",
"TaskStatus",
",",
"error",
")",
"{",
"status",
":=",
"task",
".",
"Status",
".... | // Resolve attempts to get a controller from the executor and reports the
// correct status depending on the tasks current state according to the result.
//
// Unlike Do, if an error is returned, the status should still be reported. The
// error merely reports the failure at getting the controller. | [
"Resolve",
"attempts",
"to",
"get",
"a",
"controller",
"from",
"the",
"executor",
"and",
"reports",
"the",
"correct",
"status",
"depending",
"on",
"the",
"tasks",
"current",
"state",
"according",
"to",
"the",
"result",
".",
"Unlike",
"Do",
"if",
"an",
"error... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/exec/controller.go#L96-L126 | train |
docker/swarmkit | manager/state/store/nodes.go | CreateNode | func CreateNode(tx Tx, n *api.Node) error {
return tx.create(tableNode, n)
} | go | func CreateNode(tx Tx, n *api.Node) error {
return tx.create(tableNode, n)
} | [
"func",
"CreateNode",
"(",
"tx",
"Tx",
",",
"n",
"*",
"api",
".",
"Node",
")",
"error",
"{",
"return",
"tx",
".",
"create",
"(",
"tableNode",
",",
"n",
")",
"\n",
"}"
] | // CreateNode adds a new node to the store.
// Returns ErrExist if the ID is already taken. | [
"CreateNode",
"adds",
"a",
"new",
"node",
"to",
"the",
"store",
".",
"Returns",
"ErrExist",
"if",
"the",
"ID",
"is",
"already",
"taken",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/nodes.go#L76-L78 | train |
docker/swarmkit | manager/state/store/nodes.go | UpdateNode | func UpdateNode(tx Tx, n *api.Node) error {
return tx.update(tableNode, n)
} | go | func UpdateNode(tx Tx, n *api.Node) error {
return tx.update(tableNode, n)
} | [
"func",
"UpdateNode",
"(",
"tx",
"Tx",
",",
"n",
"*",
"api",
".",
"Node",
")",
"error",
"{",
"return",
"tx",
".",
"update",
"(",
"tableNode",
",",
"n",
")",
"\n",
"}"
] | // UpdateNode updates an existing node in the store.
// Returns ErrNotExist if the node doesn't exist. | [
"UpdateNode",
"updates",
"an",
"existing",
"node",
"in",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"node",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/nodes.go#L82-L84 | train |
docker/swarmkit | manager/state/store/nodes.go | DeleteNode | func DeleteNode(tx Tx, id string) error {
return tx.delete(tableNode, id)
} | go | func DeleteNode(tx Tx, id string) error {
return tx.delete(tableNode, id)
} | [
"func",
"DeleteNode",
"(",
"tx",
"Tx",
",",
"id",
"string",
")",
"error",
"{",
"return",
"tx",
".",
"delete",
"(",
"tableNode",
",",
"id",
")",
"\n",
"}"
] | // DeleteNode removes a node from the store.
// Returns ErrNotExist if the node doesn't exist. | [
"DeleteNode",
"removes",
"a",
"node",
"from",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"node",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/nodes.go#L88-L90 | train |
docker/swarmkit | manager/state/store/nodes.go | GetNode | func GetNode(tx ReadTx, id string) *api.Node {
n := tx.get(tableNode, id)
if n == nil {
return nil
}
return n.(*api.Node)
} | go | func GetNode(tx ReadTx, id string) *api.Node {
n := tx.get(tableNode, id)
if n == nil {
return nil
}
return n.(*api.Node)
} | [
"func",
"GetNode",
"(",
"tx",
"ReadTx",
",",
"id",
"string",
")",
"*",
"api",
".",
"Node",
"{",
"n",
":=",
"tx",
".",
"get",
"(",
"tableNode",
",",
"id",
")",
"\n",
"if",
"n",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"n",
... | // GetNode looks up a node by ID.
// Returns nil if the node doesn't exist. | [
"GetNode",
"looks",
"up",
"a",
"node",
"by",
"ID",
".",
"Returns",
"nil",
"if",
"the",
"node",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/nodes.go#L94-L100 | train |
docker/swarmkit | manager/state/store/nodes.go | FindNodes | func FindNodes(tx ReadTx, by By) ([]*api.Node, error) {
checkType := func(by By) error {
switch by.(type) {
case byName, byNamePrefix, byIDPrefix, byRole, byMembership, byCustom, byCustomPrefix:
return nil
default:
return ErrInvalidFindBy
}
}
nodeList := []*api.Node{}
appendResult := func(o api.Store... | go | func FindNodes(tx ReadTx, by By) ([]*api.Node, error) {
checkType := func(by By) error {
switch by.(type) {
case byName, byNamePrefix, byIDPrefix, byRole, byMembership, byCustom, byCustomPrefix:
return nil
default:
return ErrInvalidFindBy
}
}
nodeList := []*api.Node{}
appendResult := func(o api.Store... | [
"func",
"FindNodes",
"(",
"tx",
"ReadTx",
",",
"by",
"By",
")",
"(",
"[",
"]",
"*",
"api",
".",
"Node",
",",
"error",
")",
"{",
"checkType",
":=",
"func",
"(",
"by",
"By",
")",
"error",
"{",
"switch",
"by",
".",
"(",
"type",
")",
"{",
"case",
... | // FindNodes selects a set of nodes and returns them. | [
"FindNodes",
"selects",
"a",
"set",
"of",
"nodes",
"and",
"returns",
"them",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/nodes.go#L103-L120 | train |
docker/swarmkit | manager/watchapi/server.go | Start | func (s *Server) Start(ctx context.Context) error {
s.mu.Lock()
defer s.mu.Unlock()
if s.cancelAll != nil {
return errAlreadyRunning
}
s.pctx, s.cancelAll = context.WithCancel(ctx)
return nil
} | go | func (s *Server) Start(ctx context.Context) error {
s.mu.Lock()
defer s.mu.Unlock()
if s.cancelAll != nil {
return errAlreadyRunning
}
s.pctx, s.cancelAll = context.WithCancel(ctx)
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Start",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"s",
".",
"cancelAll",
"!=",
... | // Start starts the watch server. | [
"Start",
"starts",
"the",
"watch",
"server",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/watchapi/server.go#L32-L42 | train |
docker/swarmkit | manager/watchapi/server.go | Stop | func (s *Server) Stop() error {
s.mu.Lock()
defer s.mu.Unlock()
if s.cancelAll == nil {
return errNotRunning
}
s.cancelAll()
s.cancelAll = nil
return nil
} | go | func (s *Server) Stop() error {
s.mu.Lock()
defer s.mu.Unlock()
if s.cancelAll == nil {
return errNotRunning
}
s.cancelAll()
s.cancelAll = nil
return nil
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Stop",
"(",
")",
"error",
"{",
"s",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"s",
".",
"cancelAll",
"==",
"nil",
"{",
"return",
"errNotRunning... | // Stop stops the watch server. | [
"Stop",
"stops",
"the",
"watch",
"server",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/watchapi/server.go#L45-L56 | train |
docker/swarmkit | manager/deks.go | UpdateKEK | func (r RaftDEKData) UpdateKEK(oldKEK, candidateKEK ca.KEKData) ca.PEMKeyHeaders {
if _, unlockedToLocked, err := compareKEKs(oldKEK, candidateKEK); err == nil && unlockedToLocked {
return RaftDEKData{
EncryptionKeys: r.EncryptionKeys,
NeedsRotation: true,
FIPS: r.FIPS,
}
}
return r
} | go | func (r RaftDEKData) UpdateKEK(oldKEK, candidateKEK ca.KEKData) ca.PEMKeyHeaders {
if _, unlockedToLocked, err := compareKEKs(oldKEK, candidateKEK); err == nil && unlockedToLocked {
return RaftDEKData{
EncryptionKeys: r.EncryptionKeys,
NeedsRotation: true,
FIPS: r.FIPS,
}
}
return r
} | [
"func",
"(",
"r",
"RaftDEKData",
")",
"UpdateKEK",
"(",
"oldKEK",
",",
"candidateKEK",
"ca",
".",
"KEKData",
")",
"ca",
".",
"PEMKeyHeaders",
"{",
"if",
"_",
",",
"unlockedToLocked",
",",
"err",
":=",
"compareKEKs",
"(",
"oldKEK",
",",
"candidateKEK",
")",... | // UpdateKEK sets NeedRotation to true if we go from unlocked to locked. | [
"UpdateKEK",
"sets",
"NeedRotation",
"to",
"true",
"if",
"we",
"go",
"from",
"unlocked",
"to",
"locked",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/deks.go#L105-L114 | train |
docker/swarmkit | manager/deks.go | NewRaftDEKManager | func NewRaftDEKManager(kw ca.KeyWriter, fips bool) (*RaftDEKManager, error) {
// If there is no current DEK, generate one and write it to disk
err := kw.ViewAndUpdateHeaders(func(h ca.PEMKeyHeaders) (ca.PEMKeyHeaders, error) {
dekData, ok := h.(RaftDEKData)
// it wasn't a raft DEK manager before - just replace it... | go | func NewRaftDEKManager(kw ca.KeyWriter, fips bool) (*RaftDEKManager, error) {
// If there is no current DEK, generate one and write it to disk
err := kw.ViewAndUpdateHeaders(func(h ca.PEMKeyHeaders) (ca.PEMKeyHeaders, error) {
dekData, ok := h.(RaftDEKData)
// it wasn't a raft DEK manager before - just replace it... | [
"func",
"NewRaftDEKManager",
"(",
"kw",
"ca",
".",
"KeyWriter",
",",
"fips",
"bool",
")",
"(",
"*",
"RaftDEKManager",
",",
"error",
")",
"{",
"// If there is no current DEK, generate one and write it to disk",
"err",
":=",
"kw",
".",
"ViewAndUpdateHeaders",
"(",
"fu... | // NewRaftDEKManager returns a RaftDEKManager that uses the current key writer
// and header manager | [
"NewRaftDEKManager",
"returns",
"a",
"RaftDEKManager",
"that",
"uses",
"the",
"current",
"key",
"writer",
"and",
"header",
"manager"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/deks.go#L147-L170 | train |
docker/swarmkit | manager/deks.go | NeedsRotation | func (r *RaftDEKManager) NeedsRotation() bool {
h, _ := r.kw.GetCurrentState()
data, ok := h.(RaftDEKData)
if !ok {
return false
}
return data.NeedsRotation || data.EncryptionKeys.PendingDEK != nil
} | go | func (r *RaftDEKManager) NeedsRotation() bool {
h, _ := r.kw.GetCurrentState()
data, ok := h.(RaftDEKData)
if !ok {
return false
}
return data.NeedsRotation || data.EncryptionKeys.PendingDEK != nil
} | [
"func",
"(",
"r",
"*",
"RaftDEKManager",
")",
"NeedsRotation",
"(",
")",
"bool",
"{",
"h",
",",
"_",
":=",
"r",
".",
"kw",
".",
"GetCurrentState",
"(",
")",
"\n",
"data",
",",
"ok",
":=",
"h",
".",
"(",
"RaftDEKData",
")",
"\n",
"if",
"!",
"ok",
... | // NeedsRotation returns a boolean about whether we should do a rotation | [
"NeedsRotation",
"returns",
"a",
"boolean",
"about",
"whether",
"we",
"should",
"do",
"a",
"rotation"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/deks.go#L173-L180 | train |
docker/swarmkit | manager/deks.go | GetKeys | func (r *RaftDEKManager) GetKeys() raft.EncryptionKeys {
var newKeys, originalKeys raft.EncryptionKeys
err := r.kw.ViewAndUpdateHeaders(func(h ca.PEMKeyHeaders) (ca.PEMKeyHeaders, error) {
data, ok := h.(RaftDEKData)
if !ok {
return nil, errNotUsingRaftDEKData
}
originalKeys = data.EncryptionKeys
if !dat... | go | func (r *RaftDEKManager) GetKeys() raft.EncryptionKeys {
var newKeys, originalKeys raft.EncryptionKeys
err := r.kw.ViewAndUpdateHeaders(func(h ca.PEMKeyHeaders) (ca.PEMKeyHeaders, error) {
data, ok := h.(RaftDEKData)
if !ok {
return nil, errNotUsingRaftDEKData
}
originalKeys = data.EncryptionKeys
if !dat... | [
"func",
"(",
"r",
"*",
"RaftDEKManager",
")",
"GetKeys",
"(",
")",
"raft",
".",
"EncryptionKeys",
"{",
"var",
"newKeys",
",",
"originalKeys",
"raft",
".",
"EncryptionKeys",
"\n",
"err",
":=",
"r",
".",
"kw",
".",
"ViewAndUpdateHeaders",
"(",
"func",
"(",
... | // GetKeys returns the current set of DEKs. If NeedsRotation is true, and there
// is no existing PendingDEK, it will try to create one. If it successfully creates
// and writes a PendingDEK, it sets NeedRotation to false. If there are any errors
// doing so, just return the original set of keys. | [
"GetKeys",
"returns",
"the",
"current",
"set",
"of",
"DEKs",
".",
"If",
"NeedsRotation",
"is",
"true",
"and",
"there",
"is",
"no",
"existing",
"PendingDEK",
"it",
"will",
"try",
"to",
"create",
"one",
".",
"If",
"it",
"successfully",
"creates",
"and",
"wri... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/deks.go#L186-L210 | train |
docker/swarmkit | manager/deks.go | UpdateKeys | func (r *RaftDEKManager) UpdateKeys(newKeys raft.EncryptionKeys) error {
return r.kw.ViewAndUpdateHeaders(func(h ca.PEMKeyHeaders) (ca.PEMKeyHeaders, error) {
data, ok := h.(RaftDEKData)
if !ok {
return nil, errNotUsingRaftDEKData
}
// If there is no current DEK, we are basically wiping out all DEKs (no hea... | go | func (r *RaftDEKManager) UpdateKeys(newKeys raft.EncryptionKeys) error {
return r.kw.ViewAndUpdateHeaders(func(h ca.PEMKeyHeaders) (ca.PEMKeyHeaders, error) {
data, ok := h.(RaftDEKData)
if !ok {
return nil, errNotUsingRaftDEKData
}
// If there is no current DEK, we are basically wiping out all DEKs (no hea... | [
"func",
"(",
"r",
"*",
"RaftDEKManager",
")",
"UpdateKeys",
"(",
"newKeys",
"raft",
".",
"EncryptionKeys",
")",
"error",
"{",
"return",
"r",
".",
"kw",
".",
"ViewAndUpdateHeaders",
"(",
"func",
"(",
"h",
"ca",
".",
"PEMKeyHeaders",
")",
"(",
"ca",
".",
... | // UpdateKeys will set the updated encryption keys in the headers. This finishes
// a rotation, and is expected to set the CurrentDEK to the previous PendingDEK. | [
"UpdateKeys",
"will",
"set",
"the",
"updated",
"encryption",
"keys",
"in",
"the",
"headers",
".",
"This",
"finishes",
"a",
"rotation",
"and",
"is",
"expected",
"to",
"set",
"the",
"CurrentDEK",
"to",
"the",
"previous",
"PendingDEK",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/deks.go#L220-L236 | train |
docker/swarmkit | manager/deks.go | MaybeUpdateKEK | func (r *RaftDEKManager) MaybeUpdateKEK(candidateKEK ca.KEKData) (bool, bool, error) {
var updated, unlockedToLocked bool
err := r.kw.ViewAndRotateKEK(func(currentKEK ca.KEKData, h ca.PEMKeyHeaders) (ca.KEKData, ca.PEMKeyHeaders, error) {
var err error
updated, unlockedToLocked, err = compareKEKs(currentKEK, cand... | go | func (r *RaftDEKManager) MaybeUpdateKEK(candidateKEK ca.KEKData) (bool, bool, error) {
var updated, unlockedToLocked bool
err := r.kw.ViewAndRotateKEK(func(currentKEK ca.KEKData, h ca.PEMKeyHeaders) (ca.KEKData, ca.PEMKeyHeaders, error) {
var err error
updated, unlockedToLocked, err = compareKEKs(currentKEK, cand... | [
"func",
"(",
"r",
"*",
"RaftDEKManager",
")",
"MaybeUpdateKEK",
"(",
"candidateKEK",
"ca",
".",
"KEKData",
")",
"(",
"bool",
",",
"bool",
",",
"error",
")",
"{",
"var",
"updated",
",",
"unlockedToLocked",
"bool",
"\n",
"err",
":=",
"r",
".",
"kw",
".",... | // MaybeUpdateKEK does a KEK rotation if one is required. Returns whether
// the kek was updated, whether it went from unlocked to locked, and any errors. | [
"MaybeUpdateKEK",
"does",
"a",
"KEK",
"rotation",
"if",
"one",
"is",
"required",
".",
"Returns",
"whether",
"the",
"kek",
"was",
"updated",
"whether",
"it",
"went",
"from",
"unlocked",
"to",
"locked",
"and",
"any",
"errors",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/deks.go#L240-L270 | train |
docker/swarmkit | cmd/swarm-bench/collector.go | Listen | func (c *Collector) Listen(port int) error {
var err error
c.ln, err = net.Listen("tcp", ":"+strconv.Itoa(port))
return err
} | go | func (c *Collector) Listen(port int) error {
var err error
c.ln, err = net.Listen("tcp", ":"+strconv.Itoa(port))
return err
} | [
"func",
"(",
"c",
"*",
"Collector",
")",
"Listen",
"(",
"port",
"int",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"c",
".",
"ln",
",",
"err",
"=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"strconv",
".",
"Itoa",
"(",
... | // Listen starts listening on a TCP port. Tasks have to connect to this address
// once they come online. | [
"Listen",
"starts",
"listening",
"on",
"a",
"TCP",
"port",
".",
"Tasks",
"have",
"to",
"connect",
"to",
"this",
"address",
"once",
"they",
"come",
"online",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/cmd/swarm-bench/collector.go#L23-L27 | train |
docker/swarmkit | cmd/swarm-bench/collector.go | Collect | func (c *Collector) Collect(ctx context.Context, count uint64) {
start := time.Now()
for i := uint64(0); i < count; i++ {
conn, err := c.ln.Accept()
if err != nil {
log.G(ctx).WithError(err).Error("failure accepting connection")
continue
}
c.t.UpdateSince(start)
conn.Close()
}
} | go | func (c *Collector) Collect(ctx context.Context, count uint64) {
start := time.Now()
for i := uint64(0); i < count; i++ {
conn, err := c.ln.Accept()
if err != nil {
log.G(ctx).WithError(err).Error("failure accepting connection")
continue
}
c.t.UpdateSince(start)
conn.Close()
}
} | [
"func",
"(",
"c",
"*",
"Collector",
")",
"Collect",
"(",
"ctx",
"context",
".",
"Context",
",",
"count",
"uint64",
")",
"{",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"for",
"i",
":=",
"uint64",
"(",
"0",
")",
";",
"i",
"<",
"count",
"... | // Collect blocks until `count` tasks phoned home. | [
"Collect",
"blocks",
"until",
"count",
"tasks",
"phoned",
"home",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/cmd/swarm-bench/collector.go#L30-L41 | train |
docker/swarmkit | cmd/swarm-bench/collector.go | Stats | func (c *Collector) Stats(w io.Writer, unit time.Duration) {
du := float64(unit)
duSuffix := unit.String()[1:]
t := c.t.Snapshot()
ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
fmt.Fprintln(w, "stats:")
fmt.Fprintf(w, " count: %9d\n", t.Count())
fmt.Fprintf(w, " min: %12.2f%s\n",... | go | func (c *Collector) Stats(w io.Writer, unit time.Duration) {
du := float64(unit)
duSuffix := unit.String()[1:]
t := c.t.Snapshot()
ps := t.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
fmt.Fprintln(w, "stats:")
fmt.Fprintf(w, " count: %9d\n", t.Count())
fmt.Fprintf(w, " min: %12.2f%s\n",... | [
"func",
"(",
"c",
"*",
"Collector",
")",
"Stats",
"(",
"w",
"io",
".",
"Writer",
",",
"unit",
"time",
".",
"Duration",
")",
"{",
"du",
":=",
"float64",
"(",
"unit",
")",
"\n",
"duSuffix",
":=",
"unit",
".",
"String",
"(",
")",
"[",
"1",
":",
"]... | // Stats prints various statistics related to the collection. | [
"Stats",
"prints",
"various",
"statistics",
"related",
"to",
"the",
"collection",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/cmd/swarm-bench/collector.go#L44-L66 | train |
docker/swarmkit | manager/orchestrator/replicated/slot.go | Less | func (is slotsByRunningState) Less(i, j int) bool {
iRunning := false
jRunning := false
for _, ii := range is[i] {
if ii.Status.State == api.TaskStateRunning {
iRunning = true
break
}
}
for _, ij := range is[j] {
if ij.Status.State == api.TaskStateRunning {
jRunning = true
break
}
}
if iRun... | go | func (is slotsByRunningState) Less(i, j int) bool {
iRunning := false
jRunning := false
for _, ii := range is[i] {
if ii.Status.State == api.TaskStateRunning {
iRunning = true
break
}
}
for _, ij := range is[j] {
if ij.Status.State == api.TaskStateRunning {
jRunning = true
break
}
}
if iRun... | [
"func",
"(",
"is",
"slotsByRunningState",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"iRunning",
":=",
"false",
"\n",
"jRunning",
":=",
"false",
"\n\n",
"for",
"_",
",",
"ii",
":=",
"range",
"is",
"[",
"i",
"]",
"{",
"if",
"ii",
".... | // Less returns true if the first task should be preferred over the second task,
// all other things being equal in terms of node balance. | [
"Less",
"returns",
"true",
"if",
"the",
"first",
"task",
"should",
"be",
"preferred",
"over",
"the",
"second",
"task",
"all",
"other",
"things",
"being",
"equal",
"in",
"terms",
"of",
"node",
"balance",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/replicated/slot.go#L18-L48 | train |
docker/swarmkit | manager/orchestrator/replicated/slot.go | updatableAndDeadSlots | func (r *Orchestrator) updatableAndDeadSlots(ctx context.Context, service *api.Service) (map[uint64]orchestrator.Slot, map[uint64]orchestrator.Slot, error) {
var (
tasks []*api.Task
err error
)
r.store.View(func(tx store.ReadTx) {
tasks, err = store.FindTasks(tx, store.ByServiceID(service.ID))
})
if err !=... | go | func (r *Orchestrator) updatableAndDeadSlots(ctx context.Context, service *api.Service) (map[uint64]orchestrator.Slot, map[uint64]orchestrator.Slot, error) {
var (
tasks []*api.Task
err error
)
r.store.View(func(tx store.ReadTx) {
tasks, err = store.FindTasks(tx, store.ByServiceID(service.ID))
})
if err !=... | [
"func",
"(",
"r",
"*",
"Orchestrator",
")",
"updatableAndDeadSlots",
"(",
"ctx",
"context",
".",
"Context",
",",
"service",
"*",
"api",
".",
"Service",
")",
"(",
"map",
"[",
"uint64",
"]",
"orchestrator",
".",
"Slot",
",",
"map",
"[",
"uint64",
"]",
"o... | // updatableAndDeadSlots returns two maps of slots. The first contains slots
// that have at least one task with a desired state above NEW and lesser or
// equal to RUNNING, or a task that shouldn't be restarted. The second contains
// all other slots with at least one task. | [
"updatableAndDeadSlots",
"returns",
"two",
"maps",
"of",
"slots",
".",
"The",
"first",
"contains",
"slots",
"that",
"have",
"at",
"least",
"one",
"task",
"with",
"a",
"desired",
"state",
"above",
"NEW",
"and",
"lesser",
"or",
"equal",
"to",
"RUNNING",
"or",
... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/replicated/slot.go#L78-L107 | train |
docker/swarmkit | manager/orchestrator/replicated/slot.go | SlotTuple | func (r *Orchestrator) SlotTuple(t *api.Task) orchestrator.SlotTuple {
return orchestrator.SlotTuple{
ServiceID: t.ServiceID,
Slot: t.Slot,
}
} | go | func (r *Orchestrator) SlotTuple(t *api.Task) orchestrator.SlotTuple {
return orchestrator.SlotTuple{
ServiceID: t.ServiceID,
Slot: t.Slot,
}
} | [
"func",
"(",
"r",
"*",
"Orchestrator",
")",
"SlotTuple",
"(",
"t",
"*",
"api",
".",
"Task",
")",
"orchestrator",
".",
"SlotTuple",
"{",
"return",
"orchestrator",
".",
"SlotTuple",
"{",
"ServiceID",
":",
"t",
".",
"ServiceID",
",",
"Slot",
":",
"t",
"."... | // SlotTuple returns a slot tuple for the replicated service task. | [
"SlotTuple",
"returns",
"a",
"slot",
"tuple",
"for",
"the",
"replicated",
"service",
"task",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/replicated/slot.go#L110-L115 | train |
docker/swarmkit | manager/state/store/clusters.go | CreateCluster | func CreateCluster(tx Tx, c *api.Cluster) error {
// Ensure the name is not already in use.
if tx.lookup(tableCluster, indexName, strings.ToLower(c.Spec.Annotations.Name)) != nil {
return ErrNameConflict
}
return tx.create(tableCluster, c)
} | go | func CreateCluster(tx Tx, c *api.Cluster) error {
// Ensure the name is not already in use.
if tx.lookup(tableCluster, indexName, strings.ToLower(c.Spec.Annotations.Name)) != nil {
return ErrNameConflict
}
return tx.create(tableCluster, c)
} | [
"func",
"CreateCluster",
"(",
"tx",
"Tx",
",",
"c",
"*",
"api",
".",
"Cluster",
")",
"error",
"{",
"// Ensure the name is not already in use.",
"if",
"tx",
".",
"lookup",
"(",
"tableCluster",
",",
"indexName",
",",
"strings",
".",
"ToLower",
"(",
"c",
".",
... | // CreateCluster adds a new cluster to the store.
// Returns ErrExist if the ID is already taken. | [
"CreateCluster",
"adds",
"a",
"new",
"cluster",
"to",
"the",
"store",
".",
"Returns",
"ErrExist",
"if",
"the",
"ID",
"is",
"already",
"taken",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/clusters.go#L72-L79 | train |
docker/swarmkit | manager/state/store/clusters.go | UpdateCluster | func UpdateCluster(tx Tx, c *api.Cluster) error {
// Ensure the name is either not in use or already used by this same Cluster.
if existing := tx.lookup(tableCluster, indexName, strings.ToLower(c.Spec.Annotations.Name)); existing != nil {
if existing.GetID() != c.ID {
return ErrNameConflict
}
}
return tx.up... | go | func UpdateCluster(tx Tx, c *api.Cluster) error {
// Ensure the name is either not in use or already used by this same Cluster.
if existing := tx.lookup(tableCluster, indexName, strings.ToLower(c.Spec.Annotations.Name)); existing != nil {
if existing.GetID() != c.ID {
return ErrNameConflict
}
}
return tx.up... | [
"func",
"UpdateCluster",
"(",
"tx",
"Tx",
",",
"c",
"*",
"api",
".",
"Cluster",
")",
"error",
"{",
"// Ensure the name is either not in use or already used by this same Cluster.",
"if",
"existing",
":=",
"tx",
".",
"lookup",
"(",
"tableCluster",
",",
"indexName",
",... | // UpdateCluster updates an existing cluster in the store.
// Returns ErrNotExist if the cluster doesn't exist. | [
"UpdateCluster",
"updates",
"an",
"existing",
"cluster",
"in",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"cluster",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/clusters.go#L83-L92 | train |
docker/swarmkit | manager/state/store/clusters.go | DeleteCluster | func DeleteCluster(tx Tx, id string) error {
return tx.delete(tableCluster, id)
} | go | func DeleteCluster(tx Tx, id string) error {
return tx.delete(tableCluster, id)
} | [
"func",
"DeleteCluster",
"(",
"tx",
"Tx",
",",
"id",
"string",
")",
"error",
"{",
"return",
"tx",
".",
"delete",
"(",
"tableCluster",
",",
"id",
")",
"\n",
"}"
] | // DeleteCluster removes a cluster from the store.
// Returns ErrNotExist if the cluster doesn't exist. | [
"DeleteCluster",
"removes",
"a",
"cluster",
"from",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"cluster",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/clusters.go#L96-L98 | train |
docker/swarmkit | manager/state/store/clusters.go | GetCluster | func GetCluster(tx ReadTx, id string) *api.Cluster {
n := tx.get(tableCluster, id)
if n == nil {
return nil
}
return n.(*api.Cluster)
} | go | func GetCluster(tx ReadTx, id string) *api.Cluster {
n := tx.get(tableCluster, id)
if n == nil {
return nil
}
return n.(*api.Cluster)
} | [
"func",
"GetCluster",
"(",
"tx",
"ReadTx",
",",
"id",
"string",
")",
"*",
"api",
".",
"Cluster",
"{",
"n",
":=",
"tx",
".",
"get",
"(",
"tableCluster",
",",
"id",
")",
"\n",
"if",
"n",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",... | // GetCluster looks up a cluster by ID.
// Returns nil if the cluster doesn't exist. | [
"GetCluster",
"looks",
"up",
"a",
"cluster",
"by",
"ID",
".",
"Returns",
"nil",
"if",
"the",
"cluster",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/clusters.go#L102-L108 | train |
docker/swarmkit | manager/state/store/clusters.go | FindClusters | func FindClusters(tx ReadTx, by By) ([]*api.Cluster, error) {
checkType := func(by By) error {
switch by.(type) {
case byName, byNamePrefix, byIDPrefix, byCustom, byCustomPrefix:
return nil
default:
return ErrInvalidFindBy
}
}
clusterList := []*api.Cluster{}
appendResult := func(o api.StoreObject) {
... | go | func FindClusters(tx ReadTx, by By) ([]*api.Cluster, error) {
checkType := func(by By) error {
switch by.(type) {
case byName, byNamePrefix, byIDPrefix, byCustom, byCustomPrefix:
return nil
default:
return ErrInvalidFindBy
}
}
clusterList := []*api.Cluster{}
appendResult := func(o api.StoreObject) {
... | [
"func",
"FindClusters",
"(",
"tx",
"ReadTx",
",",
"by",
"By",
")",
"(",
"[",
"]",
"*",
"api",
".",
"Cluster",
",",
"error",
")",
"{",
"checkType",
":=",
"func",
"(",
"by",
"By",
")",
"error",
"{",
"switch",
"by",
".",
"(",
"type",
")",
"{",
"ca... | // FindClusters selects a set of clusters and returns them. | [
"FindClusters",
"selects",
"a",
"set",
"of",
"clusters",
"and",
"returns",
"them",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/clusters.go#L111-L128 | train |
docker/swarmkit | manager/allocator/networkallocator/networkallocator.go | IsIngressNetwork | func IsIngressNetwork(nw *api.Network) bool {
if nw.Spec.Ingress {
return true
}
// Check if legacy defined ingress network
_, ok := nw.Spec.Annotations.Labels["com.docker.swarm.internal"]
return ok && nw.Spec.Annotations.Name == "ingress"
} | go | func IsIngressNetwork(nw *api.Network) bool {
if nw.Spec.Ingress {
return true
}
// Check if legacy defined ingress network
_, ok := nw.Spec.Annotations.Labels["com.docker.swarm.internal"]
return ok && nw.Spec.Annotations.Name == "ingress"
} | [
"func",
"IsIngressNetwork",
"(",
"nw",
"*",
"api",
".",
"Network",
")",
"bool",
"{",
"if",
"nw",
".",
"Spec",
".",
"Ingress",
"{",
"return",
"true",
"\n",
"}",
"\n",
"// Check if legacy defined ingress network",
"_",
",",
"ok",
":=",
"nw",
".",
"Spec",
"... | // IsIngressNetwork check if the network is an ingress network | [
"IsIngressNetwork",
"check",
"if",
"the",
"network",
"is",
"an",
"ingress",
"network"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/networkallocator/networkallocator.go#L95-L102 | train |
docker/swarmkit | manager/allocator/networkallocator/networkallocator.go | IsIngressNetworkNeeded | func IsIngressNetworkNeeded(s *api.Service) bool {
if s == nil {
return false
}
if s.Spec.Endpoint == nil {
return false
}
for _, p := range s.Spec.Endpoint.Ports {
// The service to which this task belongs is trying to
// expose ports with PublishMode as Ingress to the
// external world. Automatically... | go | func IsIngressNetworkNeeded(s *api.Service) bool {
if s == nil {
return false
}
if s.Spec.Endpoint == nil {
return false
}
for _, p := range s.Spec.Endpoint.Ports {
// The service to which this task belongs is trying to
// expose ports with PublishMode as Ingress to the
// external world. Automatically... | [
"func",
"IsIngressNetworkNeeded",
"(",
"s",
"*",
"api",
".",
"Service",
")",
"bool",
"{",
"if",
"s",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"s",
".",
"Spec",
".",
"Endpoint",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\... | // IsIngressNetworkNeeded checks whether the service requires the routing-mesh | [
"IsIngressNetworkNeeded",
"checks",
"whether",
"the",
"service",
"requires",
"the",
"routing",
"-",
"mesh"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/networkallocator/networkallocator.go#L105-L125 | train |
docker/swarmkit | cmd/swarmctl/common/print.go | PrintHeader | func PrintHeader(w io.Writer, columns ...string) {
underline := make([]string, len(columns))
for i := range underline {
underline[i] = strings.Repeat("-", len(columns[i]))
}
fmt.Fprintf(w, "%s\n", strings.Join(columns, "\t"))
fmt.Fprintf(w, "%s\n", strings.Join(underline, "\t"))
} | go | func PrintHeader(w io.Writer, columns ...string) {
underline := make([]string, len(columns))
for i := range underline {
underline[i] = strings.Repeat("-", len(columns[i]))
}
fmt.Fprintf(w, "%s\n", strings.Join(columns, "\t"))
fmt.Fprintf(w, "%s\n", strings.Join(underline, "\t"))
} | [
"func",
"PrintHeader",
"(",
"w",
"io",
".",
"Writer",
",",
"columns",
"...",
"string",
")",
"{",
"underline",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"columns",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"underline",
"{",
"underline",... | // PrintHeader prints a nice little header. | [
"PrintHeader",
"prints",
"a",
"nice",
"little",
"header",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/cmd/swarmctl/common/print.go#L13-L20 | train |
docker/swarmkit | remotes/remotes.go | NewRemotes | func NewRemotes(peers ...api.Peer) Remotes {
mwr := &remotesWeightedRandom{
remotes: make(map[api.Peer]int),
}
for _, peer := range peers {
mwr.Observe(peer, DefaultObservationWeight)
}
return mwr
} | go | func NewRemotes(peers ...api.Peer) Remotes {
mwr := &remotesWeightedRandom{
remotes: make(map[api.Peer]int),
}
for _, peer := range peers {
mwr.Observe(peer, DefaultObservationWeight)
}
return mwr
} | [
"func",
"NewRemotes",
"(",
"peers",
"...",
"api",
".",
"Peer",
")",
"Remotes",
"{",
"mwr",
":=",
"&",
"remotesWeightedRandom",
"{",
"remotes",
":",
"make",
"(",
"map",
"[",
"api",
".",
"Peer",
"]",
"int",
")",
",",
"}",
"\n\n",
"for",
"_",
",",
"pe... | // NewRemotes returns a Remotes instance with the provided set of addresses.
// Entries provided are heavily weighted initially. | [
"NewRemotes",
"returns",
"a",
"Remotes",
"instance",
"with",
"the",
"provided",
"set",
"of",
"addresses",
".",
"Entries",
"provided",
"are",
"heavily",
"weighted",
"initially",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/remotes/remotes.go#L47-L57 | train |
docker/swarmkit | manager/allocator/allocator.go | New | func New(store *store.MemoryStore, pg plugingetter.PluginGetter, netConfig *cnmallocator.NetworkConfig) (*Allocator, error) {
a := &Allocator{
store: store,
taskBallot: &taskBallot{
votes: make(map[string][]string),
},
stopChan: make(chan struct{}),
doneChan: make(chan struct{}),
pluginGetter:... | go | func New(store *store.MemoryStore, pg plugingetter.PluginGetter, netConfig *cnmallocator.NetworkConfig) (*Allocator, error) {
a := &Allocator{
store: store,
taskBallot: &taskBallot{
votes: make(map[string][]string),
},
stopChan: make(chan struct{}),
doneChan: make(chan struct{}),
pluginGetter:... | [
"func",
"New",
"(",
"store",
"*",
"store",
".",
"MemoryStore",
",",
"pg",
"plugingetter",
".",
"PluginGetter",
",",
"netConfig",
"*",
"cnmallocator",
".",
"NetworkConfig",
")",
"(",
"*",
"Allocator",
",",
"error",
")",
"{",
"a",
":=",
"&",
"Allocator",
"... | // New returns a new instance of Allocator for use during allocation
// stage of the manager. | [
"New",
"returns",
"a",
"new",
"instance",
"of",
"Allocator",
"for",
"use",
"during",
"allocation",
"stage",
"of",
"the",
"manager",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/allocator.go#L72-L85 | train |
docker/swarmkit | manager/allocator/allocator.go | Run | func (a *Allocator) Run(ctx context.Context) error {
// Setup cancel context for all goroutines to use.
ctx, cancel := context.WithCancel(ctx)
var (
wg sync.WaitGroup
actors []func() error
)
defer func() {
cancel()
wg.Wait()
close(a.doneChan)
}()
for _, aa := range []allocActor{
{
taskVoter:... | go | func (a *Allocator) Run(ctx context.Context) error {
// Setup cancel context for all goroutines to use.
ctx, cancel := context.WithCancel(ctx)
var (
wg sync.WaitGroup
actors []func() error
)
defer func() {
cancel()
wg.Wait()
close(a.doneChan)
}()
for _, aa := range []allocActor{
{
taskVoter:... | [
"func",
"(",
"a",
"*",
"Allocator",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"// Setup cancel context for all goroutines to use.",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"ctx",
")",
"\n",
"var",
"(",
"wg",... | // Run starts all allocator go-routines and waits for Stop to be called. | [
"Run",
"starts",
"all",
"allocator",
"go",
"-",
"routines",
"and",
"waits",
"for",
"Stop",
"to",
"be",
"called",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/allocator/allocator.go#L88-L149 | train |
docker/swarmkit | agent/exec/controller_stub.go | Update | func (sc *StubController) Update(ctx context.Context, t *api.Task) error {
sc.called()
return sc.UpdateFn(ctx, t)
} | go | func (sc *StubController) Update(ctx context.Context, t *api.Task) error {
sc.called()
return sc.UpdateFn(ctx, t)
} | [
"func",
"(",
"sc",
"*",
"StubController",
")",
"Update",
"(",
"ctx",
"context",
".",
"Context",
",",
"t",
"*",
"api",
".",
"Task",
")",
"error",
"{",
"sc",
".",
"called",
"(",
")",
"\n",
"return",
"sc",
".",
"UpdateFn",
"(",
"ctx",
",",
"t",
")",... | // Update is part of the Controller interface | [
"Update",
"is",
"part",
"of",
"the",
"Controller",
"interface"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/exec/controller_stub.go#L49-L52 | train |
docker/swarmkit | agent/exec/controller_stub.go | Terminate | func (sc *StubController) Terminate(ctx context.Context) error {
sc.called()
return sc.TerminateFn(ctx)
} | go | func (sc *StubController) Terminate(ctx context.Context) error {
sc.called()
return sc.TerminateFn(ctx)
} | [
"func",
"(",
"sc",
"*",
"StubController",
")",
"Terminate",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"sc",
".",
"called",
"(",
")",
"\n",
"return",
"sc",
".",
"TerminateFn",
"(",
"ctx",
")",
"\n",
"}"
] | // Terminate is part of the Controller interface | [
"Terminate",
"is",
"part",
"of",
"the",
"Controller",
"interface"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/exec/controller_stub.go#L67-L70 | train |
docker/swarmkit | cmd/swarmctl/service/flagparser/config.go | ParseAddConfig | func ParseAddConfig(cmd *cobra.Command, spec *api.ServiceSpec, flagName string) error {
flags := cmd.Flags()
if flags.Changed(flagName) {
configs, err := flags.GetStringSlice(flagName)
if err != nil {
return err
}
container := spec.Task.GetContainer()
if container == nil {
spec.Task.Runtime = &api.T... | go | func ParseAddConfig(cmd *cobra.Command, spec *api.ServiceSpec, flagName string) error {
flags := cmd.Flags()
if flags.Changed(flagName) {
configs, err := flags.GetStringSlice(flagName)
if err != nil {
return err
}
container := spec.Task.GetContainer()
if container == nil {
spec.Task.Runtime = &api.T... | [
"func",
"ParseAddConfig",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"spec",
"*",
"api",
".",
"ServiceSpec",
",",
"flagName",
"string",
")",
"error",
"{",
"flags",
":=",
"cmd",
".",
"Flags",
"(",
")",
"\n\n",
"if",
"flags",
".",
"Changed",
"(",
"... | // ParseAddConfig validates configs passed on the command line | [
"ParseAddConfig",
"validates",
"configs",
"passed",
"on",
"the",
"command",
"line"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/cmd/swarmctl/service/flagparser/config.go#L36-L104 | train |
docker/swarmkit | cmd/swarmctl/service/flagparser/config.go | ParseRemoveConfig | func ParseRemoveConfig(cmd *cobra.Command, spec *api.ServiceSpec, flagName string) error {
flags := cmd.Flags()
if flags.Changed(flagName) {
configs, err := flags.GetStringSlice(flagName)
if err != nil {
return err
}
container := spec.Task.GetContainer()
if container == nil {
return nil
}
wantT... | go | func ParseRemoveConfig(cmd *cobra.Command, spec *api.ServiceSpec, flagName string) error {
flags := cmd.Flags()
if flags.Changed(flagName) {
configs, err := flags.GetStringSlice(flagName)
if err != nil {
return err
}
container := spec.Task.GetContainer()
if container == nil {
return nil
}
wantT... | [
"func",
"ParseRemoveConfig",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"spec",
"*",
"api",
".",
"ServiceSpec",
",",
"flagName",
"string",
")",
"error",
"{",
"flags",
":=",
"cmd",
".",
"Flags",
"(",
")",
"\n\n",
"if",
"flags",
".",
"Changed",
"(",
... | // ParseRemoveConfig removes a set of configs from the task spec's config references | [
"ParseRemoveConfig",
"removes",
"a",
"set",
"of",
"configs",
"from",
"the",
"task",
"spec",
"s",
"config",
"references"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/cmd/swarmctl/service/flagparser/config.go#L107-L144 | train |
docker/swarmkit | ca/keyreadwriter.go | NewKeyReadWriter | func NewKeyReadWriter(paths CertPaths, kek []byte, headersObj PEMKeyHeaders) *KeyReadWriter {
return &KeyReadWriter{
kekData: KEKData{KEK: kek},
paths: paths,
headersObj: headersObj,
keyFormatter: keyutils.Default,
}
} | go | func NewKeyReadWriter(paths CertPaths, kek []byte, headersObj PEMKeyHeaders) *KeyReadWriter {
return &KeyReadWriter{
kekData: KEKData{KEK: kek},
paths: paths,
headersObj: headersObj,
keyFormatter: keyutils.Default,
}
} | [
"func",
"NewKeyReadWriter",
"(",
"paths",
"CertPaths",
",",
"kek",
"[",
"]",
"byte",
",",
"headersObj",
"PEMKeyHeaders",
")",
"*",
"KeyReadWriter",
"{",
"return",
"&",
"KeyReadWriter",
"{",
"kekData",
":",
"KEKData",
"{",
"KEK",
":",
"kek",
"}",
",",
"path... | // NewKeyReadWriter creates a new KeyReadWriter | [
"NewKeyReadWriter",
"creates",
"a",
"new",
"KeyReadWriter"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/keyreadwriter.go#L136-L143 | train |
docker/swarmkit | ca/keyreadwriter.go | SetKeyFormatter | func (k *KeyReadWriter) SetKeyFormatter(kf keyutils.Formatter) {
k.mu.Lock()
defer k.mu.Unlock()
k.keyFormatter = kf
} | go | func (k *KeyReadWriter) SetKeyFormatter(kf keyutils.Formatter) {
k.mu.Lock()
defer k.mu.Unlock()
k.keyFormatter = kf
} | [
"func",
"(",
"k",
"*",
"KeyReadWriter",
")",
"SetKeyFormatter",
"(",
"kf",
"keyutils",
".",
"Formatter",
")",
"{",
"k",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"k",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"k",
".",
"keyFormatter",
"=",
... | // SetKeyFormatter sets the keyformatter with which to encrypt and decrypt keys | [
"SetKeyFormatter",
"sets",
"the",
"keyformatter",
"with",
"which",
"to",
"encrypt",
"and",
"decrypt",
"keys"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/keyreadwriter.go#L146-L150 | train |
docker/swarmkit | ca/keyreadwriter.go | Migrate | func (k *KeyReadWriter) Migrate() error {
tmpPaths := k.genTempPaths()
keyBytes, err := ioutil.ReadFile(tmpPaths.Key)
if err != nil {
return nil // no key? no migration
}
// it does exist - no need to decrypt, because previous versions of swarmkit
// which supported this temporary key did not support encrypti... | go | func (k *KeyReadWriter) Migrate() error {
tmpPaths := k.genTempPaths()
keyBytes, err := ioutil.ReadFile(tmpPaths.Key)
if err != nil {
return nil // no key? no migration
}
// it does exist - no need to decrypt, because previous versions of swarmkit
// which supported this temporary key did not support encrypti... | [
"func",
"(",
"k",
"*",
"KeyReadWriter",
")",
"Migrate",
"(",
")",
"error",
"{",
"tmpPaths",
":=",
"k",
".",
"genTempPaths",
"(",
")",
"\n",
"keyBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"tmpPaths",
".",
"Key",
")",
"\n",
"if",
"err",
... | // Migrate checks to see if a temporary key file exists. Older versions of
// swarmkit wrote temporary keys instead of temporary certificates, so
// migrate that temporary key if it exists. We want to write temporary certificates,
// instead of temporary keys, because we may need to periodically re-encrypt the
// key... | [
"Migrate",
"checks",
"to",
"see",
"if",
"a",
"temporary",
"key",
"file",
"exists",
".",
"Older",
"versions",
"of",
"swarmkit",
"wrote",
"temporary",
"keys",
"instead",
"of",
"temporary",
"certificates",
"so",
"migrate",
"that",
"temporary",
"key",
"if",
"it",
... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/keyreadwriter.go#L158-L178 | train |
docker/swarmkit | ca/keyreadwriter.go | Read | func (k *KeyReadWriter) Read() ([]byte, []byte, error) {
k.mu.Lock()
defer k.mu.Unlock()
keyBlock, err := k.readKey()
if err != nil {
return nil, nil, err
}
if version, ok := keyBlock.Headers[versionHeader]; ok {
if versionInt, err := strconv.ParseUint(version, 10, 64); err == nil {
k.kekData.Version = ve... | go | func (k *KeyReadWriter) Read() ([]byte, []byte, error) {
k.mu.Lock()
defer k.mu.Unlock()
keyBlock, err := k.readKey()
if err != nil {
return nil, nil, err
}
if version, ok := keyBlock.Headers[versionHeader]; ok {
if versionInt, err := strconv.ParseUint(version, 10, 64); err == nil {
k.kekData.Version = ve... | [
"func",
"(",
"k",
"*",
"KeyReadWriter",
")",
"Read",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"k",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"k",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"keyBl... | // Read will read a TLS cert and key from the given paths | [
"Read",
"will",
"read",
"a",
"TLS",
"cert",
"and",
"key",
"from",
"the",
"given",
"paths"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/keyreadwriter.go#L181-L235 | train |
docker/swarmkit | ca/keyreadwriter.go | ViewAndRotateKEK | func (k *KeyReadWriter) ViewAndRotateKEK(cb func(KEKData, PEMKeyHeaders) (KEKData, PEMKeyHeaders, error)) error {
k.mu.Lock()
defer k.mu.Unlock()
updatedKEK, updatedHeaderObj, err := cb(k.kekData, k.headersObj)
if err != nil {
return err
}
keyBlock, err := k.readKey()
if err != nil {
return err
}
return... | go | func (k *KeyReadWriter) ViewAndRotateKEK(cb func(KEKData, PEMKeyHeaders) (KEKData, PEMKeyHeaders, error)) error {
k.mu.Lock()
defer k.mu.Unlock()
updatedKEK, updatedHeaderObj, err := cb(k.kekData, k.headersObj)
if err != nil {
return err
}
keyBlock, err := k.readKey()
if err != nil {
return err
}
return... | [
"func",
"(",
"k",
"*",
"KeyReadWriter",
")",
"ViewAndRotateKEK",
"(",
"cb",
"func",
"(",
"KEKData",
",",
"PEMKeyHeaders",
")",
"(",
"KEKData",
",",
"PEMKeyHeaders",
",",
"error",
")",
")",
"error",
"{",
"k",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"d... | // ViewAndRotateKEK re-encrypts the key with a new KEK | [
"ViewAndRotateKEK",
"re",
"-",
"encrypts",
"the",
"key",
"with",
"a",
"new",
"KEK"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/keyreadwriter.go#L238-L253 | train |
docker/swarmkit | ca/keyreadwriter.go | ViewAndUpdateHeaders | func (k *KeyReadWriter) ViewAndUpdateHeaders(cb func(PEMKeyHeaders) (PEMKeyHeaders, error)) error {
k.mu.Lock()
defer k.mu.Unlock()
pkh, err := cb(k.headersObj)
if err != nil {
return err
}
keyBlock, err := k.readKeyblock()
if err != nil {
return err
}
headers := make(map[string]string)
if pkh != nil {... | go | func (k *KeyReadWriter) ViewAndUpdateHeaders(cb func(PEMKeyHeaders) (PEMKeyHeaders, error)) error {
k.mu.Lock()
defer k.mu.Unlock()
pkh, err := cb(k.headersObj)
if err != nil {
return err
}
keyBlock, err := k.readKeyblock()
if err != nil {
return err
}
headers := make(map[string]string)
if pkh != nil {... | [
"func",
"(",
"k",
"*",
"KeyReadWriter",
")",
"ViewAndUpdateHeaders",
"(",
"cb",
"func",
"(",
"PEMKeyHeaders",
")",
"(",
"PEMKeyHeaders",
",",
"error",
")",
")",
"error",
"{",
"k",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"k",
".",
"mu",
".",
... | // ViewAndUpdateHeaders updates the header manager, and updates any headers on the existing key | [
"ViewAndUpdateHeaders",
"updates",
"the",
"header",
"manager",
"and",
"updates",
"any",
"headers",
"on",
"the",
"existing",
"key"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/keyreadwriter.go#L256-L293 | train |
docker/swarmkit | ca/keyreadwriter.go | GetCurrentState | func (k *KeyReadWriter) GetCurrentState() (PEMKeyHeaders, KEKData) {
k.mu.Lock()
defer k.mu.Unlock()
return k.headersObj, k.kekData
} | go | func (k *KeyReadWriter) GetCurrentState() (PEMKeyHeaders, KEKData) {
k.mu.Lock()
defer k.mu.Unlock()
return k.headersObj, k.kekData
} | [
"func",
"(",
"k",
"*",
"KeyReadWriter",
")",
"GetCurrentState",
"(",
")",
"(",
"PEMKeyHeaders",
",",
"KEKData",
")",
"{",
"k",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"k",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"k",
".",
"he... | // GetCurrentState returns the current KEK data, including version | [
"GetCurrentState",
"returns",
"the",
"current",
"KEK",
"data",
"including",
"version"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/keyreadwriter.go#L296-L300 | train |
docker/swarmkit | ca/keyreadwriter.go | writeKey | func (k *KeyReadWriter) writeKey(keyBlock *pem.Block, kekData KEKData, pkh PEMKeyHeaders) error {
if kekData.KEK != nil {
encryptedPEMBlock, err := k.keyFormatter.EncryptPEMBlock(keyBlock.Bytes, kekData.KEK)
if err != nil {
return err
}
if !keyutils.IsEncryptedPEMBlock(encryptedPEMBlock) {
return errors.... | go | func (k *KeyReadWriter) writeKey(keyBlock *pem.Block, kekData KEKData, pkh PEMKeyHeaders) error {
if kekData.KEK != nil {
encryptedPEMBlock, err := k.keyFormatter.EncryptPEMBlock(keyBlock.Bytes, kekData.KEK)
if err != nil {
return err
}
if !keyutils.IsEncryptedPEMBlock(encryptedPEMBlock) {
return errors.... | [
"func",
"(",
"k",
"*",
"KeyReadWriter",
")",
"writeKey",
"(",
"keyBlock",
"*",
"pem",
".",
"Block",
",",
"kekData",
"KEKData",
",",
"pkh",
"PEMKeyHeaders",
")",
"error",
"{",
"if",
"kekData",
".",
"KEK",
"!=",
"nil",
"{",
"encryptedPEMBlock",
",",
"err",... | // writeKey takes an unencrypted keyblock and, if the kek is not nil, encrypts it before
// writing it to disk. If the kek is nil, writes it to disk unencrypted. | [
"writeKey",
"takes",
"an",
"unencrypted",
"keyblock",
"and",
"if",
"the",
"kek",
"is",
"not",
"nil",
"encrypts",
"it",
"before",
"writing",
"it",
"to",
"disk",
".",
"If",
"the",
"kek",
"is",
"nil",
"writes",
"it",
"to",
"disk",
"unencrypted",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/keyreadwriter.go#L413-L440 | train |
docker/swarmkit | ca/keyreadwriter.go | mergePEMHeaders | func mergePEMHeaders(original, newSet map[string]string) {
for key, value := range newSet {
normalizedKey := strings.TrimSpace(strings.ToLower(key))
if normalizedKey != "proc-type" && normalizedKey != "dek-info" {
original[key] = value
}
}
} | go | func mergePEMHeaders(original, newSet map[string]string) {
for key, value := range newSet {
normalizedKey := strings.TrimSpace(strings.ToLower(key))
if normalizedKey != "proc-type" && normalizedKey != "dek-info" {
original[key] = value
}
}
} | [
"func",
"mergePEMHeaders",
"(",
"original",
",",
"newSet",
"map",
"[",
"string",
"]",
"string",
")",
"{",
"for",
"key",
",",
"value",
":=",
"range",
"newSet",
"{",
"normalizedKey",
":=",
"strings",
".",
"TrimSpace",
"(",
"strings",
".",
"ToLower",
"(",
"... | // merges one set of PEM headers onto another, excepting for key encryption value
// "proc-type" and "dek-info" | [
"merges",
"one",
"set",
"of",
"PEM",
"headers",
"onto",
"another",
"excepting",
"for",
"key",
"encryption",
"value",
"proc",
"-",
"type",
"and",
"dek",
"-",
"info"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/keyreadwriter.go#L486-L493 | train |
docker/swarmkit | cmd/swarm-bench/benchmark.go | Run | func (b *Benchmark) Run(ctx context.Context) error {
fmt.Printf("Listening for incoming connections at %s:%d\n", b.cfg.IP, b.cfg.Port)
if err := b.collector.Listen(b.cfg.Port); err != nil {
return err
}
j, err := b.launch(ctx)
if err != nil {
return err
}
fmt.Printf("Service %s launched (%d instances)\n", j.... | go | func (b *Benchmark) Run(ctx context.Context) error {
fmt.Printf("Listening for incoming connections at %s:%d\n", b.cfg.IP, b.cfg.Port)
if err := b.collector.Listen(b.cfg.Port); err != nil {
return err
}
j, err := b.launch(ctx)
if err != nil {
return err
}
fmt.Printf("Service %s launched (%d instances)\n", j.... | [
"func",
"(",
"b",
"*",
"Benchmark",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"b",
".",
"cfg",
".",
"IP",
",",
"b",
".",
"cfg",
".",
"Port",
")",
"\n",
"if",
"err"... | // Run starts the benchmark session and waits for it to be completed. | [
"Run",
"starts",
"the",
"benchmark",
"session",
"and",
"waits",
"for",
"it",
"to",
"be",
"completed",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/cmd/swarm-bench/benchmark.go#L38-L71 | train |
docker/swarmkit | ca/renewer.go | NewTLSRenewer | func NewTLSRenewer(s *SecurityConfig, connBroker *connectionbroker.Broker, rootPaths CertPaths) *TLSRenewer {
return &TLSRenewer{
s: s,
connBroker: connBroker,
renew: make(chan struct{}, 1),
rootPaths: rootPaths,
}
} | go | func NewTLSRenewer(s *SecurityConfig, connBroker *connectionbroker.Broker, rootPaths CertPaths) *TLSRenewer {
return &TLSRenewer{
s: s,
connBroker: connBroker,
renew: make(chan struct{}, 1),
rootPaths: rootPaths,
}
} | [
"func",
"NewTLSRenewer",
"(",
"s",
"*",
"SecurityConfig",
",",
"connBroker",
"*",
"connectionbroker",
".",
"Broker",
",",
"rootPaths",
"CertPaths",
")",
"*",
"TLSRenewer",
"{",
"return",
"&",
"TLSRenewer",
"{",
"s",
":",
"s",
",",
"connBroker",
":",
"connBro... | // NewTLSRenewer creates a new TLS renewer. It must be started with Start. | [
"NewTLSRenewer",
"creates",
"a",
"new",
"TLS",
"renewer",
".",
"It",
"must",
"be",
"started",
"with",
"Start",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/renewer.go#L34-L41 | train |
docker/swarmkit | ca/renewer.go | SetExpectedRole | func (t *TLSRenewer) SetExpectedRole(role string) {
t.mu.Lock()
t.expectedRole = role
t.mu.Unlock()
} | go | func (t *TLSRenewer) SetExpectedRole(role string) {
t.mu.Lock()
t.expectedRole = role
t.mu.Unlock()
} | [
"func",
"(",
"t",
"*",
"TLSRenewer",
")",
"SetExpectedRole",
"(",
"role",
"string",
")",
"{",
"t",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"t",
".",
"expectedRole",
"=",
"role",
"\n",
"t",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // SetExpectedRole sets the expected role. If a renewal is forced, and the role
// doesn't match this expectation, renewal will be retried with exponential
// backoff until it does match. | [
"SetExpectedRole",
"sets",
"the",
"expected",
"role",
".",
"If",
"a",
"renewal",
"is",
"forced",
"and",
"the",
"role",
"doesn",
"t",
"match",
"this",
"expectation",
"renewal",
"will",
"be",
"retried",
"with",
"exponential",
"backoff",
"until",
"it",
"does",
... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/ca/renewer.go#L46-L50 | train |
docker/swarmkit | manager/drivers/provider.go | NewSecretDriver | func (m *DriverProvider) NewSecretDriver(driver *api.Driver) (*SecretDriver, error) {
if m.pluginGetter == nil {
return nil, fmt.Errorf("plugin getter is nil")
}
if driver == nil && driver.Name == "" {
return nil, fmt.Errorf("driver specification is nil")
}
// Search for the specified plugin
plugin, err := m.... | go | func (m *DriverProvider) NewSecretDriver(driver *api.Driver) (*SecretDriver, error) {
if m.pluginGetter == nil {
return nil, fmt.Errorf("plugin getter is nil")
}
if driver == nil && driver.Name == "" {
return nil, fmt.Errorf("driver specification is nil")
}
// Search for the specified plugin
plugin, err := m.... | [
"func",
"(",
"m",
"*",
"DriverProvider",
")",
"NewSecretDriver",
"(",
"driver",
"*",
"api",
".",
"Driver",
")",
"(",
"*",
"SecretDriver",
",",
"error",
")",
"{",
"if",
"m",
".",
"pluginGetter",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Err... | // NewSecretDriver creates a new driver for fetching secrets | [
"NewSecretDriver",
"creates",
"a",
"new",
"driver",
"for",
"fetching",
"secrets"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/drivers/provider.go#L21-L34 | train |
docker/swarmkit | cli/external_ca.go | Set | func (m *ExternalCAOpt) Set(value string) error {
parsed, err := parseExternalCA(value)
if err != nil {
return err
}
m.values = append(m.values, parsed)
return nil
} | go | func (m *ExternalCAOpt) Set(value string) error {
parsed, err := parseExternalCA(value)
if err != nil {
return err
}
m.values = append(m.values, parsed)
return nil
} | [
"func",
"(",
"m",
"*",
"ExternalCAOpt",
")",
"Set",
"(",
"value",
"string",
")",
"error",
"{",
"parsed",
",",
"err",
":=",
"parseExternalCA",
"(",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"m",
".",
"val... | // Set parses an external CA option. | [
"Set",
"parses",
"an",
"external",
"CA",
"option",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/cli/external_ca.go#L18-L26 | train |
docker/swarmkit | manager/resourceapi/allocator.go | AttachNetwork | func (ra *ResourceAllocator) AttachNetwork(ctx context.Context, request *api.AttachNetworkRequest) (*api.AttachNetworkResponse, error) {
nodeInfo, err := ca.RemoteNode(ctx)
if err != nil {
return nil, err
}
var network *api.Network
ra.store.View(func(tx store.ReadTx) {
network = store.GetNetwork(tx, request.C... | go | func (ra *ResourceAllocator) AttachNetwork(ctx context.Context, request *api.AttachNetworkRequest) (*api.AttachNetworkResponse, error) {
nodeInfo, err := ca.RemoteNode(ctx)
if err != nil {
return nil, err
}
var network *api.Network
ra.store.View(func(tx store.ReadTx) {
network = store.GetNetwork(tx, request.C... | [
"func",
"(",
"ra",
"*",
"ResourceAllocator",
")",
"AttachNetwork",
"(",
"ctx",
"context",
".",
"Context",
",",
"request",
"*",
"api",
".",
"AttachNetworkRequest",
")",
"(",
"*",
"api",
".",
"AttachNetworkResponse",
",",
"error",
")",
"{",
"nodeInfo",
",",
... | // AttachNetwork allows the node to request the resources
// allocation needed for a network attachment on the specific node.
// - Returns `InvalidArgument` if the Spec is malformed.
// - Returns `NotFound` if the Network is not found.
// - Returns `PermissionDenied` if the Network is not manually attachable.
// - Retu... | [
"AttachNetwork",
"allows",
"the",
"node",
"to",
"request",
"the",
"resources",
"allocation",
"needed",
"for",
"a",
"network",
"attachment",
"on",
"the",
"specific",
"node",
".",
"-",
"Returns",
"InvalidArgument",
"if",
"the",
"Spec",
"is",
"malformed",
".",
"-... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/resourceapi/allocator.go#L37-L92 | train |
docker/swarmkit | manager/resourceapi/allocator.go | DetachNetwork | func (ra *ResourceAllocator) DetachNetwork(ctx context.Context, request *api.DetachNetworkRequest) (*api.DetachNetworkResponse, error) {
if request.AttachmentID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
nodeInfo, err := ca.RemoteNode(ctx)
if err != nil {
return nil,... | go | func (ra *ResourceAllocator) DetachNetwork(ctx context.Context, request *api.DetachNetworkRequest) (*api.DetachNetworkResponse, error) {
if request.AttachmentID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
nodeInfo, err := ca.RemoteNode(ctx)
if err != nil {
return nil,... | [
"func",
"(",
"ra",
"*",
"ResourceAllocator",
")",
"DetachNetwork",
"(",
"ctx",
"context",
".",
"Context",
",",
"request",
"*",
"api",
".",
"DetachNetworkRequest",
")",
"(",
"*",
"api",
".",
"DetachNetworkResponse",
",",
"error",
")",
"{",
"if",
"request",
... | // DetachNetwork allows the node to request the release of
// the resources associated to the network attachment.
// - Returns `InvalidArgument` if attachment ID is not provided.
// - Returns `NotFound` if the attachment is not found.
// - Returns an error if the deletion fails. | [
"DetachNetwork",
"allows",
"the",
"node",
"to",
"request",
"the",
"release",
"of",
"the",
"resources",
"associated",
"to",
"the",
"network",
"attachment",
".",
"-",
"Returns",
"InvalidArgument",
"if",
"attachment",
"ID",
"is",
"not",
"provided",
".",
"-",
"Ret... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/resourceapi/allocator.go#L99-L124 | train |
docker/swarmkit | manager/metrics/collector.go | NewCollector | func NewCollector(store *store.MemoryStore) *Collector {
return &Collector{
store: store,
stopChan: make(chan struct{}),
doneChan: make(chan struct{}),
}
} | go | func NewCollector(store *store.MemoryStore) *Collector {
return &Collector{
store: store,
stopChan: make(chan struct{}),
doneChan: make(chan struct{}),
}
} | [
"func",
"NewCollector",
"(",
"store",
"*",
"store",
".",
"MemoryStore",
")",
"*",
"Collector",
"{",
"return",
"&",
"Collector",
"{",
"store",
":",
"store",
",",
"stopChan",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"doneChan",
":",
"make"... | // NewCollector creates a new metrics collector | [
"NewCollector",
"creates",
"a",
"new",
"metrics",
"collector"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/metrics/collector.go#L52-L58 | train |
docker/swarmkit | manager/metrics/collector.go | Run | func (c *Collector) Run(ctx context.Context) error {
defer close(c.doneChan)
watcher, cancel, err := store.ViewAndWatch(c.store, func(readTx store.ReadTx) error {
nodes, err := store.FindNodes(readTx, store.All)
if err != nil {
return err
}
tasks, err := store.FindTasks(readTx, store.All)
if err != nil ... | go | func (c *Collector) Run(ctx context.Context) error {
defer close(c.doneChan)
watcher, cancel, err := store.ViewAndWatch(c.store, func(readTx store.ReadTx) error {
nodes, err := store.FindNodes(readTx, store.All)
if err != nil {
return err
}
tasks, err := store.FindTasks(readTx, store.All)
if err != nil ... | [
"func",
"(",
"c",
"*",
"Collector",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"defer",
"close",
"(",
"c",
".",
"doneChan",
")",
"\n\n",
"watcher",
",",
"cancel",
",",
"err",
":=",
"store",
".",
"ViewAndWatch",
"(",
"c",
... | // Run contains the collector event loop | [
"Run",
"contains",
"the",
"collector",
"event",
"loop"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/metrics/collector.go#L61-L124 | train |
docker/swarmkit | manager/metrics/collector.go | handleEvent | func (c *Collector) handleEvent(event events.Event) {
switch event.(type) {
case api.EventNode:
c.handleNodeEvent(event)
case api.EventTask:
c.handleTaskEvent(event)
case api.EventService:
c.handleServiceEvent(event)
case api.EventNetwork:
c.handleNetworkEvent(event)
case api.EventSecret:
c.handleSecret... | go | func (c *Collector) handleEvent(event events.Event) {
switch event.(type) {
case api.EventNode:
c.handleNodeEvent(event)
case api.EventTask:
c.handleTaskEvent(event)
case api.EventService:
c.handleServiceEvent(event)
case api.EventNetwork:
c.handleNetworkEvent(event)
case api.EventSecret:
c.handleSecret... | [
"func",
"(",
"c",
"*",
"Collector",
")",
"handleEvent",
"(",
"event",
"events",
".",
"Event",
")",
"{",
"switch",
"event",
".",
"(",
"type",
")",
"{",
"case",
"api",
".",
"EventNode",
":",
"c",
".",
"handleNodeEvent",
"(",
"event",
")",
"\n",
"case",... | // handleEvent handles a single incoming cluster event. | [
"handleEvent",
"handles",
"a",
"single",
"incoming",
"cluster",
"event",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/metrics/collector.go#L151-L166 | train |
docker/swarmkit | manager/controlapi/task.go | GetTask | func (s *Server) GetTask(ctx context.Context, request *api.GetTaskRequest) (*api.GetTaskResponse, error) {
if request.TaskID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
var task *api.Task
s.store.View(func(tx store.ReadTx) {
task = store.GetTask(tx, request.TaskID)
}... | go | func (s *Server) GetTask(ctx context.Context, request *api.GetTaskRequest) (*api.GetTaskResponse, error) {
if request.TaskID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
var task *api.Task
s.store.View(func(tx store.ReadTx) {
task = store.GetTask(tx, request.TaskID)
}... | [
"func",
"(",
"s",
"*",
"Server",
")",
"GetTask",
"(",
"ctx",
"context",
".",
"Context",
",",
"request",
"*",
"api",
".",
"GetTaskRequest",
")",
"(",
"*",
"api",
".",
"GetTaskResponse",
",",
"error",
")",
"{",
"if",
"request",
".",
"TaskID",
"==",
"\"... | // GetTask returns a Task given a TaskID.
// - Returns `InvalidArgument` if TaskID is not provided.
// - Returns `NotFound` if the Task is not found. | [
"GetTask",
"returns",
"a",
"Task",
"given",
"a",
"TaskID",
".",
"-",
"Returns",
"InvalidArgument",
"if",
"TaskID",
"is",
"not",
"provided",
".",
"-",
"Returns",
"NotFound",
"if",
"the",
"Task",
"is",
"not",
"found",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/controlapi/task.go#L17-L32 | train |
docker/swarmkit | manager/controlapi/task.go | RemoveTask | func (s *Server) RemoveTask(ctx context.Context, request *api.RemoveTaskRequest) (*api.RemoveTaskResponse, error) {
if request.TaskID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
err := s.store.Update(func(tx store.Tx) error {
return store.DeleteTask(tx, request.TaskID)... | go | func (s *Server) RemoveTask(ctx context.Context, request *api.RemoveTaskRequest) (*api.RemoveTaskResponse, error) {
if request.TaskID == "" {
return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
}
err := s.store.Update(func(tx store.Tx) error {
return store.DeleteTask(tx, request.TaskID)... | [
"func",
"(",
"s",
"*",
"Server",
")",
"RemoveTask",
"(",
"ctx",
"context",
".",
"Context",
",",
"request",
"*",
"api",
".",
"RemoveTaskRequest",
")",
"(",
"*",
"api",
".",
"RemoveTaskResponse",
",",
"error",
")",
"{",
"if",
"request",
".",
"TaskID",
"=... | // RemoveTask removes a Task referenced by TaskID.
// - Returns `InvalidArgument` if TaskID is not provided.
// - Returns `NotFound` if the Task is not found.
// - Returns an error if the deletion fails. | [
"RemoveTask",
"removes",
"a",
"Task",
"referenced",
"by",
"TaskID",
".",
"-",
"Returns",
"InvalidArgument",
"if",
"TaskID",
"is",
"not",
"provided",
".",
"-",
"Returns",
"NotFound",
"if",
"the",
"Task",
"is",
"not",
"found",
".",
"-",
"Returns",
"an",
"err... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/controlapi/task.go#L38-L53 | train |
docker/swarmkit | manager/orchestrator/update/updater.go | NewSupervisor | func NewSupervisor(store *store.MemoryStore, restartSupervisor *restart.Supervisor) *Supervisor {
return &Supervisor{
store: store,
updates: make(map[string]*Updater),
restarts: restartSupervisor,
}
} | go | func NewSupervisor(store *store.MemoryStore, restartSupervisor *restart.Supervisor) *Supervisor {
return &Supervisor{
store: store,
updates: make(map[string]*Updater),
restarts: restartSupervisor,
}
} | [
"func",
"NewSupervisor",
"(",
"store",
"*",
"store",
".",
"MemoryStore",
",",
"restartSupervisor",
"*",
"restart",
".",
"Supervisor",
")",
"*",
"Supervisor",
"{",
"return",
"&",
"Supervisor",
"{",
"store",
":",
"store",
",",
"updates",
":",
"make",
"(",
"m... | // NewSupervisor creates a new UpdateSupervisor. | [
"NewSupervisor",
"creates",
"a",
"new",
"UpdateSupervisor",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/update/updater.go#L34-L40 | train |
docker/swarmkit | manager/orchestrator/update/updater.go | CancelAll | func (u *Supervisor) CancelAll() {
u.l.Lock()
defer u.l.Unlock()
for _, update := range u.updates {
update.Cancel()
}
} | go | func (u *Supervisor) CancelAll() {
u.l.Lock()
defer u.l.Unlock()
for _, update := range u.updates {
update.Cancel()
}
} | [
"func",
"(",
"u",
"*",
"Supervisor",
")",
"CancelAll",
"(",
")",
"{",
"u",
".",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"u",
".",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"_",
",",
"update",
":=",
"range",
"u",
".",
"updates",
"{",
"up... | // CancelAll cancels all current updates. | [
"CancelAll",
"cancels",
"all",
"current",
"updates",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/update/updater.go#L76-L83 | train |
docker/swarmkit | manager/orchestrator/update/updater.go | NewUpdater | func NewUpdater(store *store.MemoryStore, restartSupervisor *restart.Supervisor, cluster *api.Cluster, newService *api.Service) *Updater {
return &Updater{
store: store,
watchQueue: store.WatchQueue(),
restarts: restartSupervisor,
cluster: cluster.Copy(),
newService: newService.Copy(),
... | go | func NewUpdater(store *store.MemoryStore, restartSupervisor *restart.Supervisor, cluster *api.Cluster, newService *api.Service) *Updater {
return &Updater{
store: store,
watchQueue: store.WatchQueue(),
restarts: restartSupervisor,
cluster: cluster.Copy(),
newService: newService.Copy(),
... | [
"func",
"NewUpdater",
"(",
"store",
"*",
"store",
".",
"MemoryStore",
",",
"restartSupervisor",
"*",
"restart",
".",
"Supervisor",
",",
"cluster",
"*",
"api",
".",
"Cluster",
",",
"newService",
"*",
"api",
".",
"Service",
")",
"*",
"Updater",
"{",
"return"... | // NewUpdater creates a new Updater. | [
"NewUpdater",
"creates",
"a",
"new",
"Updater",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/update/updater.go#L104-L115 | train |
docker/swarmkit | manager/orchestrator/update/updater.go | removeOldTasks | func (u *Updater) removeOldTasks(ctx context.Context, batch *store.Batch, removeTasks []*api.Task) (*api.Task, error) {
var (
lastErr error
removedTask *api.Task
)
for _, original := range removeTasks {
if original.DesiredState > api.TaskStateRunning {
continue
}
err := batch.Update(func(tx store.Tx... | go | func (u *Updater) removeOldTasks(ctx context.Context, batch *store.Batch, removeTasks []*api.Task) (*api.Task, error) {
var (
lastErr error
removedTask *api.Task
)
for _, original := range removeTasks {
if original.DesiredState > api.TaskStateRunning {
continue
}
err := batch.Update(func(tx store.Tx... | [
"func",
"(",
"u",
"*",
"Updater",
")",
"removeOldTasks",
"(",
"ctx",
"context",
".",
"Context",
",",
"batch",
"*",
"store",
".",
"Batch",
",",
"removeTasks",
"[",
"]",
"*",
"api",
".",
"Task",
")",
"(",
"*",
"api",
".",
"Task",
",",
"error",
")",
... | // removeOldTasks shuts down the given tasks and returns one of the tasks that
// was shut down, or an error. | [
"removeOldTasks",
"shuts",
"down",
"the",
"given",
"tasks",
"and",
"returns",
"one",
"of",
"the",
"tasks",
"that",
"was",
"shut",
"down",
"or",
"an",
"error",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/update/updater.go#L496-L527 | train |
docker/swarmkit | agent/task.go | Update | func (tm *taskManager) Update(ctx context.Context, task *api.Task) error {
select {
case tm.updateq <- task:
return nil
case <-tm.closed:
return ErrClosed
case <-ctx.Done():
return ctx.Err()
}
} | go | func (tm *taskManager) Update(ctx context.Context, task *api.Task) error {
select {
case tm.updateq <- task:
return nil
case <-tm.closed:
return ErrClosed
case <-ctx.Done():
return ctx.Err()
}
} | [
"func",
"(",
"tm",
"*",
"taskManager",
")",
"Update",
"(",
"ctx",
"context",
".",
"Context",
",",
"task",
"*",
"api",
".",
"Task",
")",
"error",
"{",
"select",
"{",
"case",
"tm",
".",
"updateq",
"<-",
"task",
":",
"return",
"nil",
"\n",
"case",
"<-... | // Update the task data. | [
"Update",
"the",
"task",
"data",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/task.go#L43-L52 | train |
docker/swarmkit | agent/task.go | Close | func (tm *taskManager) Close() error {
tm.shutdownOnce.Do(func() {
close(tm.shutdown)
})
<-tm.closed
return nil
} | go | func (tm *taskManager) Close() error {
tm.shutdownOnce.Do(func() {
close(tm.shutdown)
})
<-tm.closed
return nil
} | [
"func",
"(",
"tm",
"*",
"taskManager",
")",
"Close",
"(",
")",
"error",
"{",
"tm",
".",
"shutdownOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"close",
"(",
"tm",
".",
"shutdown",
")",
"\n",
"}",
")",
"\n\n",
"<-",
"tm",
".",
"closed",
"\n\n",
... | // Close shuts down the task manager, blocking until it is closed. | [
"Close",
"shuts",
"down",
"the",
"task",
"manager",
"blocking",
"until",
"it",
"is",
"closed",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/task.go#L55-L63 | train |
docker/swarmkit | api/genericresource/parse.go | Parse | func Parse(cmds []string) ([]*api.GenericResource, error) {
tokens := make(map[string][]string)
for _, term := range cmds {
kva := strings.Split(term, "=")
if len(kva) != 2 {
return nil, newParseError("incorrect term %s, missing"+
" '=' or malformed expression", term)
}
key := strings.TrimSpace(kva[0... | go | func Parse(cmds []string) ([]*api.GenericResource, error) {
tokens := make(map[string][]string)
for _, term := range cmds {
kva := strings.Split(term, "=")
if len(kva) != 2 {
return nil, newParseError("incorrect term %s, missing"+
" '=' or malformed expression", term)
}
key := strings.TrimSpace(kva[0... | [
"func",
"Parse",
"(",
"cmds",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"api",
".",
"GenericResource",
",",
"error",
")",
"{",
"tokens",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"\n\n",
"for",
"_",
",",
"term",
... | // Parse parses a table of GenericResource resources | [
"Parse",
"parses",
"a",
"table",
"of",
"GenericResource",
"resources"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/api/genericresource/parse.go#L56-L94 | train |
docker/swarmkit | agent/exec/dockerapi/controller.go | newController | func newController(client engineapi.APIClient, nodeDescription *api.NodeDescription, task *api.Task, secrets exec.SecretGetter) (exec.Controller, error) {
adapter, err := newContainerAdapter(client, nodeDescription, task, secrets)
if err != nil {
return nil, err
}
return &controller{
task: task,
adapter: ... | go | func newController(client engineapi.APIClient, nodeDescription *api.NodeDescription, task *api.Task, secrets exec.SecretGetter) (exec.Controller, error) {
adapter, err := newContainerAdapter(client, nodeDescription, task, secrets)
if err != nil {
return nil, err
}
return &controller{
task: task,
adapter: ... | [
"func",
"newController",
"(",
"client",
"engineapi",
".",
"APIClient",
",",
"nodeDescription",
"*",
"api",
".",
"NodeDescription",
",",
"task",
"*",
"api",
".",
"Task",
",",
"secrets",
"exec",
".",
"SecretGetter",
")",
"(",
"exec",
".",
"Controller",
",",
... | // newController returns a docker exec controller for the provided task. | [
"newController",
"returns",
"a",
"docker",
"exec",
"controller",
"for",
"the",
"provided",
"task",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/exec/dockerapi/controller.go#L44-L55 | train |
docker/swarmkit | agent/exec/dockerapi/controller.go | Update | func (r *controller) Update(ctx context.Context, t *api.Task) error {
log.G(ctx).Warnf("task updates not yet supported")
// TODO(stevvooe): While assignment of tasks is idempotent, we do allow
// updates of metadata, such as labelling, as well as any other properties
// that make sense.
return nil
} | go | func (r *controller) Update(ctx context.Context, t *api.Task) error {
log.G(ctx).Warnf("task updates not yet supported")
// TODO(stevvooe): While assignment of tasks is idempotent, we do allow
// updates of metadata, such as labelling, as well as any other properties
// that make sense.
return nil
} | [
"func",
"(",
"r",
"*",
"controller",
")",
"Update",
"(",
"ctx",
"context",
".",
"Context",
",",
"t",
"*",
"api",
".",
"Task",
")",
"error",
"{",
"log",
".",
"G",
"(",
"ctx",
")",
".",
"Warnf",
"(",
"\"",
"\"",
")",
"\n",
"// TODO(stevvooe): While a... | // Update takes a recent task update and applies it to the container. | [
"Update",
"takes",
"a",
"recent",
"task",
"update",
"and",
"applies",
"it",
"to",
"the",
"container",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/exec/dockerapi/controller.go#L84-L90 | train |
docker/swarmkit | agent/exec/dockerapi/controller.go | Prepare | func (r *controller) Prepare(ctx context.Context) error {
if err := r.checkClosed(); err != nil {
return err
}
// Make sure all the networks that the task needs are created.
if err := r.adapter.createNetworks(ctx); err != nil {
return err
}
// Make sure all the volumes that the task needs are created.
if e... | go | func (r *controller) Prepare(ctx context.Context) error {
if err := r.checkClosed(); err != nil {
return err
}
// Make sure all the networks that the task needs are created.
if err := r.adapter.createNetworks(ctx); err != nil {
return err
}
// Make sure all the volumes that the task needs are created.
if e... | [
"func",
"(",
"r",
"*",
"controller",
")",
"Prepare",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"err",
":=",
"r",
".",
"checkClosed",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Make sure all t... | // Prepare creates a container and ensures the image is pulled.
//
// If the container has already be created, exec.ErrTaskPrepared is returned. | [
"Prepare",
"creates",
"a",
"container",
"and",
"ensures",
"the",
"image",
"is",
"pulled",
".",
"If",
"the",
"container",
"has",
"already",
"be",
"created",
"exec",
".",
"ErrTaskPrepared",
"is",
"returned",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/exec/dockerapi/controller.go#L95-L160 | train |
docker/swarmkit | api/deepcopy/copy.go | Copy | func Copy(dst, src interface{}) {
switch dst := dst.(type) {
case *types.Any:
src := src.(*types.Any)
dst.TypeUrl = src.TypeUrl
if src.Value != nil {
dst.Value = make([]byte, len(src.Value))
copy(dst.Value, src.Value)
} else {
dst.Value = nil
}
case *types.Duration:
src := src.(*types.Duration)
... | go | func Copy(dst, src interface{}) {
switch dst := dst.(type) {
case *types.Any:
src := src.(*types.Any)
dst.TypeUrl = src.TypeUrl
if src.Value != nil {
dst.Value = make([]byte, len(src.Value))
copy(dst.Value, src.Value)
} else {
dst.Value = nil
}
case *types.Duration:
src := src.(*types.Duration)
... | [
"func",
"Copy",
"(",
"dst",
",",
"src",
"interface",
"{",
"}",
")",
"{",
"switch",
"dst",
":=",
"dst",
".",
"(",
"type",
")",
"{",
"case",
"*",
"types",
".",
"Any",
":",
"src",
":=",
"src",
".",
"(",
"*",
"types",
".",
"Any",
")",
"\n",
"dst"... | // Copy copies src into dst. dst and src must have the same type.
//
// If the type has a copy function defined, it will be used.
//
// Default implementations for builtin types and well known protobuf types may
// be provided.
//
// If the copy cannot be performed, this function will panic. Make sure to test
// types ... | [
"Copy",
"copies",
"src",
"into",
"dst",
".",
"dst",
"and",
"src",
"must",
"have",
"the",
"same",
"type",
".",
"If",
"the",
"type",
"has",
"a",
"copy",
"function",
"defined",
"it",
"will",
"be",
"used",
".",
"Default",
"implementations",
"for",
"builtin",... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/api/deepcopy/copy.go#L27-L59 | train |
docker/swarmkit | cmd/swarmctl/network/common.go | GetNetwork | func GetNetwork(ctx context.Context, c api.ControlClient, input string) (*api.Network, error) {
// GetService to match via full ID.
rg, err := c.GetNetwork(ctx, &api.GetNetworkRequest{NetworkID: input})
if err != nil {
// If any error (including NotFound), ListServices to match via full name.
rl, err := c.ListNe... | go | func GetNetwork(ctx context.Context, c api.ControlClient, input string) (*api.Network, error) {
// GetService to match via full ID.
rg, err := c.GetNetwork(ctx, &api.GetNetworkRequest{NetworkID: input})
if err != nil {
// If any error (including NotFound), ListServices to match via full name.
rl, err := c.ListNe... | [
"func",
"GetNetwork",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"api",
".",
"ControlClient",
",",
"input",
"string",
")",
"(",
"*",
"api",
".",
"Network",
",",
"error",
")",
"{",
"// GetService to match via full ID.",
"rg",
",",
"err",
":=",
"c",
... | // GetNetwork tries to query for a network as an ID and if it can't be
// found tries to query as a name. If the name query returns exactly
// one entry then it is returned to the caller. Otherwise an error is
// returned. | [
"GetNetwork",
"tries",
"to",
"query",
"for",
"a",
"network",
"as",
"an",
"ID",
"and",
"if",
"it",
"can",
"t",
"be",
"found",
"tries",
"to",
"query",
"as",
"a",
"name",
".",
"If",
"the",
"name",
"query",
"returns",
"exactly",
"one",
"entry",
"then",
"... | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/cmd/swarmctl/network/common.go#L14-L42 | train |
docker/swarmkit | cmd/swarmctl/network/common.go | ResolveServiceNetworks | func ResolveServiceNetworks(ctx context.Context, c api.ControlClient, spec *api.ServiceSpec) error {
if len(spec.Task.Networks) == 0 {
return nil
}
networks := make([]*api.NetworkAttachmentConfig, 0, len(spec.Task.Networks))
for _, na := range spec.Task.Networks {
n, err := GetNetwork(ctx, c, na.Target)
if er... | go | func ResolveServiceNetworks(ctx context.Context, c api.ControlClient, spec *api.ServiceSpec) error {
if len(spec.Task.Networks) == 0 {
return nil
}
networks := make([]*api.NetworkAttachmentConfig, 0, len(spec.Task.Networks))
for _, na := range spec.Task.Networks {
n, err := GetNetwork(ctx, c, na.Target)
if er... | [
"func",
"ResolveServiceNetworks",
"(",
"ctx",
"context",
".",
"Context",
",",
"c",
"api",
".",
"ControlClient",
",",
"spec",
"*",
"api",
".",
"ServiceSpec",
")",
"error",
"{",
"if",
"len",
"(",
"spec",
".",
"Task",
".",
"Networks",
")",
"==",
"0",
"{",... | // ResolveServiceNetworks takes a service spec and resolves network names to network IDs. | [
"ResolveServiceNetworks",
"takes",
"a",
"service",
"spec",
"and",
"resolves",
"network",
"names",
"to",
"network",
"IDs",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/cmd/swarmctl/network/common.go#L45-L63 | train |
docker/swarmkit | agent/helpers.go | runctx | func runctx(ctx context.Context, closed chan struct{}, errs chan error, fn func(ctx context.Context) error) {
select {
case errs <- fn(ctx):
case <-closed:
case <-ctx.Done():
}
} | go | func runctx(ctx context.Context, closed chan struct{}, errs chan error, fn func(ctx context.Context) error) {
select {
case errs <- fn(ctx):
case <-closed:
case <-ctx.Done():
}
} | [
"func",
"runctx",
"(",
"ctx",
"context",
".",
"Context",
",",
"closed",
"chan",
"struct",
"{",
"}",
",",
"errs",
"chan",
"error",
",",
"fn",
"func",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
")",
"{",
"select",
"{",
"case",
"errs",
"<-",
... | // runctx blocks until the function exits, closed is closed, or the context is
// cancelled. Call as part of go statement. | [
"runctx",
"blocks",
"until",
"the",
"function",
"exits",
"closed",
"is",
"closed",
"or",
"the",
"context",
"is",
"cancelled",
".",
"Call",
"as",
"part",
"of",
"go",
"statement",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/helpers.go#L7-L13 | train |
docker/swarmkit | manager/state/store/tasks.go | CreateTask | func CreateTask(tx Tx, t *api.Task) error {
return tx.create(tableTask, t)
} | go | func CreateTask(tx Tx, t *api.Task) error {
return tx.create(tableTask, t)
} | [
"func",
"CreateTask",
"(",
"tx",
"Tx",
",",
"t",
"*",
"api",
".",
"Task",
")",
"error",
"{",
"return",
"tx",
".",
"create",
"(",
"tableTask",
",",
"t",
")",
"\n",
"}"
] | // CreateTask adds a new task to the store.
// Returns ErrExist if the ID is already taken. | [
"CreateTask",
"adds",
"a",
"new",
"task",
"to",
"the",
"store",
".",
"Returns",
"ErrExist",
"if",
"the",
"ID",
"is",
"already",
"taken",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/tasks.go#L111-L113 | train |
docker/swarmkit | manager/state/store/tasks.go | UpdateTask | func UpdateTask(tx Tx, t *api.Task) error {
return tx.update(tableTask, t)
} | go | func UpdateTask(tx Tx, t *api.Task) error {
return tx.update(tableTask, t)
} | [
"func",
"UpdateTask",
"(",
"tx",
"Tx",
",",
"t",
"*",
"api",
".",
"Task",
")",
"error",
"{",
"return",
"tx",
".",
"update",
"(",
"tableTask",
",",
"t",
")",
"\n",
"}"
] | // UpdateTask updates an existing task in the store.
// Returns ErrNotExist if the node doesn't exist. | [
"UpdateTask",
"updates",
"an",
"existing",
"task",
"in",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"node",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/tasks.go#L117-L119 | train |
docker/swarmkit | manager/state/store/tasks.go | DeleteTask | func DeleteTask(tx Tx, id string) error {
return tx.delete(tableTask, id)
} | go | func DeleteTask(tx Tx, id string) error {
return tx.delete(tableTask, id)
} | [
"func",
"DeleteTask",
"(",
"tx",
"Tx",
",",
"id",
"string",
")",
"error",
"{",
"return",
"tx",
".",
"delete",
"(",
"tableTask",
",",
"id",
")",
"\n",
"}"
] | // DeleteTask removes a task from the store.
// Returns ErrNotExist if the task doesn't exist. | [
"DeleteTask",
"removes",
"a",
"task",
"from",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"task",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/tasks.go#L123-L125 | train |
docker/swarmkit | manager/state/store/tasks.go | GetTask | func GetTask(tx ReadTx, id string) *api.Task {
t := tx.get(tableTask, id)
if t == nil {
return nil
}
return t.(*api.Task)
} | go | func GetTask(tx ReadTx, id string) *api.Task {
t := tx.get(tableTask, id)
if t == nil {
return nil
}
return t.(*api.Task)
} | [
"func",
"GetTask",
"(",
"tx",
"ReadTx",
",",
"id",
"string",
")",
"*",
"api",
".",
"Task",
"{",
"t",
":=",
"tx",
".",
"get",
"(",
"tableTask",
",",
"id",
")",
"\n",
"if",
"t",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"t",
... | // GetTask looks up a task by ID.
// Returns nil if the task doesn't exist. | [
"GetTask",
"looks",
"up",
"a",
"task",
"by",
"ID",
".",
"Returns",
"nil",
"if",
"the",
"task",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/tasks.go#L129-L135 | train |
docker/swarmkit | manager/state/store/tasks.go | FindTasks | func FindTasks(tx ReadTx, by By) ([]*api.Task, error) {
checkType := func(by By) error {
switch by.(type) {
case byName, byNamePrefix, byIDPrefix, byRuntime, byDesiredState, byTaskState, byNode, byService, bySlot, byReferencedNetworkID, byReferencedSecretID, byReferencedConfigID, byCustom, byCustomPrefix:
retur... | go | func FindTasks(tx ReadTx, by By) ([]*api.Task, error) {
checkType := func(by By) error {
switch by.(type) {
case byName, byNamePrefix, byIDPrefix, byRuntime, byDesiredState, byTaskState, byNode, byService, bySlot, byReferencedNetworkID, byReferencedSecretID, byReferencedConfigID, byCustom, byCustomPrefix:
retur... | [
"func",
"FindTasks",
"(",
"tx",
"ReadTx",
",",
"by",
"By",
")",
"(",
"[",
"]",
"*",
"api",
".",
"Task",
",",
"error",
")",
"{",
"checkType",
":=",
"func",
"(",
"by",
"By",
")",
"error",
"{",
"switch",
"by",
".",
"(",
"type",
")",
"{",
"case",
... | // FindTasks selects a set of tasks and returns them. | [
"FindTasks",
"selects",
"a",
"set",
"of",
"tasks",
"and",
"returns",
"them",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/tasks.go#L138-L155 | train |
docker/swarmkit | integration/node.go | Pause | func (n *testNode) Pause(forceNewCluster bool) error {
rAddr, err := n.node.RemoteAPIAddr()
if err != nil {
rAddr = "127.0.0.1:0"
}
if err := n.stop(); err != nil {
return err
}
cfg := n.config
cfg.ListenRemoteAPI = rAddr
// If JoinAddr is set, the node will connect to the join addr and ignore any
// oth... | go | func (n *testNode) Pause(forceNewCluster bool) error {
rAddr, err := n.node.RemoteAPIAddr()
if err != nil {
rAddr = "127.0.0.1:0"
}
if err := n.stop(); err != nil {
return err
}
cfg := n.config
cfg.ListenRemoteAPI = rAddr
// If JoinAddr is set, the node will connect to the join addr and ignore any
// oth... | [
"func",
"(",
"n",
"*",
"testNode",
")",
"Pause",
"(",
"forceNewCluster",
"bool",
")",
"error",
"{",
"rAddr",
",",
"err",
":=",
"n",
".",
"node",
".",
"RemoteAPIAddr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"rAddr",
"=",
"\"",
"\"",
"\n",
... | // Pause stops the node, and creates a new swarm node while keeping all the state | [
"Pause",
"stops",
"the",
"node",
"and",
"creates",
"a",
"new",
"swarm",
"node",
"while",
"keeping",
"all",
"the",
"state"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/integration/node.go#L88-L112 | train |
docker/swarmkit | integration/node.go | Stop | func (n *testNode) Stop() error {
if err := n.stop(); err != nil {
return err
}
return os.RemoveAll(n.stateDir)
} | go | func (n *testNode) Stop() error {
if err := n.stop(); err != nil {
return err
}
return os.RemoveAll(n.stateDir)
} | [
"func",
"(",
"n",
"*",
"testNode",
")",
"Stop",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"n",
".",
"stop",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"os",
".",
"RemoveAll",
"(",
"n",
".",
"stateDir",
... | // Stop stops the node and removes its state directory. | [
"Stop",
"stops",
"the",
"node",
"and",
"removes",
"its",
"state",
"directory",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/integration/node.go#L146-L151 | train |
docker/swarmkit | integration/node.go | ControlClient | func (n *testNode) ControlClient(ctx context.Context) (api.ControlClient, error) {
ctx, cancel := context.WithTimeout(ctx, opsTimeout)
defer cancel()
connChan := n.node.ListenControlSocket(ctx)
var controlConn *grpc.ClientConn
if err := testutils.PollFuncWithTimeout(nil, func() error {
select {
case controlCon... | go | func (n *testNode) ControlClient(ctx context.Context) (api.ControlClient, error) {
ctx, cancel := context.WithTimeout(ctx, opsTimeout)
defer cancel()
connChan := n.node.ListenControlSocket(ctx)
var controlConn *grpc.ClientConn
if err := testutils.PollFuncWithTimeout(nil, func() error {
select {
case controlCon... | [
"func",
"(",
"n",
"*",
"testNode",
")",
"ControlClient",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"api",
".",
"ControlClient",
",",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"ctx",
",",
"opsTimeout",
")"... | // ControlClient returns grpc client to ControlAPI of node. It will panic for
// non-manager nodes. | [
"ControlClient",
"returns",
"grpc",
"client",
"to",
"ControlAPI",
"of",
"node",
".",
"It",
"will",
"panic",
"for",
"non",
"-",
"manager",
"nodes",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/integration/node.go#L155-L173 | train |
docker/swarmkit | manager/orchestrator/task.go | NewTask | func NewTask(cluster *api.Cluster, service *api.Service, slot uint64, nodeID string) *api.Task {
var logDriver *api.Driver
if service.Spec.Task.LogDriver != nil {
// use the log driver specific to the task, if we have it.
logDriver = service.Spec.Task.LogDriver
} else if cluster != nil {
// pick up the cluster... | go | func NewTask(cluster *api.Cluster, service *api.Service, slot uint64, nodeID string) *api.Task {
var logDriver *api.Driver
if service.Spec.Task.LogDriver != nil {
// use the log driver specific to the task, if we have it.
logDriver = service.Spec.Task.LogDriver
} else if cluster != nil {
// pick up the cluster... | [
"func",
"NewTask",
"(",
"cluster",
"*",
"api",
".",
"Cluster",
",",
"service",
"*",
"api",
".",
"Service",
",",
"slot",
"uint64",
",",
"nodeID",
"string",
")",
"*",
"api",
".",
"Task",
"{",
"var",
"logDriver",
"*",
"api",
".",
"Driver",
"\n",
"if",
... | // NewTask creates a new task. | [
"NewTask",
"creates",
"a",
"new",
"task",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/task.go#L16-L52 | train |
docker/swarmkit | manager/orchestrator/task.go | RestartCondition | func RestartCondition(task *api.Task) api.RestartPolicy_RestartCondition {
restartCondition := defaults.Service.Task.Restart.Condition
if task.Spec.Restart != nil {
restartCondition = task.Spec.Restart.Condition
}
return restartCondition
} | go | func RestartCondition(task *api.Task) api.RestartPolicy_RestartCondition {
restartCondition := defaults.Service.Task.Restart.Condition
if task.Spec.Restart != nil {
restartCondition = task.Spec.Restart.Condition
}
return restartCondition
} | [
"func",
"RestartCondition",
"(",
"task",
"*",
"api",
".",
"Task",
")",
"api",
".",
"RestartPolicy_RestartCondition",
"{",
"restartCondition",
":=",
"defaults",
".",
"Service",
".",
"Task",
".",
"Restart",
".",
"Condition",
"\n",
"if",
"task",
".",
"Spec",
".... | // RestartCondition returns the restart condition to apply to this task. | [
"RestartCondition",
"returns",
"the",
"restart",
"condition",
"to",
"apply",
"to",
"this",
"task",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/task.go#L55-L61 | train |
docker/swarmkit | manager/orchestrator/task.go | nodeMatches | func nodeMatches(s *api.Service, n *api.Node) bool {
if n == nil {
return false
}
constraints, _ := constraint.Parse(s.Spec.Task.Placement.Constraints)
return constraint.NodeMatches(constraints, n)
} | go | func nodeMatches(s *api.Service, n *api.Node) bool {
if n == nil {
return false
}
constraints, _ := constraint.Parse(s.Spec.Task.Placement.Constraints)
return constraint.NodeMatches(constraints, n)
} | [
"func",
"nodeMatches",
"(",
"s",
"*",
"api",
".",
"Service",
",",
"n",
"*",
"api",
".",
"Node",
")",
"bool",
"{",
"if",
"n",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"constraints",
",",
"_",
":=",
"constraint",
".",
"Parse",
"(",
"... | // Checks if the current assigned node matches the Placement.Constraints
// specified in the task spec for Updater.newService. | [
"Checks",
"if",
"the",
"current",
"assigned",
"node",
"matches",
"the",
"Placement",
".",
"Constraints",
"specified",
"in",
"the",
"task",
"spec",
"for",
"Updater",
".",
"newService",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/task.go#L117-L124 | train |
docker/swarmkit | manager/orchestrator/task.go | IsTaskDirtyPlacementConstraintsOnly | func IsTaskDirtyPlacementConstraintsOnly(serviceTaskSpec api.TaskSpec, t *api.Task) bool {
// Compare the task placement constraints.
if reflect.DeepEqual(serviceTaskSpec.Placement, t.Spec.Placement) {
return false
}
// Update spec placement to only the fields
// other than the placement constraints in the spec... | go | func IsTaskDirtyPlacementConstraintsOnly(serviceTaskSpec api.TaskSpec, t *api.Task) bool {
// Compare the task placement constraints.
if reflect.DeepEqual(serviceTaskSpec.Placement, t.Spec.Placement) {
return false
}
// Update spec placement to only the fields
// other than the placement constraints in the spec... | [
"func",
"IsTaskDirtyPlacementConstraintsOnly",
"(",
"serviceTaskSpec",
"api",
".",
"TaskSpec",
",",
"t",
"*",
"api",
".",
"Task",
")",
"bool",
"{",
"// Compare the task placement constraints.",
"if",
"reflect",
".",
"DeepEqual",
"(",
"serviceTaskSpec",
".",
"Placement... | // IsTaskDirtyPlacementConstraintsOnly checks if the Placement field alone
// in the spec has changed. | [
"IsTaskDirtyPlacementConstraintsOnly",
"checks",
"if",
"the",
"Placement",
"field",
"alone",
"in",
"the",
"spec",
"has",
"changed",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/task.go#L128-L138 | train |
docker/swarmkit | manager/orchestrator/task.go | InvalidNode | func InvalidNode(n *api.Node) bool {
return n == nil ||
n.Status.State == api.NodeStatus_DOWN ||
n.Spec.Availability == api.NodeAvailabilityDrain
} | go | func InvalidNode(n *api.Node) bool {
return n == nil ||
n.Status.State == api.NodeStatus_DOWN ||
n.Spec.Availability == api.NodeAvailabilityDrain
} | [
"func",
"InvalidNode",
"(",
"n",
"*",
"api",
".",
"Node",
")",
"bool",
"{",
"return",
"n",
"==",
"nil",
"||",
"n",
".",
"Status",
".",
"State",
"==",
"api",
".",
"NodeStatus_DOWN",
"||",
"n",
".",
"Spec",
".",
"Availability",
"==",
"api",
".",
"Nod... | // InvalidNode is true if the node is nil, down, or drained | [
"InvalidNode",
"is",
"true",
"if",
"the",
"node",
"is",
"nil",
"down",
"or",
"drained"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/task.go#L141-L145 | train |
docker/swarmkit | manager/orchestrator/task.go | Swap | func (t TasksByTimestamp) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
} | go | func (t TasksByTimestamp) Swap(i, j int) {
t[i], t[j] = t[j], t[i]
} | [
"func",
"(",
"t",
"TasksByTimestamp",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"t",
"[",
"i",
"]",
",",
"t",
"[",
"j",
"]",
"=",
"t",
"[",
"j",
"]",
",",
"t",
"[",
"i",
"]",
"\n",
"}"
] | // Swap implements the Swap method for sorting. | [
"Swap",
"implements",
"the",
"Swap",
"method",
"for",
"sorting",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/task.go#L165-L167 | train |
docker/swarmkit | manager/orchestrator/task.go | Less | func (t TasksByTimestamp) Less(i, j int) bool {
iTimestamp := taskTimestamp(t[i])
jTimestamp := taskTimestamp(t[j])
if iTimestamp == nil {
return true
}
if jTimestamp == nil {
return false
}
if iTimestamp.Seconds < jTimestamp.Seconds {
return true
}
if iTimestamp.Seconds > jTimestamp.Seconds {
return ... | go | func (t TasksByTimestamp) Less(i, j int) bool {
iTimestamp := taskTimestamp(t[i])
jTimestamp := taskTimestamp(t[j])
if iTimestamp == nil {
return true
}
if jTimestamp == nil {
return false
}
if iTimestamp.Seconds < jTimestamp.Seconds {
return true
}
if iTimestamp.Seconds > jTimestamp.Seconds {
return ... | [
"func",
"(",
"t",
"TasksByTimestamp",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"iTimestamp",
":=",
"taskTimestamp",
"(",
"t",
"[",
"i",
"]",
")",
"\n",
"jTimestamp",
":=",
"taskTimestamp",
"(",
"t",
"[",
"j",
"]",
")",
"\n\n",
"if"... | // Less implements the Less method for sorting. | [
"Less",
"implements",
"the",
"Less",
"method",
"for",
"sorting",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/orchestrator/task.go#L170-L187 | train |
docker/swarmkit | watch/sinks.go | NewChannelSink | func (s *TimeoutDropErrChanGen) NewChannelSink() (events.Sink, *events.Channel) {
ch := events.NewChannel(0)
return timeoutSink{
timeout: s.timeout,
sink: dropErrClosed{
sink: ch,
},
}, ch
} | go | func (s *TimeoutDropErrChanGen) NewChannelSink() (events.Sink, *events.Channel) {
ch := events.NewChannel(0)
return timeoutSink{
timeout: s.timeout,
sink: dropErrClosed{
sink: ch,
},
}, ch
} | [
"func",
"(",
"s",
"*",
"TimeoutDropErrChanGen",
")",
"NewChannelSink",
"(",
")",
"(",
"events",
".",
"Sink",
",",
"*",
"events",
".",
"Channel",
")",
"{",
"ch",
":=",
"events",
".",
"NewChannel",
"(",
"0",
")",
"\n",
"return",
"timeoutSink",
"{",
"time... | // NewChannelSink creates a new sink chain of timeoutSink->dropErrClosed->Channel | [
"NewChannelSink",
"creates",
"a",
"new",
"sink",
"chain",
"of",
"timeoutSink",
"-",
">",
"dropErrClosed",
"-",
">",
"Channel"
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/watch/sinks.go#L81-L89 | train |
docker/swarmkit | manager/state/store/networks.go | CreateNetwork | func CreateNetwork(tx Tx, n *api.Network) error {
// Ensure the name is not already in use.
if tx.lookup(tableNetwork, indexName, strings.ToLower(n.Spec.Annotations.Name)) != nil {
return ErrNameConflict
}
return tx.create(tableNetwork, n)
} | go | func CreateNetwork(tx Tx, n *api.Network) error {
// Ensure the name is not already in use.
if tx.lookup(tableNetwork, indexName, strings.ToLower(n.Spec.Annotations.Name)) != nil {
return ErrNameConflict
}
return tx.create(tableNetwork, n)
} | [
"func",
"CreateNetwork",
"(",
"tx",
"Tx",
",",
"n",
"*",
"api",
".",
"Network",
")",
"error",
"{",
"// Ensure the name is not already in use.",
"if",
"tx",
".",
"lookup",
"(",
"tableNetwork",
",",
"indexName",
",",
"strings",
".",
"ToLower",
"(",
"n",
".",
... | // CreateNetwork adds a new network to the store.
// Returns ErrExist if the ID is already taken. | [
"CreateNetwork",
"adds",
"a",
"new",
"network",
"to",
"the",
"store",
".",
"Returns",
"ErrExist",
"if",
"the",
"ID",
"is",
"already",
"taken",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/networks.go#L66-L73 | train |
docker/swarmkit | manager/state/store/networks.go | UpdateNetwork | func UpdateNetwork(tx Tx, n *api.Network) error {
// Ensure the name is either not in use or already used by this same Network.
if existing := tx.lookup(tableNetwork, indexName, strings.ToLower(n.Spec.Annotations.Name)); existing != nil {
if existing.GetID() != n.ID {
return ErrNameConflict
}
}
return tx.up... | go | func UpdateNetwork(tx Tx, n *api.Network) error {
// Ensure the name is either not in use or already used by this same Network.
if existing := tx.lookup(tableNetwork, indexName, strings.ToLower(n.Spec.Annotations.Name)); existing != nil {
if existing.GetID() != n.ID {
return ErrNameConflict
}
}
return tx.up... | [
"func",
"UpdateNetwork",
"(",
"tx",
"Tx",
",",
"n",
"*",
"api",
".",
"Network",
")",
"error",
"{",
"// Ensure the name is either not in use or already used by this same Network.",
"if",
"existing",
":=",
"tx",
".",
"lookup",
"(",
"tableNetwork",
",",
"indexName",
",... | // UpdateNetwork updates an existing network in the store.
// Returns ErrNotExist if the network doesn't exist. | [
"UpdateNetwork",
"updates",
"an",
"existing",
"network",
"in",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"network",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/networks.go#L77-L86 | train |
docker/swarmkit | manager/state/store/networks.go | DeleteNetwork | func DeleteNetwork(tx Tx, id string) error {
return tx.delete(tableNetwork, id)
} | go | func DeleteNetwork(tx Tx, id string) error {
return tx.delete(tableNetwork, id)
} | [
"func",
"DeleteNetwork",
"(",
"tx",
"Tx",
",",
"id",
"string",
")",
"error",
"{",
"return",
"tx",
".",
"delete",
"(",
"tableNetwork",
",",
"id",
")",
"\n",
"}"
] | // DeleteNetwork removes a network from the store.
// Returns ErrNotExist if the network doesn't exist. | [
"DeleteNetwork",
"removes",
"a",
"network",
"from",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"network",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/networks.go#L90-L92 | train |
docker/swarmkit | manager/state/store/networks.go | GetNetwork | func GetNetwork(tx ReadTx, id string) *api.Network {
n := tx.get(tableNetwork, id)
if n == nil {
return nil
}
return n.(*api.Network)
} | go | func GetNetwork(tx ReadTx, id string) *api.Network {
n := tx.get(tableNetwork, id)
if n == nil {
return nil
}
return n.(*api.Network)
} | [
"func",
"GetNetwork",
"(",
"tx",
"ReadTx",
",",
"id",
"string",
")",
"*",
"api",
".",
"Network",
"{",
"n",
":=",
"tx",
".",
"get",
"(",
"tableNetwork",
",",
"id",
")",
"\n",
"if",
"n",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",... | // GetNetwork looks up a network by ID.
// Returns nil if the network doesn't exist. | [
"GetNetwork",
"looks",
"up",
"a",
"network",
"by",
"ID",
".",
"Returns",
"nil",
"if",
"the",
"network",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/networks.go#L96-L102 | train |
docker/swarmkit | manager/state/store/networks.go | FindNetworks | func FindNetworks(tx ReadTx, by By) ([]*api.Network, error) {
checkType := func(by By) error {
switch by.(type) {
case byName, byNamePrefix, byIDPrefix, byCustom, byCustomPrefix, byAll:
return nil
default:
return ErrInvalidFindBy
}
}
networkList := []*api.Network{}
appendResult := func(o api.StoreObj... | go | func FindNetworks(tx ReadTx, by By) ([]*api.Network, error) {
checkType := func(by By) error {
switch by.(type) {
case byName, byNamePrefix, byIDPrefix, byCustom, byCustomPrefix, byAll:
return nil
default:
return ErrInvalidFindBy
}
}
networkList := []*api.Network{}
appendResult := func(o api.StoreObj... | [
"func",
"FindNetworks",
"(",
"tx",
"ReadTx",
",",
"by",
"By",
")",
"(",
"[",
"]",
"*",
"api",
".",
"Network",
",",
"error",
")",
"{",
"checkType",
":=",
"func",
"(",
"by",
"By",
")",
"error",
"{",
"switch",
"by",
".",
"(",
"type",
")",
"{",
"ca... | // FindNetworks selects a set of networks and returns them. | [
"FindNetworks",
"selects",
"a",
"set",
"of",
"networks",
"and",
"returns",
"them",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/networks.go#L105-L122 | train |
docker/swarmkit | agent/resource.go | AttachNetwork | func (r *resourceAllocator) AttachNetwork(ctx context.Context, id, target string, addresses []string) (string, error) {
var taskID string
if err := r.agent.withSession(ctx, func(session *session) error {
client := api.NewResourceAllocatorClient(session.conn.ClientConn)
r, err := client.AttachNetwork(ctx, &api.Att... | go | func (r *resourceAllocator) AttachNetwork(ctx context.Context, id, target string, addresses []string) (string, error) {
var taskID string
if err := r.agent.withSession(ctx, func(session *session) error {
client := api.NewResourceAllocatorClient(session.conn.ClientConn)
r, err := client.AttachNetwork(ctx, &api.Att... | [
"func",
"(",
"r",
"*",
"resourceAllocator",
")",
"AttachNetwork",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
",",
"target",
"string",
",",
"addresses",
"[",
"]",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"taskID",
"string",
"\... | // AttachNetwork creates a network attachment. | [
"AttachNetwork",
"creates",
"a",
"network",
"attachment",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/resource.go#L31-L52 | train |
docker/swarmkit | agent/resource.go | DetachNetwork | func (r *resourceAllocator) DetachNetwork(ctx context.Context, aID string) error {
return r.agent.withSession(ctx, func(session *session) error {
client := api.NewResourceAllocatorClient(session.conn.ClientConn)
_, err := client.DetachNetwork(ctx, &api.DetachNetworkRequest{
AttachmentID: aID,
})
return err... | go | func (r *resourceAllocator) DetachNetwork(ctx context.Context, aID string) error {
return r.agent.withSession(ctx, func(session *session) error {
client := api.NewResourceAllocatorClient(session.conn.ClientConn)
_, err := client.DetachNetwork(ctx, &api.DetachNetworkRequest{
AttachmentID: aID,
})
return err... | [
"func",
"(",
"r",
"*",
"resourceAllocator",
")",
"DetachNetwork",
"(",
"ctx",
"context",
".",
"Context",
",",
"aID",
"string",
")",
"error",
"{",
"return",
"r",
".",
"agent",
".",
"withSession",
"(",
"ctx",
",",
"func",
"(",
"session",
"*",
"session",
... | // DetachNetwork deletes a network attachment. | [
"DetachNetwork",
"deletes",
"a",
"network",
"attachment",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/agent/resource.go#L55-L64 | train |
docker/swarmkit | manager/state/store/secrets.go | CreateSecret | func CreateSecret(tx Tx, s *api.Secret) error {
// Ensure the name is not already in use.
if tx.lookup(tableSecret, indexName, strings.ToLower(s.Spec.Annotations.Name)) != nil {
return ErrNameConflict
}
return tx.create(tableSecret, s)
} | go | func CreateSecret(tx Tx, s *api.Secret) error {
// Ensure the name is not already in use.
if tx.lookup(tableSecret, indexName, strings.ToLower(s.Spec.Annotations.Name)) != nil {
return ErrNameConflict
}
return tx.create(tableSecret, s)
} | [
"func",
"CreateSecret",
"(",
"tx",
"Tx",
",",
"s",
"*",
"api",
".",
"Secret",
")",
"error",
"{",
"// Ensure the name is not already in use.",
"if",
"tx",
".",
"lookup",
"(",
"tableSecret",
",",
"indexName",
",",
"strings",
".",
"ToLower",
"(",
"s",
".",
"S... | // CreateSecret adds a new secret to the store.
// Returns ErrExist if the ID is already taken. | [
"CreateSecret",
"adds",
"a",
"new",
"secret",
"to",
"the",
"store",
".",
"Returns",
"ErrExist",
"if",
"the",
"ID",
"is",
"already",
"taken",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/secrets.go#L66-L73 | train |
docker/swarmkit | manager/state/store/secrets.go | UpdateSecret | func UpdateSecret(tx Tx, s *api.Secret) error {
// Ensure the name is either not in use or already used by this same Secret.
if existing := tx.lookup(tableSecret, indexName, strings.ToLower(s.Spec.Annotations.Name)); existing != nil {
if existing.GetID() != s.ID {
return ErrNameConflict
}
}
return tx.update... | go | func UpdateSecret(tx Tx, s *api.Secret) error {
// Ensure the name is either not in use or already used by this same Secret.
if existing := tx.lookup(tableSecret, indexName, strings.ToLower(s.Spec.Annotations.Name)); existing != nil {
if existing.GetID() != s.ID {
return ErrNameConflict
}
}
return tx.update... | [
"func",
"UpdateSecret",
"(",
"tx",
"Tx",
",",
"s",
"*",
"api",
".",
"Secret",
")",
"error",
"{",
"// Ensure the name is either not in use or already used by this same Secret.",
"if",
"existing",
":=",
"tx",
".",
"lookup",
"(",
"tableSecret",
",",
"indexName",
",",
... | // UpdateSecret updates an existing secret in the store.
// Returns ErrNotExist if the secret doesn't exist. | [
"UpdateSecret",
"updates",
"an",
"existing",
"secret",
"in",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"secret",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/secrets.go#L77-L86 | train |
docker/swarmkit | manager/state/store/secrets.go | DeleteSecret | func DeleteSecret(tx Tx, id string) error {
return tx.delete(tableSecret, id)
} | go | func DeleteSecret(tx Tx, id string) error {
return tx.delete(tableSecret, id)
} | [
"func",
"DeleteSecret",
"(",
"tx",
"Tx",
",",
"id",
"string",
")",
"error",
"{",
"return",
"tx",
".",
"delete",
"(",
"tableSecret",
",",
"id",
")",
"\n",
"}"
] | // DeleteSecret removes a secret from the store.
// Returns ErrNotExist if the secret doesn't exist. | [
"DeleteSecret",
"removes",
"a",
"secret",
"from",
"the",
"store",
".",
"Returns",
"ErrNotExist",
"if",
"the",
"secret",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/secrets.go#L90-L92 | train |
docker/swarmkit | manager/state/store/secrets.go | GetSecret | func GetSecret(tx ReadTx, id string) *api.Secret {
n := tx.get(tableSecret, id)
if n == nil {
return nil
}
return n.(*api.Secret)
} | go | func GetSecret(tx ReadTx, id string) *api.Secret {
n := tx.get(tableSecret, id)
if n == nil {
return nil
}
return n.(*api.Secret)
} | [
"func",
"GetSecret",
"(",
"tx",
"ReadTx",
",",
"id",
"string",
")",
"*",
"api",
".",
"Secret",
"{",
"n",
":=",
"tx",
".",
"get",
"(",
"tableSecret",
",",
"id",
")",
"\n",
"if",
"n",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
... | // GetSecret looks up a secret by ID.
// Returns nil if the secret doesn't exist. | [
"GetSecret",
"looks",
"up",
"a",
"secret",
"by",
"ID",
".",
"Returns",
"nil",
"if",
"the",
"secret",
"doesn",
"t",
"exist",
"."
] | 59163bf75df38489d4a10392265d27156dc473c5 | https://github.com/docker/swarmkit/blob/59163bf75df38489d4a10392265d27156dc473c5/manager/state/store/secrets.go#L96-L102 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.