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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/scale.go | ScaleSimple | func (scaler *DeploymentScaler) ScaleSimple(namespace, name string, preconditions *ScalePrecondition, newSize uint) error {
deployment, err := scaler.c.Deployments(namespace).Get(name)
if err != nil {
return ScaleError{ScaleGetFailure, "Unknown", err}
}
if preconditions != nil {
if err := preconditions.ValidateDeployment(deployment); err != nil {
return err
}
}
// TODO(madhusudancs): Fix this when Scale group issues are resolved (see issue #18528).
// For now I'm falling back to regular Deployment update operation.
deployment.Spec.Replicas = int(newSize)
if _, err := scaler.c.Deployments(namespace).Update(deployment); err != nil {
if errors.IsInvalid(err) {
return ScaleError{ScaleUpdateInvalidFailure, deployment.ResourceVersion, err}
}
return ScaleError{ScaleUpdateFailure, deployment.ResourceVersion, err}
}
return nil
} | go | func (scaler *DeploymentScaler) ScaleSimple(namespace, name string, preconditions *ScalePrecondition, newSize uint) error {
deployment, err := scaler.c.Deployments(namespace).Get(name)
if err != nil {
return ScaleError{ScaleGetFailure, "Unknown", err}
}
if preconditions != nil {
if err := preconditions.ValidateDeployment(deployment); err != nil {
return err
}
}
// TODO(madhusudancs): Fix this when Scale group issues are resolved (see issue #18528).
// For now I'm falling back to regular Deployment update operation.
deployment.Spec.Replicas = int(newSize)
if _, err := scaler.c.Deployments(namespace).Update(deployment); err != nil {
if errors.IsInvalid(err) {
return ScaleError{ScaleUpdateInvalidFailure, deployment.ResourceVersion, err}
}
return ScaleError{ScaleUpdateFailure, deployment.ResourceVersion, err}
}
return nil
} | [
"func",
"(",
"scaler",
"*",
"DeploymentScaler",
")",
"ScaleSimple",
"(",
"namespace",
",",
"name",
"string",
",",
"preconditions",
"*",
"ScalePrecondition",
",",
"newSize",
"uint",
")",
"error",
"{",
"deployment",
",",
"err",
":=",
"scaler",
".",
"c",
".",
"Deployments",
"(",
"namespace",
")",
".",
"Get",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ScaleError",
"{",
"ScaleGetFailure",
",",
"\"",
"\"",
",",
"err",
"}",
"\n",
"}",
"\n",
"if",
"preconditions",
"!=",
"nil",
"{",
"if",
"err",
":=",
"preconditions",
".",
"ValidateDeployment",
"(",
"deployment",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// TODO(madhusudancs): Fix this when Scale group issues are resolved (see issue #18528).",
"// For now I'm falling back to regular Deployment update operation.",
"deployment",
".",
"Spec",
".",
"Replicas",
"=",
"int",
"(",
"newSize",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"scaler",
".",
"c",
".",
"Deployments",
"(",
"namespace",
")",
".",
"Update",
"(",
"deployment",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"errors",
".",
"IsInvalid",
"(",
"err",
")",
"{",
"return",
"ScaleError",
"{",
"ScaleUpdateInvalidFailure",
",",
"deployment",
".",
"ResourceVersion",
",",
"err",
"}",
"\n",
"}",
"\n",
"return",
"ScaleError",
"{",
"ScaleUpdateFailure",
",",
"deployment",
".",
"ResourceVersion",
",",
"err",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ScaleSimple is responsible for updating a deployment's desired replicas count. | [
"ScaleSimple",
"is",
"responsible",
"for",
"updating",
"a",
"deployment",
"s",
"desired",
"replicas",
"count",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/scale.go#L336-L357 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/conditions.go | ReplicaSetHasDesiredReplicas | func ReplicaSetHasDesiredReplicas(c ExtensionsInterface, replicaSet *extensions.ReplicaSet) wait.ConditionFunc {
// If we're given a ReplicaSet where the status lags the spec, it either means that the
// ReplicaSet is stale, or that the ReplicaSet manager hasn't noticed the update yet.
// Polling status.Replicas is not safe in the latter case.
desiredGeneration := replicaSet.Generation
return func() (bool, error) {
rs, err := c.ReplicaSets(replicaSet.Namespace).Get(replicaSet.Name)
if err != nil {
return false, err
}
// There's a chance a concurrent update modifies the Spec.Replicas causing this check to
// pass, or, after this check has passed, a modification causes the ReplicaSet manager to
// create more pods. This will not be an issue once we've implemented graceful delete for
// ReplicaSets, but till then concurrent stop operations on the same ReplicaSet might have
// unintended side effects.
return rs.Status.ObservedGeneration >= desiredGeneration && rs.Status.Replicas == rs.Spec.Replicas, nil
}
} | go | func ReplicaSetHasDesiredReplicas(c ExtensionsInterface, replicaSet *extensions.ReplicaSet) wait.ConditionFunc {
// If we're given a ReplicaSet where the status lags the spec, it either means that the
// ReplicaSet is stale, or that the ReplicaSet manager hasn't noticed the update yet.
// Polling status.Replicas is not safe in the latter case.
desiredGeneration := replicaSet.Generation
return func() (bool, error) {
rs, err := c.ReplicaSets(replicaSet.Namespace).Get(replicaSet.Name)
if err != nil {
return false, err
}
// There's a chance a concurrent update modifies the Spec.Replicas causing this check to
// pass, or, after this check has passed, a modification causes the ReplicaSet manager to
// create more pods. This will not be an issue once we've implemented graceful delete for
// ReplicaSets, but till then concurrent stop operations on the same ReplicaSet might have
// unintended side effects.
return rs.Status.ObservedGeneration >= desiredGeneration && rs.Status.Replicas == rs.Spec.Replicas, nil
}
} | [
"func",
"ReplicaSetHasDesiredReplicas",
"(",
"c",
"ExtensionsInterface",
",",
"replicaSet",
"*",
"extensions",
".",
"ReplicaSet",
")",
"wait",
".",
"ConditionFunc",
"{",
"// If we're given a ReplicaSet where the status lags the spec, it either means that the",
"// ReplicaSet is stale, or that the ReplicaSet manager hasn't noticed the update yet.",
"// Polling status.Replicas is not safe in the latter case.",
"desiredGeneration",
":=",
"replicaSet",
".",
"Generation",
"\n\n",
"return",
"func",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"rs",
",",
"err",
":=",
"c",
".",
"ReplicaSets",
"(",
"replicaSet",
".",
"Namespace",
")",
".",
"Get",
"(",
"replicaSet",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"// There's a chance a concurrent update modifies the Spec.Replicas causing this check to",
"// pass, or, after this check has passed, a modification causes the ReplicaSet manager to",
"// create more pods. This will not be an issue once we've implemented graceful delete for",
"// ReplicaSets, but till then concurrent stop operations on the same ReplicaSet might have",
"// unintended side effects.",
"return",
"rs",
".",
"Status",
".",
"ObservedGeneration",
">=",
"desiredGeneration",
"&&",
"rs",
".",
"Status",
".",
"Replicas",
"==",
"rs",
".",
"Spec",
".",
"Replicas",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // ReplicaSetHasDesiredReplicas returns a condition that will be true if and only if
// the desired replica count for a ReplicaSet's ReplicaSelector equals the Replicas count. | [
"ReplicaSetHasDesiredReplicas",
"returns",
"a",
"condition",
"that",
"will",
"be",
"true",
"if",
"and",
"only",
"if",
"the",
"desired",
"replica",
"count",
"for",
"a",
"ReplicaSet",
"s",
"ReplicaSelector",
"equals",
"the",
"Replicas",
"count",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/conditions.go#L106-L125 | train |
kubernetes-retired/contrib | exec-healthz/cmd/exechealthz/exechealthz.go | getResults | func (h *execWorker) getResults() execResult {
h.mutex.Lock()
defer h.mutex.Unlock()
return h.result
} | go | func (h *execWorker) getResults() execResult {
h.mutex.Lock()
defer h.mutex.Unlock()
return h.result
} | [
"func",
"(",
"h",
"*",
"execWorker",
")",
"getResults",
"(",
")",
"execResult",
"{",
"h",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"h",
".",
"result",
"\n",
"}"
] | // getResults returns the results of the latest execWorker run.
// The caller should treat returned results as read-only. | [
"getResults",
"returns",
"the",
"results",
"of",
"the",
"latest",
"execWorker",
"run",
".",
"The",
"caller",
"should",
"treat",
"returned",
"results",
"as",
"read",
"-",
"only",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/exec-healthz/cmd/exechealthz/exechealthz.go#L116-L120 | train |
kubernetes-retired/contrib | exec-healthz/cmd/exechealthz/exechealthz.go | start | func (h *execWorker) start() {
ticker := h.clock.Tick(h.period)
h.readyCh <- struct{}{} // For testing.
for {
select {
// If the command takes > period, the command runs continuously.
case <-ticker:
logf("Worker running %v to serve %v", h.probeCmd, h.probePath)
output, err := h.exec.Command("sh", "-c", h.probeCmd).CombinedOutput()
ts := h.clock.Now()
func() {
h.mutex.Lock()
defer h.mutex.Unlock()
h.result = execResult{output, err, ts}
}()
case <-h.stopCh:
return
}
}
} | go | func (h *execWorker) start() {
ticker := h.clock.Tick(h.period)
h.readyCh <- struct{}{} // For testing.
for {
select {
// If the command takes > period, the command runs continuously.
case <-ticker:
logf("Worker running %v to serve %v", h.probeCmd, h.probePath)
output, err := h.exec.Command("sh", "-c", h.probeCmd).CombinedOutput()
ts := h.clock.Now()
func() {
h.mutex.Lock()
defer h.mutex.Unlock()
h.result = execResult{output, err, ts}
}()
case <-h.stopCh:
return
}
}
} | [
"func",
"(",
"h",
"*",
"execWorker",
")",
"start",
"(",
")",
"{",
"ticker",
":=",
"h",
".",
"clock",
".",
"Tick",
"(",
"h",
".",
"period",
")",
"\n",
"h",
".",
"readyCh",
"<-",
"struct",
"{",
"}",
"{",
"}",
"// For testing.",
"\n\n",
"for",
"{",
"select",
"{",
"// If the command takes > period, the command runs continuously.",
"case",
"<-",
"ticker",
":",
"logf",
"(",
"\"",
"\"",
",",
"h",
".",
"probeCmd",
",",
"h",
".",
"probePath",
")",
"\n",
"output",
",",
"err",
":=",
"h",
".",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"h",
".",
"probeCmd",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"ts",
":=",
"h",
".",
"clock",
".",
"Now",
"(",
")",
"\n",
"func",
"(",
")",
"{",
"h",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"h",
".",
"result",
"=",
"execResult",
"{",
"output",
",",
"err",
",",
"ts",
"}",
"\n",
"}",
"(",
")",
"\n",
"case",
"<-",
"h",
".",
"stopCh",
":",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // start attempts to run the probeCmd every `period` seconds.
// Meant to be called as a goroutine. | [
"start",
"attempts",
"to",
"run",
"the",
"probeCmd",
"every",
"period",
"seconds",
".",
"Meant",
"to",
"be",
"called",
"as",
"a",
"goroutine",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/exec-healthz/cmd/exechealthz/exechealthz.go#L131-L151 | train |
kubernetes-retired/contrib | exec-healthz/cmd/exechealthz/exechealthz.go | newExecWorker | func newExecWorker(probeCmd, probePath string, execPeriod time.Duration, exec utilexec.Interface, clock clock.Clock, readyCh chan<- struct{}) *execWorker {
return &execWorker{
// Initializing the result with a timestamp here allows us to
// wait maxLatency for the worker goroutine to start, and for each
// iteration of the worker to complete.
exec: exec,
clock: clock,
result: execResult{[]byte{}, nil, clock.Now()},
period: execPeriod,
probeCmd: probeCmd,
probePath: probePath,
stopCh: make(chan struct{}),
readyCh: readyCh,
}
} | go | func newExecWorker(probeCmd, probePath string, execPeriod time.Duration, exec utilexec.Interface, clock clock.Clock, readyCh chan<- struct{}) *execWorker {
return &execWorker{
// Initializing the result with a timestamp here allows us to
// wait maxLatency for the worker goroutine to start, and for each
// iteration of the worker to complete.
exec: exec,
clock: clock,
result: execResult{[]byte{}, nil, clock.Now()},
period: execPeriod,
probeCmd: probeCmd,
probePath: probePath,
stopCh: make(chan struct{}),
readyCh: readyCh,
}
} | [
"func",
"newExecWorker",
"(",
"probeCmd",
",",
"probePath",
"string",
",",
"execPeriod",
"time",
".",
"Duration",
",",
"exec",
"utilexec",
".",
"Interface",
",",
"clock",
"clock",
".",
"Clock",
",",
"readyCh",
"chan",
"<-",
"struct",
"{",
"}",
")",
"*",
"execWorker",
"{",
"return",
"&",
"execWorker",
"{",
"// Initializing the result with a timestamp here allows us to",
"// wait maxLatency for the worker goroutine to start, and for each",
"// iteration of the worker to complete.",
"exec",
":",
"exec",
",",
"clock",
":",
"clock",
",",
"result",
":",
"execResult",
"{",
"[",
"]",
"byte",
"{",
"}",
",",
"nil",
",",
"clock",
".",
"Now",
"(",
")",
"}",
",",
"period",
":",
"execPeriod",
",",
"probeCmd",
":",
"probeCmd",
",",
"probePath",
":",
"probePath",
",",
"stopCh",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"readyCh",
":",
"readyCh",
",",
"}",
"\n",
"}"
] | // newExecWorker is a constructor for execWorker. | [
"newExecWorker",
"is",
"a",
"constructor",
"for",
"execWorker",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/exec-healthz/cmd/exechealthz/exechealthz.go#L154-L168 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/sorter.go | numLess | func numLess(a, b reflect.Value) bool {
switch a.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return a.Int() < b.Int()
case reflect.Float32, reflect.Float64:
return a.Float() < b.Float()
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return a.Uint() < b.Uint()
case reflect.Bool:
return !a.Bool() && b.Bool()
}
panic("not a number")
} | go | func numLess(a, b reflect.Value) bool {
switch a.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return a.Int() < b.Int()
case reflect.Float32, reflect.Float64:
return a.Float() < b.Float()
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return a.Uint() < b.Uint()
case reflect.Bool:
return !a.Bool() && b.Bool()
}
panic("not a number")
} | [
"func",
"numLess",
"(",
"a",
",",
"b",
"reflect",
".",
"Value",
")",
"bool",
"{",
"switch",
"a",
".",
"Kind",
"(",
")",
"{",
"case",
"reflect",
".",
"Int",
",",
"reflect",
".",
"Int8",
",",
"reflect",
".",
"Int16",
",",
"reflect",
".",
"Int32",
",",
"reflect",
".",
"Int64",
":",
"return",
"a",
".",
"Int",
"(",
")",
"<",
"b",
".",
"Int",
"(",
")",
"\n",
"case",
"reflect",
".",
"Float32",
",",
"reflect",
".",
"Float64",
":",
"return",
"a",
".",
"Float",
"(",
")",
"<",
"b",
".",
"Float",
"(",
")",
"\n",
"case",
"reflect",
".",
"Uint",
",",
"reflect",
".",
"Uint8",
",",
"reflect",
".",
"Uint16",
",",
"reflect",
".",
"Uint32",
",",
"reflect",
".",
"Uint64",
",",
"reflect",
".",
"Uintptr",
":",
"return",
"a",
".",
"Uint",
"(",
")",
"<",
"b",
".",
"Uint",
"(",
")",
"\n",
"case",
"reflect",
".",
"Bool",
":",
"return",
"!",
"a",
".",
"Bool",
"(",
")",
"&&",
"b",
".",
"Bool",
"(",
")",
"\n",
"}",
"\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // numLess returns whether a < b.
// a and b must necessarily have the same kind. | [
"numLess",
"returns",
"whether",
"a",
"<",
"b",
".",
"a",
"and",
"b",
"must",
"necessarily",
"have",
"the",
"same",
"kind",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/sorter.go#L92-L104 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/pods.go | newPods | func newPods(c *Client, namespace string) *pods {
return &pods{
r: c,
ns: namespace,
}
} | go | func newPods(c *Client, namespace string) *pods {
return &pods{
r: c,
ns: namespace,
}
} | [
"func",
"newPods",
"(",
"c",
"*",
"Client",
",",
"namespace",
"string",
")",
"*",
"pods",
"{",
"return",
"&",
"pods",
"{",
"r",
":",
"c",
",",
"ns",
":",
"namespace",
",",
"}",
"\n",
"}"
] | // newPods returns a pods | [
"newPods",
"returns",
"a",
"pods"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/pods.go#L49-L54 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/pods.go | UpdateStatus | func (c *pods) UpdateStatus(pod *api.Pod) (result *api.Pod, err error) {
result = &api.Pod{}
err = c.r.Put().Namespace(c.ns).Resource("pods").Name(pod.Name).SubResource("status").Body(pod).Do().Into(result)
return
} | go | func (c *pods) UpdateStatus(pod *api.Pod) (result *api.Pod, err error) {
result = &api.Pod{}
err = c.r.Put().Namespace(c.ns).Resource("pods").Name(pod.Name).SubResource("status").Body(pod).Do().Into(result)
return
} | [
"func",
"(",
"c",
"*",
"pods",
")",
"UpdateStatus",
"(",
"pod",
"*",
"api",
".",
"Pod",
")",
"(",
"result",
"*",
"api",
".",
"Pod",
",",
"err",
"error",
")",
"{",
"result",
"=",
"&",
"api",
".",
"Pod",
"{",
"}",
"\n",
"err",
"=",
"c",
".",
"r",
".",
"Put",
"(",
")",
".",
"Namespace",
"(",
"c",
".",
"ns",
")",
".",
"Resource",
"(",
"\"",
"\"",
")",
".",
"Name",
"(",
"pod",
".",
"Name",
")",
".",
"SubResource",
"(",
"\"",
"\"",
")",
".",
"Body",
"(",
"pod",
")",
".",
"Do",
"(",
")",
".",
"Into",
"(",
"result",
")",
"\n",
"return",
"\n",
"}"
] | // UpdateStatus takes the name of the pod and the new status. Returns the server's representation of the pod, and an error, if it occurs. | [
"UpdateStatus",
"takes",
"the",
"name",
"of",
"the",
"pod",
"and",
"the",
"new",
"status",
".",
"Returns",
"the",
"server",
"s",
"representation",
"of",
"the",
"pod",
"and",
"an",
"error",
"if",
"it",
"occurs",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/pods.go#L105-L109 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/clientcmd/overrides.go | BindStringFlag | func (f FlagInfo) BindStringFlag(flags *pflag.FlagSet, target *string) {
// you can't register a flag without a long name
if len(f.LongName) > 0 {
flags.StringVarP(target, f.LongName, f.ShortName, f.Default, f.Description)
}
} | go | func (f FlagInfo) BindStringFlag(flags *pflag.FlagSet, target *string) {
// you can't register a flag without a long name
if len(f.LongName) > 0 {
flags.StringVarP(target, f.LongName, f.ShortName, f.Default, f.Description)
}
} | [
"func",
"(",
"f",
"FlagInfo",
")",
"BindStringFlag",
"(",
"flags",
"*",
"pflag",
".",
"FlagSet",
",",
"target",
"*",
"string",
")",
"{",
"// you can't register a flag without a long name",
"if",
"len",
"(",
"f",
".",
"LongName",
")",
">",
"0",
"{",
"flags",
".",
"StringVarP",
"(",
"target",
",",
"f",
".",
"LongName",
",",
"f",
".",
"ShortName",
",",
"f",
".",
"Default",
",",
"f",
".",
"Description",
")",
"\n",
"}",
"\n",
"}"
] | // BindStringFlag binds the flag based on the provided info. If LongName == "", nothing is registered | [
"BindStringFlag",
"binds",
"the",
"flag",
"based",
"on",
"the",
"provided",
"info",
".",
"If",
"LongName",
"==",
"nothing",
"is",
"registered"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/clientcmd/overrides.go#L84-L89 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/clientcmd/overrides.go | RecommendedConfigOverrideFlags | func RecommendedConfigOverrideFlags(prefix string) ConfigOverrideFlags {
return ConfigOverrideFlags{
AuthOverrideFlags: RecommendedAuthOverrideFlags(prefix),
ClusterOverrideFlags: RecommendedClusterOverrideFlags(prefix),
ContextOverrideFlags: RecommendedContextOverrideFlags(prefix),
CurrentContext: FlagInfo{prefix + FlagContext, "", "", "The name of the kubeconfig context to use"},
}
} | go | func RecommendedConfigOverrideFlags(prefix string) ConfigOverrideFlags {
return ConfigOverrideFlags{
AuthOverrideFlags: RecommendedAuthOverrideFlags(prefix),
ClusterOverrideFlags: RecommendedClusterOverrideFlags(prefix),
ContextOverrideFlags: RecommendedContextOverrideFlags(prefix),
CurrentContext: FlagInfo{prefix + FlagContext, "", "", "The name of the kubeconfig context to use"},
}
} | [
"func",
"RecommendedConfigOverrideFlags",
"(",
"prefix",
"string",
")",
"ConfigOverrideFlags",
"{",
"return",
"ConfigOverrideFlags",
"{",
"AuthOverrideFlags",
":",
"RecommendedAuthOverrideFlags",
"(",
"prefix",
")",
",",
"ClusterOverrideFlags",
":",
"RecommendedClusterOverrideFlags",
"(",
"prefix",
")",
",",
"ContextOverrideFlags",
":",
"RecommendedContextOverrideFlags",
"(",
"prefix",
")",
",",
"CurrentContext",
":",
"FlagInfo",
"{",
"prefix",
"+",
"FlagContext",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"}",
"\n",
"}"
] | // RecommendedConfigOverrideFlags is a convenience method to return recommended flag names prefixed with a string of your choosing | [
"RecommendedConfigOverrideFlags",
"is",
"a",
"convenience",
"method",
"to",
"return",
"recommended",
"flag",
"names",
"prefixed",
"with",
"a",
"string",
"of",
"your",
"choosing"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/clientcmd/overrides.go#L144-L151 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/clientcmd/overrides.go | BindClusterFlags | func BindClusterFlags(clusterInfo *clientcmdapi.Cluster, flags *pflag.FlagSet, flagNames ClusterOverrideFlags) {
flagNames.APIServer.BindStringFlag(flags, &clusterInfo.Server)
flagNames.APIVersion.BindStringFlag(flags, &clusterInfo.APIVersion)
flagNames.CertificateAuthority.BindStringFlag(flags, &clusterInfo.CertificateAuthority)
flagNames.InsecureSkipTLSVerify.BindBoolFlag(flags, &clusterInfo.InsecureSkipTLSVerify)
} | go | func BindClusterFlags(clusterInfo *clientcmdapi.Cluster, flags *pflag.FlagSet, flagNames ClusterOverrideFlags) {
flagNames.APIServer.BindStringFlag(flags, &clusterInfo.Server)
flagNames.APIVersion.BindStringFlag(flags, &clusterInfo.APIVersion)
flagNames.CertificateAuthority.BindStringFlag(flags, &clusterInfo.CertificateAuthority)
flagNames.InsecureSkipTLSVerify.BindBoolFlag(flags, &clusterInfo.InsecureSkipTLSVerify)
} | [
"func",
"BindClusterFlags",
"(",
"clusterInfo",
"*",
"clientcmdapi",
".",
"Cluster",
",",
"flags",
"*",
"pflag",
".",
"FlagSet",
",",
"flagNames",
"ClusterOverrideFlags",
")",
"{",
"flagNames",
".",
"APIServer",
".",
"BindStringFlag",
"(",
"flags",
",",
"&",
"clusterInfo",
".",
"Server",
")",
"\n",
"flagNames",
".",
"APIVersion",
".",
"BindStringFlag",
"(",
"flags",
",",
"&",
"clusterInfo",
".",
"APIVersion",
")",
"\n",
"flagNames",
".",
"CertificateAuthority",
".",
"BindStringFlag",
"(",
"flags",
",",
"&",
"clusterInfo",
".",
"CertificateAuthority",
")",
"\n",
"flagNames",
".",
"InsecureSkipTLSVerify",
".",
"BindBoolFlag",
"(",
"flags",
",",
"&",
"clusterInfo",
".",
"InsecureSkipTLSVerify",
")",
"\n",
"}"
] | // BindClusterFlags is a convenience method to bind the specified flags to their associated variables | [
"BindClusterFlags",
"is",
"a",
"convenience",
"method",
"to",
"bind",
"the",
"specified",
"flags",
"to",
"their",
"associated",
"variables"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/clientcmd/overrides.go#L172-L177 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/clientcmd/overrides.go | BindOverrideFlags | func BindOverrideFlags(overrides *ConfigOverrides, flags *pflag.FlagSet, flagNames ConfigOverrideFlags) {
BindAuthInfoFlags(&overrides.AuthInfo, flags, flagNames.AuthOverrideFlags)
BindClusterFlags(&overrides.ClusterInfo, flags, flagNames.ClusterOverrideFlags)
BindContextFlags(&overrides.Context, flags, flagNames.ContextOverrideFlags)
flagNames.CurrentContext.BindStringFlag(flags, &overrides.CurrentContext)
} | go | func BindOverrideFlags(overrides *ConfigOverrides, flags *pflag.FlagSet, flagNames ConfigOverrideFlags) {
BindAuthInfoFlags(&overrides.AuthInfo, flags, flagNames.AuthOverrideFlags)
BindClusterFlags(&overrides.ClusterInfo, flags, flagNames.ClusterOverrideFlags)
BindContextFlags(&overrides.Context, flags, flagNames.ContextOverrideFlags)
flagNames.CurrentContext.BindStringFlag(flags, &overrides.CurrentContext)
} | [
"func",
"BindOverrideFlags",
"(",
"overrides",
"*",
"ConfigOverrides",
",",
"flags",
"*",
"pflag",
".",
"FlagSet",
",",
"flagNames",
"ConfigOverrideFlags",
")",
"{",
"BindAuthInfoFlags",
"(",
"&",
"overrides",
".",
"AuthInfo",
",",
"flags",
",",
"flagNames",
".",
"AuthOverrideFlags",
")",
"\n",
"BindClusterFlags",
"(",
"&",
"overrides",
".",
"ClusterInfo",
",",
"flags",
",",
"flagNames",
".",
"ClusterOverrideFlags",
")",
"\n",
"BindContextFlags",
"(",
"&",
"overrides",
".",
"Context",
",",
"flags",
",",
"flagNames",
".",
"ContextOverrideFlags",
")",
"\n",
"flagNames",
".",
"CurrentContext",
".",
"BindStringFlag",
"(",
"flags",
",",
"&",
"overrides",
".",
"CurrentContext",
")",
"\n",
"}"
] | // BindOverrideFlags is a convenience method to bind the specified flags to their associated variables | [
"BindOverrideFlags",
"is",
"a",
"convenience",
"method",
"to",
"bind",
"the",
"specified",
"flags",
"to",
"their",
"associated",
"variables"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/clientcmd/overrides.go#L180-L185 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/cmd/util/printing.go | PrintSuccess | func PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource string, name string, operation string) {
resource, _ = mapper.ResourceSingularizer(resource)
if shortOutput {
// -o name: prints resource/name
if len(resource) > 0 {
fmt.Fprintf(out, "%s/%s\n", resource, name)
} else {
fmt.Fprintf(out, "%s\n", name)
}
} else {
// understandable output by default
if len(resource) > 0 {
fmt.Fprintf(out, "%s \"%s\" %s\n", resource, name, operation)
} else {
fmt.Fprintf(out, "\"%s\" %s\n", name, operation)
}
}
} | go | func PrintSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource string, name string, operation string) {
resource, _ = mapper.ResourceSingularizer(resource)
if shortOutput {
// -o name: prints resource/name
if len(resource) > 0 {
fmt.Fprintf(out, "%s/%s\n", resource, name)
} else {
fmt.Fprintf(out, "%s\n", name)
}
} else {
// understandable output by default
if len(resource) > 0 {
fmt.Fprintf(out, "%s \"%s\" %s\n", resource, name, operation)
} else {
fmt.Fprintf(out, "\"%s\" %s\n", name, operation)
}
}
} | [
"func",
"PrintSuccess",
"(",
"mapper",
"meta",
".",
"RESTMapper",
",",
"shortOutput",
"bool",
",",
"out",
"io",
".",
"Writer",
",",
"resource",
"string",
",",
"name",
"string",
",",
"operation",
"string",
")",
"{",
"resource",
",",
"_",
"=",
"mapper",
".",
"ResourceSingularizer",
"(",
"resource",
")",
"\n",
"if",
"shortOutput",
"{",
"// -o name: prints resource/name",
"if",
"len",
"(",
"resource",
")",
">",
"0",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\n",
"\"",
",",
"resource",
",",
"name",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\n",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// understandable output by default",
"if",
"len",
"(",
"resource",
")",
">",
"0",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"resource",
",",
"name",
",",
"operation",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\\"",
"\\\"",
"\\n",
"\"",
",",
"name",
",",
"operation",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // PrintSuccess prints message after finishing mutating operations | [
"PrintSuccess",
"prints",
"message",
"after",
"finishing",
"mutating",
"operations"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/cmd/util/printing.go#L51-L68 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/cmd/util/printing.go | ValidateOutputArgs | func ValidateOutputArgs(cmd *cobra.Command) error {
outputMode := GetFlagString(cmd, "output")
if outputMode != "" && outputMode != "name" {
return UsageError(cmd, "Unexpected -o output mode: %v. We only support '-o name'.", outputMode)
}
return nil
} | go | func ValidateOutputArgs(cmd *cobra.Command) error {
outputMode := GetFlagString(cmd, "output")
if outputMode != "" && outputMode != "name" {
return UsageError(cmd, "Unexpected -o output mode: %v. We only support '-o name'.", outputMode)
}
return nil
} | [
"func",
"ValidateOutputArgs",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
")",
"error",
"{",
"outputMode",
":=",
"GetFlagString",
"(",
"cmd",
",",
"\"",
"\"",
")",
"\n",
"if",
"outputMode",
"!=",
"\"",
"\"",
"&&",
"outputMode",
"!=",
"\"",
"\"",
"{",
"return",
"UsageError",
"(",
"cmd",
",",
"\"",
"\"",
",",
"outputMode",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ValidateOutputArgs validates -o flag args for mutations | [
"ValidateOutputArgs",
"validates",
"-",
"o",
"flag",
"args",
"for",
"mutations"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/cmd/util/printing.go#L71-L77 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/discovery_client.go | ServerResources | func (d *DiscoveryClient) ServerResources() (map[string]*unversioned.APIResourceList, error) {
apiGroups, err := d.ServerGroups()
if err != nil {
return nil, err
}
groupVersions := ExtractGroupVersions(apiGroups)
result := map[string]*unversioned.APIResourceList{}
for _, groupVersion := range groupVersions {
resources, err := d.ServerResourcesForGroupVersion(groupVersion)
if err != nil {
return nil, err
}
result[groupVersion] = resources
}
return result, nil
} | go | func (d *DiscoveryClient) ServerResources() (map[string]*unversioned.APIResourceList, error) {
apiGroups, err := d.ServerGroups()
if err != nil {
return nil, err
}
groupVersions := ExtractGroupVersions(apiGroups)
result := map[string]*unversioned.APIResourceList{}
for _, groupVersion := range groupVersions {
resources, err := d.ServerResourcesForGroupVersion(groupVersion)
if err != nil {
return nil, err
}
result[groupVersion] = resources
}
return result, nil
} | [
"func",
"(",
"d",
"*",
"DiscoveryClient",
")",
"ServerResources",
"(",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"unversioned",
".",
"APIResourceList",
",",
"error",
")",
"{",
"apiGroups",
",",
"err",
":=",
"d",
".",
"ServerGroups",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"groupVersions",
":=",
"ExtractGroupVersions",
"(",
"apiGroups",
")",
"\n",
"result",
":=",
"map",
"[",
"string",
"]",
"*",
"unversioned",
".",
"APIResourceList",
"{",
"}",
"\n",
"for",
"_",
",",
"groupVersion",
":=",
"range",
"groupVersions",
"{",
"resources",
",",
"err",
":=",
"d",
".",
"ServerResourcesForGroupVersion",
"(",
"groupVersion",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"result",
"[",
"groupVersion",
"]",
"=",
"resources",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // ServerResources returns the supported resources for all groups and versions. | [
"ServerResources",
"returns",
"the",
"supported",
"resources",
"for",
"all",
"groups",
"and",
"versions",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/discovery_client.go#L124-L139 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/net/context/context.go | propagateCancel | func propagateCancel(parent Context, child canceler) {
if parent.Done() == nil {
return // parent is never canceled
}
if p, ok := parentCancelCtx(parent); ok {
p.mu.Lock()
if p.err != nil {
// parent has already been canceled
child.cancel(false, p.err)
} else {
if p.children == nil {
p.children = make(map[canceler]bool)
}
p.children[child] = true
}
p.mu.Unlock()
} else {
go func() {
select {
case <-parent.Done():
child.cancel(false, parent.Err())
case <-child.Done():
}
}()
}
} | go | func propagateCancel(parent Context, child canceler) {
if parent.Done() == nil {
return // parent is never canceled
}
if p, ok := parentCancelCtx(parent); ok {
p.mu.Lock()
if p.err != nil {
// parent has already been canceled
child.cancel(false, p.err)
} else {
if p.children == nil {
p.children = make(map[canceler]bool)
}
p.children[child] = true
}
p.mu.Unlock()
} else {
go func() {
select {
case <-parent.Done():
child.cancel(false, parent.Err())
case <-child.Done():
}
}()
}
} | [
"func",
"propagateCancel",
"(",
"parent",
"Context",
",",
"child",
"canceler",
")",
"{",
"if",
"parent",
".",
"Done",
"(",
")",
"==",
"nil",
"{",
"return",
"// parent is never canceled",
"\n",
"}",
"\n",
"if",
"p",
",",
"ok",
":=",
"parentCancelCtx",
"(",
"parent",
")",
";",
"ok",
"{",
"p",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"p",
".",
"err",
"!=",
"nil",
"{",
"// parent has already been canceled",
"child",
".",
"cancel",
"(",
"false",
",",
"p",
".",
"err",
")",
"\n",
"}",
"else",
"{",
"if",
"p",
".",
"children",
"==",
"nil",
"{",
"p",
".",
"children",
"=",
"make",
"(",
"map",
"[",
"canceler",
"]",
"bool",
")",
"\n",
"}",
"\n",
"p",
".",
"children",
"[",
"child",
"]",
"=",
"true",
"\n",
"}",
"\n",
"p",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}",
"else",
"{",
"go",
"func",
"(",
")",
"{",
"select",
"{",
"case",
"<-",
"parent",
".",
"Done",
"(",
")",
":",
"child",
".",
"cancel",
"(",
"false",
",",
"parent",
".",
"Err",
"(",
")",
")",
"\n",
"case",
"<-",
"child",
".",
"Done",
"(",
")",
":",
"}",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // propagateCancel arranges for child to be canceled when parent is. | [
"propagateCancel",
"arranges",
"for",
"child",
"to",
"be",
"canceled",
"when",
"parent",
"is",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/net/context/context.go#L226-L251 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/net/context/context.go | removeChild | func removeChild(parent Context, child canceler) {
p, ok := parentCancelCtx(parent)
if !ok {
return
}
p.mu.Lock()
if p.children != nil {
delete(p.children, child)
}
p.mu.Unlock()
} | go | func removeChild(parent Context, child canceler) {
p, ok := parentCancelCtx(parent)
if !ok {
return
}
p.mu.Lock()
if p.children != nil {
delete(p.children, child)
}
p.mu.Unlock()
} | [
"func",
"removeChild",
"(",
"parent",
"Context",
",",
"child",
"canceler",
")",
"{",
"p",
",",
"ok",
":=",
"parentCancelCtx",
"(",
"parent",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"p",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"p",
".",
"children",
"!=",
"nil",
"{",
"delete",
"(",
"p",
".",
"children",
",",
"child",
")",
"\n",
"}",
"\n",
"p",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // removeChild removes a context from its parent. | [
"removeChild",
"removes",
"a",
"context",
"from",
"its",
"parent",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/net/context/context.go#L272-L282 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/net/context/context.go | cancel | func (c *cancelCtx) cancel(removeFromParent bool, err error) {
if err == nil {
panic("context: internal error: missing cancel error")
}
c.mu.Lock()
if c.err != nil {
c.mu.Unlock()
return // already canceled
}
c.err = err
close(c.done)
for child := range c.children {
// NOTE: acquiring the child's lock while holding parent's lock.
child.cancel(false, err)
}
c.children = nil
c.mu.Unlock()
if removeFromParent {
removeChild(c.Context, c)
}
} | go | func (c *cancelCtx) cancel(removeFromParent bool, err error) {
if err == nil {
panic("context: internal error: missing cancel error")
}
c.mu.Lock()
if c.err != nil {
c.mu.Unlock()
return // already canceled
}
c.err = err
close(c.done)
for child := range c.children {
// NOTE: acquiring the child's lock while holding parent's lock.
child.cancel(false, err)
}
c.children = nil
c.mu.Unlock()
if removeFromParent {
removeChild(c.Context, c)
}
} | [
"func",
"(",
"c",
"*",
"cancelCtx",
")",
"cancel",
"(",
"removeFromParent",
"bool",
",",
"err",
"error",
")",
"{",
"if",
"err",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"if",
"c",
".",
"err",
"!=",
"nil",
"{",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"// already canceled",
"\n",
"}",
"\n",
"c",
".",
"err",
"=",
"err",
"\n",
"close",
"(",
"c",
".",
"done",
")",
"\n",
"for",
"child",
":=",
"range",
"c",
".",
"children",
"{",
"// NOTE: acquiring the child's lock while holding parent's lock.",
"child",
".",
"cancel",
"(",
"false",
",",
"err",
")",
"\n",
"}",
"\n",
"c",
".",
"children",
"=",
"nil",
"\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"removeFromParent",
"{",
"removeChild",
"(",
"c",
".",
"Context",
",",
"c",
")",
"\n",
"}",
"\n",
"}"
] | // cancel closes c.done, cancels each of c's children, and, if
// removeFromParent is true, removes c from its parent's children. | [
"cancel",
"closes",
"c",
".",
"done",
"cancels",
"each",
"of",
"c",
"s",
"children",
"and",
"if",
"removeFromParent",
"is",
"true",
"removes",
"c",
"from",
"its",
"parent",
"s",
"children",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/net/context/context.go#L319-L340 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/deployment/deployment.go | GetOldRCs | func GetOldRCs(deployment extensions.Deployment, c client.Interface) ([]*api.ReplicationController, error) {
return GetOldRCsFromLists(deployment, c,
func(namespace string, options api.ListOptions) (*api.PodList, error) {
return c.Pods(namespace).List(options)
},
func(namespace string, options api.ListOptions) ([]api.ReplicationController, error) {
rcList, err := c.ReplicationControllers(namespace).List(options)
return rcList.Items, err
})
} | go | func GetOldRCs(deployment extensions.Deployment, c client.Interface) ([]*api.ReplicationController, error) {
return GetOldRCsFromLists(deployment, c,
func(namespace string, options api.ListOptions) (*api.PodList, error) {
return c.Pods(namespace).List(options)
},
func(namespace string, options api.ListOptions) ([]api.ReplicationController, error) {
rcList, err := c.ReplicationControllers(namespace).List(options)
return rcList.Items, err
})
} | [
"func",
"GetOldRCs",
"(",
"deployment",
"extensions",
".",
"Deployment",
",",
"c",
"client",
".",
"Interface",
")",
"(",
"[",
"]",
"*",
"api",
".",
"ReplicationController",
",",
"error",
")",
"{",
"return",
"GetOldRCsFromLists",
"(",
"deployment",
",",
"c",
",",
"func",
"(",
"namespace",
"string",
",",
"options",
"api",
".",
"ListOptions",
")",
"(",
"*",
"api",
".",
"PodList",
",",
"error",
")",
"{",
"return",
"c",
".",
"Pods",
"(",
"namespace",
")",
".",
"List",
"(",
"options",
")",
"\n",
"}",
",",
"func",
"(",
"namespace",
"string",
",",
"options",
"api",
".",
"ListOptions",
")",
"(",
"[",
"]",
"api",
".",
"ReplicationController",
",",
"error",
")",
"{",
"rcList",
",",
"err",
":=",
"c",
".",
"ReplicationControllers",
"(",
"namespace",
")",
".",
"List",
"(",
"options",
")",
"\n",
"return",
"rcList",
".",
"Items",
",",
"err",
"\n",
"}",
")",
"\n",
"}"
] | // GetOldRCs returns the old RCs targeted by the given Deployment; get PodList and RCList from client interface. | [
"GetOldRCs",
"returns",
"the",
"old",
"RCs",
"targeted",
"by",
"the",
"given",
"Deployment",
";",
"get",
"PodList",
"and",
"RCList",
"from",
"client",
"interface",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/deployment/deployment.go#L32-L41 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/deployment/deployment.go | GetNewRC | func GetNewRC(deployment extensions.Deployment, c client.Interface) (*api.ReplicationController, error) {
return GetNewRCFromList(deployment, c,
func(namespace string, options api.ListOptions) ([]api.ReplicationController, error) {
rcList, err := c.ReplicationControllers(namespace).List(options)
return rcList.Items, err
})
} | go | func GetNewRC(deployment extensions.Deployment, c client.Interface) (*api.ReplicationController, error) {
return GetNewRCFromList(deployment, c,
func(namespace string, options api.ListOptions) ([]api.ReplicationController, error) {
rcList, err := c.ReplicationControllers(namespace).List(options)
return rcList.Items, err
})
} | [
"func",
"GetNewRC",
"(",
"deployment",
"extensions",
".",
"Deployment",
",",
"c",
"client",
".",
"Interface",
")",
"(",
"*",
"api",
".",
"ReplicationController",
",",
"error",
")",
"{",
"return",
"GetNewRCFromList",
"(",
"deployment",
",",
"c",
",",
"func",
"(",
"namespace",
"string",
",",
"options",
"api",
".",
"ListOptions",
")",
"(",
"[",
"]",
"api",
".",
"ReplicationController",
",",
"error",
")",
"{",
"rcList",
",",
"err",
":=",
"c",
".",
"ReplicationControllers",
"(",
"namespace",
")",
".",
"List",
"(",
"options",
")",
"\n",
"return",
"rcList",
".",
"Items",
",",
"err",
"\n",
"}",
")",
"\n",
"}"
] | // GetNewRC returns an RC that matches the intent of the given deployment; get RCList from client interface.
// Returns nil if the new RC doesnt exist yet. | [
"GetNewRC",
"returns",
"an",
"RC",
"that",
"matches",
"the",
"intent",
"of",
"the",
"given",
"deployment",
";",
"get",
"RCList",
"from",
"client",
"interface",
".",
"Returns",
"nil",
"if",
"the",
"new",
"RC",
"doesnt",
"exist",
"yet",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/deployment/deployment.go#L84-L90 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/deployment/deployment.go | GetNewRCFromList | func GetNewRCFromList(deployment extensions.Deployment, c client.Interface, getRcList func(string, api.ListOptions) ([]api.ReplicationController, error)) (*api.ReplicationController, error) {
namespace := deployment.ObjectMeta.Namespace
rcList, err := getRcList(namespace, api.ListOptions{})
if err != nil {
return nil, fmt.Errorf("error listing replication controllers: %v", err)
}
newRCTemplate := GetNewRCTemplate(deployment)
for i := range rcList {
if api.Semantic.DeepEqual(rcList[i].Spec.Template, &newRCTemplate) {
// This is the new RC.
return &rcList[i], nil
}
}
// new RC does not exist.
return nil, nil
} | go | func GetNewRCFromList(deployment extensions.Deployment, c client.Interface, getRcList func(string, api.ListOptions) ([]api.ReplicationController, error)) (*api.ReplicationController, error) {
namespace := deployment.ObjectMeta.Namespace
rcList, err := getRcList(namespace, api.ListOptions{})
if err != nil {
return nil, fmt.Errorf("error listing replication controllers: %v", err)
}
newRCTemplate := GetNewRCTemplate(deployment)
for i := range rcList {
if api.Semantic.DeepEqual(rcList[i].Spec.Template, &newRCTemplate) {
// This is the new RC.
return &rcList[i], nil
}
}
// new RC does not exist.
return nil, nil
} | [
"func",
"GetNewRCFromList",
"(",
"deployment",
"extensions",
".",
"Deployment",
",",
"c",
"client",
".",
"Interface",
",",
"getRcList",
"func",
"(",
"string",
",",
"api",
".",
"ListOptions",
")",
"(",
"[",
"]",
"api",
".",
"ReplicationController",
",",
"error",
")",
")",
"(",
"*",
"api",
".",
"ReplicationController",
",",
"error",
")",
"{",
"namespace",
":=",
"deployment",
".",
"ObjectMeta",
".",
"Namespace",
"\n",
"rcList",
",",
"err",
":=",
"getRcList",
"(",
"namespace",
",",
"api",
".",
"ListOptions",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"newRCTemplate",
":=",
"GetNewRCTemplate",
"(",
"deployment",
")",
"\n\n",
"for",
"i",
":=",
"range",
"rcList",
"{",
"if",
"api",
".",
"Semantic",
".",
"DeepEqual",
"(",
"rcList",
"[",
"i",
"]",
".",
"Spec",
".",
"Template",
",",
"&",
"newRCTemplate",
")",
"{",
"// This is the new RC.",
"return",
"&",
"rcList",
"[",
"i",
"]",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"// new RC does not exist.",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // GetNewRCFromList returns an RC that matches the intent of the given deployment; get RCList with the input function.
// Returns nil if the new RC doesnt exist yet. | [
"GetNewRCFromList",
"returns",
"an",
"RC",
"that",
"matches",
"the",
"intent",
"of",
"the",
"given",
"deployment",
";",
"get",
"RCList",
"with",
"the",
"input",
"function",
".",
"Returns",
"nil",
"if",
"the",
"new",
"RC",
"doesnt",
"exist",
"yet",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/deployment/deployment.go#L94-L110 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/deployment/deployment.go | GetNewRCTemplate | func GetNewRCTemplate(deployment extensions.Deployment) api.PodTemplateSpec {
// newRC will have the same template as in deployment spec, plus a unique label in some cases.
newRCTemplate := api.PodTemplateSpec{
ObjectMeta: deployment.Spec.Template.ObjectMeta,
Spec: deployment.Spec.Template.Spec,
}
newRCTemplate.ObjectMeta.Labels = CloneAndAddLabel(
deployment.Spec.Template.ObjectMeta.Labels,
deployment.Spec.UniqueLabelKey,
GetPodTemplateSpecHash(newRCTemplate))
return newRCTemplate
} | go | func GetNewRCTemplate(deployment extensions.Deployment) api.PodTemplateSpec {
// newRC will have the same template as in deployment spec, plus a unique label in some cases.
newRCTemplate := api.PodTemplateSpec{
ObjectMeta: deployment.Spec.Template.ObjectMeta,
Spec: deployment.Spec.Template.Spec,
}
newRCTemplate.ObjectMeta.Labels = CloneAndAddLabel(
deployment.Spec.Template.ObjectMeta.Labels,
deployment.Spec.UniqueLabelKey,
GetPodTemplateSpecHash(newRCTemplate))
return newRCTemplate
} | [
"func",
"GetNewRCTemplate",
"(",
"deployment",
"extensions",
".",
"Deployment",
")",
"api",
".",
"PodTemplateSpec",
"{",
"// newRC will have the same template as in deployment spec, plus a unique label in some cases.",
"newRCTemplate",
":=",
"api",
".",
"PodTemplateSpec",
"{",
"ObjectMeta",
":",
"deployment",
".",
"Spec",
".",
"Template",
".",
"ObjectMeta",
",",
"Spec",
":",
"deployment",
".",
"Spec",
".",
"Template",
".",
"Spec",
",",
"}",
"\n",
"newRCTemplate",
".",
"ObjectMeta",
".",
"Labels",
"=",
"CloneAndAddLabel",
"(",
"deployment",
".",
"Spec",
".",
"Template",
".",
"ObjectMeta",
".",
"Labels",
",",
"deployment",
".",
"Spec",
".",
"UniqueLabelKey",
",",
"GetPodTemplateSpecHash",
"(",
"newRCTemplate",
")",
")",
"\n",
"return",
"newRCTemplate",
"\n",
"}"
] | // Returns the desired PodTemplateSpec for the new RC corresponding to the given RC. | [
"Returns",
"the",
"desired",
"PodTemplateSpec",
"for",
"the",
"new",
"RC",
"corresponding",
"to",
"the",
"given",
"RC",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/deployment/deployment.go#L113-L124 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/deployment/deployment.go | GetReplicaCountForRCs | func GetReplicaCountForRCs(replicationControllers []*api.ReplicationController) int {
totalReplicaCount := 0
for _, rc := range replicationControllers {
totalReplicaCount += rc.Spec.Replicas
}
return totalReplicaCount
} | go | func GetReplicaCountForRCs(replicationControllers []*api.ReplicationController) int {
totalReplicaCount := 0
for _, rc := range replicationControllers {
totalReplicaCount += rc.Spec.Replicas
}
return totalReplicaCount
} | [
"func",
"GetReplicaCountForRCs",
"(",
"replicationControllers",
"[",
"]",
"*",
"api",
".",
"ReplicationController",
")",
"int",
"{",
"totalReplicaCount",
":=",
"0",
"\n",
"for",
"_",
",",
"rc",
":=",
"range",
"replicationControllers",
"{",
"totalReplicaCount",
"+=",
"rc",
".",
"Spec",
".",
"Replicas",
"\n",
"}",
"\n",
"return",
"totalReplicaCount",
"\n",
"}"
] | // Returns the sum of Replicas of the given replication controllers. | [
"Returns",
"the",
"sum",
"of",
"Replicas",
"of",
"the",
"given",
"replication",
"controllers",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/deployment/deployment.go#L149-L155 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/deployment/deployment.go | GetAvailablePodsForRCs | func GetAvailablePodsForRCs(c client.Interface, rcs []*api.ReplicationController, minReadySeconds int) (int, error) {
allPods, err := getPodsForRCs(c, rcs)
if err != nil {
return 0, err
}
return getReadyPodsCount(allPods, minReadySeconds), nil
} | go | func GetAvailablePodsForRCs(c client.Interface, rcs []*api.ReplicationController, minReadySeconds int) (int, error) {
allPods, err := getPodsForRCs(c, rcs)
if err != nil {
return 0, err
}
return getReadyPodsCount(allPods, minReadySeconds), nil
} | [
"func",
"GetAvailablePodsForRCs",
"(",
"c",
"client",
".",
"Interface",
",",
"rcs",
"[",
"]",
"*",
"api",
".",
"ReplicationController",
",",
"minReadySeconds",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"allPods",
",",
"err",
":=",
"getPodsForRCs",
"(",
"c",
",",
"rcs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"getReadyPodsCount",
"(",
"allPods",
",",
"minReadySeconds",
")",
",",
"nil",
"\n",
"}"
] | // Returns the number of available pods corresponding to the given RCs. | [
"Returns",
"the",
"number",
"of",
"available",
"pods",
"corresponding",
"to",
"the",
"given",
"RCs",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/deployment/deployment.go#L158-L164 | train |
kubernetes-retired/contrib | keepalived-vip/keepalived.go | WriteCfg | func (k *keepalived) WriteCfg(svcs []vip) error {
w, err := os.Create(keepalivedCfg)
if err != nil {
return err
}
defer w.Close()
k.vips = getVIPs(svcs)
conf := make(map[string]interface{})
conf["iptablesChain"] = iptablesChain
conf["iface"] = k.iface
conf["myIP"] = k.ip
conf["netmask"] = k.netmask
conf["svcs"] = svcs
conf["vips"] = getVIPs(svcs)
conf["nodes"] = k.neighbors
conf["priority"] = k.priority
conf["useUnicast"] = k.useUnicast
conf["vrid"] = k.vrid
conf["vrrpVersion"] = k.vrrpVersion
conf["notify"] = k.notify
if glog.V(2) {
b, _ := json.Marshal(conf)
glog.Infof("%v", string(b))
}
return k.tmpl.Execute(w, conf)
} | go | func (k *keepalived) WriteCfg(svcs []vip) error {
w, err := os.Create(keepalivedCfg)
if err != nil {
return err
}
defer w.Close()
k.vips = getVIPs(svcs)
conf := make(map[string]interface{})
conf["iptablesChain"] = iptablesChain
conf["iface"] = k.iface
conf["myIP"] = k.ip
conf["netmask"] = k.netmask
conf["svcs"] = svcs
conf["vips"] = getVIPs(svcs)
conf["nodes"] = k.neighbors
conf["priority"] = k.priority
conf["useUnicast"] = k.useUnicast
conf["vrid"] = k.vrid
conf["vrrpVersion"] = k.vrrpVersion
conf["notify"] = k.notify
if glog.V(2) {
b, _ := json.Marshal(conf)
glog.Infof("%v", string(b))
}
return k.tmpl.Execute(w, conf)
} | [
"func",
"(",
"k",
"*",
"keepalived",
")",
"WriteCfg",
"(",
"svcs",
"[",
"]",
"vip",
")",
"error",
"{",
"w",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"keepalivedCfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"w",
".",
"Close",
"(",
")",
"\n\n",
"k",
".",
"vips",
"=",
"getVIPs",
"(",
"svcs",
")",
"\n\n",
"conf",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"iptablesChain",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"k",
".",
"iface",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"k",
".",
"ip",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"k",
".",
"netmask",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"svcs",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"getVIPs",
"(",
"svcs",
")",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"k",
".",
"neighbors",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"k",
".",
"priority",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"k",
".",
"useUnicast",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"k",
".",
"vrid",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"k",
".",
"vrrpVersion",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"k",
".",
"notify",
"\n\n",
"if",
"glog",
".",
"V",
"(",
"2",
")",
"{",
"b",
",",
"_",
":=",
"json",
".",
"Marshal",
"(",
"conf",
")",
"\n",
"glog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"string",
"(",
"b",
")",
")",
"\n",
"}",
"\n\n",
"return",
"k",
".",
"tmpl",
".",
"Execute",
"(",
"w",
",",
"conf",
")",
"\n",
"}"
] | // WriteCfg creates a new keepalived configuration file.
// In case of an error with the generation it returns the error | [
"WriteCfg",
"creates",
"a",
"new",
"keepalived",
"configuration",
"file",
".",
"In",
"case",
"of",
"an",
"error",
"with",
"the",
"generation",
"it",
"returns",
"the",
"error"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/keepalived-vip/keepalived.go#L59-L88 | train |
kubernetes-retired/contrib | keepalived-vip/keepalived.go | Start | func (k *keepalived) Start() {
ae, err := k.ipt.EnsureChain(iptables.TableFilter, iptables.Chain(iptablesChain))
if err != nil {
glog.Fatalf("unexpected error: %v", err)
}
if ae {
glog.V(2).Infof("chain %v already existed", iptablesChain)
}
k.cmd = exec.Command("keepalived",
"--dont-fork",
"--log-console",
"--release-vips",
"--pid", "/keepalived.pid")
k.cmd.Stdout = os.Stdout
k.cmd.Stderr = os.Stderr
k.started = true
if err := k.cmd.Start(); err != nil {
glog.Errorf("keepalived error: %v", err)
}
if err := k.cmd.Wait(); err != nil {
glog.Fatalf("keepalived error: %v", err)
}
} | go | func (k *keepalived) Start() {
ae, err := k.ipt.EnsureChain(iptables.TableFilter, iptables.Chain(iptablesChain))
if err != nil {
glog.Fatalf("unexpected error: %v", err)
}
if ae {
glog.V(2).Infof("chain %v already existed", iptablesChain)
}
k.cmd = exec.Command("keepalived",
"--dont-fork",
"--log-console",
"--release-vips",
"--pid", "/keepalived.pid")
k.cmd.Stdout = os.Stdout
k.cmd.Stderr = os.Stderr
k.started = true
if err := k.cmd.Start(); err != nil {
glog.Errorf("keepalived error: %v", err)
}
if err := k.cmd.Wait(); err != nil {
glog.Fatalf("keepalived error: %v", err)
}
} | [
"func",
"(",
"k",
"*",
"keepalived",
")",
"Start",
"(",
")",
"{",
"ae",
",",
"err",
":=",
"k",
".",
"ipt",
".",
"EnsureChain",
"(",
"iptables",
".",
"TableFilter",
",",
"iptables",
".",
"Chain",
"(",
"iptablesChain",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"ae",
"{",
"glog",
".",
"V",
"(",
"2",
")",
".",
"Infof",
"(",
"\"",
"\"",
",",
"iptablesChain",
")",
"\n",
"}",
"\n\n",
"k",
".",
"cmd",
"=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"k",
".",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"k",
".",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n\n",
"k",
".",
"started",
"=",
"true",
"\n\n",
"if",
"err",
":=",
"k",
".",
"cmd",
".",
"Start",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"k",
".",
"cmd",
".",
"Wait",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // Start starts a keepalived process in foreground.
// In case of any error it will terminate the execution with a fatal error | [
"Start",
"starts",
"a",
"keepalived",
"process",
"in",
"foreground",
".",
"In",
"case",
"of",
"any",
"error",
"it",
"will",
"terminate",
"the",
"execution",
"with",
"a",
"fatal",
"error"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/keepalived-vip/keepalived.go#L103-L130 | train |
kubernetes-retired/contrib | keepalived-vip/keepalived.go | Reload | func (k *keepalived) Reload() error {
if !k.started {
// TODO: add a warning indicating that keepalived is not started?
return nil
}
glog.Info("reloading keepalived")
err := syscall.Kill(k.cmd.Process.Pid, syscall.SIGHUP)
if err != nil {
return fmt.Errorf("error reloading keepalived: %v", err)
}
return nil
} | go | func (k *keepalived) Reload() error {
if !k.started {
// TODO: add a warning indicating that keepalived is not started?
return nil
}
glog.Info("reloading keepalived")
err := syscall.Kill(k.cmd.Process.Pid, syscall.SIGHUP)
if err != nil {
return fmt.Errorf("error reloading keepalived: %v", err)
}
return nil
} | [
"func",
"(",
"k",
"*",
"keepalived",
")",
"Reload",
"(",
")",
"error",
"{",
"if",
"!",
"k",
".",
"started",
"{",
"// TODO: add a warning indicating that keepalived is not started?",
"return",
"nil",
"\n",
"}",
"\n\n",
"glog",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"err",
":=",
"syscall",
".",
"Kill",
"(",
"k",
".",
"cmd",
".",
"Process",
".",
"Pid",
",",
"syscall",
".",
"SIGHUP",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Reload sends SIGHUP to keepalived to reload the configuration. | [
"Reload",
"sends",
"SIGHUP",
"to",
"keepalived",
"to",
"reload",
"the",
"configuration",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/keepalived-vip/keepalived.go#L133-L146 | train |
kubernetes-retired/contrib | keepalived-vip/keepalived.go | Stop | func (k *keepalived) Stop() {
for _, vip := range k.vips {
k.removeVIP(vip)
}
err := k.ipt.FlushChain(iptables.TableFilter, iptables.Chain(iptablesChain))
if err != nil {
glog.V(2).Infof("unexpected error flushing iptables chain %v: %v", err, iptablesChain)
}
err = syscall.Kill(k.cmd.Process.Pid, syscall.SIGTERM)
if err != nil {
glog.Errorf("error stopping keepalived: %v", err)
}
} | go | func (k *keepalived) Stop() {
for _, vip := range k.vips {
k.removeVIP(vip)
}
err := k.ipt.FlushChain(iptables.TableFilter, iptables.Chain(iptablesChain))
if err != nil {
glog.V(2).Infof("unexpected error flushing iptables chain %v: %v", err, iptablesChain)
}
err = syscall.Kill(k.cmd.Process.Pid, syscall.SIGTERM)
if err != nil {
glog.Errorf("error stopping keepalived: %v", err)
}
} | [
"func",
"(",
"k",
"*",
"keepalived",
")",
"Stop",
"(",
")",
"{",
"for",
"_",
",",
"vip",
":=",
"range",
"k",
".",
"vips",
"{",
"k",
".",
"removeVIP",
"(",
"vip",
")",
"\n",
"}",
"\n\n",
"err",
":=",
"k",
".",
"ipt",
".",
"FlushChain",
"(",
"iptables",
".",
"TableFilter",
",",
"iptables",
".",
"Chain",
"(",
"iptablesChain",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"glog",
".",
"V",
"(",
"2",
")",
".",
"Infof",
"(",
"\"",
"\"",
",",
"err",
",",
"iptablesChain",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"syscall",
".",
"Kill",
"(",
"k",
".",
"cmd",
".",
"Process",
".",
"Pid",
",",
"syscall",
".",
"SIGTERM",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // Stop stop keepalived process | [
"Stop",
"stop",
"keepalived",
"process"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/keepalived-vip/keepalived.go#L149-L163 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/jsonpath/parser.go | parseQuote | func (p *Parser) parseQuote(cur *ListNode) error {
Loop:
for {
switch p.next() {
case eof, '\n':
return fmt.Errorf("unterminated quoted string")
case '"':
break Loop
}
}
value := p.consumeText()
s, err := strconv.Unquote(value)
if err != nil {
return fmt.Errorf("unquote string %s error %v", value, err)
}
cur.append(newText(s))
return p.parseInsideAction(cur)
} | go | func (p *Parser) parseQuote(cur *ListNode) error {
Loop:
for {
switch p.next() {
case eof, '\n':
return fmt.Errorf("unterminated quoted string")
case '"':
break Loop
}
}
value := p.consumeText()
s, err := strconv.Unquote(value)
if err != nil {
return fmt.Errorf("unquote string %s error %v", value, err)
}
cur.append(newText(s))
return p.parseInsideAction(cur)
} | [
"func",
"(",
"p",
"*",
"Parser",
")",
"parseQuote",
"(",
"cur",
"*",
"ListNode",
")",
"error",
"{",
"Loop",
":",
"for",
"{",
"switch",
"p",
".",
"next",
"(",
")",
"{",
"case",
"eof",
",",
"'\\n'",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"case",
"'\"'",
":",
"break",
"Loop",
"\n",
"}",
"\n",
"}",
"\n",
"value",
":=",
"p",
".",
"consumeText",
"(",
")",
"\n",
"s",
",",
"err",
":=",
"strconv",
".",
"Unquote",
"(",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"value",
",",
"err",
")",
"\n",
"}",
"\n",
"cur",
".",
"append",
"(",
"newText",
"(",
"s",
")",
")",
"\n",
"return",
"p",
".",
"parseInsideAction",
"(",
"cur",
")",
"\n",
"}"
] | // parseQuote unquotes string inside double quote | [
"parseQuote",
"unquotes",
"string",
"inside",
"double",
"quote"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/jsonpath/parser.go#L363-L380 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/v1/defaults.go | defaultHostNetworkPorts | func defaultHostNetworkPorts(containers *[]Container) {
for i := range *containers {
for j := range (*containers)[i].Ports {
if (*containers)[i].Ports[j].HostPort == 0 {
(*containers)[i].Ports[j].HostPort = (*containers)[i].Ports[j].ContainerPort
}
}
}
} | go | func defaultHostNetworkPorts(containers *[]Container) {
for i := range *containers {
for j := range (*containers)[i].Ports {
if (*containers)[i].Ports[j].HostPort == 0 {
(*containers)[i].Ports[j].HostPort = (*containers)[i].Ports[j].ContainerPort
}
}
}
} | [
"func",
"defaultHostNetworkPorts",
"(",
"containers",
"*",
"[",
"]",
"Container",
")",
"{",
"for",
"i",
":=",
"range",
"*",
"containers",
"{",
"for",
"j",
":=",
"range",
"(",
"*",
"containers",
")",
"[",
"i",
"]",
".",
"Ports",
"{",
"if",
"(",
"*",
"containers",
")",
"[",
"i",
"]",
".",
"Ports",
"[",
"j",
"]",
".",
"HostPort",
"==",
"0",
"{",
"(",
"*",
"containers",
")",
"[",
"i",
"]",
".",
"Ports",
"[",
"j",
"]",
".",
"HostPort",
"=",
"(",
"*",
"containers",
")",
"[",
"i",
"]",
".",
"Ports",
"[",
"j",
"]",
".",
"ContainerPort",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // With host networking default all container ports to host ports. | [
"With",
"host",
"networking",
"default",
"all",
"container",
"ports",
"to",
"host",
"ports",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/v1/defaults.go#L255-L263 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/validation/schema.go | validateList | func (s *SwaggerSchema) validateList(obj map[string]interface{}) []error {
allErrs := []error{}
items, exists := obj["items"]
if !exists {
return append(allErrs, fmt.Errorf("no items field in %#v", obj))
}
itemList, ok := items.([]interface{})
if !ok {
return append(allErrs, fmt.Errorf("items isn't a slice"))
}
for i, item := range itemList {
fields, ok := item.(map[string]interface{})
if !ok {
allErrs = append(allErrs, fmt.Errorf("items[%d] isn't a map[string]interface{}", i))
continue
}
groupVersion := fields["apiVersion"]
if groupVersion == nil {
allErrs = append(allErrs, fmt.Errorf("items[%d].apiVersion not set", i))
continue
}
itemVersion, ok := groupVersion.(string)
if !ok {
allErrs = append(allErrs, fmt.Errorf("items[%d].apiVersion isn't string type", i))
continue
}
if len(itemVersion) == 0 {
allErrs = append(allErrs, fmt.Errorf("items[%d].apiVersion is empty", i))
}
kind := fields["kind"]
if kind == nil {
allErrs = append(allErrs, fmt.Errorf("items[%d].kind not set", i))
continue
}
itemKind, ok := kind.(string)
if !ok {
allErrs = append(allErrs, fmt.Errorf("items[%d].kind isn't string type", i))
continue
}
if len(itemKind) == 0 {
allErrs = append(allErrs, fmt.Errorf("items[%d].kind is empty", i))
}
version := apiutil.GetVersion(itemVersion)
errs := s.ValidateObject(item, "", version+"."+itemKind)
if len(errs) >= 1 {
allErrs = append(allErrs, errs...)
}
}
return allErrs
} | go | func (s *SwaggerSchema) validateList(obj map[string]interface{}) []error {
allErrs := []error{}
items, exists := obj["items"]
if !exists {
return append(allErrs, fmt.Errorf("no items field in %#v", obj))
}
itemList, ok := items.([]interface{})
if !ok {
return append(allErrs, fmt.Errorf("items isn't a slice"))
}
for i, item := range itemList {
fields, ok := item.(map[string]interface{})
if !ok {
allErrs = append(allErrs, fmt.Errorf("items[%d] isn't a map[string]interface{}", i))
continue
}
groupVersion := fields["apiVersion"]
if groupVersion == nil {
allErrs = append(allErrs, fmt.Errorf("items[%d].apiVersion not set", i))
continue
}
itemVersion, ok := groupVersion.(string)
if !ok {
allErrs = append(allErrs, fmt.Errorf("items[%d].apiVersion isn't string type", i))
continue
}
if len(itemVersion) == 0 {
allErrs = append(allErrs, fmt.Errorf("items[%d].apiVersion is empty", i))
}
kind := fields["kind"]
if kind == nil {
allErrs = append(allErrs, fmt.Errorf("items[%d].kind not set", i))
continue
}
itemKind, ok := kind.(string)
if !ok {
allErrs = append(allErrs, fmt.Errorf("items[%d].kind isn't string type", i))
continue
}
if len(itemKind) == 0 {
allErrs = append(allErrs, fmt.Errorf("items[%d].kind is empty", i))
}
version := apiutil.GetVersion(itemVersion)
errs := s.ValidateObject(item, "", version+"."+itemKind)
if len(errs) >= 1 {
allErrs = append(allErrs, errs...)
}
}
return allErrs
} | [
"func",
"(",
"s",
"*",
"SwaggerSchema",
")",
"validateList",
"(",
"obj",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"[",
"]",
"error",
"{",
"allErrs",
":=",
"[",
"]",
"error",
"{",
"}",
"\n",
"items",
",",
"exists",
":=",
"obj",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"exists",
"{",
"return",
"append",
"(",
"allErrs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
")",
")",
"\n",
"}",
"\n",
"itemList",
",",
"ok",
":=",
"items",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"append",
"(",
"allErrs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"for",
"i",
",",
"item",
":=",
"range",
"itemList",
"{",
"fields",
",",
"ok",
":=",
"item",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"allErrs",
"=",
"append",
"(",
"allErrs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
")",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"groupVersion",
":=",
"fields",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"groupVersion",
"==",
"nil",
"{",
"allErrs",
"=",
"append",
"(",
"allErrs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
")",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"itemVersion",
",",
"ok",
":=",
"groupVersion",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"allErrs",
"=",
"append",
"(",
"allErrs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
")",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"len",
"(",
"itemVersion",
")",
"==",
"0",
"{",
"allErrs",
"=",
"append",
"(",
"allErrs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
")",
")",
"\n",
"}",
"\n",
"kind",
":=",
"fields",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"kind",
"==",
"nil",
"{",
"allErrs",
"=",
"append",
"(",
"allErrs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
")",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"itemKind",
",",
"ok",
":=",
"kind",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"allErrs",
"=",
"append",
"(",
"allErrs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
")",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"len",
"(",
"itemKind",
")",
"==",
"0",
"{",
"allErrs",
"=",
"append",
"(",
"allErrs",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
")",
")",
"\n",
"}",
"\n",
"version",
":=",
"apiutil",
".",
"GetVersion",
"(",
"itemVersion",
")",
"\n",
"errs",
":=",
"s",
".",
"ValidateObject",
"(",
"item",
",",
"\"",
"\"",
",",
"version",
"+",
"\"",
"\"",
"+",
"itemKind",
")",
"\n",
"if",
"len",
"(",
"errs",
")",
">=",
"1",
"{",
"allErrs",
"=",
"append",
"(",
"allErrs",
",",
"errs",
"...",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"allErrs",
"\n",
"}"
] | // validateList unpacks a list and validate every item in the list.
// It return nil if every item is ok.
// Otherwise it return an error list contain errors of every item. | [
"validateList",
"unpacks",
"a",
"list",
"and",
"validate",
"every",
"item",
"in",
"the",
"list",
".",
"It",
"return",
"nil",
"if",
"every",
"item",
"is",
"ok",
".",
"Otherwise",
"it",
"return",
"an",
"error",
"list",
"contain",
"errors",
"of",
"every",
"item",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/validation/schema.go#L72-L121 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/util.go | AllPtrFieldsNil | func AllPtrFieldsNil(obj interface{}) bool {
v := reflect.ValueOf(obj)
if !v.IsValid() {
panic(fmt.Sprintf("reflect.ValueOf() produced a non-valid Value for %#v", obj))
}
if v.Kind() == reflect.Ptr {
if v.IsNil() {
return true
}
v = v.Elem()
}
for i := 0; i < v.NumField(); i++ {
if v.Field(i).Kind() == reflect.Ptr && !v.Field(i).IsNil() {
return false
}
}
return true
} | go | func AllPtrFieldsNil(obj interface{}) bool {
v := reflect.ValueOf(obj)
if !v.IsValid() {
panic(fmt.Sprintf("reflect.ValueOf() produced a non-valid Value for %#v", obj))
}
if v.Kind() == reflect.Ptr {
if v.IsNil() {
return true
}
v = v.Elem()
}
for i := 0; i < v.NumField(); i++ {
if v.Field(i).Kind() == reflect.Ptr && !v.Field(i).IsNil() {
return false
}
}
return true
} | [
"func",
"AllPtrFieldsNil",
"(",
"obj",
"interface",
"{",
"}",
")",
"bool",
"{",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"obj",
")",
"\n",
"if",
"!",
"v",
".",
"IsValid",
"(",
")",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"obj",
")",
")",
"\n",
"}",
"\n",
"if",
"v",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"{",
"if",
"v",
".",
"IsNil",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"v",
"=",
"v",
".",
"Elem",
"(",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"v",
".",
"NumField",
"(",
")",
";",
"i",
"++",
"{",
"if",
"v",
".",
"Field",
"(",
"i",
")",
".",
"Kind",
"(",
")",
"==",
"reflect",
".",
"Ptr",
"&&",
"!",
"v",
".",
"Field",
"(",
"i",
")",
".",
"IsNil",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Tests whether all pointer fields in a struct are nil. This is useful when,
// for example, an API struct is handled by plugins which need to distinguish
// "no plugin accepted this spec" from "this spec is empty".
//
// This function is only valid for structs and pointers to structs. Any other
// type will cause a panic. Passing a typed nil pointer will return true. | [
"Tests",
"whether",
"all",
"pointer",
"fields",
"in",
"a",
"struct",
"are",
"nil",
".",
"This",
"is",
"useful",
"when",
"for",
"example",
"an",
"API",
"struct",
"is",
"handled",
"by",
"plugins",
"which",
"need",
"to",
"distinguish",
"no",
"plugin",
"accepted",
"this",
"spec",
"from",
"this",
"spec",
"is",
"empty",
".",
"This",
"function",
"is",
"only",
"valid",
"for",
"structs",
"and",
"pointers",
"to",
"structs",
".",
"Any",
"other",
"type",
"will",
"cause",
"a",
"panic",
".",
"Passing",
"a",
"typed",
"nil",
"pointer",
"will",
"return",
"true",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/util.go#L59-L76 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/util.go | ReadDirNoExit | func ReadDirNoExit(dirname string) ([]os.FileInfo, []error, error) {
if dirname == "" {
dirname = "."
}
f, err := os.Open(dirname)
if err != nil {
return nil, nil, err
}
defer f.Close()
names, err := f.Readdirnames(-1)
list := make([]os.FileInfo, 0, len(names))
errs := make([]error, 0, len(names))
for _, filename := range names {
fip, lerr := os.Lstat(dirname + "/" + filename)
if os.IsNotExist(lerr) {
// File disappeared between readdir + stat.
// Just treat it as if it didn't exist.
continue
}
list = append(list, fip)
errs = append(errs, lerr)
}
return list, errs, nil
} | go | func ReadDirNoExit(dirname string) ([]os.FileInfo, []error, error) {
if dirname == "" {
dirname = "."
}
f, err := os.Open(dirname)
if err != nil {
return nil, nil, err
}
defer f.Close()
names, err := f.Readdirnames(-1)
list := make([]os.FileInfo, 0, len(names))
errs := make([]error, 0, len(names))
for _, filename := range names {
fip, lerr := os.Lstat(dirname + "/" + filename)
if os.IsNotExist(lerr) {
// File disappeared between readdir + stat.
// Just treat it as if it didn't exist.
continue
}
list = append(list, fip)
errs = append(errs, lerr)
}
return list, errs, nil
} | [
"func",
"ReadDirNoExit",
"(",
"dirname",
"string",
")",
"(",
"[",
"]",
"os",
".",
"FileInfo",
",",
"[",
"]",
"error",
",",
"error",
")",
"{",
"if",
"dirname",
"==",
"\"",
"\"",
"{",
"dirname",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"dirname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"names",
",",
"err",
":=",
"f",
".",
"Readdirnames",
"(",
"-",
"1",
")",
"\n",
"list",
":=",
"make",
"(",
"[",
"]",
"os",
".",
"FileInfo",
",",
"0",
",",
"len",
"(",
"names",
")",
")",
"\n",
"errs",
":=",
"make",
"(",
"[",
"]",
"error",
",",
"0",
",",
"len",
"(",
"names",
")",
")",
"\n",
"for",
"_",
",",
"filename",
":=",
"range",
"names",
"{",
"fip",
",",
"lerr",
":=",
"os",
".",
"Lstat",
"(",
"dirname",
"+",
"\"",
"\"",
"+",
"filename",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"lerr",
")",
"{",
"// File disappeared between readdir + stat.",
"// Just treat it as if it didn't exist.",
"continue",
"\n",
"}",
"\n\n",
"list",
"=",
"append",
"(",
"list",
",",
"fip",
")",
"\n",
"errs",
"=",
"append",
"(",
"errs",
",",
"lerr",
")",
"\n",
"}",
"\n\n",
"return",
"list",
",",
"errs",
",",
"nil",
"\n",
"}"
] | // borrowed from ioutil.ReadDir
// ReadDir reads the directory named by dirname and returns
// a list of directory entries, minus those with lstat errors | [
"borrowed",
"from",
"ioutil",
".",
"ReadDir",
"ReadDir",
"reads",
"the",
"directory",
"named",
"by",
"dirname",
"and",
"returns",
"a",
"list",
"of",
"directory",
"entries",
"minus",
"those",
"with",
"lstat",
"errors"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/util.go#L90-L117 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/util.go | IntPtrDerefOr | func IntPtrDerefOr(ptr *int, def int) int {
if ptr != nil {
return *ptr
}
return def
} | go | func IntPtrDerefOr(ptr *int, def int) int {
if ptr != nil {
return *ptr
}
return def
} | [
"func",
"IntPtrDerefOr",
"(",
"ptr",
"*",
"int",
",",
"def",
"int",
")",
"int",
"{",
"if",
"ptr",
"!=",
"nil",
"{",
"return",
"*",
"ptr",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
] | // IntPtrDerefOr dereference the int ptr and returns it i not nil,
// else returns def. | [
"IntPtrDerefOr",
"dereference",
"the",
"int",
"ptr",
"and",
"returns",
"it",
"i",
"not",
"nil",
"else",
"returns",
"def",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/util.go#L127-L132 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/events.go | Create | func (e *events) Create(event *api.Event) (*api.Event, error) {
if e.namespace != "" && event.Namespace != e.namespace {
return nil, fmt.Errorf("can't create an event with namespace '%v' in namespace '%v'", event.Namespace, e.namespace)
}
result := &api.Event{}
err := e.client.Post().
Namespace(event.Namespace).
Resource("events").
Body(event).
Do().
Into(result)
return result, err
} | go | func (e *events) Create(event *api.Event) (*api.Event, error) {
if e.namespace != "" && event.Namespace != e.namespace {
return nil, fmt.Errorf("can't create an event with namespace '%v' in namespace '%v'", event.Namespace, e.namespace)
}
result := &api.Event{}
err := e.client.Post().
Namespace(event.Namespace).
Resource("events").
Body(event).
Do().
Into(result)
return result, err
} | [
"func",
"(",
"e",
"*",
"events",
")",
"Create",
"(",
"event",
"*",
"api",
".",
"Event",
")",
"(",
"*",
"api",
".",
"Event",
",",
"error",
")",
"{",
"if",
"e",
".",
"namespace",
"!=",
"\"",
"\"",
"&&",
"event",
".",
"Namespace",
"!=",
"e",
".",
"namespace",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"event",
".",
"Namespace",
",",
"e",
".",
"namespace",
")",
"\n",
"}",
"\n",
"result",
":=",
"&",
"api",
".",
"Event",
"{",
"}",
"\n",
"err",
":=",
"e",
".",
"client",
".",
"Post",
"(",
")",
".",
"Namespace",
"(",
"event",
".",
"Namespace",
")",
".",
"Resource",
"(",
"\"",
"\"",
")",
".",
"Body",
"(",
"event",
")",
".",
"Do",
"(",
")",
".",
"Into",
"(",
"result",
")",
"\n",
"return",
"result",
",",
"err",
"\n",
"}"
] | // Create makes a new event. Returns the copy of the event the server returns,
// or an error. The namespace to create the event within is deduced from the
// event; it must either match this event client's namespace, or this event
// client must have been created with the "" namespace. | [
"Create",
"makes",
"a",
"new",
"event",
".",
"Returns",
"the",
"copy",
"of",
"the",
"event",
"the",
"server",
"returns",
"or",
"an",
"error",
".",
"The",
"namespace",
"to",
"create",
"the",
"event",
"within",
"is",
"deduced",
"from",
"the",
"event",
";",
"it",
"must",
"either",
"match",
"this",
"event",
"client",
"s",
"namespace",
"or",
"this",
"event",
"client",
"must",
"have",
"been",
"created",
"with",
"the",
"namespace",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/events.go#L69-L81 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/events.go | Patch | func (e *events) Patch(incompleteEvent *api.Event, data []byte) (*api.Event, error) {
result := &api.Event{}
err := e.client.Patch(api.StrategicMergePatchType).
Namespace(incompleteEvent.Namespace).
Resource("events").
Name(incompleteEvent.Name).
Body(data).
Do().
Into(result)
return result, err
} | go | func (e *events) Patch(incompleteEvent *api.Event, data []byte) (*api.Event, error) {
result := &api.Event{}
err := e.client.Patch(api.StrategicMergePatchType).
Namespace(incompleteEvent.Namespace).
Resource("events").
Name(incompleteEvent.Name).
Body(data).
Do().
Into(result)
return result, err
} | [
"func",
"(",
"e",
"*",
"events",
")",
"Patch",
"(",
"incompleteEvent",
"*",
"api",
".",
"Event",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"*",
"api",
".",
"Event",
",",
"error",
")",
"{",
"result",
":=",
"&",
"api",
".",
"Event",
"{",
"}",
"\n",
"err",
":=",
"e",
".",
"client",
".",
"Patch",
"(",
"api",
".",
"StrategicMergePatchType",
")",
".",
"Namespace",
"(",
"incompleteEvent",
".",
"Namespace",
")",
".",
"Resource",
"(",
"\"",
"\"",
")",
".",
"Name",
"(",
"incompleteEvent",
".",
"Name",
")",
".",
"Body",
"(",
"data",
")",
".",
"Do",
"(",
")",
".",
"Into",
"(",
"result",
")",
"\n",
"return",
"result",
",",
"err",
"\n",
"}"
] | // Patch modifies an existing event. It returns the copy of the event that the server returns, or an
// error. The namespace and name of the target event is deduced from the incompleteEvent. The
// namespace must either match this event client's namespace, or this event client must have been
// created with the "" namespace. | [
"Patch",
"modifies",
"an",
"existing",
"event",
".",
"It",
"returns",
"the",
"copy",
"of",
"the",
"event",
"that",
"the",
"server",
"returns",
"or",
"an",
"error",
".",
"The",
"namespace",
"and",
"name",
"of",
"the",
"target",
"event",
"is",
"deduced",
"from",
"the",
"incompleteEvent",
".",
"The",
"namespace",
"must",
"either",
"match",
"this",
"event",
"client",
"s",
"namespace",
"or",
"this",
"event",
"client",
"must",
"have",
"been",
"created",
"with",
"the",
"namespace",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/events.go#L104-L114 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/rolling_updater.go | scaleDown | func (r *RollingUpdater) scaleDown(newRc, oldRc *api.ReplicationController, desired, minAvailable, maxUnavailable, maxSurge int, config *RollingUpdaterConfig) (*api.ReplicationController, error) {
// Already scaled down; do nothing.
if oldRc.Spec.Replicas == 0 {
return oldRc, nil
}
// Block until there are any pods ready.
_, newAvailable, err := r.waitForReadyPods(config.Interval, config.Timeout, oldRc, newRc)
if err != nil {
return nil, err
}
// The old controller is considered as part of the total because we want to
// maintain minimum availability even with a volatile old controller.
// Scale down as much as possible while maintaining minimum availability
decrement := oldRc.Spec.Replicas + newAvailable - minAvailable
// The decrement normally shouldn't drop below 0 because the available count
// always starts below the old replica count, but the old replica count can
// decrement due to externalities like pods death in the replica set. This
// will be considered a transient condition; do nothing and try again later
// with new readiness values.
//
// If the most we can scale is 0, it means we can't scale down without
// violating the minimum. Do nothing and try again later when conditions may
// have changed.
if decrement <= 0 {
return oldRc, nil
}
// Reduce the replica count, and deal with fenceposts.
oldRc.Spec.Replicas -= decrement
if oldRc.Spec.Replicas < 0 {
oldRc.Spec.Replicas = 0
}
// If the new is already fully scaled and available up to the desired size, go
// ahead and scale old all the way down.
if newRc.Spec.Replicas == desired && newAvailable == desired {
oldRc.Spec.Replicas = 0
}
// Perform the scale-down.
fmt.Fprintf(config.Out, "Scaling %s down to %d\n", oldRc.Name, oldRc.Spec.Replicas)
retryWait := &RetryParams{config.Interval, config.Timeout}
scaledRc, err := r.scaleAndWait(oldRc, retryWait, retryWait)
if err != nil {
return nil, err
}
return scaledRc, nil
} | go | func (r *RollingUpdater) scaleDown(newRc, oldRc *api.ReplicationController, desired, minAvailable, maxUnavailable, maxSurge int, config *RollingUpdaterConfig) (*api.ReplicationController, error) {
// Already scaled down; do nothing.
if oldRc.Spec.Replicas == 0 {
return oldRc, nil
}
// Block until there are any pods ready.
_, newAvailable, err := r.waitForReadyPods(config.Interval, config.Timeout, oldRc, newRc)
if err != nil {
return nil, err
}
// The old controller is considered as part of the total because we want to
// maintain minimum availability even with a volatile old controller.
// Scale down as much as possible while maintaining minimum availability
decrement := oldRc.Spec.Replicas + newAvailable - minAvailable
// The decrement normally shouldn't drop below 0 because the available count
// always starts below the old replica count, but the old replica count can
// decrement due to externalities like pods death in the replica set. This
// will be considered a transient condition; do nothing and try again later
// with new readiness values.
//
// If the most we can scale is 0, it means we can't scale down without
// violating the minimum. Do nothing and try again later when conditions may
// have changed.
if decrement <= 0 {
return oldRc, nil
}
// Reduce the replica count, and deal with fenceposts.
oldRc.Spec.Replicas -= decrement
if oldRc.Spec.Replicas < 0 {
oldRc.Spec.Replicas = 0
}
// If the new is already fully scaled and available up to the desired size, go
// ahead and scale old all the way down.
if newRc.Spec.Replicas == desired && newAvailable == desired {
oldRc.Spec.Replicas = 0
}
// Perform the scale-down.
fmt.Fprintf(config.Out, "Scaling %s down to %d\n", oldRc.Name, oldRc.Spec.Replicas)
retryWait := &RetryParams{config.Interval, config.Timeout}
scaledRc, err := r.scaleAndWait(oldRc, retryWait, retryWait)
if err != nil {
return nil, err
}
return scaledRc, nil
} | [
"func",
"(",
"r",
"*",
"RollingUpdater",
")",
"scaleDown",
"(",
"newRc",
",",
"oldRc",
"*",
"api",
".",
"ReplicationController",
",",
"desired",
",",
"minAvailable",
",",
"maxUnavailable",
",",
"maxSurge",
"int",
",",
"config",
"*",
"RollingUpdaterConfig",
")",
"(",
"*",
"api",
".",
"ReplicationController",
",",
"error",
")",
"{",
"// Already scaled down; do nothing.",
"if",
"oldRc",
".",
"Spec",
".",
"Replicas",
"==",
"0",
"{",
"return",
"oldRc",
",",
"nil",
"\n",
"}",
"\n",
"// Block until there are any pods ready.",
"_",
",",
"newAvailable",
",",
"err",
":=",
"r",
".",
"waitForReadyPods",
"(",
"config",
".",
"Interval",
",",
"config",
".",
"Timeout",
",",
"oldRc",
",",
"newRc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// The old controller is considered as part of the total because we want to",
"// maintain minimum availability even with a volatile old controller.",
"// Scale down as much as possible while maintaining minimum availability",
"decrement",
":=",
"oldRc",
".",
"Spec",
".",
"Replicas",
"+",
"newAvailable",
"-",
"minAvailable",
"\n",
"// The decrement normally shouldn't drop below 0 because the available count",
"// always starts below the old replica count, but the old replica count can",
"// decrement due to externalities like pods death in the replica set. This",
"// will be considered a transient condition; do nothing and try again later",
"// with new readiness values.",
"//",
"// If the most we can scale is 0, it means we can't scale down without",
"// violating the minimum. Do nothing and try again later when conditions may",
"// have changed.",
"if",
"decrement",
"<=",
"0",
"{",
"return",
"oldRc",
",",
"nil",
"\n",
"}",
"\n",
"// Reduce the replica count, and deal with fenceposts.",
"oldRc",
".",
"Spec",
".",
"Replicas",
"-=",
"decrement",
"\n",
"if",
"oldRc",
".",
"Spec",
".",
"Replicas",
"<",
"0",
"{",
"oldRc",
".",
"Spec",
".",
"Replicas",
"=",
"0",
"\n",
"}",
"\n",
"// If the new is already fully scaled and available up to the desired size, go",
"// ahead and scale old all the way down.",
"if",
"newRc",
".",
"Spec",
".",
"Replicas",
"==",
"desired",
"&&",
"newAvailable",
"==",
"desired",
"{",
"oldRc",
".",
"Spec",
".",
"Replicas",
"=",
"0",
"\n",
"}",
"\n",
"// Perform the scale-down.",
"fmt",
".",
"Fprintf",
"(",
"config",
".",
"Out",
",",
"\"",
"\\n",
"\"",
",",
"oldRc",
".",
"Name",
",",
"oldRc",
".",
"Spec",
".",
"Replicas",
")",
"\n",
"retryWait",
":=",
"&",
"RetryParams",
"{",
"config",
".",
"Interval",
",",
"config",
".",
"Timeout",
"}",
"\n",
"scaledRc",
",",
"err",
":=",
"r",
".",
"scaleAndWait",
"(",
"oldRc",
",",
"retryWait",
",",
"retryWait",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"scaledRc",
",",
"nil",
"\n",
"}"
] | // scaleDown scales down oldRc to 0 at whatever increment possible given the
// thresholds defined on the config. scaleDown will safely no-op as necessary
// when it detects redundancy or other relevant conditions. | [
"scaleDown",
"scales",
"down",
"oldRc",
"to",
"0",
"at",
"whatever",
"increment",
"possible",
"given",
"the",
"thresholds",
"defined",
"on",
"the",
"config",
".",
"scaleDown",
"will",
"safely",
"no",
"-",
"op",
"as",
"necessary",
"when",
"it",
"detects",
"redundancy",
"or",
"other",
"relevant",
"conditions",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/rolling_updater.go#L305-L349 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/rolling_updater.go | extractMaxValue | func extractMaxValue(field intstr.IntOrString, name string, value int) (int, error) {
switch field.Type {
case intstr.Int:
if field.IntVal < 0 {
return 0, fmt.Errorf("%s must be >= 0", name)
}
return field.IntValue(), nil
case intstr.String:
s := strings.Replace(field.StrVal, "%", "", -1)
v, err := strconv.Atoi(s)
if err != nil {
return 0, fmt.Errorf("invalid %s value %q: %v", name, field.StrVal, err)
}
if v < 0 {
return 0, fmt.Errorf("%s must be >= 0", name)
}
return int(math.Ceil(float64(value) * (float64(v)) / 100)), nil
}
return 0, fmt.Errorf("invalid kind %q for %s", field.Type, name)
} | go | func extractMaxValue(field intstr.IntOrString, name string, value int) (int, error) {
switch field.Type {
case intstr.Int:
if field.IntVal < 0 {
return 0, fmt.Errorf("%s must be >= 0", name)
}
return field.IntValue(), nil
case intstr.String:
s := strings.Replace(field.StrVal, "%", "", -1)
v, err := strconv.Atoi(s)
if err != nil {
return 0, fmt.Errorf("invalid %s value %q: %v", name, field.StrVal, err)
}
if v < 0 {
return 0, fmt.Errorf("%s must be >= 0", name)
}
return int(math.Ceil(float64(value) * (float64(v)) / 100)), nil
}
return 0, fmt.Errorf("invalid kind %q for %s", field.Type, name)
} | [
"func",
"extractMaxValue",
"(",
"field",
"intstr",
".",
"IntOrString",
",",
"name",
"string",
",",
"value",
"int",
")",
"(",
"int",
",",
"error",
")",
"{",
"switch",
"field",
".",
"Type",
"{",
"case",
"intstr",
".",
"Int",
":",
"if",
"field",
".",
"IntVal",
"<",
"0",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"field",
".",
"IntValue",
"(",
")",
",",
"nil",
"\n",
"case",
"intstr",
".",
"String",
":",
"s",
":=",
"strings",
".",
"Replace",
"(",
"field",
".",
"StrVal",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"v",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"field",
".",
"StrVal",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"v",
"<",
"0",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"return",
"int",
"(",
"math",
".",
"Ceil",
"(",
"float64",
"(",
"value",
")",
"*",
"(",
"float64",
"(",
"v",
")",
")",
"/",
"100",
")",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"field",
".",
"Type",
",",
"name",
")",
"\n",
"}"
] | // func extractMaxValue is a helper to extract config max values as either
// absolute numbers or based on percentages of the given value. | [
"func",
"extractMaxValue",
"is",
"a",
"helper",
"to",
"extract",
"config",
"max",
"values",
"as",
"either",
"absolute",
"numbers",
"or",
"based",
"on",
"percentages",
"of",
"the",
"given",
"value",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/rolling_updater.go#L495-L514 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/rolling_updater.go | updateWithRetries | func updateWithRetries(rcClient client.ReplicationControllerInterface, rc *api.ReplicationController, applyUpdate updateFunc) (*api.ReplicationController, error) {
var err error
oldRc := rc
err = wait.Poll(10*time.Millisecond, 1*time.Minute, func() (bool, error) {
// Apply the update, then attempt to push it to the apiserver.
applyUpdate(rc)
if rc, err = rcClient.Update(rc); err == nil {
// rc contains the latest controller post update
return true, nil
}
// Update the controller with the latest resource version, if the update failed we
// can't trust rc so use oldRc.Name.
if rc, err = rcClient.Get(oldRc.Name); err != nil {
// The Get failed: Value in rc cannot be trusted.
rc = oldRc
}
// The Get passed: rc contains the latest controller, expect a poll for the update.
return false, nil
})
// If the error is non-nil the returned controller cannot be trusted, if it is nil, the returned
// controller contains the applied update.
return rc, err
} | go | func updateWithRetries(rcClient client.ReplicationControllerInterface, rc *api.ReplicationController, applyUpdate updateFunc) (*api.ReplicationController, error) {
var err error
oldRc := rc
err = wait.Poll(10*time.Millisecond, 1*time.Minute, func() (bool, error) {
// Apply the update, then attempt to push it to the apiserver.
applyUpdate(rc)
if rc, err = rcClient.Update(rc); err == nil {
// rc contains the latest controller post update
return true, nil
}
// Update the controller with the latest resource version, if the update failed we
// can't trust rc so use oldRc.Name.
if rc, err = rcClient.Get(oldRc.Name); err != nil {
// The Get failed: Value in rc cannot be trusted.
rc = oldRc
}
// The Get passed: rc contains the latest controller, expect a poll for the update.
return false, nil
})
// If the error is non-nil the returned controller cannot be trusted, if it is nil, the returned
// controller contains the applied update.
return rc, err
} | [
"func",
"updateWithRetries",
"(",
"rcClient",
"client",
".",
"ReplicationControllerInterface",
",",
"rc",
"*",
"api",
".",
"ReplicationController",
",",
"applyUpdate",
"updateFunc",
")",
"(",
"*",
"api",
".",
"ReplicationController",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"oldRc",
":=",
"rc",
"\n",
"err",
"=",
"wait",
".",
"Poll",
"(",
"10",
"*",
"time",
".",
"Millisecond",
",",
"1",
"*",
"time",
".",
"Minute",
",",
"func",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// Apply the update, then attempt to push it to the apiserver.",
"applyUpdate",
"(",
"rc",
")",
"\n",
"if",
"rc",
",",
"err",
"=",
"rcClient",
".",
"Update",
"(",
"rc",
")",
";",
"err",
"==",
"nil",
"{",
"// rc contains the latest controller post update",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"// Update the controller with the latest resource version, if the update failed we",
"// can't trust rc so use oldRc.Name.",
"if",
"rc",
",",
"err",
"=",
"rcClient",
".",
"Get",
"(",
"oldRc",
".",
"Name",
")",
";",
"err",
"!=",
"nil",
"{",
"// The Get failed: Value in rc cannot be trusted.",
"rc",
"=",
"oldRc",
"\n",
"}",
"\n",
"// The Get passed: rc contains the latest controller, expect a poll for the update.",
"return",
"false",
",",
"nil",
"\n",
"}",
")",
"\n",
"// If the error is non-nil the returned controller cannot be trusted, if it is nil, the returned",
"// controller contains the applied update.",
"return",
"rc",
",",
"err",
"\n",
"}"
] | // updateWithRetries updates applies the given rc as an update. | [
"updateWithRetries",
"updates",
"applies",
"the",
"given",
"rc",
"as",
"an",
"update",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/rolling_updater.go#L726-L748 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/nodes.go | Create | func (c *nodes) Create(node *api.Node) (*api.Node, error) {
result := &api.Node{}
err := c.r.Post().Resource(c.resourceName()).Body(node).Do().Into(result)
return result, err
} | go | func (c *nodes) Create(node *api.Node) (*api.Node, error) {
result := &api.Node{}
err := c.r.Post().Resource(c.resourceName()).Body(node).Do().Into(result)
return result, err
} | [
"func",
"(",
"c",
"*",
"nodes",
")",
"Create",
"(",
"node",
"*",
"api",
".",
"Node",
")",
"(",
"*",
"api",
".",
"Node",
",",
"error",
")",
"{",
"result",
":=",
"&",
"api",
".",
"Node",
"{",
"}",
"\n",
"err",
":=",
"c",
".",
"r",
".",
"Post",
"(",
")",
".",
"Resource",
"(",
"c",
".",
"resourceName",
"(",
")",
")",
".",
"Body",
"(",
"node",
")",
".",
"Do",
"(",
")",
".",
"Into",
"(",
"result",
")",
"\n",
"return",
"result",
",",
"err",
"\n",
"}"
] | // Create creates a new node. | [
"Create",
"creates",
"a",
"new",
"node",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/nodes.go#L56-L60 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/nodes.go | Get | func (c *nodes) Get(name string) (*api.Node, error) {
result := &api.Node{}
err := c.r.Get().Resource(c.resourceName()).Name(name).Do().Into(result)
return result, err
} | go | func (c *nodes) Get(name string) (*api.Node, error) {
result := &api.Node{}
err := c.r.Get().Resource(c.resourceName()).Name(name).Do().Into(result)
return result, err
} | [
"func",
"(",
"c",
"*",
"nodes",
")",
"Get",
"(",
"name",
"string",
")",
"(",
"*",
"api",
".",
"Node",
",",
"error",
")",
"{",
"result",
":=",
"&",
"api",
".",
"Node",
"{",
"}",
"\n",
"err",
":=",
"c",
".",
"r",
".",
"Get",
"(",
")",
".",
"Resource",
"(",
"c",
".",
"resourceName",
"(",
")",
")",
".",
"Name",
"(",
"name",
")",
".",
"Do",
"(",
")",
".",
"Into",
"(",
"result",
")",
"\n",
"return",
"result",
",",
"err",
"\n",
"}"
] | // Get gets an existing node. | [
"Get",
"gets",
"an",
"existing",
"node",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/nodes.go#L70-L74 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/nodes.go | Delete | func (c *nodes) Delete(name string) error {
return c.r.Delete().Resource(c.resourceName()).Name(name).Do().Error()
} | go | func (c *nodes) Delete(name string) error {
return c.r.Delete().Resource(c.resourceName()).Name(name).Do().Error()
} | [
"func",
"(",
"c",
"*",
"nodes",
")",
"Delete",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"c",
".",
"r",
".",
"Delete",
"(",
")",
".",
"Resource",
"(",
"c",
".",
"resourceName",
"(",
")",
")",
".",
"Name",
"(",
"name",
")",
".",
"Do",
"(",
")",
".",
"Error",
"(",
")",
"\n",
"}"
] | // Delete deletes an existing node. | [
"Delete",
"deletes",
"an",
"existing",
"node",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/nodes.go#L77-L79 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/validation/validation.go | IsValidIPv4 | func IsValidIPv4(value string) bool {
return net.ParseIP(value) != nil && net.ParseIP(value).To4() != nil
} | go | func IsValidIPv4(value string) bool {
return net.ParseIP(value) != nil && net.ParseIP(value).To4() != nil
} | [
"func",
"IsValidIPv4",
"(",
"value",
"string",
")",
"bool",
"{",
"return",
"net",
".",
"ParseIP",
"(",
"value",
")",
"!=",
"nil",
"&&",
"net",
".",
"ParseIP",
"(",
"value",
")",
".",
"To4",
"(",
")",
"!=",
"nil",
"\n",
"}"
] | // IsValidIPv4 tests that the argument is a valid IPv4 address. | [
"IsValidIPv4",
"tests",
"that",
"the",
"argument",
"is",
"a",
"valid",
"IPv4",
"address",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/validation/validation.go#L139-L141 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/unversioned/group_version.go | IsEmpty | func (gvk GroupVersionKind) IsEmpty() bool {
return len(gvk.Group) == 0 && len(gvk.Version) == 0 && len(gvk.Kind) == 0
} | go | func (gvk GroupVersionKind) IsEmpty() bool {
return len(gvk.Group) == 0 && len(gvk.Version) == 0 && len(gvk.Kind) == 0
} | [
"func",
"(",
"gvk",
"GroupVersionKind",
")",
"IsEmpty",
"(",
")",
"bool",
"{",
"return",
"len",
"(",
"gvk",
".",
"Group",
")",
"==",
"0",
"&&",
"len",
"(",
"gvk",
".",
"Version",
")",
"==",
"0",
"&&",
"len",
"(",
"gvk",
".",
"Kind",
")",
"==",
"0",
"\n",
"}"
] | // IsEmpty returns true if group, version, and kind are empty | [
"IsEmpty",
"returns",
"true",
"if",
"group",
"version",
"and",
"kind",
"are",
"empty"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/unversioned/group_version.go#L102-L104 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/unversioned/group_version.go | IsEmpty | func (gv GroupVersion) IsEmpty() bool {
return len(gv.Group) == 0 && len(gv.Version) == 0
} | go | func (gv GroupVersion) IsEmpty() bool {
return len(gv.Group) == 0 && len(gv.Version) == 0
} | [
"func",
"(",
"gv",
"GroupVersion",
")",
"IsEmpty",
"(",
")",
"bool",
"{",
"return",
"len",
"(",
"gv",
".",
"Group",
")",
"==",
"0",
"&&",
"len",
"(",
"gv",
".",
"Version",
")",
"==",
"0",
"\n",
"}"
] | // IsEmpty returns true if group and version are empty | [
"IsEmpty",
"returns",
"true",
"if",
"group",
"and",
"version",
"are",
"empty"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/unversioned/group_version.go#L127-L129 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/describe.go | DescribableResources | func DescribableResources() []string {
keys := make([]string, 0)
for k := range describerMap(nil) {
resource := strings.ToLower(k.Kind)
keys = append(keys, resource)
}
return keys
} | go | func DescribableResources() []string {
keys := make([]string, 0)
for k := range describerMap(nil) {
resource := strings.ToLower(k.Kind)
keys = append(keys, resource)
}
return keys
} | [
"func",
"DescribableResources",
"(",
")",
"[",
"]",
"string",
"{",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n\n",
"for",
"k",
":=",
"range",
"describerMap",
"(",
"nil",
")",
"{",
"resource",
":=",
"strings",
".",
"ToLower",
"(",
"k",
".",
"Kind",
")",
"\n",
"keys",
"=",
"append",
"(",
"keys",
",",
"resource",
")",
"\n",
"}",
"\n",
"return",
"keys",
"\n",
"}"
] | // List of all resource types we can describe | [
"List",
"of",
"all",
"resource",
"types",
"we",
"can",
"describe"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/describe.go#L106-L114 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/describe.go | DescriberFor | func DescriberFor(kind unversioned.GroupKind, c *client.Client) (Describer, bool) {
f, ok := describerMap(c)[kind]
return f, ok
} | go | func DescriberFor(kind unversioned.GroupKind, c *client.Client) (Describer, bool) {
f, ok := describerMap(c)[kind]
return f, ok
} | [
"func",
"DescriberFor",
"(",
"kind",
"unversioned",
".",
"GroupKind",
",",
"c",
"*",
"client",
".",
"Client",
")",
"(",
"Describer",
",",
"bool",
")",
"{",
"f",
",",
"ok",
":=",
"describerMap",
"(",
"c",
")",
"[",
"kind",
"]",
"\n",
"return",
"f",
",",
"ok",
"\n",
"}"
] | // Describer returns the default describe functions for each of the standard
// Kubernetes types. | [
"Describer",
"returns",
"the",
"default",
"describe",
"functions",
"for",
"each",
"of",
"the",
"standard",
"Kubernetes",
"types",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/describe.go#L118-L121 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/describe.go | DescribeContainers | func DescribeContainers(containers []api.Container, containerStatuses []api.ContainerStatus, resolverFn EnvVarResolverFunc, out io.Writer) {
statuses := map[string]api.ContainerStatus{}
for _, status := range containerStatuses {
statuses[status.Name] = status
}
for _, container := range containers {
status := statuses[container.Name]
state := status.State
fmt.Fprintf(out, " %v:\n", container.Name)
fmt.Fprintf(out, " Container ID:\t%s\n", status.ContainerID)
fmt.Fprintf(out, " Image:\t%s\n", container.Image)
fmt.Fprintf(out, " Image ID:\t%s\n", status.ImageID)
if len(container.Command) > 0 {
fmt.Fprintf(out, " Command:\n")
for _, c := range container.Command {
fmt.Fprintf(out, " %s\n", c)
}
}
if len(container.Args) > 0 {
fmt.Fprintf(out, " Args:\n")
for _, arg := range container.Args {
fmt.Fprintf(out, " %s\n", arg)
}
}
resourceToQoS := qosutil.GetQoS(&container)
if len(resourceToQoS) > 0 {
fmt.Fprintf(out, " QoS Tier:\n")
}
for resource, qos := range resourceToQoS {
fmt.Fprintf(out, " %s:\t%s\n", resource, qos)
}
if len(container.Resources.Limits) > 0 {
fmt.Fprintf(out, " Limits:\n")
}
for name, quantity := range container.Resources.Limits {
fmt.Fprintf(out, " %s:\t%s\n", name, quantity.String())
}
if len(container.Resources.Requests) > 0 {
fmt.Fprintf(out, " Requests:\n")
}
for name, quantity := range container.Resources.Requests {
fmt.Fprintf(out, " %s:\t%s\n", name, quantity.String())
}
describeStatus("State", state, out)
if status.LastTerminationState.Terminated != nil {
describeStatus("Last State", status.LastTerminationState, out)
}
fmt.Fprintf(out, " Ready:\t%v\n", printBool(status.Ready))
fmt.Fprintf(out, " Restart Count:\t%d\n", status.RestartCount)
if container.LivenessProbe != nil {
probe := DescribeProbe(container.LivenessProbe)
fmt.Fprintf(out, " Liveness:\t%s\n", probe)
}
if container.ReadinessProbe != nil {
probe := DescribeProbe(container.ReadinessProbe)
fmt.Fprintf(out, " Readiness:\t%s\n", probe)
}
fmt.Fprintf(out, " Environment Variables:\n")
for _, e := range container.Env {
if e.ValueFrom != nil && e.ValueFrom.FieldRef != nil {
var valueFrom string
if resolverFn != nil {
valueFrom = resolverFn(e)
}
fmt.Fprintf(out, " %s:\t%s (%s:%s)\n", e.Name, valueFrom, e.ValueFrom.FieldRef.APIVersion, e.ValueFrom.FieldRef.FieldPath)
} else {
fmt.Fprintf(out, " %s:\t%s\n", e.Name, e.Value)
}
}
}
} | go | func DescribeContainers(containers []api.Container, containerStatuses []api.ContainerStatus, resolverFn EnvVarResolverFunc, out io.Writer) {
statuses := map[string]api.ContainerStatus{}
for _, status := range containerStatuses {
statuses[status.Name] = status
}
for _, container := range containers {
status := statuses[container.Name]
state := status.State
fmt.Fprintf(out, " %v:\n", container.Name)
fmt.Fprintf(out, " Container ID:\t%s\n", status.ContainerID)
fmt.Fprintf(out, " Image:\t%s\n", container.Image)
fmt.Fprintf(out, " Image ID:\t%s\n", status.ImageID)
if len(container.Command) > 0 {
fmt.Fprintf(out, " Command:\n")
for _, c := range container.Command {
fmt.Fprintf(out, " %s\n", c)
}
}
if len(container.Args) > 0 {
fmt.Fprintf(out, " Args:\n")
for _, arg := range container.Args {
fmt.Fprintf(out, " %s\n", arg)
}
}
resourceToQoS := qosutil.GetQoS(&container)
if len(resourceToQoS) > 0 {
fmt.Fprintf(out, " QoS Tier:\n")
}
for resource, qos := range resourceToQoS {
fmt.Fprintf(out, " %s:\t%s\n", resource, qos)
}
if len(container.Resources.Limits) > 0 {
fmt.Fprintf(out, " Limits:\n")
}
for name, quantity := range container.Resources.Limits {
fmt.Fprintf(out, " %s:\t%s\n", name, quantity.String())
}
if len(container.Resources.Requests) > 0 {
fmt.Fprintf(out, " Requests:\n")
}
for name, quantity := range container.Resources.Requests {
fmt.Fprintf(out, " %s:\t%s\n", name, quantity.String())
}
describeStatus("State", state, out)
if status.LastTerminationState.Terminated != nil {
describeStatus("Last State", status.LastTerminationState, out)
}
fmt.Fprintf(out, " Ready:\t%v\n", printBool(status.Ready))
fmt.Fprintf(out, " Restart Count:\t%d\n", status.RestartCount)
if container.LivenessProbe != nil {
probe := DescribeProbe(container.LivenessProbe)
fmt.Fprintf(out, " Liveness:\t%s\n", probe)
}
if container.ReadinessProbe != nil {
probe := DescribeProbe(container.ReadinessProbe)
fmt.Fprintf(out, " Readiness:\t%s\n", probe)
}
fmt.Fprintf(out, " Environment Variables:\n")
for _, e := range container.Env {
if e.ValueFrom != nil && e.ValueFrom.FieldRef != nil {
var valueFrom string
if resolverFn != nil {
valueFrom = resolverFn(e)
}
fmt.Fprintf(out, " %s:\t%s (%s:%s)\n", e.Name, valueFrom, e.ValueFrom.FieldRef.APIVersion, e.ValueFrom.FieldRef.FieldPath)
} else {
fmt.Fprintf(out, " %s:\t%s\n", e.Name, e.Value)
}
}
}
} | [
"func",
"DescribeContainers",
"(",
"containers",
"[",
"]",
"api",
".",
"Container",
",",
"containerStatuses",
"[",
"]",
"api",
".",
"ContainerStatus",
",",
"resolverFn",
"EnvVarResolverFunc",
",",
"out",
"io",
".",
"Writer",
")",
"{",
"statuses",
":=",
"map",
"[",
"string",
"]",
"api",
".",
"ContainerStatus",
"{",
"}",
"\n",
"for",
"_",
",",
"status",
":=",
"range",
"containerStatuses",
"{",
"statuses",
"[",
"status",
".",
"Name",
"]",
"=",
"status",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"container",
":=",
"range",
"containers",
"{",
"status",
":=",
"statuses",
"[",
"container",
".",
"Name",
"]",
"\n",
"state",
":=",
"status",
".",
"State",
"\n\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\n",
"\"",
",",
"container",
".",
"Name",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"status",
".",
"ContainerID",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"container",
".",
"Image",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"status",
".",
"ImageID",
")",
"\n\n",
"if",
"len",
"(",
"container",
".",
"Command",
")",
">",
"0",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"container",
".",
"Command",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\n",
"\"",
",",
"c",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"container",
".",
"Args",
")",
">",
"0",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"for",
"_",
",",
"arg",
":=",
"range",
"container",
".",
"Args",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\n",
"\"",
",",
"arg",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"resourceToQoS",
":=",
"qosutil",
".",
"GetQoS",
"(",
"&",
"container",
")",
"\n",
"if",
"len",
"(",
"resourceToQoS",
")",
">",
"0",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"for",
"resource",
",",
"qos",
":=",
"range",
"resourceToQoS",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"resource",
",",
"qos",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"container",
".",
"Resources",
".",
"Limits",
")",
">",
"0",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"for",
"name",
",",
"quantity",
":=",
"range",
"container",
".",
"Resources",
".",
"Limits",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"name",
",",
"quantity",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"container",
".",
"Resources",
".",
"Requests",
")",
">",
"0",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"for",
"name",
",",
"quantity",
":=",
"range",
"container",
".",
"Resources",
".",
"Requests",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"name",
",",
"quantity",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"describeStatus",
"(",
"\"",
"\"",
",",
"state",
",",
"out",
")",
"\n",
"if",
"status",
".",
"LastTerminationState",
".",
"Terminated",
"!=",
"nil",
"{",
"describeStatus",
"(",
"\"",
"\"",
",",
"status",
".",
"LastTerminationState",
",",
"out",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"printBool",
"(",
"status",
".",
"Ready",
")",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"status",
".",
"RestartCount",
")",
"\n\n",
"if",
"container",
".",
"LivenessProbe",
"!=",
"nil",
"{",
"probe",
":=",
"DescribeProbe",
"(",
"container",
".",
"LivenessProbe",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"probe",
")",
"\n",
"}",
"\n",
"if",
"container",
".",
"ReadinessProbe",
"!=",
"nil",
"{",
"probe",
":=",
"DescribeProbe",
"(",
"container",
".",
"ReadinessProbe",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"probe",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"container",
".",
"Env",
"{",
"if",
"e",
".",
"ValueFrom",
"!=",
"nil",
"&&",
"e",
".",
"ValueFrom",
".",
"FieldRef",
"!=",
"nil",
"{",
"var",
"valueFrom",
"string",
"\n",
"if",
"resolverFn",
"!=",
"nil",
"{",
"valueFrom",
"=",
"resolverFn",
"(",
"e",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"e",
".",
"Name",
",",
"valueFrom",
",",
"e",
".",
"ValueFrom",
".",
"FieldRef",
".",
"APIVersion",
",",
"e",
".",
"ValueFrom",
".",
"FieldRef",
".",
"FieldPath",
")",
"\n",
"}",
"else",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"e",
".",
"Name",
",",
"e",
".",
"Value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // DescribeContainers is exported for consumers in other API groups that have container templates | [
"DescribeContainers",
"is",
"exported",
"for",
"consumers",
"in",
"other",
"API",
"groups",
"that",
"have",
"container",
"templates"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/describe.go#L718-L796 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/scale.go | Get | func (c *scales) Get(kind string, name string) (result *extensions.Scale, err error) {
result = &extensions.Scale{}
// TODO this method needs to take a proper unambiguous kind
fullyQualifiedKind := unversioned.GroupVersionKind{Kind: kind}
resource, _ := meta.KindToResource(fullyQualifiedKind)
err = c.client.Get().Namespace(c.ns).Resource(resource.Resource).Name(name).SubResource("scale").Do().Into(result)
return
} | go | func (c *scales) Get(kind string, name string) (result *extensions.Scale, err error) {
result = &extensions.Scale{}
// TODO this method needs to take a proper unambiguous kind
fullyQualifiedKind := unversioned.GroupVersionKind{Kind: kind}
resource, _ := meta.KindToResource(fullyQualifiedKind)
err = c.client.Get().Namespace(c.ns).Resource(resource.Resource).Name(name).SubResource("scale").Do().Into(result)
return
} | [
"func",
"(",
"c",
"*",
"scales",
")",
"Get",
"(",
"kind",
"string",
",",
"name",
"string",
")",
"(",
"result",
"*",
"extensions",
".",
"Scale",
",",
"err",
"error",
")",
"{",
"result",
"=",
"&",
"extensions",
".",
"Scale",
"{",
"}",
"\n\n",
"// TODO this method needs to take a proper unambiguous kind",
"fullyQualifiedKind",
":=",
"unversioned",
".",
"GroupVersionKind",
"{",
"Kind",
":",
"kind",
"}",
"\n",
"resource",
",",
"_",
":=",
"meta",
".",
"KindToResource",
"(",
"fullyQualifiedKind",
")",
"\n\n",
"err",
"=",
"c",
".",
"client",
".",
"Get",
"(",
")",
".",
"Namespace",
"(",
"c",
".",
"ns",
")",
".",
"Resource",
"(",
"resource",
".",
"Resource",
")",
".",
"Name",
"(",
"name",
")",
".",
"SubResource",
"(",
"\"",
"\"",
")",
".",
"Do",
"(",
")",
".",
"Into",
"(",
"result",
")",
"\n",
"return",
"\n",
"}"
] | // Get takes the reference to scale subresource and returns the subresource or error, if one occurs. | [
"Get",
"takes",
"the",
"reference",
"to",
"scale",
"subresource",
"and",
"returns",
"the",
"subresource",
"or",
"error",
"if",
"one",
"occurs",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/scale.go#L50-L59 | train |
kubernetes-retired/contrib | service-loadbalancer/service_loadbalancer.go | Getfunc | func (s *staticPageHandler) Getfunc(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(s.returnCode)
w.Write(s.pageContents)
} | go | func (s *staticPageHandler) Getfunc(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(s.returnCode)
w.Write(s.pageContents)
} | [
"func",
"(",
"s",
"*",
"staticPageHandler",
")",
"Getfunc",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"w",
".",
"WriteHeader",
"(",
"s",
".",
"returnCode",
")",
"\n",
"w",
".",
"Write",
"(",
"s",
".",
"pageContents",
")",
"\n",
"}"
] | // Get serves the error page | [
"Get",
"serves",
"the",
"error",
"page"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/service_loadbalancer.go#L252-L255 | train |
kubernetes-retired/contrib | service-loadbalancer/service_loadbalancer.go | write | func (cfg *loadBalancerConfig) write(services map[string][]service, dryRun bool) (err error) {
var w io.Writer
if dryRun {
w = os.Stdout
} else {
w, err = os.Create(cfg.Config)
if err != nil {
return
}
}
var t *template.Template
t, err = template.ParseFiles(cfg.Template)
if err != nil {
return
}
conf := make(map[string]interface{})
conf["startSyslog"] = strconv.FormatBool(cfg.startSyslog)
conf["services"] = services
var sslConfig string
if cfg.sslCert != "" {
sslConfig = "crt " + cfg.sslCert
}
if cfg.sslCaCert != "" {
sslConfig += " ca-file " + cfg.sslCaCert
}
conf["sslCert"] = sslConfig
// default load balancer algorithm is roundrobin
conf["defLbAlgorithm"] = lbDefAlgorithm
if cfg.lbDefAlgorithm != "" {
conf["defLbAlgorithm"] = cfg.lbDefAlgorithm
}
err = t.Execute(w, conf)
return
} | go | func (cfg *loadBalancerConfig) write(services map[string][]service, dryRun bool) (err error) {
var w io.Writer
if dryRun {
w = os.Stdout
} else {
w, err = os.Create(cfg.Config)
if err != nil {
return
}
}
var t *template.Template
t, err = template.ParseFiles(cfg.Template)
if err != nil {
return
}
conf := make(map[string]interface{})
conf["startSyslog"] = strconv.FormatBool(cfg.startSyslog)
conf["services"] = services
var sslConfig string
if cfg.sslCert != "" {
sslConfig = "crt " + cfg.sslCert
}
if cfg.sslCaCert != "" {
sslConfig += " ca-file " + cfg.sslCaCert
}
conf["sslCert"] = sslConfig
// default load balancer algorithm is roundrobin
conf["defLbAlgorithm"] = lbDefAlgorithm
if cfg.lbDefAlgorithm != "" {
conf["defLbAlgorithm"] = cfg.lbDefAlgorithm
}
err = t.Execute(w, conf)
return
} | [
"func",
"(",
"cfg",
"*",
"loadBalancerConfig",
")",
"write",
"(",
"services",
"map",
"[",
"string",
"]",
"[",
"]",
"service",
",",
"dryRun",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"var",
"w",
"io",
".",
"Writer",
"\n",
"if",
"dryRun",
"{",
"w",
"=",
"os",
".",
"Stdout",
"\n",
"}",
"else",
"{",
"w",
",",
"err",
"=",
"os",
".",
"Create",
"(",
"cfg",
".",
"Config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"t",
"*",
"template",
".",
"Template",
"\n",
"t",
",",
"err",
"=",
"template",
".",
"ParseFiles",
"(",
"cfg",
".",
"Template",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"conf",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"strconv",
".",
"FormatBool",
"(",
"cfg",
".",
"startSyslog",
")",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"services",
"\n\n",
"var",
"sslConfig",
"string",
"\n",
"if",
"cfg",
".",
"sslCert",
"!=",
"\"",
"\"",
"{",
"sslConfig",
"=",
"\"",
"\"",
"+",
"cfg",
".",
"sslCert",
"\n",
"}",
"\n",
"if",
"cfg",
".",
"sslCaCert",
"!=",
"\"",
"\"",
"{",
"sslConfig",
"+=",
"\"",
"\"",
"+",
"cfg",
".",
"sslCaCert",
"\n",
"}",
"\n",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"sslConfig",
"\n\n",
"// default load balancer algorithm is roundrobin",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"lbDefAlgorithm",
"\n",
"if",
"cfg",
".",
"lbDefAlgorithm",
"!=",
"\"",
"\"",
"{",
"conf",
"[",
"\"",
"\"",
"]",
"=",
"cfg",
".",
"lbDefAlgorithm",
"\n",
"}",
"\n\n",
"err",
"=",
"t",
".",
"Execute",
"(",
"w",
",",
"conf",
")",
"\n",
"return",
"\n",
"}"
] | // write writes the configuration file, will write to stdout if dryRun == true | [
"write",
"writes",
"the",
"configuration",
"file",
"will",
"write",
"to",
"stdout",
"if",
"dryRun",
"==",
"true"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/service_loadbalancer.go#L292-L329 | train |
kubernetes-retired/contrib | service-loadbalancer/service_loadbalancer.go | reload | func (cfg *loadBalancerConfig) reload() error {
output, err := exec.Command("sh", "-c", cfg.ReloadCmd).CombinedOutput()
msg := fmt.Sprintf("%v -- %v", cfg.Name, string(output))
if err != nil {
return fmt.Errorf("error restarting %v: %v", msg, err)
}
glog.Infof(msg)
return nil
} | go | func (cfg *loadBalancerConfig) reload() error {
output, err := exec.Command("sh", "-c", cfg.ReloadCmd).CombinedOutput()
msg := fmt.Sprintf("%v -- %v", cfg.Name, string(output))
if err != nil {
return fmt.Errorf("error restarting %v: %v", msg, err)
}
glog.Infof(msg)
return nil
} | [
"func",
"(",
"cfg",
"*",
"loadBalancerConfig",
")",
"reload",
"(",
")",
"error",
"{",
"output",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cfg",
".",
"ReloadCmd",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cfg",
".",
"Name",
",",
"string",
"(",
"output",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"msg",
",",
"err",
")",
"\n",
"}",
"\n",
"glog",
".",
"Infof",
"(",
"msg",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // reload reloads the loadbalancer using the reload cmd specified in the json manifest. | [
"reload",
"reloads",
"the",
"loadbalancer",
"using",
"the",
"reload",
"cmd",
"specified",
"in",
"the",
"json",
"manifest",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/service_loadbalancer.go#L332-L340 | train |
kubernetes-retired/contrib | service-loadbalancer/service_loadbalancer.go | sync | func (lbc *loadBalancerController) sync(dryRun bool) error {
if !lbc.epController.HasSynced() || !lbc.svcController.HasSynced() {
time.Sleep(100 * time.Millisecond)
return errDeferredSync
}
httpSvc, httpsTermSvc, tcpSvc := lbc.getServices()
if len(httpSvc) == 0 && len(httpsTermSvc) == 0 && len(tcpSvc) == 0 {
return nil
}
if err := lbc.cfg.write(
map[string][]service{
"http": httpSvc,
"httpsTerm": httpsTermSvc,
"tcp": tcpSvc,
}, dryRun); err != nil {
return err
}
if dryRun {
return nil
}
return lbc.cfg.reload()
} | go | func (lbc *loadBalancerController) sync(dryRun bool) error {
if !lbc.epController.HasSynced() || !lbc.svcController.HasSynced() {
time.Sleep(100 * time.Millisecond)
return errDeferredSync
}
httpSvc, httpsTermSvc, tcpSvc := lbc.getServices()
if len(httpSvc) == 0 && len(httpsTermSvc) == 0 && len(tcpSvc) == 0 {
return nil
}
if err := lbc.cfg.write(
map[string][]service{
"http": httpSvc,
"httpsTerm": httpsTermSvc,
"tcp": tcpSvc,
}, dryRun); err != nil {
return err
}
if dryRun {
return nil
}
return lbc.cfg.reload()
} | [
"func",
"(",
"lbc",
"*",
"loadBalancerController",
")",
"sync",
"(",
"dryRun",
"bool",
")",
"error",
"{",
"if",
"!",
"lbc",
".",
"epController",
".",
"HasSynced",
"(",
")",
"||",
"!",
"lbc",
".",
"svcController",
".",
"HasSynced",
"(",
")",
"{",
"time",
".",
"Sleep",
"(",
"100",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"return",
"errDeferredSync",
"\n",
"}",
"\n",
"httpSvc",
",",
"httpsTermSvc",
",",
"tcpSvc",
":=",
"lbc",
".",
"getServices",
"(",
")",
"\n",
"if",
"len",
"(",
"httpSvc",
")",
"==",
"0",
"&&",
"len",
"(",
"httpsTermSvc",
")",
"==",
"0",
"&&",
"len",
"(",
"tcpSvc",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"err",
":=",
"lbc",
".",
"cfg",
".",
"write",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"service",
"{",
"\"",
"\"",
":",
"httpSvc",
",",
"\"",
"\"",
":",
"httpsTermSvc",
",",
"\"",
"\"",
":",
"tcpSvc",
",",
"}",
",",
"dryRun",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"dryRun",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"lbc",
".",
"cfg",
".",
"reload",
"(",
")",
"\n",
"}"
] | // sync all services with the loadbalancer. | [
"sync",
"all",
"services",
"with",
"the",
"loadbalancer",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/service_loadbalancer.go#L509-L530 | train |
kubernetes-retired/contrib | service-loadbalancer/service_loadbalancer.go | worker | func (lbc *loadBalancerController) worker() {
for {
key, _ := lbc.queue.Get()
glog.Infof("Sync triggered by service %v", key)
if err := lbc.sync(false); err != nil {
glog.Warningf("Requeuing %v because of error: %v", key, err)
lbc.queue.Add(key)
}
lbc.queue.Done(key)
}
} | go | func (lbc *loadBalancerController) worker() {
for {
key, _ := lbc.queue.Get()
glog.Infof("Sync triggered by service %v", key)
if err := lbc.sync(false); err != nil {
glog.Warningf("Requeuing %v because of error: %v", key, err)
lbc.queue.Add(key)
}
lbc.queue.Done(key)
}
} | [
"func",
"(",
"lbc",
"*",
"loadBalancerController",
")",
"worker",
"(",
")",
"{",
"for",
"{",
"key",
",",
"_",
":=",
"lbc",
".",
"queue",
".",
"Get",
"(",
")",
"\n",
"glog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"if",
"err",
":=",
"lbc",
".",
"sync",
"(",
"false",
")",
";",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"key",
",",
"err",
")",
"\n",
"lbc",
".",
"queue",
".",
"Add",
"(",
"key",
")",
"\n",
"}",
"\n",
"lbc",
".",
"queue",
".",
"Done",
"(",
"key",
")",
"\n",
"}",
"\n",
"}"
] | // worker handles the work queue. | [
"worker",
"handles",
"the",
"work",
"queue",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/service_loadbalancer.go#L533-L543 | train |
kubernetes-retired/contrib | service-loadbalancer/service_loadbalancer.go | newLoadBalancerController | func newLoadBalancerController(cfg *loadBalancerConfig, kubeClient *unversioned.Client, namespace string, tcpServices map[string]int) *loadBalancerController {
lbc := loadBalancerController{
cfg: cfg,
client: kubeClient,
queue: workqueue.New(),
reloadRateLimiter: util.NewTokenBucketRateLimiter(
reloadQPS, int(reloadQPS)),
targetService: *targetService,
forwardServices: *forwardServices,
httpPort: *httpPort,
tcpServices: tcpServices,
}
enqueue := func(obj interface{}) {
key, err := keyFunc(obj)
if err != nil {
glog.Infof("Couldn't get key for object %+v: %v", obj, err)
return
}
lbc.queue.Add(key)
}
eventHandlers := framework.ResourceEventHandlerFuncs{
AddFunc: enqueue,
DeleteFunc: enqueue,
UpdateFunc: func(old, cur interface{}) {
if !reflect.DeepEqual(old, cur) {
enqueue(cur)
}
},
}
lbc.svcLister.Store, lbc.svcController = framework.NewInformer(
cache.NewListWatchFromClient(
lbc.client, "services", namespace, fields.Everything()),
&api.Service{}, resyncPeriod, eventHandlers)
lbc.epLister.Store, lbc.epController = framework.NewInformer(
cache.NewListWatchFromClient(
lbc.client, "endpoints", namespace, fields.Everything()),
&api.Endpoints{}, resyncPeriod, eventHandlers)
return &lbc
} | go | func newLoadBalancerController(cfg *loadBalancerConfig, kubeClient *unversioned.Client, namespace string, tcpServices map[string]int) *loadBalancerController {
lbc := loadBalancerController{
cfg: cfg,
client: kubeClient,
queue: workqueue.New(),
reloadRateLimiter: util.NewTokenBucketRateLimiter(
reloadQPS, int(reloadQPS)),
targetService: *targetService,
forwardServices: *forwardServices,
httpPort: *httpPort,
tcpServices: tcpServices,
}
enqueue := func(obj interface{}) {
key, err := keyFunc(obj)
if err != nil {
glog.Infof("Couldn't get key for object %+v: %v", obj, err)
return
}
lbc.queue.Add(key)
}
eventHandlers := framework.ResourceEventHandlerFuncs{
AddFunc: enqueue,
DeleteFunc: enqueue,
UpdateFunc: func(old, cur interface{}) {
if !reflect.DeepEqual(old, cur) {
enqueue(cur)
}
},
}
lbc.svcLister.Store, lbc.svcController = framework.NewInformer(
cache.NewListWatchFromClient(
lbc.client, "services", namespace, fields.Everything()),
&api.Service{}, resyncPeriod, eventHandlers)
lbc.epLister.Store, lbc.epController = framework.NewInformer(
cache.NewListWatchFromClient(
lbc.client, "endpoints", namespace, fields.Everything()),
&api.Endpoints{}, resyncPeriod, eventHandlers)
return &lbc
} | [
"func",
"newLoadBalancerController",
"(",
"cfg",
"*",
"loadBalancerConfig",
",",
"kubeClient",
"*",
"unversioned",
".",
"Client",
",",
"namespace",
"string",
",",
"tcpServices",
"map",
"[",
"string",
"]",
"int",
")",
"*",
"loadBalancerController",
"{",
"lbc",
":=",
"loadBalancerController",
"{",
"cfg",
":",
"cfg",
",",
"client",
":",
"kubeClient",
",",
"queue",
":",
"workqueue",
".",
"New",
"(",
")",
",",
"reloadRateLimiter",
":",
"util",
".",
"NewTokenBucketRateLimiter",
"(",
"reloadQPS",
",",
"int",
"(",
"reloadQPS",
")",
")",
",",
"targetService",
":",
"*",
"targetService",
",",
"forwardServices",
":",
"*",
"forwardServices",
",",
"httpPort",
":",
"*",
"httpPort",
",",
"tcpServices",
":",
"tcpServices",
",",
"}",
"\n\n",
"enqueue",
":=",
"func",
"(",
"obj",
"interface",
"{",
"}",
")",
"{",
"key",
",",
"err",
":=",
"keyFunc",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"obj",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"lbc",
".",
"queue",
".",
"Add",
"(",
"key",
")",
"\n",
"}",
"\n",
"eventHandlers",
":=",
"framework",
".",
"ResourceEventHandlerFuncs",
"{",
"AddFunc",
":",
"enqueue",
",",
"DeleteFunc",
":",
"enqueue",
",",
"UpdateFunc",
":",
"func",
"(",
"old",
",",
"cur",
"interface",
"{",
"}",
")",
"{",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"old",
",",
"cur",
")",
"{",
"enqueue",
"(",
"cur",
")",
"\n",
"}",
"\n",
"}",
",",
"}",
"\n\n",
"lbc",
".",
"svcLister",
".",
"Store",
",",
"lbc",
".",
"svcController",
"=",
"framework",
".",
"NewInformer",
"(",
"cache",
".",
"NewListWatchFromClient",
"(",
"lbc",
".",
"client",
",",
"\"",
"\"",
",",
"namespace",
",",
"fields",
".",
"Everything",
"(",
")",
")",
",",
"&",
"api",
".",
"Service",
"{",
"}",
",",
"resyncPeriod",
",",
"eventHandlers",
")",
"\n\n",
"lbc",
".",
"epLister",
".",
"Store",
",",
"lbc",
".",
"epController",
"=",
"framework",
".",
"NewInformer",
"(",
"cache",
".",
"NewListWatchFromClient",
"(",
"lbc",
".",
"client",
",",
"\"",
"\"",
",",
"namespace",
",",
"fields",
".",
"Everything",
"(",
")",
")",
",",
"&",
"api",
".",
"Endpoints",
"{",
"}",
",",
"resyncPeriod",
",",
"eventHandlers",
")",
"\n\n",
"return",
"&",
"lbc",
"\n",
"}"
] | // newLoadBalancerController creates a new controller from the given config. | [
"newLoadBalancerController",
"creates",
"a",
"new",
"controller",
"from",
"the",
"given",
"config",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/service_loadbalancer.go#L546-L588 | train |
kubernetes-retired/contrib | service-loadbalancer/service_loadbalancer.go | parseCfg | func parseCfg(configPath string, defLbAlgorithm string, sslCert string, sslCaCert string) *loadBalancerConfig {
jsonBlob, err := ioutil.ReadFile(configPath)
if err != nil {
glog.Fatalf("Could not parse lb config: %v", err)
}
var cfg loadBalancerConfig
err = json.Unmarshal(jsonBlob, &cfg)
if err != nil {
glog.Fatalf("Unable to unmarshal json blob: %v", string(jsonBlob))
}
cfg.sslCert = sslCert
cfg.sslCaCert = sslCaCert
cfg.lbDefAlgorithm = defLbAlgorithm
glog.Infof("Creating new loadbalancer: %+v", cfg)
return &cfg
} | go | func parseCfg(configPath string, defLbAlgorithm string, sslCert string, sslCaCert string) *loadBalancerConfig {
jsonBlob, err := ioutil.ReadFile(configPath)
if err != nil {
glog.Fatalf("Could not parse lb config: %v", err)
}
var cfg loadBalancerConfig
err = json.Unmarshal(jsonBlob, &cfg)
if err != nil {
glog.Fatalf("Unable to unmarshal json blob: %v", string(jsonBlob))
}
cfg.sslCert = sslCert
cfg.sslCaCert = sslCaCert
cfg.lbDefAlgorithm = defLbAlgorithm
glog.Infof("Creating new loadbalancer: %+v", cfg)
return &cfg
} | [
"func",
"parseCfg",
"(",
"configPath",
"string",
",",
"defLbAlgorithm",
"string",
",",
"sslCert",
"string",
",",
"sslCaCert",
"string",
")",
"*",
"loadBalancerConfig",
"{",
"jsonBlob",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"configPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"var",
"cfg",
"loadBalancerConfig",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"jsonBlob",
",",
"&",
"cfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"string",
"(",
"jsonBlob",
")",
")",
"\n",
"}",
"\n",
"cfg",
".",
"sslCert",
"=",
"sslCert",
"\n",
"cfg",
".",
"sslCaCert",
"=",
"sslCaCert",
"\n",
"cfg",
".",
"lbDefAlgorithm",
"=",
"defLbAlgorithm",
"\n",
"glog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"cfg",
")",
"\n",
"return",
"&",
"cfg",
"\n",
"}"
] | // parseCfg parses the given configuration file.
// cmd line params take precedence over config directives. | [
"parseCfg",
"parses",
"the",
"given",
"configuration",
"file",
".",
"cmd",
"line",
"params",
"take",
"precedence",
"over",
"config",
"directives",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/service_loadbalancer.go#L592-L607 | train |
kubernetes-retired/contrib | service-loadbalancer/service_loadbalancer.go | registerHandlers | func registerHandlers(s *staticPageHandler) {
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
// Delegate a check to the haproxy stats service.
response, err := http.Get(fmt.Sprintf("http://localhost:%v", *statsPort))
if err != nil {
glog.Infof("Error %v", err)
w.WriteHeader(http.StatusInternalServerError)
} else {
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
glog.Infof("Error reading resonse on receiving status %v: %v",
response.StatusCode, err)
}
glog.Infof("%v\n", string(contents))
w.WriteHeader(response.StatusCode)
} else {
w.WriteHeader(200)
w.Write([]byte("ok"))
}
}
})
// handler for not matched traffic
http.HandleFunc("/", s.Getfunc)
glog.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", lbApiPort), nil))
} | go | func registerHandlers(s *staticPageHandler) {
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
// Delegate a check to the haproxy stats service.
response, err := http.Get(fmt.Sprintf("http://localhost:%v", *statsPort))
if err != nil {
glog.Infof("Error %v", err)
w.WriteHeader(http.StatusInternalServerError)
} else {
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
glog.Infof("Error reading resonse on receiving status %v: %v",
response.StatusCode, err)
}
glog.Infof("%v\n", string(contents))
w.WriteHeader(response.StatusCode)
} else {
w.WriteHeader(200)
w.Write([]byte("ok"))
}
}
})
// handler for not matched traffic
http.HandleFunc("/", s.Getfunc)
glog.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", lbApiPort), nil))
} | [
"func",
"registerHandlers",
"(",
"s",
"*",
"staticPageHandler",
")",
"{",
"http",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"// Delegate a check to the haproxy stats service.",
"response",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"*",
"statsPort",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"}",
"else",
"{",
"defer",
"response",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"response",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"contents",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"response",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"glog",
".",
"Infof",
"(",
"\"",
"\"",
",",
"response",
".",
"StatusCode",
",",
"err",
")",
"\n",
"}",
"\n",
"glog",
".",
"Infof",
"(",
"\"",
"\\n",
"\"",
",",
"string",
"(",
"contents",
")",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"response",
".",
"StatusCode",
")",
"\n",
"}",
"else",
"{",
"w",
".",
"WriteHeader",
"(",
"200",
")",
"\n",
"w",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
")",
"\n\n",
"// handler for not matched traffic",
"http",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"s",
".",
"Getfunc",
")",
"\n\n",
"glog",
".",
"Fatal",
"(",
"http",
".",
"ListenAndServe",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"lbApiPort",
")",
",",
"nil",
")",
")",
"\n",
"}"
] | // registerHandlers services liveness probes. | [
"registerHandlers",
"services",
"liveness",
"probes",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/service_loadbalancer.go#L610-L638 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/typed/generated/core/unversioned/event_expansion.go | UpdateWithEventNamespace | func (e *events) UpdateWithEventNamespace(event *api.Event) (*api.Event, error) {
result := &api.Event{}
err := e.client.Put().
NamespaceIfScoped(event.Namespace, len(event.Namespace) > 0).
Resource("events").
Name(event.Name).
Body(event).
Do().
Into(result)
return result, err
} | go | func (e *events) UpdateWithEventNamespace(event *api.Event) (*api.Event, error) {
result := &api.Event{}
err := e.client.Put().
NamespaceIfScoped(event.Namespace, len(event.Namespace) > 0).
Resource("events").
Name(event.Name).
Body(event).
Do().
Into(result)
return result, err
} | [
"func",
"(",
"e",
"*",
"events",
")",
"UpdateWithEventNamespace",
"(",
"event",
"*",
"api",
".",
"Event",
")",
"(",
"*",
"api",
".",
"Event",
",",
"error",
")",
"{",
"result",
":=",
"&",
"api",
".",
"Event",
"{",
"}",
"\n",
"err",
":=",
"e",
".",
"client",
".",
"Put",
"(",
")",
".",
"NamespaceIfScoped",
"(",
"event",
".",
"Namespace",
",",
"len",
"(",
"event",
".",
"Namespace",
")",
">",
"0",
")",
".",
"Resource",
"(",
"\"",
"\"",
")",
".",
"Name",
"(",
"event",
".",
"Name",
")",
".",
"Body",
"(",
"event",
")",
".",
"Do",
"(",
")",
".",
"Into",
"(",
"result",
")",
"\n",
"return",
"result",
",",
"err",
"\n",
"}"
] | // UpdateWithEventNamespace modifies an existing event. It returns the copy of the event that the server returns,
// or an error. The namespace and key to update the event within is deduced from the event. The
// namespace must either match this event client's namespace, or this event client must have been
// created with the "" namespace. Update also requires the ResourceVersion to be set in the event
// object. | [
"UpdateWithEventNamespace",
"modifies",
"an",
"existing",
"event",
".",
"It",
"returns",
"the",
"copy",
"of",
"the",
"event",
"that",
"the",
"server",
"returns",
"or",
"an",
"error",
".",
"The",
"namespace",
"and",
"key",
"to",
"update",
"the",
"event",
"within",
"is",
"deduced",
"from",
"the",
"event",
".",
"The",
"namespace",
"must",
"either",
"match",
"this",
"event",
"client",
"s",
"namespace",
"or",
"this",
"event",
"client",
"must",
"have",
"been",
"created",
"with",
"the",
"namespace",
".",
"Update",
"also",
"requires",
"the",
"ResourceVersion",
"to",
"be",
"set",
"in",
"the",
"event",
"object",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/typed/generated/core/unversioned/event_expansion.go#L64-L74 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/pod_templates.go | newPodTemplates | func newPodTemplates(c *Client, namespace string) *podTemplates {
return &podTemplates{
r: c,
ns: namespace,
}
} | go | func newPodTemplates(c *Client, namespace string) *podTemplates {
return &podTemplates{
r: c,
ns: namespace,
}
} | [
"func",
"newPodTemplates",
"(",
"c",
"*",
"Client",
",",
"namespace",
"string",
")",
"*",
"podTemplates",
"{",
"return",
"&",
"podTemplates",
"{",
"r",
":",
"c",
",",
"ns",
":",
"namespace",
",",
"}",
"\n",
"}"
] | // newPodTemplates returns a podTemplates | [
"newPodTemplates",
"returns",
"a",
"podTemplates"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/pod_templates.go#L46-L51 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/pod_templates.go | Update | func (c *podTemplates) Update(podTemplate *api.PodTemplate) (result *api.PodTemplate, err error) {
result = &api.PodTemplate{}
err = c.r.Put().Namespace(c.ns).Resource("podTemplates").Name(podTemplate.Name).Body(podTemplate).Do().Into(result)
return
} | go | func (c *podTemplates) Update(podTemplate *api.PodTemplate) (result *api.PodTemplate, err error) {
result = &api.PodTemplate{}
err = c.r.Put().Namespace(c.ns).Resource("podTemplates").Name(podTemplate.Name).Body(podTemplate).Do().Into(result)
return
} | [
"func",
"(",
"c",
"*",
"podTemplates",
")",
"Update",
"(",
"podTemplate",
"*",
"api",
".",
"PodTemplate",
")",
"(",
"result",
"*",
"api",
".",
"PodTemplate",
",",
"err",
"error",
")",
"{",
"result",
"=",
"&",
"api",
".",
"PodTemplate",
"{",
"}",
"\n",
"err",
"=",
"c",
".",
"r",
".",
"Put",
"(",
")",
".",
"Namespace",
"(",
"c",
".",
"ns",
")",
".",
"Resource",
"(",
"\"",
"\"",
")",
".",
"Name",
"(",
"podTemplate",
".",
"Name",
")",
".",
"Body",
"(",
"podTemplate",
")",
".",
"Do",
"(",
")",
".",
"Into",
"(",
"result",
")",
"\n",
"return",
"\n",
"}"
] | // Update takes the representation of a podTemplate to update. Returns the server's representation of the podTemplate, and an error, if it occurs. | [
"Update",
"takes",
"the",
"representation",
"of",
"a",
"podTemplate",
"to",
"update",
".",
"Returns",
"the",
"server",
"s",
"representation",
"of",
"the",
"podTemplate",
"and",
"an",
"error",
"if",
"it",
"occurs",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/unversioned/pod_templates.go#L80-L84 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go | bytesToKey | func bytesToKey(b []byte, pasteActive bool) (rune, []byte) {
if len(b) == 0 {
return utf8.RuneError, nil
}
if !pasteActive {
switch b[0] {
case 1: // ^A
return keyHome, b[1:]
case 5: // ^E
return keyEnd, b[1:]
case 8: // ^H
return keyBackspace, b[1:]
case 11: // ^K
return keyDeleteLine, b[1:]
case 12: // ^L
return keyClearScreen, b[1:]
case 23: // ^W
return keyDeleteWord, b[1:]
}
}
if b[0] != keyEscape {
if !utf8.FullRune(b) {
return utf8.RuneError, b
}
r, l := utf8.DecodeRune(b)
return r, b[l:]
}
if !pasteActive && len(b) >= 3 && b[0] == keyEscape && b[1] == '[' {
switch b[2] {
case 'A':
return keyUp, b[3:]
case 'B':
return keyDown, b[3:]
case 'C':
return keyRight, b[3:]
case 'D':
return keyLeft, b[3:]
case 'H':
return keyHome, b[3:]
case 'F':
return keyEnd, b[3:]
}
}
if !pasteActive && len(b) >= 6 && b[0] == keyEscape && b[1] == '[' && b[2] == '1' && b[3] == ';' && b[4] == '3' {
switch b[5] {
case 'C':
return keyAltRight, b[6:]
case 'D':
return keyAltLeft, b[6:]
}
}
if !pasteActive && len(b) >= 6 && bytes.Equal(b[:6], pasteStart) {
return keyPasteStart, b[6:]
}
if pasteActive && len(b) >= 6 && bytes.Equal(b[:6], pasteEnd) {
return keyPasteEnd, b[6:]
}
// If we get here then we have a key that we don't recognise, or a
// partial sequence. It's not clear how one should find the end of a
// sequence without knowing them all, but it seems that [a-zA-Z~] only
// appears at the end of a sequence.
for i, c := range b[0:] {
if c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '~' {
return keyUnknown, b[i+1:]
}
}
return utf8.RuneError, b
} | go | func bytesToKey(b []byte, pasteActive bool) (rune, []byte) {
if len(b) == 0 {
return utf8.RuneError, nil
}
if !pasteActive {
switch b[0] {
case 1: // ^A
return keyHome, b[1:]
case 5: // ^E
return keyEnd, b[1:]
case 8: // ^H
return keyBackspace, b[1:]
case 11: // ^K
return keyDeleteLine, b[1:]
case 12: // ^L
return keyClearScreen, b[1:]
case 23: // ^W
return keyDeleteWord, b[1:]
}
}
if b[0] != keyEscape {
if !utf8.FullRune(b) {
return utf8.RuneError, b
}
r, l := utf8.DecodeRune(b)
return r, b[l:]
}
if !pasteActive && len(b) >= 3 && b[0] == keyEscape && b[1] == '[' {
switch b[2] {
case 'A':
return keyUp, b[3:]
case 'B':
return keyDown, b[3:]
case 'C':
return keyRight, b[3:]
case 'D':
return keyLeft, b[3:]
case 'H':
return keyHome, b[3:]
case 'F':
return keyEnd, b[3:]
}
}
if !pasteActive && len(b) >= 6 && b[0] == keyEscape && b[1] == '[' && b[2] == '1' && b[3] == ';' && b[4] == '3' {
switch b[5] {
case 'C':
return keyAltRight, b[6:]
case 'D':
return keyAltLeft, b[6:]
}
}
if !pasteActive && len(b) >= 6 && bytes.Equal(b[:6], pasteStart) {
return keyPasteStart, b[6:]
}
if pasteActive && len(b) >= 6 && bytes.Equal(b[:6], pasteEnd) {
return keyPasteEnd, b[6:]
}
// If we get here then we have a key that we don't recognise, or a
// partial sequence. It's not clear how one should find the end of a
// sequence without knowing them all, but it seems that [a-zA-Z~] only
// appears at the end of a sequence.
for i, c := range b[0:] {
if c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '~' {
return keyUnknown, b[i+1:]
}
}
return utf8.RuneError, b
} | [
"func",
"bytesToKey",
"(",
"b",
"[",
"]",
"byte",
",",
"pasteActive",
"bool",
")",
"(",
"rune",
",",
"[",
"]",
"byte",
")",
"{",
"if",
"len",
"(",
"b",
")",
"==",
"0",
"{",
"return",
"utf8",
".",
"RuneError",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"!",
"pasteActive",
"{",
"switch",
"b",
"[",
"0",
"]",
"{",
"case",
"1",
":",
"// ^A",
"return",
"keyHome",
",",
"b",
"[",
"1",
":",
"]",
"\n",
"case",
"5",
":",
"// ^E",
"return",
"keyEnd",
",",
"b",
"[",
"1",
":",
"]",
"\n",
"case",
"8",
":",
"// ^H",
"return",
"keyBackspace",
",",
"b",
"[",
"1",
":",
"]",
"\n",
"case",
"11",
":",
"// ^K",
"return",
"keyDeleteLine",
",",
"b",
"[",
"1",
":",
"]",
"\n",
"case",
"12",
":",
"// ^L",
"return",
"keyClearScreen",
",",
"b",
"[",
"1",
":",
"]",
"\n",
"case",
"23",
":",
"// ^W",
"return",
"keyDeleteWord",
",",
"b",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"b",
"[",
"0",
"]",
"!=",
"keyEscape",
"{",
"if",
"!",
"utf8",
".",
"FullRune",
"(",
"b",
")",
"{",
"return",
"utf8",
".",
"RuneError",
",",
"b",
"\n",
"}",
"\n",
"r",
",",
"l",
":=",
"utf8",
".",
"DecodeRune",
"(",
"b",
")",
"\n",
"return",
"r",
",",
"b",
"[",
"l",
":",
"]",
"\n",
"}",
"\n\n",
"if",
"!",
"pasteActive",
"&&",
"len",
"(",
"b",
")",
">=",
"3",
"&&",
"b",
"[",
"0",
"]",
"==",
"keyEscape",
"&&",
"b",
"[",
"1",
"]",
"==",
"'['",
"{",
"switch",
"b",
"[",
"2",
"]",
"{",
"case",
"'A'",
":",
"return",
"keyUp",
",",
"b",
"[",
"3",
":",
"]",
"\n",
"case",
"'B'",
":",
"return",
"keyDown",
",",
"b",
"[",
"3",
":",
"]",
"\n",
"case",
"'C'",
":",
"return",
"keyRight",
",",
"b",
"[",
"3",
":",
"]",
"\n",
"case",
"'D'",
":",
"return",
"keyLeft",
",",
"b",
"[",
"3",
":",
"]",
"\n",
"case",
"'H'",
":",
"return",
"keyHome",
",",
"b",
"[",
"3",
":",
"]",
"\n",
"case",
"'F'",
":",
"return",
"keyEnd",
",",
"b",
"[",
"3",
":",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"pasteActive",
"&&",
"len",
"(",
"b",
")",
">=",
"6",
"&&",
"b",
"[",
"0",
"]",
"==",
"keyEscape",
"&&",
"b",
"[",
"1",
"]",
"==",
"'['",
"&&",
"b",
"[",
"2",
"]",
"==",
"'1'",
"&&",
"b",
"[",
"3",
"]",
"==",
"';'",
"&&",
"b",
"[",
"4",
"]",
"==",
"'3'",
"{",
"switch",
"b",
"[",
"5",
"]",
"{",
"case",
"'C'",
":",
"return",
"keyAltRight",
",",
"b",
"[",
"6",
":",
"]",
"\n",
"case",
"'D'",
":",
"return",
"keyAltLeft",
",",
"b",
"[",
"6",
":",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"pasteActive",
"&&",
"len",
"(",
"b",
")",
">=",
"6",
"&&",
"bytes",
".",
"Equal",
"(",
"b",
"[",
":",
"6",
"]",
",",
"pasteStart",
")",
"{",
"return",
"keyPasteStart",
",",
"b",
"[",
"6",
":",
"]",
"\n",
"}",
"\n\n",
"if",
"pasteActive",
"&&",
"len",
"(",
"b",
")",
">=",
"6",
"&&",
"bytes",
".",
"Equal",
"(",
"b",
"[",
":",
"6",
"]",
",",
"pasteEnd",
")",
"{",
"return",
"keyPasteEnd",
",",
"b",
"[",
"6",
":",
"]",
"\n",
"}",
"\n\n",
"// If we get here then we have a key that we don't recognise, or a",
"// partial sequence. It's not clear how one should find the end of a",
"// sequence without knowing them all, but it seems that [a-zA-Z~] only",
"// appears at the end of a sequence.",
"for",
"i",
",",
"c",
":=",
"range",
"b",
"[",
"0",
":",
"]",
"{",
"if",
"c",
">=",
"'a'",
"&&",
"c",
"<=",
"'z'",
"||",
"c",
">=",
"'A'",
"&&",
"c",
"<=",
"'Z'",
"||",
"c",
"==",
"'~'",
"{",
"return",
"keyUnknown",
",",
"b",
"[",
"i",
"+",
"1",
":",
"]",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"utf8",
".",
"RuneError",
",",
"b",
"\n",
"}"
] | // bytesToKey tries to parse a key sequence from b. If successful, it returns
// the key and the remainder of the input. Otherwise it returns utf8.RuneError. | [
"bytesToKey",
"tries",
"to",
"parse",
"a",
"key",
"sequence",
"from",
"b",
".",
"If",
"successful",
"it",
"returns",
"the",
"key",
"and",
"the",
"remainder",
"of",
"the",
"input",
".",
"Otherwise",
"it",
"returns",
"utf8",
".",
"RuneError",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go#L140-L215 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go | queue | func (t *Terminal) queue(data []rune) {
t.outBuf = append(t.outBuf, []byte(string(data))...)
} | go | func (t *Terminal) queue(data []rune) {
t.outBuf = append(t.outBuf, []byte(string(data))...)
} | [
"func",
"(",
"t",
"*",
"Terminal",
")",
"queue",
"(",
"data",
"[",
"]",
"rune",
")",
"{",
"t",
".",
"outBuf",
"=",
"append",
"(",
"t",
".",
"outBuf",
",",
"[",
"]",
"byte",
"(",
"string",
"(",
"data",
")",
")",
"...",
")",
"\n",
"}"
] | // queue appends data to the end of t.outBuf | [
"queue",
"appends",
"data",
"to",
"the",
"end",
"of",
"t",
".",
"outBuf"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go#L218-L220 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go | moveCursorToPos | func (t *Terminal) moveCursorToPos(pos int) {
if !t.echo {
return
}
x := visualLength(t.prompt) + pos
y := x / t.termWidth
x = x % t.termWidth
up := 0
if y < t.cursorY {
up = t.cursorY - y
}
down := 0
if y > t.cursorY {
down = y - t.cursorY
}
left := 0
if x < t.cursorX {
left = t.cursorX - x
}
right := 0
if x > t.cursorX {
right = x - t.cursorX
}
t.cursorX = x
t.cursorY = y
t.move(up, down, left, right)
} | go | func (t *Terminal) moveCursorToPos(pos int) {
if !t.echo {
return
}
x := visualLength(t.prompt) + pos
y := x / t.termWidth
x = x % t.termWidth
up := 0
if y < t.cursorY {
up = t.cursorY - y
}
down := 0
if y > t.cursorY {
down = y - t.cursorY
}
left := 0
if x < t.cursorX {
left = t.cursorX - x
}
right := 0
if x > t.cursorX {
right = x - t.cursorX
}
t.cursorX = x
t.cursorY = y
t.move(up, down, left, right)
} | [
"func",
"(",
"t",
"*",
"Terminal",
")",
"moveCursorToPos",
"(",
"pos",
"int",
")",
"{",
"if",
"!",
"t",
".",
"echo",
"{",
"return",
"\n",
"}",
"\n\n",
"x",
":=",
"visualLength",
"(",
"t",
".",
"prompt",
")",
"+",
"pos",
"\n",
"y",
":=",
"x",
"/",
"t",
".",
"termWidth",
"\n",
"x",
"=",
"x",
"%",
"t",
".",
"termWidth",
"\n\n",
"up",
":=",
"0",
"\n",
"if",
"y",
"<",
"t",
".",
"cursorY",
"{",
"up",
"=",
"t",
".",
"cursorY",
"-",
"y",
"\n",
"}",
"\n\n",
"down",
":=",
"0",
"\n",
"if",
"y",
">",
"t",
".",
"cursorY",
"{",
"down",
"=",
"y",
"-",
"t",
".",
"cursorY",
"\n",
"}",
"\n\n",
"left",
":=",
"0",
"\n",
"if",
"x",
"<",
"t",
".",
"cursorX",
"{",
"left",
"=",
"t",
".",
"cursorX",
"-",
"x",
"\n",
"}",
"\n\n",
"right",
":=",
"0",
"\n",
"if",
"x",
">",
"t",
".",
"cursorX",
"{",
"right",
"=",
"x",
"-",
"t",
".",
"cursorX",
"\n",
"}",
"\n\n",
"t",
".",
"cursorX",
"=",
"x",
"\n",
"t",
".",
"cursorY",
"=",
"y",
"\n",
"t",
".",
"move",
"(",
"up",
",",
"down",
",",
"left",
",",
"right",
")",
"\n",
"}"
] | // moveCursorToPos appends data to t.outBuf which will move the cursor to the
// given, logical position in the text. | [
"moveCursorToPos",
"appends",
"data",
"to",
"t",
".",
"outBuf",
"which",
"will",
"move",
"the",
"cursor",
"to",
"the",
"given",
"logical",
"position",
"in",
"the",
"text",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go#L232-L264 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go | countToLeftWord | func (t *Terminal) countToLeftWord() int {
if t.pos == 0 {
return 0
}
pos := t.pos - 1
for pos > 0 {
if t.line[pos] != ' ' {
break
}
pos--
}
for pos > 0 {
if t.line[pos] == ' ' {
pos++
break
}
pos--
}
return t.pos - pos
} | go | func (t *Terminal) countToLeftWord() int {
if t.pos == 0 {
return 0
}
pos := t.pos - 1
for pos > 0 {
if t.line[pos] != ' ' {
break
}
pos--
}
for pos > 0 {
if t.line[pos] == ' ' {
pos++
break
}
pos--
}
return t.pos - pos
} | [
"func",
"(",
"t",
"*",
"Terminal",
")",
"countToLeftWord",
"(",
")",
"int",
"{",
"if",
"t",
".",
"pos",
"==",
"0",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"pos",
":=",
"t",
".",
"pos",
"-",
"1",
"\n",
"for",
"pos",
">",
"0",
"{",
"if",
"t",
".",
"line",
"[",
"pos",
"]",
"!=",
"' '",
"{",
"break",
"\n",
"}",
"\n",
"pos",
"--",
"\n",
"}",
"\n",
"for",
"pos",
">",
"0",
"{",
"if",
"t",
".",
"line",
"[",
"pos",
"]",
"==",
"' '",
"{",
"pos",
"++",
"\n",
"break",
"\n",
"}",
"\n",
"pos",
"--",
"\n",
"}",
"\n\n",
"return",
"t",
".",
"pos",
"-",
"pos",
"\n",
"}"
] | // countToLeftWord returns then number of characters from the cursor to the
// start of the previous word. | [
"countToLeftWord",
"returns",
"then",
"number",
"of",
"characters",
"from",
"the",
"cursor",
"to",
"the",
"start",
"of",
"the",
"previous",
"word",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go#L365-L386 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go | countToRightWord | func (t *Terminal) countToRightWord() int {
pos := t.pos
for pos < len(t.line) {
if t.line[pos] == ' ' {
break
}
pos++
}
for pos < len(t.line) {
if t.line[pos] != ' ' {
break
}
pos++
}
return pos - t.pos
} | go | func (t *Terminal) countToRightWord() int {
pos := t.pos
for pos < len(t.line) {
if t.line[pos] == ' ' {
break
}
pos++
}
for pos < len(t.line) {
if t.line[pos] != ' ' {
break
}
pos++
}
return pos - t.pos
} | [
"func",
"(",
"t",
"*",
"Terminal",
")",
"countToRightWord",
"(",
")",
"int",
"{",
"pos",
":=",
"t",
".",
"pos",
"\n",
"for",
"pos",
"<",
"len",
"(",
"t",
".",
"line",
")",
"{",
"if",
"t",
".",
"line",
"[",
"pos",
"]",
"==",
"' '",
"{",
"break",
"\n",
"}",
"\n",
"pos",
"++",
"\n",
"}",
"\n",
"for",
"pos",
"<",
"len",
"(",
"t",
".",
"line",
")",
"{",
"if",
"t",
".",
"line",
"[",
"pos",
"]",
"!=",
"' '",
"{",
"break",
"\n",
"}",
"\n",
"pos",
"++",
"\n",
"}",
"\n",
"return",
"pos",
"-",
"t",
".",
"pos",
"\n",
"}"
] | // countToRightWord returns then number of characters from the cursor to the
// start of the next word. | [
"countToRightWord",
"returns",
"then",
"number",
"of",
"characters",
"from",
"the",
"cursor",
"to",
"the",
"start",
"of",
"the",
"next",
"word",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go#L390-L405 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go | visualLength | func visualLength(runes []rune) int {
inEscapeSeq := false
length := 0
for _, r := range runes {
switch {
case inEscapeSeq:
if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') {
inEscapeSeq = false
}
case r == '\x1b':
inEscapeSeq = true
default:
length++
}
}
return length
} | go | func visualLength(runes []rune) int {
inEscapeSeq := false
length := 0
for _, r := range runes {
switch {
case inEscapeSeq:
if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') {
inEscapeSeq = false
}
case r == '\x1b':
inEscapeSeq = true
default:
length++
}
}
return length
} | [
"func",
"visualLength",
"(",
"runes",
"[",
"]",
"rune",
")",
"int",
"{",
"inEscapeSeq",
":=",
"false",
"\n",
"length",
":=",
"0",
"\n\n",
"for",
"_",
",",
"r",
":=",
"range",
"runes",
"{",
"switch",
"{",
"case",
"inEscapeSeq",
":",
"if",
"(",
"r",
">=",
"'a'",
"&&",
"r",
"<=",
"'z'",
")",
"||",
"(",
"r",
">=",
"'A'",
"&&",
"r",
"<=",
"'Z'",
")",
"{",
"inEscapeSeq",
"=",
"false",
"\n",
"}",
"\n",
"case",
"r",
"==",
"'\\x1b'",
":",
"inEscapeSeq",
"=",
"true",
"\n",
"default",
":",
"length",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"length",
"\n",
"}"
] | // visualLength returns the number of visible glyphs in s. | [
"visualLength",
"returns",
"the",
"number",
"of",
"visible",
"glyphs",
"in",
"s",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go#L408-L426 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go | addKeyToLine | func (t *Terminal) addKeyToLine(key rune) {
if len(t.line) == cap(t.line) {
newLine := make([]rune, len(t.line), 2*(1+len(t.line)))
copy(newLine, t.line)
t.line = newLine
}
t.line = t.line[:len(t.line)+1]
copy(t.line[t.pos+1:], t.line[t.pos:])
t.line[t.pos] = key
if t.echo {
t.writeLine(t.line[t.pos:])
}
t.pos++
t.moveCursorToPos(t.pos)
} | go | func (t *Terminal) addKeyToLine(key rune) {
if len(t.line) == cap(t.line) {
newLine := make([]rune, len(t.line), 2*(1+len(t.line)))
copy(newLine, t.line)
t.line = newLine
}
t.line = t.line[:len(t.line)+1]
copy(t.line[t.pos+1:], t.line[t.pos:])
t.line[t.pos] = key
if t.echo {
t.writeLine(t.line[t.pos:])
}
t.pos++
t.moveCursorToPos(t.pos)
} | [
"func",
"(",
"t",
"*",
"Terminal",
")",
"addKeyToLine",
"(",
"key",
"rune",
")",
"{",
"if",
"len",
"(",
"t",
".",
"line",
")",
"==",
"cap",
"(",
"t",
".",
"line",
")",
"{",
"newLine",
":=",
"make",
"(",
"[",
"]",
"rune",
",",
"len",
"(",
"t",
".",
"line",
")",
",",
"2",
"*",
"(",
"1",
"+",
"len",
"(",
"t",
".",
"line",
")",
")",
")",
"\n",
"copy",
"(",
"newLine",
",",
"t",
".",
"line",
")",
"\n",
"t",
".",
"line",
"=",
"newLine",
"\n",
"}",
"\n",
"t",
".",
"line",
"=",
"t",
".",
"line",
"[",
":",
"len",
"(",
"t",
".",
"line",
")",
"+",
"1",
"]",
"\n",
"copy",
"(",
"t",
".",
"line",
"[",
"t",
".",
"pos",
"+",
"1",
":",
"]",
",",
"t",
".",
"line",
"[",
"t",
".",
"pos",
":",
"]",
")",
"\n",
"t",
".",
"line",
"[",
"t",
".",
"pos",
"]",
"=",
"key",
"\n",
"if",
"t",
".",
"echo",
"{",
"t",
".",
"writeLine",
"(",
"t",
".",
"line",
"[",
"t",
".",
"pos",
":",
"]",
")",
"\n",
"}",
"\n",
"t",
".",
"pos",
"++",
"\n",
"t",
".",
"moveCursorToPos",
"(",
"t",
".",
"pos",
")",
"\n",
"}"
] | // addKeyToLine inserts the given key at the current position in the current
// line. | [
"addKeyToLine",
"inserts",
"the",
"given",
"key",
"at",
"the",
"current",
"position",
"in",
"the",
"current",
"line",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go#L567-L581 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go | ReadPassword | func (t *Terminal) ReadPassword(prompt string) (line string, err error) {
t.lock.Lock()
defer t.lock.Unlock()
oldPrompt := t.prompt
t.prompt = []rune(prompt)
t.echo = false
line, err = t.readLine()
t.prompt = oldPrompt
t.echo = true
return
} | go | func (t *Terminal) ReadPassword(prompt string) (line string, err error) {
t.lock.Lock()
defer t.lock.Unlock()
oldPrompt := t.prompt
t.prompt = []rune(prompt)
t.echo = false
line, err = t.readLine()
t.prompt = oldPrompt
t.echo = true
return
} | [
"func",
"(",
"t",
"*",
"Terminal",
")",
"ReadPassword",
"(",
"prompt",
"string",
")",
"(",
"line",
"string",
",",
"err",
"error",
")",
"{",
"t",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"oldPrompt",
":=",
"t",
".",
"prompt",
"\n",
"t",
".",
"prompt",
"=",
"[",
"]",
"rune",
"(",
"prompt",
")",
"\n",
"t",
".",
"echo",
"=",
"false",
"\n\n",
"line",
",",
"err",
"=",
"t",
".",
"readLine",
"(",
")",
"\n\n",
"t",
".",
"prompt",
"=",
"oldPrompt",
"\n",
"t",
".",
"echo",
"=",
"true",
"\n\n",
"return",
"\n",
"}"
] | // ReadPassword temporarily changes the prompt and reads a password, without
// echo, from the terminal. | [
"ReadPassword",
"temporarily",
"changes",
"the",
"prompt",
"and",
"reads",
"a",
"password",
"without",
"echo",
"from",
"the",
"terminal",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go#L643-L657 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go | ReadLine | func (t *Terminal) ReadLine() (line string, err error) {
t.lock.Lock()
defer t.lock.Unlock()
return t.readLine()
} | go | func (t *Terminal) ReadLine() (line string, err error) {
t.lock.Lock()
defer t.lock.Unlock()
return t.readLine()
} | [
"func",
"(",
"t",
"*",
"Terminal",
")",
"ReadLine",
"(",
")",
"(",
"line",
"string",
",",
"err",
"error",
")",
"{",
"t",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"t",
".",
"readLine",
"(",
")",
"\n",
"}"
] | // ReadLine returns a line of input from the terminal. | [
"ReadLine",
"returns",
"a",
"line",
"of",
"input",
"from",
"the",
"terminal",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go#L660-L665 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go | SetPrompt | func (t *Terminal) SetPrompt(prompt string) {
t.lock.Lock()
defer t.lock.Unlock()
t.prompt = []rune(prompt)
} | go | func (t *Terminal) SetPrompt(prompt string) {
t.lock.Lock()
defer t.lock.Unlock()
t.prompt = []rune(prompt)
} | [
"func",
"(",
"t",
"*",
"Terminal",
")",
"SetPrompt",
"(",
"prompt",
"string",
")",
"{",
"t",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"t",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n\n",
"t",
".",
"prompt",
"=",
"[",
"]",
"rune",
"(",
"prompt",
")",
"\n",
"}"
] | // SetPrompt sets the prompt to be used when reading subsequent lines. | [
"SetPrompt",
"sets",
"the",
"prompt",
"to",
"be",
"used",
"when",
"reading",
"subsequent",
"lines",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go#L748-L753 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go | SetBracketedPasteMode | func (t *Terminal) SetBracketedPasteMode(on bool) {
if on {
io.WriteString(t.c, "\x1b[?2004h")
} else {
io.WriteString(t.c, "\x1b[?2004l")
}
} | go | func (t *Terminal) SetBracketedPasteMode(on bool) {
if on {
io.WriteString(t.c, "\x1b[?2004h")
} else {
io.WriteString(t.c, "\x1b[?2004l")
}
} | [
"func",
"(",
"t",
"*",
"Terminal",
")",
"SetBracketedPasteMode",
"(",
"on",
"bool",
")",
"{",
"if",
"on",
"{",
"io",
".",
"WriteString",
"(",
"t",
".",
"c",
",",
"\"",
"\\x1b",
"\"",
")",
"\n",
"}",
"else",
"{",
"io",
".",
"WriteString",
"(",
"t",
".",
"c",
",",
"\"",
"\\x1b",
"\"",
")",
"\n",
"}",
"\n",
"}"
] | // SetBracketedPasteMode requests that the terminal bracket paste operations
// with markers. Not all terminals support this but, if it is supported, then
// enabling this mode will stop any autocomplete callback from running due to
// pastes. Additionally, any lines that are completely pasted will be returned
// from ReadLine with the error set to ErrPasteIndicator. | [
"SetBracketedPasteMode",
"requests",
"that",
"the",
"terminal",
"bracket",
"paste",
"operations",
"with",
"markers",
".",
"Not",
"all",
"terminals",
"support",
"this",
"but",
"if",
"it",
"is",
"supported",
"then",
"enabling",
"this",
"mode",
"will",
"stop",
"any",
"autocomplete",
"callback",
"from",
"running",
"due",
"to",
"pastes",
".",
"Additionally",
"any",
"lines",
"that",
"are",
"completely",
"pasted",
"will",
"be",
"returned",
"from",
"ReadLine",
"with",
"the",
"error",
"set",
"to",
"ErrPasteIndicator",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go#L846-L852 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go | NthPreviousEntry | func (s *stRingBuffer) NthPreviousEntry(n int) (value string, ok bool) {
if n >= s.size {
return "", false
}
index := s.head - n
if index < 0 {
index += s.max
}
return s.entries[index], true
} | go | func (s *stRingBuffer) NthPreviousEntry(n int) (value string, ok bool) {
if n >= s.size {
return "", false
}
index := s.head - n
if index < 0 {
index += s.max
}
return s.entries[index], true
} | [
"func",
"(",
"s",
"*",
"stRingBuffer",
")",
"NthPreviousEntry",
"(",
"n",
"int",
")",
"(",
"value",
"string",
",",
"ok",
"bool",
")",
"{",
"if",
"n",
">=",
"s",
".",
"size",
"{",
"return",
"\"",
"\"",
",",
"false",
"\n",
"}",
"\n",
"index",
":=",
"s",
".",
"head",
"-",
"n",
"\n",
"if",
"index",
"<",
"0",
"{",
"index",
"+=",
"s",
".",
"max",
"\n",
"}",
"\n",
"return",
"s",
".",
"entries",
"[",
"index",
"]",
",",
"true",
"\n",
"}"
] | // NthPreviousEntry returns the value passed to the nth previous call to Add.
// If n is zero then the immediately prior value is returned, if one, then the
// next most recent, and so on. If such an element doesn't exist then ok is
// false. | [
"NthPreviousEntry",
"returns",
"the",
"value",
"passed",
"to",
"the",
"nth",
"previous",
"call",
"to",
"Add",
".",
"If",
"n",
"is",
"zero",
"then",
"the",
"immediately",
"prior",
"value",
"is",
"returned",
"if",
"one",
"then",
"the",
"next",
"most",
"recent",
"and",
"so",
"on",
".",
"If",
"such",
"an",
"element",
"doesn",
"t",
"exist",
"then",
"ok",
"is",
"false",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/golang.org/x/crypto/ssh/terminal/terminal.go#L883-L892 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/parserc.go | yaml_parser_parse | func yaml_parser_parse(parser *yaml_parser_t, event *yaml_event_t) bool {
// Erase the event object.
*event = yaml_event_t{}
// No events after the end of the stream or error.
if parser.stream_end_produced || parser.error != yaml_NO_ERROR || parser.state == yaml_PARSE_END_STATE {
return true
}
// Generate the next event.
return yaml_parser_state_machine(parser, event)
} | go | func yaml_parser_parse(parser *yaml_parser_t, event *yaml_event_t) bool {
// Erase the event object.
*event = yaml_event_t{}
// No events after the end of the stream or error.
if parser.stream_end_produced || parser.error != yaml_NO_ERROR || parser.state == yaml_PARSE_END_STATE {
return true
}
// Generate the next event.
return yaml_parser_state_machine(parser, event)
} | [
"func",
"yaml_parser_parse",
"(",
"parser",
"*",
"yaml_parser_t",
",",
"event",
"*",
"yaml_event_t",
")",
"bool",
"{",
"// Erase the event object.",
"*",
"event",
"=",
"yaml_event_t",
"{",
"}",
"\n\n",
"// No events after the end of the stream or error.",
"if",
"parser",
".",
"stream_end_produced",
"||",
"parser",
".",
"error",
"!=",
"yaml_NO_ERROR",
"||",
"parser",
".",
"state",
"==",
"yaml_PARSE_END_STATE",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"// Generate the next event.",
"return",
"yaml_parser_state_machine",
"(",
"parser",
",",
"event",
")",
"\n",
"}"
] | // Get the next event. | [
"Get",
"the",
"next",
"event",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/parserc.go#L62-L73 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/parserc.go | yaml_parser_set_parser_error | func yaml_parser_set_parser_error(parser *yaml_parser_t, problem string, problem_mark yaml_mark_t) bool {
parser.error = yaml_PARSER_ERROR
parser.problem = problem
parser.problem_mark = problem_mark
return false
} | go | func yaml_parser_set_parser_error(parser *yaml_parser_t, problem string, problem_mark yaml_mark_t) bool {
parser.error = yaml_PARSER_ERROR
parser.problem = problem
parser.problem_mark = problem_mark
return false
} | [
"func",
"yaml_parser_set_parser_error",
"(",
"parser",
"*",
"yaml_parser_t",
",",
"problem",
"string",
",",
"problem_mark",
"yaml_mark_t",
")",
"bool",
"{",
"parser",
".",
"error",
"=",
"yaml_PARSER_ERROR",
"\n",
"parser",
".",
"problem",
"=",
"problem",
"\n",
"parser",
".",
"problem_mark",
"=",
"problem_mark",
"\n",
"return",
"false",
"\n",
"}"
] | // Set parser error. | [
"Set",
"parser",
"error",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/parserc.go#L76-L81 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/parserc.go | yaml_parser_process_empty_scalar | func yaml_parser_process_empty_scalar(parser *yaml_parser_t, event *yaml_event_t, mark yaml_mark_t) bool {
*event = yaml_event_t{
typ: yaml_SCALAR_EVENT,
start_mark: mark,
end_mark: mark,
value: nil, // Empty
implicit: true,
style: yaml_style_t(yaml_PLAIN_SCALAR_STYLE),
}
return true
} | go | func yaml_parser_process_empty_scalar(parser *yaml_parser_t, event *yaml_event_t, mark yaml_mark_t) bool {
*event = yaml_event_t{
typ: yaml_SCALAR_EVENT,
start_mark: mark,
end_mark: mark,
value: nil, // Empty
implicit: true,
style: yaml_style_t(yaml_PLAIN_SCALAR_STYLE),
}
return true
} | [
"func",
"yaml_parser_process_empty_scalar",
"(",
"parser",
"*",
"yaml_parser_t",
",",
"event",
"*",
"yaml_event_t",
",",
"mark",
"yaml_mark_t",
")",
"bool",
"{",
"*",
"event",
"=",
"yaml_event_t",
"{",
"typ",
":",
"yaml_SCALAR_EVENT",
",",
"start_mark",
":",
"mark",
",",
"end_mark",
":",
"mark",
",",
"value",
":",
"nil",
",",
"// Empty",
"implicit",
":",
"true",
",",
"style",
":",
"yaml_style_t",
"(",
"yaml_PLAIN_SCALAR_STYLE",
")",
",",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Generate an empty scalar event. | [
"Generate",
"an",
"empty",
"scalar",
"event",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/parserc.go#L996-L1006 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/parserc.go | yaml_parser_process_directives | func yaml_parser_process_directives(parser *yaml_parser_t,
version_directive_ref **yaml_version_directive_t,
tag_directives_ref *[]yaml_tag_directive_t) bool {
var version_directive *yaml_version_directive_t
var tag_directives []yaml_tag_directive_t
token := peek_token(parser)
if token == nil {
return false
}
for token.typ == yaml_VERSION_DIRECTIVE_TOKEN || token.typ == yaml_TAG_DIRECTIVE_TOKEN {
if token.typ == yaml_VERSION_DIRECTIVE_TOKEN {
if version_directive != nil {
yaml_parser_set_parser_error(parser,
"found duplicate %YAML directive", token.start_mark)
return false
}
if token.major != 1 || token.minor != 1 {
yaml_parser_set_parser_error(parser,
"found incompatible YAML document", token.start_mark)
return false
}
version_directive = &yaml_version_directive_t{
major: token.major,
minor: token.minor,
}
} else if token.typ == yaml_TAG_DIRECTIVE_TOKEN {
value := yaml_tag_directive_t{
handle: token.value,
prefix: token.prefix,
}
if !yaml_parser_append_tag_directive(parser, value, false, token.start_mark) {
return false
}
tag_directives = append(tag_directives, value)
}
skip_token(parser)
token = peek_token(parser)
if token == nil {
return false
}
}
for i := range default_tag_directives {
if !yaml_parser_append_tag_directive(parser, default_tag_directives[i], true, token.start_mark) {
return false
}
}
if version_directive_ref != nil {
*version_directive_ref = version_directive
}
if tag_directives_ref != nil {
*tag_directives_ref = tag_directives
}
return true
} | go | func yaml_parser_process_directives(parser *yaml_parser_t,
version_directive_ref **yaml_version_directive_t,
tag_directives_ref *[]yaml_tag_directive_t) bool {
var version_directive *yaml_version_directive_t
var tag_directives []yaml_tag_directive_t
token := peek_token(parser)
if token == nil {
return false
}
for token.typ == yaml_VERSION_DIRECTIVE_TOKEN || token.typ == yaml_TAG_DIRECTIVE_TOKEN {
if token.typ == yaml_VERSION_DIRECTIVE_TOKEN {
if version_directive != nil {
yaml_parser_set_parser_error(parser,
"found duplicate %YAML directive", token.start_mark)
return false
}
if token.major != 1 || token.minor != 1 {
yaml_parser_set_parser_error(parser,
"found incompatible YAML document", token.start_mark)
return false
}
version_directive = &yaml_version_directive_t{
major: token.major,
minor: token.minor,
}
} else if token.typ == yaml_TAG_DIRECTIVE_TOKEN {
value := yaml_tag_directive_t{
handle: token.value,
prefix: token.prefix,
}
if !yaml_parser_append_tag_directive(parser, value, false, token.start_mark) {
return false
}
tag_directives = append(tag_directives, value)
}
skip_token(parser)
token = peek_token(parser)
if token == nil {
return false
}
}
for i := range default_tag_directives {
if !yaml_parser_append_tag_directive(parser, default_tag_directives[i], true, token.start_mark) {
return false
}
}
if version_directive_ref != nil {
*version_directive_ref = version_directive
}
if tag_directives_ref != nil {
*tag_directives_ref = tag_directives
}
return true
} | [
"func",
"yaml_parser_process_directives",
"(",
"parser",
"*",
"yaml_parser_t",
",",
"version_directive_ref",
"*",
"*",
"yaml_version_directive_t",
",",
"tag_directives_ref",
"*",
"[",
"]",
"yaml_tag_directive_t",
")",
"bool",
"{",
"var",
"version_directive",
"*",
"yaml_version_directive_t",
"\n",
"var",
"tag_directives",
"[",
"]",
"yaml_tag_directive_t",
"\n\n",
"token",
":=",
"peek_token",
"(",
"parser",
")",
"\n",
"if",
"token",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"for",
"token",
".",
"typ",
"==",
"yaml_VERSION_DIRECTIVE_TOKEN",
"||",
"token",
".",
"typ",
"==",
"yaml_TAG_DIRECTIVE_TOKEN",
"{",
"if",
"token",
".",
"typ",
"==",
"yaml_VERSION_DIRECTIVE_TOKEN",
"{",
"if",
"version_directive",
"!=",
"nil",
"{",
"yaml_parser_set_parser_error",
"(",
"parser",
",",
"\"",
"\"",
",",
"token",
".",
"start_mark",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"if",
"token",
".",
"major",
"!=",
"1",
"||",
"token",
".",
"minor",
"!=",
"1",
"{",
"yaml_parser_set_parser_error",
"(",
"parser",
",",
"\"",
"\"",
",",
"token",
".",
"start_mark",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"version_directive",
"=",
"&",
"yaml_version_directive_t",
"{",
"major",
":",
"token",
".",
"major",
",",
"minor",
":",
"token",
".",
"minor",
",",
"}",
"\n",
"}",
"else",
"if",
"token",
".",
"typ",
"==",
"yaml_TAG_DIRECTIVE_TOKEN",
"{",
"value",
":=",
"yaml_tag_directive_t",
"{",
"handle",
":",
"token",
".",
"value",
",",
"prefix",
":",
"token",
".",
"prefix",
",",
"}",
"\n",
"if",
"!",
"yaml_parser_append_tag_directive",
"(",
"parser",
",",
"value",
",",
"false",
",",
"token",
".",
"start_mark",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"tag_directives",
"=",
"append",
"(",
"tag_directives",
",",
"value",
")",
"\n",
"}",
"\n\n",
"skip_token",
"(",
"parser",
")",
"\n",
"token",
"=",
"peek_token",
"(",
"parser",
")",
"\n",
"if",
"token",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"default_tag_directives",
"{",
"if",
"!",
"yaml_parser_append_tag_directive",
"(",
"parser",
",",
"default_tag_directives",
"[",
"i",
"]",
",",
"true",
",",
"token",
".",
"start_mark",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"version_directive_ref",
"!=",
"nil",
"{",
"*",
"version_directive_ref",
"=",
"version_directive",
"\n",
"}",
"\n",
"if",
"tag_directives_ref",
"!=",
"nil",
"{",
"*",
"tag_directives_ref",
"=",
"tag_directives",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Parse directives. | [
"Parse",
"directives",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/parserc.go#L1014-L1073 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/parserc.go | yaml_parser_append_tag_directive | func yaml_parser_append_tag_directive(parser *yaml_parser_t, value yaml_tag_directive_t, allow_duplicates bool, mark yaml_mark_t) bool {
for i := range parser.tag_directives {
if bytes.Equal(value.handle, parser.tag_directives[i].handle) {
if allow_duplicates {
return true
}
return yaml_parser_set_parser_error(parser, "found duplicate %TAG directive", mark)
}
}
// [Go] I suspect the copy is unnecessary. This was likely done
// because there was no way to track ownership of the data.
value_copy := yaml_tag_directive_t{
handle: make([]byte, len(value.handle)),
prefix: make([]byte, len(value.prefix)),
}
copy(value_copy.handle, value.handle)
copy(value_copy.prefix, value.prefix)
parser.tag_directives = append(parser.tag_directives, value_copy)
return true
} | go | func yaml_parser_append_tag_directive(parser *yaml_parser_t, value yaml_tag_directive_t, allow_duplicates bool, mark yaml_mark_t) bool {
for i := range parser.tag_directives {
if bytes.Equal(value.handle, parser.tag_directives[i].handle) {
if allow_duplicates {
return true
}
return yaml_parser_set_parser_error(parser, "found duplicate %TAG directive", mark)
}
}
// [Go] I suspect the copy is unnecessary. This was likely done
// because there was no way to track ownership of the data.
value_copy := yaml_tag_directive_t{
handle: make([]byte, len(value.handle)),
prefix: make([]byte, len(value.prefix)),
}
copy(value_copy.handle, value.handle)
copy(value_copy.prefix, value.prefix)
parser.tag_directives = append(parser.tag_directives, value_copy)
return true
} | [
"func",
"yaml_parser_append_tag_directive",
"(",
"parser",
"*",
"yaml_parser_t",
",",
"value",
"yaml_tag_directive_t",
",",
"allow_duplicates",
"bool",
",",
"mark",
"yaml_mark_t",
")",
"bool",
"{",
"for",
"i",
":=",
"range",
"parser",
".",
"tag_directives",
"{",
"if",
"bytes",
".",
"Equal",
"(",
"value",
".",
"handle",
",",
"parser",
".",
"tag_directives",
"[",
"i",
"]",
".",
"handle",
")",
"{",
"if",
"allow_duplicates",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"yaml_parser_set_parser_error",
"(",
"parser",
",",
"\"",
"\"",
",",
"mark",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// [Go] I suspect the copy is unnecessary. This was likely done",
"// because there was no way to track ownership of the data.",
"value_copy",
":=",
"yaml_tag_directive_t",
"{",
"handle",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"value",
".",
"handle",
")",
")",
",",
"prefix",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"value",
".",
"prefix",
")",
")",
",",
"}",
"\n",
"copy",
"(",
"value_copy",
".",
"handle",
",",
"value",
".",
"handle",
")",
"\n",
"copy",
"(",
"value_copy",
".",
"prefix",
",",
"value",
".",
"prefix",
")",
"\n",
"parser",
".",
"tag_directives",
"=",
"append",
"(",
"parser",
".",
"tag_directives",
",",
"value_copy",
")",
"\n",
"return",
"true",
"\n",
"}"
] | // Append a tag directive to the directives stack. | [
"Append",
"a",
"tag",
"directive",
"to",
"the",
"directives",
"stack",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/parserc.go#L1076-L1096 | train |
kubernetes-retired/contrib | service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/secret.go | handleFromFileSources | func handleFromFileSources(secret *api.Secret, fileSources []string) error {
for _, fileSource := range fileSources {
keyName, filePath, err := parseFileSource(fileSource)
if err != nil {
return err
}
info, err := os.Stat(filePath)
if err != nil {
switch err := err.(type) {
case *os.PathError:
return fmt.Errorf("error reading %s: %v", filePath, err.Err)
default:
return fmt.Errorf("error reading %s: %v", filePath, err)
}
}
if info.IsDir() {
if strings.Contains(fileSource, "=") {
return fmt.Errorf("cannot give a key name for a directory path.")
}
fileList, err := ioutil.ReadDir(filePath)
if err != nil {
return fmt.Errorf("error listing files in %s: %v", filePath, err)
}
for _, item := range fileList {
itemPath := path.Join(filePath, item.Name())
if item.Mode().IsRegular() {
keyName = item.Name()
err = addKeyFromFileToSecret(secret, keyName, itemPath)
if err != nil {
return err
}
}
}
} else {
err = addKeyFromFileToSecret(secret, keyName, filePath)
if err != nil {
return err
}
}
}
return nil
} | go | func handleFromFileSources(secret *api.Secret, fileSources []string) error {
for _, fileSource := range fileSources {
keyName, filePath, err := parseFileSource(fileSource)
if err != nil {
return err
}
info, err := os.Stat(filePath)
if err != nil {
switch err := err.(type) {
case *os.PathError:
return fmt.Errorf("error reading %s: %v", filePath, err.Err)
default:
return fmt.Errorf("error reading %s: %v", filePath, err)
}
}
if info.IsDir() {
if strings.Contains(fileSource, "=") {
return fmt.Errorf("cannot give a key name for a directory path.")
}
fileList, err := ioutil.ReadDir(filePath)
if err != nil {
return fmt.Errorf("error listing files in %s: %v", filePath, err)
}
for _, item := range fileList {
itemPath := path.Join(filePath, item.Name())
if item.Mode().IsRegular() {
keyName = item.Name()
err = addKeyFromFileToSecret(secret, keyName, itemPath)
if err != nil {
return err
}
}
}
} else {
err = addKeyFromFileToSecret(secret, keyName, filePath)
if err != nil {
return err
}
}
}
return nil
} | [
"func",
"handleFromFileSources",
"(",
"secret",
"*",
"api",
".",
"Secret",
",",
"fileSources",
"[",
"]",
"string",
")",
"error",
"{",
"for",
"_",
",",
"fileSource",
":=",
"range",
"fileSources",
"{",
"keyName",
",",
"filePath",
",",
"err",
":=",
"parseFileSource",
"(",
"fileSource",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"info",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"os",
".",
"PathError",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"filePath",
",",
"err",
".",
"Err",
")",
"\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"filePath",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"info",
".",
"IsDir",
"(",
")",
"{",
"if",
"strings",
".",
"Contains",
"(",
"fileSource",
",",
"\"",
"\"",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"fileList",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"filePath",
",",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"item",
":=",
"range",
"fileList",
"{",
"itemPath",
":=",
"path",
".",
"Join",
"(",
"filePath",
",",
"item",
".",
"Name",
"(",
")",
")",
"\n",
"if",
"item",
".",
"Mode",
"(",
")",
".",
"IsRegular",
"(",
")",
"{",
"keyName",
"=",
"item",
".",
"Name",
"(",
")",
"\n",
"err",
"=",
"addKeyFromFileToSecret",
"(",
"secret",
",",
"keyName",
",",
"itemPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"err",
"=",
"addKeyFromFileToSecret",
"(",
"secret",
",",
"keyName",
",",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // handleFromFileSources adds the specified file source information into the provided secret | [
"handleFromFileSources",
"adds",
"the",
"specified",
"file",
"source",
"information",
"into",
"the",
"provided",
"secret"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/service-loadbalancer/Godeps/_workspace/src/k8s.io/kubernetes/pkg/kubectl/secret.go#L146-L188 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/transport/transport.go | New | func New(config *Config) (http.RoundTripper, error) {
// Set transport level security
if config.Transport != nil && (config.HasCA() || config.HasCertAuth() || config.TLS.Insecure) {
return nil, fmt.Errorf("using a custom transport with TLS certificate options or the insecure flag is not allowed")
}
var (
rt http.RoundTripper
err error
)
if config.Transport != nil {
rt = config.Transport
} else {
rt, err = tlsCache.get(config)
if err != nil {
return nil, err
}
}
return HTTPWrappersForConfig(config, rt)
} | go | func New(config *Config) (http.RoundTripper, error) {
// Set transport level security
if config.Transport != nil && (config.HasCA() || config.HasCertAuth() || config.TLS.Insecure) {
return nil, fmt.Errorf("using a custom transport with TLS certificate options or the insecure flag is not allowed")
}
var (
rt http.RoundTripper
err error
)
if config.Transport != nil {
rt = config.Transport
} else {
rt, err = tlsCache.get(config)
if err != nil {
return nil, err
}
}
return HTTPWrappersForConfig(config, rt)
} | [
"func",
"New",
"(",
"config",
"*",
"Config",
")",
"(",
"http",
".",
"RoundTripper",
",",
"error",
")",
"{",
"// Set transport level security",
"if",
"config",
".",
"Transport",
"!=",
"nil",
"&&",
"(",
"config",
".",
"HasCA",
"(",
")",
"||",
"config",
".",
"HasCertAuth",
"(",
")",
"||",
"config",
".",
"TLS",
".",
"Insecure",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"(",
"rt",
"http",
".",
"RoundTripper",
"\n",
"err",
"error",
"\n",
")",
"\n\n",
"if",
"config",
".",
"Transport",
"!=",
"nil",
"{",
"rt",
"=",
"config",
".",
"Transport",
"\n",
"}",
"else",
"{",
"rt",
",",
"err",
"=",
"tlsCache",
".",
"get",
"(",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"HTTPWrappersForConfig",
"(",
"config",
",",
"rt",
")",
"\n",
"}"
] | // New returns an http.RoundTripper that will provide the authentication
// or transport level security defined by the provided Config. | [
"New",
"returns",
"an",
"http",
".",
"RoundTripper",
"that",
"will",
"provide",
"the",
"authentication",
"or",
"transport",
"level",
"security",
"defined",
"by",
"the",
"provided",
"Config",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/client/transport/transport.go#L29-L50 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/exec/exec.go | Command | func (executor *executor) Command(cmd string, args ...string) Cmd {
return (*cmdWrapper)(osexec.Command(cmd, args...))
} | go | func (executor *executor) Command(cmd string, args ...string) Cmd {
return (*cmdWrapper)(osexec.Command(cmd, args...))
} | [
"func",
"(",
"executor",
"*",
"executor",
")",
"Command",
"(",
"cmd",
"string",
",",
"args",
"...",
"string",
")",
"Cmd",
"{",
"return",
"(",
"*",
"cmdWrapper",
")",
"(",
"osexec",
".",
"Command",
"(",
"cmd",
",",
"args",
"...",
")",
")",
"\n",
"}"
] | // Command is part of the Interface interface. | [
"Command",
"is",
"part",
"of",
"the",
"Interface",
"interface",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/exec/exec.go#L67-L69 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/exec/exec.go | LookPath | func (executor *executor) LookPath(file string) (string, error) {
return osexec.LookPath(file)
} | go | func (executor *executor) LookPath(file string) (string, error) {
return osexec.LookPath(file)
} | [
"func",
"(",
"executor",
"*",
"executor",
")",
"LookPath",
"(",
"file",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"osexec",
".",
"LookPath",
"(",
"file",
")",
"\n",
"}"
] | // LookPath is part of the Interface interface | [
"LookPath",
"is",
"part",
"of",
"the",
"Interface",
"interface"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/exec/exec.go#L72-L74 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/exec/exec.go | CombinedOutput | func (cmd *cmdWrapper) CombinedOutput() ([]byte, error) {
out, err := (*osexec.Cmd)(cmd).CombinedOutput()
if err != nil {
if ee, ok := err.(*osexec.ExitError); ok {
// Force a compile fail if exitErrorWrapper can't convert to ExitError.
var x ExitError = &exitErrorWrapper{ee}
return out, x
}
if ee, ok := err.(*osexec.Error); ok {
if ee.Err == osexec.ErrNotFound {
return out, ErrExecutableNotFound
}
}
return out, err
}
return out, nil
} | go | func (cmd *cmdWrapper) CombinedOutput() ([]byte, error) {
out, err := (*osexec.Cmd)(cmd).CombinedOutput()
if err != nil {
if ee, ok := err.(*osexec.ExitError); ok {
// Force a compile fail if exitErrorWrapper can't convert to ExitError.
var x ExitError = &exitErrorWrapper{ee}
return out, x
}
if ee, ok := err.(*osexec.Error); ok {
if ee.Err == osexec.ErrNotFound {
return out, ErrExecutableNotFound
}
}
return out, err
}
return out, nil
} | [
"func",
"(",
"cmd",
"*",
"cmdWrapper",
")",
"CombinedOutput",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"out",
",",
"err",
":=",
"(",
"*",
"osexec",
".",
"Cmd",
")",
"(",
"cmd",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"ee",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"osexec",
".",
"ExitError",
")",
";",
"ok",
"{",
"// Force a compile fail if exitErrorWrapper can't convert to ExitError.",
"var",
"x",
"ExitError",
"=",
"&",
"exitErrorWrapper",
"{",
"ee",
"}",
"\n",
"return",
"out",
",",
"x",
"\n",
"}",
"\n",
"if",
"ee",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"osexec",
".",
"Error",
")",
";",
"ok",
"{",
"if",
"ee",
".",
"Err",
"==",
"osexec",
".",
"ErrNotFound",
"{",
"return",
"out",
",",
"ErrExecutableNotFound",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"out",
",",
"err",
"\n",
"}",
"\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // CombinedOutput is part of the Cmd interface. | [
"CombinedOutput",
"is",
"part",
"of",
"the",
"Cmd",
"interface",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/exec/exec.go#L84-L100 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/exec/exec.go | ExitStatus | func (eew exitErrorWrapper) ExitStatus() int {
ws, ok := eew.Sys().(syscall.WaitStatus)
if !ok {
panic("can't call ExitStatus() on a non-WaitStatus exitErrorWrapper")
}
return ws.ExitStatus()
} | go | func (eew exitErrorWrapper) ExitStatus() int {
ws, ok := eew.Sys().(syscall.WaitStatus)
if !ok {
panic("can't call ExitStatus() on a non-WaitStatus exitErrorWrapper")
}
return ws.ExitStatus()
} | [
"func",
"(",
"eew",
"exitErrorWrapper",
")",
"ExitStatus",
"(",
")",
"int",
"{",
"ws",
",",
"ok",
":=",
"eew",
".",
"Sys",
"(",
")",
".",
"(",
"syscall",
".",
"WaitStatus",
")",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"ws",
".",
"ExitStatus",
"(",
")",
"\n",
"}"
] | // ExitStatus is part of the ExitError interface. | [
"ExitStatus",
"is",
"part",
"of",
"the",
"ExitError",
"interface",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/exec/exec.go#L109-L115 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/wsstream/stream.go | NewReader | func NewReader(r io.Reader, ping bool) *Reader {
return &Reader{
r: r,
err: make(chan error),
ping: ping,
}
} | go | func NewReader(r io.Reader, ping bool) *Reader {
return &Reader{
r: r,
err: make(chan error),
ping: ping,
}
} | [
"func",
"NewReader",
"(",
"r",
"io",
".",
"Reader",
",",
"ping",
"bool",
")",
"*",
"Reader",
"{",
"return",
"&",
"Reader",
"{",
"r",
":",
"r",
",",
"err",
":",
"make",
"(",
"chan",
"error",
")",
",",
"ping",
":",
"ping",
",",
"}",
"\n",
"}"
] | // NewReader creates a WebSocket pipe that will copy the contents of r to a provided
// WebSocket connection. If ping is true, a zero length message will be sent to the client
// before the stream begins reading. | [
"NewReader",
"creates",
"a",
"WebSocket",
"pipe",
"that",
"will",
"copy",
"the",
"contents",
"of",
"r",
"to",
"a",
"provided",
"WebSocket",
"connection",
".",
"If",
"ping",
"is",
"true",
"a",
"zero",
"length",
"message",
"will",
"be",
"sent",
"to",
"the",
"client",
"before",
"the",
"stream",
"begins",
"reading",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/wsstream/stream.go#L52-L58 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/wsstream/stream.go | Copy | func (r *Reader) Copy(w http.ResponseWriter, req *http.Request) error {
go func() {
defer util.HandleCrash()
websocket.Server{Handshake: r.handshake, Handler: r.handle}.ServeHTTP(w, req)
}()
return <-r.err
} | go | func (r *Reader) Copy(w http.ResponseWriter, req *http.Request) error {
go func() {
defer util.HandleCrash()
websocket.Server{Handshake: r.handshake, Handler: r.handle}.ServeHTTP(w, req)
}()
return <-r.err
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"Copy",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"go",
"func",
"(",
")",
"{",
"defer",
"util",
".",
"HandleCrash",
"(",
")",
"\n",
"websocket",
".",
"Server",
"{",
"Handshake",
":",
"r",
".",
"handshake",
",",
"Handler",
":",
"r",
".",
"handle",
"}",
".",
"ServeHTTP",
"(",
"w",
",",
"req",
")",
"\n",
"}",
"(",
")",
"\n",
"return",
"<-",
"r",
".",
"err",
"\n",
"}"
] | // Copy the reader to the response. The created WebSocket is closed after this
// method completes. | [
"Copy",
"the",
"reader",
"to",
"the",
"response",
".",
"The",
"created",
"WebSocket",
"is",
"closed",
"after",
"this",
"method",
"completes",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/wsstream/stream.go#L72-L78 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | flush | func flush(emitter *yaml_emitter_t) bool {
if emitter.buffer_pos+5 >= len(emitter.buffer) {
return yaml_emitter_flush(emitter)
}
return true
} | go | func flush(emitter *yaml_emitter_t) bool {
if emitter.buffer_pos+5 >= len(emitter.buffer) {
return yaml_emitter_flush(emitter)
}
return true
} | [
"func",
"flush",
"(",
"emitter",
"*",
"yaml_emitter_t",
")",
"bool",
"{",
"if",
"emitter",
".",
"buffer_pos",
"+",
"5",
">=",
"len",
"(",
"emitter",
".",
"buffer",
")",
"{",
"return",
"yaml_emitter_flush",
"(",
"emitter",
")",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Flush the buffer if needed. | [
"Flush",
"the",
"buffer",
"if",
"needed",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L8-L13 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | put | func put(emitter *yaml_emitter_t, value byte) bool {
if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) {
return false
}
emitter.buffer[emitter.buffer_pos] = value
emitter.buffer_pos++
emitter.column++
return true
} | go | func put(emitter *yaml_emitter_t, value byte) bool {
if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) {
return false
}
emitter.buffer[emitter.buffer_pos] = value
emitter.buffer_pos++
emitter.column++
return true
} | [
"func",
"put",
"(",
"emitter",
"*",
"yaml_emitter_t",
",",
"value",
"byte",
")",
"bool",
"{",
"if",
"emitter",
".",
"buffer_pos",
"+",
"5",
">=",
"len",
"(",
"emitter",
".",
"buffer",
")",
"&&",
"!",
"yaml_emitter_flush",
"(",
"emitter",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"emitter",
".",
"buffer",
"[",
"emitter",
".",
"buffer_pos",
"]",
"=",
"value",
"\n",
"emitter",
".",
"buffer_pos",
"++",
"\n",
"emitter",
".",
"column",
"++",
"\n",
"return",
"true",
"\n",
"}"
] | // Put a character to the output buffer. | [
"Put",
"a",
"character",
"to",
"the",
"output",
"buffer",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L16-L24 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | put_break | func put_break(emitter *yaml_emitter_t) bool {
if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) {
return false
}
switch emitter.line_break {
case yaml_CR_BREAK:
emitter.buffer[emitter.buffer_pos] = '\r'
emitter.buffer_pos += 1
case yaml_LN_BREAK:
emitter.buffer[emitter.buffer_pos] = '\n'
emitter.buffer_pos += 1
case yaml_CRLN_BREAK:
emitter.buffer[emitter.buffer_pos+0] = '\r'
emitter.buffer[emitter.buffer_pos+1] = '\n'
emitter.buffer_pos += 2
default:
panic("unknown line break setting")
}
emitter.column = 0
emitter.line++
return true
} | go | func put_break(emitter *yaml_emitter_t) bool {
if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) {
return false
}
switch emitter.line_break {
case yaml_CR_BREAK:
emitter.buffer[emitter.buffer_pos] = '\r'
emitter.buffer_pos += 1
case yaml_LN_BREAK:
emitter.buffer[emitter.buffer_pos] = '\n'
emitter.buffer_pos += 1
case yaml_CRLN_BREAK:
emitter.buffer[emitter.buffer_pos+0] = '\r'
emitter.buffer[emitter.buffer_pos+1] = '\n'
emitter.buffer_pos += 2
default:
panic("unknown line break setting")
}
emitter.column = 0
emitter.line++
return true
} | [
"func",
"put_break",
"(",
"emitter",
"*",
"yaml_emitter_t",
")",
"bool",
"{",
"if",
"emitter",
".",
"buffer_pos",
"+",
"5",
">=",
"len",
"(",
"emitter",
".",
"buffer",
")",
"&&",
"!",
"yaml_emitter_flush",
"(",
"emitter",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"switch",
"emitter",
".",
"line_break",
"{",
"case",
"yaml_CR_BREAK",
":",
"emitter",
".",
"buffer",
"[",
"emitter",
".",
"buffer_pos",
"]",
"=",
"'\\r'",
"\n",
"emitter",
".",
"buffer_pos",
"+=",
"1",
"\n",
"case",
"yaml_LN_BREAK",
":",
"emitter",
".",
"buffer",
"[",
"emitter",
".",
"buffer_pos",
"]",
"=",
"'\\n'",
"\n",
"emitter",
".",
"buffer_pos",
"+=",
"1",
"\n",
"case",
"yaml_CRLN_BREAK",
":",
"emitter",
".",
"buffer",
"[",
"emitter",
".",
"buffer_pos",
"+",
"0",
"]",
"=",
"'\\r'",
"\n",
"emitter",
".",
"buffer",
"[",
"emitter",
".",
"buffer_pos",
"+",
"1",
"]",
"=",
"'\\n'",
"\n",
"emitter",
".",
"buffer_pos",
"+=",
"2",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"emitter",
".",
"column",
"=",
"0",
"\n",
"emitter",
".",
"line",
"++",
"\n",
"return",
"true",
"\n",
"}"
] | // Put a line break to the output buffer. | [
"Put",
"a",
"line",
"break",
"to",
"the",
"output",
"buffer",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L27-L48 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | write | func write(emitter *yaml_emitter_t, s []byte, i *int) bool {
if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) {
return false
}
p := emitter.buffer_pos
w := width(s[*i])
switch w {
case 4:
emitter.buffer[p+3] = s[*i+3]
fallthrough
case 3:
emitter.buffer[p+2] = s[*i+2]
fallthrough
case 2:
emitter.buffer[p+1] = s[*i+1]
fallthrough
case 1:
emitter.buffer[p+0] = s[*i+0]
default:
panic("unknown character width")
}
emitter.column++
emitter.buffer_pos += w
*i += w
return true
} | go | func write(emitter *yaml_emitter_t, s []byte, i *int) bool {
if emitter.buffer_pos+5 >= len(emitter.buffer) && !yaml_emitter_flush(emitter) {
return false
}
p := emitter.buffer_pos
w := width(s[*i])
switch w {
case 4:
emitter.buffer[p+3] = s[*i+3]
fallthrough
case 3:
emitter.buffer[p+2] = s[*i+2]
fallthrough
case 2:
emitter.buffer[p+1] = s[*i+1]
fallthrough
case 1:
emitter.buffer[p+0] = s[*i+0]
default:
panic("unknown character width")
}
emitter.column++
emitter.buffer_pos += w
*i += w
return true
} | [
"func",
"write",
"(",
"emitter",
"*",
"yaml_emitter_t",
",",
"s",
"[",
"]",
"byte",
",",
"i",
"*",
"int",
")",
"bool",
"{",
"if",
"emitter",
".",
"buffer_pos",
"+",
"5",
">=",
"len",
"(",
"emitter",
".",
"buffer",
")",
"&&",
"!",
"yaml_emitter_flush",
"(",
"emitter",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"p",
":=",
"emitter",
".",
"buffer_pos",
"\n",
"w",
":=",
"width",
"(",
"s",
"[",
"*",
"i",
"]",
")",
"\n",
"switch",
"w",
"{",
"case",
"4",
":",
"emitter",
".",
"buffer",
"[",
"p",
"+",
"3",
"]",
"=",
"s",
"[",
"*",
"i",
"+",
"3",
"]",
"\n",
"fallthrough",
"\n",
"case",
"3",
":",
"emitter",
".",
"buffer",
"[",
"p",
"+",
"2",
"]",
"=",
"s",
"[",
"*",
"i",
"+",
"2",
"]",
"\n",
"fallthrough",
"\n",
"case",
"2",
":",
"emitter",
".",
"buffer",
"[",
"p",
"+",
"1",
"]",
"=",
"s",
"[",
"*",
"i",
"+",
"1",
"]",
"\n",
"fallthrough",
"\n",
"case",
"1",
":",
"emitter",
".",
"buffer",
"[",
"p",
"+",
"0",
"]",
"=",
"s",
"[",
"*",
"i",
"+",
"0",
"]",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"emitter",
".",
"column",
"++",
"\n",
"emitter",
".",
"buffer_pos",
"+=",
"w",
"\n",
"*",
"i",
"+=",
"w",
"\n",
"return",
"true",
"\n",
"}"
] | // Copy a character from a string into buffer. | [
"Copy",
"a",
"character",
"from",
"a",
"string",
"into",
"buffer",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L51-L76 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | write_all | func write_all(emitter *yaml_emitter_t, s []byte) bool {
for i := 0; i < len(s); {
if !write(emitter, s, &i) {
return false
}
}
return true
} | go | func write_all(emitter *yaml_emitter_t, s []byte) bool {
for i := 0; i < len(s); {
if !write(emitter, s, &i) {
return false
}
}
return true
} | [
"func",
"write_all",
"(",
"emitter",
"*",
"yaml_emitter_t",
",",
"s",
"[",
"]",
"byte",
")",
"bool",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"s",
")",
";",
"{",
"if",
"!",
"write",
"(",
"emitter",
",",
"s",
",",
"&",
"i",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Write a whole string into buffer. | [
"Write",
"a",
"whole",
"string",
"into",
"buffer",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L79-L86 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | write_break | func write_break(emitter *yaml_emitter_t, s []byte, i *int) bool {
if s[*i] == '\n' {
if !put_break(emitter) {
return false
}
*i++
} else {
if !write(emitter, s, i) {
return false
}
emitter.column = 0
emitter.line++
}
return true
} | go | func write_break(emitter *yaml_emitter_t, s []byte, i *int) bool {
if s[*i] == '\n' {
if !put_break(emitter) {
return false
}
*i++
} else {
if !write(emitter, s, i) {
return false
}
emitter.column = 0
emitter.line++
}
return true
} | [
"func",
"write_break",
"(",
"emitter",
"*",
"yaml_emitter_t",
",",
"s",
"[",
"]",
"byte",
",",
"i",
"*",
"int",
")",
"bool",
"{",
"if",
"s",
"[",
"*",
"i",
"]",
"==",
"'\\n'",
"{",
"if",
"!",
"put_break",
"(",
"emitter",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"*",
"i",
"++",
"\n",
"}",
"else",
"{",
"if",
"!",
"write",
"(",
"emitter",
",",
"s",
",",
"i",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"emitter",
".",
"column",
"=",
"0",
"\n",
"emitter",
".",
"line",
"++",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Copy a line break character from a string into buffer. | [
"Copy",
"a",
"line",
"break",
"character",
"from",
"a",
"string",
"into",
"buffer",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L89-L103 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | yaml_emitter_set_emitter_error | func yaml_emitter_set_emitter_error(emitter *yaml_emitter_t, problem string) bool {
emitter.error = yaml_EMITTER_ERROR
emitter.problem = problem
return false
} | go | func yaml_emitter_set_emitter_error(emitter *yaml_emitter_t, problem string) bool {
emitter.error = yaml_EMITTER_ERROR
emitter.problem = problem
return false
} | [
"func",
"yaml_emitter_set_emitter_error",
"(",
"emitter",
"*",
"yaml_emitter_t",
",",
"problem",
"string",
")",
"bool",
"{",
"emitter",
".",
"error",
"=",
"yaml_EMITTER_ERROR",
"\n",
"emitter",
".",
"problem",
"=",
"problem",
"\n",
"return",
"false",
"\n",
"}"
] | // Set an emitter error and return false. | [
"Set",
"an",
"emitter",
"error",
"and",
"return",
"false",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L106-L110 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | yaml_emitter_emit | func yaml_emitter_emit(emitter *yaml_emitter_t, event *yaml_event_t) bool {
emitter.events = append(emitter.events, *event)
for !yaml_emitter_need_more_events(emitter) {
event := &emitter.events[emitter.events_head]
if !yaml_emitter_analyze_event(emitter, event) {
return false
}
if !yaml_emitter_state_machine(emitter, event) {
return false
}
yaml_event_delete(event)
emitter.events_head++
}
return true
} | go | func yaml_emitter_emit(emitter *yaml_emitter_t, event *yaml_event_t) bool {
emitter.events = append(emitter.events, *event)
for !yaml_emitter_need_more_events(emitter) {
event := &emitter.events[emitter.events_head]
if !yaml_emitter_analyze_event(emitter, event) {
return false
}
if !yaml_emitter_state_machine(emitter, event) {
return false
}
yaml_event_delete(event)
emitter.events_head++
}
return true
} | [
"func",
"yaml_emitter_emit",
"(",
"emitter",
"*",
"yaml_emitter_t",
",",
"event",
"*",
"yaml_event_t",
")",
"bool",
"{",
"emitter",
".",
"events",
"=",
"append",
"(",
"emitter",
".",
"events",
",",
"*",
"event",
")",
"\n",
"for",
"!",
"yaml_emitter_need_more_events",
"(",
"emitter",
")",
"{",
"event",
":=",
"&",
"emitter",
".",
"events",
"[",
"emitter",
".",
"events_head",
"]",
"\n",
"if",
"!",
"yaml_emitter_analyze_event",
"(",
"emitter",
",",
"event",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"yaml_emitter_state_machine",
"(",
"emitter",
",",
"event",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"yaml_event_delete",
"(",
"event",
")",
"\n",
"emitter",
".",
"events_head",
"++",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Emit an event. | [
"Emit",
"an",
"event",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L113-L127 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | yaml_emitter_need_more_events | func yaml_emitter_need_more_events(emitter *yaml_emitter_t) bool {
if emitter.events_head == len(emitter.events) {
return true
}
var accumulate int
switch emitter.events[emitter.events_head].typ {
case yaml_DOCUMENT_START_EVENT:
accumulate = 1
break
case yaml_SEQUENCE_START_EVENT:
accumulate = 2
break
case yaml_MAPPING_START_EVENT:
accumulate = 3
break
default:
return false
}
if len(emitter.events)-emitter.events_head > accumulate {
return false
}
var level int
for i := emitter.events_head; i < len(emitter.events); i++ {
switch emitter.events[i].typ {
case yaml_STREAM_START_EVENT, yaml_DOCUMENT_START_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT:
level++
case yaml_STREAM_END_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_END_EVENT, yaml_MAPPING_END_EVENT:
level--
}
if level == 0 {
return false
}
}
return true
} | go | func yaml_emitter_need_more_events(emitter *yaml_emitter_t) bool {
if emitter.events_head == len(emitter.events) {
return true
}
var accumulate int
switch emitter.events[emitter.events_head].typ {
case yaml_DOCUMENT_START_EVENT:
accumulate = 1
break
case yaml_SEQUENCE_START_EVENT:
accumulate = 2
break
case yaml_MAPPING_START_EVENT:
accumulate = 3
break
default:
return false
}
if len(emitter.events)-emitter.events_head > accumulate {
return false
}
var level int
for i := emitter.events_head; i < len(emitter.events); i++ {
switch emitter.events[i].typ {
case yaml_STREAM_START_EVENT, yaml_DOCUMENT_START_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT:
level++
case yaml_STREAM_END_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_END_EVENT, yaml_MAPPING_END_EVENT:
level--
}
if level == 0 {
return false
}
}
return true
} | [
"func",
"yaml_emitter_need_more_events",
"(",
"emitter",
"*",
"yaml_emitter_t",
")",
"bool",
"{",
"if",
"emitter",
".",
"events_head",
"==",
"len",
"(",
"emitter",
".",
"events",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"var",
"accumulate",
"int",
"\n",
"switch",
"emitter",
".",
"events",
"[",
"emitter",
".",
"events_head",
"]",
".",
"typ",
"{",
"case",
"yaml_DOCUMENT_START_EVENT",
":",
"accumulate",
"=",
"1",
"\n",
"break",
"\n",
"case",
"yaml_SEQUENCE_START_EVENT",
":",
"accumulate",
"=",
"2",
"\n",
"break",
"\n",
"case",
"yaml_MAPPING_START_EVENT",
":",
"accumulate",
"=",
"3",
"\n",
"break",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"if",
"len",
"(",
"emitter",
".",
"events",
")",
"-",
"emitter",
".",
"events_head",
">",
"accumulate",
"{",
"return",
"false",
"\n",
"}",
"\n",
"var",
"level",
"int",
"\n",
"for",
"i",
":=",
"emitter",
".",
"events_head",
";",
"i",
"<",
"len",
"(",
"emitter",
".",
"events",
")",
";",
"i",
"++",
"{",
"switch",
"emitter",
".",
"events",
"[",
"i",
"]",
".",
"typ",
"{",
"case",
"yaml_STREAM_START_EVENT",
",",
"yaml_DOCUMENT_START_EVENT",
",",
"yaml_SEQUENCE_START_EVENT",
",",
"yaml_MAPPING_START_EVENT",
":",
"level",
"++",
"\n",
"case",
"yaml_STREAM_END_EVENT",
",",
"yaml_DOCUMENT_END_EVENT",
",",
"yaml_SEQUENCE_END_EVENT",
",",
"yaml_MAPPING_END_EVENT",
":",
"level",
"--",
"\n",
"}",
"\n",
"if",
"level",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Check if we need to accumulate more events before emitting.
//
// We accumulate extra
// - 1 event for DOCUMENT-START
// - 2 events for SEQUENCE-START
// - 3 events for MAPPING-START
// | [
"Check",
"if",
"we",
"need",
"to",
"accumulate",
"more",
"events",
"before",
"emitting",
".",
"We",
"accumulate",
"extra",
"-",
"1",
"event",
"for",
"DOCUMENT",
"-",
"START",
"-",
"2",
"events",
"for",
"SEQUENCE",
"-",
"START",
"-",
"3",
"events",
"for",
"MAPPING",
"-",
"START"
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L136-L170 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | yaml_emitter_append_tag_directive | func yaml_emitter_append_tag_directive(emitter *yaml_emitter_t, value *yaml_tag_directive_t, allow_duplicates bool) bool {
for i := 0; i < len(emitter.tag_directives); i++ {
if bytes.Equal(value.handle, emitter.tag_directives[i].handle) {
if allow_duplicates {
return true
}
return yaml_emitter_set_emitter_error(emitter, "duplicate %TAG directive")
}
}
// [Go] Do we actually need to copy this given garbage collection
// and the lack of deallocating destructors?
tag_copy := yaml_tag_directive_t{
handle: make([]byte, len(value.handle)),
prefix: make([]byte, len(value.prefix)),
}
copy(tag_copy.handle, value.handle)
copy(tag_copy.prefix, value.prefix)
emitter.tag_directives = append(emitter.tag_directives, tag_copy)
return true
} | go | func yaml_emitter_append_tag_directive(emitter *yaml_emitter_t, value *yaml_tag_directive_t, allow_duplicates bool) bool {
for i := 0; i < len(emitter.tag_directives); i++ {
if bytes.Equal(value.handle, emitter.tag_directives[i].handle) {
if allow_duplicates {
return true
}
return yaml_emitter_set_emitter_error(emitter, "duplicate %TAG directive")
}
}
// [Go] Do we actually need to copy this given garbage collection
// and the lack of deallocating destructors?
tag_copy := yaml_tag_directive_t{
handle: make([]byte, len(value.handle)),
prefix: make([]byte, len(value.prefix)),
}
copy(tag_copy.handle, value.handle)
copy(tag_copy.prefix, value.prefix)
emitter.tag_directives = append(emitter.tag_directives, tag_copy)
return true
} | [
"func",
"yaml_emitter_append_tag_directive",
"(",
"emitter",
"*",
"yaml_emitter_t",
",",
"value",
"*",
"yaml_tag_directive_t",
",",
"allow_duplicates",
"bool",
")",
"bool",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"emitter",
".",
"tag_directives",
")",
";",
"i",
"++",
"{",
"if",
"bytes",
".",
"Equal",
"(",
"value",
".",
"handle",
",",
"emitter",
".",
"tag_directives",
"[",
"i",
"]",
".",
"handle",
")",
"{",
"if",
"allow_duplicates",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"yaml_emitter_set_emitter_error",
"(",
"emitter",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// [Go] Do we actually need to copy this given garbage collection",
"// and the lack of deallocating destructors?",
"tag_copy",
":=",
"yaml_tag_directive_t",
"{",
"handle",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"value",
".",
"handle",
")",
")",
",",
"prefix",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"value",
".",
"prefix",
")",
")",
",",
"}",
"\n",
"copy",
"(",
"tag_copy",
".",
"handle",
",",
"value",
".",
"handle",
")",
"\n",
"copy",
"(",
"tag_copy",
".",
"prefix",
",",
"value",
".",
"prefix",
")",
"\n",
"emitter",
".",
"tag_directives",
"=",
"append",
"(",
"emitter",
".",
"tag_directives",
",",
"tag_copy",
")",
"\n",
"return",
"true",
"\n",
"}"
] | // Append a directive to the directives stack. | [
"Append",
"a",
"directive",
"to",
"the",
"directives",
"stack",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L173-L193 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | yaml_emitter_increase_indent | func yaml_emitter_increase_indent(emitter *yaml_emitter_t, flow, indentless bool) bool {
emitter.indents = append(emitter.indents, emitter.indent)
if emitter.indent < 0 {
if flow {
emitter.indent = emitter.best_indent
} else {
emitter.indent = 0
}
} else if !indentless {
emitter.indent += emitter.best_indent
}
return true
} | go | func yaml_emitter_increase_indent(emitter *yaml_emitter_t, flow, indentless bool) bool {
emitter.indents = append(emitter.indents, emitter.indent)
if emitter.indent < 0 {
if flow {
emitter.indent = emitter.best_indent
} else {
emitter.indent = 0
}
} else if !indentless {
emitter.indent += emitter.best_indent
}
return true
} | [
"func",
"yaml_emitter_increase_indent",
"(",
"emitter",
"*",
"yaml_emitter_t",
",",
"flow",
",",
"indentless",
"bool",
")",
"bool",
"{",
"emitter",
".",
"indents",
"=",
"append",
"(",
"emitter",
".",
"indents",
",",
"emitter",
".",
"indent",
")",
"\n",
"if",
"emitter",
".",
"indent",
"<",
"0",
"{",
"if",
"flow",
"{",
"emitter",
".",
"indent",
"=",
"emitter",
".",
"best_indent",
"\n",
"}",
"else",
"{",
"emitter",
".",
"indent",
"=",
"0",
"\n",
"}",
"\n",
"}",
"else",
"if",
"!",
"indentless",
"{",
"emitter",
".",
"indent",
"+=",
"emitter",
".",
"best_indent",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // Increase the indentation level. | [
"Increase",
"the",
"indentation",
"level",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L196-L208 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | yaml_emitter_emit_stream_start | func yaml_emitter_emit_stream_start(emitter *yaml_emitter_t, event *yaml_event_t) bool {
if event.typ != yaml_STREAM_START_EVENT {
return yaml_emitter_set_emitter_error(emitter, "expected STREAM-START")
}
if emitter.encoding == yaml_ANY_ENCODING {
emitter.encoding = event.encoding
if emitter.encoding == yaml_ANY_ENCODING {
emitter.encoding = yaml_UTF8_ENCODING
}
}
if emitter.best_indent < 2 || emitter.best_indent > 9 {
emitter.best_indent = 2
}
if emitter.best_width >= 0 && emitter.best_width <= emitter.best_indent*2 {
emitter.best_width = 80
}
if emitter.best_width < 0 {
emitter.best_width = 1<<31 - 1
}
if emitter.line_break == yaml_ANY_BREAK {
emitter.line_break = yaml_LN_BREAK
}
emitter.indent = -1
emitter.line = 0
emitter.column = 0
emitter.whitespace = true
emitter.indention = true
if emitter.encoding != yaml_UTF8_ENCODING {
if !yaml_emitter_write_bom(emitter) {
return false
}
}
emitter.state = yaml_EMIT_FIRST_DOCUMENT_START_STATE
return true
} | go | func yaml_emitter_emit_stream_start(emitter *yaml_emitter_t, event *yaml_event_t) bool {
if event.typ != yaml_STREAM_START_EVENT {
return yaml_emitter_set_emitter_error(emitter, "expected STREAM-START")
}
if emitter.encoding == yaml_ANY_ENCODING {
emitter.encoding = event.encoding
if emitter.encoding == yaml_ANY_ENCODING {
emitter.encoding = yaml_UTF8_ENCODING
}
}
if emitter.best_indent < 2 || emitter.best_indent > 9 {
emitter.best_indent = 2
}
if emitter.best_width >= 0 && emitter.best_width <= emitter.best_indent*2 {
emitter.best_width = 80
}
if emitter.best_width < 0 {
emitter.best_width = 1<<31 - 1
}
if emitter.line_break == yaml_ANY_BREAK {
emitter.line_break = yaml_LN_BREAK
}
emitter.indent = -1
emitter.line = 0
emitter.column = 0
emitter.whitespace = true
emitter.indention = true
if emitter.encoding != yaml_UTF8_ENCODING {
if !yaml_emitter_write_bom(emitter) {
return false
}
}
emitter.state = yaml_EMIT_FIRST_DOCUMENT_START_STATE
return true
} | [
"func",
"yaml_emitter_emit_stream_start",
"(",
"emitter",
"*",
"yaml_emitter_t",
",",
"event",
"*",
"yaml_event_t",
")",
"bool",
"{",
"if",
"event",
".",
"typ",
"!=",
"yaml_STREAM_START_EVENT",
"{",
"return",
"yaml_emitter_set_emitter_error",
"(",
"emitter",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"emitter",
".",
"encoding",
"==",
"yaml_ANY_ENCODING",
"{",
"emitter",
".",
"encoding",
"=",
"event",
".",
"encoding",
"\n",
"if",
"emitter",
".",
"encoding",
"==",
"yaml_ANY_ENCODING",
"{",
"emitter",
".",
"encoding",
"=",
"yaml_UTF8_ENCODING",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"emitter",
".",
"best_indent",
"<",
"2",
"||",
"emitter",
".",
"best_indent",
">",
"9",
"{",
"emitter",
".",
"best_indent",
"=",
"2",
"\n",
"}",
"\n",
"if",
"emitter",
".",
"best_width",
">=",
"0",
"&&",
"emitter",
".",
"best_width",
"<=",
"emitter",
".",
"best_indent",
"*",
"2",
"{",
"emitter",
".",
"best_width",
"=",
"80",
"\n",
"}",
"\n",
"if",
"emitter",
".",
"best_width",
"<",
"0",
"{",
"emitter",
".",
"best_width",
"=",
"1",
"<<",
"31",
"-",
"1",
"\n",
"}",
"\n",
"if",
"emitter",
".",
"line_break",
"==",
"yaml_ANY_BREAK",
"{",
"emitter",
".",
"line_break",
"=",
"yaml_LN_BREAK",
"\n",
"}",
"\n\n",
"emitter",
".",
"indent",
"=",
"-",
"1",
"\n",
"emitter",
".",
"line",
"=",
"0",
"\n",
"emitter",
".",
"column",
"=",
"0",
"\n",
"emitter",
".",
"whitespace",
"=",
"true",
"\n",
"emitter",
".",
"indention",
"=",
"true",
"\n\n",
"if",
"emitter",
".",
"encoding",
"!=",
"yaml_UTF8_ENCODING",
"{",
"if",
"!",
"yaml_emitter_write_bom",
"(",
"emitter",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"emitter",
".",
"state",
"=",
"yaml_EMIT_FIRST_DOCUMENT_START_STATE",
"\n",
"return",
"true",
"\n",
"}"
] | // Expect STREAM-START. | [
"Expect",
"STREAM",
"-",
"START",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L272-L308 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | yaml_emitter_emit_document_content | func yaml_emitter_emit_document_content(emitter *yaml_emitter_t, event *yaml_event_t) bool {
emitter.states = append(emitter.states, yaml_EMIT_DOCUMENT_END_STATE)
return yaml_emitter_emit_node(emitter, event, true, false, false, false)
} | go | func yaml_emitter_emit_document_content(emitter *yaml_emitter_t, event *yaml_event_t) bool {
emitter.states = append(emitter.states, yaml_EMIT_DOCUMENT_END_STATE)
return yaml_emitter_emit_node(emitter, event, true, false, false, false)
} | [
"func",
"yaml_emitter_emit_document_content",
"(",
"emitter",
"*",
"yaml_emitter_t",
",",
"event",
"*",
"yaml_event_t",
")",
"bool",
"{",
"emitter",
".",
"states",
"=",
"append",
"(",
"emitter",
".",
"states",
",",
"yaml_EMIT_DOCUMENT_END_STATE",
")",
"\n",
"return",
"yaml_emitter_emit_node",
"(",
"emitter",
",",
"event",
",",
"true",
",",
"false",
",",
"false",
",",
"false",
")",
"\n",
"}"
] | // Expect the root node. | [
"Expect",
"the",
"root",
"node",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L425-L428 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | yaml_emitter_emit_document_end | func yaml_emitter_emit_document_end(emitter *yaml_emitter_t, event *yaml_event_t) bool {
if event.typ != yaml_DOCUMENT_END_EVENT {
return yaml_emitter_set_emitter_error(emitter, "expected DOCUMENT-END")
}
if !yaml_emitter_write_indent(emitter) {
return false
}
if !event.implicit {
// [Go] Allocate the slice elsewhere.
if !yaml_emitter_write_indicator(emitter, []byte("..."), true, false, false) {
return false
}
if !yaml_emitter_write_indent(emitter) {
return false
}
}
if !yaml_emitter_flush(emitter) {
return false
}
emitter.state = yaml_EMIT_DOCUMENT_START_STATE
emitter.tag_directives = emitter.tag_directives[:0]
return true
} | go | func yaml_emitter_emit_document_end(emitter *yaml_emitter_t, event *yaml_event_t) bool {
if event.typ != yaml_DOCUMENT_END_EVENT {
return yaml_emitter_set_emitter_error(emitter, "expected DOCUMENT-END")
}
if !yaml_emitter_write_indent(emitter) {
return false
}
if !event.implicit {
// [Go] Allocate the slice elsewhere.
if !yaml_emitter_write_indicator(emitter, []byte("..."), true, false, false) {
return false
}
if !yaml_emitter_write_indent(emitter) {
return false
}
}
if !yaml_emitter_flush(emitter) {
return false
}
emitter.state = yaml_EMIT_DOCUMENT_START_STATE
emitter.tag_directives = emitter.tag_directives[:0]
return true
} | [
"func",
"yaml_emitter_emit_document_end",
"(",
"emitter",
"*",
"yaml_emitter_t",
",",
"event",
"*",
"yaml_event_t",
")",
"bool",
"{",
"if",
"event",
".",
"typ",
"!=",
"yaml_DOCUMENT_END_EVENT",
"{",
"return",
"yaml_emitter_set_emitter_error",
"(",
"emitter",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"yaml_emitter_write_indent",
"(",
"emitter",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"event",
".",
"implicit",
"{",
"// [Go] Allocate the slice elsewhere.",
"if",
"!",
"yaml_emitter_write_indicator",
"(",
"emitter",
",",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
",",
"true",
",",
"false",
",",
"false",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"yaml_emitter_write_indent",
"(",
"emitter",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"yaml_emitter_flush",
"(",
"emitter",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"emitter",
".",
"state",
"=",
"yaml_EMIT_DOCUMENT_START_STATE",
"\n",
"emitter",
".",
"tag_directives",
"=",
"emitter",
".",
"tag_directives",
"[",
":",
"0",
"]",
"\n",
"return",
"true",
"\n",
"}"
] | // Expect DOCUMENT-END. | [
"Expect",
"DOCUMENT",
"-",
"END",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L431-L453 | train |
kubernetes-retired/contrib | scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go | yaml_emitter_emit_flow_sequence_item | func yaml_emitter_emit_flow_sequence_item(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool {
if first {
if !yaml_emitter_write_indicator(emitter, []byte{'['}, true, true, false) {
return false
}
if !yaml_emitter_increase_indent(emitter, true, false) {
return false
}
emitter.flow_level++
}
if event.typ == yaml_SEQUENCE_END_EVENT {
emitter.flow_level--
emitter.indent = emitter.indents[len(emitter.indents)-1]
emitter.indents = emitter.indents[:len(emitter.indents)-1]
if emitter.canonical && !first {
if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) {
return false
}
if !yaml_emitter_write_indent(emitter) {
return false
}
}
if !yaml_emitter_write_indicator(emitter, []byte{']'}, false, false, false) {
return false
}
emitter.state = emitter.states[len(emitter.states)-1]
emitter.states = emitter.states[:len(emitter.states)-1]
return true
}
if !first {
if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) {
return false
}
}
if emitter.canonical || emitter.column > emitter.best_width {
if !yaml_emitter_write_indent(emitter) {
return false
}
}
emitter.states = append(emitter.states, yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE)
return yaml_emitter_emit_node(emitter, event, false, true, false, false)
} | go | func yaml_emitter_emit_flow_sequence_item(emitter *yaml_emitter_t, event *yaml_event_t, first bool) bool {
if first {
if !yaml_emitter_write_indicator(emitter, []byte{'['}, true, true, false) {
return false
}
if !yaml_emitter_increase_indent(emitter, true, false) {
return false
}
emitter.flow_level++
}
if event.typ == yaml_SEQUENCE_END_EVENT {
emitter.flow_level--
emitter.indent = emitter.indents[len(emitter.indents)-1]
emitter.indents = emitter.indents[:len(emitter.indents)-1]
if emitter.canonical && !first {
if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) {
return false
}
if !yaml_emitter_write_indent(emitter) {
return false
}
}
if !yaml_emitter_write_indicator(emitter, []byte{']'}, false, false, false) {
return false
}
emitter.state = emitter.states[len(emitter.states)-1]
emitter.states = emitter.states[:len(emitter.states)-1]
return true
}
if !first {
if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) {
return false
}
}
if emitter.canonical || emitter.column > emitter.best_width {
if !yaml_emitter_write_indent(emitter) {
return false
}
}
emitter.states = append(emitter.states, yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE)
return yaml_emitter_emit_node(emitter, event, false, true, false, false)
} | [
"func",
"yaml_emitter_emit_flow_sequence_item",
"(",
"emitter",
"*",
"yaml_emitter_t",
",",
"event",
"*",
"yaml_event_t",
",",
"first",
"bool",
")",
"bool",
"{",
"if",
"first",
"{",
"if",
"!",
"yaml_emitter_write_indicator",
"(",
"emitter",
",",
"[",
"]",
"byte",
"{",
"'['",
"}",
",",
"true",
",",
"true",
",",
"false",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"yaml_emitter_increase_indent",
"(",
"emitter",
",",
"true",
",",
"false",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"emitter",
".",
"flow_level",
"++",
"\n",
"}",
"\n\n",
"if",
"event",
".",
"typ",
"==",
"yaml_SEQUENCE_END_EVENT",
"{",
"emitter",
".",
"flow_level",
"--",
"\n",
"emitter",
".",
"indent",
"=",
"emitter",
".",
"indents",
"[",
"len",
"(",
"emitter",
".",
"indents",
")",
"-",
"1",
"]",
"\n",
"emitter",
".",
"indents",
"=",
"emitter",
".",
"indents",
"[",
":",
"len",
"(",
"emitter",
".",
"indents",
")",
"-",
"1",
"]",
"\n",
"if",
"emitter",
".",
"canonical",
"&&",
"!",
"first",
"{",
"if",
"!",
"yaml_emitter_write_indicator",
"(",
"emitter",
",",
"[",
"]",
"byte",
"{",
"','",
"}",
",",
"false",
",",
"false",
",",
"false",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"yaml_emitter_write_indent",
"(",
"emitter",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"yaml_emitter_write_indicator",
"(",
"emitter",
",",
"[",
"]",
"byte",
"{",
"']'",
"}",
",",
"false",
",",
"false",
",",
"false",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"emitter",
".",
"state",
"=",
"emitter",
".",
"states",
"[",
"len",
"(",
"emitter",
".",
"states",
")",
"-",
"1",
"]",
"\n",
"emitter",
".",
"states",
"=",
"emitter",
".",
"states",
"[",
":",
"len",
"(",
"emitter",
".",
"states",
")",
"-",
"1",
"]",
"\n\n",
"return",
"true",
"\n",
"}",
"\n\n",
"if",
"!",
"first",
"{",
"if",
"!",
"yaml_emitter_write_indicator",
"(",
"emitter",
",",
"[",
"]",
"byte",
"{",
"','",
"}",
",",
"false",
",",
"false",
",",
"false",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"emitter",
".",
"canonical",
"||",
"emitter",
".",
"column",
">",
"emitter",
".",
"best_width",
"{",
"if",
"!",
"yaml_emitter_write_indent",
"(",
"emitter",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"emitter",
".",
"states",
"=",
"append",
"(",
"emitter",
".",
"states",
",",
"yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE",
")",
"\n",
"return",
"yaml_emitter_emit_node",
"(",
"emitter",
",",
"event",
",",
"false",
",",
"true",
",",
"false",
",",
"false",
")",
"\n",
"}"
] | // Expect a flow item node. | [
"Expect",
"a",
"flow",
"item",
"node",
"."
] | 89f6948e24578fed2a90a87871b2263729f90ac3 | https://github.com/kubernetes-retired/contrib/blob/89f6948e24578fed2a90a87871b2263729f90ac3/scale-demo/Godeps/_workspace/src/gopkg.in/yaml.v2/emitterc.go#L456-L501 | train |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.