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 |
---|---|---|---|---|---|---|---|---|---|---|---|
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *RawArtifact) DeepCopy() *RawArtifact {
if in == nil {
return nil
}
out := new(RawArtifact)
in.DeepCopyInto(out)
return out
} | go | func (in *RawArtifact) DeepCopy() *RawArtifact {
if in == nil {
return nil
}
out := new(RawArtifact)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"RawArtifact",
")",
"DeepCopy",
"(",
")",
"*",
"RawArtifact",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"RawArtifact",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RawArtifact. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"RawArtifact",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L586-L593 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *ResourceTemplate) DeepCopy() *ResourceTemplate {
if in == nil {
return nil
}
out := new(ResourceTemplate)
in.DeepCopyInto(out)
return out
} | go | func (in *ResourceTemplate) DeepCopy() *ResourceTemplate {
if in == nil {
return nil
}
out := new(ResourceTemplate)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"ResourceTemplate",
")",
"DeepCopy",
"(",
")",
"*",
"ResourceTemplate",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"ResourceTemplate",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceTemplate. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"ResourceTemplate",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L602-L609 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *RetryStrategy) DeepCopy() *RetryStrategy {
if in == nil {
return nil
}
out := new(RetryStrategy)
in.DeepCopyInto(out)
return out
} | go | func (in *RetryStrategy) DeepCopy() *RetryStrategy {
if in == nil {
return nil
}
out := new(RetryStrategy)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"RetryStrategy",
")",
"DeepCopy",
"(",
")",
"*",
"RetryStrategy",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"RetryStrategy",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RetryStrategy. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"RetryStrategy",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L623-L630 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *S3Artifact) DeepCopy() *S3Artifact {
if in == nil {
return nil
}
out := new(S3Artifact)
in.DeepCopyInto(out)
return out
} | go | func (in *S3Artifact) DeepCopy() *S3Artifact {
if in == nil {
return nil
}
out := new(S3Artifact)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"S3Artifact",
")",
"DeepCopy",
"(",
")",
"*",
"S3Artifact",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"S3Artifact",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S3Artifact. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"S3Artifact",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L640-L647 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *S3Bucket) DeepCopy() *S3Bucket {
if in == nil {
return nil
}
out := new(S3Bucket)
in.DeepCopyInto(out)
return out
} | go | func (in *S3Bucket) DeepCopy() *S3Bucket {
if in == nil {
return nil
}
out := new(S3Bucket)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"S3Bucket",
")",
"DeepCopy",
"(",
")",
"*",
"S3Bucket",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"S3Bucket",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new S3Bucket. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"S3Bucket",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L663-L670 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *ScriptTemplate) DeepCopy() *ScriptTemplate {
if in == nil {
return nil
}
out := new(ScriptTemplate)
in.DeepCopyInto(out)
return out
} | go | func (in *ScriptTemplate) DeepCopy() *ScriptTemplate {
if in == nil {
return nil
}
out := new(ScriptTemplate)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"ScriptTemplate",
")",
"DeepCopy",
"(",
")",
"*",
"ScriptTemplate",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"ScriptTemplate",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScriptTemplate. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"ScriptTemplate",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L680-L687 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *Sequence) DeepCopy() *Sequence {
if in == nil {
return nil
}
out := new(Sequence)
in.DeepCopyInto(out)
return out
} | go | func (in *Sequence) DeepCopy() *Sequence {
if in == nil {
return nil
}
out := new(Sequence)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"Sequence",
")",
"DeepCopy",
"(",
")",
"*",
"Sequence",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"Sequence",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Sequence. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"Sequence",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L696-L703 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *SuspendTemplate) DeepCopy() *SuspendTemplate {
if in == nil {
return nil
}
out := new(SuspendTemplate)
in.DeepCopyInto(out)
return out
} | go | func (in *SuspendTemplate) DeepCopy() *SuspendTemplate {
if in == nil {
return nil
}
out := new(SuspendTemplate)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"SuspendTemplate",
")",
"DeepCopy",
"(",
")",
"*",
"SuspendTemplate",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"SuspendTemplate",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SuspendTemplate. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"SuspendTemplate",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L712-L719 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *TarStrategy) DeepCopy() *TarStrategy {
if in == nil {
return nil
}
out := new(TarStrategy)
in.DeepCopyInto(out)
return out
} | go | func (in *TarStrategy) DeepCopy() *TarStrategy {
if in == nil {
return nil
}
out := new(TarStrategy)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"TarStrategy",
")",
"DeepCopy",
"(",
")",
"*",
"TarStrategy",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"TarStrategy",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TarStrategy. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"TarStrategy",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L728-L735 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *UserContainer) DeepCopy() *UserContainer {
if in == nil {
return nil
}
out := new(UserContainer)
in.DeepCopyInto(out)
return out
} | go | func (in *UserContainer) DeepCopy() *UserContainer {
if in == nil {
return nil
}
out := new(UserContainer)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"UserContainer",
")",
"DeepCopy",
"(",
")",
"*",
"UserContainer",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"UserContainer",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UserContainer. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"UserContainer",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L877-L884 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *ValueFrom) DeepCopy() *ValueFrom {
if in == nil {
return nil
}
out := new(ValueFrom)
in.DeepCopyInto(out)
return out
} | go | func (in *ValueFrom) DeepCopy() *ValueFrom {
if in == nil {
return nil
}
out := new(ValueFrom)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"ValueFrom",
")",
"DeepCopy",
"(",
")",
"*",
"ValueFrom",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"ValueFrom",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ValueFrom. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"ValueFrom",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L893-L900 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *Workflow) DeepCopy() *Workflow {
if in == nil {
return nil
}
out := new(Workflow)
in.DeepCopyInto(out)
return out
} | go | func (in *Workflow) DeepCopy() *Workflow {
if in == nil {
return nil
}
out := new(Workflow)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"Workflow",
")",
"DeepCopy",
"(",
")",
"*",
"Workflow",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"Workflow",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Workflow. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"Workflow",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L913-L920 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *WorkflowList) DeepCopy() *WorkflowList {
if in == nil {
return nil
}
out := new(WorkflowList)
in.DeepCopyInto(out)
return out
} | go | func (in *WorkflowList) DeepCopy() *WorkflowList {
if in == nil {
return nil
}
out := new(WorkflowList)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"WorkflowList",
")",
"DeepCopy",
"(",
")",
"*",
"WorkflowList",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"WorkflowList",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkflowList. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"WorkflowList",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L946-L953 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *WorkflowSpec) DeepCopy() *WorkflowSpec {
if in == nil {
return nil
}
out := new(WorkflowSpec)
in.DeepCopyInto(out)
return out
} | go | func (in *WorkflowSpec) DeepCopy() *WorkflowSpec {
if in == nil {
return nil
}
out := new(WorkflowSpec)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"WorkflowSpec",
")",
"DeepCopy",
"(",
")",
"*",
"WorkflowSpec",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"WorkflowSpec",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkflowSpec. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"WorkflowSpec",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L1061-L1068 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *WorkflowStatus) DeepCopy() *WorkflowStatus {
if in == nil {
return nil
}
out := new(WorkflowStatus)
in.DeepCopyInto(out)
return out
} | go | func (in *WorkflowStatus) DeepCopy() *WorkflowStatus {
if in == nil {
return nil
}
out := new(WorkflowStatus)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"WorkflowStatus",
")",
"DeepCopy",
"(",
")",
"*",
"WorkflowStatus",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"WorkflowStatus",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkflowStatus. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"WorkflowStatus",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L1098-L1105 | train |
argoproj/argo | pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go | DeepCopy | func (in *WorkflowStep) DeepCopy() *WorkflowStep {
if in == nil {
return nil
}
out := new(WorkflowStep)
in.DeepCopyInto(out)
return out
} | go | func (in *WorkflowStep) DeepCopy() *WorkflowStep {
if in == nil {
return nil
}
out := new(WorkflowStep)
in.DeepCopyInto(out)
return out
} | [
"func",
"(",
"in",
"*",
"WorkflowStep",
")",
"DeepCopy",
"(",
")",
"*",
"WorkflowStep",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"WorkflowStep",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new WorkflowStep. | [
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"WorkflowStep",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/apis/workflow/v1alpha1/zz_generated.deepcopy.go#L1132-L1139 | train |
argoproj/argo | workflow/executor/resource.go | ExecResource | func (we *WorkflowExecutor) ExecResource(action string, manifestPath string, isDelete bool) (string, string, error) {
args := []string{
action,
}
output := "json"
if isDelete {
args = append(args, "--ignore-not-found")
output = "name"
}
if action == "patch" {
mergeStrategy := "strategic"
if we.Template.Resource.MergeStrategy != "" {
mergeStrategy = we.Template.Resource.MergeStrategy
}
args = append(args, "--type")
args = append(args, mergeStrategy)
args = append(args, "-p")
buff, err := ioutil.ReadFile(manifestPath)
if err != nil {
return "", "", errors.New(errors.CodeBadRequest, err.Error())
}
args = append(args, string(buff))
}
args = append(args, "-f")
args = append(args, manifestPath)
args = append(args, "-o")
args = append(args, output)
cmd := exec.Command("kubectl", args...)
log.Info(strings.Join(cmd.Args, " "))
out, err := cmd.Output()
if err != nil {
exErr := err.(*exec.ExitError)
errMsg := strings.TrimSpace(string(exErr.Stderr))
return "", "", errors.New(errors.CodeBadRequest, errMsg)
}
if action == "delete" {
return "", "", nil
}
obj := unstructured.Unstructured{}
err = json.Unmarshal(out, &obj)
if err != nil {
return "", "", err
}
resourceName := fmt.Sprintf("%s.%s/%s", obj.GroupVersionKind().Kind, obj.GroupVersionKind().Group, obj.GetName())
log.Infof("%s/%s", obj.GetNamespace(), resourceName)
return obj.GetNamespace(), resourceName, nil
} | go | func (we *WorkflowExecutor) ExecResource(action string, manifestPath string, isDelete bool) (string, string, error) {
args := []string{
action,
}
output := "json"
if isDelete {
args = append(args, "--ignore-not-found")
output = "name"
}
if action == "patch" {
mergeStrategy := "strategic"
if we.Template.Resource.MergeStrategy != "" {
mergeStrategy = we.Template.Resource.MergeStrategy
}
args = append(args, "--type")
args = append(args, mergeStrategy)
args = append(args, "-p")
buff, err := ioutil.ReadFile(manifestPath)
if err != nil {
return "", "", errors.New(errors.CodeBadRequest, err.Error())
}
args = append(args, string(buff))
}
args = append(args, "-f")
args = append(args, manifestPath)
args = append(args, "-o")
args = append(args, output)
cmd := exec.Command("kubectl", args...)
log.Info(strings.Join(cmd.Args, " "))
out, err := cmd.Output()
if err != nil {
exErr := err.(*exec.ExitError)
errMsg := strings.TrimSpace(string(exErr.Stderr))
return "", "", errors.New(errors.CodeBadRequest, errMsg)
}
if action == "delete" {
return "", "", nil
}
obj := unstructured.Unstructured{}
err = json.Unmarshal(out, &obj)
if err != nil {
return "", "", err
}
resourceName := fmt.Sprintf("%s.%s/%s", obj.GroupVersionKind().Kind, obj.GroupVersionKind().Group, obj.GetName())
log.Infof("%s/%s", obj.GetNamespace(), resourceName)
return obj.GetNamespace(), resourceName, nil
} | [
"func",
"(",
"we",
"*",
"WorkflowExecutor",
")",
"ExecResource",
"(",
"action",
"string",
",",
"manifestPath",
"string",
",",
"isDelete",
"bool",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"action",
",",
"}",
"\n",
"output",
":=",
"\"",
"\"",
"\n",
"if",
"isDelete",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
")",
"\n",
"output",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"action",
"==",
"\"",
"\"",
"{",
"mergeStrategy",
":=",
"\"",
"\"",
"\n",
"if",
"we",
".",
"Template",
".",
"Resource",
".",
"MergeStrategy",
"!=",
"\"",
"\"",
"{",
"mergeStrategy",
"=",
"we",
".",
"Template",
".",
"Resource",
".",
"MergeStrategy",
"\n",
"}",
"\n\n",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"mergeStrategy",
")",
"\n\n",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
")",
"\n",
"buff",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"manifestPath",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"errors",
".",
"CodeBadRequest",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"args",
"=",
"append",
"(",
"args",
",",
"string",
"(",
"buff",
")",
")",
"\n",
"}",
"\n\n",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"manifestPath",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
")",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"output",
")",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"args",
"...",
")",
"\n",
"log",
".",
"Info",
"(",
"strings",
".",
"Join",
"(",
"cmd",
".",
"Args",
",",
"\"",
"\"",
")",
")",
"\n",
"out",
",",
"err",
":=",
"cmd",
".",
"Output",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"exErr",
":=",
"err",
".",
"(",
"*",
"exec",
".",
"ExitError",
")",
"\n",
"errMsg",
":=",
"strings",
".",
"TrimSpace",
"(",
"string",
"(",
"exErr",
".",
"Stderr",
")",
")",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"errors",
".",
"New",
"(",
"errors",
".",
"CodeBadRequest",
",",
"errMsg",
")",
"\n",
"}",
"\n",
"if",
"action",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"obj",
":=",
"unstructured",
".",
"Unstructured",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"out",
",",
"&",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"resourceName",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"obj",
".",
"GroupVersionKind",
"(",
")",
".",
"Kind",
",",
"obj",
".",
"GroupVersionKind",
"(",
")",
".",
"Group",
",",
"obj",
".",
"GetName",
"(",
")",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"obj",
".",
"GetNamespace",
"(",
")",
",",
"resourceName",
")",
"\n",
"return",
"obj",
".",
"GetNamespace",
"(",
")",
",",
"resourceName",
",",
"nil",
"\n",
"}"
] | // ExecResource will run kubectl action against a manifest | [
"ExecResource",
"will",
"run",
"kubectl",
"action",
"against",
"a",
"manifest"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/resource.go#L23-L75 | train |
argoproj/argo | workflow/executor/resource.go | Has | func (g gjsonLabels) Has(label string) bool {
return gjson.GetBytes(g.json, label).Exists()
} | go | func (g gjsonLabels) Has(label string) bool {
return gjson.GetBytes(g.json, label).Exists()
} | [
"func",
"(",
"g",
"gjsonLabels",
")",
"Has",
"(",
"label",
"string",
")",
"bool",
"{",
"return",
"gjson",
".",
"GetBytes",
"(",
"g",
".",
"json",
",",
"label",
")",
".",
"Exists",
"(",
")",
"\n",
"}"
] | // Has returns whether the provided label exists. | [
"Has",
"returns",
"whether",
"the",
"provided",
"label",
"exists",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/resource.go#L85-L87 | train |
argoproj/argo | workflow/executor/resource.go | Get | func (g gjsonLabels) Get(label string) string {
return gjson.GetBytes(g.json, label).String()
} | go | func (g gjsonLabels) Get(label string) string {
return gjson.GetBytes(g.json, label).String()
} | [
"func",
"(",
"g",
"gjsonLabels",
")",
"Get",
"(",
"label",
"string",
")",
"string",
"{",
"return",
"gjson",
".",
"GetBytes",
"(",
"g",
".",
"json",
",",
"label",
")",
".",
"String",
"(",
")",
"\n",
"}"
] | // Get returns the value for the provided label. | [
"Get",
"returns",
"the",
"value",
"for",
"the",
"provided",
"label",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/resource.go#L90-L92 | train |
argoproj/argo | workflow/executor/resource.go | WaitResource | func (we *WorkflowExecutor) WaitResource(resourceNamespace string, resourceName string) error {
if we.Template.Resource.SuccessCondition == "" && we.Template.Resource.FailureCondition == "" {
return nil
}
var successReqs labels.Requirements
if we.Template.Resource.SuccessCondition != "" {
successSelector, err := labels.Parse(we.Template.Resource.SuccessCondition)
if err != nil {
return errors.Errorf(errors.CodeBadRequest, "success condition '%s' failed to parse: %v", we.Template.Resource.SuccessCondition, err)
}
log.Infof("Waiting for conditions: %s", successSelector)
successReqs, _ = successSelector.Requirements()
}
var failReqs labels.Requirements
if we.Template.Resource.FailureCondition != "" {
failSelector, err := labels.Parse(we.Template.Resource.FailureCondition)
if err != nil {
return errors.Errorf(errors.CodeBadRequest, "fail condition '%s' failed to parse: %v", we.Template.Resource.FailureCondition, err)
}
log.Infof("Failing for conditions: %s", failSelector)
failReqs, _ = failSelector.Requirements()
}
// Start the condition result reader using PollImmediateInfinite
// Poll intervall of 5 seconds serves as a backoff intervall in case of immediate result reader failure
err := wait.PollImmediateInfinite(time.Second*5,
func() (bool, error) {
isErrRetry, err := checkResourceState(resourceNamespace, resourceName, successReqs, failReqs)
if err == nil {
log.Infof("Returning from successful wait for resource %s", resourceName)
return true, nil
}
if isErrRetry {
log.Infof("Waiting for resource %s resulted in retryable error %v", resourceName, err)
return false, nil
}
log.Warnf("Waiting for resource %s resulted in non-retryable error %v", resourceName, err)
return false, err
})
if err != nil {
if err == wait.ErrWaitTimeout {
log.Warnf("Waiting for resource %s resulted in timeout due to repeated errors", resourceName)
} else {
log.Warnf("Waiting for resource %s resulted in error %v", resourceName, err)
}
}
return err
} | go | func (we *WorkflowExecutor) WaitResource(resourceNamespace string, resourceName string) error {
if we.Template.Resource.SuccessCondition == "" && we.Template.Resource.FailureCondition == "" {
return nil
}
var successReqs labels.Requirements
if we.Template.Resource.SuccessCondition != "" {
successSelector, err := labels.Parse(we.Template.Resource.SuccessCondition)
if err != nil {
return errors.Errorf(errors.CodeBadRequest, "success condition '%s' failed to parse: %v", we.Template.Resource.SuccessCondition, err)
}
log.Infof("Waiting for conditions: %s", successSelector)
successReqs, _ = successSelector.Requirements()
}
var failReqs labels.Requirements
if we.Template.Resource.FailureCondition != "" {
failSelector, err := labels.Parse(we.Template.Resource.FailureCondition)
if err != nil {
return errors.Errorf(errors.CodeBadRequest, "fail condition '%s' failed to parse: %v", we.Template.Resource.FailureCondition, err)
}
log.Infof("Failing for conditions: %s", failSelector)
failReqs, _ = failSelector.Requirements()
}
// Start the condition result reader using PollImmediateInfinite
// Poll intervall of 5 seconds serves as a backoff intervall in case of immediate result reader failure
err := wait.PollImmediateInfinite(time.Second*5,
func() (bool, error) {
isErrRetry, err := checkResourceState(resourceNamespace, resourceName, successReqs, failReqs)
if err == nil {
log.Infof("Returning from successful wait for resource %s", resourceName)
return true, nil
}
if isErrRetry {
log.Infof("Waiting for resource %s resulted in retryable error %v", resourceName, err)
return false, nil
}
log.Warnf("Waiting for resource %s resulted in non-retryable error %v", resourceName, err)
return false, err
})
if err != nil {
if err == wait.ErrWaitTimeout {
log.Warnf("Waiting for resource %s resulted in timeout due to repeated errors", resourceName)
} else {
log.Warnf("Waiting for resource %s resulted in error %v", resourceName, err)
}
}
return err
} | [
"func",
"(",
"we",
"*",
"WorkflowExecutor",
")",
"WaitResource",
"(",
"resourceNamespace",
"string",
",",
"resourceName",
"string",
")",
"error",
"{",
"if",
"we",
".",
"Template",
".",
"Resource",
".",
"SuccessCondition",
"==",
"\"",
"\"",
"&&",
"we",
".",
"Template",
".",
"Resource",
".",
"FailureCondition",
"==",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"successReqs",
"labels",
".",
"Requirements",
"\n",
"if",
"we",
".",
"Template",
".",
"Resource",
".",
"SuccessCondition",
"!=",
"\"",
"\"",
"{",
"successSelector",
",",
"err",
":=",
"labels",
".",
"Parse",
"(",
"we",
".",
"Template",
".",
"Resource",
".",
"SuccessCondition",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"errors",
".",
"CodeBadRequest",
",",
"\"",
"\"",
",",
"we",
".",
"Template",
".",
"Resource",
".",
"SuccessCondition",
",",
"err",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"successSelector",
")",
"\n",
"successReqs",
",",
"_",
"=",
"successSelector",
".",
"Requirements",
"(",
")",
"\n",
"}",
"\n\n",
"var",
"failReqs",
"labels",
".",
"Requirements",
"\n",
"if",
"we",
".",
"Template",
".",
"Resource",
".",
"FailureCondition",
"!=",
"\"",
"\"",
"{",
"failSelector",
",",
"err",
":=",
"labels",
".",
"Parse",
"(",
"we",
".",
"Template",
".",
"Resource",
".",
"FailureCondition",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"errors",
".",
"CodeBadRequest",
",",
"\"",
"\"",
",",
"we",
".",
"Template",
".",
"Resource",
".",
"FailureCondition",
",",
"err",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"failSelector",
")",
"\n",
"failReqs",
",",
"_",
"=",
"failSelector",
".",
"Requirements",
"(",
")",
"\n",
"}",
"\n\n",
"// Start the condition result reader using PollImmediateInfinite",
"// Poll intervall of 5 seconds serves as a backoff intervall in case of immediate result reader failure",
"err",
":=",
"wait",
".",
"PollImmediateInfinite",
"(",
"time",
".",
"Second",
"*",
"5",
",",
"func",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"isErrRetry",
",",
"err",
":=",
"checkResourceState",
"(",
"resourceNamespace",
",",
"resourceName",
",",
"successReqs",
",",
"failReqs",
")",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"resourceName",
")",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"isErrRetry",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"resourceName",
",",
"err",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"resourceName",
",",
"err",
")",
"\n",
"return",
"false",
",",
"err",
"\n",
"}",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"wait",
".",
"ErrWaitTimeout",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"resourceName",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"resourceName",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // WaitResource waits for a specific resource to satisfy either the success or failure condition | [
"WaitResource",
"waits",
"for",
"a",
"specific",
"resource",
"to",
"satisfy",
"either",
"the",
"success",
"or",
"failure",
"condition"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/resource.go#L95-L148 | train |
argoproj/argo | workflow/executor/resource.go | checkResourceState | func checkResourceState(resourceNamespace string, resourceName string, successReqs labels.Requirements, failReqs labels.Requirements) (bool, error) {
cmd, reader, err := startKubectlWaitCmd(resourceNamespace, resourceName)
if err != nil {
return false, err
}
defer func() {
_ = cmd.Process.Kill()
}()
for {
jsonBytes, err := readJSON(reader)
if err != nil {
resultErr := err
log.Warnf("Json reader returned error %v. Calling kill (usually superfluous)", err)
// We don't want to write OS specific code so we don't want to call syscall package code. But that means
// there is no way to figure out if a process is running or not in an asynchronous manner. exec.Wait will
// always block and we need to call that to get the exit code of the process. So we will unconditionally
// call exec.Process.Kill and then assume that wait will not block after that. Two things may happen:
// 1. Process already exited and kill does nothing (returns error which we ignore) and then we call
// Wait and get the proper return value
// 2. Process is running gets, killed with exec.Process.Kill call and Wait returns an error code and we give up
// and don't retry
_ = cmd.Process.Kill()
log.Warnf("Command for kubectl get -w for %s exited. Getting return value using Wait", resourceName)
err = cmd.Wait()
if err != nil {
log.Warnf("cmd.Wait for kubectl get -w command for resource %s returned error %v",
resourceName, err)
resultErr = err
} else {
log.Infof("readJSon failed for resource %s but cmd.Wait for kubectl get -w command did not error", resourceName)
}
return true, resultErr
}
log.Info(string(jsonBytes))
ls := gjsonLabels{json: jsonBytes}
for _, req := range failReqs {
failed := req.Matches(ls)
msg := fmt.Sprintf("failure condition '%s' evaluated %v", req, failed)
log.Infof(msg)
if failed {
// TODO: need a better error code instead of BadRequest
return false, errors.Errorf(errors.CodeBadRequest, msg)
}
}
numMatched := 0
for _, req := range successReqs {
matched := req.Matches(ls)
log.Infof("success condition '%s' evaluated %v", req, matched)
if matched {
numMatched++
}
}
log.Infof("%d/%d success conditions matched", numMatched, len(successReqs))
if numMatched >= len(successReqs) {
return false, nil
}
}
} | go | func checkResourceState(resourceNamespace string, resourceName string, successReqs labels.Requirements, failReqs labels.Requirements) (bool, error) {
cmd, reader, err := startKubectlWaitCmd(resourceNamespace, resourceName)
if err != nil {
return false, err
}
defer func() {
_ = cmd.Process.Kill()
}()
for {
jsonBytes, err := readJSON(reader)
if err != nil {
resultErr := err
log.Warnf("Json reader returned error %v. Calling kill (usually superfluous)", err)
// We don't want to write OS specific code so we don't want to call syscall package code. But that means
// there is no way to figure out if a process is running or not in an asynchronous manner. exec.Wait will
// always block and we need to call that to get the exit code of the process. So we will unconditionally
// call exec.Process.Kill and then assume that wait will not block after that. Two things may happen:
// 1. Process already exited and kill does nothing (returns error which we ignore) and then we call
// Wait and get the proper return value
// 2. Process is running gets, killed with exec.Process.Kill call and Wait returns an error code and we give up
// and don't retry
_ = cmd.Process.Kill()
log.Warnf("Command for kubectl get -w for %s exited. Getting return value using Wait", resourceName)
err = cmd.Wait()
if err != nil {
log.Warnf("cmd.Wait for kubectl get -w command for resource %s returned error %v",
resourceName, err)
resultErr = err
} else {
log.Infof("readJSon failed for resource %s but cmd.Wait for kubectl get -w command did not error", resourceName)
}
return true, resultErr
}
log.Info(string(jsonBytes))
ls := gjsonLabels{json: jsonBytes}
for _, req := range failReqs {
failed := req.Matches(ls)
msg := fmt.Sprintf("failure condition '%s' evaluated %v", req, failed)
log.Infof(msg)
if failed {
// TODO: need a better error code instead of BadRequest
return false, errors.Errorf(errors.CodeBadRequest, msg)
}
}
numMatched := 0
for _, req := range successReqs {
matched := req.Matches(ls)
log.Infof("success condition '%s' evaluated %v", req, matched)
if matched {
numMatched++
}
}
log.Infof("%d/%d success conditions matched", numMatched, len(successReqs))
if numMatched >= len(successReqs) {
return false, nil
}
}
} | [
"func",
"checkResourceState",
"(",
"resourceNamespace",
"string",
",",
"resourceName",
"string",
",",
"successReqs",
"labels",
".",
"Requirements",
",",
"failReqs",
"labels",
".",
"Requirements",
")",
"(",
"bool",
",",
"error",
")",
"{",
"cmd",
",",
"reader",
",",
"err",
":=",
"startKubectlWaitCmd",
"(",
"resourceNamespace",
",",
"resourceName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"_",
"=",
"cmd",
".",
"Process",
".",
"Kill",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"for",
"{",
"jsonBytes",
",",
"err",
":=",
"readJSON",
"(",
"reader",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"resultErr",
":=",
"err",
"\n",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"// We don't want to write OS specific code so we don't want to call syscall package code. But that means",
"// there is no way to figure out if a process is running or not in an asynchronous manner. exec.Wait will",
"// always block and we need to call that to get the exit code of the process. So we will unconditionally",
"// call exec.Process.Kill and then assume that wait will not block after that. Two things may happen:",
"// 1. Process already exited and kill does nothing (returns error which we ignore) and then we call",
"// Wait and get the proper return value",
"// 2. Process is running gets, killed with exec.Process.Kill call and Wait returns an error code and we give up",
"// and don't retry",
"_",
"=",
"cmd",
".",
"Process",
".",
"Kill",
"(",
")",
"\n\n",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"resourceName",
")",
"\n",
"err",
"=",
"cmd",
".",
"Wait",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"resourceName",
",",
"err",
")",
"\n",
"resultErr",
"=",
"err",
"\n",
"}",
"else",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"resourceName",
")",
"\n",
"}",
"\n",
"return",
"true",
",",
"resultErr",
"\n",
"}",
"\n\n",
"log",
".",
"Info",
"(",
"string",
"(",
"jsonBytes",
")",
")",
"\n",
"ls",
":=",
"gjsonLabels",
"{",
"json",
":",
"jsonBytes",
"}",
"\n",
"for",
"_",
",",
"req",
":=",
"range",
"failReqs",
"{",
"failed",
":=",
"req",
".",
"Matches",
"(",
"ls",
")",
"\n",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"req",
",",
"failed",
")",
"\n",
"log",
".",
"Infof",
"(",
"msg",
")",
"\n",
"if",
"failed",
"{",
"// TODO: need a better error code instead of BadRequest",
"return",
"false",
",",
"errors",
".",
"Errorf",
"(",
"errors",
".",
"CodeBadRequest",
",",
"msg",
")",
"\n",
"}",
"\n",
"}",
"\n",
"numMatched",
":=",
"0",
"\n",
"for",
"_",
",",
"req",
":=",
"range",
"successReqs",
"{",
"matched",
":=",
"req",
".",
"Matches",
"(",
"ls",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"req",
",",
"matched",
")",
"\n",
"if",
"matched",
"{",
"numMatched",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"numMatched",
",",
"len",
"(",
"successReqs",
")",
")",
"\n",
"if",
"numMatched",
">=",
"len",
"(",
"successReqs",
")",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // Function to do the kubectl get -w command and then waiting on json reading. | [
"Function",
"to",
"do",
"the",
"kubectl",
"get",
"-",
"w",
"command",
"and",
"then",
"waiting",
"on",
"json",
"reading",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/resource.go#L151-L213 | train |
argoproj/argo | workflow/executor/resource.go | startKubectlWaitCmd | func startKubectlWaitCmd(resourceNamespace string, resourceName string) (*exec.Cmd, *bufio.Reader, error) {
args := []string{"get", resourceName, "-w", "-o", "json"}
if resourceNamespace != "" {
args = append(args, "-n", resourceNamespace)
}
cmd := exec.Command("kubectl", args...)
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, nil, errors.InternalWrapError(err)
}
reader := bufio.NewReader(stdout)
log.Info(strings.Join(cmd.Args, " "))
if err := cmd.Start(); err != nil {
return nil, nil, errors.InternalWrapError(err)
}
return cmd, reader, nil
} | go | func startKubectlWaitCmd(resourceNamespace string, resourceName string) (*exec.Cmd, *bufio.Reader, error) {
args := []string{"get", resourceName, "-w", "-o", "json"}
if resourceNamespace != "" {
args = append(args, "-n", resourceNamespace)
}
cmd := exec.Command("kubectl", args...)
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, nil, errors.InternalWrapError(err)
}
reader := bufio.NewReader(stdout)
log.Info(strings.Join(cmd.Args, " "))
if err := cmd.Start(); err != nil {
return nil, nil, errors.InternalWrapError(err)
}
return cmd, reader, nil
} | [
"func",
"startKubectlWaitCmd",
"(",
"resourceNamespace",
"string",
",",
"resourceName",
"string",
")",
"(",
"*",
"exec",
".",
"Cmd",
",",
"*",
"bufio",
".",
"Reader",
",",
"error",
")",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"resourceName",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"if",
"resourceNamespace",
"!=",
"\"",
"\"",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
",",
"resourceNamespace",
")",
"\n",
"}",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"args",
"...",
")",
"\n",
"stdout",
",",
"err",
":=",
"cmd",
".",
"StdoutPipe",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"InternalWrapError",
"(",
"err",
")",
"\n",
"}",
"\n",
"reader",
":=",
"bufio",
".",
"NewReader",
"(",
"stdout",
")",
"\n",
"log",
".",
"Info",
"(",
"strings",
".",
"Join",
"(",
"cmd",
".",
"Args",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
":=",
"cmd",
".",
"Start",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"InternalWrapError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"cmd",
",",
"reader",
",",
"nil",
"\n",
"}"
] | // Start Kubectl command Get with -w return error if unable to start command | [
"Start",
"Kubectl",
"command",
"Get",
"with",
"-",
"w",
"return",
"error",
"if",
"unable",
"to",
"start",
"command"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/resource.go#L216-L233 | train |
argoproj/argo | workflow/executor/resource.go | readJSON | func readJSON(reader *bufio.Reader) ([]byte, error) {
var buffer bytes.Buffer
for {
line, err := reader.ReadBytes('\n')
if err != nil {
return nil, err
}
isDelimiter := len(line) == 2 && line[0] == byte('}')
line = bytes.TrimSpace(line)
_, err = buffer.Write(line)
if err != nil {
return nil, err
}
if isDelimiter {
break
}
}
return buffer.Bytes(), nil
} | go | func readJSON(reader *bufio.Reader) ([]byte, error) {
var buffer bytes.Buffer
for {
line, err := reader.ReadBytes('\n')
if err != nil {
return nil, err
}
isDelimiter := len(line) == 2 && line[0] == byte('}')
line = bytes.TrimSpace(line)
_, err = buffer.Write(line)
if err != nil {
return nil, err
}
if isDelimiter {
break
}
}
return buffer.Bytes(), nil
} | [
"func",
"readJSON",
"(",
"reader",
"*",
"bufio",
".",
"Reader",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n",
"for",
"{",
"line",
",",
"err",
":=",
"reader",
".",
"ReadBytes",
"(",
"'\\n'",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"isDelimiter",
":=",
"len",
"(",
"line",
")",
"==",
"2",
"&&",
"line",
"[",
"0",
"]",
"==",
"byte",
"(",
"'}'",
")",
"\n",
"line",
"=",
"bytes",
".",
"TrimSpace",
"(",
"line",
")",
"\n",
"_",
",",
"err",
"=",
"buffer",
".",
"Write",
"(",
"line",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"isDelimiter",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"buffer",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] | // readJSON reads from a reader line-by-line until it reaches "}\n" indicating end of json | [
"readJSON",
"reads",
"from",
"a",
"reader",
"line",
"-",
"by",
"-",
"line",
"until",
"it",
"reaches",
"}",
"\\",
"n",
"indicating",
"end",
"of",
"json"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/resource.go#L236-L254 | train |
argoproj/argo | workflow/executor/resource.go | SaveResourceParameters | func (we *WorkflowExecutor) SaveResourceParameters(resourceNamespace string, resourceName string) error {
if len(we.Template.Outputs.Parameters) == 0 {
log.Infof("No output parameters")
return nil
}
log.Infof("Saving resource output parameters")
for i, param := range we.Template.Outputs.Parameters {
if param.ValueFrom == nil {
continue
}
var cmd *exec.Cmd
if param.ValueFrom.JSONPath != "" {
args := []string{"get", resourceName, "-o", fmt.Sprintf("jsonpath=%s", param.ValueFrom.JSONPath)}
if resourceNamespace != "" {
args = append(args, "-n", resourceNamespace)
}
cmd = exec.Command("kubectl", args...)
} else if param.ValueFrom.JQFilter != "" {
resArgs := []string{resourceName}
if resourceNamespace != "" {
resArgs = append(resArgs, "-n", resourceNamespace)
}
cmdStr := fmt.Sprintf("kubectl get %s -o json | jq -c '%s'", strings.Join(resArgs, " "), param.ValueFrom.JQFilter)
cmd = exec.Command("sh", "-c", cmdStr)
} else {
continue
}
log.Info(cmd.Args)
out, err := cmd.Output()
if err != nil {
if exErr, ok := err.(*exec.ExitError); ok {
log.Errorf("`%s` stderr:\n%s", cmd.Args, string(exErr.Stderr))
}
return errors.InternalWrapError(err)
}
output := string(out)
we.Template.Outputs.Parameters[i].Value = &output
log.Infof("Saved output parameter: %s, value: %s", param.Name, output)
}
err := we.AnnotateOutputs(nil)
if err != nil {
return err
}
return nil
} | go | func (we *WorkflowExecutor) SaveResourceParameters(resourceNamespace string, resourceName string) error {
if len(we.Template.Outputs.Parameters) == 0 {
log.Infof("No output parameters")
return nil
}
log.Infof("Saving resource output parameters")
for i, param := range we.Template.Outputs.Parameters {
if param.ValueFrom == nil {
continue
}
var cmd *exec.Cmd
if param.ValueFrom.JSONPath != "" {
args := []string{"get", resourceName, "-o", fmt.Sprintf("jsonpath=%s", param.ValueFrom.JSONPath)}
if resourceNamespace != "" {
args = append(args, "-n", resourceNamespace)
}
cmd = exec.Command("kubectl", args...)
} else if param.ValueFrom.JQFilter != "" {
resArgs := []string{resourceName}
if resourceNamespace != "" {
resArgs = append(resArgs, "-n", resourceNamespace)
}
cmdStr := fmt.Sprintf("kubectl get %s -o json | jq -c '%s'", strings.Join(resArgs, " "), param.ValueFrom.JQFilter)
cmd = exec.Command("sh", "-c", cmdStr)
} else {
continue
}
log.Info(cmd.Args)
out, err := cmd.Output()
if err != nil {
if exErr, ok := err.(*exec.ExitError); ok {
log.Errorf("`%s` stderr:\n%s", cmd.Args, string(exErr.Stderr))
}
return errors.InternalWrapError(err)
}
output := string(out)
we.Template.Outputs.Parameters[i].Value = &output
log.Infof("Saved output parameter: %s, value: %s", param.Name, output)
}
err := we.AnnotateOutputs(nil)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"we",
"*",
"WorkflowExecutor",
")",
"SaveResourceParameters",
"(",
"resourceNamespace",
"string",
",",
"resourceName",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"we",
".",
"Template",
".",
"Outputs",
".",
"Parameters",
")",
"==",
"0",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"for",
"i",
",",
"param",
":=",
"range",
"we",
".",
"Template",
".",
"Outputs",
".",
"Parameters",
"{",
"if",
"param",
".",
"ValueFrom",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"var",
"cmd",
"*",
"exec",
".",
"Cmd",
"\n",
"if",
"param",
".",
"ValueFrom",
".",
"JSONPath",
"!=",
"\"",
"\"",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"resourceName",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"param",
".",
"ValueFrom",
".",
"JSONPath",
")",
"}",
"\n",
"if",
"resourceNamespace",
"!=",
"\"",
"\"",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
",",
"resourceNamespace",
")",
"\n",
"}",
"\n",
"cmd",
"=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"args",
"...",
")",
"\n",
"}",
"else",
"if",
"param",
".",
"ValueFrom",
".",
"JQFilter",
"!=",
"\"",
"\"",
"{",
"resArgs",
":=",
"[",
"]",
"string",
"{",
"resourceName",
"}",
"\n",
"if",
"resourceNamespace",
"!=",
"\"",
"\"",
"{",
"resArgs",
"=",
"append",
"(",
"resArgs",
",",
"\"",
"\"",
",",
"resourceNamespace",
")",
"\n",
"}",
"\n",
"cmdStr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"resArgs",
",",
"\"",
"\"",
")",
",",
"param",
".",
"ValueFrom",
".",
"JQFilter",
")",
"\n",
"cmd",
"=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"cmdStr",
")",
"\n",
"}",
"else",
"{",
"continue",
"\n",
"}",
"\n",
"log",
".",
"Info",
"(",
"cmd",
".",
"Args",
")",
"\n",
"out",
",",
"err",
":=",
"cmd",
".",
"Output",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"exErr",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"exec",
".",
"ExitError",
")",
";",
"ok",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\\n",
"\"",
",",
"cmd",
".",
"Args",
",",
"string",
"(",
"exErr",
".",
"Stderr",
")",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"InternalWrapError",
"(",
"err",
")",
"\n",
"}",
"\n",
"output",
":=",
"string",
"(",
"out",
")",
"\n",
"we",
".",
"Template",
".",
"Outputs",
".",
"Parameters",
"[",
"i",
"]",
".",
"Value",
"=",
"&",
"output",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"param",
".",
"Name",
",",
"output",
")",
"\n",
"}",
"\n",
"err",
":=",
"we",
".",
"AnnotateOutputs",
"(",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SaveResourceParameters will save any resource output parameters | [
"SaveResourceParameters",
"will",
"save",
"any",
"resource",
"output",
"parameters"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/resource.go#L257-L301 | train |
argoproj/argo | util/retry/retry.go | IsRetryableKubeAPIError | func IsRetryableKubeAPIError(err error) bool {
// get original error if it was wrapped
err = argoerrs.Cause(err)
if apierr.IsNotFound(err) || apierr.IsForbidden(err) || apierr.IsInvalid(err) || apierr.IsMethodNotSupported(err) {
return false
}
return true
} | go | func IsRetryableKubeAPIError(err error) bool {
// get original error if it was wrapped
err = argoerrs.Cause(err)
if apierr.IsNotFound(err) || apierr.IsForbidden(err) || apierr.IsInvalid(err) || apierr.IsMethodNotSupported(err) {
return false
}
return true
} | [
"func",
"IsRetryableKubeAPIError",
"(",
"err",
"error",
")",
"bool",
"{",
"// get original error if it was wrapped",
"err",
"=",
"argoerrs",
".",
"Cause",
"(",
"err",
")",
"\n",
"if",
"apierr",
".",
"IsNotFound",
"(",
"err",
")",
"||",
"apierr",
".",
"IsForbidden",
"(",
"err",
")",
"||",
"apierr",
".",
"IsInvalid",
"(",
"err",
")",
"||",
"apierr",
".",
"IsMethodNotSupported",
"(",
"err",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // IsRetryableKubeAPIError returns if the error is a retryable kubernetes error | [
"IsRetryableKubeAPIError",
"returns",
"if",
"the",
"error",
"is",
"a",
"retryable",
"kubernetes",
"error"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/util/retry/retry.go#L23-L30 | train |
argoproj/argo | util/retry/retry.go | IsRetryableNetworkError | func IsRetryableNetworkError(err error) bool {
if err == nil {
return false
}
// get original error if it was wrapped
err = argoerrs.Cause(err)
errStr := err.Error()
switch err.(type) {
case net.Error:
switch err.(type) {
case *net.DNSError, *net.OpError, net.UnknownNetworkError:
return true
case *url.Error:
// For a URL error, where it replies back "connection closed"
// retry again.
if strings.Contains(errStr, "Connection closed by foreign host") {
return true
}
default:
if strings.Contains(errStr, "net/http: TLS handshake timeout") {
// If error is - tlsHandshakeTimeoutError, retry.
return true
} else if strings.Contains(errStr, "i/o timeout") {
// If error is - tcp timeoutError, retry.
return true
} else if strings.Contains(errStr, "connection timed out") {
// If err is a net.Dial timeout, retry.
return true
}
}
}
return false
} | go | func IsRetryableNetworkError(err error) bool {
if err == nil {
return false
}
// get original error if it was wrapped
err = argoerrs.Cause(err)
errStr := err.Error()
switch err.(type) {
case net.Error:
switch err.(type) {
case *net.DNSError, *net.OpError, net.UnknownNetworkError:
return true
case *url.Error:
// For a URL error, where it replies back "connection closed"
// retry again.
if strings.Contains(errStr, "Connection closed by foreign host") {
return true
}
default:
if strings.Contains(errStr, "net/http: TLS handshake timeout") {
// If error is - tlsHandshakeTimeoutError, retry.
return true
} else if strings.Contains(errStr, "i/o timeout") {
// If error is - tcp timeoutError, retry.
return true
} else if strings.Contains(errStr, "connection timed out") {
// If err is a net.Dial timeout, retry.
return true
}
}
}
return false
} | [
"func",
"IsRetryableNetworkError",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"// get original error if it was wrapped",
"err",
"=",
"argoerrs",
".",
"Cause",
"(",
"err",
")",
"\n",
"errStr",
":=",
"err",
".",
"Error",
"(",
")",
"\n\n",
"switch",
"err",
".",
"(",
"type",
")",
"{",
"case",
"net",
".",
"Error",
":",
"switch",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"net",
".",
"DNSError",
",",
"*",
"net",
".",
"OpError",
",",
"net",
".",
"UnknownNetworkError",
":",
"return",
"true",
"\n",
"case",
"*",
"url",
".",
"Error",
":",
"// For a URL error, where it replies back \"connection closed\"",
"// retry again.",
"if",
"strings",
".",
"Contains",
"(",
"errStr",
",",
"\"",
"\"",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"default",
":",
"if",
"strings",
".",
"Contains",
"(",
"errStr",
",",
"\"",
"\"",
")",
"{",
"// If error is - tlsHandshakeTimeoutError, retry.",
"return",
"true",
"\n",
"}",
"else",
"if",
"strings",
".",
"Contains",
"(",
"errStr",
",",
"\"",
"\"",
")",
"{",
"// If error is - tcp timeoutError, retry.",
"return",
"true",
"\n",
"}",
"else",
"if",
"strings",
".",
"Contains",
"(",
"errStr",
",",
"\"",
"\"",
")",
"{",
"// If err is a net.Dial timeout, retry.",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsRetryableNetworkError returns whether or not the error is a retryable network error | [
"IsRetryableNetworkError",
"returns",
"whether",
"or",
"not",
"the",
"error",
"is",
"a",
"retryable",
"network",
"error"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/util/retry/retry.go#L33-L66 | train |
argoproj/argo | workflow/controller/steps.go | updateOutboundNodes | func (woc *wfOperationCtx) updateOutboundNodes(nodeName string, tmpl *wfv1.Template) {
outbound := make([]string, 0)
// Find the last, initialized stepgroup node
var lastSGNode *wfv1.NodeStatus
for i := len(tmpl.Steps) - 1; i >= 0; i-- {
sgNode := woc.getNodeByName(fmt.Sprintf("%s[%d]", nodeName, i))
if sgNode != nil {
lastSGNode = sgNode
break
}
}
if lastSGNode == nil {
woc.log.Warnf("node '%s' had no initialized StepGroup nodes", nodeName)
return
}
for _, childID := range lastSGNode.Children {
outboundNodeIDs := woc.getOutboundNodes(childID)
woc.log.Infof("Outbound nodes of %s is %s", childID, outboundNodeIDs)
for _, outNodeID := range outboundNodeIDs {
outbound = append(outbound, outNodeID)
}
}
node := woc.getNodeByName(nodeName)
woc.log.Infof("Outbound nodes of %s is %s", node.ID, outbound)
node.OutboundNodes = outbound
woc.wf.Status.Nodes[node.ID] = *node
} | go | func (woc *wfOperationCtx) updateOutboundNodes(nodeName string, tmpl *wfv1.Template) {
outbound := make([]string, 0)
// Find the last, initialized stepgroup node
var lastSGNode *wfv1.NodeStatus
for i := len(tmpl.Steps) - 1; i >= 0; i-- {
sgNode := woc.getNodeByName(fmt.Sprintf("%s[%d]", nodeName, i))
if sgNode != nil {
lastSGNode = sgNode
break
}
}
if lastSGNode == nil {
woc.log.Warnf("node '%s' had no initialized StepGroup nodes", nodeName)
return
}
for _, childID := range lastSGNode.Children {
outboundNodeIDs := woc.getOutboundNodes(childID)
woc.log.Infof("Outbound nodes of %s is %s", childID, outboundNodeIDs)
for _, outNodeID := range outboundNodeIDs {
outbound = append(outbound, outNodeID)
}
}
node := woc.getNodeByName(nodeName)
woc.log.Infof("Outbound nodes of %s is %s", node.ID, outbound)
node.OutboundNodes = outbound
woc.wf.Status.Nodes[node.ID] = *node
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"updateOutboundNodes",
"(",
"nodeName",
"string",
",",
"tmpl",
"*",
"wfv1",
".",
"Template",
")",
"{",
"outbound",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"// Find the last, initialized stepgroup node",
"var",
"lastSGNode",
"*",
"wfv1",
".",
"NodeStatus",
"\n",
"for",
"i",
":=",
"len",
"(",
"tmpl",
".",
"Steps",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"sgNode",
":=",
"woc",
".",
"getNodeByName",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"nodeName",
",",
"i",
")",
")",
"\n",
"if",
"sgNode",
"!=",
"nil",
"{",
"lastSGNode",
"=",
"sgNode",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"lastSGNode",
"==",
"nil",
"{",
"woc",
".",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"nodeName",
")",
"\n",
"return",
"\n",
"}",
"\n",
"for",
"_",
",",
"childID",
":=",
"range",
"lastSGNode",
".",
"Children",
"{",
"outboundNodeIDs",
":=",
"woc",
".",
"getOutboundNodes",
"(",
"childID",
")",
"\n",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"childID",
",",
"outboundNodeIDs",
")",
"\n",
"for",
"_",
",",
"outNodeID",
":=",
"range",
"outboundNodeIDs",
"{",
"outbound",
"=",
"append",
"(",
"outbound",
",",
"outNodeID",
")",
"\n",
"}",
"\n",
"}",
"\n",
"node",
":=",
"woc",
".",
"getNodeByName",
"(",
"nodeName",
")",
"\n",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"node",
".",
"ID",
",",
"outbound",
")",
"\n",
"node",
".",
"OutboundNodes",
"=",
"outbound",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"[",
"node",
".",
"ID",
"]",
"=",
"*",
"node",
"\n",
"}"
] | // updateOutboundNodes set the outbound nodes from the last step group | [
"updateOutboundNodes",
"set",
"the",
"outbound",
"nodes",
"from",
"the",
"last",
"step",
"group"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/steps.go#L122-L148 | train |
argoproj/argo | workflow/controller/steps.go | shouldExecute | func shouldExecute(when string) (bool, error) {
if when == "" {
return true, nil
}
expression, err := govaluate.NewEvaluableExpression(when)
if err != nil {
return false, errors.Errorf(errors.CodeBadRequest, "Invalid 'when' expression '%s': %v", when, err)
}
// The following loop converts govaluate variables (which we don't use), into strings. This
// allows us to have expressions like: "foo != bar" without requiring foo and bar to be quoted.
tokens := expression.Tokens()
for i, tok := range tokens {
switch tok.Kind {
case govaluate.VARIABLE:
tok.Kind = govaluate.STRING
default:
continue
}
tokens[i] = tok
}
expression, err = govaluate.NewEvaluableExpressionFromTokens(tokens)
if err != nil {
return false, errors.InternalWrapErrorf(err, "Failed to parse 'when' expression '%s': %v", when, err)
}
result, err := expression.Evaluate(nil)
if err != nil {
return false, errors.InternalWrapErrorf(err, "Failed to evaluate 'when' expresion '%s': %v", when, err)
}
boolRes, ok := result.(bool)
if !ok {
return false, errors.Errorf(errors.CodeBadRequest, "Expected boolean evaluation for '%s'. Got %v", when, result)
}
return boolRes, nil
} | go | func shouldExecute(when string) (bool, error) {
if when == "" {
return true, nil
}
expression, err := govaluate.NewEvaluableExpression(when)
if err != nil {
return false, errors.Errorf(errors.CodeBadRequest, "Invalid 'when' expression '%s': %v", when, err)
}
// The following loop converts govaluate variables (which we don't use), into strings. This
// allows us to have expressions like: "foo != bar" without requiring foo and bar to be quoted.
tokens := expression.Tokens()
for i, tok := range tokens {
switch tok.Kind {
case govaluate.VARIABLE:
tok.Kind = govaluate.STRING
default:
continue
}
tokens[i] = tok
}
expression, err = govaluate.NewEvaluableExpressionFromTokens(tokens)
if err != nil {
return false, errors.InternalWrapErrorf(err, "Failed to parse 'when' expression '%s': %v", when, err)
}
result, err := expression.Evaluate(nil)
if err != nil {
return false, errors.InternalWrapErrorf(err, "Failed to evaluate 'when' expresion '%s': %v", when, err)
}
boolRes, ok := result.(bool)
if !ok {
return false, errors.Errorf(errors.CodeBadRequest, "Expected boolean evaluation for '%s'. Got %v", when, result)
}
return boolRes, nil
} | [
"func",
"shouldExecute",
"(",
"when",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"when",
"==",
"\"",
"\"",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"expression",
",",
"err",
":=",
"govaluate",
".",
"NewEvaluableExpression",
"(",
"when",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Errorf",
"(",
"errors",
".",
"CodeBadRequest",
",",
"\"",
"\"",
",",
"when",
",",
"err",
")",
"\n",
"}",
"\n",
"// The following loop converts govaluate variables (which we don't use), into strings. This",
"// allows us to have expressions like: \"foo != bar\" without requiring foo and bar to be quoted.",
"tokens",
":=",
"expression",
".",
"Tokens",
"(",
")",
"\n",
"for",
"i",
",",
"tok",
":=",
"range",
"tokens",
"{",
"switch",
"tok",
".",
"Kind",
"{",
"case",
"govaluate",
".",
"VARIABLE",
":",
"tok",
".",
"Kind",
"=",
"govaluate",
".",
"STRING",
"\n",
"default",
":",
"continue",
"\n",
"}",
"\n",
"tokens",
"[",
"i",
"]",
"=",
"tok",
"\n",
"}",
"\n",
"expression",
",",
"err",
"=",
"govaluate",
".",
"NewEvaluableExpressionFromTokens",
"(",
"tokens",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"InternalWrapErrorf",
"(",
"err",
",",
"\"",
"\"",
",",
"when",
",",
"err",
")",
"\n",
"}",
"\n",
"result",
",",
"err",
":=",
"expression",
".",
"Evaluate",
"(",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"InternalWrapErrorf",
"(",
"err",
",",
"\"",
"\"",
",",
"when",
",",
"err",
")",
"\n",
"}",
"\n",
"boolRes",
",",
"ok",
":=",
"result",
".",
"(",
"bool",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
",",
"errors",
".",
"Errorf",
"(",
"errors",
".",
"CodeBadRequest",
",",
"\"",
"\"",
",",
"when",
",",
"result",
")",
"\n",
"}",
"\n",
"return",
"boolRes",
",",
"nil",
"\n",
"}"
] | // shouldExecute evaluates a already substituted when expression to decide whether or not a step should execute | [
"shouldExecute",
"evaluates",
"a",
"already",
"substituted",
"when",
"expression",
"to",
"decide",
"whether",
"or",
"not",
"a",
"step",
"should",
"execute"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/steps.go#L236-L269 | train |
argoproj/argo | workflow/controller/steps.go | expandStep | func (woc *wfOperationCtx) expandStep(step wfv1.WorkflowStep) ([]wfv1.WorkflowStep, error) {
stepBytes, err := json.Marshal(step)
if err != nil {
return nil, errors.InternalWrapError(err)
}
fstTmpl := fasttemplate.New(string(stepBytes), "{{", "}}")
expandedStep := make([]wfv1.WorkflowStep, 0)
var items []wfv1.Item
if len(step.WithItems) > 0 {
items = step.WithItems
} else if step.WithParam != "" {
err = json.Unmarshal([]byte(step.WithParam), &items)
if err != nil {
return nil, errors.Errorf(errors.CodeBadRequest, "withParam value could not be parsed as a JSON list: %s", strings.TrimSpace(step.WithParam))
}
} else if step.WithSequence != nil {
items, err = expandSequence(step.WithSequence)
if err != nil {
return nil, err
}
} else {
// this should have been prevented in expandStepGroup()
return nil, errors.InternalError("expandStep() was called with withItems and withParam empty")
}
for i, item := range items {
var newStep wfv1.WorkflowStep
newStepName, err := processItem(fstTmpl, step.Name, i, item, &newStep)
if err != nil {
return nil, err
}
newStep.Name = newStepName
newStep.Template = step.Template
expandedStep = append(expandedStep, newStep)
}
return expandedStep, nil
} | go | func (woc *wfOperationCtx) expandStep(step wfv1.WorkflowStep) ([]wfv1.WorkflowStep, error) {
stepBytes, err := json.Marshal(step)
if err != nil {
return nil, errors.InternalWrapError(err)
}
fstTmpl := fasttemplate.New(string(stepBytes), "{{", "}}")
expandedStep := make([]wfv1.WorkflowStep, 0)
var items []wfv1.Item
if len(step.WithItems) > 0 {
items = step.WithItems
} else if step.WithParam != "" {
err = json.Unmarshal([]byte(step.WithParam), &items)
if err != nil {
return nil, errors.Errorf(errors.CodeBadRequest, "withParam value could not be parsed as a JSON list: %s", strings.TrimSpace(step.WithParam))
}
} else if step.WithSequence != nil {
items, err = expandSequence(step.WithSequence)
if err != nil {
return nil, err
}
} else {
// this should have been prevented in expandStepGroup()
return nil, errors.InternalError("expandStep() was called with withItems and withParam empty")
}
for i, item := range items {
var newStep wfv1.WorkflowStep
newStepName, err := processItem(fstTmpl, step.Name, i, item, &newStep)
if err != nil {
return nil, err
}
newStep.Name = newStepName
newStep.Template = step.Template
expandedStep = append(expandedStep, newStep)
}
return expandedStep, nil
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"expandStep",
"(",
"step",
"wfv1",
".",
"WorkflowStep",
")",
"(",
"[",
"]",
"wfv1",
".",
"WorkflowStep",
",",
"error",
")",
"{",
"stepBytes",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"step",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"InternalWrapError",
"(",
"err",
")",
"\n",
"}",
"\n",
"fstTmpl",
":=",
"fasttemplate",
".",
"New",
"(",
"string",
"(",
"stepBytes",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"expandedStep",
":=",
"make",
"(",
"[",
"]",
"wfv1",
".",
"WorkflowStep",
",",
"0",
")",
"\n",
"var",
"items",
"[",
"]",
"wfv1",
".",
"Item",
"\n",
"if",
"len",
"(",
"step",
".",
"WithItems",
")",
">",
"0",
"{",
"items",
"=",
"step",
".",
"WithItems",
"\n",
"}",
"else",
"if",
"step",
".",
"WithParam",
"!=",
"\"",
"\"",
"{",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"step",
".",
"WithParam",
")",
",",
"&",
"items",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"errors",
".",
"CodeBadRequest",
",",
"\"",
"\"",
",",
"strings",
".",
"TrimSpace",
"(",
"step",
".",
"WithParam",
")",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"step",
".",
"WithSequence",
"!=",
"nil",
"{",
"items",
",",
"err",
"=",
"expandSequence",
"(",
"step",
".",
"WithSequence",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// this should have been prevented in expandStepGroup()",
"return",
"nil",
",",
"errors",
".",
"InternalError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"item",
":=",
"range",
"items",
"{",
"var",
"newStep",
"wfv1",
".",
"WorkflowStep",
"\n",
"newStepName",
",",
"err",
":=",
"processItem",
"(",
"fstTmpl",
",",
"step",
".",
"Name",
",",
"i",
",",
"item",
",",
"&",
"newStep",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"newStep",
".",
"Name",
"=",
"newStepName",
"\n",
"newStep",
".",
"Template",
"=",
"step",
".",
"Template",
"\n",
"expandedStep",
"=",
"append",
"(",
"expandedStep",
",",
"newStep",
")",
"\n",
"}",
"\n",
"return",
"expandedStep",
",",
"nil",
"\n",
"}"
] | // expandStep expands a step containing withItems or withParams into multiple parallel steps | [
"expandStep",
"expands",
"a",
"step",
"containing",
"withItems",
"or",
"withParams",
"into",
"multiple",
"parallel",
"steps"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/steps.go#L343-L379 | train |
argoproj/argo | version.go | GetVersion | func GetVersion() Version {
var versionStr string
if gitCommit != "" && gitTag != "" && gitTreeState == "clean" {
// if we have a clean tree state and the current commit is tagged,
// this is an official release.
versionStr = gitTag
} else {
// otherwise formulate a version string based on as much metadata
// information we have available.
versionStr = "v" + version
if len(gitCommit) >= 7 {
versionStr += "+" + gitCommit[0:7]
if gitTreeState != "clean" {
versionStr += ".dirty"
}
} else {
versionStr += "+unknown"
}
}
return Version{
Version: versionStr,
BuildDate: buildDate,
GitCommit: gitCommit,
GitTag: gitTag,
GitTreeState: gitTreeState,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
} | go | func GetVersion() Version {
var versionStr string
if gitCommit != "" && gitTag != "" && gitTreeState == "clean" {
// if we have a clean tree state and the current commit is tagged,
// this is an official release.
versionStr = gitTag
} else {
// otherwise formulate a version string based on as much metadata
// information we have available.
versionStr = "v" + version
if len(gitCommit) >= 7 {
versionStr += "+" + gitCommit[0:7]
if gitTreeState != "clean" {
versionStr += ".dirty"
}
} else {
versionStr += "+unknown"
}
}
return Version{
Version: versionStr,
BuildDate: buildDate,
GitCommit: gitCommit,
GitTag: gitTag,
GitTreeState: gitTreeState,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
} | [
"func",
"GetVersion",
"(",
")",
"Version",
"{",
"var",
"versionStr",
"string",
"\n",
"if",
"gitCommit",
"!=",
"\"",
"\"",
"&&",
"gitTag",
"!=",
"\"",
"\"",
"&&",
"gitTreeState",
"==",
"\"",
"\"",
"{",
"// if we have a clean tree state and the current commit is tagged,",
"// this is an official release.",
"versionStr",
"=",
"gitTag",
"\n",
"}",
"else",
"{",
"// otherwise formulate a version string based on as much metadata",
"// information we have available.",
"versionStr",
"=",
"\"",
"\"",
"+",
"version",
"\n",
"if",
"len",
"(",
"gitCommit",
")",
">=",
"7",
"{",
"versionStr",
"+=",
"\"",
"\"",
"+",
"gitCommit",
"[",
"0",
":",
"7",
"]",
"\n",
"if",
"gitTreeState",
"!=",
"\"",
"\"",
"{",
"versionStr",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"else",
"{",
"versionStr",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"Version",
"{",
"Version",
":",
"versionStr",
",",
"BuildDate",
":",
"buildDate",
",",
"GitCommit",
":",
"gitCommit",
",",
"GitTag",
":",
"gitTag",
",",
"GitTreeState",
":",
"gitTreeState",
",",
"GoVersion",
":",
"runtime",
".",
"Version",
"(",
")",
",",
"Compiler",
":",
"runtime",
".",
"Compiler",
",",
"Platform",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"runtime",
".",
"GOOS",
",",
"runtime",
".",
"GOARCH",
")",
",",
"}",
"\n",
"}"
] | // GetVersion returns the version information | [
"GetVersion",
"returns",
"the",
"version",
"information"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/version.go#L35-L64 | train |
argoproj/argo | workflow/executor/pns/pns.go | enterChroot | func (p *PNSExecutor) enterChroot() error {
if p.mainFS == nil {
return errors.InternalErrorf("could not chroot into main for artifact collection: container may have exited too quickly")
}
if err := p.mainFS.Chdir(); err != nil {
return errors.InternalWrapErrorf(err, "failed to chdir to main filesystem: %v", err)
}
err := syscall.Chroot(".")
if err != nil {
return errors.InternalWrapErrorf(err, "failed to chroot to main filesystem: %v", err)
}
return nil
} | go | func (p *PNSExecutor) enterChroot() error {
if p.mainFS == nil {
return errors.InternalErrorf("could not chroot into main for artifact collection: container may have exited too quickly")
}
if err := p.mainFS.Chdir(); err != nil {
return errors.InternalWrapErrorf(err, "failed to chdir to main filesystem: %v", err)
}
err := syscall.Chroot(".")
if err != nil {
return errors.InternalWrapErrorf(err, "failed to chroot to main filesystem: %v", err)
}
return nil
} | [
"func",
"(",
"p",
"*",
"PNSExecutor",
")",
"enterChroot",
"(",
")",
"error",
"{",
"if",
"p",
".",
"mainFS",
"==",
"nil",
"{",
"return",
"errors",
".",
"InternalErrorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"p",
".",
"mainFS",
".",
"Chdir",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"InternalWrapErrorf",
"(",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"err",
":=",
"syscall",
".",
"Chroot",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"InternalWrapErrorf",
"(",
"err",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // enterChroot enters chroot of the main container | [
"enterChroot",
"enters",
"chroot",
"of",
"the",
"main",
"container"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/pns/pns.go#L92-L104 | train |
argoproj/argo | workflow/executor/pns/pns.go | exitChroot | func (p *PNSExecutor) exitChroot() error {
if err := p.rootFS.Chdir(); err != nil {
return errors.InternalWrapError(err)
}
err := syscall.Chroot(".")
if err != nil {
return errors.InternalWrapError(err)
}
return nil
} | go | func (p *PNSExecutor) exitChroot() error {
if err := p.rootFS.Chdir(); err != nil {
return errors.InternalWrapError(err)
}
err := syscall.Chroot(".")
if err != nil {
return errors.InternalWrapError(err)
}
return nil
} | [
"func",
"(",
"p",
"*",
"PNSExecutor",
")",
"exitChroot",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"p",
".",
"rootFS",
".",
"Chdir",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"InternalWrapError",
"(",
"err",
")",
"\n",
"}",
"\n",
"err",
":=",
"syscall",
".",
"Chroot",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"InternalWrapError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // exitChroot exits chroot | [
"exitChroot",
"exits",
"chroot"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/pns/pns.go#L107-L116 | train |
argoproj/argo | workflow/executor/pns/pns.go | CopyFile | func (p *PNSExecutor) CopyFile(containerID string, sourcePath string, destPath string) (err error) {
destFile, err := os.Create(destPath)
if err != nil {
return err
}
defer func() {
// exit chroot and close the file. preserve the original error
deferErr := p.exitChroot()
if err == nil && deferErr != nil {
err = errors.InternalWrapError(deferErr)
}
deferErr = destFile.Close()
if err == nil && deferErr != nil {
err = errors.InternalWrapError(deferErr)
}
}()
w := bufio.NewWriter(destFile)
err = p.enterChroot()
if err != nil {
return err
}
err = archive.TarGzToWriter(sourcePath, w)
if err != nil {
return err
}
return nil
} | go | func (p *PNSExecutor) CopyFile(containerID string, sourcePath string, destPath string) (err error) {
destFile, err := os.Create(destPath)
if err != nil {
return err
}
defer func() {
// exit chroot and close the file. preserve the original error
deferErr := p.exitChroot()
if err == nil && deferErr != nil {
err = errors.InternalWrapError(deferErr)
}
deferErr = destFile.Close()
if err == nil && deferErr != nil {
err = errors.InternalWrapError(deferErr)
}
}()
w := bufio.NewWriter(destFile)
err = p.enterChroot()
if err != nil {
return err
}
err = archive.TarGzToWriter(sourcePath, w)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"p",
"*",
"PNSExecutor",
")",
"CopyFile",
"(",
"containerID",
"string",
",",
"sourcePath",
"string",
",",
"destPath",
"string",
")",
"(",
"err",
"error",
")",
"{",
"destFile",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"destPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"// exit chroot and close the file. preserve the original error",
"deferErr",
":=",
"p",
".",
"exitChroot",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"deferErr",
"!=",
"nil",
"{",
"err",
"=",
"errors",
".",
"InternalWrapError",
"(",
"deferErr",
")",
"\n",
"}",
"\n",
"deferErr",
"=",
"destFile",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"deferErr",
"!=",
"nil",
"{",
"err",
"=",
"errors",
".",
"InternalWrapError",
"(",
"deferErr",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"w",
":=",
"bufio",
".",
"NewWriter",
"(",
"destFile",
")",
"\n",
"err",
"=",
"p",
".",
"enterChroot",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"archive",
".",
"TarGzToWriter",
"(",
"sourcePath",
",",
"w",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // CopyFile copies a source file in a container to a local path | [
"CopyFile",
"copies",
"a",
"source",
"file",
"in",
"a",
"container",
"to",
"a",
"local",
"path"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/pns/pns.go#L119-L147 | train |
argoproj/argo | workflow/executor/pns/pns.go | Kill | func (p *PNSExecutor) Kill(containerIDs []string) error {
var asyncErr error
wg := sync.WaitGroup{}
for _, cid := range containerIDs {
wg.Add(1)
go func(containerID string) {
err := p.killContainer(containerID)
if err != nil && asyncErr != nil {
asyncErr = err
}
wg.Done()
}(cid)
}
wg.Wait()
return asyncErr
} | go | func (p *PNSExecutor) Kill(containerIDs []string) error {
var asyncErr error
wg := sync.WaitGroup{}
for _, cid := range containerIDs {
wg.Add(1)
go func(containerID string) {
err := p.killContainer(containerID)
if err != nil && asyncErr != nil {
asyncErr = err
}
wg.Done()
}(cid)
}
wg.Wait()
return asyncErr
} | [
"func",
"(",
"p",
"*",
"PNSExecutor",
")",
"Kill",
"(",
"containerIDs",
"[",
"]",
"string",
")",
"error",
"{",
"var",
"asyncErr",
"error",
"\n",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"for",
"_",
",",
"cid",
":=",
"range",
"containerIDs",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"containerID",
"string",
")",
"{",
"err",
":=",
"p",
".",
"killContainer",
"(",
"containerID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"asyncErr",
"!=",
"nil",
"{",
"asyncErr",
"=",
"err",
"\n",
"}",
"\n",
"wg",
".",
"Done",
"(",
")",
"\n",
"}",
"(",
"cid",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"return",
"asyncErr",
"\n",
"}"
] | // Kill a list of containerIDs first with a SIGTERM then with a SIGKILL after a grace period | [
"Kill",
"a",
"list",
"of",
"containerIDs",
"first",
"with",
"a",
"SIGTERM",
"then",
"with",
"a",
"SIGKILL",
"after",
"a",
"grace",
"period"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/pns/pns.go#L232-L247 | train |
argoproj/argo | workflow/executor/pns/pns.go | getContainerPID | func (p *PNSExecutor) getContainerPID(containerID string) (int, error) {
pid, ok := p.ctrIDToPid[containerID]
if ok {
return pid, nil
}
p.updateCtrIDMap()
pid, ok = p.ctrIDToPid[containerID]
if !ok {
return -1, errors.InternalErrorf("Failed to determine pid for containerID %s: container may have exited too quickly", containerID)
}
return pid, nil
} | go | func (p *PNSExecutor) getContainerPID(containerID string) (int, error) {
pid, ok := p.ctrIDToPid[containerID]
if ok {
return pid, nil
}
p.updateCtrIDMap()
pid, ok = p.ctrIDToPid[containerID]
if !ok {
return -1, errors.InternalErrorf("Failed to determine pid for containerID %s: container may have exited too quickly", containerID)
}
return pid, nil
} | [
"func",
"(",
"p",
"*",
"PNSExecutor",
")",
"getContainerPID",
"(",
"containerID",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"pid",
",",
"ok",
":=",
"p",
".",
"ctrIDToPid",
"[",
"containerID",
"]",
"\n",
"if",
"ok",
"{",
"return",
"pid",
",",
"nil",
"\n",
"}",
"\n",
"p",
".",
"updateCtrIDMap",
"(",
")",
"\n",
"pid",
",",
"ok",
"=",
"p",
".",
"ctrIDToPid",
"[",
"containerID",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"-",
"1",
",",
"errors",
".",
"InternalErrorf",
"(",
"\"",
"\"",
",",
"containerID",
")",
"\n",
"}",
"\n",
"return",
"pid",
",",
"nil",
"\n",
"}"
] | // getContainerPID returns the pid associated with the container id. Returns error if it was unable
// to be determined because no running root processes exist with that container ID | [
"getContainerPID",
"returns",
"the",
"pid",
"associated",
"with",
"the",
"container",
"id",
".",
"Returns",
"error",
"if",
"it",
"was",
"unable",
"to",
"be",
"determined",
"because",
"no",
"running",
"root",
"processes",
"exist",
"with",
"that",
"container",
"ID"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/pns/pns.go#L284-L295 | train |
argoproj/argo | workflow/executor/pns/pns.go | updateCtrIDMap | func (p *PNSExecutor) updateCtrIDMap() {
allProcs, err := gops.Processes()
if err != nil {
log.Warnf("Failed to list processes: %v", err)
return
}
for _, proc := range allProcs {
pid := proc.Pid()
if pid == 1 || pid == p.thisPID || proc.PPid() != 0 {
// ignore the pause container, our own pid, and non-root processes
continue
}
// Useful code for debugging:
if p.debug {
if data, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/root", pid) + "/etc/os-release"); err == nil {
log.Infof("pid %d: %s", pid, string(data))
_, _ = parseContainerID(pid)
}
}
if p.hasOutputs && p.mainFS == nil {
rootPath := fmt.Sprintf("/proc/%d/root", pid)
currInfo, err := os.Stat(rootPath)
if err != nil {
log.Warnf("Failed to stat %s: %v", rootPath, err)
continue
}
log.Infof("pid %d: %v", pid, currInfo)
prevInfo := p.pidFileHandles[pid]
// Secure the root filehandle of the process. NOTE if the file changed, it means that
// the main container may have switched (e.g. gone from busybox to the user's container)
if prevInfo == nil || !os.SameFile(prevInfo.info, currInfo) {
fs, err := os.Open(rootPath)
if err != nil {
log.Warnf("Failed to open %s: %v", rootPath, err)
continue
}
log.Infof("Secured filehandle on %s", rootPath)
p.pidFileHandles[pid] = &fileInfo{
info: currInfo,
file: *fs,
}
if prevInfo != nil {
_ = prevInfo.file.Close()
}
}
}
// Update maps of pids to container ids
if _, ok := p.pidToCtrID[pid]; !ok {
containerID, err := parseContainerID(pid)
if err != nil {
log.Warnf("Failed to identify containerID for process %d", pid)
continue
}
log.Infof("containerID %s mapped to pid %d", containerID, pid)
p.ctrIDToPid[containerID] = pid
p.pidToCtrID[pid] = containerID
}
}
} | go | func (p *PNSExecutor) updateCtrIDMap() {
allProcs, err := gops.Processes()
if err != nil {
log.Warnf("Failed to list processes: %v", err)
return
}
for _, proc := range allProcs {
pid := proc.Pid()
if pid == 1 || pid == p.thisPID || proc.PPid() != 0 {
// ignore the pause container, our own pid, and non-root processes
continue
}
// Useful code for debugging:
if p.debug {
if data, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/root", pid) + "/etc/os-release"); err == nil {
log.Infof("pid %d: %s", pid, string(data))
_, _ = parseContainerID(pid)
}
}
if p.hasOutputs && p.mainFS == nil {
rootPath := fmt.Sprintf("/proc/%d/root", pid)
currInfo, err := os.Stat(rootPath)
if err != nil {
log.Warnf("Failed to stat %s: %v", rootPath, err)
continue
}
log.Infof("pid %d: %v", pid, currInfo)
prevInfo := p.pidFileHandles[pid]
// Secure the root filehandle of the process. NOTE if the file changed, it means that
// the main container may have switched (e.g. gone from busybox to the user's container)
if prevInfo == nil || !os.SameFile(prevInfo.info, currInfo) {
fs, err := os.Open(rootPath)
if err != nil {
log.Warnf("Failed to open %s: %v", rootPath, err)
continue
}
log.Infof("Secured filehandle on %s", rootPath)
p.pidFileHandles[pid] = &fileInfo{
info: currInfo,
file: *fs,
}
if prevInfo != nil {
_ = prevInfo.file.Close()
}
}
}
// Update maps of pids to container ids
if _, ok := p.pidToCtrID[pid]; !ok {
containerID, err := parseContainerID(pid)
if err != nil {
log.Warnf("Failed to identify containerID for process %d", pid)
continue
}
log.Infof("containerID %s mapped to pid %d", containerID, pid)
p.ctrIDToPid[containerID] = pid
p.pidToCtrID[pid] = containerID
}
}
} | [
"func",
"(",
"p",
"*",
"PNSExecutor",
")",
"updateCtrIDMap",
"(",
")",
"{",
"allProcs",
",",
"err",
":=",
"gops",
".",
"Processes",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"for",
"_",
",",
"proc",
":=",
"range",
"allProcs",
"{",
"pid",
":=",
"proc",
".",
"Pid",
"(",
")",
"\n",
"if",
"pid",
"==",
"1",
"||",
"pid",
"==",
"p",
".",
"thisPID",
"||",
"proc",
".",
"PPid",
"(",
")",
"!=",
"0",
"{",
"// ignore the pause container, our own pid, and non-root processes",
"continue",
"\n",
"}",
"\n\n",
"// Useful code for debugging:",
"if",
"p",
".",
"debug",
"{",
"if",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pid",
")",
"+",
"\"",
"\"",
")",
";",
"err",
"==",
"nil",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"pid",
",",
"string",
"(",
"data",
")",
")",
"\n",
"_",
",",
"_",
"=",
"parseContainerID",
"(",
"pid",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"p",
".",
"hasOutputs",
"&&",
"p",
".",
"mainFS",
"==",
"nil",
"{",
"rootPath",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pid",
")",
"\n",
"currInfo",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"rootPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"rootPath",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"pid",
",",
"currInfo",
")",
"\n",
"prevInfo",
":=",
"p",
".",
"pidFileHandles",
"[",
"pid",
"]",
"\n\n",
"// Secure the root filehandle of the process. NOTE if the file changed, it means that",
"// the main container may have switched (e.g. gone from busybox to the user's container)",
"if",
"prevInfo",
"==",
"nil",
"||",
"!",
"os",
".",
"SameFile",
"(",
"prevInfo",
".",
"info",
",",
"currInfo",
")",
"{",
"fs",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"rootPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"rootPath",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"rootPath",
")",
"\n",
"p",
".",
"pidFileHandles",
"[",
"pid",
"]",
"=",
"&",
"fileInfo",
"{",
"info",
":",
"currInfo",
",",
"file",
":",
"*",
"fs",
",",
"}",
"\n",
"if",
"prevInfo",
"!=",
"nil",
"{",
"_",
"=",
"prevInfo",
".",
"file",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Update maps of pids to container ids",
"if",
"_",
",",
"ok",
":=",
"p",
".",
"pidToCtrID",
"[",
"pid",
"]",
";",
"!",
"ok",
"{",
"containerID",
",",
"err",
":=",
"parseContainerID",
"(",
"pid",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"pid",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"containerID",
",",
"pid",
")",
"\n",
"p",
".",
"ctrIDToPid",
"[",
"containerID",
"]",
"=",
"pid",
"\n",
"p",
".",
"pidToCtrID",
"[",
"pid",
"]",
"=",
"containerID",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // updateCtrIDMap updates the mapping between container IDs to PIDs | [
"updateCtrIDMap",
"updates",
"the",
"mapping",
"between",
"container",
"IDs",
"to",
"PIDs"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/pns/pns.go#L298-L360 | train |
argoproj/argo | workflow/executor/pns/pns.go | parseContainerID | func parseContainerID(pid int) (string, error) {
cgroupPath := fmt.Sprintf("/proc/%d/cgroup", pid)
cgroupFile, err := os.OpenFile(cgroupPath, os.O_RDONLY, os.ModePerm)
if err != nil {
return "", errors.InternalWrapError(err)
}
defer func() { _ = cgroupFile.Close() }()
sc := bufio.NewScanner(cgroupFile)
for sc.Scan() {
// See https://www.systutorials.com/docs/linux/man/5-proc/ for /proc/XX/cgroup format. e.g.:
// 5:cpuacct,cpu,cpuset:/daemons
line := sc.Text()
log.Debugf("pid %d: %s", pid, line)
parts := strings.Split(line, "/")
if len(parts) > 1 {
if containerID := parts[len(parts)-1]; containerID != "" {
// need to check for empty string because the line may look like: 5:rdma:/
return containerID, nil
}
}
}
return "", errors.InternalErrorf("Failed to parse container ID from %s", cgroupPath)
} | go | func parseContainerID(pid int) (string, error) {
cgroupPath := fmt.Sprintf("/proc/%d/cgroup", pid)
cgroupFile, err := os.OpenFile(cgroupPath, os.O_RDONLY, os.ModePerm)
if err != nil {
return "", errors.InternalWrapError(err)
}
defer func() { _ = cgroupFile.Close() }()
sc := bufio.NewScanner(cgroupFile)
for sc.Scan() {
// See https://www.systutorials.com/docs/linux/man/5-proc/ for /proc/XX/cgroup format. e.g.:
// 5:cpuacct,cpu,cpuset:/daemons
line := sc.Text()
log.Debugf("pid %d: %s", pid, line)
parts := strings.Split(line, "/")
if len(parts) > 1 {
if containerID := parts[len(parts)-1]; containerID != "" {
// need to check for empty string because the line may look like: 5:rdma:/
return containerID, nil
}
}
}
return "", errors.InternalErrorf("Failed to parse container ID from %s", cgroupPath)
} | [
"func",
"parseContainerID",
"(",
"pid",
"int",
")",
"(",
"string",
",",
"error",
")",
"{",
"cgroupPath",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pid",
")",
"\n",
"cgroupFile",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"cgroupPath",
",",
"os",
".",
"O_RDONLY",
",",
"os",
".",
"ModePerm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"InternalWrapError",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"_",
"=",
"cgroupFile",
".",
"Close",
"(",
")",
"}",
"(",
")",
"\n",
"sc",
":=",
"bufio",
".",
"NewScanner",
"(",
"cgroupFile",
")",
"\n",
"for",
"sc",
".",
"Scan",
"(",
")",
"{",
"// See https://www.systutorials.com/docs/linux/man/5-proc/ for /proc/XX/cgroup format. e.g.:",
"// 5:cpuacct,cpu,cpuset:/daemons",
"line",
":=",
"sc",
".",
"Text",
"(",
")",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"pid",
",",
"line",
")",
"\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
">",
"1",
"{",
"if",
"containerID",
":=",
"parts",
"[",
"len",
"(",
"parts",
")",
"-",
"1",
"]",
";",
"containerID",
"!=",
"\"",
"\"",
"{",
"// need to check for empty string because the line may look like: 5:rdma:/",
"return",
"containerID",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"InternalErrorf",
"(",
"\"",
"\"",
",",
"cgroupPath",
")",
"\n",
"}"
] | // parseContainerID parses the containerID of a pid | [
"parseContainerID",
"parses",
"the",
"containerID",
"of",
"a",
"pid"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/pns/pns.go#L363-L385 | train |
argoproj/argo | workflow/artifacts/s3/s3.go | newS3Client | func (s3Driver *S3ArtifactDriver) newS3Client() (argos3.S3Client, error) {
opts := argos3.S3ClientOpts{
Endpoint: s3Driver.Endpoint,
Region: s3Driver.Region,
Secure: s3Driver.Secure,
AccessKey: s3Driver.AccessKey,
SecretKey: s3Driver.SecretKey,
}
return argos3.NewS3Client(opts)
} | go | func (s3Driver *S3ArtifactDriver) newS3Client() (argos3.S3Client, error) {
opts := argos3.S3ClientOpts{
Endpoint: s3Driver.Endpoint,
Region: s3Driver.Region,
Secure: s3Driver.Secure,
AccessKey: s3Driver.AccessKey,
SecretKey: s3Driver.SecretKey,
}
return argos3.NewS3Client(opts)
} | [
"func",
"(",
"s3Driver",
"*",
"S3ArtifactDriver",
")",
"newS3Client",
"(",
")",
"(",
"argos3",
".",
"S3Client",
",",
"error",
")",
"{",
"opts",
":=",
"argos3",
".",
"S3ClientOpts",
"{",
"Endpoint",
":",
"s3Driver",
".",
"Endpoint",
",",
"Region",
":",
"s3Driver",
".",
"Region",
",",
"Secure",
":",
"s3Driver",
".",
"Secure",
",",
"AccessKey",
":",
"s3Driver",
".",
"AccessKey",
",",
"SecretKey",
":",
"s3Driver",
".",
"SecretKey",
",",
"}",
"\n",
"return",
"argos3",
".",
"NewS3Client",
"(",
"opts",
")",
"\n",
"}"
] | // newMinioClient instantiates a new minio client object. | [
"newMinioClient",
"instantiates",
"a",
"new",
"minio",
"client",
"object",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/artifacts/s3/s3.go#L24-L33 | train |
argoproj/argo | workflow/artifacts/s3/s3.go | Load | func (s3Driver *S3ArtifactDriver) Load(inputArtifact *wfv1.Artifact, path string) error {
err := wait.ExponentialBackoff(wait.Backoff{Duration: time.Second * 2, Factor: 2.0, Steps: 5, Jitter: 0.1},
func() (bool, error) {
log.Infof("S3 Load path: %s, key: %s", path, inputArtifact.S3.Key)
s3cli, err := s3Driver.newS3Client()
if err != nil {
log.Warnf("Failed to create new S3 client: %v", err)
return false, nil
}
origErr := s3cli.GetFile(inputArtifact.S3.Bucket, inputArtifact.S3.Key, path)
if origErr == nil {
return true, nil
}
if !argos3.IsS3ErrCode(origErr, "NoSuchKey") {
log.Warnf("Failed get file: %v", origErr)
return false, nil
}
// If we get here, the error was a NoSuchKey. The key might be a s3 "directory"
isDir, err := s3cli.IsDirectory(inputArtifact.S3.Bucket, inputArtifact.S3.Key)
if err != nil {
log.Warnf("Failed to test if %s is a directory: %v", inputArtifact.S3.Bucket, err)
return false, nil
}
if !isDir {
// It's neither a file, nor a directory. Return the original NoSuchKey error
return false, origErr
}
if err = s3cli.GetDirectory(inputArtifact.S3.Bucket, inputArtifact.S3.Key, path); err != nil {
log.Warnf("Failed get directory: %v", err)
return false, nil
}
return true, nil
})
return err
} | go | func (s3Driver *S3ArtifactDriver) Load(inputArtifact *wfv1.Artifact, path string) error {
err := wait.ExponentialBackoff(wait.Backoff{Duration: time.Second * 2, Factor: 2.0, Steps: 5, Jitter: 0.1},
func() (bool, error) {
log.Infof("S3 Load path: %s, key: %s", path, inputArtifact.S3.Key)
s3cli, err := s3Driver.newS3Client()
if err != nil {
log.Warnf("Failed to create new S3 client: %v", err)
return false, nil
}
origErr := s3cli.GetFile(inputArtifact.S3.Bucket, inputArtifact.S3.Key, path)
if origErr == nil {
return true, nil
}
if !argos3.IsS3ErrCode(origErr, "NoSuchKey") {
log.Warnf("Failed get file: %v", origErr)
return false, nil
}
// If we get here, the error was a NoSuchKey. The key might be a s3 "directory"
isDir, err := s3cli.IsDirectory(inputArtifact.S3.Bucket, inputArtifact.S3.Key)
if err != nil {
log.Warnf("Failed to test if %s is a directory: %v", inputArtifact.S3.Bucket, err)
return false, nil
}
if !isDir {
// It's neither a file, nor a directory. Return the original NoSuchKey error
return false, origErr
}
if err = s3cli.GetDirectory(inputArtifact.S3.Bucket, inputArtifact.S3.Key, path); err != nil {
log.Warnf("Failed get directory: %v", err)
return false, nil
}
return true, nil
})
return err
} | [
"func",
"(",
"s3Driver",
"*",
"S3ArtifactDriver",
")",
"Load",
"(",
"inputArtifact",
"*",
"wfv1",
".",
"Artifact",
",",
"path",
"string",
")",
"error",
"{",
"err",
":=",
"wait",
".",
"ExponentialBackoff",
"(",
"wait",
".",
"Backoff",
"{",
"Duration",
":",
"time",
".",
"Second",
"*",
"2",
",",
"Factor",
":",
"2.0",
",",
"Steps",
":",
"5",
",",
"Jitter",
":",
"0.1",
"}",
",",
"func",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"path",
",",
"inputArtifact",
".",
"S3",
".",
"Key",
")",
"\n",
"s3cli",
",",
"err",
":=",
"s3Driver",
".",
"newS3Client",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"origErr",
":=",
"s3cli",
".",
"GetFile",
"(",
"inputArtifact",
".",
"S3",
".",
"Bucket",
",",
"inputArtifact",
".",
"S3",
".",
"Key",
",",
"path",
")",
"\n",
"if",
"origErr",
"==",
"nil",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"argos3",
".",
"IsS3ErrCode",
"(",
"origErr",
",",
"\"",
"\"",
")",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"origErr",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"// If we get here, the error was a NoSuchKey. The key might be a s3 \"directory\"",
"isDir",
",",
"err",
":=",
"s3cli",
".",
"IsDirectory",
"(",
"inputArtifact",
".",
"S3",
".",
"Bucket",
",",
"inputArtifact",
".",
"S3",
".",
"Key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"inputArtifact",
".",
"S3",
".",
"Bucket",
",",
"err",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"isDir",
"{",
"// It's neither a file, nor a directory. Return the original NoSuchKey error",
"return",
"false",
",",
"origErr",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"s3cli",
".",
"GetDirectory",
"(",
"inputArtifact",
".",
"S3",
".",
"Bucket",
",",
"inputArtifact",
".",
"S3",
".",
"Key",
",",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Load downloads artifacts from S3 compliant storage | [
"Load",
"downloads",
"artifacts",
"from",
"S3",
"compliant",
"storage"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/artifacts/s3/s3.go#L36-L72 | train |
argoproj/argo | workflow/artifacts/s3/s3.go | Save | func (s3Driver *S3ArtifactDriver) Save(path string, outputArtifact *wfv1.Artifact) error {
err := wait.ExponentialBackoff(wait.Backoff{Duration: time.Second * 2, Factor: 2.0, Steps: 5, Jitter: 0.1},
func() (bool, error) {
log.Infof("S3 Save path: %s, key: %s", path, outputArtifact.S3.Key)
s3cli, err := s3Driver.newS3Client()
if err != nil {
log.Warnf("Failed to create new S3 client: %v", err)
return false, nil
}
isDir, err := file.IsDirectory(path)
if err != nil {
log.Warnf("Failed to test if %s is a directory: %v", path, err)
return false, nil
}
if isDir {
if err = s3cli.PutDirectory(outputArtifact.S3.Bucket, outputArtifact.S3.Key, path); err != nil {
log.Warnf("Failed to put directory: %v", err)
return false, nil
}
} else {
if err = s3cli.PutFile(outputArtifact.S3.Bucket, outputArtifact.S3.Key, path); err != nil {
log.Warnf("Failed to put file: %v", err)
return false, nil
}
}
return true, nil
})
return err
} | go | func (s3Driver *S3ArtifactDriver) Save(path string, outputArtifact *wfv1.Artifact) error {
err := wait.ExponentialBackoff(wait.Backoff{Duration: time.Second * 2, Factor: 2.0, Steps: 5, Jitter: 0.1},
func() (bool, error) {
log.Infof("S3 Save path: %s, key: %s", path, outputArtifact.S3.Key)
s3cli, err := s3Driver.newS3Client()
if err != nil {
log.Warnf("Failed to create new S3 client: %v", err)
return false, nil
}
isDir, err := file.IsDirectory(path)
if err != nil {
log.Warnf("Failed to test if %s is a directory: %v", path, err)
return false, nil
}
if isDir {
if err = s3cli.PutDirectory(outputArtifact.S3.Bucket, outputArtifact.S3.Key, path); err != nil {
log.Warnf("Failed to put directory: %v", err)
return false, nil
}
} else {
if err = s3cli.PutFile(outputArtifact.S3.Bucket, outputArtifact.S3.Key, path); err != nil {
log.Warnf("Failed to put file: %v", err)
return false, nil
}
}
return true, nil
})
return err
} | [
"func",
"(",
"s3Driver",
"*",
"S3ArtifactDriver",
")",
"Save",
"(",
"path",
"string",
",",
"outputArtifact",
"*",
"wfv1",
".",
"Artifact",
")",
"error",
"{",
"err",
":=",
"wait",
".",
"ExponentialBackoff",
"(",
"wait",
".",
"Backoff",
"{",
"Duration",
":",
"time",
".",
"Second",
"*",
"2",
",",
"Factor",
":",
"2.0",
",",
"Steps",
":",
"5",
",",
"Jitter",
":",
"0.1",
"}",
",",
"func",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"path",
",",
"outputArtifact",
".",
"S3",
".",
"Key",
")",
"\n",
"s3cli",
",",
"err",
":=",
"s3Driver",
".",
"newS3Client",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"isDir",
",",
"err",
":=",
"file",
".",
"IsDirectory",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"path",
",",
"err",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"if",
"isDir",
"{",
"if",
"err",
"=",
"s3cli",
".",
"PutDirectory",
"(",
"outputArtifact",
".",
"S3",
".",
"Bucket",
",",
"outputArtifact",
".",
"S3",
".",
"Key",
",",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"err",
"=",
"s3cli",
".",
"PutFile",
"(",
"outputArtifact",
".",
"S3",
".",
"Bucket",
",",
"outputArtifact",
".",
"S3",
".",
"Key",
",",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Save saves an artifact to S3 compliant storage | [
"Save",
"saves",
"an",
"artifact",
"to",
"S3",
"compliant",
"storage"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/artifacts/s3/s3.go#L75-L103 | train |
argoproj/argo | workflow/artifacts/raw/raw.go | Load | func (a *RawArtifactDriver) Load(artifact *wfv1.Artifact, path string) error {
lf, err := os.Create(path)
if err != nil {
return err
}
defer func() {
_ = lf.Close()
}()
_, err = lf.WriteString(artifact.Raw.Data)
return err
} | go | func (a *RawArtifactDriver) Load(artifact *wfv1.Artifact, path string) error {
lf, err := os.Create(path)
if err != nil {
return err
}
defer func() {
_ = lf.Close()
}()
_, err = lf.WriteString(artifact.Raw.Data)
return err
} | [
"func",
"(",
"a",
"*",
"RawArtifactDriver",
")",
"Load",
"(",
"artifact",
"*",
"wfv1",
".",
"Artifact",
",",
"path",
"string",
")",
"error",
"{",
"lf",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"_",
"=",
"lf",
".",
"Close",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"_",
",",
"err",
"=",
"lf",
".",
"WriteString",
"(",
"artifact",
".",
"Raw",
".",
"Data",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Store raw content as artifact | [
"Store",
"raw",
"content",
"as",
"artifact"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/artifacts/raw/raw.go#L13-L24 | train |
argoproj/argo | cmd/argo/commands/delete.go | NewDeleteCommand | func NewDeleteCommand() *cobra.Command {
var (
all bool
completed bool
older string
)
var command = &cobra.Command{
Use: "delete WORKFLOW",
Short: "delete a workflow and its associated pods",
Run: func(cmd *cobra.Command, args []string) {
wfClient = InitWorkflowClient()
if all {
deleteWorkflows(metav1.ListOptions{}, nil)
} else if older != "" {
olderTime, err := argotime.ParseSince(older)
if err != nil {
log.Fatal(err)
}
deleteWorkflows(completedWorkflowListOption, olderTime)
} else if completed {
deleteWorkflows(completedWorkflowListOption, nil)
} else {
if len(args) == 0 {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
}
for _, wfName := range args {
deleteWorkflow(wfName)
}
}
},
}
command.Flags().BoolVar(&all, "all", false, "Delete all workflows")
command.Flags().BoolVar(&completed, "completed", false, "Delete completed workflows")
command.Flags().StringVar(&older, "older", "", "Delete completed workflows older than the specified duration (e.g. 10m, 3h, 1d)")
return command
} | go | func NewDeleteCommand() *cobra.Command {
var (
all bool
completed bool
older string
)
var command = &cobra.Command{
Use: "delete WORKFLOW",
Short: "delete a workflow and its associated pods",
Run: func(cmd *cobra.Command, args []string) {
wfClient = InitWorkflowClient()
if all {
deleteWorkflows(metav1.ListOptions{}, nil)
} else if older != "" {
olderTime, err := argotime.ParseSince(older)
if err != nil {
log.Fatal(err)
}
deleteWorkflows(completedWorkflowListOption, olderTime)
} else if completed {
deleteWorkflows(completedWorkflowListOption, nil)
} else {
if len(args) == 0 {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
}
for _, wfName := range args {
deleteWorkflow(wfName)
}
}
},
}
command.Flags().BoolVar(&all, "all", false, "Delete all workflows")
command.Flags().BoolVar(&completed, "completed", false, "Delete completed workflows")
command.Flags().StringVar(&older, "older", "", "Delete completed workflows older than the specified duration (e.g. 10m, 3h, 1d)")
return command
} | [
"func",
"NewDeleteCommand",
"(",
")",
"*",
"cobra",
".",
"Command",
"{",
"var",
"(",
"all",
"bool",
"\n",
"completed",
"bool",
"\n",
"older",
"string",
"\n",
")",
"\n\n",
"var",
"command",
"=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Run",
":",
"func",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"{",
"wfClient",
"=",
"InitWorkflowClient",
"(",
")",
"\n",
"if",
"all",
"{",
"deleteWorkflows",
"(",
"metav1",
".",
"ListOptions",
"{",
"}",
",",
"nil",
")",
"\n",
"}",
"else",
"if",
"older",
"!=",
"\"",
"\"",
"{",
"olderTime",
",",
"err",
":=",
"argotime",
".",
"ParseSince",
"(",
"older",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n",
"deleteWorkflows",
"(",
"completedWorkflowListOption",
",",
"olderTime",
")",
"\n",
"}",
"else",
"if",
"completed",
"{",
"deleteWorkflows",
"(",
"completedWorkflowListOption",
",",
"nil",
")",
"\n",
"}",
"else",
"{",
"if",
"len",
"(",
"args",
")",
"==",
"0",
"{",
"cmd",
".",
"HelpFunc",
"(",
")",
"(",
"cmd",
",",
"args",
")",
"\n",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"wfName",
":=",
"range",
"args",
"{",
"deleteWorkflow",
"(",
"wfName",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
",",
"}",
"\n\n",
"command",
".",
"Flags",
"(",
")",
".",
"BoolVar",
"(",
"&",
"all",
",",
"\"",
"\"",
",",
"false",
",",
"\"",
"\"",
")",
"\n",
"command",
".",
"Flags",
"(",
")",
".",
"BoolVar",
"(",
"&",
"completed",
",",
"\"",
"\"",
",",
"false",
",",
"\"",
"\"",
")",
"\n",
"command",
".",
"Flags",
"(",
")",
".",
"StringVar",
"(",
"&",
"older",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"return",
"command",
"\n",
"}"
] | // NewDeleteCommand returns a new instance of an `argo delete` command | [
"NewDeleteCommand",
"returns",
"a",
"new",
"instance",
"of",
"an",
"argo",
"delete",
"command"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/cmd/argo/commands/delete.go#L23-L61 | train |
argoproj/argo | pkg/client/clientset/versioned/fake/clientset_generated.go | ArgoprojV1alpha1 | func (c *Clientset) ArgoprojV1alpha1() argoprojv1alpha1.ArgoprojV1alpha1Interface {
return &fakeargoprojv1alpha1.FakeArgoprojV1alpha1{Fake: &c.Fake}
} | go | func (c *Clientset) ArgoprojV1alpha1() argoprojv1alpha1.ArgoprojV1alpha1Interface {
return &fakeargoprojv1alpha1.FakeArgoprojV1alpha1{Fake: &c.Fake}
} | [
"func",
"(",
"c",
"*",
"Clientset",
")",
"ArgoprojV1alpha1",
"(",
")",
"argoprojv1alpha1",
".",
"ArgoprojV1alpha1Interface",
"{",
"return",
"&",
"fakeargoprojv1alpha1",
".",
"FakeArgoprojV1alpha1",
"{",
"Fake",
":",
"&",
"c",
".",
"Fake",
"}",
"\n",
"}"
] | // ArgoprojV1alpha1 retrieves the ArgoprojV1alpha1Client | [
"ArgoprojV1alpha1",
"retrieves",
"the",
"ArgoprojV1alpha1Client"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/client/clientset/versioned/fake/clientset_generated.go#L59-L61 | train |
argoproj/argo | pkg/client/clientset/versioned/fake/clientset_generated.go | Argoproj | func (c *Clientset) Argoproj() argoprojv1alpha1.ArgoprojV1alpha1Interface {
return &fakeargoprojv1alpha1.FakeArgoprojV1alpha1{Fake: &c.Fake}
} | go | func (c *Clientset) Argoproj() argoprojv1alpha1.ArgoprojV1alpha1Interface {
return &fakeargoprojv1alpha1.FakeArgoprojV1alpha1{Fake: &c.Fake}
} | [
"func",
"(",
"c",
"*",
"Clientset",
")",
"Argoproj",
"(",
")",
"argoprojv1alpha1",
".",
"ArgoprojV1alpha1Interface",
"{",
"return",
"&",
"fakeargoprojv1alpha1",
".",
"FakeArgoprojV1alpha1",
"{",
"Fake",
":",
"&",
"c",
".",
"Fake",
"}",
"\n",
"}"
] | // Argoproj retrieves the ArgoprojV1alpha1Client | [
"Argoproj",
"retrieves",
"the",
"ArgoprojV1alpha1Client"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/client/clientset/versioned/fake/clientset_generated.go#L64-L66 | train |
argoproj/argo | workflow/controller/dag.go | taskNodeName | func (d *dagContext) taskNodeName(taskName string) string {
return fmt.Sprintf("%s.%s", d.boundaryName, taskName)
} | go | func (d *dagContext) taskNodeName(taskName string) string {
return fmt.Sprintf("%s.%s", d.boundaryName, taskName)
} | [
"func",
"(",
"d",
"*",
"dagContext",
")",
"taskNodeName",
"(",
"taskName",
"string",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"d",
".",
"boundaryName",
",",
"taskName",
")",
"\n",
"}"
] | // taskNodeName formulates the nodeName for a dag task | [
"taskNodeName",
"formulates",
"the",
"nodeName",
"for",
"a",
"dag",
"task"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/dag.go#L45-L47 | train |
argoproj/argo | workflow/controller/dag.go | taskNodeID | func (d *dagContext) taskNodeID(taskName string) string {
nodeName := d.taskNodeName(taskName)
return d.wf.NodeID(nodeName)
} | go | func (d *dagContext) taskNodeID(taskName string) string {
nodeName := d.taskNodeName(taskName)
return d.wf.NodeID(nodeName)
} | [
"func",
"(",
"d",
"*",
"dagContext",
")",
"taskNodeID",
"(",
"taskName",
"string",
")",
"string",
"{",
"nodeName",
":=",
"d",
".",
"taskNodeName",
"(",
"taskName",
")",
"\n",
"return",
"d",
".",
"wf",
".",
"NodeID",
"(",
"nodeName",
")",
"\n",
"}"
] | // taskNodeID formulates the node ID for a dag task | [
"taskNodeID",
"formulates",
"the",
"node",
"ID",
"for",
"a",
"dag",
"task"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/dag.go#L50-L53 | train |
argoproj/argo | workflow/controller/dag.go | assessDAGPhase | func (d *dagContext) assessDAGPhase(targetTasks []string, nodes map[string]wfv1.NodeStatus) wfv1.NodePhase {
// First check all our nodes to see if anything is still running. If so, then the DAG is
// considered still running (even if there are failures). Remember any failures and if retry
// nodes have been exhausted.
var unsuccessfulPhase wfv1.NodePhase
retriesExhausted := true
for _, node := range nodes {
if node.BoundaryID != d.boundaryID {
continue
}
if !node.Completed() {
return wfv1.NodeRunning
}
if !node.Successful() && unsuccessfulPhase == "" {
unsuccessfulPhase = node.Phase
}
if node.Type == wfv1.NodeTypeRetry {
if node.Successful() {
retriesExhausted = false
} else if hasMoreRetries(&node, d.wf) {
retriesExhausted = false
}
}
}
if unsuccessfulPhase != "" {
// if we were unsuccessful, we can return *only* if all retry nodes have ben exhausted.
if retriesExhausted {
return unsuccessfulPhase
}
}
// There are no currently running tasks. Now check if our dependencies were met
for _, depName := range targetTasks {
depNode := d.getTaskNode(depName)
if depNode == nil {
return wfv1.NodeRunning
}
if !depNode.Successful() {
// we should theoretically never get here since it would have been caught in first loop
return depNode.Phase
}
}
// If we get here, all our dependencies were completed and successful
return wfv1.NodeSucceeded
} | go | func (d *dagContext) assessDAGPhase(targetTasks []string, nodes map[string]wfv1.NodeStatus) wfv1.NodePhase {
// First check all our nodes to see if anything is still running. If so, then the DAG is
// considered still running (even if there are failures). Remember any failures and if retry
// nodes have been exhausted.
var unsuccessfulPhase wfv1.NodePhase
retriesExhausted := true
for _, node := range nodes {
if node.BoundaryID != d.boundaryID {
continue
}
if !node.Completed() {
return wfv1.NodeRunning
}
if !node.Successful() && unsuccessfulPhase == "" {
unsuccessfulPhase = node.Phase
}
if node.Type == wfv1.NodeTypeRetry {
if node.Successful() {
retriesExhausted = false
} else if hasMoreRetries(&node, d.wf) {
retriesExhausted = false
}
}
}
if unsuccessfulPhase != "" {
// if we were unsuccessful, we can return *only* if all retry nodes have ben exhausted.
if retriesExhausted {
return unsuccessfulPhase
}
}
// There are no currently running tasks. Now check if our dependencies were met
for _, depName := range targetTasks {
depNode := d.getTaskNode(depName)
if depNode == nil {
return wfv1.NodeRunning
}
if !depNode.Successful() {
// we should theoretically never get here since it would have been caught in first loop
return depNode.Phase
}
}
// If we get here, all our dependencies were completed and successful
return wfv1.NodeSucceeded
} | [
"func",
"(",
"d",
"*",
"dagContext",
")",
"assessDAGPhase",
"(",
"targetTasks",
"[",
"]",
"string",
",",
"nodes",
"map",
"[",
"string",
"]",
"wfv1",
".",
"NodeStatus",
")",
"wfv1",
".",
"NodePhase",
"{",
"// First check all our nodes to see if anything is still running. If so, then the DAG is",
"// considered still running (even if there are failures). Remember any failures and if retry",
"// nodes have been exhausted.",
"var",
"unsuccessfulPhase",
"wfv1",
".",
"NodePhase",
"\n",
"retriesExhausted",
":=",
"true",
"\n",
"for",
"_",
",",
"node",
":=",
"range",
"nodes",
"{",
"if",
"node",
".",
"BoundaryID",
"!=",
"d",
".",
"boundaryID",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"!",
"node",
".",
"Completed",
"(",
")",
"{",
"return",
"wfv1",
".",
"NodeRunning",
"\n",
"}",
"\n",
"if",
"!",
"node",
".",
"Successful",
"(",
")",
"&&",
"unsuccessfulPhase",
"==",
"\"",
"\"",
"{",
"unsuccessfulPhase",
"=",
"node",
".",
"Phase",
"\n",
"}",
"\n",
"if",
"node",
".",
"Type",
"==",
"wfv1",
".",
"NodeTypeRetry",
"{",
"if",
"node",
".",
"Successful",
"(",
")",
"{",
"retriesExhausted",
"=",
"false",
"\n",
"}",
"else",
"if",
"hasMoreRetries",
"(",
"&",
"node",
",",
"d",
".",
"wf",
")",
"{",
"retriesExhausted",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"unsuccessfulPhase",
"!=",
"\"",
"\"",
"{",
"// if we were unsuccessful, we can return *only* if all retry nodes have ben exhausted.",
"if",
"retriesExhausted",
"{",
"return",
"unsuccessfulPhase",
"\n",
"}",
"\n",
"}",
"\n",
"// There are no currently running tasks. Now check if our dependencies were met",
"for",
"_",
",",
"depName",
":=",
"range",
"targetTasks",
"{",
"depNode",
":=",
"d",
".",
"getTaskNode",
"(",
"depName",
")",
"\n",
"if",
"depNode",
"==",
"nil",
"{",
"return",
"wfv1",
".",
"NodeRunning",
"\n",
"}",
"\n",
"if",
"!",
"depNode",
".",
"Successful",
"(",
")",
"{",
"// we should theoretically never get here since it would have been caught in first loop",
"return",
"depNode",
".",
"Phase",
"\n",
"}",
"\n",
"}",
"\n",
"// If we get here, all our dependencies were completed and successful",
"return",
"wfv1",
".",
"NodeSucceeded",
"\n",
"}"
] | // assessDAGPhase assesses the overall DAG status | [
"assessDAGPhase",
"assesses",
"the",
"overall",
"DAG",
"status"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/dag.go#L65-L108 | train |
argoproj/argo | workflow/controller/dag.go | findLeafTaskNames | func findLeafTaskNames(tasks []wfv1.DAGTask) []string {
taskIsLeaf := make(map[string]bool)
for _, task := range tasks {
if _, ok := taskIsLeaf[task.Name]; !ok {
taskIsLeaf[task.Name] = true
}
for _, dependency := range task.Dependencies {
taskIsLeaf[dependency] = false
}
}
leafTaskNames := make([]string, 0)
for taskName, isLeaf := range taskIsLeaf {
if isLeaf {
leafTaskNames = append(leafTaskNames, taskName)
}
}
return leafTaskNames
} | go | func findLeafTaskNames(tasks []wfv1.DAGTask) []string {
taskIsLeaf := make(map[string]bool)
for _, task := range tasks {
if _, ok := taskIsLeaf[task.Name]; !ok {
taskIsLeaf[task.Name] = true
}
for _, dependency := range task.Dependencies {
taskIsLeaf[dependency] = false
}
}
leafTaskNames := make([]string, 0)
for taskName, isLeaf := range taskIsLeaf {
if isLeaf {
leafTaskNames = append(leafTaskNames, taskName)
}
}
return leafTaskNames
} | [
"func",
"findLeafTaskNames",
"(",
"tasks",
"[",
"]",
"wfv1",
".",
"DAGTask",
")",
"[",
"]",
"string",
"{",
"taskIsLeaf",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"task",
":=",
"range",
"tasks",
"{",
"if",
"_",
",",
"ok",
":=",
"taskIsLeaf",
"[",
"task",
".",
"Name",
"]",
";",
"!",
"ok",
"{",
"taskIsLeaf",
"[",
"task",
".",
"Name",
"]",
"=",
"true",
"\n",
"}",
"\n",
"for",
"_",
",",
"dependency",
":=",
"range",
"task",
".",
"Dependencies",
"{",
"taskIsLeaf",
"[",
"dependency",
"]",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"leafTaskNames",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"for",
"taskName",
",",
"isLeaf",
":=",
"range",
"taskIsLeaf",
"{",
"if",
"isLeaf",
"{",
"leafTaskNames",
"=",
"append",
"(",
"leafTaskNames",
",",
"taskName",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"leafTaskNames",
"\n",
"}"
] | // findLeafTaskNames finds the names of all tasks whom no other nodes depend on.
// This list of tasks is used as the the default list of targets when dag.targets is omitted. | [
"findLeafTaskNames",
"finds",
"the",
"names",
"of",
"all",
"tasks",
"whom",
"no",
"other",
"nodes",
"depend",
"on",
".",
"This",
"list",
"of",
"tasks",
"is",
"used",
"as",
"the",
"the",
"default",
"list",
"of",
"targets",
"when",
"dag",
".",
"targets",
"is",
"omitted",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/dag.go#L422-L439 | train |
argoproj/argo | workflow/controller/dag.go | expandTask | func (woc *wfOperationCtx) expandTask(task wfv1.DAGTask) ([]wfv1.DAGTask, error) {
taskBytes, err := json.Marshal(task)
if err != nil {
return nil, errors.InternalWrapError(err)
}
var items []wfv1.Item
if len(task.WithItems) > 0 {
items = task.WithItems
} else if task.WithParam != "" {
err = json.Unmarshal([]byte(task.WithParam), &items)
if err != nil {
return nil, errors.Errorf(errors.CodeBadRequest, "withParam value could not be parsed as a JSON list: %s", strings.TrimSpace(task.WithParam))
}
} else if task.WithSequence != nil {
items, err = expandSequence(task.WithSequence)
if err != nil {
return nil, err
}
} else {
return []wfv1.DAGTask{task}, nil
}
fstTmpl := fasttemplate.New(string(taskBytes), "{{", "}}")
expandedTasks := make([]wfv1.DAGTask, 0)
for i, item := range items {
var newTask wfv1.DAGTask
newTaskName, err := processItem(fstTmpl, task.Name, i, item, &newTask)
if err != nil {
return nil, err
}
newTask.Name = newTaskName
newTask.Template = task.Template
expandedTasks = append(expandedTasks, newTask)
}
return expandedTasks, nil
} | go | func (woc *wfOperationCtx) expandTask(task wfv1.DAGTask) ([]wfv1.DAGTask, error) {
taskBytes, err := json.Marshal(task)
if err != nil {
return nil, errors.InternalWrapError(err)
}
var items []wfv1.Item
if len(task.WithItems) > 0 {
items = task.WithItems
} else if task.WithParam != "" {
err = json.Unmarshal([]byte(task.WithParam), &items)
if err != nil {
return nil, errors.Errorf(errors.CodeBadRequest, "withParam value could not be parsed as a JSON list: %s", strings.TrimSpace(task.WithParam))
}
} else if task.WithSequence != nil {
items, err = expandSequence(task.WithSequence)
if err != nil {
return nil, err
}
} else {
return []wfv1.DAGTask{task}, nil
}
fstTmpl := fasttemplate.New(string(taskBytes), "{{", "}}")
expandedTasks := make([]wfv1.DAGTask, 0)
for i, item := range items {
var newTask wfv1.DAGTask
newTaskName, err := processItem(fstTmpl, task.Name, i, item, &newTask)
if err != nil {
return nil, err
}
newTask.Name = newTaskName
newTask.Template = task.Template
expandedTasks = append(expandedTasks, newTask)
}
return expandedTasks, nil
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"expandTask",
"(",
"task",
"wfv1",
".",
"DAGTask",
")",
"(",
"[",
"]",
"wfv1",
".",
"DAGTask",
",",
"error",
")",
"{",
"taskBytes",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"task",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"InternalWrapError",
"(",
"err",
")",
"\n",
"}",
"\n",
"var",
"items",
"[",
"]",
"wfv1",
".",
"Item",
"\n",
"if",
"len",
"(",
"task",
".",
"WithItems",
")",
">",
"0",
"{",
"items",
"=",
"task",
".",
"WithItems",
"\n",
"}",
"else",
"if",
"task",
".",
"WithParam",
"!=",
"\"",
"\"",
"{",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"task",
".",
"WithParam",
")",
",",
"&",
"items",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"errors",
".",
"CodeBadRequest",
",",
"\"",
"\"",
",",
"strings",
".",
"TrimSpace",
"(",
"task",
".",
"WithParam",
")",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"task",
".",
"WithSequence",
"!=",
"nil",
"{",
"items",
",",
"err",
"=",
"expandSequence",
"(",
"task",
".",
"WithSequence",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"return",
"[",
"]",
"wfv1",
".",
"DAGTask",
"{",
"task",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"fstTmpl",
":=",
"fasttemplate",
".",
"New",
"(",
"string",
"(",
"taskBytes",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"expandedTasks",
":=",
"make",
"(",
"[",
"]",
"wfv1",
".",
"DAGTask",
",",
"0",
")",
"\n",
"for",
"i",
",",
"item",
":=",
"range",
"items",
"{",
"var",
"newTask",
"wfv1",
".",
"DAGTask",
"\n",
"newTaskName",
",",
"err",
":=",
"processItem",
"(",
"fstTmpl",
",",
"task",
".",
"Name",
",",
"i",
",",
"item",
",",
"&",
"newTask",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"newTask",
".",
"Name",
"=",
"newTaskName",
"\n",
"newTask",
".",
"Template",
"=",
"task",
".",
"Template",
"\n",
"expandedTasks",
"=",
"append",
"(",
"expandedTasks",
",",
"newTask",
")",
"\n",
"}",
"\n",
"return",
"expandedTasks",
",",
"nil",
"\n",
"}"
] | // expandTask expands a single DAG task containing withItems, withParams, withSequence into multiple parallel tasks | [
"expandTask",
"expands",
"a",
"single",
"DAG",
"task",
"containing",
"withItems",
"withParams",
"withSequence",
"into",
"multiple",
"parallel",
"tasks"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/dag.go#L442-L477 | train |
argoproj/argo | workflow/executor/kubelet/client.go | CreateArchive | func (k *kubeletClient) CreateArchive(containerID, sourcePath string) (*bytes.Buffer, error) {
return k.getCommandOutput(containerID, fmt.Sprintf("command=tar&command=-cf&command=-&command=%s&output=1", sourcePath))
} | go | func (k *kubeletClient) CreateArchive(containerID, sourcePath string) (*bytes.Buffer, error) {
return k.getCommandOutput(containerID, fmt.Sprintf("command=tar&command=-cf&command=-&command=%s&output=1", sourcePath))
} | [
"func",
"(",
"k",
"*",
"kubeletClient",
")",
"CreateArchive",
"(",
"containerID",
",",
"sourcePath",
"string",
")",
"(",
"*",
"bytes",
".",
"Buffer",
",",
"error",
")",
"{",
"return",
"k",
".",
"getCommandOutput",
"(",
"containerID",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sourcePath",
")",
")",
"\n",
"}"
] | // createArchive exec in the given containerID and create a tarball of the given sourcePath. Works with directory | [
"createArchive",
"exec",
"in",
"the",
"given",
"containerID",
"and",
"create",
"a",
"tarball",
"of",
"the",
"given",
"sourcePath",
".",
"Works",
"with",
"directory"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/executor/kubelet/client.go#L245-L247 | train |
argoproj/argo | pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflow.go | Get | func (c *FakeWorkflows) Get(name string, options v1.GetOptions) (result *v1alpha1.Workflow, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(workflowsResource, c.ns, name), &v1alpha1.Workflow{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Workflow), err
} | go | func (c *FakeWorkflows) Get(name string, options v1.GetOptions) (result *v1alpha1.Workflow, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(workflowsResource, c.ns, name), &v1alpha1.Workflow{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Workflow), err
} | [
"func",
"(",
"c",
"*",
"FakeWorkflows",
")",
"Get",
"(",
"name",
"string",
",",
"options",
"v1",
".",
"GetOptions",
")",
"(",
"result",
"*",
"v1alpha1",
".",
"Workflow",
",",
"err",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewGetAction",
"(",
"workflowsResource",
",",
"c",
".",
"ns",
",",
"name",
")",
",",
"&",
"v1alpha1",
".",
"Workflow",
"{",
"}",
")",
"\n\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"obj",
".",
"(",
"*",
"v1alpha1",
".",
"Workflow",
")",
",",
"err",
"\n",
"}"
] | // Get takes name of the workflow, and returns the corresponding workflow object, and an error if there is any. | [
"Get",
"takes",
"name",
"of",
"the",
"workflow",
"and",
"returns",
"the",
"corresponding",
"workflow",
"object",
"and",
"an",
"error",
"if",
"there",
"is",
"any",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflow.go#L26-L34 | train |
argoproj/argo | pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflow.go | List | func (c *FakeWorkflows) List(opts v1.ListOptions) (result *v1alpha1.WorkflowList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(workflowsResource, workflowsKind, c.ns, opts), &v1alpha1.WorkflowList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v1alpha1.WorkflowList{ListMeta: obj.(*v1alpha1.WorkflowList).ListMeta}
for _, item := range obj.(*v1alpha1.WorkflowList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
} | go | func (c *FakeWorkflows) List(opts v1.ListOptions) (result *v1alpha1.WorkflowList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(workflowsResource, workflowsKind, c.ns, opts), &v1alpha1.WorkflowList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v1alpha1.WorkflowList{ListMeta: obj.(*v1alpha1.WorkflowList).ListMeta}
for _, item := range obj.(*v1alpha1.WorkflowList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
} | [
"func",
"(",
"c",
"*",
"FakeWorkflows",
")",
"List",
"(",
"opts",
"v1",
".",
"ListOptions",
")",
"(",
"result",
"*",
"v1alpha1",
".",
"WorkflowList",
",",
"err",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewListAction",
"(",
"workflowsResource",
",",
"workflowsKind",
",",
"c",
".",
"ns",
",",
"opts",
")",
",",
"&",
"v1alpha1",
".",
"WorkflowList",
"{",
"}",
")",
"\n\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"label",
",",
"_",
",",
"_",
":=",
"testing",
".",
"ExtractFromListOptions",
"(",
"opts",
")",
"\n",
"if",
"label",
"==",
"nil",
"{",
"label",
"=",
"labels",
".",
"Everything",
"(",
")",
"\n",
"}",
"\n",
"list",
":=",
"&",
"v1alpha1",
".",
"WorkflowList",
"{",
"ListMeta",
":",
"obj",
".",
"(",
"*",
"v1alpha1",
".",
"WorkflowList",
")",
".",
"ListMeta",
"}",
"\n",
"for",
"_",
",",
"item",
":=",
"range",
"obj",
".",
"(",
"*",
"v1alpha1",
".",
"WorkflowList",
")",
".",
"Items",
"{",
"if",
"label",
".",
"Matches",
"(",
"labels",
".",
"Set",
"(",
"item",
".",
"Labels",
")",
")",
"{",
"list",
".",
"Items",
"=",
"append",
"(",
"list",
".",
"Items",
",",
"item",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"list",
",",
"err",
"\n",
"}"
] | // List takes label and field selectors, and returns the list of Workflows that match those selectors. | [
"List",
"takes",
"label",
"and",
"field",
"selectors",
"and",
"returns",
"the",
"list",
"of",
"Workflows",
"that",
"match",
"those",
"selectors",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflow.go#L37-L56 | train |
argoproj/argo | pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflow.go | Watch | func (c *FakeWorkflows) Watch(opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(workflowsResource, c.ns, opts))
} | go | func (c *FakeWorkflows) Watch(opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(workflowsResource, c.ns, opts))
} | [
"func",
"(",
"c",
"*",
"FakeWorkflows",
")",
"Watch",
"(",
"opts",
"v1",
".",
"ListOptions",
")",
"(",
"watch",
".",
"Interface",
",",
"error",
")",
"{",
"return",
"c",
".",
"Fake",
".",
"InvokesWatch",
"(",
"testing",
".",
"NewWatchAction",
"(",
"workflowsResource",
",",
"c",
".",
"ns",
",",
"opts",
")",
")",
"\n\n",
"}"
] | // Watch returns a watch.Interface that watches the requested workflows. | [
"Watch",
"returns",
"a",
"watch",
".",
"Interface",
"that",
"watches",
"the",
"requested",
"workflows",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflow.go#L59-L63 | train |
argoproj/argo | pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflow.go | Delete | func (c *FakeWorkflows) Delete(name string, options *v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteAction(workflowsResource, c.ns, name), &v1alpha1.Workflow{})
return err
} | go | func (c *FakeWorkflows) Delete(name string, options *v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteAction(workflowsResource, c.ns, name), &v1alpha1.Workflow{})
return err
} | [
"func",
"(",
"c",
"*",
"FakeWorkflows",
")",
"Delete",
"(",
"name",
"string",
",",
"options",
"*",
"v1",
".",
"DeleteOptions",
")",
"error",
"{",
"_",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewDeleteAction",
"(",
"workflowsResource",
",",
"c",
".",
"ns",
",",
"name",
")",
",",
"&",
"v1alpha1",
".",
"Workflow",
"{",
"}",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Delete takes name of the workflow and deletes it. Returns an error if one occurs. | [
"Delete",
"takes",
"name",
"of",
"the",
"workflow",
"and",
"deletes",
"it",
".",
"Returns",
"an",
"error",
"if",
"one",
"occurs",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflow.go#L88-L93 | train |
argoproj/argo | pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflow.go | Patch | func (c *FakeWorkflows) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Workflow, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(workflowsResource, c.ns, name, data, subresources...), &v1alpha1.Workflow{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Workflow), err
} | go | func (c *FakeWorkflows) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Workflow, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(workflowsResource, c.ns, name, data, subresources...), &v1alpha1.Workflow{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Workflow), err
} | [
"func",
"(",
"c",
"*",
"FakeWorkflows",
")",
"Patch",
"(",
"name",
"string",
",",
"pt",
"types",
".",
"PatchType",
",",
"data",
"[",
"]",
"byte",
",",
"subresources",
"...",
"string",
")",
"(",
"result",
"*",
"v1alpha1",
".",
"Workflow",
",",
"err",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewPatchSubresourceAction",
"(",
"workflowsResource",
",",
"c",
".",
"ns",
",",
"name",
",",
"data",
",",
"subresources",
"...",
")",
",",
"&",
"v1alpha1",
".",
"Workflow",
"{",
"}",
")",
"\n\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"obj",
".",
"(",
"*",
"v1alpha1",
".",
"Workflow",
")",
",",
"err",
"\n",
"}"
] | // Patch applies the patch and returns the patched workflow. | [
"Patch",
"applies",
"the",
"patch",
"and",
"returns",
"the",
"patched",
"workflow",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake/fake_workflow.go#L104-L112 | train |
argoproj/argo | workflow/artifacts/git/git.go | Load | func (g *GitArtifactDriver) Load(inputArtifact *wfv1.Artifact, path string) error {
if g.SSHPrivateKey != "" {
signer, err := ssh.ParsePrivateKey([]byte(g.SSHPrivateKey))
if err != nil {
return errors.InternalWrapError(err)
}
auth := &ssh2.PublicKeys{User: "git", Signer: signer}
if g.InsecureIgnoreHostKey {
auth.HostKeyCallback = ssh.InsecureIgnoreHostKey()
}
return gitClone(path, inputArtifact, auth, g.SSHPrivateKey)
}
if g.Username != "" || g.Password != "" {
auth := &http.BasicAuth{Username: g.Username, Password: g.Password}
return gitClone(path, inputArtifact, auth, "")
}
return gitClone(path, inputArtifact, nil, "")
} | go | func (g *GitArtifactDriver) Load(inputArtifact *wfv1.Artifact, path string) error {
if g.SSHPrivateKey != "" {
signer, err := ssh.ParsePrivateKey([]byte(g.SSHPrivateKey))
if err != nil {
return errors.InternalWrapError(err)
}
auth := &ssh2.PublicKeys{User: "git", Signer: signer}
if g.InsecureIgnoreHostKey {
auth.HostKeyCallback = ssh.InsecureIgnoreHostKey()
}
return gitClone(path, inputArtifact, auth, g.SSHPrivateKey)
}
if g.Username != "" || g.Password != "" {
auth := &http.BasicAuth{Username: g.Username, Password: g.Password}
return gitClone(path, inputArtifact, auth, "")
}
return gitClone(path, inputArtifact, nil, "")
} | [
"func",
"(",
"g",
"*",
"GitArtifactDriver",
")",
"Load",
"(",
"inputArtifact",
"*",
"wfv1",
".",
"Artifact",
",",
"path",
"string",
")",
"error",
"{",
"if",
"g",
".",
"SSHPrivateKey",
"!=",
"\"",
"\"",
"{",
"signer",
",",
"err",
":=",
"ssh",
".",
"ParsePrivateKey",
"(",
"[",
"]",
"byte",
"(",
"g",
".",
"SSHPrivateKey",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"InternalWrapError",
"(",
"err",
")",
"\n",
"}",
"\n",
"auth",
":=",
"&",
"ssh2",
".",
"PublicKeys",
"{",
"User",
":",
"\"",
"\"",
",",
"Signer",
":",
"signer",
"}",
"\n",
"if",
"g",
".",
"InsecureIgnoreHostKey",
"{",
"auth",
".",
"HostKeyCallback",
"=",
"ssh",
".",
"InsecureIgnoreHostKey",
"(",
")",
"\n",
"}",
"\n",
"return",
"gitClone",
"(",
"path",
",",
"inputArtifact",
",",
"auth",
",",
"g",
".",
"SSHPrivateKey",
")",
"\n",
"}",
"\n",
"if",
"g",
".",
"Username",
"!=",
"\"",
"\"",
"||",
"g",
".",
"Password",
"!=",
"\"",
"\"",
"{",
"auth",
":=",
"&",
"http",
".",
"BasicAuth",
"{",
"Username",
":",
"g",
".",
"Username",
",",
"Password",
":",
"g",
".",
"Password",
"}",
"\n",
"return",
"gitClone",
"(",
"path",
",",
"inputArtifact",
",",
"auth",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"gitClone",
"(",
"path",
",",
"inputArtifact",
",",
"nil",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Load download artifacts from an git URL | [
"Load",
"download",
"artifacts",
"from",
"an",
"git",
"URL"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/artifacts/git/git.go#L31-L48 | train |
argoproj/argo | workflow/artifacts/git/git.go | Save | func (g *GitArtifactDriver) Save(path string, outputArtifact *wfv1.Artifact) error {
return errors.Errorf(errors.CodeBadRequest, "Git output artifacts unsupported")
} | go | func (g *GitArtifactDriver) Save(path string, outputArtifact *wfv1.Artifact) error {
return errors.Errorf(errors.CodeBadRequest, "Git output artifacts unsupported")
} | [
"func",
"(",
"g",
"*",
"GitArtifactDriver",
")",
"Save",
"(",
"path",
"string",
",",
"outputArtifact",
"*",
"wfv1",
".",
"Artifact",
")",
"error",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"errors",
".",
"CodeBadRequest",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Save is unsupported for git output artifacts | [
"Save",
"is",
"unsupported",
"for",
"git",
"output",
"artifacts"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/artifacts/git/git.go#L51-L53 | train |
argoproj/argo | cmd/argo/commands/list.go | parameterString | func parameterString(params []wfv1.Parameter) string {
truncateString := func(str string, num int) string {
bnoden := str
if len(str) > num {
if num > 3 {
num -= 3
}
bnoden = str[0:num-15] + "..." + str[len(str)-15:]
}
return bnoden
}
pStrs := make([]string, 0)
for _, p := range params {
if p.Value != nil {
str := fmt.Sprintf("%s=%s", p.Name, truncateString(*p.Value, 50))
pStrs = append(pStrs, str)
}
}
return strings.Join(pStrs, ",")
} | go | func parameterString(params []wfv1.Parameter) string {
truncateString := func(str string, num int) string {
bnoden := str
if len(str) > num {
if num > 3 {
num -= 3
}
bnoden = str[0:num-15] + "..." + str[len(str)-15:]
}
return bnoden
}
pStrs := make([]string, 0)
for _, p := range params {
if p.Value != nil {
str := fmt.Sprintf("%s=%s", p.Name, truncateString(*p.Value, 50))
pStrs = append(pStrs, str)
}
}
return strings.Join(pStrs, ",")
} | [
"func",
"parameterString",
"(",
"params",
"[",
"]",
"wfv1",
".",
"Parameter",
")",
"string",
"{",
"truncateString",
":=",
"func",
"(",
"str",
"string",
",",
"num",
"int",
")",
"string",
"{",
"bnoden",
":=",
"str",
"\n",
"if",
"len",
"(",
"str",
")",
">",
"num",
"{",
"if",
"num",
">",
"3",
"{",
"num",
"-=",
"3",
"\n",
"}",
"\n",
"bnoden",
"=",
"str",
"[",
"0",
":",
"num",
"-",
"15",
"]",
"+",
"\"",
"\"",
"+",
"str",
"[",
"len",
"(",
"str",
")",
"-",
"15",
":",
"]",
"\n",
"}",
"\n",
"return",
"bnoden",
"\n",
"}",
"\n\n",
"pStrs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"params",
"{",
"if",
"p",
".",
"Value",
"!=",
"nil",
"{",
"str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"Name",
",",
"truncateString",
"(",
"*",
"p",
".",
"Value",
",",
"50",
")",
")",
"\n",
"pStrs",
"=",
"append",
"(",
"pStrs",
",",
"str",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"pStrs",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // parameterString returns a human readable display string of the parameters, truncating if necessary | [
"parameterString",
"returns",
"a",
"human",
"readable",
"display",
"string",
"of",
"the",
"parameters",
"truncating",
"if",
"necessary"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/cmd/argo/commands/list.go#L162-L182 | train |
argoproj/argo | cmd/argo/commands/list.go | workflowStatus | func workflowStatus(wf *wfv1.Workflow) wfv1.NodePhase {
switch wf.Status.Phase {
case wfv1.NodeRunning:
if util.IsWorkflowSuspended(wf) {
return "Running (Suspended)"
}
return wf.Status.Phase
case wfv1.NodeFailed:
if util.IsWorkflowTerminated(wf) {
return "Failed (Terminated)"
}
return wf.Status.Phase
case "", wfv1.NodePending:
if !wf.ObjectMeta.CreationTimestamp.IsZero() {
return wfv1.NodePending
}
return "Unknown"
default:
return wf.Status.Phase
}
} | go | func workflowStatus(wf *wfv1.Workflow) wfv1.NodePhase {
switch wf.Status.Phase {
case wfv1.NodeRunning:
if util.IsWorkflowSuspended(wf) {
return "Running (Suspended)"
}
return wf.Status.Phase
case wfv1.NodeFailed:
if util.IsWorkflowTerminated(wf) {
return "Failed (Terminated)"
}
return wf.Status.Phase
case "", wfv1.NodePending:
if !wf.ObjectMeta.CreationTimestamp.IsZero() {
return wfv1.NodePending
}
return "Unknown"
default:
return wf.Status.Phase
}
} | [
"func",
"workflowStatus",
"(",
"wf",
"*",
"wfv1",
".",
"Workflow",
")",
"wfv1",
".",
"NodePhase",
"{",
"switch",
"wf",
".",
"Status",
".",
"Phase",
"{",
"case",
"wfv1",
".",
"NodeRunning",
":",
"if",
"util",
".",
"IsWorkflowSuspended",
"(",
"wf",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"wf",
".",
"Status",
".",
"Phase",
"\n",
"case",
"wfv1",
".",
"NodeFailed",
":",
"if",
"util",
".",
"IsWorkflowTerminated",
"(",
"wf",
")",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"wf",
".",
"Status",
".",
"Phase",
"\n",
"case",
"\"",
"\"",
",",
"wfv1",
".",
"NodePending",
":",
"if",
"!",
"wf",
".",
"ObjectMeta",
".",
"CreationTimestamp",
".",
"IsZero",
"(",
")",
"{",
"return",
"wfv1",
".",
"NodePending",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"default",
":",
"return",
"wf",
".",
"Status",
".",
"Phase",
"\n",
"}",
"\n",
"}"
] | // workflowStatus returns a human readable inferred workflow status based on workflow phase and conditions | [
"workflowStatus",
"returns",
"a",
"human",
"readable",
"inferred",
"workflow",
"status",
"based",
"on",
"workflow",
"phase",
"and",
"conditions"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/cmd/argo/commands/list.go#L207-L227 | train |
argoproj/argo | workflow/controller/exec_control.go | applyExecutionControl | func (woc *wfOperationCtx) applyExecutionControl(pod *apiv1.Pod, wfNodesLock *sync.RWMutex) error {
if pod == nil {
return nil
}
switch pod.Status.Phase {
case apiv1.PodSucceeded, apiv1.PodFailed:
// Skip any pod which are already completed
return nil
case apiv1.PodPending:
// Check if we are past the workflow deadline. If we are, and the pod is still pending
// then we should simply delete it and mark the pod as Failed
if woc.workflowDeadline != nil && time.Now().UTC().After(*woc.workflowDeadline) {
woc.log.Infof("Deleting Pending pod %s/%s which has exceeded workflow deadline %s", pod.Namespace, pod.Name, woc.workflowDeadline)
err := woc.controller.kubeclientset.CoreV1().Pods(pod.Namespace).Delete(pod.Name, &metav1.DeleteOptions{})
if err == nil {
wfNodesLock.Lock()
defer wfNodesLock.Unlock()
node := woc.wf.Status.Nodes[pod.Name]
var message string
if woc.workflowDeadline.IsZero() {
message = "terminated"
} else {
message = fmt.Sprintf("step exceeded workflow deadline %s", *woc.workflowDeadline)
}
woc.markNodePhase(node.Name, wfv1.NodeFailed, message)
return nil
}
// If we fail to delete the pod, fall back to setting the annotation
woc.log.Warnf("Failed to delete %s/%s: %v", pod.Namespace, pod.Name, err)
}
}
// Now ensure the pod's current annotation matches our desired deadline
desiredExecCtl := common.ExecutionControl{
Deadline: woc.workflowDeadline,
}
var podExecCtl common.ExecutionControl
if execCtlStr, ok := pod.Annotations[common.AnnotationKeyExecutionControl]; ok && execCtlStr != "" {
err := json.Unmarshal([]byte(execCtlStr), &podExecCtl)
if err != nil {
woc.log.Warnf("Failed to unmarshal execution control from pod %s", pod.Name)
}
}
if podExecCtl.Deadline == nil && desiredExecCtl.Deadline == nil {
return nil
} else if podExecCtl.Deadline != nil && desiredExecCtl.Deadline != nil {
if podExecCtl.Deadline.Equal(*desiredExecCtl.Deadline) {
return nil
}
}
if podExecCtl.Deadline != nil && podExecCtl.Deadline.IsZero() {
// If the pod has already been explicitly signaled to terminate, then do nothing.
// This can happen when daemon steps are terminated.
woc.log.Infof("Skipping sync of execution control of pod %s. pod has been signaled to terminate", pod.Name)
return nil
}
woc.log.Infof("Execution control for pod %s out-of-sync desired: %v, actual: %v", pod.Name, desiredExecCtl.Deadline, podExecCtl.Deadline)
return woc.updateExecutionControl(pod.Name, desiredExecCtl)
} | go | func (woc *wfOperationCtx) applyExecutionControl(pod *apiv1.Pod, wfNodesLock *sync.RWMutex) error {
if pod == nil {
return nil
}
switch pod.Status.Phase {
case apiv1.PodSucceeded, apiv1.PodFailed:
// Skip any pod which are already completed
return nil
case apiv1.PodPending:
// Check if we are past the workflow deadline. If we are, and the pod is still pending
// then we should simply delete it and mark the pod as Failed
if woc.workflowDeadline != nil && time.Now().UTC().After(*woc.workflowDeadline) {
woc.log.Infof("Deleting Pending pod %s/%s which has exceeded workflow deadline %s", pod.Namespace, pod.Name, woc.workflowDeadline)
err := woc.controller.kubeclientset.CoreV1().Pods(pod.Namespace).Delete(pod.Name, &metav1.DeleteOptions{})
if err == nil {
wfNodesLock.Lock()
defer wfNodesLock.Unlock()
node := woc.wf.Status.Nodes[pod.Name]
var message string
if woc.workflowDeadline.IsZero() {
message = "terminated"
} else {
message = fmt.Sprintf("step exceeded workflow deadline %s", *woc.workflowDeadline)
}
woc.markNodePhase(node.Name, wfv1.NodeFailed, message)
return nil
}
// If we fail to delete the pod, fall back to setting the annotation
woc.log.Warnf("Failed to delete %s/%s: %v", pod.Namespace, pod.Name, err)
}
}
// Now ensure the pod's current annotation matches our desired deadline
desiredExecCtl := common.ExecutionControl{
Deadline: woc.workflowDeadline,
}
var podExecCtl common.ExecutionControl
if execCtlStr, ok := pod.Annotations[common.AnnotationKeyExecutionControl]; ok && execCtlStr != "" {
err := json.Unmarshal([]byte(execCtlStr), &podExecCtl)
if err != nil {
woc.log.Warnf("Failed to unmarshal execution control from pod %s", pod.Name)
}
}
if podExecCtl.Deadline == nil && desiredExecCtl.Deadline == nil {
return nil
} else if podExecCtl.Deadline != nil && desiredExecCtl.Deadline != nil {
if podExecCtl.Deadline.Equal(*desiredExecCtl.Deadline) {
return nil
}
}
if podExecCtl.Deadline != nil && podExecCtl.Deadline.IsZero() {
// If the pod has already been explicitly signaled to terminate, then do nothing.
// This can happen when daemon steps are terminated.
woc.log.Infof("Skipping sync of execution control of pod %s. pod has been signaled to terminate", pod.Name)
return nil
}
woc.log.Infof("Execution control for pod %s out-of-sync desired: %v, actual: %v", pod.Name, desiredExecCtl.Deadline, podExecCtl.Deadline)
return woc.updateExecutionControl(pod.Name, desiredExecCtl)
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"applyExecutionControl",
"(",
"pod",
"*",
"apiv1",
".",
"Pod",
",",
"wfNodesLock",
"*",
"sync",
".",
"RWMutex",
")",
"error",
"{",
"if",
"pod",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"switch",
"pod",
".",
"Status",
".",
"Phase",
"{",
"case",
"apiv1",
".",
"PodSucceeded",
",",
"apiv1",
".",
"PodFailed",
":",
"// Skip any pod which are already completed",
"return",
"nil",
"\n",
"case",
"apiv1",
".",
"PodPending",
":",
"// Check if we are past the workflow deadline. If we are, and the pod is still pending",
"// then we should simply delete it and mark the pod as Failed",
"if",
"woc",
".",
"workflowDeadline",
"!=",
"nil",
"&&",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
".",
"After",
"(",
"*",
"woc",
".",
"workflowDeadline",
")",
"{",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"pod",
".",
"Namespace",
",",
"pod",
".",
"Name",
",",
"woc",
".",
"workflowDeadline",
")",
"\n",
"err",
":=",
"woc",
".",
"controller",
".",
"kubeclientset",
".",
"CoreV1",
"(",
")",
".",
"Pods",
"(",
"pod",
".",
"Namespace",
")",
".",
"Delete",
"(",
"pod",
".",
"Name",
",",
"&",
"metav1",
".",
"DeleteOptions",
"{",
"}",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"wfNodesLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"wfNodesLock",
".",
"Unlock",
"(",
")",
"\n",
"node",
":=",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"[",
"pod",
".",
"Name",
"]",
"\n",
"var",
"message",
"string",
"\n",
"if",
"woc",
".",
"workflowDeadline",
".",
"IsZero",
"(",
")",
"{",
"message",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"message",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"*",
"woc",
".",
"workflowDeadline",
")",
"\n",
"}",
"\n",
"woc",
".",
"markNodePhase",
"(",
"node",
".",
"Name",
",",
"wfv1",
".",
"NodeFailed",
",",
"message",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"// If we fail to delete the pod, fall back to setting the annotation",
"woc",
".",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"pod",
".",
"Namespace",
",",
"pod",
".",
"Name",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Now ensure the pod's current annotation matches our desired deadline",
"desiredExecCtl",
":=",
"common",
".",
"ExecutionControl",
"{",
"Deadline",
":",
"woc",
".",
"workflowDeadline",
",",
"}",
"\n",
"var",
"podExecCtl",
"common",
".",
"ExecutionControl",
"\n",
"if",
"execCtlStr",
",",
"ok",
":=",
"pod",
".",
"Annotations",
"[",
"common",
".",
"AnnotationKeyExecutionControl",
"]",
";",
"ok",
"&&",
"execCtlStr",
"!=",
"\"",
"\"",
"{",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"execCtlStr",
")",
",",
"&",
"podExecCtl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"woc",
".",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"pod",
".",
"Name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"podExecCtl",
".",
"Deadline",
"==",
"nil",
"&&",
"desiredExecCtl",
".",
"Deadline",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"else",
"if",
"podExecCtl",
".",
"Deadline",
"!=",
"nil",
"&&",
"desiredExecCtl",
".",
"Deadline",
"!=",
"nil",
"{",
"if",
"podExecCtl",
".",
"Deadline",
".",
"Equal",
"(",
"*",
"desiredExecCtl",
".",
"Deadline",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"podExecCtl",
".",
"Deadline",
"!=",
"nil",
"&&",
"podExecCtl",
".",
"Deadline",
".",
"IsZero",
"(",
")",
"{",
"// If the pod has already been explicitly signaled to terminate, then do nothing.",
"// This can happen when daemon steps are terminated.",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"pod",
".",
"Name",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"pod",
".",
"Name",
",",
"desiredExecCtl",
".",
"Deadline",
",",
"podExecCtl",
".",
"Deadline",
")",
"\n",
"return",
"woc",
".",
"updateExecutionControl",
"(",
"pod",
".",
"Name",
",",
"desiredExecCtl",
")",
"\n",
"}"
] | // applyExecutionControl will ensure a pod's execution control annotation is up-to-date
// kills any pending pods when workflow has reached it's deadline | [
"applyExecutionControl",
"will",
"ensure",
"a",
"pod",
"s",
"execution",
"control",
"annotation",
"is",
"up",
"-",
"to",
"-",
"date",
"kills",
"any",
"pending",
"pods",
"when",
"workflow",
"has",
"reached",
"it",
"s",
"deadline"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/exec_control.go#L19-L77 | train |
argoproj/argo | workflow/controller/exec_control.go | killDaemonedChildren | func (woc *wfOperationCtx) killDaemonedChildren(nodeID string) error {
woc.log.Infof("Checking daemoned children of %s", nodeID)
var firstErr error
execCtl := common.ExecutionControl{
Deadline: &time.Time{},
}
for _, childNode := range woc.wf.Status.Nodes {
if childNode.BoundaryID != nodeID {
continue
}
if childNode.Daemoned == nil || !*childNode.Daemoned {
continue
}
err := woc.updateExecutionControl(childNode.ID, execCtl)
if err != nil {
woc.log.Errorf("Failed to update execution control of node %s: %+v", childNode.ID, err)
if firstErr == nil {
firstErr = err
}
}
}
return firstErr
} | go | func (woc *wfOperationCtx) killDaemonedChildren(nodeID string) error {
woc.log.Infof("Checking daemoned children of %s", nodeID)
var firstErr error
execCtl := common.ExecutionControl{
Deadline: &time.Time{},
}
for _, childNode := range woc.wf.Status.Nodes {
if childNode.BoundaryID != nodeID {
continue
}
if childNode.Daemoned == nil || !*childNode.Daemoned {
continue
}
err := woc.updateExecutionControl(childNode.ID, execCtl)
if err != nil {
woc.log.Errorf("Failed to update execution control of node %s: %+v", childNode.ID, err)
if firstErr == nil {
firstErr = err
}
}
}
return firstErr
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"killDaemonedChildren",
"(",
"nodeID",
"string",
")",
"error",
"{",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"nodeID",
")",
"\n",
"var",
"firstErr",
"error",
"\n",
"execCtl",
":=",
"common",
".",
"ExecutionControl",
"{",
"Deadline",
":",
"&",
"time",
".",
"Time",
"{",
"}",
",",
"}",
"\n",
"for",
"_",
",",
"childNode",
":=",
"range",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"{",
"if",
"childNode",
".",
"BoundaryID",
"!=",
"nodeID",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"childNode",
".",
"Daemoned",
"==",
"nil",
"||",
"!",
"*",
"childNode",
".",
"Daemoned",
"{",
"continue",
"\n",
"}",
"\n",
"err",
":=",
"woc",
".",
"updateExecutionControl",
"(",
"childNode",
".",
"ID",
",",
"execCtl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"woc",
".",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"childNode",
".",
"ID",
",",
"err",
")",
"\n",
"if",
"firstErr",
"==",
"nil",
"{",
"firstErr",
"=",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"firstErr",
"\n",
"}"
] | // killDaemonedChildren kill any daemoned pods of a steps or DAG template node. | [
"killDaemonedChildren",
"kill",
"any",
"daemoned",
"pods",
"of",
"a",
"steps",
"or",
"DAG",
"template",
"node",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/exec_control.go#L80-L102 | train |
argoproj/argo | workflow/controller/exec_control.go | updateExecutionControl | func (woc *wfOperationCtx) updateExecutionControl(podName string, execCtl common.ExecutionControl) error {
execCtlBytes, err := json.Marshal(execCtl)
if err != nil {
return errors.InternalWrapError(err)
}
woc.log.Infof("Updating execution control of %s: %s", podName, execCtlBytes)
err = common.AddPodAnnotation(
woc.controller.kubeclientset,
podName,
woc.wf.ObjectMeta.Namespace,
common.AnnotationKeyExecutionControl,
string(execCtlBytes),
)
if err != nil {
return err
}
// Ideally we would simply annotate the pod with the updates and be done with it, allowing
// the executor to notice the updates naturally via the Downward API annotations volume
// mounted file. However, updates to the Downward API volumes take a very long time to
// propagate (minutes). The following code fast-tracks this by signaling the executor
// using SIGUSR2 that something changed.
woc.log.Infof("Signalling %s of updates", podName)
exec, err := common.ExecPodContainer(
woc.controller.restConfig, woc.wf.ObjectMeta.Namespace, podName,
common.WaitContainerName, true, true, "sh", "-c", "kill -s USR2 $(pidof argoexec)",
)
if err != nil {
return err
}
go func() {
// This call is necessary to actually send the exec. Since signalling is best effort,
// it is launched as a goroutine and the error is discarded
_, _, err = common.GetExecutorOutput(exec)
if err != nil {
woc.log.Warnf("Signal command failed: %v", err)
return
}
woc.log.Infof("Signal of %s (%s) successfully issued", podName, common.WaitContainerName)
}()
return nil
} | go | func (woc *wfOperationCtx) updateExecutionControl(podName string, execCtl common.ExecutionControl) error {
execCtlBytes, err := json.Marshal(execCtl)
if err != nil {
return errors.InternalWrapError(err)
}
woc.log.Infof("Updating execution control of %s: %s", podName, execCtlBytes)
err = common.AddPodAnnotation(
woc.controller.kubeclientset,
podName,
woc.wf.ObjectMeta.Namespace,
common.AnnotationKeyExecutionControl,
string(execCtlBytes),
)
if err != nil {
return err
}
// Ideally we would simply annotate the pod with the updates and be done with it, allowing
// the executor to notice the updates naturally via the Downward API annotations volume
// mounted file. However, updates to the Downward API volumes take a very long time to
// propagate (minutes). The following code fast-tracks this by signaling the executor
// using SIGUSR2 that something changed.
woc.log.Infof("Signalling %s of updates", podName)
exec, err := common.ExecPodContainer(
woc.controller.restConfig, woc.wf.ObjectMeta.Namespace, podName,
common.WaitContainerName, true, true, "sh", "-c", "kill -s USR2 $(pidof argoexec)",
)
if err != nil {
return err
}
go func() {
// This call is necessary to actually send the exec. Since signalling is best effort,
// it is launched as a goroutine and the error is discarded
_, _, err = common.GetExecutorOutput(exec)
if err != nil {
woc.log.Warnf("Signal command failed: %v", err)
return
}
woc.log.Infof("Signal of %s (%s) successfully issued", podName, common.WaitContainerName)
}()
return nil
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"updateExecutionControl",
"(",
"podName",
"string",
",",
"execCtl",
"common",
".",
"ExecutionControl",
")",
"error",
"{",
"execCtlBytes",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"execCtl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"InternalWrapError",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"podName",
",",
"execCtlBytes",
")",
"\n",
"err",
"=",
"common",
".",
"AddPodAnnotation",
"(",
"woc",
".",
"controller",
".",
"kubeclientset",
",",
"podName",
",",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Namespace",
",",
"common",
".",
"AnnotationKeyExecutionControl",
",",
"string",
"(",
"execCtlBytes",
")",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Ideally we would simply annotate the pod with the updates and be done with it, allowing",
"// the executor to notice the updates naturally via the Downward API annotations volume",
"// mounted file. However, updates to the Downward API volumes take a very long time to",
"// propagate (minutes). The following code fast-tracks this by signaling the executor",
"// using SIGUSR2 that something changed.",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"podName",
")",
"\n",
"exec",
",",
"err",
":=",
"common",
".",
"ExecPodContainer",
"(",
"woc",
".",
"controller",
".",
"restConfig",
",",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Namespace",
",",
"podName",
",",
"common",
".",
"WaitContainerName",
",",
"true",
",",
"true",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"go",
"func",
"(",
")",
"{",
"// This call is necessary to actually send the exec. Since signalling is best effort,",
"// it is launched as a goroutine and the error is discarded",
"_",
",",
"_",
",",
"err",
"=",
"common",
".",
"GetExecutorOutput",
"(",
"exec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"woc",
".",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"podName",
",",
"common",
".",
"WaitContainerName",
")",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // updateExecutionControl updates the execution control parameters | [
"updateExecutionControl",
"updates",
"the",
"execution",
"control",
"parameters"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/exec_control.go#L105-L148 | train |
argoproj/argo | util/cmd/cmd.go | MustIsDir | func MustIsDir(filePath string) bool {
fileInfo, err := os.Stat(filePath)
if err != nil {
log.Fatal(err)
}
return fileInfo.IsDir()
} | go | func MustIsDir(filePath string) bool {
fileInfo, err := os.Stat(filePath)
if err != nil {
log.Fatal(err)
}
return fileInfo.IsDir()
} | [
"func",
"MustIsDir",
"(",
"filePath",
"string",
")",
"bool",
"{",
"fileInfo",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"filePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"fileInfo",
".",
"IsDir",
"(",
")",
"\n",
"}"
] | // MustIsDir returns whether or not the given filePath is a directory. Exits if path does not exist | [
"MustIsDir",
"returns",
"whether",
"or",
"not",
"the",
"given",
"filePath",
"is",
"a",
"directory",
".",
"Exits",
"if",
"path",
"does",
"not",
"exist"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/util/cmd/cmd.go#L45-L51 | train |
argoproj/argo | util/cmd/cmd.go | MustHomeDir | func MustHomeDir() string {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
return usr.HomeDir
} | go | func MustHomeDir() string {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
return usr.HomeDir
} | [
"func",
"MustHomeDir",
"(",
")",
"string",
"{",
"usr",
",",
"err",
":=",
"user",
".",
"Current",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"usr",
".",
"HomeDir",
"\n",
"}"
] | // MustHomeDir returns the home directory of the user | [
"MustHomeDir",
"returns",
"the",
"home",
"directory",
"of",
"the",
"user"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/util/cmd/cmd.go#L54-L60 | train |
argoproj/argo | util/cmd/cmd.go | IsURL | func IsURL(u string) bool {
var parsedURL *url.URL
var err error
parsedURL, err = url.ParseRequestURI(u)
if err == nil {
if parsedURL != nil && parsedURL.Host != "" {
return true
}
}
return false
} | go | func IsURL(u string) bool {
var parsedURL *url.URL
var err error
parsedURL, err = url.ParseRequestURI(u)
if err == nil {
if parsedURL != nil && parsedURL.Host != "" {
return true
}
}
return false
} | [
"func",
"IsURL",
"(",
"u",
"string",
")",
"bool",
"{",
"var",
"parsedURL",
"*",
"url",
".",
"URL",
"\n",
"var",
"err",
"error",
"\n\n",
"parsedURL",
",",
"err",
"=",
"url",
".",
"ParseRequestURI",
"(",
"u",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"if",
"parsedURL",
"!=",
"nil",
"&&",
"parsedURL",
".",
"Host",
"!=",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsURL returns whether or not a string is a URL | [
"IsURL",
"returns",
"whether",
"or",
"not",
"a",
"string",
"is",
"a",
"URL"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/util/cmd/cmd.go#L63-L74 | train |
argoproj/argo | util/unstructured/unstructured.go | NewUnstructuredInformer | func NewUnstructuredInformer(resource schema.GroupVersionResource, client dynamic.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredUnstructuredInformer(resource, client, namespace, resyncPeriod, indexers, nil)
} | go | func NewUnstructuredInformer(resource schema.GroupVersionResource, client dynamic.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredUnstructuredInformer(resource, client, namespace, resyncPeriod, indexers, nil)
} | [
"func",
"NewUnstructuredInformer",
"(",
"resource",
"schema",
".",
"GroupVersionResource",
",",
"client",
"dynamic",
".",
"Interface",
",",
"namespace",
"string",
",",
"resyncPeriod",
"time",
".",
"Duration",
",",
"indexers",
"cache",
".",
"Indexers",
")",
"cache",
".",
"SharedIndexInformer",
"{",
"return",
"NewFilteredUnstructuredInformer",
"(",
"resource",
",",
"client",
",",
"namespace",
",",
"resyncPeriod",
",",
"indexers",
",",
"nil",
")",
"\n",
"}"
] | // NewUnstructuredInformer constructs a new informer for Unstructured type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server. | [
"NewUnstructuredInformer",
"constructs",
"a",
"new",
"informer",
"for",
"Unstructured",
"type",
".",
"Always",
"prefer",
"using",
"an",
"informer",
"factory",
"to",
"get",
"a",
"shared",
"informer",
"instead",
"of",
"getting",
"an",
"independent",
"one",
".",
"This",
"reduces",
"memory",
"footprint",
"and",
"number",
"of",
"connections",
"to",
"the",
"server",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/util/unstructured/unstructured.go#L19-L21 | train |
argoproj/argo | util/unstructured/unstructured.go | NewFilteredUnstructuredInformer | func NewFilteredUnstructuredInformer(resource schema.GroupVersionResource, client dynamic.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.Resource(resource).Namespace(namespace).List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.Resource(resource).Namespace(namespace).Watch(options)
},
},
&unstructured.Unstructured{},
resyncPeriod,
indexers,
)
} | go | func NewFilteredUnstructuredInformer(resource schema.GroupVersionResource, client dynamic.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.Resource(resource).Namespace(namespace).List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.Resource(resource).Namespace(namespace).Watch(options)
},
},
&unstructured.Unstructured{},
resyncPeriod,
indexers,
)
} | [
"func",
"NewFilteredUnstructuredInformer",
"(",
"resource",
"schema",
".",
"GroupVersionResource",
",",
"client",
"dynamic",
".",
"Interface",
",",
"namespace",
"string",
",",
"resyncPeriod",
"time",
".",
"Duration",
",",
"indexers",
"cache",
".",
"Indexers",
",",
"tweakListOptions",
"internalinterfaces",
".",
"TweakListOptionsFunc",
")",
"cache",
".",
"SharedIndexInformer",
"{",
"return",
"cache",
".",
"NewSharedIndexInformer",
"(",
"&",
"cache",
".",
"ListWatch",
"{",
"ListFunc",
":",
"func",
"(",
"options",
"metav1",
".",
"ListOptions",
")",
"(",
"runtime",
".",
"Object",
",",
"error",
")",
"{",
"if",
"tweakListOptions",
"!=",
"nil",
"{",
"tweakListOptions",
"(",
"&",
"options",
")",
"\n",
"}",
"\n",
"return",
"client",
".",
"Resource",
"(",
"resource",
")",
".",
"Namespace",
"(",
"namespace",
")",
".",
"List",
"(",
"options",
")",
"\n",
"}",
",",
"WatchFunc",
":",
"func",
"(",
"options",
"metav1",
".",
"ListOptions",
")",
"(",
"watch",
".",
"Interface",
",",
"error",
")",
"{",
"if",
"tweakListOptions",
"!=",
"nil",
"{",
"tweakListOptions",
"(",
"&",
"options",
")",
"\n",
"}",
"\n",
"return",
"client",
".",
"Resource",
"(",
"resource",
")",
".",
"Namespace",
"(",
"namespace",
")",
".",
"Watch",
"(",
"options",
")",
"\n",
"}",
",",
"}",
",",
"&",
"unstructured",
".",
"Unstructured",
"{",
"}",
",",
"resyncPeriod",
",",
"indexers",
",",
")",
"\n",
"}"
] | // NewFilteredUnstructuredInformer constructs a new informer for Unstructured type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server. | [
"NewFilteredUnstructuredInformer",
"constructs",
"a",
"new",
"informer",
"for",
"Unstructured",
"type",
".",
"Always",
"prefer",
"using",
"an",
"informer",
"factory",
"to",
"get",
"a",
"shared",
"informer",
"instead",
"of",
"getting",
"an",
"independent",
"one",
".",
"This",
"reduces",
"memory",
"footprint",
"and",
"number",
"of",
"connections",
"to",
"the",
"server",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/util/unstructured/unstructured.go#L26-L46 | train |
argoproj/argo | pkg/client/informers/externalversions/workflow/v1alpha1/workflow.go | NewWorkflowInformer | func NewWorkflowInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredWorkflowInformer(client, namespace, resyncPeriod, indexers, nil)
} | go | func NewWorkflowInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredWorkflowInformer(client, namespace, resyncPeriod, indexers, nil)
} | [
"func",
"NewWorkflowInformer",
"(",
"client",
"versioned",
".",
"Interface",
",",
"namespace",
"string",
",",
"resyncPeriod",
"time",
".",
"Duration",
",",
"indexers",
"cache",
".",
"Indexers",
")",
"cache",
".",
"SharedIndexInformer",
"{",
"return",
"NewFilteredWorkflowInformer",
"(",
"client",
",",
"namespace",
",",
"resyncPeriod",
",",
"indexers",
",",
"nil",
")",
"\n",
"}"
] | // NewWorkflowInformer constructs a new informer for Workflow type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server. | [
"NewWorkflowInformer",
"constructs",
"a",
"new",
"informer",
"for",
"Workflow",
"type",
".",
"Always",
"prefer",
"using",
"an",
"informer",
"factory",
"to",
"get",
"a",
"shared",
"informer",
"instead",
"of",
"getting",
"an",
"independent",
"one",
".",
"This",
"reduces",
"memory",
"footprint",
"and",
"number",
"of",
"connections",
"to",
"the",
"server",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/client/informers/externalversions/workflow/v1alpha1/workflow.go#L34-L36 | train |
argoproj/argo | pkg/client/informers/externalversions/workflow/v1alpha1/workflow.go | NewFilteredWorkflowInformer | func NewFilteredWorkflowInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.ArgoprojV1alpha1().Workflows(namespace).List(options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.ArgoprojV1alpha1().Workflows(namespace).Watch(options)
},
},
&workflowv1alpha1.Workflow{},
resyncPeriod,
indexers,
)
} | go | func NewFilteredWorkflowInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.ArgoprojV1alpha1().Workflows(namespace).List(options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.ArgoprojV1alpha1().Workflows(namespace).Watch(options)
},
},
&workflowv1alpha1.Workflow{},
resyncPeriod,
indexers,
)
} | [
"func",
"NewFilteredWorkflowInformer",
"(",
"client",
"versioned",
".",
"Interface",
",",
"namespace",
"string",
",",
"resyncPeriod",
"time",
".",
"Duration",
",",
"indexers",
"cache",
".",
"Indexers",
",",
"tweakListOptions",
"internalinterfaces",
".",
"TweakListOptionsFunc",
")",
"cache",
".",
"SharedIndexInformer",
"{",
"return",
"cache",
".",
"NewSharedIndexInformer",
"(",
"&",
"cache",
".",
"ListWatch",
"{",
"ListFunc",
":",
"func",
"(",
"options",
"v1",
".",
"ListOptions",
")",
"(",
"runtime",
".",
"Object",
",",
"error",
")",
"{",
"if",
"tweakListOptions",
"!=",
"nil",
"{",
"tweakListOptions",
"(",
"&",
"options",
")",
"\n",
"}",
"\n",
"return",
"client",
".",
"ArgoprojV1alpha1",
"(",
")",
".",
"Workflows",
"(",
"namespace",
")",
".",
"List",
"(",
"options",
")",
"\n",
"}",
",",
"WatchFunc",
":",
"func",
"(",
"options",
"v1",
".",
"ListOptions",
")",
"(",
"watch",
".",
"Interface",
",",
"error",
")",
"{",
"if",
"tweakListOptions",
"!=",
"nil",
"{",
"tweakListOptions",
"(",
"&",
"options",
")",
"\n",
"}",
"\n",
"return",
"client",
".",
"ArgoprojV1alpha1",
"(",
")",
".",
"Workflows",
"(",
"namespace",
")",
".",
"Watch",
"(",
"options",
")",
"\n",
"}",
",",
"}",
",",
"&",
"workflowv1alpha1",
".",
"Workflow",
"{",
"}",
",",
"resyncPeriod",
",",
"indexers",
",",
")",
"\n",
"}"
] | // NewFilteredWorkflowInformer constructs a new informer for Workflow type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server. | [
"NewFilteredWorkflowInformer",
"constructs",
"a",
"new",
"informer",
"for",
"Workflow",
"type",
".",
"Always",
"prefer",
"using",
"an",
"informer",
"factory",
"to",
"get",
"a",
"shared",
"informer",
"instead",
"of",
"getting",
"an",
"independent",
"one",
".",
"This",
"reduces",
"memory",
"footprint",
"and",
"number",
"of",
"connections",
"to",
"the",
"server",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/client/informers/externalversions/workflow/v1alpha1/workflow.go#L41-L61 | train |
argoproj/argo | pkg/client/informers/externalversions/workflow/v1alpha1/interface.go | Workflows | func (v *version) Workflows() WorkflowInformer {
return &workflowInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
} | go | func (v *version) Workflows() WorkflowInformer {
return &workflowInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
} | [
"func",
"(",
"v",
"*",
"version",
")",
"Workflows",
"(",
")",
"WorkflowInformer",
"{",
"return",
"&",
"workflowInformer",
"{",
"factory",
":",
"v",
".",
"factory",
",",
"namespace",
":",
"v",
".",
"namespace",
",",
"tweakListOptions",
":",
"v",
".",
"tweakListOptions",
"}",
"\n",
"}"
] | // Workflows returns a WorkflowInformer. | [
"Workflows",
"returns",
"a",
"WorkflowInformer",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/pkg/client/informers/externalversions/workflow/v1alpha1/interface.go#L27-L29 | train |
argoproj/argo | workflow/metrics/collector.go | NewWorkflowRegistry | func NewWorkflowRegistry(informer cache.SharedIndexInformer) *prometheus.Registry {
workflowLister := util.NewWorkflowLister(informer)
registry := prometheus.NewRegistry()
registry.MustRegister(&workflowCollector{store: workflowLister})
return registry
} | go | func NewWorkflowRegistry(informer cache.SharedIndexInformer) *prometheus.Registry {
workflowLister := util.NewWorkflowLister(informer)
registry := prometheus.NewRegistry()
registry.MustRegister(&workflowCollector{store: workflowLister})
return registry
} | [
"func",
"NewWorkflowRegistry",
"(",
"informer",
"cache",
".",
"SharedIndexInformer",
")",
"*",
"prometheus",
".",
"Registry",
"{",
"workflowLister",
":=",
"util",
".",
"NewWorkflowLister",
"(",
"informer",
")",
"\n",
"registry",
":=",
"prometheus",
".",
"NewRegistry",
"(",
")",
"\n",
"registry",
".",
"MustRegister",
"(",
"&",
"workflowCollector",
"{",
"store",
":",
"workflowLister",
"}",
")",
"\n",
"return",
"registry",
"\n",
"}"
] | // NewWorkflowRegistry creates a new prometheus registry that collects workflows | [
"NewWorkflowRegistry",
"creates",
"a",
"new",
"prometheus",
"registry",
"that",
"collects",
"workflows"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/metrics/collector.go#L62-L67 | train |
argoproj/argo | workflow/metrics/collector.go | NewTelemetryRegistry | func NewTelemetryRegistry() *prometheus.Registry {
registry := prometheus.NewRegistry()
registry.MustRegister(prometheus.NewProcessCollector(os.Getpid(), ""))
registry.MustRegister(prometheus.NewGoCollector())
return registry
} | go | func NewTelemetryRegistry() *prometheus.Registry {
registry := prometheus.NewRegistry()
registry.MustRegister(prometheus.NewProcessCollector(os.Getpid(), ""))
registry.MustRegister(prometheus.NewGoCollector())
return registry
} | [
"func",
"NewTelemetryRegistry",
"(",
")",
"*",
"prometheus",
".",
"Registry",
"{",
"registry",
":=",
"prometheus",
".",
"NewRegistry",
"(",
")",
"\n",
"registry",
".",
"MustRegister",
"(",
"prometheus",
".",
"NewProcessCollector",
"(",
"os",
".",
"Getpid",
"(",
")",
",",
"\"",
"\"",
")",
")",
"\n",
"registry",
".",
"MustRegister",
"(",
"prometheus",
".",
"NewGoCollector",
"(",
")",
")",
"\n",
"return",
"registry",
"\n",
"}"
] | // NewTelemetryRegistry creates a new prometheus registry that collects telemetry | [
"NewTelemetryRegistry",
"creates",
"a",
"new",
"prometheus",
"registry",
"that",
"collects",
"telemetry"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/metrics/collector.go#L70-L75 | train |
argoproj/argo | hack/gen-openapi-spec/main.go | main | func main() {
if len(os.Args) <= 1 {
log.Fatal("Supply a version")
}
version := os.Args[1]
if !strings.HasPrefix(version, "v") {
version = "v" + version
}
oAPIDefs := wfv1.GetOpenAPIDefinitions(func(name string) spec.Ref {
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name)))
})
defs := spec.Definitions{}
for defName, val := range oAPIDefs {
defs[swaggify(defName)] = val.Schema
}
swagger := spec.Swagger{
SwaggerProps: spec.SwaggerProps{
Swagger: "2.0",
Definitions: defs,
Paths: &spec.Paths{Paths: map[string]spec.PathItem{}},
Info: &spec.Info{
InfoProps: spec.InfoProps{
Title: "Argo",
Version: version,
},
},
},
}
jsonBytes, err := json.MarshalIndent(swagger, "", " ")
if err != nil {
log.Fatal(err.Error())
}
fmt.Println(string(jsonBytes))
} | go | func main() {
if len(os.Args) <= 1 {
log.Fatal("Supply a version")
}
version := os.Args[1]
if !strings.HasPrefix(version, "v") {
version = "v" + version
}
oAPIDefs := wfv1.GetOpenAPIDefinitions(func(name string) spec.Ref {
return spec.MustCreateRef("#/definitions/" + common.EscapeJsonPointer(swaggify(name)))
})
defs := spec.Definitions{}
for defName, val := range oAPIDefs {
defs[swaggify(defName)] = val.Schema
}
swagger := spec.Swagger{
SwaggerProps: spec.SwaggerProps{
Swagger: "2.0",
Definitions: defs,
Paths: &spec.Paths{Paths: map[string]spec.PathItem{}},
Info: &spec.Info{
InfoProps: spec.InfoProps{
Title: "Argo",
Version: version,
},
},
},
}
jsonBytes, err := json.MarshalIndent(swagger, "", " ")
if err != nil {
log.Fatal(err.Error())
}
fmt.Println(string(jsonBytes))
} | [
"func",
"main",
"(",
")",
"{",
"if",
"len",
"(",
"os",
".",
"Args",
")",
"<=",
"1",
"{",
"log",
".",
"Fatal",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"version",
":=",
"os",
".",
"Args",
"[",
"1",
"]",
"\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"version",
",",
"\"",
"\"",
")",
"{",
"version",
"=",
"\"",
"\"",
"+",
"version",
"\n",
"}",
"\n",
"oAPIDefs",
":=",
"wfv1",
".",
"GetOpenAPIDefinitions",
"(",
"func",
"(",
"name",
"string",
")",
"spec",
".",
"Ref",
"{",
"return",
"spec",
".",
"MustCreateRef",
"(",
"\"",
"\"",
"+",
"common",
".",
"EscapeJsonPointer",
"(",
"swaggify",
"(",
"name",
")",
")",
")",
"\n",
"}",
")",
"\n",
"defs",
":=",
"spec",
".",
"Definitions",
"{",
"}",
"\n",
"for",
"defName",
",",
"val",
":=",
"range",
"oAPIDefs",
"{",
"defs",
"[",
"swaggify",
"(",
"defName",
")",
"]",
"=",
"val",
".",
"Schema",
"\n",
"}",
"\n",
"swagger",
":=",
"spec",
".",
"Swagger",
"{",
"SwaggerProps",
":",
"spec",
".",
"SwaggerProps",
"{",
"Swagger",
":",
"\"",
"\"",
",",
"Definitions",
":",
"defs",
",",
"Paths",
":",
"&",
"spec",
".",
"Paths",
"{",
"Paths",
":",
"map",
"[",
"string",
"]",
"spec",
".",
"PathItem",
"{",
"}",
"}",
",",
"Info",
":",
"&",
"spec",
".",
"Info",
"{",
"InfoProps",
":",
"spec",
".",
"InfoProps",
"{",
"Title",
":",
"\"",
"\"",
",",
"Version",
":",
"version",
",",
"}",
",",
"}",
",",
"}",
",",
"}",
"\n",
"jsonBytes",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"swagger",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Println",
"(",
"string",
"(",
"jsonBytes",
")",
")",
"\n",
"}"
] | // Generate OpenAPI spec definitions for Workflow Resource | [
"Generate",
"OpenAPI",
"spec",
"definitions",
"for",
"Workflow",
"Resource"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/hack/gen-openapi-spec/main.go#L16-L49 | train |
argoproj/argo | workflow/controller/operator.go | newWorkflowOperationCtx | func newWorkflowOperationCtx(wf *wfv1.Workflow, wfc *WorkflowController) *wfOperationCtx {
// NEVER modify objects from the store. It's a read-only, local cache.
// You can use DeepCopy() to make a deep copy of original object and modify this copy
// Or create a copy manually for better performance
woc := wfOperationCtx{
wf: wf.DeepCopyObject().(*wfv1.Workflow),
orig: wf,
updated: false,
log: log.WithFields(log.Fields{
"workflow": wf.ObjectMeta.Name,
"namespace": wf.ObjectMeta.Namespace,
}),
controller: wfc,
globalParams: make(map[string]string),
volumes: wf.Spec.DeepCopy().Volumes,
completedPods: make(map[string]bool),
deadline: time.Now().UTC().Add(maxOperationTime),
}
if woc.wf.Status.Nodes == nil {
woc.wf.Status.Nodes = make(map[string]wfv1.NodeStatus)
}
return &woc
} | go | func newWorkflowOperationCtx(wf *wfv1.Workflow, wfc *WorkflowController) *wfOperationCtx {
// NEVER modify objects from the store. It's a read-only, local cache.
// You can use DeepCopy() to make a deep copy of original object and modify this copy
// Or create a copy manually for better performance
woc := wfOperationCtx{
wf: wf.DeepCopyObject().(*wfv1.Workflow),
orig: wf,
updated: false,
log: log.WithFields(log.Fields{
"workflow": wf.ObjectMeta.Name,
"namespace": wf.ObjectMeta.Namespace,
}),
controller: wfc,
globalParams: make(map[string]string),
volumes: wf.Spec.DeepCopy().Volumes,
completedPods: make(map[string]bool),
deadline: time.Now().UTC().Add(maxOperationTime),
}
if woc.wf.Status.Nodes == nil {
woc.wf.Status.Nodes = make(map[string]wfv1.NodeStatus)
}
return &woc
} | [
"func",
"newWorkflowOperationCtx",
"(",
"wf",
"*",
"wfv1",
".",
"Workflow",
",",
"wfc",
"*",
"WorkflowController",
")",
"*",
"wfOperationCtx",
"{",
"// NEVER modify objects from the store. It's a read-only, local cache.",
"// You can use DeepCopy() to make a deep copy of original object and modify this copy",
"// Or create a copy manually for better performance",
"woc",
":=",
"wfOperationCtx",
"{",
"wf",
":",
"wf",
".",
"DeepCopyObject",
"(",
")",
".",
"(",
"*",
"wfv1",
".",
"Workflow",
")",
",",
"orig",
":",
"wf",
",",
"updated",
":",
"false",
",",
"log",
":",
"log",
".",
"WithFields",
"(",
"log",
".",
"Fields",
"{",
"\"",
"\"",
":",
"wf",
".",
"ObjectMeta",
".",
"Name",
",",
"\"",
"\"",
":",
"wf",
".",
"ObjectMeta",
".",
"Namespace",
",",
"}",
")",
",",
"controller",
":",
"wfc",
",",
"globalParams",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
",",
"volumes",
":",
"wf",
".",
"Spec",
".",
"DeepCopy",
"(",
")",
".",
"Volumes",
",",
"completedPods",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
",",
"deadline",
":",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
".",
"Add",
"(",
"maxOperationTime",
")",
",",
"}",
"\n\n",
"if",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"==",
"nil",
"{",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"wfv1",
".",
"NodeStatus",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"woc",
"\n",
"}"
] | // newWorkflowOperationCtx creates and initializes a new wfOperationCtx object. | [
"newWorkflowOperationCtx",
"creates",
"and",
"initializes",
"a",
"new",
"wfOperationCtx",
"object",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L85-L109 | train |
argoproj/argo | workflow/controller/operator.go | setGlobalParameters | func (woc *wfOperationCtx) setGlobalParameters() {
woc.globalParams[common.GlobalVarWorkflowName] = woc.wf.ObjectMeta.Name
woc.globalParams[common.GlobalVarWorkflowNamespace] = woc.wf.ObjectMeta.Namespace
woc.globalParams[common.GlobalVarWorkflowUID] = string(woc.wf.ObjectMeta.UID)
woc.globalParams[common.GlobalVarWorkflowCreationTimestamp] = woc.wf.ObjectMeta.CreationTimestamp.String()
for char := range strftime.FormatChars {
cTimeVar := fmt.Sprintf("%s.%s", common.GlobalVarWorkflowCreationTimestamp, string(char))
woc.globalParams[cTimeVar] = strftime.Format("%"+string(char), woc.wf.ObjectMeta.CreationTimestamp.Time)
}
for _, param := range woc.wf.Spec.Arguments.Parameters {
woc.globalParams["workflow.parameters."+param.Name] = *param.Value
}
for k, v := range woc.wf.ObjectMeta.Annotations {
woc.globalParams["workflow.annotations."+k] = v
}
for k, v := range woc.wf.ObjectMeta.Labels {
woc.globalParams["workflow.labels."+k] = v
}
if woc.wf.Status.Outputs != nil {
for _, param := range woc.wf.Status.Outputs.Parameters {
woc.globalParams["workflow.outputs.parameters."+param.Name] = *param.Value
}
}
} | go | func (woc *wfOperationCtx) setGlobalParameters() {
woc.globalParams[common.GlobalVarWorkflowName] = woc.wf.ObjectMeta.Name
woc.globalParams[common.GlobalVarWorkflowNamespace] = woc.wf.ObjectMeta.Namespace
woc.globalParams[common.GlobalVarWorkflowUID] = string(woc.wf.ObjectMeta.UID)
woc.globalParams[common.GlobalVarWorkflowCreationTimestamp] = woc.wf.ObjectMeta.CreationTimestamp.String()
for char := range strftime.FormatChars {
cTimeVar := fmt.Sprintf("%s.%s", common.GlobalVarWorkflowCreationTimestamp, string(char))
woc.globalParams[cTimeVar] = strftime.Format("%"+string(char), woc.wf.ObjectMeta.CreationTimestamp.Time)
}
for _, param := range woc.wf.Spec.Arguments.Parameters {
woc.globalParams["workflow.parameters."+param.Name] = *param.Value
}
for k, v := range woc.wf.ObjectMeta.Annotations {
woc.globalParams["workflow.annotations."+k] = v
}
for k, v := range woc.wf.ObjectMeta.Labels {
woc.globalParams["workflow.labels."+k] = v
}
if woc.wf.Status.Outputs != nil {
for _, param := range woc.wf.Status.Outputs.Parameters {
woc.globalParams["workflow.outputs.parameters."+param.Name] = *param.Value
}
}
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"setGlobalParameters",
"(",
")",
"{",
"woc",
".",
"globalParams",
"[",
"common",
".",
"GlobalVarWorkflowName",
"]",
"=",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Name",
"\n",
"woc",
".",
"globalParams",
"[",
"common",
".",
"GlobalVarWorkflowNamespace",
"]",
"=",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Namespace",
"\n",
"woc",
".",
"globalParams",
"[",
"common",
".",
"GlobalVarWorkflowUID",
"]",
"=",
"string",
"(",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"UID",
")",
"\n",
"woc",
".",
"globalParams",
"[",
"common",
".",
"GlobalVarWorkflowCreationTimestamp",
"]",
"=",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"CreationTimestamp",
".",
"String",
"(",
")",
"\n",
"for",
"char",
":=",
"range",
"strftime",
".",
"FormatChars",
"{",
"cTimeVar",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"common",
".",
"GlobalVarWorkflowCreationTimestamp",
",",
"string",
"(",
"char",
")",
")",
"\n",
"woc",
".",
"globalParams",
"[",
"cTimeVar",
"]",
"=",
"strftime",
".",
"Format",
"(",
"\"",
"\"",
"+",
"string",
"(",
"char",
")",
",",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"CreationTimestamp",
".",
"Time",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"param",
":=",
"range",
"woc",
".",
"wf",
".",
"Spec",
".",
"Arguments",
".",
"Parameters",
"{",
"woc",
".",
"globalParams",
"[",
"\"",
"\"",
"+",
"param",
".",
"Name",
"]",
"=",
"*",
"param",
".",
"Value",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Annotations",
"{",
"woc",
".",
"globalParams",
"[",
"\"",
"\"",
"+",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Labels",
"{",
"woc",
".",
"globalParams",
"[",
"\"",
"\"",
"+",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"if",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
"!=",
"nil",
"{",
"for",
"_",
",",
"param",
":=",
"range",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
".",
"Parameters",
"{",
"woc",
".",
"globalParams",
"[",
"\"",
"\"",
"+",
"param",
".",
"Name",
"]",
"=",
"*",
"param",
".",
"Value",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // setGlobalParameters sets the globalParam map with global parameters | [
"setGlobalParameters",
"sets",
"the",
"globalParam",
"map",
"with",
"global",
"parameters"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L261-L284 | train |
argoproj/argo | workflow/controller/operator.go | requeue | func (woc *wfOperationCtx) requeue() {
key, err := cache.MetaNamespaceKeyFunc(woc.wf)
if err != nil {
woc.log.Errorf("Failed to requeue workflow %s: %v", woc.wf.ObjectMeta.Name, err)
return
}
woc.controller.wfQueue.Add(key)
} | go | func (woc *wfOperationCtx) requeue() {
key, err := cache.MetaNamespaceKeyFunc(woc.wf)
if err != nil {
woc.log.Errorf("Failed to requeue workflow %s: %v", woc.wf.ObjectMeta.Name, err)
return
}
woc.controller.wfQueue.Add(key)
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"requeue",
"(",
")",
"{",
"key",
",",
"err",
":=",
"cache",
".",
"MetaNamespaceKeyFunc",
"(",
"woc",
".",
"wf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"woc",
".",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Name",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"woc",
".",
"controller",
".",
"wfQueue",
".",
"Add",
"(",
"key",
")",
"\n",
"}"
] | // requeue this workflow onto the workqueue for later processing | [
"requeue",
"this",
"workflow",
"onto",
"the",
"workqueue",
"for",
"later",
"processing"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L409-L416 | train |
argoproj/argo | workflow/controller/operator.go | podReconciliation | func (woc *wfOperationCtx) podReconciliation() error {
podList, err := woc.getAllWorkflowPods()
if err != nil {
return err
}
seenPods := make(map[string]bool)
seenPodLock := &sync.Mutex{}
wfNodesLock := &sync.RWMutex{}
performAssessment := func(pod *apiv1.Pod) {
if pod == nil {
return
}
nodeNameForPod := pod.Annotations[common.AnnotationKeyNodeName]
nodeID := woc.wf.NodeID(nodeNameForPod)
seenPodLock.Lock()
seenPods[nodeID] = true
seenPodLock.Unlock()
wfNodesLock.Lock()
defer wfNodesLock.Unlock()
if node, ok := woc.wf.Status.Nodes[nodeID]; ok {
if newState := assessNodeStatus(pod, &node); newState != nil {
woc.wf.Status.Nodes[nodeID] = *newState
woc.addOutputsToScope("workflow", node.Outputs, nil)
woc.updated = true
}
node := woc.wf.Status.Nodes[pod.ObjectMeta.Name]
if node.Completed() && !node.IsDaemoned() {
if tmpVal, tmpOk := pod.Labels[common.LabelKeyCompleted]; tmpOk {
if tmpVal == "true" {
return
}
}
woc.completedPods[pod.ObjectMeta.Name] = true
}
}
return
}
parallelPodNum := make(chan string, 500)
var wg sync.WaitGroup
for _, pod := range podList.Items {
parallelPodNum <- pod.Name
wg.Add(1)
go func(tmpPod apiv1.Pod) {
defer wg.Done()
performAssessment(&tmpPod)
err = woc.applyExecutionControl(&tmpPod, wfNodesLock)
if err != nil {
woc.log.Warnf("Failed to apply execution control to pod %s", tmpPod.Name)
}
<-parallelPodNum
}(pod)
}
wg.Wait()
// Now check for deleted pods. Iterate our nodes. If any one of our nodes does not show up in
// the seen list it implies that the pod was deleted without the controller seeing the event.
// It is now impossible to infer pod status. The only thing we can do at this point is to mark
// the node with Error.
for nodeID, node := range woc.wf.Status.Nodes {
if node.Type != wfv1.NodeTypePod || node.Completed() {
// node is not a pod, or it is already complete
continue
}
if _, ok := seenPods[nodeID]; !ok {
node.Message = "pod deleted"
node.Phase = wfv1.NodeError
woc.wf.Status.Nodes[nodeID] = node
woc.log.Warnf("pod %s deleted", nodeID)
woc.updated = true
}
}
return nil
} | go | func (woc *wfOperationCtx) podReconciliation() error {
podList, err := woc.getAllWorkflowPods()
if err != nil {
return err
}
seenPods := make(map[string]bool)
seenPodLock := &sync.Mutex{}
wfNodesLock := &sync.RWMutex{}
performAssessment := func(pod *apiv1.Pod) {
if pod == nil {
return
}
nodeNameForPod := pod.Annotations[common.AnnotationKeyNodeName]
nodeID := woc.wf.NodeID(nodeNameForPod)
seenPodLock.Lock()
seenPods[nodeID] = true
seenPodLock.Unlock()
wfNodesLock.Lock()
defer wfNodesLock.Unlock()
if node, ok := woc.wf.Status.Nodes[nodeID]; ok {
if newState := assessNodeStatus(pod, &node); newState != nil {
woc.wf.Status.Nodes[nodeID] = *newState
woc.addOutputsToScope("workflow", node.Outputs, nil)
woc.updated = true
}
node := woc.wf.Status.Nodes[pod.ObjectMeta.Name]
if node.Completed() && !node.IsDaemoned() {
if tmpVal, tmpOk := pod.Labels[common.LabelKeyCompleted]; tmpOk {
if tmpVal == "true" {
return
}
}
woc.completedPods[pod.ObjectMeta.Name] = true
}
}
return
}
parallelPodNum := make(chan string, 500)
var wg sync.WaitGroup
for _, pod := range podList.Items {
parallelPodNum <- pod.Name
wg.Add(1)
go func(tmpPod apiv1.Pod) {
defer wg.Done()
performAssessment(&tmpPod)
err = woc.applyExecutionControl(&tmpPod, wfNodesLock)
if err != nil {
woc.log.Warnf("Failed to apply execution control to pod %s", tmpPod.Name)
}
<-parallelPodNum
}(pod)
}
wg.Wait()
// Now check for deleted pods. Iterate our nodes. If any one of our nodes does not show up in
// the seen list it implies that the pod was deleted without the controller seeing the event.
// It is now impossible to infer pod status. The only thing we can do at this point is to mark
// the node with Error.
for nodeID, node := range woc.wf.Status.Nodes {
if node.Type != wfv1.NodeTypePod || node.Completed() {
// node is not a pod, or it is already complete
continue
}
if _, ok := seenPods[nodeID]; !ok {
node.Message = "pod deleted"
node.Phase = wfv1.NodeError
woc.wf.Status.Nodes[nodeID] = node
woc.log.Warnf("pod %s deleted", nodeID)
woc.updated = true
}
}
return nil
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"podReconciliation",
"(",
")",
"error",
"{",
"podList",
",",
"err",
":=",
"woc",
".",
"getAllWorkflowPods",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"seenPods",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"seenPodLock",
":=",
"&",
"sync",
".",
"Mutex",
"{",
"}",
"\n",
"wfNodesLock",
":=",
"&",
"sync",
".",
"RWMutex",
"{",
"}",
"\n\n",
"performAssessment",
":=",
"func",
"(",
"pod",
"*",
"apiv1",
".",
"Pod",
")",
"{",
"if",
"pod",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"nodeNameForPod",
":=",
"pod",
".",
"Annotations",
"[",
"common",
".",
"AnnotationKeyNodeName",
"]",
"\n",
"nodeID",
":=",
"woc",
".",
"wf",
".",
"NodeID",
"(",
"nodeNameForPod",
")",
"\n",
"seenPodLock",
".",
"Lock",
"(",
")",
"\n",
"seenPods",
"[",
"nodeID",
"]",
"=",
"true",
"\n",
"seenPodLock",
".",
"Unlock",
"(",
")",
"\n\n",
"wfNodesLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"wfNodesLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"node",
",",
"ok",
":=",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"[",
"nodeID",
"]",
";",
"ok",
"{",
"if",
"newState",
":=",
"assessNodeStatus",
"(",
"pod",
",",
"&",
"node",
")",
";",
"newState",
"!=",
"nil",
"{",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"[",
"nodeID",
"]",
"=",
"*",
"newState",
"\n",
"woc",
".",
"addOutputsToScope",
"(",
"\"",
"\"",
",",
"node",
".",
"Outputs",
",",
"nil",
")",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"}",
"\n",
"node",
":=",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"[",
"pod",
".",
"ObjectMeta",
".",
"Name",
"]",
"\n",
"if",
"node",
".",
"Completed",
"(",
")",
"&&",
"!",
"node",
".",
"IsDaemoned",
"(",
")",
"{",
"if",
"tmpVal",
",",
"tmpOk",
":=",
"pod",
".",
"Labels",
"[",
"common",
".",
"LabelKeyCompleted",
"]",
";",
"tmpOk",
"{",
"if",
"tmpVal",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"woc",
".",
"completedPods",
"[",
"pod",
".",
"ObjectMeta",
".",
"Name",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n\n",
"parallelPodNum",
":=",
"make",
"(",
"chan",
"string",
",",
"500",
")",
"\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n\n",
"for",
"_",
",",
"pod",
":=",
"range",
"podList",
".",
"Items",
"{",
"parallelPodNum",
"<-",
"pod",
".",
"Name",
"\n",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"tmpPod",
"apiv1",
".",
"Pod",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"performAssessment",
"(",
"&",
"tmpPod",
")",
"\n",
"err",
"=",
"woc",
".",
"applyExecutionControl",
"(",
"&",
"tmpPod",
",",
"wfNodesLock",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"woc",
".",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"tmpPod",
".",
"Name",
")",
"\n",
"}",
"\n",
"<-",
"parallelPodNum",
"\n",
"}",
"(",
"pod",
")",
"\n",
"}",
"\n\n",
"wg",
".",
"Wait",
"(",
")",
"\n\n",
"// Now check for deleted pods. Iterate our nodes. If any one of our nodes does not show up in",
"// the seen list it implies that the pod was deleted without the controller seeing the event.",
"// It is now impossible to infer pod status. The only thing we can do at this point is to mark",
"// the node with Error.",
"for",
"nodeID",
",",
"node",
":=",
"range",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"{",
"if",
"node",
".",
"Type",
"!=",
"wfv1",
".",
"NodeTypePod",
"||",
"node",
".",
"Completed",
"(",
")",
"{",
"// node is not a pod, or it is already complete",
"continue",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"seenPods",
"[",
"nodeID",
"]",
";",
"!",
"ok",
"{",
"node",
".",
"Message",
"=",
"\"",
"\"",
"\n",
"node",
".",
"Phase",
"=",
"wfv1",
".",
"NodeError",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"[",
"nodeID",
"]",
"=",
"node",
"\n",
"woc",
".",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"nodeID",
")",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // podReconciliation is the process by which a workflow will examine all its related
// pods and update the node state before continuing the evaluation of the workflow.
// Records all pods which were observed completed, which will be labeled completed=true
// after successful persist of the workflow. | [
"podReconciliation",
"is",
"the",
"process",
"by",
"which",
"a",
"workflow",
"will",
"examine",
"all",
"its",
"related",
"pods",
"and",
"update",
"the",
"node",
"state",
"before",
"continuing",
"the",
"evaluation",
"of",
"the",
"workflow",
".",
"Records",
"all",
"pods",
"which",
"were",
"observed",
"completed",
"which",
"will",
"be",
"labeled",
"completed",
"=",
"true",
"after",
"successful",
"persist",
"of",
"the",
"workflow",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L463-L540 | train |
argoproj/argo | workflow/controller/operator.go | getAllWorkflowPods | func (woc *wfOperationCtx) getAllWorkflowPods() (*apiv1.PodList, error) {
options := metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s",
common.LabelKeyWorkflow,
woc.wf.ObjectMeta.Name),
}
podList, err := woc.controller.kubeclientset.CoreV1().Pods(woc.wf.Namespace).List(options)
if err != nil {
return nil, errors.InternalWrapError(err)
}
return podList, nil
} | go | func (woc *wfOperationCtx) getAllWorkflowPods() (*apiv1.PodList, error) {
options := metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s",
common.LabelKeyWorkflow,
woc.wf.ObjectMeta.Name),
}
podList, err := woc.controller.kubeclientset.CoreV1().Pods(woc.wf.Namespace).List(options)
if err != nil {
return nil, errors.InternalWrapError(err)
}
return podList, nil
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"getAllWorkflowPods",
"(",
")",
"(",
"*",
"apiv1",
".",
"PodList",
",",
"error",
")",
"{",
"options",
":=",
"metav1",
".",
"ListOptions",
"{",
"LabelSelector",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"common",
".",
"LabelKeyWorkflow",
",",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Name",
")",
",",
"}",
"\n",
"podList",
",",
"err",
":=",
"woc",
".",
"controller",
".",
"kubeclientset",
".",
"CoreV1",
"(",
")",
".",
"Pods",
"(",
"woc",
".",
"wf",
".",
"Namespace",
")",
".",
"List",
"(",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"InternalWrapError",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"podList",
",",
"nil",
"\n",
"}"
] | // getAllWorkflowPods returns all pods related to the current workflow | [
"getAllWorkflowPods",
"returns",
"all",
"pods",
"related",
"to",
"the",
"current",
"workflow"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L592-L603 | train |
argoproj/argo | workflow/controller/operator.go | markWorkflowPhase | func (woc *wfOperationCtx) markWorkflowPhase(phase wfv1.NodePhase, markCompleted bool, message ...string) {
if woc.wf.Status.Phase != phase {
woc.log.Infof("Updated phase %s -> %s", woc.wf.Status.Phase, phase)
woc.updated = true
woc.wf.Status.Phase = phase
if woc.wf.ObjectMeta.Labels == nil {
woc.wf.ObjectMeta.Labels = make(map[string]string)
}
woc.wf.ObjectMeta.Labels[common.LabelKeyPhase] = string(phase)
}
if woc.wf.Status.StartedAt.IsZero() {
woc.updated = true
woc.wf.Status.StartedAt = metav1.Time{Time: time.Now().UTC()}
}
if len(message) > 0 && woc.wf.Status.Message != message[0] {
woc.log.Infof("Updated message %s -> %s", woc.wf.Status.Message, message[0])
woc.updated = true
woc.wf.Status.Message = message[0]
}
switch phase {
case wfv1.NodeSucceeded, wfv1.NodeFailed, wfv1.NodeError:
// wait for all daemon nodes to get terminated before marking workflow completed
if markCompleted && !woc.hasDaemonNodes() {
woc.log.Infof("Marking workflow completed")
woc.wf.Status.FinishedAt = metav1.Time{Time: time.Now().UTC()}
if woc.wf.ObjectMeta.Labels == nil {
woc.wf.ObjectMeta.Labels = make(map[string]string)
}
woc.wf.ObjectMeta.Labels[common.LabelKeyCompleted] = "true"
woc.updated = true
}
}
} | go | func (woc *wfOperationCtx) markWorkflowPhase(phase wfv1.NodePhase, markCompleted bool, message ...string) {
if woc.wf.Status.Phase != phase {
woc.log.Infof("Updated phase %s -> %s", woc.wf.Status.Phase, phase)
woc.updated = true
woc.wf.Status.Phase = phase
if woc.wf.ObjectMeta.Labels == nil {
woc.wf.ObjectMeta.Labels = make(map[string]string)
}
woc.wf.ObjectMeta.Labels[common.LabelKeyPhase] = string(phase)
}
if woc.wf.Status.StartedAt.IsZero() {
woc.updated = true
woc.wf.Status.StartedAt = metav1.Time{Time: time.Now().UTC()}
}
if len(message) > 0 && woc.wf.Status.Message != message[0] {
woc.log.Infof("Updated message %s -> %s", woc.wf.Status.Message, message[0])
woc.updated = true
woc.wf.Status.Message = message[0]
}
switch phase {
case wfv1.NodeSucceeded, wfv1.NodeFailed, wfv1.NodeError:
// wait for all daemon nodes to get terminated before marking workflow completed
if markCompleted && !woc.hasDaemonNodes() {
woc.log.Infof("Marking workflow completed")
woc.wf.Status.FinishedAt = metav1.Time{Time: time.Now().UTC()}
if woc.wf.ObjectMeta.Labels == nil {
woc.wf.ObjectMeta.Labels = make(map[string]string)
}
woc.wf.ObjectMeta.Labels[common.LabelKeyCompleted] = "true"
woc.updated = true
}
}
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"markWorkflowPhase",
"(",
"phase",
"wfv1",
".",
"NodePhase",
",",
"markCompleted",
"bool",
",",
"message",
"...",
"string",
")",
"{",
"if",
"woc",
".",
"wf",
".",
"Status",
".",
"Phase",
"!=",
"phase",
"{",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"woc",
".",
"wf",
".",
"Status",
".",
"Phase",
",",
"phase",
")",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"Phase",
"=",
"phase",
"\n",
"if",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Labels",
"==",
"nil",
"{",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Labels",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Labels",
"[",
"common",
".",
"LabelKeyPhase",
"]",
"=",
"string",
"(",
"phase",
")",
"\n",
"}",
"\n",
"if",
"woc",
".",
"wf",
".",
"Status",
".",
"StartedAt",
".",
"IsZero",
"(",
")",
"{",
"woc",
".",
"updated",
"=",
"true",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"StartedAt",
"=",
"metav1",
".",
"Time",
"{",
"Time",
":",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"message",
")",
">",
"0",
"&&",
"woc",
".",
"wf",
".",
"Status",
".",
"Message",
"!=",
"message",
"[",
"0",
"]",
"{",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"woc",
".",
"wf",
".",
"Status",
".",
"Message",
",",
"message",
"[",
"0",
"]",
")",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"Message",
"=",
"message",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"switch",
"phase",
"{",
"case",
"wfv1",
".",
"NodeSucceeded",
",",
"wfv1",
".",
"NodeFailed",
",",
"wfv1",
".",
"NodeError",
":",
"// wait for all daemon nodes to get terminated before marking workflow completed",
"if",
"markCompleted",
"&&",
"!",
"woc",
".",
"hasDaemonNodes",
"(",
")",
"{",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"FinishedAt",
"=",
"metav1",
".",
"Time",
"{",
"Time",
":",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
"}",
"\n",
"if",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Labels",
"==",
"nil",
"{",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Labels",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"}",
"\n",
"woc",
".",
"wf",
".",
"ObjectMeta",
".",
"Labels",
"[",
"common",
".",
"LabelKeyCompleted",
"]",
"=",
"\"",
"\"",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // markWorkflowPhase is a convenience method to set the phase of the workflow with optional message
// optionally marks the workflow completed, which sets the finishedAt timestamp and completed label | [
"markWorkflowPhase",
"is",
"a",
"convenience",
"method",
"to",
"set",
"the",
"phase",
"of",
"the",
"workflow",
"with",
"optional",
"message",
"optionally",
"marks",
"the",
"workflow",
"completed",
"which",
"sets",
"the",
"finishedAt",
"timestamp",
"and",
"completed",
"label"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L1072-L1105 | train |
argoproj/argo | workflow/controller/operator.go | markNodePhase | func (woc *wfOperationCtx) markNodePhase(nodeName string, phase wfv1.NodePhase, message ...string) *wfv1.NodeStatus {
node := woc.getNodeByName(nodeName)
if node == nil {
panic(fmt.Sprintf("node %s uninitialized", nodeName))
}
if node.Phase != phase {
woc.log.Infof("node %s phase %s -> %s", node, node.Phase, phase)
node.Phase = phase
woc.updated = true
}
if len(message) > 0 {
if message[0] != node.Message {
woc.log.Infof("node %s message: %s", node, message[0])
node.Message = message[0]
woc.updated = true
}
}
if node.Completed() && node.FinishedAt.IsZero() {
node.FinishedAt = metav1.Time{Time: time.Now().UTC()}
woc.log.Infof("node %s finished: %s", node, node.FinishedAt)
woc.updated = true
}
woc.wf.Status.Nodes[node.ID] = *node
return node
} | go | func (woc *wfOperationCtx) markNodePhase(nodeName string, phase wfv1.NodePhase, message ...string) *wfv1.NodeStatus {
node := woc.getNodeByName(nodeName)
if node == nil {
panic(fmt.Sprintf("node %s uninitialized", nodeName))
}
if node.Phase != phase {
woc.log.Infof("node %s phase %s -> %s", node, node.Phase, phase)
node.Phase = phase
woc.updated = true
}
if len(message) > 0 {
if message[0] != node.Message {
woc.log.Infof("node %s message: %s", node, message[0])
node.Message = message[0]
woc.updated = true
}
}
if node.Completed() && node.FinishedAt.IsZero() {
node.FinishedAt = metav1.Time{Time: time.Now().UTC()}
woc.log.Infof("node %s finished: %s", node, node.FinishedAt)
woc.updated = true
}
woc.wf.Status.Nodes[node.ID] = *node
return node
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"markNodePhase",
"(",
"nodeName",
"string",
",",
"phase",
"wfv1",
".",
"NodePhase",
",",
"message",
"...",
"string",
")",
"*",
"wfv1",
".",
"NodeStatus",
"{",
"node",
":=",
"woc",
".",
"getNodeByName",
"(",
"nodeName",
")",
"\n",
"if",
"node",
"==",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"nodeName",
")",
")",
"\n",
"}",
"\n",
"if",
"node",
".",
"Phase",
"!=",
"phase",
"{",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"node",
",",
"node",
".",
"Phase",
",",
"phase",
")",
"\n",
"node",
".",
"Phase",
"=",
"phase",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"}",
"\n",
"if",
"len",
"(",
"message",
")",
">",
"0",
"{",
"if",
"message",
"[",
"0",
"]",
"!=",
"node",
".",
"Message",
"{",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"node",
",",
"message",
"[",
"0",
"]",
")",
"\n",
"node",
".",
"Message",
"=",
"message",
"[",
"0",
"]",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"node",
".",
"Completed",
"(",
")",
"&&",
"node",
".",
"FinishedAt",
".",
"IsZero",
"(",
")",
"{",
"node",
".",
"FinishedAt",
"=",
"metav1",
".",
"Time",
"{",
"Time",
":",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
"}",
"\n",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"node",
",",
"node",
".",
"FinishedAt",
")",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"}",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"[",
"node",
".",
"ID",
"]",
"=",
"*",
"node",
"\n",
"return",
"node",
"\n",
"}"
] | // markNodePhase marks a node with the given phase, creating the node if necessary and handles timestamps | [
"markNodePhase",
"marks",
"a",
"node",
"with",
"the",
"given",
"phase",
"creating",
"the",
"node",
"if",
"necessary",
"and",
"handles",
"timestamps"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L1175-L1199 | train |
argoproj/argo | workflow/controller/operator.go | markNodeErrorClearOuput | func (woc *wfOperationCtx) markNodeErrorClearOuput(nodeName string, err error) *wfv1.NodeStatus {
nodeStatus := woc.markNodeError(nodeName, err)
nodeStatus.Outputs = nil
woc.wf.Status.Nodes[nodeStatus.ID] = *nodeStatus
return nodeStatus
} | go | func (woc *wfOperationCtx) markNodeErrorClearOuput(nodeName string, err error) *wfv1.NodeStatus {
nodeStatus := woc.markNodeError(nodeName, err)
nodeStatus.Outputs = nil
woc.wf.Status.Nodes[nodeStatus.ID] = *nodeStatus
return nodeStatus
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"markNodeErrorClearOuput",
"(",
"nodeName",
"string",
",",
"err",
"error",
")",
"*",
"wfv1",
".",
"NodeStatus",
"{",
"nodeStatus",
":=",
"woc",
".",
"markNodeError",
"(",
"nodeName",
",",
"err",
")",
"\n",
"nodeStatus",
".",
"Outputs",
"=",
"nil",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"[",
"nodeStatus",
".",
"ID",
"]",
"=",
"*",
"nodeStatus",
"\n",
"return",
"nodeStatus",
"\n",
"}"
] | // markNodeErrorClearOuput is a convenience method to mark a node with an error and clear the output | [
"markNodeErrorClearOuput",
"is",
"a",
"convenience",
"method",
"to",
"mark",
"a",
"node",
"with",
"an",
"error",
"and",
"clear",
"the",
"output"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L1202-L1207 | train |
argoproj/argo | workflow/controller/operator.go | markNodeError | func (woc *wfOperationCtx) markNodeError(nodeName string, err error) *wfv1.NodeStatus {
return woc.markNodePhase(nodeName, wfv1.NodeError, err.Error())
} | go | func (woc *wfOperationCtx) markNodeError(nodeName string, err error) *wfv1.NodeStatus {
return woc.markNodePhase(nodeName, wfv1.NodeError, err.Error())
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"markNodeError",
"(",
"nodeName",
"string",
",",
"err",
"error",
")",
"*",
"wfv1",
".",
"NodeStatus",
"{",
"return",
"woc",
".",
"markNodePhase",
"(",
"nodeName",
",",
"wfv1",
".",
"NodeError",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}"
] | // markNodeError is a convenience method to mark a node with an error and set the message from the error | [
"markNodeError",
"is",
"a",
"convenience",
"method",
"to",
"mark",
"a",
"node",
"with",
"an",
"error",
"and",
"set",
"the",
"message",
"from",
"the",
"error"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L1210-L1212 | train |
argoproj/argo | workflow/controller/operator.go | getTemplateOutputsFromScope | func getTemplateOutputsFromScope(tmpl *wfv1.Template, scope *wfScope) (*wfv1.Outputs, error) {
if !tmpl.Outputs.HasOutputs() {
return nil, nil
}
var outputs wfv1.Outputs
if len(tmpl.Outputs.Parameters) > 0 {
outputs.Parameters = make([]wfv1.Parameter, 0)
for _, param := range tmpl.Outputs.Parameters {
val, err := scope.resolveParameter(param.ValueFrom.Parameter)
if err != nil {
return nil, err
}
param.Value = &val
param.ValueFrom = nil
outputs.Parameters = append(outputs.Parameters, param)
}
}
if len(tmpl.Outputs.Artifacts) > 0 {
outputs.Artifacts = make([]wfv1.Artifact, 0)
for _, art := range tmpl.Outputs.Artifacts {
resolvedArt, err := scope.resolveArtifact(art.From)
if err != nil {
return nil, err
}
resolvedArt.Name = art.Name
outputs.Artifacts = append(outputs.Artifacts, *resolvedArt)
}
}
return &outputs, nil
} | go | func getTemplateOutputsFromScope(tmpl *wfv1.Template, scope *wfScope) (*wfv1.Outputs, error) {
if !tmpl.Outputs.HasOutputs() {
return nil, nil
}
var outputs wfv1.Outputs
if len(tmpl.Outputs.Parameters) > 0 {
outputs.Parameters = make([]wfv1.Parameter, 0)
for _, param := range tmpl.Outputs.Parameters {
val, err := scope.resolveParameter(param.ValueFrom.Parameter)
if err != nil {
return nil, err
}
param.Value = &val
param.ValueFrom = nil
outputs.Parameters = append(outputs.Parameters, param)
}
}
if len(tmpl.Outputs.Artifacts) > 0 {
outputs.Artifacts = make([]wfv1.Artifact, 0)
for _, art := range tmpl.Outputs.Artifacts {
resolvedArt, err := scope.resolveArtifact(art.From)
if err != nil {
return nil, err
}
resolvedArt.Name = art.Name
outputs.Artifacts = append(outputs.Artifacts, *resolvedArt)
}
}
return &outputs, nil
} | [
"func",
"getTemplateOutputsFromScope",
"(",
"tmpl",
"*",
"wfv1",
".",
"Template",
",",
"scope",
"*",
"wfScope",
")",
"(",
"*",
"wfv1",
".",
"Outputs",
",",
"error",
")",
"{",
"if",
"!",
"tmpl",
".",
"Outputs",
".",
"HasOutputs",
"(",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"var",
"outputs",
"wfv1",
".",
"Outputs",
"\n",
"if",
"len",
"(",
"tmpl",
".",
"Outputs",
".",
"Parameters",
")",
">",
"0",
"{",
"outputs",
".",
"Parameters",
"=",
"make",
"(",
"[",
"]",
"wfv1",
".",
"Parameter",
",",
"0",
")",
"\n",
"for",
"_",
",",
"param",
":=",
"range",
"tmpl",
".",
"Outputs",
".",
"Parameters",
"{",
"val",
",",
"err",
":=",
"scope",
".",
"resolveParameter",
"(",
"param",
".",
"ValueFrom",
".",
"Parameter",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"param",
".",
"Value",
"=",
"&",
"val",
"\n",
"param",
".",
"ValueFrom",
"=",
"nil",
"\n",
"outputs",
".",
"Parameters",
"=",
"append",
"(",
"outputs",
".",
"Parameters",
",",
"param",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"tmpl",
".",
"Outputs",
".",
"Artifacts",
")",
">",
"0",
"{",
"outputs",
".",
"Artifacts",
"=",
"make",
"(",
"[",
"]",
"wfv1",
".",
"Artifact",
",",
"0",
")",
"\n",
"for",
"_",
",",
"art",
":=",
"range",
"tmpl",
".",
"Outputs",
".",
"Artifacts",
"{",
"resolvedArt",
",",
"err",
":=",
"scope",
".",
"resolveArtifact",
"(",
"art",
".",
"From",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"resolvedArt",
".",
"Name",
"=",
"art",
".",
"Name",
"\n",
"outputs",
".",
"Artifacts",
"=",
"append",
"(",
"outputs",
".",
"Artifacts",
",",
"*",
"resolvedArt",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"outputs",
",",
"nil",
"\n",
"}"
] | // getTemplateOutputsFromScope resolves a template's outputs from the scope of the template | [
"getTemplateOutputsFromScope",
"resolves",
"a",
"template",
"s",
"outputs",
"from",
"the",
"scope",
"of",
"the",
"template"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L1300-L1329 | train |
argoproj/argo | workflow/controller/operator.go | processNodeOutputs | func (woc *wfOperationCtx) processNodeOutputs(scope *wfScope, prefix string, node *wfv1.NodeStatus) {
if node.PodIP != "" {
key := fmt.Sprintf("%s.ip", prefix)
scope.addParamToScope(key, node.PodIP)
}
woc.addOutputsToScope(prefix, node.Outputs, scope)
} | go | func (woc *wfOperationCtx) processNodeOutputs(scope *wfScope, prefix string, node *wfv1.NodeStatus) {
if node.PodIP != "" {
key := fmt.Sprintf("%s.ip", prefix)
scope.addParamToScope(key, node.PodIP)
}
woc.addOutputsToScope(prefix, node.Outputs, scope)
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"processNodeOutputs",
"(",
"scope",
"*",
"wfScope",
",",
"prefix",
"string",
",",
"node",
"*",
"wfv1",
".",
"NodeStatus",
")",
"{",
"if",
"node",
".",
"PodIP",
"!=",
"\"",
"\"",
"{",
"key",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"prefix",
")",
"\n",
"scope",
".",
"addParamToScope",
"(",
"key",
",",
"node",
".",
"PodIP",
")",
"\n",
"}",
"\n",
"woc",
".",
"addOutputsToScope",
"(",
"prefix",
",",
"node",
".",
"Outputs",
",",
"scope",
")",
"\n",
"}"
] | // processNodeOutputs adds all of a nodes outputs to the local scope with the given prefix, as well
// as the global scope, if specified with a globalName | [
"processNodeOutputs",
"adds",
"all",
"of",
"a",
"nodes",
"outputs",
"to",
"the",
"local",
"scope",
"with",
"the",
"given",
"prefix",
"as",
"well",
"as",
"the",
"global",
"scope",
"if",
"specified",
"with",
"a",
"globalName"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L1347-L1353 | train |
argoproj/argo | workflow/controller/operator.go | addParamToGlobalScope | func (woc *wfOperationCtx) addParamToGlobalScope(param wfv1.Parameter) {
if param.GlobalName == "" {
return
}
index := -1
if woc.wf.Status.Outputs != nil {
for i, gParam := range woc.wf.Status.Outputs.Parameters {
if gParam.Name == param.GlobalName {
index = i
break
}
}
} else {
woc.wf.Status.Outputs = &wfv1.Outputs{}
}
paramName := fmt.Sprintf("workflow.outputs.parameters.%s", param.GlobalName)
woc.globalParams[paramName] = *param.Value
if index == -1 {
woc.log.Infof("setting %s: '%s'", paramName, *param.Value)
gParam := wfv1.Parameter{Name: param.GlobalName, Value: param.Value}
woc.wf.Status.Outputs.Parameters = append(woc.wf.Status.Outputs.Parameters, gParam)
woc.updated = true
} else {
prevVal := *woc.wf.Status.Outputs.Parameters[index].Value
if prevVal != *param.Value {
woc.log.Infof("overwriting %s: '%s' -> '%s'", paramName, *woc.wf.Status.Outputs.Parameters[index].Value, *param.Value)
woc.wf.Status.Outputs.Parameters[index].Value = param.Value
woc.updated = true
}
}
} | go | func (woc *wfOperationCtx) addParamToGlobalScope(param wfv1.Parameter) {
if param.GlobalName == "" {
return
}
index := -1
if woc.wf.Status.Outputs != nil {
for i, gParam := range woc.wf.Status.Outputs.Parameters {
if gParam.Name == param.GlobalName {
index = i
break
}
}
} else {
woc.wf.Status.Outputs = &wfv1.Outputs{}
}
paramName := fmt.Sprintf("workflow.outputs.parameters.%s", param.GlobalName)
woc.globalParams[paramName] = *param.Value
if index == -1 {
woc.log.Infof("setting %s: '%s'", paramName, *param.Value)
gParam := wfv1.Parameter{Name: param.GlobalName, Value: param.Value}
woc.wf.Status.Outputs.Parameters = append(woc.wf.Status.Outputs.Parameters, gParam)
woc.updated = true
} else {
prevVal := *woc.wf.Status.Outputs.Parameters[index].Value
if prevVal != *param.Value {
woc.log.Infof("overwriting %s: '%s' -> '%s'", paramName, *woc.wf.Status.Outputs.Parameters[index].Value, *param.Value)
woc.wf.Status.Outputs.Parameters[index].Value = param.Value
woc.updated = true
}
}
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"addParamToGlobalScope",
"(",
"param",
"wfv1",
".",
"Parameter",
")",
"{",
"if",
"param",
".",
"GlobalName",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"index",
":=",
"-",
"1",
"\n",
"if",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
"!=",
"nil",
"{",
"for",
"i",
",",
"gParam",
":=",
"range",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
".",
"Parameters",
"{",
"if",
"gParam",
".",
"Name",
"==",
"param",
".",
"GlobalName",
"{",
"index",
"=",
"i",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
"=",
"&",
"wfv1",
".",
"Outputs",
"{",
"}",
"\n",
"}",
"\n",
"paramName",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"param",
".",
"GlobalName",
")",
"\n",
"woc",
".",
"globalParams",
"[",
"paramName",
"]",
"=",
"*",
"param",
".",
"Value",
"\n",
"if",
"index",
"==",
"-",
"1",
"{",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"paramName",
",",
"*",
"param",
".",
"Value",
")",
"\n",
"gParam",
":=",
"wfv1",
".",
"Parameter",
"{",
"Name",
":",
"param",
".",
"GlobalName",
",",
"Value",
":",
"param",
".",
"Value",
"}",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
".",
"Parameters",
"=",
"append",
"(",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
".",
"Parameters",
",",
"gParam",
")",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"}",
"else",
"{",
"prevVal",
":=",
"*",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
".",
"Parameters",
"[",
"index",
"]",
".",
"Value",
"\n",
"if",
"prevVal",
"!=",
"*",
"param",
".",
"Value",
"{",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"paramName",
",",
"*",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
".",
"Parameters",
"[",
"index",
"]",
".",
"Value",
",",
"*",
"param",
".",
"Value",
")",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
".",
"Parameters",
"[",
"index",
"]",
".",
"Value",
"=",
"param",
".",
"Value",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // addParamToGlobalScope exports any desired node outputs to the global scope, and adds it to the global outputs. | [
"addParamToGlobalScope",
"exports",
"any",
"desired",
"node",
"outputs",
"to",
"the",
"global",
"scope",
"and",
"adds",
"it",
"to",
"the",
"global",
"outputs",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L1450-L1480 | train |
argoproj/argo | workflow/controller/operator.go | addArtifactToGlobalScope | func (woc *wfOperationCtx) addArtifactToGlobalScope(art wfv1.Artifact, scope *wfScope) {
if art.GlobalName == "" {
return
}
globalArtName := fmt.Sprintf("workflow.outputs.artifacts.%s", art.GlobalName)
if woc.wf.Status.Outputs != nil {
for i, gArt := range woc.wf.Status.Outputs.Artifacts {
if gArt.Name == art.GlobalName {
// global output already exists. overwrite the value if different
art.Name = art.GlobalName
art.GlobalName = ""
art.Path = ""
if !reflect.DeepEqual(woc.wf.Status.Outputs.Artifacts[i], art) {
woc.wf.Status.Outputs.Artifacts[i] = art
if scope != nil {
scope.addArtifactToScope(globalArtName, art)
}
woc.log.Infof("overwriting %s: %v", globalArtName, art)
woc.updated = true
}
return
}
}
} else {
woc.wf.Status.Outputs = &wfv1.Outputs{}
}
// global output does not yet exist
art.Name = art.GlobalName
art.GlobalName = ""
art.Path = ""
woc.log.Infof("setting %s: %v", globalArtName, art)
woc.wf.Status.Outputs.Artifacts = append(woc.wf.Status.Outputs.Artifacts, art)
if scope != nil {
scope.addArtifactToScope(globalArtName, art)
}
woc.updated = true
} | go | func (woc *wfOperationCtx) addArtifactToGlobalScope(art wfv1.Artifact, scope *wfScope) {
if art.GlobalName == "" {
return
}
globalArtName := fmt.Sprintf("workflow.outputs.artifacts.%s", art.GlobalName)
if woc.wf.Status.Outputs != nil {
for i, gArt := range woc.wf.Status.Outputs.Artifacts {
if gArt.Name == art.GlobalName {
// global output already exists. overwrite the value if different
art.Name = art.GlobalName
art.GlobalName = ""
art.Path = ""
if !reflect.DeepEqual(woc.wf.Status.Outputs.Artifacts[i], art) {
woc.wf.Status.Outputs.Artifacts[i] = art
if scope != nil {
scope.addArtifactToScope(globalArtName, art)
}
woc.log.Infof("overwriting %s: %v", globalArtName, art)
woc.updated = true
}
return
}
}
} else {
woc.wf.Status.Outputs = &wfv1.Outputs{}
}
// global output does not yet exist
art.Name = art.GlobalName
art.GlobalName = ""
art.Path = ""
woc.log.Infof("setting %s: %v", globalArtName, art)
woc.wf.Status.Outputs.Artifacts = append(woc.wf.Status.Outputs.Artifacts, art)
if scope != nil {
scope.addArtifactToScope(globalArtName, art)
}
woc.updated = true
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"addArtifactToGlobalScope",
"(",
"art",
"wfv1",
".",
"Artifact",
",",
"scope",
"*",
"wfScope",
")",
"{",
"if",
"art",
".",
"GlobalName",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"globalArtName",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"art",
".",
"GlobalName",
")",
"\n",
"if",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
"!=",
"nil",
"{",
"for",
"i",
",",
"gArt",
":=",
"range",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
".",
"Artifacts",
"{",
"if",
"gArt",
".",
"Name",
"==",
"art",
".",
"GlobalName",
"{",
"// global output already exists. overwrite the value if different",
"art",
".",
"Name",
"=",
"art",
".",
"GlobalName",
"\n",
"art",
".",
"GlobalName",
"=",
"\"",
"\"",
"\n",
"art",
".",
"Path",
"=",
"\"",
"\"",
"\n",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
".",
"Artifacts",
"[",
"i",
"]",
",",
"art",
")",
"{",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
".",
"Artifacts",
"[",
"i",
"]",
"=",
"art",
"\n",
"if",
"scope",
"!=",
"nil",
"{",
"scope",
".",
"addArtifactToScope",
"(",
"globalArtName",
",",
"art",
")",
"\n",
"}",
"\n",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"globalArtName",
",",
"art",
")",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
"=",
"&",
"wfv1",
".",
"Outputs",
"{",
"}",
"\n",
"}",
"\n",
"// global output does not yet exist",
"art",
".",
"Name",
"=",
"art",
".",
"GlobalName",
"\n",
"art",
".",
"GlobalName",
"=",
"\"",
"\"",
"\n",
"art",
".",
"Path",
"=",
"\"",
"\"",
"\n",
"woc",
".",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"globalArtName",
",",
"art",
")",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
".",
"Artifacts",
"=",
"append",
"(",
"woc",
".",
"wf",
".",
"Status",
".",
"Outputs",
".",
"Artifacts",
",",
"art",
")",
"\n",
"if",
"scope",
"!=",
"nil",
"{",
"scope",
".",
"addArtifactToScope",
"(",
"globalArtName",
",",
"art",
")",
"\n",
"}",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"}"
] | // addArtifactToGlobalScope exports any desired node outputs to the global scope
// Optionally adds to a local scope if supplied | [
"addArtifactToGlobalScope",
"exports",
"any",
"desired",
"node",
"outputs",
"to",
"the",
"global",
"scope",
"Optionally",
"adds",
"to",
"a",
"local",
"scope",
"if",
"supplied"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L1484-L1520 | train |
argoproj/argo | workflow/controller/operator.go | addChildNode | func (woc *wfOperationCtx) addChildNode(parent string, child string) {
parentID := woc.wf.NodeID(parent)
childID := woc.wf.NodeID(child)
node, ok := woc.wf.Status.Nodes[parentID]
if !ok {
panic(fmt.Sprintf("parent node %s not initialized", parent))
}
for _, nodeID := range node.Children {
if childID == nodeID {
// already exists
return
}
}
node.Children = append(node.Children, childID)
woc.wf.Status.Nodes[parentID] = node
woc.updated = true
} | go | func (woc *wfOperationCtx) addChildNode(parent string, child string) {
parentID := woc.wf.NodeID(parent)
childID := woc.wf.NodeID(child)
node, ok := woc.wf.Status.Nodes[parentID]
if !ok {
panic(fmt.Sprintf("parent node %s not initialized", parent))
}
for _, nodeID := range node.Children {
if childID == nodeID {
// already exists
return
}
}
node.Children = append(node.Children, childID)
woc.wf.Status.Nodes[parentID] = node
woc.updated = true
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"addChildNode",
"(",
"parent",
"string",
",",
"child",
"string",
")",
"{",
"parentID",
":=",
"woc",
".",
"wf",
".",
"NodeID",
"(",
"parent",
")",
"\n",
"childID",
":=",
"woc",
".",
"wf",
".",
"NodeID",
"(",
"child",
")",
"\n",
"node",
",",
"ok",
":=",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"[",
"parentID",
"]",
"\n",
"if",
"!",
"ok",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"parent",
")",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"nodeID",
":=",
"range",
"node",
".",
"Children",
"{",
"if",
"childID",
"==",
"nodeID",
"{",
"// already exists",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"node",
".",
"Children",
"=",
"append",
"(",
"node",
".",
"Children",
",",
"childID",
")",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
"[",
"parentID",
"]",
"=",
"node",
"\n",
"woc",
".",
"updated",
"=",
"true",
"\n",
"}"
] | // addChildNode adds a nodeID as a child to a parent
// parent and child are both node names | [
"addChildNode",
"adds",
"a",
"nodeID",
"as",
"a",
"child",
"to",
"a",
"parent",
"parent",
"and",
"child",
"are",
"both",
"node",
"names"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L1524-L1540 | train |
argoproj/argo | workflow/controller/operator.go | executeResource | func (woc *wfOperationCtx) executeResource(nodeName string, tmpl *wfv1.Template, boundaryID string) *wfv1.NodeStatus {
node := woc.getNodeByName(nodeName)
if node != nil {
return node
}
mainCtr := woc.newExecContainer(common.MainContainerName)
mainCtr.Command = []string{"argoexec", "resource", tmpl.Resource.Action}
mainCtr.VolumeMounts = []apiv1.VolumeMount{
volumeMountPodMetadata,
}
_, err := woc.createWorkflowPod(nodeName, *mainCtr, tmpl)
if err != nil {
return woc.initializeNode(nodeName, wfv1.NodeTypePod, tmpl.Name, boundaryID, wfv1.NodeError, err.Error())
}
return woc.initializeNode(nodeName, wfv1.NodeTypePod, tmpl.Name, boundaryID, wfv1.NodePending)
} | go | func (woc *wfOperationCtx) executeResource(nodeName string, tmpl *wfv1.Template, boundaryID string) *wfv1.NodeStatus {
node := woc.getNodeByName(nodeName)
if node != nil {
return node
}
mainCtr := woc.newExecContainer(common.MainContainerName)
mainCtr.Command = []string{"argoexec", "resource", tmpl.Resource.Action}
mainCtr.VolumeMounts = []apiv1.VolumeMount{
volumeMountPodMetadata,
}
_, err := woc.createWorkflowPod(nodeName, *mainCtr, tmpl)
if err != nil {
return woc.initializeNode(nodeName, wfv1.NodeTypePod, tmpl.Name, boundaryID, wfv1.NodeError, err.Error())
}
return woc.initializeNode(nodeName, wfv1.NodeTypePod, tmpl.Name, boundaryID, wfv1.NodePending)
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"executeResource",
"(",
"nodeName",
"string",
",",
"tmpl",
"*",
"wfv1",
".",
"Template",
",",
"boundaryID",
"string",
")",
"*",
"wfv1",
".",
"NodeStatus",
"{",
"node",
":=",
"woc",
".",
"getNodeByName",
"(",
"nodeName",
")",
"\n",
"if",
"node",
"!=",
"nil",
"{",
"return",
"node",
"\n",
"}",
"\n",
"mainCtr",
":=",
"woc",
".",
"newExecContainer",
"(",
"common",
".",
"MainContainerName",
")",
"\n",
"mainCtr",
".",
"Command",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"tmpl",
".",
"Resource",
".",
"Action",
"}",
"\n",
"mainCtr",
".",
"VolumeMounts",
"=",
"[",
"]",
"apiv1",
".",
"VolumeMount",
"{",
"volumeMountPodMetadata",
",",
"}",
"\n",
"_",
",",
"err",
":=",
"woc",
".",
"createWorkflowPod",
"(",
"nodeName",
",",
"*",
"mainCtr",
",",
"tmpl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"woc",
".",
"initializeNode",
"(",
"nodeName",
",",
"wfv1",
".",
"NodeTypePod",
",",
"tmpl",
".",
"Name",
",",
"boundaryID",
",",
"wfv1",
".",
"NodeError",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"woc",
".",
"initializeNode",
"(",
"nodeName",
",",
"wfv1",
".",
"NodeTypePod",
",",
"tmpl",
".",
"Name",
",",
"boundaryID",
",",
"wfv1",
".",
"NodePending",
")",
"\n",
"}"
] | // executeResource is runs a kubectl command against a manifest | [
"executeResource",
"is",
"runs",
"a",
"kubectl",
"command",
"against",
"a",
"manifest"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L1543-L1558 | train |
argoproj/argo | workflow/controller/operator.go | getSize | func (woc *wfOperationCtx) getSize() int {
nodeContent, err := json.Marshal(woc.wf)
if err != nil {
return -1
}
compressNodeSize := len(woc.wf.Status.CompressedNodes)
if compressNodeSize > 0 {
nodeStatus, err := json.Marshal(woc.wf.Status.Nodes)
if err != nil {
return -1
}
return len(nodeContent) - len(nodeStatus)
}
return len(nodeContent)
} | go | func (woc *wfOperationCtx) getSize() int {
nodeContent, err := json.Marshal(woc.wf)
if err != nil {
return -1
}
compressNodeSize := len(woc.wf.Status.CompressedNodes)
if compressNodeSize > 0 {
nodeStatus, err := json.Marshal(woc.wf.Status.Nodes)
if err != nil {
return -1
}
return len(nodeContent) - len(nodeStatus)
}
return len(nodeContent)
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"getSize",
"(",
")",
"int",
"{",
"nodeContent",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"woc",
".",
"wf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n\n",
"compressNodeSize",
":=",
"len",
"(",
"woc",
".",
"wf",
".",
"Status",
".",
"CompressedNodes",
")",
"\n\n",
"if",
"compressNodeSize",
">",
"0",
"{",
"nodeStatus",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"len",
"(",
"nodeContent",
")",
"-",
"len",
"(",
"nodeStatus",
")",
"\n",
"}",
"\n",
"return",
"len",
"(",
"nodeContent",
")",
"\n",
"}"
] | // getSize return the entire workflow json string size | [
"getSize",
"return",
"the",
"entire",
"workflow",
"json",
"string",
"size"
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L1644-L1660 | train |
argoproj/argo | workflow/controller/operator.go | checkAndCompress | func (woc *wfOperationCtx) checkAndCompress() error {
if woc.wf.Status.CompressedNodes != "" || (woc.wf.Status.CompressedNodes == "" && woc.getSize() >= maxWorkflowSize) {
nodeContent, err := json.Marshal(woc.wf.Status.Nodes)
if err != nil {
return errors.InternalWrapError(err)
}
buff := string(nodeContent)
woc.wf.Status.CompressedNodes = file.CompressEncodeString(buff)
}
if woc.wf.Status.CompressedNodes != "" && woc.getSize() >= maxWorkflowSize {
return errors.InternalError(fmt.Sprintf("Workflow is longer than maximum allowed size. Size=%d", woc.getSize()))
}
return nil
} | go | func (woc *wfOperationCtx) checkAndCompress() error {
if woc.wf.Status.CompressedNodes != "" || (woc.wf.Status.CompressedNodes == "" && woc.getSize() >= maxWorkflowSize) {
nodeContent, err := json.Marshal(woc.wf.Status.Nodes)
if err != nil {
return errors.InternalWrapError(err)
}
buff := string(nodeContent)
woc.wf.Status.CompressedNodes = file.CompressEncodeString(buff)
}
if woc.wf.Status.CompressedNodes != "" && woc.getSize() >= maxWorkflowSize {
return errors.InternalError(fmt.Sprintf("Workflow is longer than maximum allowed size. Size=%d", woc.getSize()))
}
return nil
} | [
"func",
"(",
"woc",
"*",
"wfOperationCtx",
")",
"checkAndCompress",
"(",
")",
"error",
"{",
"if",
"woc",
".",
"wf",
".",
"Status",
".",
"CompressedNodes",
"!=",
"\"",
"\"",
"||",
"(",
"woc",
".",
"wf",
".",
"Status",
".",
"CompressedNodes",
"==",
"\"",
"\"",
"&&",
"woc",
".",
"getSize",
"(",
")",
">=",
"maxWorkflowSize",
")",
"{",
"nodeContent",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"woc",
".",
"wf",
".",
"Status",
".",
"Nodes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"InternalWrapError",
"(",
"err",
")",
"\n",
"}",
"\n",
"buff",
":=",
"string",
"(",
"nodeContent",
")",
"\n",
"woc",
".",
"wf",
".",
"Status",
".",
"CompressedNodes",
"=",
"file",
".",
"CompressEncodeString",
"(",
"buff",
")",
"\n",
"}",
"\n\n",
"if",
"woc",
".",
"wf",
".",
"Status",
".",
"CompressedNodes",
"!=",
"\"",
"\"",
"&&",
"woc",
".",
"getSize",
"(",
")",
">=",
"maxWorkflowSize",
"{",
"return",
"errors",
".",
"InternalError",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"woc",
".",
"getSize",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // checkAndCompress will check the workflow size and compress node status if total workflow size is more than maxWorkflowSize.
// The compressed content will be assign to compressedNodes element and clear the nodestatus map. | [
"checkAndCompress",
"will",
"check",
"the",
"workflow",
"size",
"and",
"compress",
"node",
"status",
"if",
"total",
"workflow",
"size",
"is",
"more",
"than",
"maxWorkflowSize",
".",
"The",
"compressed",
"content",
"will",
"be",
"assign",
"to",
"compressedNodes",
"element",
"and",
"clear",
"the",
"nodestatus",
"map",
"."
] | 4e37a444bde2a034885d0db35f7b38684505063e | https://github.com/argoproj/argo/blob/4e37a444bde2a034885d0db35f7b38684505063e/workflow/controller/operator.go#L1664-L1680 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/permissions.go | NewUserPermission | func NewUserPermission(fields []*querypb.Field, values []sqltypes.Value) *tabletmanagerdatapb.UserPermission {
up := &tabletmanagerdatapb.UserPermission{
Privileges: make(map[string]string),
}
for i, field := range fields {
switch strings.ToLower(field.Name) {
case "host":
up.Host = values[i].ToString()
case "user":
up.User = values[i].ToString()
case "password":
up.PasswordChecksum = crc64.Checksum(values[i].ToBytes(), hashTable)
case "password_last_changed":
// we skip this one, as the value may be
// different on master and slaves.
default:
up.Privileges[field.Name] = values[i].ToString()
}
}
return up
} | go | func NewUserPermission(fields []*querypb.Field, values []sqltypes.Value) *tabletmanagerdatapb.UserPermission {
up := &tabletmanagerdatapb.UserPermission{
Privileges: make(map[string]string),
}
for i, field := range fields {
switch strings.ToLower(field.Name) {
case "host":
up.Host = values[i].ToString()
case "user":
up.User = values[i].ToString()
case "password":
up.PasswordChecksum = crc64.Checksum(values[i].ToBytes(), hashTable)
case "password_last_changed":
// we skip this one, as the value may be
// different on master and slaves.
default:
up.Privileges[field.Name] = values[i].ToString()
}
}
return up
} | [
"func",
"NewUserPermission",
"(",
"fields",
"[",
"]",
"*",
"querypb",
".",
"Field",
",",
"values",
"[",
"]",
"sqltypes",
".",
"Value",
")",
"*",
"tabletmanagerdatapb",
".",
"UserPermission",
"{",
"up",
":=",
"&",
"tabletmanagerdatapb",
".",
"UserPermission",
"{",
"Privileges",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
",",
"}",
"\n",
"for",
"i",
",",
"field",
":=",
"range",
"fields",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"field",
".",
"Name",
")",
"{",
"case",
"\"",
"\"",
":",
"up",
".",
"Host",
"=",
"values",
"[",
"i",
"]",
".",
"ToString",
"(",
")",
"\n",
"case",
"\"",
"\"",
":",
"up",
".",
"User",
"=",
"values",
"[",
"i",
"]",
".",
"ToString",
"(",
")",
"\n",
"case",
"\"",
"\"",
":",
"up",
".",
"PasswordChecksum",
"=",
"crc64",
".",
"Checksum",
"(",
"values",
"[",
"i",
"]",
".",
"ToBytes",
"(",
")",
",",
"hashTable",
")",
"\n",
"case",
"\"",
"\"",
":",
"// we skip this one, as the value may be",
"// different on master and slaves.",
"default",
":",
"up",
".",
"Privileges",
"[",
"field",
".",
"Name",
"]",
"=",
"values",
"[",
"i",
"]",
".",
"ToString",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"up",
"\n",
"}"
] | // NewUserPermission is a helper method to create a tabletmanagerdatapb.UserPermission | [
"NewUserPermission",
"is",
"a",
"helper",
"method",
"to",
"create",
"a",
"tabletmanagerdatapb",
".",
"UserPermission"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/permissions.go#L60-L80 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/permissions.go | UserPermissionString | func UserPermissionString(up *tabletmanagerdatapb.UserPermission) string {
var passwd string
if up.PasswordChecksum == 0 {
passwd = "NoPassword"
} else {
passwd = fmt.Sprintf("PasswordChecksum(%v)", up.PasswordChecksum)
}
return "UserPermission " + passwd + printPrivileges(up.Privileges)
} | go | func UserPermissionString(up *tabletmanagerdatapb.UserPermission) string {
var passwd string
if up.PasswordChecksum == 0 {
passwd = "NoPassword"
} else {
passwd = fmt.Sprintf("PasswordChecksum(%v)", up.PasswordChecksum)
}
return "UserPermission " + passwd + printPrivileges(up.Privileges)
} | [
"func",
"UserPermissionString",
"(",
"up",
"*",
"tabletmanagerdatapb",
".",
"UserPermission",
")",
"string",
"{",
"var",
"passwd",
"string",
"\n",
"if",
"up",
".",
"PasswordChecksum",
"==",
"0",
"{",
"passwd",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"passwd",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"up",
".",
"PasswordChecksum",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"+",
"passwd",
"+",
"printPrivileges",
"(",
"up",
".",
"Privileges",
")",
"\n",
"}"
] | // UserPermissionString pretty-prints a UserPermission | [
"UserPermissionString",
"pretty",
"-",
"prints",
"a",
"UserPermission"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/permissions.go#L88-L96 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/permissions.go | NewDbPermission | func NewDbPermission(fields []*querypb.Field, values []sqltypes.Value) *tabletmanagerdatapb.DbPermission {
up := &tabletmanagerdatapb.DbPermission{
Privileges: make(map[string]string),
}
for i, field := range fields {
switch field.Name {
case "Host":
up.Host = values[i].ToString()
case "Db":
up.Db = values[i].ToString()
case "User":
up.User = values[i].ToString()
default:
up.Privileges[field.Name] = values[i].ToString()
}
}
return up
} | go | func NewDbPermission(fields []*querypb.Field, values []sqltypes.Value) *tabletmanagerdatapb.DbPermission {
up := &tabletmanagerdatapb.DbPermission{
Privileges: make(map[string]string),
}
for i, field := range fields {
switch field.Name {
case "Host":
up.Host = values[i].ToString()
case "Db":
up.Db = values[i].ToString()
case "User":
up.User = values[i].ToString()
default:
up.Privileges[field.Name] = values[i].ToString()
}
}
return up
} | [
"func",
"NewDbPermission",
"(",
"fields",
"[",
"]",
"*",
"querypb",
".",
"Field",
",",
"values",
"[",
"]",
"sqltypes",
".",
"Value",
")",
"*",
"tabletmanagerdatapb",
".",
"DbPermission",
"{",
"up",
":=",
"&",
"tabletmanagerdatapb",
".",
"DbPermission",
"{",
"Privileges",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
",",
"}",
"\n",
"for",
"i",
",",
"field",
":=",
"range",
"fields",
"{",
"switch",
"field",
".",
"Name",
"{",
"case",
"\"",
"\"",
":",
"up",
".",
"Host",
"=",
"values",
"[",
"i",
"]",
".",
"ToString",
"(",
")",
"\n",
"case",
"\"",
"\"",
":",
"up",
".",
"Db",
"=",
"values",
"[",
"i",
"]",
".",
"ToString",
"(",
")",
"\n",
"case",
"\"",
"\"",
":",
"up",
".",
"User",
"=",
"values",
"[",
"i",
"]",
".",
"ToString",
"(",
")",
"\n",
"default",
":",
"up",
".",
"Privileges",
"[",
"field",
".",
"Name",
"]",
"=",
"values",
"[",
"i",
"]",
".",
"ToString",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"up",
"\n",
"}"
] | // NewDbPermission is a helper method to create a tabletmanagerdatapb.DbPermission | [
"NewDbPermission",
"is",
"a",
"helper",
"method",
"to",
"create",
"a",
"tabletmanagerdatapb",
".",
"DbPermission"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/permissions.go#L109-L126 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/permissions.go | DbPermissionPrimaryKey | func DbPermissionPrimaryKey(dp *tabletmanagerdatapb.DbPermission) string {
return dp.Host + ":" + dp.Db + ":" + dp.User
} | go | func DbPermissionPrimaryKey(dp *tabletmanagerdatapb.DbPermission) string {
return dp.Host + ":" + dp.Db + ":" + dp.User
} | [
"func",
"DbPermissionPrimaryKey",
"(",
"dp",
"*",
"tabletmanagerdatapb",
".",
"DbPermission",
")",
"string",
"{",
"return",
"dp",
".",
"Host",
"+",
"\"",
"\"",
"+",
"dp",
".",
"Db",
"+",
"\"",
"\"",
"+",
"dp",
".",
"User",
"\n",
"}"
] | // DbPermissionPrimaryKey returns the sorting key for a DbPermission | [
"DbPermissionPrimaryKey",
"returns",
"the",
"sorting",
"key",
"for",
"a",
"DbPermission"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/permissions.go#L129-L131 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/permissions.go | PermissionsString | func PermissionsString(permissions *tabletmanagerdatapb.Permissions) string {
return printPermissions("User", userPermissionList(permissions.UserPermissions)) +
printPermissions("Db", dbPermissionList(permissions.DbPermissions))
} | go | func PermissionsString(permissions *tabletmanagerdatapb.Permissions) string {
return printPermissions("User", userPermissionList(permissions.UserPermissions)) +
printPermissions("Db", dbPermissionList(permissions.DbPermissions))
} | [
"func",
"PermissionsString",
"(",
"permissions",
"*",
"tabletmanagerdatapb",
".",
"Permissions",
")",
"string",
"{",
"return",
"printPermissions",
"(",
"\"",
"\"",
",",
"userPermissionList",
"(",
"permissions",
".",
"UserPermissions",
")",
")",
"+",
"printPermissions",
"(",
"\"",
"\"",
",",
"dbPermissionList",
"(",
"permissions",
".",
"DbPermissions",
")",
")",
"\n",
"}"
] | // PermissionsString pretty-prints Permissions | [
"PermissionsString",
"pretty",
"-",
"prints",
"Permissions"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/permissions.go#L158-L161 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/permissions.go | DiffPermissions | func DiffPermissions(leftName string, left *tabletmanagerdatapb.Permissions, rightName string, right *tabletmanagerdatapb.Permissions, er concurrency.ErrorRecorder) {
diffPermissions("user", leftName, userPermissionList(left.UserPermissions), rightName, userPermissionList(right.UserPermissions), er)
diffPermissions("db", leftName, dbPermissionList(left.DbPermissions), rightName, dbPermissionList(right.DbPermissions), er)
} | go | func DiffPermissions(leftName string, left *tabletmanagerdatapb.Permissions, rightName string, right *tabletmanagerdatapb.Permissions, er concurrency.ErrorRecorder) {
diffPermissions("user", leftName, userPermissionList(left.UserPermissions), rightName, userPermissionList(right.UserPermissions), er)
diffPermissions("db", leftName, dbPermissionList(left.DbPermissions), rightName, dbPermissionList(right.DbPermissions), er)
} | [
"func",
"DiffPermissions",
"(",
"leftName",
"string",
",",
"left",
"*",
"tabletmanagerdatapb",
".",
"Permissions",
",",
"rightName",
"string",
",",
"right",
"*",
"tabletmanagerdatapb",
".",
"Permissions",
",",
"er",
"concurrency",
".",
"ErrorRecorder",
")",
"{",
"diffPermissions",
"(",
"\"",
"\"",
",",
"leftName",
",",
"userPermissionList",
"(",
"left",
".",
"UserPermissions",
")",
",",
"rightName",
",",
"userPermissionList",
"(",
"right",
".",
"UserPermissions",
")",
",",
"er",
")",
"\n",
"diffPermissions",
"(",
"\"",
"\"",
",",
"leftName",
",",
"dbPermissionList",
"(",
"left",
".",
"DbPermissions",
")",
",",
"rightName",
",",
"dbPermissionList",
"(",
"right",
".",
"DbPermissions",
")",
",",
"er",
")",
"\n",
"}"
] | // DiffPermissions records the errors between two permission sets | [
"DiffPermissions",
"records",
"the",
"errors",
"between",
"two",
"permission",
"sets"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/permissions.go#L205-L208 | train |
vitessio/vitess | go/vt/mysqlctl/tmutils/permissions.go | DiffPermissionsToArray | func DiffPermissionsToArray(leftName string, left *tabletmanagerdatapb.Permissions, rightName string, right *tabletmanagerdatapb.Permissions) (result []string) {
er := concurrency.AllErrorRecorder{}
DiffPermissions(leftName, left, rightName, right, &er)
if er.HasErrors() {
return er.ErrorStrings()
}
return nil
} | go | func DiffPermissionsToArray(leftName string, left *tabletmanagerdatapb.Permissions, rightName string, right *tabletmanagerdatapb.Permissions) (result []string) {
er := concurrency.AllErrorRecorder{}
DiffPermissions(leftName, left, rightName, right, &er)
if er.HasErrors() {
return er.ErrorStrings()
}
return nil
} | [
"func",
"DiffPermissionsToArray",
"(",
"leftName",
"string",
",",
"left",
"*",
"tabletmanagerdatapb",
".",
"Permissions",
",",
"rightName",
"string",
",",
"right",
"*",
"tabletmanagerdatapb",
".",
"Permissions",
")",
"(",
"result",
"[",
"]",
"string",
")",
"{",
"er",
":=",
"concurrency",
".",
"AllErrorRecorder",
"{",
"}",
"\n",
"DiffPermissions",
"(",
"leftName",
",",
"left",
",",
"rightName",
",",
"right",
",",
"&",
"er",
")",
"\n",
"if",
"er",
".",
"HasErrors",
"(",
")",
"{",
"return",
"er",
".",
"ErrorStrings",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // DiffPermissionsToArray difs two sets of permissions, and returns the difference | [
"DiffPermissionsToArray",
"difs",
"two",
"sets",
"of",
"permissions",
"and",
"returns",
"the",
"difference"
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/mysqlctl/tmutils/permissions.go#L211-L218 | train |
vitessio/vitess | go/vt/vitessdriver/rows.go | newRows | func newRows(qr *sqltypes.Result, c *converter) driver.Rows {
return &rows{qr: qr, convert: c}
} | go | func newRows(qr *sqltypes.Result, c *converter) driver.Rows {
return &rows{qr: qr, convert: c}
} | [
"func",
"newRows",
"(",
"qr",
"*",
"sqltypes",
".",
"Result",
",",
"c",
"*",
"converter",
")",
"driver",
".",
"Rows",
"{",
"return",
"&",
"rows",
"{",
"qr",
":",
"qr",
",",
"convert",
":",
"c",
"}",
"\n",
"}"
] | // newRows creates a new rows from qr. | [
"newRows",
"creates",
"a",
"new",
"rows",
"from",
"qr",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vitessdriver/rows.go#L35-L37 | train |
vitessio/vitess | go/vt/servenv/unix_socket.go | serveSocketFile | func serveSocketFile() {
if SocketFile == nil || *SocketFile == "" {
log.Infof("Not listening on socket file")
return
}
name := *SocketFile
// try to delete if file exists
if _, err := os.Stat(name); err == nil {
err = os.Remove(name)
if err != nil {
log.Exitf("Cannot remove socket file %v: %v", name, err)
}
}
l, err := net.Listen("unix", name)
if err != nil {
log.Exitf("Error listening on socket file %v: %v", name, err)
}
log.Infof("Listening on socket file %v for gRPC", name)
go GRPCServer.Serve(l)
} | go | func serveSocketFile() {
if SocketFile == nil || *SocketFile == "" {
log.Infof("Not listening on socket file")
return
}
name := *SocketFile
// try to delete if file exists
if _, err := os.Stat(name); err == nil {
err = os.Remove(name)
if err != nil {
log.Exitf("Cannot remove socket file %v: %v", name, err)
}
}
l, err := net.Listen("unix", name)
if err != nil {
log.Exitf("Error listening on socket file %v: %v", name, err)
}
log.Infof("Listening on socket file %v for gRPC", name)
go GRPCServer.Serve(l)
} | [
"func",
"serveSocketFile",
"(",
")",
"{",
"if",
"SocketFile",
"==",
"nil",
"||",
"*",
"SocketFile",
"==",
"\"",
"\"",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"name",
":=",
"*",
"SocketFile",
"\n\n",
"// try to delete if file exists",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"name",
")",
";",
"err",
"==",
"nil",
"{",
"err",
"=",
"os",
".",
"Remove",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Exitf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"l",
",",
"err",
":=",
"net",
".",
"Listen",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Exitf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"go",
"GRPCServer",
".",
"Serve",
"(",
"l",
")",
"\n",
"}"
] | // serveSocketFile listen to the named socket and serves RPCs on it. | [
"serveSocketFile",
"listen",
"to",
"the",
"named",
"socket",
"and",
"serves",
"RPCs",
"on",
"it",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/servenv/unix_socket.go#L34-L55 | train |
vitessio/vitess | go/vt/vtgate/safe_session.go | NewAutocommitSession | func NewAutocommitSession(sessn *vtgatepb.Session) *SafeSession {
newSession := proto.Clone(sessn).(*vtgatepb.Session)
newSession.InTransaction = false
newSession.ShardSessions = nil
newSession.Autocommit = true
return NewSafeSession(newSession)
} | go | func NewAutocommitSession(sessn *vtgatepb.Session) *SafeSession {
newSession := proto.Clone(sessn).(*vtgatepb.Session)
newSession.InTransaction = false
newSession.ShardSessions = nil
newSession.Autocommit = true
return NewSafeSession(newSession)
} | [
"func",
"NewAutocommitSession",
"(",
"sessn",
"*",
"vtgatepb",
".",
"Session",
")",
"*",
"SafeSession",
"{",
"newSession",
":=",
"proto",
".",
"Clone",
"(",
"sessn",
")",
".",
"(",
"*",
"vtgatepb",
".",
"Session",
")",
"\n",
"newSession",
".",
"InTransaction",
"=",
"false",
"\n",
"newSession",
".",
"ShardSessions",
"=",
"nil",
"\n",
"newSession",
".",
"Autocommit",
"=",
"true",
"\n",
"return",
"NewSafeSession",
"(",
"newSession",
")",
"\n",
"}"
] | // NewAutocommitSession returns a SafeSession based on the original
// session, but with autocommit enabled. | [
"NewAutocommitSession",
"returns",
"a",
"SafeSession",
"based",
"on",
"the",
"original",
"session",
"but",
"with",
"autocommit",
"enabled",
"."
] | d568817542a413611801aa17a1c213aa95592182 | https://github.com/vitessio/vitess/blob/d568817542a413611801aa17a1c213aa95592182/go/vt/vtgate/safe_session.go#L73-L79 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.