repo
stringlengths 5
67
| path
stringlengths 4
218
| func_name
stringlengths 0
151
| original_string
stringlengths 52
373k
| language
stringclasses 6
values | code
stringlengths 52
373k
| code_tokens
listlengths 10
512
| docstring
stringlengths 3
47.2k
| docstring_tokens
listlengths 3
234
| sha
stringlengths 40
40
| url
stringlengths 85
339
| partition
stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
kubernetes/test-infra
|
boskos/crds/client.go
|
Validate
|
func (o *KubernetesClientOptions) Validate() error {
if o.kubeConfig != "" {
if _, err := os.Stat(o.kubeConfig); err != nil {
return err
}
}
return nil
}
|
go
|
func (o *KubernetesClientOptions) Validate() error {
if o.kubeConfig != "" {
if _, err := os.Stat(o.kubeConfig); err != nil {
return err
}
}
return nil
}
|
[
"func",
"(",
"o",
"*",
"KubernetesClientOptions",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"o",
".",
"kubeConfig",
"!=",
"\"\"",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"o",
".",
"kubeConfig",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Validate validates Kubernetes client options.
|
[
"Validate",
"validates",
"Kubernetes",
"client",
"options",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/crds/client.go#L57-L64
|
test
|
kubernetes/test-infra
|
boskos/crds/client.go
|
Client
|
func (o *KubernetesClientOptions) Client(t Type) (ClientInterface, error) {
if o.inMemory {
return newDummyClient(t), nil
}
return o.newCRDClient(t)
}
|
go
|
func (o *KubernetesClientOptions) Client(t Type) (ClientInterface, error) {
if o.inMemory {
return newDummyClient(t), nil
}
return o.newCRDClient(t)
}
|
[
"func",
"(",
"o",
"*",
"KubernetesClientOptions",
")",
"Client",
"(",
"t",
"Type",
")",
"(",
"ClientInterface",
",",
"error",
")",
"{",
"if",
"o",
".",
"inMemory",
"{",
"return",
"newDummyClient",
"(",
"t",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"o",
".",
"newCRDClient",
"(",
"t",
")",
"\n",
"}"
] |
// Client returns a ClientInterface based on the flags provided.
|
[
"Client",
"returns",
"a",
"ClientInterface",
"based",
"on",
"the",
"flags",
"provided",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/crds/client.go#L67-L72
|
test
|
kubernetes/test-infra
|
boskos/crds/client.go
|
newCRDClient
|
func (o *KubernetesClientOptions) newCRDClient(t Type) (*Client, error) {
config, scheme, err := createRESTConfig(o.kubeConfig, t)
if err != nil {
return nil, err
}
if err = registerResource(config, t); err != nil {
return nil, err
}
// creates the client
var restClient *rest.RESTClient
restClient, err = rest.RESTClientFor(config)
if err != nil {
return nil, err
}
rc := Client{cl: restClient, ns: o.namespace, t: t,
codec: runtime.NewParameterCodec(scheme)}
return &rc, nil
}
|
go
|
func (o *KubernetesClientOptions) newCRDClient(t Type) (*Client, error) {
config, scheme, err := createRESTConfig(o.kubeConfig, t)
if err != nil {
return nil, err
}
if err = registerResource(config, t); err != nil {
return nil, err
}
// creates the client
var restClient *rest.RESTClient
restClient, err = rest.RESTClientFor(config)
if err != nil {
return nil, err
}
rc := Client{cl: restClient, ns: o.namespace, t: t,
codec: runtime.NewParameterCodec(scheme)}
return &rc, nil
}
|
[
"func",
"(",
"o",
"*",
"KubernetesClientOptions",
")",
"newCRDClient",
"(",
"t",
"Type",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"config",
",",
"scheme",
",",
"err",
":=",
"createRESTConfig",
"(",
"o",
".",
"kubeConfig",
",",
"t",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
"=",
"registerResource",
"(",
"config",
",",
"t",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"restClient",
"*",
"rest",
".",
"RESTClient",
"\n",
"restClient",
",",
"err",
"=",
"rest",
".",
"RESTClientFor",
"(",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"rc",
":=",
"Client",
"{",
"cl",
":",
"restClient",
",",
"ns",
":",
"o",
".",
"namespace",
",",
"t",
":",
"t",
",",
"codec",
":",
"runtime",
".",
"NewParameterCodec",
"(",
"scheme",
")",
"}",
"\n",
"return",
"&",
"rc",
",",
"nil",
"\n",
"}"
] |
// newClientFromFlags creates a CRD rest client from provided flags.
|
[
"newClientFromFlags",
"creates",
"a",
"CRD",
"rest",
"client",
"from",
"provided",
"flags",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/crds/client.go#L75-L93
|
test
|
kubernetes/test-infra
|
boskos/crds/client.go
|
createRESTConfig
|
func createRESTConfig(kubeconfig string, t Type) (config *rest.Config, types *runtime.Scheme, err error) {
if kubeconfig == "" {
config, err = rest.InClusterConfig()
} else {
config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
}
if err != nil {
return
}
version := schema.GroupVersion{
Group: group,
Version: version,
}
config.GroupVersion = &version
config.APIPath = "/apis"
config.ContentType = runtime.ContentTypeJSON
types = runtime.NewScheme()
schemeBuilder := runtime.NewSchemeBuilder(
func(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(version, t.Object, t.Collection)
v1.AddToGroupVersion(scheme, version)
return nil
})
err = schemeBuilder.AddToScheme(types)
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: serializer.NewCodecFactory(types)}
return
}
|
go
|
func createRESTConfig(kubeconfig string, t Type) (config *rest.Config, types *runtime.Scheme, err error) {
if kubeconfig == "" {
config, err = rest.InClusterConfig()
} else {
config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
}
if err != nil {
return
}
version := schema.GroupVersion{
Group: group,
Version: version,
}
config.GroupVersion = &version
config.APIPath = "/apis"
config.ContentType = runtime.ContentTypeJSON
types = runtime.NewScheme()
schemeBuilder := runtime.NewSchemeBuilder(
func(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(version, t.Object, t.Collection)
v1.AddToGroupVersion(scheme, version)
return nil
})
err = schemeBuilder.AddToScheme(types)
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: serializer.NewCodecFactory(types)}
return
}
|
[
"func",
"createRESTConfig",
"(",
"kubeconfig",
"string",
",",
"t",
"Type",
")",
"(",
"config",
"*",
"rest",
".",
"Config",
",",
"types",
"*",
"runtime",
".",
"Scheme",
",",
"err",
"error",
")",
"{",
"if",
"kubeconfig",
"==",
"\"\"",
"{",
"config",
",",
"err",
"=",
"rest",
".",
"InClusterConfig",
"(",
")",
"\n",
"}",
"else",
"{",
"config",
",",
"err",
"=",
"clientcmd",
".",
"BuildConfigFromFlags",
"(",
"\"\"",
",",
"kubeconfig",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"version",
":=",
"schema",
".",
"GroupVersion",
"{",
"Group",
":",
"group",
",",
"Version",
":",
"version",
",",
"}",
"\n",
"config",
".",
"GroupVersion",
"=",
"&",
"version",
"\n",
"config",
".",
"APIPath",
"=",
"\"/apis\"",
"\n",
"config",
".",
"ContentType",
"=",
"runtime",
".",
"ContentTypeJSON",
"\n",
"types",
"=",
"runtime",
".",
"NewScheme",
"(",
")",
"\n",
"schemeBuilder",
":=",
"runtime",
".",
"NewSchemeBuilder",
"(",
"func",
"(",
"scheme",
"*",
"runtime",
".",
"Scheme",
")",
"error",
"{",
"scheme",
".",
"AddKnownTypes",
"(",
"version",
",",
"t",
".",
"Object",
",",
"t",
".",
"Collection",
")",
"\n",
"v1",
".",
"AddToGroupVersion",
"(",
"scheme",
",",
"version",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"err",
"=",
"schemeBuilder",
".",
"AddToScheme",
"(",
"types",
")",
"\n",
"config",
".",
"NegotiatedSerializer",
"=",
"serializer",
".",
"DirectCodecFactory",
"{",
"CodecFactory",
":",
"serializer",
".",
"NewCodecFactory",
"(",
"types",
")",
"}",
"\n",
"return",
"\n",
"}"
] |
// createRESTConfig for cluster API server, pass empty config file for in-cluster
|
[
"createRESTConfig",
"for",
"cluster",
"API",
"server",
"pass",
"empty",
"config",
"file",
"for",
"in",
"-",
"cluster"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/crds/client.go#L120-L151
|
test
|
kubernetes/test-infra
|
boskos/crds/client.go
|
registerResource
|
func registerResource(config *rest.Config, t Type) error {
c, err := apiextensionsclient.NewForConfig(config)
if err != nil {
return err
}
crd := &apiextensionsv1beta1.CustomResourceDefinition{
ObjectMeta: v1.ObjectMeta{
Name: fmt.Sprintf("%s.%s", t.Plural, group),
},
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
Group: group,
Version: version,
Scope: apiextensionsv1beta1.NamespaceScoped,
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
Singular: t.Singular,
Plural: t.Plural,
Kind: t.Kind,
ListKind: t.ListKind,
},
},
}
if _, err := c.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd); err != nil && !apierrors.IsAlreadyExists(err) {
return err
}
return nil
}
|
go
|
func registerResource(config *rest.Config, t Type) error {
c, err := apiextensionsclient.NewForConfig(config)
if err != nil {
return err
}
crd := &apiextensionsv1beta1.CustomResourceDefinition{
ObjectMeta: v1.ObjectMeta{
Name: fmt.Sprintf("%s.%s", t.Plural, group),
},
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
Group: group,
Version: version,
Scope: apiextensionsv1beta1.NamespaceScoped,
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
Singular: t.Singular,
Plural: t.Plural,
Kind: t.Kind,
ListKind: t.ListKind,
},
},
}
if _, err := c.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd); err != nil && !apierrors.IsAlreadyExists(err) {
return err
}
return nil
}
|
[
"func",
"registerResource",
"(",
"config",
"*",
"rest",
".",
"Config",
",",
"t",
"Type",
")",
"error",
"{",
"c",
",",
"err",
":=",
"apiextensionsclient",
".",
"NewForConfig",
"(",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"crd",
":=",
"&",
"apiextensionsv1beta1",
".",
"CustomResourceDefinition",
"{",
"ObjectMeta",
":",
"v1",
".",
"ObjectMeta",
"{",
"Name",
":",
"fmt",
".",
"Sprintf",
"(",
"\"%s.%s\"",
",",
"t",
".",
"Plural",
",",
"group",
")",
",",
"}",
",",
"Spec",
":",
"apiextensionsv1beta1",
".",
"CustomResourceDefinitionSpec",
"{",
"Group",
":",
"group",
",",
"Version",
":",
"version",
",",
"Scope",
":",
"apiextensionsv1beta1",
".",
"NamespaceScoped",
",",
"Names",
":",
"apiextensionsv1beta1",
".",
"CustomResourceDefinitionNames",
"{",
"Singular",
":",
"t",
".",
"Singular",
",",
"Plural",
":",
"t",
".",
"Plural",
",",
"Kind",
":",
"t",
".",
"Kind",
",",
"ListKind",
":",
"t",
".",
"ListKind",
",",
"}",
",",
"}",
",",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"c",
".",
"ApiextensionsV1beta1",
"(",
")",
".",
"CustomResourceDefinitions",
"(",
")",
".",
"Create",
"(",
"crd",
")",
";",
"err",
"!=",
"nil",
"&&",
"!",
"apierrors",
".",
"IsAlreadyExists",
"(",
"err",
")",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// registerResource sends a request to create CRDs and waits for them to initialize
|
[
"registerResource",
"sends",
"a",
"request",
"to",
"create",
"CRDs",
"and",
"waits",
"for",
"them",
"to",
"initialize"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/crds/client.go#L154-L180
|
test
|
kubernetes/test-infra
|
boskos/crds/client.go
|
newDummyClient
|
func newDummyClient(t Type) *dummyClient {
c := &dummyClient{
t: t,
objects: make(map[string]Object),
}
return c
}
|
go
|
func newDummyClient(t Type) *dummyClient {
c := &dummyClient{
t: t,
objects: make(map[string]Object),
}
return c
}
|
[
"func",
"newDummyClient",
"(",
"t",
"Type",
")",
"*",
"dummyClient",
"{",
"c",
":=",
"&",
"dummyClient",
"{",
"t",
":",
"t",
",",
"objects",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"Object",
")",
",",
"}",
"\n",
"return",
"c",
"\n",
"}"
] |
// newDummyClient creates a in memory client representation for testing, such that we do not need to use a kubernetes API Server.
|
[
"newDummyClient",
"creates",
"a",
"in",
"memory",
"client",
"representation",
"for",
"testing",
"such",
"that",
"we",
"do",
"not",
"need",
"to",
"use",
"a",
"kubernetes",
"API",
"Server",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/crds/client.go#L183-L189
|
test
|
kubernetes/test-infra
|
boskos/crds/client.go
|
Update
|
func (c *dummyClient) Update(obj Object) (Object, error) {
_, ok := c.objects[obj.GetName()]
if !ok {
return nil, fmt.Errorf("cannot find object %s", obj.GetName())
}
c.objects[obj.GetName()] = obj
return obj, nil
}
|
go
|
func (c *dummyClient) Update(obj Object) (Object, error) {
_, ok := c.objects[obj.GetName()]
if !ok {
return nil, fmt.Errorf("cannot find object %s", obj.GetName())
}
c.objects[obj.GetName()] = obj
return obj, nil
}
|
[
"func",
"(",
"c",
"*",
"dummyClient",
")",
"Update",
"(",
"obj",
"Object",
")",
"(",
"Object",
",",
"error",
")",
"{",
"_",
",",
"ok",
":=",
"c",
".",
"objects",
"[",
"obj",
".",
"GetName",
"(",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"cannot find object %s\"",
",",
"obj",
".",
"GetName",
"(",
")",
")",
"\n",
"}",
"\n",
"c",
".",
"objects",
"[",
"obj",
".",
"GetName",
"(",
")",
"]",
"=",
"obj",
"\n",
"return",
"obj",
",",
"nil",
"\n",
"}"
] |
// Update implements ClientInterface
|
[
"Update",
"implements",
"ClientInterface"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/crds/client.go#L232-L239
|
test
|
kubernetes/test-infra
|
prow/plugins/trigger/pull-request.go
|
TrustedPullRequest
|
func TrustedPullRequest(ghc githubClient, trigger plugins.Trigger, author, org, repo string, num int, l []github.Label) ([]github.Label, bool, error) {
// First check if the author is a member of the org.
if orgMember, err := TrustedUser(ghc, trigger, author, org, repo); err != nil {
return l, false, fmt.Errorf("error checking %s for trust: %v", author, err)
} else if orgMember {
return l, true, nil
}
// Then check if PR has ok-to-test label
if l == nil {
var err error
l, err = ghc.GetIssueLabels(org, repo, num)
if err != nil {
return l, false, err
}
}
return l, github.HasLabel(labels.OkToTest, l), nil
}
|
go
|
func TrustedPullRequest(ghc githubClient, trigger plugins.Trigger, author, org, repo string, num int, l []github.Label) ([]github.Label, bool, error) {
// First check if the author is a member of the org.
if orgMember, err := TrustedUser(ghc, trigger, author, org, repo); err != nil {
return l, false, fmt.Errorf("error checking %s for trust: %v", author, err)
} else if orgMember {
return l, true, nil
}
// Then check if PR has ok-to-test label
if l == nil {
var err error
l, err = ghc.GetIssueLabels(org, repo, num)
if err != nil {
return l, false, err
}
}
return l, github.HasLabel(labels.OkToTest, l), nil
}
|
[
"func",
"TrustedPullRequest",
"(",
"ghc",
"githubClient",
",",
"trigger",
"plugins",
".",
"Trigger",
",",
"author",
",",
"org",
",",
"repo",
"string",
",",
"num",
"int",
",",
"l",
"[",
"]",
"github",
".",
"Label",
")",
"(",
"[",
"]",
"github",
".",
"Label",
",",
"bool",
",",
"error",
")",
"{",
"if",
"orgMember",
",",
"err",
":=",
"TrustedUser",
"(",
"ghc",
",",
"trigger",
",",
"author",
",",
"org",
",",
"repo",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"l",
",",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"error checking %s for trust: %v\"",
",",
"author",
",",
"err",
")",
"\n",
"}",
"else",
"if",
"orgMember",
"{",
"return",
"l",
",",
"true",
",",
"nil",
"\n",
"}",
"\n",
"if",
"l",
"==",
"nil",
"{",
"var",
"err",
"error",
"\n",
"l",
",",
"err",
"=",
"ghc",
".",
"GetIssueLabels",
"(",
"org",
",",
"repo",
",",
"num",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"l",
",",
"false",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"l",
",",
"github",
".",
"HasLabel",
"(",
"labels",
".",
"OkToTest",
",",
"l",
")",
",",
"nil",
"\n",
"}"
] |
// TrustedPullRequest returns whether or not the given PR should be tested.
// It first checks if the author is in the org, then looks for "ok-to-test" label.
|
[
"TrustedPullRequest",
"returns",
"whether",
"or",
"not",
"the",
"given",
"PR",
"should",
"be",
"tested",
".",
"It",
"first",
"checks",
"if",
"the",
"author",
"is",
"in",
"the",
"org",
"then",
"looks",
"for",
"ok",
"-",
"to",
"-",
"test",
"label",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/trigger/pull-request.go#L207-L223
|
test
|
kubernetes/test-infra
|
prow/plugins/trigger/pull-request.go
|
buildAll
|
func buildAll(c Client, pr *github.PullRequest, eventGUID string, elideSkippedContexts bool) error {
org, repo, number, branch := pr.Base.Repo.Owner.Login, pr.Base.Repo.Name, pr.Number, pr.Base.Ref
changes := config.NewGitHubDeferredChangedFilesProvider(c.GitHubClient, org, repo, number)
toTest, toSkipSuperset, err := pjutil.FilterPresubmits(pjutil.TestAllFilter(), changes, branch, c.Config.Presubmits[pr.Base.Repo.FullName], c.Logger)
if err != nil {
return err
}
toSkip := determineSkippedPresubmits(toTest, toSkipSuperset, c.Logger)
return runAndSkipJobs(c, pr, toTest, toSkip, eventGUID, elideSkippedContexts)
}
|
go
|
func buildAll(c Client, pr *github.PullRequest, eventGUID string, elideSkippedContexts bool) error {
org, repo, number, branch := pr.Base.Repo.Owner.Login, pr.Base.Repo.Name, pr.Number, pr.Base.Ref
changes := config.NewGitHubDeferredChangedFilesProvider(c.GitHubClient, org, repo, number)
toTest, toSkipSuperset, err := pjutil.FilterPresubmits(pjutil.TestAllFilter(), changes, branch, c.Config.Presubmits[pr.Base.Repo.FullName], c.Logger)
if err != nil {
return err
}
toSkip := determineSkippedPresubmits(toTest, toSkipSuperset, c.Logger)
return runAndSkipJobs(c, pr, toTest, toSkip, eventGUID, elideSkippedContexts)
}
|
[
"func",
"buildAll",
"(",
"c",
"Client",
",",
"pr",
"*",
"github",
".",
"PullRequest",
",",
"eventGUID",
"string",
",",
"elideSkippedContexts",
"bool",
")",
"error",
"{",
"org",
",",
"repo",
",",
"number",
",",
"branch",
":=",
"pr",
".",
"Base",
".",
"Repo",
".",
"Owner",
".",
"Login",
",",
"pr",
".",
"Base",
".",
"Repo",
".",
"Name",
",",
"pr",
".",
"Number",
",",
"pr",
".",
"Base",
".",
"Ref",
"\n",
"changes",
":=",
"config",
".",
"NewGitHubDeferredChangedFilesProvider",
"(",
"c",
".",
"GitHubClient",
",",
"org",
",",
"repo",
",",
"number",
")",
"\n",
"toTest",
",",
"toSkipSuperset",
",",
"err",
":=",
"pjutil",
".",
"FilterPresubmits",
"(",
"pjutil",
".",
"TestAllFilter",
"(",
")",
",",
"changes",
",",
"branch",
",",
"c",
".",
"Config",
".",
"Presubmits",
"[",
"pr",
".",
"Base",
".",
"Repo",
".",
"FullName",
"]",
",",
"c",
".",
"Logger",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"toSkip",
":=",
"determineSkippedPresubmits",
"(",
"toTest",
",",
"toSkipSuperset",
",",
"c",
".",
"Logger",
")",
"\n",
"return",
"runAndSkipJobs",
"(",
"c",
",",
"pr",
",",
"toTest",
",",
"toSkip",
",",
"eventGUID",
",",
"elideSkippedContexts",
")",
"\n",
"}"
] |
// buildAll ensures that all builds that should run and will be required are built
|
[
"buildAll",
"ensures",
"that",
"all",
"builds",
"that",
"should",
"run",
"and",
"will",
"be",
"required",
"are",
"built"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/plugins/trigger/pull-request.go#L226-L236
|
test
|
kubernetes/test-infra
|
prow/sidecar/run.go
|
Run
|
func (o Options) Run(ctx context.Context) (int, error) {
spec, err := downwardapi.ResolveSpecFromEnv()
if err != nil {
return 0, fmt.Errorf("could not resolve job spec: %v", err)
}
ctx, cancel := context.WithCancel(ctx)
// If we are being asked to terminate by the kubelet but we have
// NOT seen the test process exit cleanly, we need a to start
// uploading artifacts to GCS immediately. If we notice the process
// exit while doing this best-effort upload, we can race with the
// second upload but we can tolerate this as we'd rather get SOME
// data into GCS than attempt to cancel these uploads and get none.
interrupt := make(chan os.Signal)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
go func() {
select {
case s := <-interrupt:
logrus.Errorf("Received an interrupt: %s, cancelling...", s)
cancel()
case <-ctx.Done():
}
}()
if o.DeprecatedWrapperOptions != nil {
// This only fires if the prowjob controller and sidecar are at different commits
logrus.Warnf("Using deprecated wrapper_options instead of entries. Please update prow/pod-utils/decorate before June 2019")
}
entries := o.entries()
passed, aborted, failures := wait(ctx, entries)
cancel()
// If we are being asked to terminate by the kubelet but we have
// seen the test process exit cleanly, we need a chance to upload
// artifacts to GCS. The only valid way for this program to exit
// after a SIGINT or SIGTERM in this situation is to finish
// uploading, so we ignore the signals.
signal.Ignore(os.Interrupt, syscall.SIGTERM)
buildLog := logReader(entries)
metadata := combineMetadata(entries)
return failures, o.doUpload(spec, passed, aborted, metadata, buildLog)
}
|
go
|
func (o Options) Run(ctx context.Context) (int, error) {
spec, err := downwardapi.ResolveSpecFromEnv()
if err != nil {
return 0, fmt.Errorf("could not resolve job spec: %v", err)
}
ctx, cancel := context.WithCancel(ctx)
// If we are being asked to terminate by the kubelet but we have
// NOT seen the test process exit cleanly, we need a to start
// uploading artifacts to GCS immediately. If we notice the process
// exit while doing this best-effort upload, we can race with the
// second upload but we can tolerate this as we'd rather get SOME
// data into GCS than attempt to cancel these uploads and get none.
interrupt := make(chan os.Signal)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
go func() {
select {
case s := <-interrupt:
logrus.Errorf("Received an interrupt: %s, cancelling...", s)
cancel()
case <-ctx.Done():
}
}()
if o.DeprecatedWrapperOptions != nil {
// This only fires if the prowjob controller and sidecar are at different commits
logrus.Warnf("Using deprecated wrapper_options instead of entries. Please update prow/pod-utils/decorate before June 2019")
}
entries := o.entries()
passed, aborted, failures := wait(ctx, entries)
cancel()
// If we are being asked to terminate by the kubelet but we have
// seen the test process exit cleanly, we need a chance to upload
// artifacts to GCS. The only valid way for this program to exit
// after a SIGINT or SIGTERM in this situation is to finish
// uploading, so we ignore the signals.
signal.Ignore(os.Interrupt, syscall.SIGTERM)
buildLog := logReader(entries)
metadata := combineMetadata(entries)
return failures, o.doUpload(spec, passed, aborted, metadata, buildLog)
}
|
[
"func",
"(",
"o",
"Options",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"int",
",",
"error",
")",
"{",
"spec",
",",
"err",
":=",
"downwardapi",
".",
"ResolveSpecFromEnv",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"could not resolve job spec: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"ctx",
")",
"\n",
"interrupt",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
")",
"\n",
"signal",
".",
"Notify",
"(",
"interrupt",
",",
"os",
".",
"Interrupt",
",",
"syscall",
".",
"SIGTERM",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"select",
"{",
"case",
"s",
":=",
"<-",
"interrupt",
":",
"logrus",
".",
"Errorf",
"(",
"\"Received an interrupt: %s, cancelling...\"",
",",
"s",
")",
"\n",
"cancel",
"(",
")",
"\n",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"}",
"\n",
"}",
"(",
")",
"\n",
"if",
"o",
".",
"DeprecatedWrapperOptions",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"Using deprecated wrapper_options instead of entries. Please update prow/pod-utils/decorate before June 2019\"",
")",
"\n",
"}",
"\n",
"entries",
":=",
"o",
".",
"entries",
"(",
")",
"\n",
"passed",
",",
"aborted",
",",
"failures",
":=",
"wait",
"(",
"ctx",
",",
"entries",
")",
"\n",
"cancel",
"(",
")",
"\n",
"signal",
".",
"Ignore",
"(",
"os",
".",
"Interrupt",
",",
"syscall",
".",
"SIGTERM",
")",
"\n",
"buildLog",
":=",
"logReader",
"(",
"entries",
")",
"\n",
"metadata",
":=",
"combineMetadata",
"(",
"entries",
")",
"\n",
"return",
"failures",
",",
"o",
".",
"doUpload",
"(",
"spec",
",",
"passed",
",",
"aborted",
",",
"metadata",
",",
"buildLog",
")",
"\n",
"}"
] |
// Run will watch for the process being wrapped to exit
// and then post the status of that process and any artifacts
// to cloud storage.
|
[
"Run",
"will",
"watch",
"for",
"the",
"process",
"being",
"wrapped",
"to",
"exit",
"and",
"then",
"post",
"the",
"status",
"of",
"that",
"process",
"and",
"any",
"artifacts",
"to",
"cloud",
"storage",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/sidecar/run.go#L63-L106
|
test
|
kubernetes/test-infra
|
boskos/mason/storage.go
|
AddConfig
|
func (s *Storage) AddConfig(conf common.ResourcesConfig) error {
return s.configs.Add(conf)
}
|
go
|
func (s *Storage) AddConfig(conf common.ResourcesConfig) error {
return s.configs.Add(conf)
}
|
[
"func",
"(",
"s",
"*",
"Storage",
")",
"AddConfig",
"(",
"conf",
"common",
".",
"ResourcesConfig",
")",
"error",
"{",
"return",
"s",
".",
"configs",
".",
"Add",
"(",
"conf",
")",
"\n",
"}"
] |
// AddConfig adds a new config
|
[
"AddConfig",
"adds",
"a",
"new",
"config"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/mason/storage.go#L43-L45
|
test
|
kubernetes/test-infra
|
boskos/mason/storage.go
|
DeleteConfig
|
func (s *Storage) DeleteConfig(name string) error {
return s.configs.Delete(name)
}
|
go
|
func (s *Storage) DeleteConfig(name string) error {
return s.configs.Delete(name)
}
|
[
"func",
"(",
"s",
"*",
"Storage",
")",
"DeleteConfig",
"(",
"name",
"string",
")",
"error",
"{",
"return",
"s",
".",
"configs",
".",
"Delete",
"(",
"name",
")",
"\n",
"}"
] |
// DeleteConfig deletes an existing config if it exists or fail otherwise
|
[
"DeleteConfig",
"deletes",
"an",
"existing",
"config",
"if",
"it",
"exists",
"or",
"fail",
"otherwise"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/mason/storage.go#L48-L50
|
test
|
kubernetes/test-infra
|
boskos/mason/storage.go
|
UpdateConfig
|
func (s *Storage) UpdateConfig(conf common.ResourcesConfig) error {
return s.configs.Update(conf)
}
|
go
|
func (s *Storage) UpdateConfig(conf common.ResourcesConfig) error {
return s.configs.Update(conf)
}
|
[
"func",
"(",
"s",
"*",
"Storage",
")",
"UpdateConfig",
"(",
"conf",
"common",
".",
"ResourcesConfig",
")",
"error",
"{",
"return",
"s",
".",
"configs",
".",
"Update",
"(",
"conf",
")",
"\n",
"}"
] |
// UpdateConfig updates a given if it exists or fail otherwise
|
[
"UpdateConfig",
"updates",
"a",
"given",
"if",
"it",
"exists",
"or",
"fail",
"otherwise"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/mason/storage.go#L53-L55
|
test
|
kubernetes/test-infra
|
boskos/mason/storage.go
|
GetConfig
|
func (s *Storage) GetConfig(name string) (common.ResourcesConfig, error) {
i, err := s.configs.Get(name)
if err != nil {
return common.ResourcesConfig{}, err
}
var conf common.ResourcesConfig
conf, err = common.ItemToResourcesConfig(i)
if err != nil {
return common.ResourcesConfig{}, err
}
return conf, nil
}
|
go
|
func (s *Storage) GetConfig(name string) (common.ResourcesConfig, error) {
i, err := s.configs.Get(name)
if err != nil {
return common.ResourcesConfig{}, err
}
var conf common.ResourcesConfig
conf, err = common.ItemToResourcesConfig(i)
if err != nil {
return common.ResourcesConfig{}, err
}
return conf, nil
}
|
[
"func",
"(",
"s",
"*",
"Storage",
")",
"GetConfig",
"(",
"name",
"string",
")",
"(",
"common",
".",
"ResourcesConfig",
",",
"error",
")",
"{",
"i",
",",
"err",
":=",
"s",
".",
"configs",
".",
"Get",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"common",
".",
"ResourcesConfig",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"var",
"conf",
"common",
".",
"ResourcesConfig",
"\n",
"conf",
",",
"err",
"=",
"common",
".",
"ItemToResourcesConfig",
"(",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"common",
".",
"ResourcesConfig",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"conf",
",",
"nil",
"\n",
"}"
] |
// GetConfig returns an existing if it exists errors out otherwise
|
[
"GetConfig",
"returns",
"an",
"existing",
"if",
"it",
"exists",
"errors",
"out",
"otherwise"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/mason/storage.go#L58-L69
|
test
|
kubernetes/test-infra
|
boskos/mason/storage.go
|
GetConfigs
|
func (s *Storage) GetConfigs() ([]common.ResourcesConfig, error) {
var configs []common.ResourcesConfig
items, err := s.configs.List()
if err != nil {
return configs, err
}
for _, i := range items {
var conf common.ResourcesConfig
conf, err = common.ItemToResourcesConfig(i)
if err != nil {
return nil, err
}
configs = append(configs, conf)
}
return configs, nil
}
|
go
|
func (s *Storage) GetConfigs() ([]common.ResourcesConfig, error) {
var configs []common.ResourcesConfig
items, err := s.configs.List()
if err != nil {
return configs, err
}
for _, i := range items {
var conf common.ResourcesConfig
conf, err = common.ItemToResourcesConfig(i)
if err != nil {
return nil, err
}
configs = append(configs, conf)
}
return configs, nil
}
|
[
"func",
"(",
"s",
"*",
"Storage",
")",
"GetConfigs",
"(",
")",
"(",
"[",
"]",
"common",
".",
"ResourcesConfig",
",",
"error",
")",
"{",
"var",
"configs",
"[",
"]",
"common",
".",
"ResourcesConfig",
"\n",
"items",
",",
"err",
":=",
"s",
".",
"configs",
".",
"List",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"configs",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"i",
":=",
"range",
"items",
"{",
"var",
"conf",
"common",
".",
"ResourcesConfig",
"\n",
"conf",
",",
"err",
"=",
"common",
".",
"ItemToResourcesConfig",
"(",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"configs",
"=",
"append",
"(",
"configs",
",",
"conf",
")",
"\n",
"}",
"\n",
"return",
"configs",
",",
"nil",
"\n",
"}"
] |
// GetConfigs returns all configs
|
[
"GetConfigs",
"returns",
"all",
"configs"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/mason/storage.go#L72-L87
|
test
|
kubernetes/test-infra
|
boskos/mason/storage.go
|
SyncConfigs
|
func (s *Storage) SyncConfigs(newConfigs []common.ResourcesConfig) error {
s.configsLock.Lock()
defer s.configsLock.Unlock()
currentConfigs, err := s.GetConfigs()
if err != nil {
logrus.WithError(err).Error("cannot find configs")
return err
}
currentSet := mapset.NewSet()
newSet := mapset.NewSet()
toUpdate := mapset.NewSet()
configs := map[string]common.ResourcesConfig{}
for _, c := range currentConfigs {
currentSet.Add(c.Name)
configs[c.Name] = c
}
for _, c := range newConfigs {
newSet.Add(c.Name)
if old, exists := configs[c.Name]; exists {
if !reflect.DeepEqual(old, c) {
toUpdate.Add(c.Name)
configs[c.Name] = c
}
} else {
configs[c.Name] = c
}
}
var finalError error
toDelete := currentSet.Difference(newSet)
toAdd := newSet.Difference(currentSet)
for _, n := range toDelete.ToSlice() {
logrus.Infof("Deleting config %s", n.(string))
if err := s.DeleteConfig(n.(string)); err != nil {
logrus.WithError(err).Errorf("failed to delete config %s", n)
finalError = multierror.Append(finalError, err)
}
}
for _, n := range toAdd.ToSlice() {
rc := configs[n.(string)]
logrus.Infof("Adding config %s", n.(string))
if err := s.AddConfig(rc); err != nil {
logrus.WithError(err).Errorf("failed to create resources %s", n)
finalError = multierror.Append(finalError, err)
}
}
for _, n := range toUpdate.ToSlice() {
rc := configs[n.(string)]
logrus.Infof("Updating config %s", n.(string))
if err := s.UpdateConfig(rc); err != nil {
logrus.WithError(err).Errorf("failed to update resources %s", n)
finalError = multierror.Append(finalError, err)
}
}
return finalError
}
|
go
|
func (s *Storage) SyncConfigs(newConfigs []common.ResourcesConfig) error {
s.configsLock.Lock()
defer s.configsLock.Unlock()
currentConfigs, err := s.GetConfigs()
if err != nil {
logrus.WithError(err).Error("cannot find configs")
return err
}
currentSet := mapset.NewSet()
newSet := mapset.NewSet()
toUpdate := mapset.NewSet()
configs := map[string]common.ResourcesConfig{}
for _, c := range currentConfigs {
currentSet.Add(c.Name)
configs[c.Name] = c
}
for _, c := range newConfigs {
newSet.Add(c.Name)
if old, exists := configs[c.Name]; exists {
if !reflect.DeepEqual(old, c) {
toUpdate.Add(c.Name)
configs[c.Name] = c
}
} else {
configs[c.Name] = c
}
}
var finalError error
toDelete := currentSet.Difference(newSet)
toAdd := newSet.Difference(currentSet)
for _, n := range toDelete.ToSlice() {
logrus.Infof("Deleting config %s", n.(string))
if err := s.DeleteConfig(n.(string)); err != nil {
logrus.WithError(err).Errorf("failed to delete config %s", n)
finalError = multierror.Append(finalError, err)
}
}
for _, n := range toAdd.ToSlice() {
rc := configs[n.(string)]
logrus.Infof("Adding config %s", n.(string))
if err := s.AddConfig(rc); err != nil {
logrus.WithError(err).Errorf("failed to create resources %s", n)
finalError = multierror.Append(finalError, err)
}
}
for _, n := range toUpdate.ToSlice() {
rc := configs[n.(string)]
logrus.Infof("Updating config %s", n.(string))
if err := s.UpdateConfig(rc); err != nil {
logrus.WithError(err).Errorf("failed to update resources %s", n)
finalError = multierror.Append(finalError, err)
}
}
return finalError
}
|
[
"func",
"(",
"s",
"*",
"Storage",
")",
"SyncConfigs",
"(",
"newConfigs",
"[",
"]",
"common",
".",
"ResourcesConfig",
")",
"error",
"{",
"s",
".",
"configsLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"configsLock",
".",
"Unlock",
"(",
")",
"\n",
"currentConfigs",
",",
"err",
":=",
"s",
".",
"GetConfigs",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"cannot find configs\"",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"currentSet",
":=",
"mapset",
".",
"NewSet",
"(",
")",
"\n",
"newSet",
":=",
"mapset",
".",
"NewSet",
"(",
")",
"\n",
"toUpdate",
":=",
"mapset",
".",
"NewSet",
"(",
")",
"\n",
"configs",
":=",
"map",
"[",
"string",
"]",
"common",
".",
"ResourcesConfig",
"{",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"currentConfigs",
"{",
"currentSet",
".",
"Add",
"(",
"c",
".",
"Name",
")",
"\n",
"configs",
"[",
"c",
".",
"Name",
"]",
"=",
"c",
"\n",
"}",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"newConfigs",
"{",
"newSet",
".",
"Add",
"(",
"c",
".",
"Name",
")",
"\n",
"if",
"old",
",",
"exists",
":=",
"configs",
"[",
"c",
".",
"Name",
"]",
";",
"exists",
"{",
"if",
"!",
"reflect",
".",
"DeepEqual",
"(",
"old",
",",
"c",
")",
"{",
"toUpdate",
".",
"Add",
"(",
"c",
".",
"Name",
")",
"\n",
"configs",
"[",
"c",
".",
"Name",
"]",
"=",
"c",
"\n",
"}",
"\n",
"}",
"else",
"{",
"configs",
"[",
"c",
".",
"Name",
"]",
"=",
"c",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"finalError",
"error",
"\n",
"toDelete",
":=",
"currentSet",
".",
"Difference",
"(",
"newSet",
")",
"\n",
"toAdd",
":=",
"newSet",
".",
"Difference",
"(",
"currentSet",
")",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"toDelete",
".",
"ToSlice",
"(",
")",
"{",
"logrus",
".",
"Infof",
"(",
"\"Deleting config %s\"",
",",
"n",
".",
"(",
"string",
")",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"DeleteConfig",
"(",
"n",
".",
"(",
"string",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Errorf",
"(",
"\"failed to delete config %s\"",
",",
"n",
")",
"\n",
"finalError",
"=",
"multierror",
".",
"Append",
"(",
"finalError",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"toAdd",
".",
"ToSlice",
"(",
")",
"{",
"rc",
":=",
"configs",
"[",
"n",
".",
"(",
"string",
")",
"]",
"\n",
"logrus",
".",
"Infof",
"(",
"\"Adding config %s\"",
",",
"n",
".",
"(",
"string",
")",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"AddConfig",
"(",
"rc",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Errorf",
"(",
"\"failed to create resources %s\"",
",",
"n",
")",
"\n",
"finalError",
"=",
"multierror",
".",
"Append",
"(",
"finalError",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"n",
":=",
"range",
"toUpdate",
".",
"ToSlice",
"(",
")",
"{",
"rc",
":=",
"configs",
"[",
"n",
".",
"(",
"string",
")",
"]",
"\n",
"logrus",
".",
"Infof",
"(",
"\"Updating config %s\"",
",",
"n",
".",
"(",
"string",
")",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"UpdateConfig",
"(",
"rc",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Errorf",
"(",
"\"failed to update resources %s\"",
",",
"n",
")",
"\n",
"finalError",
"=",
"multierror",
".",
"Append",
"(",
"finalError",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"finalError",
"\n",
"}"
] |
// SyncConfigs syncs new configs
|
[
"SyncConfigs",
"syncs",
"new",
"configs"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/mason/storage.go#L90-L155
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/register.go
|
addKnownTypes
|
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&ProwJob{},
&ProwJobList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
|
go
|
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&ProwJob{},
&ProwJobList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
|
[
"func",
"addKnownTypes",
"(",
"scheme",
"*",
"runtime",
".",
"Scheme",
")",
"error",
"{",
"scheme",
".",
"AddKnownTypes",
"(",
"SchemeGroupVersion",
",",
"&",
"ProwJob",
"{",
"}",
",",
"&",
"ProwJobList",
"{",
"}",
",",
")",
"\n",
"metav1",
".",
"AddToGroupVersion",
"(",
"scheme",
",",
"SchemeGroupVersion",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Adds the list of known types to the Scheme.
|
[
"Adds",
"the",
"list",
"of",
"known",
"types",
"to",
"the",
"Scheme",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/register.go#L48-L55
|
test
|
kubernetes/test-infra
|
prow/statusreconciler/controller.go
|
NewController
|
func NewController(continueOnError bool, addedPresubmitBlacklist sets.String, prowJobClient prowv1.ProwJobInterface, githubClient *github.Client, configAgent *config.Agent, pluginAgent *plugins.ConfigAgent) *Controller {
return &Controller{
continueOnError: continueOnError,
addedPresubmitBlacklist: addedPresubmitBlacklist,
prowJobTriggerer: &kubeProwJobTriggerer{
prowJobClient: prowJobClient,
githubClient: githubClient,
configAgent: configAgent,
},
githubClient: githubClient,
statusMigrator: &gitHubMigrator{
githubClient: githubClient,
continueOnError: continueOnError,
},
trustedChecker: &githubTrustedChecker{
githubClient: githubClient,
pluginAgent: pluginAgent,
},
}
}
|
go
|
func NewController(continueOnError bool, addedPresubmitBlacklist sets.String, prowJobClient prowv1.ProwJobInterface, githubClient *github.Client, configAgent *config.Agent, pluginAgent *plugins.ConfigAgent) *Controller {
return &Controller{
continueOnError: continueOnError,
addedPresubmitBlacklist: addedPresubmitBlacklist,
prowJobTriggerer: &kubeProwJobTriggerer{
prowJobClient: prowJobClient,
githubClient: githubClient,
configAgent: configAgent,
},
githubClient: githubClient,
statusMigrator: &gitHubMigrator{
githubClient: githubClient,
continueOnError: continueOnError,
},
trustedChecker: &githubTrustedChecker{
githubClient: githubClient,
pluginAgent: pluginAgent,
},
}
}
|
[
"func",
"NewController",
"(",
"continueOnError",
"bool",
",",
"addedPresubmitBlacklist",
"sets",
".",
"String",
",",
"prowJobClient",
"prowv1",
".",
"ProwJobInterface",
",",
"githubClient",
"*",
"github",
".",
"Client",
",",
"configAgent",
"*",
"config",
".",
"Agent",
",",
"pluginAgent",
"*",
"plugins",
".",
"ConfigAgent",
")",
"*",
"Controller",
"{",
"return",
"&",
"Controller",
"{",
"continueOnError",
":",
"continueOnError",
",",
"addedPresubmitBlacklist",
":",
"addedPresubmitBlacklist",
",",
"prowJobTriggerer",
":",
"&",
"kubeProwJobTriggerer",
"{",
"prowJobClient",
":",
"prowJobClient",
",",
"githubClient",
":",
"githubClient",
",",
"configAgent",
":",
"configAgent",
",",
"}",
",",
"githubClient",
":",
"githubClient",
",",
"statusMigrator",
":",
"&",
"gitHubMigrator",
"{",
"githubClient",
":",
"githubClient",
",",
"continueOnError",
":",
"continueOnError",
",",
"}",
",",
"trustedChecker",
":",
"&",
"githubTrustedChecker",
"{",
"githubClient",
":",
"githubClient",
",",
"pluginAgent",
":",
"pluginAgent",
",",
"}",
",",
"}",
"\n",
"}"
] |
// NewController constructs a new controller to reconcile stauses on config change
|
[
"NewController",
"constructs",
"a",
"new",
"controller",
"to",
"reconcile",
"stauses",
"on",
"config",
"change"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/statusreconciler/controller.go#L38-L57
|
test
|
kubernetes/test-infra
|
prow/statusreconciler/controller.go
|
Run
|
func (c *Controller) Run(stop <-chan os.Signal, changes <-chan config.Delta) {
for {
select {
case change := <-changes:
start := time.Now()
if err := c.reconcile(change); err != nil {
logrus.WithError(err).Error("Error reconciling statuses.")
}
logrus.WithField("duration", fmt.Sprintf("%v", time.Since(start))).Info("Statuses reconciled")
case <-stop:
logrus.Info("status-reconciler is shutting down...")
return
}
}
}
|
go
|
func (c *Controller) Run(stop <-chan os.Signal, changes <-chan config.Delta) {
for {
select {
case change := <-changes:
start := time.Now()
if err := c.reconcile(change); err != nil {
logrus.WithError(err).Error("Error reconciling statuses.")
}
logrus.WithField("duration", fmt.Sprintf("%v", time.Since(start))).Info("Statuses reconciled")
case <-stop:
logrus.Info("status-reconciler is shutting down...")
return
}
}
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"Run",
"(",
"stop",
"<-",
"chan",
"os",
".",
"Signal",
",",
"changes",
"<-",
"chan",
"config",
".",
"Delta",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"change",
":=",
"<-",
"changes",
":",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"reconcile",
"(",
"change",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"Error reconciling statuses.\"",
")",
"\n",
"}",
"\n",
"logrus",
".",
"WithField",
"(",
"\"duration\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"%v\"",
",",
"time",
".",
"Since",
"(",
"start",
")",
")",
")",
".",
"Info",
"(",
"\"Statuses reconciled\"",
")",
"\n",
"case",
"<-",
"stop",
":",
"logrus",
".",
"Info",
"(",
"\"status-reconciler is shutting down...\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Run monitors the incoming configuration changes to determine when statuses need to be
// reconciled on PRs in flight when blocking presubmits change
|
[
"Run",
"monitors",
"the",
"incoming",
"configuration",
"changes",
"to",
"determine",
"when",
"statuses",
"need",
"to",
"be",
"reconciled",
"on",
"PRs",
"in",
"flight",
"when",
"blocking",
"presubmits",
"change"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/statusreconciler/controller.go#L139-L153
|
test
|
kubernetes/test-infra
|
prow/statusreconciler/controller.go
|
addedBlockingPresubmits
|
func addedBlockingPresubmits(old, new map[string][]config.Presubmit) map[string][]config.Presubmit {
added := map[string][]config.Presubmit{}
for repo, oldPresubmits := range old {
added[repo] = []config.Presubmit{}
for _, newPresubmit := range new[repo] {
if !newPresubmit.ContextRequired() || newPresubmit.NeedsExplicitTrigger() {
continue
}
var found bool
for _, oldPresubmit := range oldPresubmits {
if oldPresubmit.Name == newPresubmit.Name {
if oldPresubmit.SkipReport && !newPresubmit.SkipReport {
added[repo] = append(added[repo], newPresubmit)
logrus.WithFields(logrus.Fields{
"repo": repo,
"name": oldPresubmit.Name,
}).Debug("Identified a newly-reporting blocking presubmit.")
}
if oldPresubmit.RunIfChanged != newPresubmit.RunIfChanged {
added[repo] = append(added[repo], newPresubmit)
logrus.WithFields(logrus.Fields{
"repo": repo,
"name": oldPresubmit.Name,
}).Debug("Identified a blocking presubmit running over a different set of files.")
}
found = true
break
}
}
if !found {
added[repo] = append(added[repo], newPresubmit)
logrus.WithFields(logrus.Fields{
"repo": repo,
"name": newPresubmit.Name,
}).Debug("Identified an added blocking presubmit.")
}
}
}
var numAdded int
for _, presubmits := range added {
numAdded += len(presubmits)
}
logrus.Infof("Identified %d added blocking presubmits.", numAdded)
return added
}
|
go
|
func addedBlockingPresubmits(old, new map[string][]config.Presubmit) map[string][]config.Presubmit {
added := map[string][]config.Presubmit{}
for repo, oldPresubmits := range old {
added[repo] = []config.Presubmit{}
for _, newPresubmit := range new[repo] {
if !newPresubmit.ContextRequired() || newPresubmit.NeedsExplicitTrigger() {
continue
}
var found bool
for _, oldPresubmit := range oldPresubmits {
if oldPresubmit.Name == newPresubmit.Name {
if oldPresubmit.SkipReport && !newPresubmit.SkipReport {
added[repo] = append(added[repo], newPresubmit)
logrus.WithFields(logrus.Fields{
"repo": repo,
"name": oldPresubmit.Name,
}).Debug("Identified a newly-reporting blocking presubmit.")
}
if oldPresubmit.RunIfChanged != newPresubmit.RunIfChanged {
added[repo] = append(added[repo], newPresubmit)
logrus.WithFields(logrus.Fields{
"repo": repo,
"name": oldPresubmit.Name,
}).Debug("Identified a blocking presubmit running over a different set of files.")
}
found = true
break
}
}
if !found {
added[repo] = append(added[repo], newPresubmit)
logrus.WithFields(logrus.Fields{
"repo": repo,
"name": newPresubmit.Name,
}).Debug("Identified an added blocking presubmit.")
}
}
}
var numAdded int
for _, presubmits := range added {
numAdded += len(presubmits)
}
logrus.Infof("Identified %d added blocking presubmits.", numAdded)
return added
}
|
[
"func",
"addedBlockingPresubmits",
"(",
"old",
",",
"new",
"map",
"[",
"string",
"]",
"[",
"]",
"config",
".",
"Presubmit",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"config",
".",
"Presubmit",
"{",
"added",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"config",
".",
"Presubmit",
"{",
"}",
"\n",
"for",
"repo",
",",
"oldPresubmits",
":=",
"range",
"old",
"{",
"added",
"[",
"repo",
"]",
"=",
"[",
"]",
"config",
".",
"Presubmit",
"{",
"}",
"\n",
"for",
"_",
",",
"newPresubmit",
":=",
"range",
"new",
"[",
"repo",
"]",
"{",
"if",
"!",
"newPresubmit",
".",
"ContextRequired",
"(",
")",
"||",
"newPresubmit",
".",
"NeedsExplicitTrigger",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"var",
"found",
"bool",
"\n",
"for",
"_",
",",
"oldPresubmit",
":=",
"range",
"oldPresubmits",
"{",
"if",
"oldPresubmit",
".",
"Name",
"==",
"newPresubmit",
".",
"Name",
"{",
"if",
"oldPresubmit",
".",
"SkipReport",
"&&",
"!",
"newPresubmit",
".",
"SkipReport",
"{",
"added",
"[",
"repo",
"]",
"=",
"append",
"(",
"added",
"[",
"repo",
"]",
",",
"newPresubmit",
")",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"repo\"",
":",
"repo",
",",
"\"name\"",
":",
"oldPresubmit",
".",
"Name",
",",
"}",
")",
".",
"Debug",
"(",
"\"Identified a newly-reporting blocking presubmit.\"",
")",
"\n",
"}",
"\n",
"if",
"oldPresubmit",
".",
"RunIfChanged",
"!=",
"newPresubmit",
".",
"RunIfChanged",
"{",
"added",
"[",
"repo",
"]",
"=",
"append",
"(",
"added",
"[",
"repo",
"]",
",",
"newPresubmit",
")",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"repo\"",
":",
"repo",
",",
"\"name\"",
":",
"oldPresubmit",
".",
"Name",
",",
"}",
")",
".",
"Debug",
"(",
"\"Identified a blocking presubmit running over a different set of files.\"",
")",
"\n",
"}",
"\n",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"added",
"[",
"repo",
"]",
"=",
"append",
"(",
"added",
"[",
"repo",
"]",
",",
"newPresubmit",
")",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"repo\"",
":",
"repo",
",",
"\"name\"",
":",
"newPresubmit",
".",
"Name",
",",
"}",
")",
".",
"Debug",
"(",
"\"Identified an added blocking presubmit.\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"numAdded",
"int",
"\n",
"for",
"_",
",",
"presubmits",
":=",
"range",
"added",
"{",
"numAdded",
"+=",
"len",
"(",
"presubmits",
")",
"\n",
"}",
"\n",
"logrus",
".",
"Infof",
"(",
"\"Identified %d added blocking presubmits.\"",
",",
"numAdded",
")",
"\n",
"return",
"added",
"\n",
"}"
] |
// addedBlockingPresubmits determines new blocking presubmits based on a
// config update. New blocking presubmits are either brand-new presubmits
// or extant presubmits that are now reporting. Previous presubmits that
// reported but were optional that are no longer optional require no action
// as their contexts will already exist on PRs.
|
[
"addedBlockingPresubmits",
"determines",
"new",
"blocking",
"presubmits",
"based",
"on",
"a",
"config",
"update",
".",
"New",
"blocking",
"presubmits",
"are",
"either",
"brand",
"-",
"new",
"presubmits",
"or",
"extant",
"presubmits",
"that",
"are",
"now",
"reporting",
".",
"Previous",
"presubmits",
"that",
"reported",
"but",
"were",
"optional",
"that",
"are",
"no",
"longer",
"optional",
"require",
"no",
"action",
"as",
"their",
"contexts",
"will",
"already",
"exist",
"on",
"PRs",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/statusreconciler/controller.go#L293-L339
|
test
|
kubernetes/test-infra
|
prow/statusreconciler/controller.go
|
removedBlockingPresubmits
|
func removedBlockingPresubmits(old, new map[string][]config.Presubmit) map[string][]config.Presubmit {
removed := map[string][]config.Presubmit{}
for repo, oldPresubmits := range old {
removed[repo] = []config.Presubmit{}
for _, oldPresubmit := range oldPresubmits {
if !oldPresubmit.ContextRequired() {
continue
}
var found bool
for _, newPresubmit := range new[repo] {
if oldPresubmit.Name == newPresubmit.Name {
found = true
break
}
}
if !found {
removed[repo] = append(removed[repo], oldPresubmit)
logrus.WithFields(logrus.Fields{
"repo": repo,
"name": oldPresubmit.Name,
}).Debug("Identified a removed blocking presubmit.")
}
}
}
var numRemoved int
for _, presubmits := range removed {
numRemoved += len(presubmits)
}
logrus.Infof("Identified %d removed blocking presubmits.", numRemoved)
return removed
}
|
go
|
func removedBlockingPresubmits(old, new map[string][]config.Presubmit) map[string][]config.Presubmit {
removed := map[string][]config.Presubmit{}
for repo, oldPresubmits := range old {
removed[repo] = []config.Presubmit{}
for _, oldPresubmit := range oldPresubmits {
if !oldPresubmit.ContextRequired() {
continue
}
var found bool
for _, newPresubmit := range new[repo] {
if oldPresubmit.Name == newPresubmit.Name {
found = true
break
}
}
if !found {
removed[repo] = append(removed[repo], oldPresubmit)
logrus.WithFields(logrus.Fields{
"repo": repo,
"name": oldPresubmit.Name,
}).Debug("Identified a removed blocking presubmit.")
}
}
}
var numRemoved int
for _, presubmits := range removed {
numRemoved += len(presubmits)
}
logrus.Infof("Identified %d removed blocking presubmits.", numRemoved)
return removed
}
|
[
"func",
"removedBlockingPresubmits",
"(",
"old",
",",
"new",
"map",
"[",
"string",
"]",
"[",
"]",
"config",
".",
"Presubmit",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"config",
".",
"Presubmit",
"{",
"removed",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"config",
".",
"Presubmit",
"{",
"}",
"\n",
"for",
"repo",
",",
"oldPresubmits",
":=",
"range",
"old",
"{",
"removed",
"[",
"repo",
"]",
"=",
"[",
"]",
"config",
".",
"Presubmit",
"{",
"}",
"\n",
"for",
"_",
",",
"oldPresubmit",
":=",
"range",
"oldPresubmits",
"{",
"if",
"!",
"oldPresubmit",
".",
"ContextRequired",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"var",
"found",
"bool",
"\n",
"for",
"_",
",",
"newPresubmit",
":=",
"range",
"new",
"[",
"repo",
"]",
"{",
"if",
"oldPresubmit",
".",
"Name",
"==",
"newPresubmit",
".",
"Name",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"removed",
"[",
"repo",
"]",
"=",
"append",
"(",
"removed",
"[",
"repo",
"]",
",",
"oldPresubmit",
")",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"repo\"",
":",
"repo",
",",
"\"name\"",
":",
"oldPresubmit",
".",
"Name",
",",
"}",
")",
".",
"Debug",
"(",
"\"Identified a removed blocking presubmit.\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"numRemoved",
"int",
"\n",
"for",
"_",
",",
"presubmits",
":=",
"range",
"removed",
"{",
"numRemoved",
"+=",
"len",
"(",
"presubmits",
")",
"\n",
"}",
"\n",
"logrus",
".",
"Infof",
"(",
"\"Identified %d removed blocking presubmits.\"",
",",
"numRemoved",
")",
"\n",
"return",
"removed",
"\n",
"}"
] |
// removedBlockingPresubmits determines stale blocking presubmits based on a
// config update. Presubmits that are no longer blocking due to no longer
// reporting or being optional require no action as Tide will honor those
// statuses correctly.
|
[
"removedBlockingPresubmits",
"determines",
"stale",
"blocking",
"presubmits",
"based",
"on",
"a",
"config",
"update",
".",
"Presubmits",
"that",
"are",
"no",
"longer",
"blocking",
"due",
"to",
"no",
"longer",
"reporting",
"or",
"being",
"optional",
"require",
"no",
"action",
"as",
"Tide",
"will",
"honor",
"those",
"statuses",
"correctly",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/statusreconciler/controller.go#L345-L377
|
test
|
kubernetes/test-infra
|
prow/statusreconciler/controller.go
|
migratedBlockingPresubmits
|
func migratedBlockingPresubmits(old, new map[string][]config.Presubmit) map[string][]presubmitMigration {
migrated := map[string][]presubmitMigration{}
for repo, oldPresubmits := range old {
migrated[repo] = []presubmitMigration{}
for _, newPresubmit := range new[repo] {
if !newPresubmit.ContextRequired() {
continue
}
for _, oldPresubmit := range oldPresubmits {
if oldPresubmit.Context != newPresubmit.Context && oldPresubmit.Name == newPresubmit.Name {
migrated[repo] = append(migrated[repo], presubmitMigration{from: oldPresubmit, to: newPresubmit})
logrus.WithFields(logrus.Fields{
"repo": repo,
"name": oldPresubmit.Name,
"from": oldPresubmit.Context,
"to": newPresubmit.Context,
}).Debug("Identified a migrated blocking presubmit.")
}
}
}
}
var numMigrated int
for _, presubmits := range migrated {
numMigrated += len(presubmits)
}
logrus.Infof("Identified %d migrated blocking presubmits.", numMigrated)
return migrated
}
|
go
|
func migratedBlockingPresubmits(old, new map[string][]config.Presubmit) map[string][]presubmitMigration {
migrated := map[string][]presubmitMigration{}
for repo, oldPresubmits := range old {
migrated[repo] = []presubmitMigration{}
for _, newPresubmit := range new[repo] {
if !newPresubmit.ContextRequired() {
continue
}
for _, oldPresubmit := range oldPresubmits {
if oldPresubmit.Context != newPresubmit.Context && oldPresubmit.Name == newPresubmit.Name {
migrated[repo] = append(migrated[repo], presubmitMigration{from: oldPresubmit, to: newPresubmit})
logrus.WithFields(logrus.Fields{
"repo": repo,
"name": oldPresubmit.Name,
"from": oldPresubmit.Context,
"to": newPresubmit.Context,
}).Debug("Identified a migrated blocking presubmit.")
}
}
}
}
var numMigrated int
for _, presubmits := range migrated {
numMigrated += len(presubmits)
}
logrus.Infof("Identified %d migrated blocking presubmits.", numMigrated)
return migrated
}
|
[
"func",
"migratedBlockingPresubmits",
"(",
"old",
",",
"new",
"map",
"[",
"string",
"]",
"[",
"]",
"config",
".",
"Presubmit",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"presubmitMigration",
"{",
"migrated",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"presubmitMigration",
"{",
"}",
"\n",
"for",
"repo",
",",
"oldPresubmits",
":=",
"range",
"old",
"{",
"migrated",
"[",
"repo",
"]",
"=",
"[",
"]",
"presubmitMigration",
"{",
"}",
"\n",
"for",
"_",
",",
"newPresubmit",
":=",
"range",
"new",
"[",
"repo",
"]",
"{",
"if",
"!",
"newPresubmit",
".",
"ContextRequired",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"for",
"_",
",",
"oldPresubmit",
":=",
"range",
"oldPresubmits",
"{",
"if",
"oldPresubmit",
".",
"Context",
"!=",
"newPresubmit",
".",
"Context",
"&&",
"oldPresubmit",
".",
"Name",
"==",
"newPresubmit",
".",
"Name",
"{",
"migrated",
"[",
"repo",
"]",
"=",
"append",
"(",
"migrated",
"[",
"repo",
"]",
",",
"presubmitMigration",
"{",
"from",
":",
"oldPresubmit",
",",
"to",
":",
"newPresubmit",
"}",
")",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"repo\"",
":",
"repo",
",",
"\"name\"",
":",
"oldPresubmit",
".",
"Name",
",",
"\"from\"",
":",
"oldPresubmit",
".",
"Context",
",",
"\"to\"",
":",
"newPresubmit",
".",
"Context",
",",
"}",
")",
".",
"Debug",
"(",
"\"Identified a migrated blocking presubmit.\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"numMigrated",
"int",
"\n",
"for",
"_",
",",
"presubmits",
":=",
"range",
"migrated",
"{",
"numMigrated",
"+=",
"len",
"(",
"presubmits",
")",
"\n",
"}",
"\n",
"logrus",
".",
"Infof",
"(",
"\"Identified %d migrated blocking presubmits.\"",
",",
"numMigrated",
")",
"\n",
"return",
"migrated",
"\n",
"}"
] |
// migratedBlockingPresubmits determines blocking presubmits that have had
// their status contexts migrated. This is a best-effort evaluation as we
// can only track a presubmit between configuration versions by its name.
// A presubmit "migration" that had its underlying job and context changed
// will be treated as a deletion and creation.
|
[
"migratedBlockingPresubmits",
"determines",
"blocking",
"presubmits",
"that",
"have",
"had",
"their",
"status",
"contexts",
"migrated",
".",
"This",
"is",
"a",
"best",
"-",
"effort",
"evaluation",
"as",
"we",
"can",
"only",
"track",
"a",
"presubmit",
"between",
"configuration",
"versions",
"by",
"its",
"name",
".",
"A",
"presubmit",
"migration",
"that",
"had",
"its",
"underlying",
"job",
"and",
"context",
"changed",
"will",
"be",
"treated",
"as",
"a",
"deletion",
"and",
"creation",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/statusreconciler/controller.go#L388-L417
|
test
|
kubernetes/test-infra
|
prow/pod-utils/options/load.go
|
Load
|
func Load(loader OptionLoader) error {
if jsonConfig, provided := os.LookupEnv(loader.ConfigVar()); provided {
if err := loader.LoadConfig(jsonConfig); err != nil {
return fmt.Errorf("could not load config from JSON var %s: %v", loader.ConfigVar(), err)
}
return nil
}
fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
loader.AddFlags(fs)
fs.Parse(os.Args[1:])
loader.Complete(fs.Args())
return nil
}
|
go
|
func Load(loader OptionLoader) error {
if jsonConfig, provided := os.LookupEnv(loader.ConfigVar()); provided {
if err := loader.LoadConfig(jsonConfig); err != nil {
return fmt.Errorf("could not load config from JSON var %s: %v", loader.ConfigVar(), err)
}
return nil
}
fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
loader.AddFlags(fs)
fs.Parse(os.Args[1:])
loader.Complete(fs.Args())
return nil
}
|
[
"func",
"Load",
"(",
"loader",
"OptionLoader",
")",
"error",
"{",
"if",
"jsonConfig",
",",
"provided",
":=",
"os",
".",
"LookupEnv",
"(",
"loader",
".",
"ConfigVar",
"(",
")",
")",
";",
"provided",
"{",
"if",
"err",
":=",
"loader",
".",
"LoadConfig",
"(",
"jsonConfig",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"could not load config from JSON var %s: %v\"",
",",
"loader",
".",
"ConfigVar",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"fs",
":=",
"flag",
".",
"NewFlagSet",
"(",
"os",
".",
"Args",
"[",
"0",
"]",
",",
"flag",
".",
"ExitOnError",
")",
"\n",
"loader",
".",
"AddFlags",
"(",
"fs",
")",
"\n",
"fs",
".",
"Parse",
"(",
"os",
".",
"Args",
"[",
"1",
":",
"]",
")",
"\n",
"loader",
".",
"Complete",
"(",
"fs",
".",
"Args",
"(",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Load loads the set of options, preferring to use
// JSON config from an env var, but falling back to
// command line flags if not possible.
|
[
"Load",
"loads",
"the",
"set",
"of",
"options",
"preferring",
"to",
"use",
"JSON",
"config",
"from",
"an",
"env",
"var",
"but",
"falling",
"back",
"to",
"command",
"line",
"flags",
"if",
"not",
"possible",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/pod-utils/options/load.go#L36-L50
|
test
|
kubernetes/test-infra
|
prow/jenkins/controller.go
|
canExecuteConcurrently
|
func (c *Controller) canExecuteConcurrently(pj *prowapi.ProwJob) bool {
c.lock.Lock()
defer c.lock.Unlock()
if max := c.config().MaxConcurrency; max > 0 {
var running int
for _, num := range c.pendingJobs {
running += num
}
if running >= max {
c.log.WithFields(pjutil.ProwJobFields(pj)).Debugf("Not starting another job, already %d running.", running)
return false
}
}
if pj.Spec.MaxConcurrency == 0 {
c.pendingJobs[pj.Spec.Job]++
return true
}
numPending := c.pendingJobs[pj.Spec.Job]
if numPending >= pj.Spec.MaxConcurrency {
c.log.WithFields(pjutil.ProwJobFields(pj)).Debugf("Not starting another instance of %s, already %d running.", pj.Spec.Job, numPending)
return false
}
c.pendingJobs[pj.Spec.Job]++
return true
}
|
go
|
func (c *Controller) canExecuteConcurrently(pj *prowapi.ProwJob) bool {
c.lock.Lock()
defer c.lock.Unlock()
if max := c.config().MaxConcurrency; max > 0 {
var running int
for _, num := range c.pendingJobs {
running += num
}
if running >= max {
c.log.WithFields(pjutil.ProwJobFields(pj)).Debugf("Not starting another job, already %d running.", running)
return false
}
}
if pj.Spec.MaxConcurrency == 0 {
c.pendingJobs[pj.Spec.Job]++
return true
}
numPending := c.pendingJobs[pj.Spec.Job]
if numPending >= pj.Spec.MaxConcurrency {
c.log.WithFields(pjutil.ProwJobFields(pj)).Debugf("Not starting another instance of %s, already %d running.", pj.Spec.Job, numPending)
return false
}
c.pendingJobs[pj.Spec.Job]++
return true
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"canExecuteConcurrently",
"(",
"pj",
"*",
"prowapi",
".",
"ProwJob",
")",
"bool",
"{",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"max",
":=",
"c",
".",
"config",
"(",
")",
".",
"MaxConcurrency",
";",
"max",
">",
"0",
"{",
"var",
"running",
"int",
"\n",
"for",
"_",
",",
"num",
":=",
"range",
"c",
".",
"pendingJobs",
"{",
"running",
"+=",
"num",
"\n",
"}",
"\n",
"if",
"running",
">=",
"max",
"{",
"c",
".",
"log",
".",
"WithFields",
"(",
"pjutil",
".",
"ProwJobFields",
"(",
"pj",
")",
")",
".",
"Debugf",
"(",
"\"Not starting another job, already %d running.\"",
",",
"running",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"pj",
".",
"Spec",
".",
"MaxConcurrency",
"==",
"0",
"{",
"c",
".",
"pendingJobs",
"[",
"pj",
".",
"Spec",
".",
"Job",
"]",
"++",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"numPending",
":=",
"c",
".",
"pendingJobs",
"[",
"pj",
".",
"Spec",
".",
"Job",
"]",
"\n",
"if",
"numPending",
">=",
"pj",
".",
"Spec",
".",
"MaxConcurrency",
"{",
"c",
".",
"log",
".",
"WithFields",
"(",
"pjutil",
".",
"ProwJobFields",
"(",
"pj",
")",
")",
".",
"Debugf",
"(",
"\"Not starting another instance of %s, already %d running.\"",
",",
"pj",
".",
"Spec",
".",
"Job",
",",
"numPending",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"c",
".",
"pendingJobs",
"[",
"pj",
".",
"Spec",
".",
"Job",
"]",
"++",
"\n",
"return",
"true",
"\n",
"}"
] |
// canExecuteConcurrently checks whether the provided ProwJob can
// be executed concurrently.
|
[
"canExecuteConcurrently",
"checks",
"whether",
"the",
"provided",
"ProwJob",
"can",
"be",
"executed",
"concurrently",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/jenkins/controller.go#L128-L155
|
test
|
kubernetes/test-infra
|
prow/jenkins/controller.go
|
getJenkinsJobs
|
func getJenkinsJobs(pjs []prowapi.ProwJob) []BuildQueryParams {
jenkinsJobs := []BuildQueryParams{}
for _, pj := range pjs {
if pj.Complete() {
continue
}
jenkinsJobs = append(jenkinsJobs, BuildQueryParams{
JobName: getJobName(&pj.Spec),
ProwJobID: pj.Name,
})
}
return jenkinsJobs
}
|
go
|
func getJenkinsJobs(pjs []prowapi.ProwJob) []BuildQueryParams {
jenkinsJobs := []BuildQueryParams{}
for _, pj := range pjs {
if pj.Complete() {
continue
}
jenkinsJobs = append(jenkinsJobs, BuildQueryParams{
JobName: getJobName(&pj.Spec),
ProwJobID: pj.Name,
})
}
return jenkinsJobs
}
|
[
"func",
"getJenkinsJobs",
"(",
"pjs",
"[",
"]",
"prowapi",
".",
"ProwJob",
")",
"[",
"]",
"BuildQueryParams",
"{",
"jenkinsJobs",
":=",
"[",
"]",
"BuildQueryParams",
"{",
"}",
"\n",
"for",
"_",
",",
"pj",
":=",
"range",
"pjs",
"{",
"if",
"pj",
".",
"Complete",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"jenkinsJobs",
"=",
"append",
"(",
"jenkinsJobs",
",",
"BuildQueryParams",
"{",
"JobName",
":",
"getJobName",
"(",
"&",
"pj",
".",
"Spec",
")",
",",
"ProwJobID",
":",
"pj",
".",
"Name",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"jenkinsJobs",
"\n",
"}"
] |
// getJenkinsJobs returns all the Jenkins jobs for all active
// prowjobs from the provided list. It handles deduplication.
|
[
"getJenkinsJobs",
"returns",
"all",
"the",
"Jenkins",
"jobs",
"for",
"all",
"active",
"prowjobs",
"from",
"the",
"provided",
"list",
".",
"It",
"handles",
"deduplication",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/jenkins/controller.go#L241-L256
|
test
|
kubernetes/test-infra
|
prow/jenkins/controller.go
|
terminateDupes
|
func (c *Controller) terminateDupes(pjs []prowapi.ProwJob, jbs map[string]Build) error {
// "job org/repo#number" -> newest job
dupes := make(map[string]int)
for i, pj := range pjs {
if pj.Complete() || pj.Spec.Type != prowapi.PresubmitJob {
continue
}
n := fmt.Sprintf("%s %s/%s#%d", pj.Spec.Job, pj.Spec.Refs.Org, pj.Spec.Refs.Repo, pj.Spec.Refs.Pulls[0].Number)
prev, ok := dupes[n]
if !ok {
dupes[n] = i
continue
}
cancelIndex := i
if (&pjs[prev].Status.StartTime).Before(&pj.Status.StartTime) {
cancelIndex = prev
dupes[n] = i
}
toCancel := pjs[cancelIndex]
// Allow aborting presubmit jobs for commits that have been superseded by
// newer commits in GitHub pull requests.
if c.config().AllowCancellations {
build, buildExists := jbs[toCancel.ObjectMeta.Name]
// Avoid cancelling enqueued builds.
if buildExists && build.IsEnqueued() {
continue
}
// Otherwise, abort it.
if buildExists {
if err := c.jc.Abort(getJobName(&toCancel.Spec), &build); err != nil {
c.log.WithError(err).WithFields(pjutil.ProwJobFields(&toCancel)).Warn("Cannot cancel Jenkins build")
}
}
}
toCancel.SetComplete()
prevState := toCancel.Status.State
toCancel.Status.State = prowapi.AbortedState
c.log.WithFields(pjutil.ProwJobFields(&toCancel)).
WithField("from", prevState).
WithField("to", toCancel.Status.State).Info("Transitioning states.")
npj, err := c.prowJobClient.Update(&toCancel)
if err != nil {
return err
}
pjs[cancelIndex] = *npj
}
return nil
}
|
go
|
func (c *Controller) terminateDupes(pjs []prowapi.ProwJob, jbs map[string]Build) error {
// "job org/repo#number" -> newest job
dupes := make(map[string]int)
for i, pj := range pjs {
if pj.Complete() || pj.Spec.Type != prowapi.PresubmitJob {
continue
}
n := fmt.Sprintf("%s %s/%s#%d", pj.Spec.Job, pj.Spec.Refs.Org, pj.Spec.Refs.Repo, pj.Spec.Refs.Pulls[0].Number)
prev, ok := dupes[n]
if !ok {
dupes[n] = i
continue
}
cancelIndex := i
if (&pjs[prev].Status.StartTime).Before(&pj.Status.StartTime) {
cancelIndex = prev
dupes[n] = i
}
toCancel := pjs[cancelIndex]
// Allow aborting presubmit jobs for commits that have been superseded by
// newer commits in GitHub pull requests.
if c.config().AllowCancellations {
build, buildExists := jbs[toCancel.ObjectMeta.Name]
// Avoid cancelling enqueued builds.
if buildExists && build.IsEnqueued() {
continue
}
// Otherwise, abort it.
if buildExists {
if err := c.jc.Abort(getJobName(&toCancel.Spec), &build); err != nil {
c.log.WithError(err).WithFields(pjutil.ProwJobFields(&toCancel)).Warn("Cannot cancel Jenkins build")
}
}
}
toCancel.SetComplete()
prevState := toCancel.Status.State
toCancel.Status.State = prowapi.AbortedState
c.log.WithFields(pjutil.ProwJobFields(&toCancel)).
WithField("from", prevState).
WithField("to", toCancel.Status.State).Info("Transitioning states.")
npj, err := c.prowJobClient.Update(&toCancel)
if err != nil {
return err
}
pjs[cancelIndex] = *npj
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"terminateDupes",
"(",
"pjs",
"[",
"]",
"prowapi",
".",
"ProwJob",
",",
"jbs",
"map",
"[",
"string",
"]",
"Build",
")",
"error",
"{",
"dupes",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int",
")",
"\n",
"for",
"i",
",",
"pj",
":=",
"range",
"pjs",
"{",
"if",
"pj",
".",
"Complete",
"(",
")",
"||",
"pj",
".",
"Spec",
".",
"Type",
"!=",
"prowapi",
".",
"PresubmitJob",
"{",
"continue",
"\n",
"}",
"\n",
"n",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"%s %s/%s#%d\"",
",",
"pj",
".",
"Spec",
".",
"Job",
",",
"pj",
".",
"Spec",
".",
"Refs",
".",
"Org",
",",
"pj",
".",
"Spec",
".",
"Refs",
".",
"Repo",
",",
"pj",
".",
"Spec",
".",
"Refs",
".",
"Pulls",
"[",
"0",
"]",
".",
"Number",
")",
"\n",
"prev",
",",
"ok",
":=",
"dupes",
"[",
"n",
"]",
"\n",
"if",
"!",
"ok",
"{",
"dupes",
"[",
"n",
"]",
"=",
"i",
"\n",
"continue",
"\n",
"}",
"\n",
"cancelIndex",
":=",
"i",
"\n",
"if",
"(",
"&",
"pjs",
"[",
"prev",
"]",
".",
"Status",
".",
"StartTime",
")",
".",
"Before",
"(",
"&",
"pj",
".",
"Status",
".",
"StartTime",
")",
"{",
"cancelIndex",
"=",
"prev",
"\n",
"dupes",
"[",
"n",
"]",
"=",
"i",
"\n",
"}",
"\n",
"toCancel",
":=",
"pjs",
"[",
"cancelIndex",
"]",
"\n",
"if",
"c",
".",
"config",
"(",
")",
".",
"AllowCancellations",
"{",
"build",
",",
"buildExists",
":=",
"jbs",
"[",
"toCancel",
".",
"ObjectMeta",
".",
"Name",
"]",
"\n",
"if",
"buildExists",
"&&",
"build",
".",
"IsEnqueued",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"buildExists",
"{",
"if",
"err",
":=",
"c",
".",
"jc",
".",
"Abort",
"(",
"getJobName",
"(",
"&",
"toCancel",
".",
"Spec",
")",
",",
"&",
"build",
")",
";",
"err",
"!=",
"nil",
"{",
"c",
".",
"log",
".",
"WithError",
"(",
"err",
")",
".",
"WithFields",
"(",
"pjutil",
".",
"ProwJobFields",
"(",
"&",
"toCancel",
")",
")",
".",
"Warn",
"(",
"\"Cannot cancel Jenkins build\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"toCancel",
".",
"SetComplete",
"(",
")",
"\n",
"prevState",
":=",
"toCancel",
".",
"Status",
".",
"State",
"\n",
"toCancel",
".",
"Status",
".",
"State",
"=",
"prowapi",
".",
"AbortedState",
"\n",
"c",
".",
"log",
".",
"WithFields",
"(",
"pjutil",
".",
"ProwJobFields",
"(",
"&",
"toCancel",
")",
")",
".",
"WithField",
"(",
"\"from\"",
",",
"prevState",
")",
".",
"WithField",
"(",
"\"to\"",
",",
"toCancel",
".",
"Status",
".",
"State",
")",
".",
"Info",
"(",
"\"Transitioning states.\"",
")",
"\n",
"npj",
",",
"err",
":=",
"c",
".",
"prowJobClient",
".",
"Update",
"(",
"&",
"toCancel",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"pjs",
"[",
"cancelIndex",
"]",
"=",
"*",
"npj",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// terminateDupes aborts presubmits that have a newer version. It modifies pjs
// in-place when it aborts.
|
[
"terminateDupes",
"aborts",
"presubmits",
"that",
"have",
"a",
"newer",
"version",
".",
"It",
"modifies",
"pjs",
"in",
"-",
"place",
"when",
"it",
"aborts",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/jenkins/controller.go#L260-L307
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
Throttle
|
func (c *Client) Throttle(hourlyTokens, burst int) {
c.log("Throttle", hourlyTokens, burst)
c.throttle.lock.Lock()
defer c.throttle.lock.Unlock()
previouslyThrottled := c.throttle.ticker != nil
if hourlyTokens <= 0 || burst <= 0 { // Disable throttle
if previouslyThrottled { // Unwrap clients if necessary
c.client = c.throttle.http
c.gqlc = c.throttle.graph
c.throttle.ticker.Stop()
c.throttle.ticker = nil
}
return
}
rate := time.Hour / time.Duration(hourlyTokens)
ticker := time.NewTicker(rate)
throttle := make(chan time.Time, burst)
for i := 0; i < burst; i++ { // Fill up the channel
throttle <- time.Now()
}
go func() {
// Refill the channel
for t := range ticker.C {
select {
case throttle <- t:
default:
}
}
}()
if !previouslyThrottled { // Wrap clients if we haven't already
c.throttle.http = c.client
c.throttle.graph = c.gqlc
c.client = &c.throttle
c.gqlc = &c.throttle
}
c.throttle.ticker = ticker
c.throttle.throttle = throttle
}
|
go
|
func (c *Client) Throttle(hourlyTokens, burst int) {
c.log("Throttle", hourlyTokens, burst)
c.throttle.lock.Lock()
defer c.throttle.lock.Unlock()
previouslyThrottled := c.throttle.ticker != nil
if hourlyTokens <= 0 || burst <= 0 { // Disable throttle
if previouslyThrottled { // Unwrap clients if necessary
c.client = c.throttle.http
c.gqlc = c.throttle.graph
c.throttle.ticker.Stop()
c.throttle.ticker = nil
}
return
}
rate := time.Hour / time.Duration(hourlyTokens)
ticker := time.NewTicker(rate)
throttle := make(chan time.Time, burst)
for i := 0; i < burst; i++ { // Fill up the channel
throttle <- time.Now()
}
go func() {
// Refill the channel
for t := range ticker.C {
select {
case throttle <- t:
default:
}
}
}()
if !previouslyThrottled { // Wrap clients if we haven't already
c.throttle.http = c.client
c.throttle.graph = c.gqlc
c.client = &c.throttle
c.gqlc = &c.throttle
}
c.throttle.ticker = ticker
c.throttle.throttle = throttle
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Throttle",
"(",
"hourlyTokens",
",",
"burst",
"int",
")",
"{",
"c",
".",
"log",
"(",
"\"Throttle\"",
",",
"hourlyTokens",
",",
"burst",
")",
"\n",
"c",
".",
"throttle",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"throttle",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"previouslyThrottled",
":=",
"c",
".",
"throttle",
".",
"ticker",
"!=",
"nil",
"\n",
"if",
"hourlyTokens",
"<=",
"0",
"||",
"burst",
"<=",
"0",
"{",
"if",
"previouslyThrottled",
"{",
"c",
".",
"client",
"=",
"c",
".",
"throttle",
".",
"http",
"\n",
"c",
".",
"gqlc",
"=",
"c",
".",
"throttle",
".",
"graph",
"\n",
"c",
".",
"throttle",
".",
"ticker",
".",
"Stop",
"(",
")",
"\n",
"c",
".",
"throttle",
".",
"ticker",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"rate",
":=",
"time",
".",
"Hour",
"/",
"time",
".",
"Duration",
"(",
"hourlyTokens",
")",
"\n",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"rate",
")",
"\n",
"throttle",
":=",
"make",
"(",
"chan",
"time",
".",
"Time",
",",
"burst",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"burst",
";",
"i",
"++",
"{",
"throttle",
"<-",
"time",
".",
"Now",
"(",
")",
"\n",
"}",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"t",
":=",
"range",
"ticker",
".",
"C",
"{",
"select",
"{",
"case",
"throttle",
"<-",
"t",
":",
"default",
":",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"if",
"!",
"previouslyThrottled",
"{",
"c",
".",
"throttle",
".",
"http",
"=",
"c",
".",
"client",
"\n",
"c",
".",
"throttle",
".",
"graph",
"=",
"c",
".",
"gqlc",
"\n",
"c",
".",
"client",
"=",
"&",
"c",
".",
"throttle",
"\n",
"c",
".",
"gqlc",
"=",
"&",
"c",
".",
"throttle",
"\n",
"}",
"\n",
"c",
".",
"throttle",
".",
"ticker",
"=",
"ticker",
"\n",
"c",
".",
"throttle",
".",
"throttle",
"=",
"throttle",
"\n",
"}"
] |
// Throttle client to a rate of at most hourlyTokens requests per hour,
// allowing burst tokens.
|
[
"Throttle",
"client",
"to",
"a",
"rate",
"of",
"at",
"most",
"hourlyTokens",
"requests",
"per",
"hour",
"allowing",
"burst",
"tokens",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L187-L224
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
NewClientWithFields
|
func NewClientWithFields(fields logrus.Fields, getToken func() []byte, graphqlEndpoint string, bases ...string) *Client {
return &Client{
logger: logrus.WithFields(fields).WithField("client", "github"),
time: &standardTime{},
gqlc: githubql.NewEnterpriseClient(
graphqlEndpoint,
&http.Client{
Timeout: maxRequestTime,
Transport: &oauth2.Transport{Source: newReloadingTokenSource(getToken)},
}),
client: &http.Client{Timeout: maxRequestTime},
bases: bases,
getToken: getToken,
dry: false,
}
}
|
go
|
func NewClientWithFields(fields logrus.Fields, getToken func() []byte, graphqlEndpoint string, bases ...string) *Client {
return &Client{
logger: logrus.WithFields(fields).WithField("client", "github"),
time: &standardTime{},
gqlc: githubql.NewEnterpriseClient(
graphqlEndpoint,
&http.Client{
Timeout: maxRequestTime,
Transport: &oauth2.Transport{Source: newReloadingTokenSource(getToken)},
}),
client: &http.Client{Timeout: maxRequestTime},
bases: bases,
getToken: getToken,
dry: false,
}
}
|
[
"func",
"NewClientWithFields",
"(",
"fields",
"logrus",
".",
"Fields",
",",
"getToken",
"func",
"(",
")",
"[",
"]",
"byte",
",",
"graphqlEndpoint",
"string",
",",
"bases",
"...",
"string",
")",
"*",
"Client",
"{",
"return",
"&",
"Client",
"{",
"logger",
":",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"WithField",
"(",
"\"client\"",
",",
"\"github\"",
")",
",",
"time",
":",
"&",
"standardTime",
"{",
"}",
",",
"gqlc",
":",
"githubql",
".",
"NewEnterpriseClient",
"(",
"graphqlEndpoint",
",",
"&",
"http",
".",
"Client",
"{",
"Timeout",
":",
"maxRequestTime",
",",
"Transport",
":",
"&",
"oauth2",
".",
"Transport",
"{",
"Source",
":",
"newReloadingTokenSource",
"(",
"getToken",
")",
"}",
",",
"}",
")",
",",
"client",
":",
"&",
"http",
".",
"Client",
"{",
"Timeout",
":",
"maxRequestTime",
"}",
",",
"bases",
":",
"bases",
",",
"getToken",
":",
"getToken",
",",
"dry",
":",
"false",
",",
"}",
"\n",
"}"
] |
// NewClientWithFields creates a new fully operational GitHub client. With
// added logging fields.
// 'getToken' is a generator for the GitHub access token to use.
// 'bases' is a variadic slice of endpoints to use in order of preference.
// An endpoint is used when all preceding endpoints have returned a conn err.
// This should be used when using the ghproxy GitHub proxy cache to allow
// this client to bypass the cache if it is temporarily unavailable.
|
[
"NewClientWithFields",
"creates",
"a",
"new",
"fully",
"operational",
"GitHub",
"client",
".",
"With",
"added",
"logging",
"fields",
".",
"getToken",
"is",
"a",
"generator",
"for",
"the",
"GitHub",
"access",
"token",
"to",
"use",
".",
"bases",
"is",
"a",
"variadic",
"slice",
"of",
"endpoints",
"to",
"use",
"in",
"order",
"of",
"preference",
".",
"An",
"endpoint",
"is",
"used",
"when",
"all",
"preceding",
"endpoints",
"have",
"returned",
"a",
"conn",
"err",
".",
"This",
"should",
"be",
"used",
"when",
"using",
"the",
"ghproxy",
"GitHub",
"proxy",
"cache",
"to",
"allow",
"this",
"client",
"to",
"bypass",
"the",
"cache",
"if",
"it",
"is",
"temporarily",
"unavailable",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L233-L248
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
NewClient
|
func NewClient(getToken func() []byte, graphqlEndpoint string, bases ...string) *Client {
return NewClientWithFields(logrus.Fields{}, getToken, graphqlEndpoint, bases...)
}
|
go
|
func NewClient(getToken func() []byte, graphqlEndpoint string, bases ...string) *Client {
return NewClientWithFields(logrus.Fields{}, getToken, graphqlEndpoint, bases...)
}
|
[
"func",
"NewClient",
"(",
"getToken",
"func",
"(",
")",
"[",
"]",
"byte",
",",
"graphqlEndpoint",
"string",
",",
"bases",
"...",
"string",
")",
"*",
"Client",
"{",
"return",
"NewClientWithFields",
"(",
"logrus",
".",
"Fields",
"{",
"}",
",",
"getToken",
",",
"graphqlEndpoint",
",",
"bases",
"...",
")",
"\n",
"}"
] |
// NewClient creates a new fully operational GitHub client.
|
[
"NewClient",
"creates",
"a",
"new",
"fully",
"operational",
"GitHub",
"client",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L251-L253
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
NewDryRunClient
|
func NewDryRunClient(getToken func() []byte, graphqlEndpoint string, bases ...string) *Client {
return NewDryRunClientWithFields(logrus.Fields{}, getToken, graphqlEndpoint, bases...)
}
|
go
|
func NewDryRunClient(getToken func() []byte, graphqlEndpoint string, bases ...string) *Client {
return NewDryRunClientWithFields(logrus.Fields{}, getToken, graphqlEndpoint, bases...)
}
|
[
"func",
"NewDryRunClient",
"(",
"getToken",
"func",
"(",
")",
"[",
"]",
"byte",
",",
"graphqlEndpoint",
"string",
",",
"bases",
"...",
"string",
")",
"*",
"Client",
"{",
"return",
"NewDryRunClientWithFields",
"(",
"logrus",
".",
"Fields",
"{",
"}",
",",
"getToken",
",",
"graphqlEndpoint",
",",
"bases",
"...",
")",
"\n",
"}"
] |
// NewDryRunClient creates a new client that will not perform mutating actions
// such as setting statuses or commenting, but it will still query GitHub and
// use up API tokens.
// 'getToken' is a generator the GitHub access token to use.
// 'bases' is a variadic slice of endpoints to use in order of preference.
// An endpoint is used when all preceding endpoints have returned a conn err.
// This should be used when using the ghproxy GitHub proxy cache to allow
// this client to bypass the cache if it is temporarily unavailable.
|
[
"NewDryRunClient",
"creates",
"a",
"new",
"client",
"that",
"will",
"not",
"perform",
"mutating",
"actions",
"such",
"as",
"setting",
"statuses",
"or",
"commenting",
"but",
"it",
"will",
"still",
"query",
"GitHub",
"and",
"use",
"up",
"API",
"tokens",
".",
"getToken",
"is",
"a",
"generator",
"the",
"GitHub",
"access",
"token",
"to",
"use",
".",
"bases",
"is",
"a",
"variadic",
"slice",
"of",
"endpoints",
"to",
"use",
"in",
"order",
"of",
"preference",
".",
"An",
"endpoint",
"is",
"used",
"when",
"all",
"preceding",
"endpoints",
"have",
"returned",
"a",
"conn",
"err",
".",
"This",
"should",
"be",
"used",
"when",
"using",
"the",
"ghproxy",
"GitHub",
"proxy",
"cache",
"to",
"allow",
"this",
"client",
"to",
"bypass",
"the",
"cache",
"if",
"it",
"is",
"temporarily",
"unavailable",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L288-L290
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
NewFakeClient
|
func NewFakeClient() *Client {
return &Client{
logger: logrus.WithField("client", "github"),
time: &standardTime{},
fake: true,
dry: true,
}
}
|
go
|
func NewFakeClient() *Client {
return &Client{
logger: logrus.WithField("client", "github"),
time: &standardTime{},
fake: true,
dry: true,
}
}
|
[
"func",
"NewFakeClient",
"(",
")",
"*",
"Client",
"{",
"return",
"&",
"Client",
"{",
"logger",
":",
"logrus",
".",
"WithField",
"(",
"\"client\"",
",",
"\"github\"",
")",
",",
"time",
":",
"&",
"standardTime",
"{",
"}",
",",
"fake",
":",
"true",
",",
"dry",
":",
"true",
",",
"}",
"\n",
"}"
] |
// NewFakeClient creates a new client that will not perform any actions at all.
|
[
"NewFakeClient",
"creates",
"a",
"new",
"client",
"that",
"will",
"not",
"perform",
"any",
"actions",
"at",
"all",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L293-L300
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
request
|
func (c *Client) request(r *request, ret interface{}) (int, error) {
statusCode, b, err := c.requestRaw(r)
if err != nil {
return statusCode, err
}
if ret != nil {
if err := json.Unmarshal(b, ret); err != nil {
return statusCode, err
}
}
return statusCode, nil
}
|
go
|
func (c *Client) request(r *request, ret interface{}) (int, error) {
statusCode, b, err := c.requestRaw(r)
if err != nil {
return statusCode, err
}
if ret != nil {
if err := json.Unmarshal(b, ret); err != nil {
return statusCode, err
}
}
return statusCode, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"request",
"(",
"r",
"*",
"request",
",",
"ret",
"interface",
"{",
"}",
")",
"(",
"int",
",",
"error",
")",
"{",
"statusCode",
",",
"b",
",",
"err",
":=",
"c",
".",
"requestRaw",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"statusCode",
",",
"err",
"\n",
"}",
"\n",
"if",
"ret",
"!=",
"nil",
"{",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"ret",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"statusCode",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"statusCode",
",",
"nil",
"\n",
"}"
] |
// Make a request with retries. If ret is not nil, unmarshal the response body
// into it. Returns an error if the exit code is not one of the provided codes.
|
[
"Make",
"a",
"request",
"with",
"retries",
".",
"If",
"ret",
"is",
"not",
"nil",
"unmarshal",
"the",
"response",
"body",
"into",
"it",
".",
"Returns",
"an",
"error",
"if",
"the",
"exit",
"code",
"is",
"not",
"one",
"of",
"the",
"provided",
"codes",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L348-L359
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
requestRaw
|
func (c *Client) requestRaw(r *request) (int, []byte, error) {
if c.fake || (c.dry && r.method != http.MethodGet) {
return r.exitCodes[0], nil, nil
}
resp, err := c.requestRetry(r.method, r.path, r.accept, r.requestBody)
if err != nil {
return 0, nil, err
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return 0, nil, err
}
var okCode bool
for _, code := range r.exitCodes {
if code == resp.StatusCode {
okCode = true
break
}
}
if !okCode {
clientError := unmarshalClientError(b)
err = requestError{
ClientError: clientError,
ErrorString: fmt.Sprintf("status code %d not one of %v, body: %s", resp.StatusCode, r.exitCodes, string(b)),
}
}
return resp.StatusCode, b, err
}
|
go
|
func (c *Client) requestRaw(r *request) (int, []byte, error) {
if c.fake || (c.dry && r.method != http.MethodGet) {
return r.exitCodes[0], nil, nil
}
resp, err := c.requestRetry(r.method, r.path, r.accept, r.requestBody)
if err != nil {
return 0, nil, err
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return 0, nil, err
}
var okCode bool
for _, code := range r.exitCodes {
if code == resp.StatusCode {
okCode = true
break
}
}
if !okCode {
clientError := unmarshalClientError(b)
err = requestError{
ClientError: clientError,
ErrorString: fmt.Sprintf("status code %d not one of %v, body: %s", resp.StatusCode, r.exitCodes, string(b)),
}
}
return resp.StatusCode, b, err
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"requestRaw",
"(",
"r",
"*",
"request",
")",
"(",
"int",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"c",
".",
"fake",
"||",
"(",
"c",
".",
"dry",
"&&",
"r",
".",
"method",
"!=",
"http",
".",
"MethodGet",
")",
"{",
"return",
"r",
".",
"exitCodes",
"[",
"0",
"]",
",",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"requestRetry",
"(",
"r",
".",
"method",
",",
"r",
".",
"path",
",",
"r",
".",
"accept",
",",
"r",
".",
"requestBody",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"okCode",
"bool",
"\n",
"for",
"_",
",",
"code",
":=",
"range",
"r",
".",
"exitCodes",
"{",
"if",
"code",
"==",
"resp",
".",
"StatusCode",
"{",
"okCode",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"okCode",
"{",
"clientError",
":=",
"unmarshalClientError",
"(",
"b",
")",
"\n",
"err",
"=",
"requestError",
"{",
"ClientError",
":",
"clientError",
",",
"ErrorString",
":",
"fmt",
".",
"Sprintf",
"(",
"\"status code %d not one of %v, body: %s\"",
",",
"resp",
".",
"StatusCode",
",",
"r",
".",
"exitCodes",
",",
"string",
"(",
"b",
")",
")",
",",
"}",
"\n",
"}",
"\n",
"return",
"resp",
".",
"StatusCode",
",",
"b",
",",
"err",
"\n",
"}"
] |
// requestRaw makes a request with retries and returns the response body.
// Returns an error if the exit code is not one of the provided codes.
|
[
"requestRaw",
"makes",
"a",
"request",
"with",
"retries",
"and",
"returns",
"the",
"response",
"body",
".",
"Returns",
"an",
"error",
"if",
"the",
"exit",
"code",
"is",
"not",
"one",
"of",
"the",
"provided",
"codes",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L363-L391
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
getUserData
|
func (c *Client) getUserData() error {
c.log("User")
var u User
_, err := c.request(&request{
method: http.MethodGet,
path: "/user",
exitCodes: []int{200},
}, &u)
if err != nil {
return err
}
c.botName = u.Login
// email needs to be publicly accessible via the profile
// of the current account. Read below for more info
// https://developer.github.com/v3/users/#get-a-single-user
c.email = u.Email
return nil
}
|
go
|
func (c *Client) getUserData() error {
c.log("User")
var u User
_, err := c.request(&request{
method: http.MethodGet,
path: "/user",
exitCodes: []int{200},
}, &u)
if err != nil {
return err
}
c.botName = u.Login
// email needs to be publicly accessible via the profile
// of the current account. Read below for more info
// https://developer.github.com/v3/users/#get-a-single-user
c.email = u.Email
return nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"getUserData",
"(",
")",
"error",
"{",
"c",
".",
"log",
"(",
"\"User\"",
")",
"\n",
"var",
"u",
"User",
"\n",
"_",
",",
"err",
":=",
"c",
".",
"request",
"(",
"&",
"request",
"{",
"method",
":",
"http",
".",
"MethodGet",
",",
"path",
":",
"\"/user\"",
",",
"exitCodes",
":",
"[",
"]",
"int",
"{",
"200",
"}",
",",
"}",
",",
"&",
"u",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"c",
".",
"botName",
"=",
"u",
".",
"Login",
"\n",
"c",
".",
"email",
"=",
"u",
".",
"Email",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Not thread-safe - callers need to hold c.mut.
|
[
"Not",
"thread",
"-",
"safe",
"-",
"callers",
"need",
"to",
"hold",
"c",
".",
"mut",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L514-L531
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
readPaginatedResultsWithValues
|
func (c *Client) readPaginatedResultsWithValues(path string, values url.Values, accept string, newObj func() interface{}, accumulate func(interface{})) error {
pagedPath := path
if len(values) > 0 {
pagedPath += "?" + values.Encode()
}
for {
resp, err := c.requestRetry(http.MethodGet, pagedPath, accept, nil)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return fmt.Errorf("return code not 2XX: %s", resp.Status)
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
obj := newObj()
if err := json.Unmarshal(b, obj); err != nil {
return err
}
accumulate(obj)
link := parseLinks(resp.Header.Get("Link"))["next"]
if link == "" {
break
}
u, err := url.Parse(link)
if err != nil {
return fmt.Errorf("failed to parse 'next' link: %v", err)
}
pagedPath = u.RequestURI()
}
return nil
}
|
go
|
func (c *Client) readPaginatedResultsWithValues(path string, values url.Values, accept string, newObj func() interface{}, accumulate func(interface{})) error {
pagedPath := path
if len(values) > 0 {
pagedPath += "?" + values.Encode()
}
for {
resp, err := c.requestRetry(http.MethodGet, pagedPath, accept, nil)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return fmt.Errorf("return code not 2XX: %s", resp.Status)
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
obj := newObj()
if err := json.Unmarshal(b, obj); err != nil {
return err
}
accumulate(obj)
link := parseLinks(resp.Header.Get("Link"))["next"]
if link == "" {
break
}
u, err := url.Parse(link)
if err != nil {
return fmt.Errorf("failed to parse 'next' link: %v", err)
}
pagedPath = u.RequestURI()
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"readPaginatedResultsWithValues",
"(",
"path",
"string",
",",
"values",
"url",
".",
"Values",
",",
"accept",
"string",
",",
"newObj",
"func",
"(",
")",
"interface",
"{",
"}",
",",
"accumulate",
"func",
"(",
"interface",
"{",
"}",
")",
")",
"error",
"{",
"pagedPath",
":=",
"path",
"\n",
"if",
"len",
"(",
"values",
")",
">",
"0",
"{",
"pagedPath",
"+=",
"\"?\"",
"+",
"values",
".",
"Encode",
"(",
")",
"\n",
"}",
"\n",
"for",
"{",
"resp",
",",
"err",
":=",
"c",
".",
"requestRetry",
"(",
"http",
".",
"MethodGet",
",",
"pagedPath",
",",
"accept",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"resp",
".",
"StatusCode",
"<",
"200",
"||",
"resp",
".",
"StatusCode",
">",
"299",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"return code not 2XX: %s\"",
",",
"resp",
".",
"Status",
")",
"\n",
"}",
"\n",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"obj",
":=",
"newObj",
"(",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"obj",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"accumulate",
"(",
"obj",
")",
"\n",
"link",
":=",
"parseLinks",
"(",
"resp",
".",
"Header",
".",
"Get",
"(",
"\"Link\"",
")",
")",
"[",
"\"next\"",
"]",
"\n",
"if",
"link",
"==",
"\"\"",
"{",
"break",
"\n",
"}",
"\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"link",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to parse 'next' link: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"pagedPath",
"=",
"u",
".",
"RequestURI",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// readPaginatedResultsWithValues is an override that allows control over the query string.
|
[
"readPaginatedResultsWithValues",
"is",
"an",
"override",
"that",
"allows",
"control",
"over",
"the",
"query",
"string",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L983-L1021
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
UpdatePullRequest
|
func (c *Client) UpdatePullRequest(org, repo string, number int, title, body *string, open *bool, branch *string, canModify *bool) error {
c.log("UpdatePullRequest", org, repo, title)
data := struct {
State *string `json:"state,omitempty"`
Title *string `json:"title,omitempty"`
Body *string `json:"body,omitempty"`
Base *string `json:"base,omitempty"`
// MaintainerCanModify allows maintainers of the repo to modify this
// pull request, eg. push changes to it before merging.
MaintainerCanModify *bool `json:"maintainer_can_modify,omitempty"`
}{
Title: title,
Body: body,
Base: branch,
MaintainerCanModify: canModify,
}
if open != nil && *open {
op := "open"
data.State = &op
} else if open != nil {
cl := "clossed"
data.State = &cl
}
_, err := c.request(&request{
// allow the description and draft fields
// https://developer.github.com/changes/2018-02-22-label-description-search-preview/
// https://developer.github.com/changes/2019-02-14-draft-pull-requests/
accept: "application/vnd.github.symmetra-preview+json, application/vnd.github.shadow-cat-preview",
method: http.MethodPatch,
path: fmt.Sprintf("/repos/%s/%s/pulls/%d", org, repo, number),
requestBody: &data,
exitCodes: []int{200},
}, nil)
return err
}
|
go
|
func (c *Client) UpdatePullRequest(org, repo string, number int, title, body *string, open *bool, branch *string, canModify *bool) error {
c.log("UpdatePullRequest", org, repo, title)
data := struct {
State *string `json:"state,omitempty"`
Title *string `json:"title,omitempty"`
Body *string `json:"body,omitempty"`
Base *string `json:"base,omitempty"`
// MaintainerCanModify allows maintainers of the repo to modify this
// pull request, eg. push changes to it before merging.
MaintainerCanModify *bool `json:"maintainer_can_modify,omitempty"`
}{
Title: title,
Body: body,
Base: branch,
MaintainerCanModify: canModify,
}
if open != nil && *open {
op := "open"
data.State = &op
} else if open != nil {
cl := "clossed"
data.State = &cl
}
_, err := c.request(&request{
// allow the description and draft fields
// https://developer.github.com/changes/2018-02-22-label-description-search-preview/
// https://developer.github.com/changes/2019-02-14-draft-pull-requests/
accept: "application/vnd.github.symmetra-preview+json, application/vnd.github.shadow-cat-preview",
method: http.MethodPatch,
path: fmt.Sprintf("/repos/%s/%s/pulls/%d", org, repo, number),
requestBody: &data,
exitCodes: []int{200},
}, nil)
return err
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"UpdatePullRequest",
"(",
"org",
",",
"repo",
"string",
",",
"number",
"int",
",",
"title",
",",
"body",
"*",
"string",
",",
"open",
"*",
"bool",
",",
"branch",
"*",
"string",
",",
"canModify",
"*",
"bool",
")",
"error",
"{",
"c",
".",
"log",
"(",
"\"UpdatePullRequest\"",
",",
"org",
",",
"repo",
",",
"title",
")",
"\n",
"data",
":=",
"struct",
"{",
"State",
"*",
"string",
"`json:\"state,omitempty\"`",
"\n",
"Title",
"*",
"string",
"`json:\"title,omitempty\"`",
"\n",
"Body",
"*",
"string",
"`json:\"body,omitempty\"`",
"\n",
"Base",
"*",
"string",
"`json:\"base,omitempty\"`",
"\n",
"MaintainerCanModify",
"*",
"bool",
"`json:\"maintainer_can_modify,omitempty\"`",
"\n",
"}",
"{",
"Title",
":",
"title",
",",
"Body",
":",
"body",
",",
"Base",
":",
"branch",
",",
"MaintainerCanModify",
":",
"canModify",
",",
"}",
"\n",
"if",
"open",
"!=",
"nil",
"&&",
"*",
"open",
"{",
"op",
":=",
"\"open\"",
"\n",
"data",
".",
"State",
"=",
"&",
"op",
"\n",
"}",
"else",
"if",
"open",
"!=",
"nil",
"{",
"cl",
":=",
"\"clossed\"",
"\n",
"data",
".",
"State",
"=",
"&",
"cl",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"c",
".",
"request",
"(",
"&",
"request",
"{",
"accept",
":",
"\"application/vnd.github.symmetra-preview+json, application/vnd.github.shadow-cat-preview\"",
",",
"method",
":",
"http",
".",
"MethodPatch",
",",
"path",
":",
"fmt",
".",
"Sprintf",
"(",
"\"/repos/%s/%s/pulls/%d\"",
",",
"org",
",",
"repo",
",",
"number",
")",
",",
"requestBody",
":",
"&",
"data",
",",
"exitCodes",
":",
"[",
"]",
"int",
"{",
"200",
"}",
",",
"}",
",",
"nil",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// UpdatePullRequest modifies the title, body, open state
|
[
"UpdatePullRequest",
"modifies",
"the",
"title",
"body",
"open",
"state"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L1154-L1188
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
getLabels
|
func (c *Client) getLabels(path string) ([]Label, error) {
var labels []Label
if c.fake {
return labels, nil
}
err := c.readPaginatedResults(
path,
"application/vnd.github.symmetra-preview+json", // allow the description field -- https://developer.github.com/changes/2018-02-22-label-description-search-preview/
func() interface{} {
return &[]Label{}
},
func(obj interface{}) {
labels = append(labels, *(obj.(*[]Label))...)
},
)
if err != nil {
return nil, err
}
return labels, nil
}
|
go
|
func (c *Client) getLabels(path string) ([]Label, error) {
var labels []Label
if c.fake {
return labels, nil
}
err := c.readPaginatedResults(
path,
"application/vnd.github.symmetra-preview+json", // allow the description field -- https://developer.github.com/changes/2018-02-22-label-description-search-preview/
func() interface{} {
return &[]Label{}
},
func(obj interface{}) {
labels = append(labels, *(obj.(*[]Label))...)
},
)
if err != nil {
return nil, err
}
return labels, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"getLabels",
"(",
"path",
"string",
")",
"(",
"[",
"]",
"Label",
",",
"error",
")",
"{",
"var",
"labels",
"[",
"]",
"Label",
"\n",
"if",
"c",
".",
"fake",
"{",
"return",
"labels",
",",
"nil",
"\n",
"}",
"\n",
"err",
":=",
"c",
".",
"readPaginatedResults",
"(",
"path",
",",
"\"application/vnd.github.symmetra-preview+json\"",
",",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"return",
"&",
"[",
"]",
"Label",
"{",
"}",
"\n",
"}",
",",
"func",
"(",
"obj",
"interface",
"{",
"}",
")",
"{",
"labels",
"=",
"append",
"(",
"labels",
",",
"*",
"(",
"obj",
".",
"(",
"*",
"[",
"]",
"Label",
")",
")",
"...",
")",
"\n",
"}",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"labels",
",",
"nil",
"\n",
"}"
] |
// getLabels is a helper function that retrieves a paginated list of labels from a github URI path.
|
[
"getLabels",
"is",
"a",
"helper",
"function",
"that",
"retrieves",
"a",
"paginated",
"list",
"of",
"labels",
"from",
"a",
"github",
"URI",
"path",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L1496-L1515
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
stateCannotBeChangedOrOriginalError
|
func stateCannotBeChangedOrOriginalError(err error) error {
requestErr, ok := err.(requestError)
if ok {
for _, errorMsg := range requestErr.ErrorMessages() {
if strings.Contains(errorMsg, stateCannotBeChangedMessagePrefix) {
return StateCannotBeChanged{
Message: errorMsg,
}
}
}
}
return err
}
|
go
|
func stateCannotBeChangedOrOriginalError(err error) error {
requestErr, ok := err.(requestError)
if ok {
for _, errorMsg := range requestErr.ErrorMessages() {
if strings.Contains(errorMsg, stateCannotBeChangedMessagePrefix) {
return StateCannotBeChanged{
Message: errorMsg,
}
}
}
}
return err
}
|
[
"func",
"stateCannotBeChangedOrOriginalError",
"(",
"err",
"error",
")",
"error",
"{",
"requestErr",
",",
"ok",
":=",
"err",
".",
"(",
"requestError",
")",
"\n",
"if",
"ok",
"{",
"for",
"_",
",",
"errorMsg",
":=",
"range",
"requestErr",
".",
"ErrorMessages",
"(",
")",
"{",
"if",
"strings",
".",
"Contains",
"(",
"errorMsg",
",",
"stateCannotBeChangedMessagePrefix",
")",
"{",
"return",
"StateCannotBeChanged",
"{",
"Message",
":",
"errorMsg",
",",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// convert to a StateCannotBeChanged if appropriate or else return the original error
|
[
"convert",
"to",
"a",
"StateCannotBeChanged",
"if",
"appropriate",
"or",
"else",
"return",
"the",
"original",
"error"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L1845-L1857
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
IsMergeable
|
func (c *Client) IsMergeable(org, repo string, number int, SHA string) (bool, error) {
backoff := time.Second * 3
maxTries := 3
for try := 0; try < maxTries; try++ {
pr, err := c.GetPullRequest(org, repo, number)
if err != nil {
return false, err
}
if pr.Head.SHA != SHA {
return false, fmt.Errorf("pull request head changed while checking mergeability (%s -> %s)", SHA, pr.Head.SHA)
}
if pr.Merged {
return false, errors.New("pull request was merged while checking mergeability")
}
if pr.Mergable != nil {
return *pr.Mergable, nil
}
if try+1 < maxTries {
c.time.Sleep(backoff)
backoff *= 2
}
}
return false, fmt.Errorf("reached maximum number of retries (%d) checking mergeability", maxTries)
}
|
go
|
func (c *Client) IsMergeable(org, repo string, number int, SHA string) (bool, error) {
backoff := time.Second * 3
maxTries := 3
for try := 0; try < maxTries; try++ {
pr, err := c.GetPullRequest(org, repo, number)
if err != nil {
return false, err
}
if pr.Head.SHA != SHA {
return false, fmt.Errorf("pull request head changed while checking mergeability (%s -> %s)", SHA, pr.Head.SHA)
}
if pr.Merged {
return false, errors.New("pull request was merged while checking mergeability")
}
if pr.Mergable != nil {
return *pr.Mergable, nil
}
if try+1 < maxTries {
c.time.Sleep(backoff)
backoff *= 2
}
}
return false, fmt.Errorf("reached maximum number of retries (%d) checking mergeability", maxTries)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"IsMergeable",
"(",
"org",
",",
"repo",
"string",
",",
"number",
"int",
",",
"SHA",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"backoff",
":=",
"time",
".",
"Second",
"*",
"3",
"\n",
"maxTries",
":=",
"3",
"\n",
"for",
"try",
":=",
"0",
";",
"try",
"<",
"maxTries",
";",
"try",
"++",
"{",
"pr",
",",
"err",
":=",
"c",
".",
"GetPullRequest",
"(",
"org",
",",
"repo",
",",
"number",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"pr",
".",
"Head",
".",
"SHA",
"!=",
"SHA",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"pull request head changed while checking mergeability (%s -> %s)\"",
",",
"SHA",
",",
"pr",
".",
"Head",
".",
"SHA",
")",
"\n",
"}",
"\n",
"if",
"pr",
".",
"Merged",
"{",
"return",
"false",
",",
"errors",
".",
"New",
"(",
"\"pull request was merged while checking mergeability\"",
")",
"\n",
"}",
"\n",
"if",
"pr",
".",
"Mergable",
"!=",
"nil",
"{",
"return",
"*",
"pr",
".",
"Mergable",
",",
"nil",
"\n",
"}",
"\n",
"if",
"try",
"+",
"1",
"<",
"maxTries",
"{",
"c",
".",
"time",
".",
"Sleep",
"(",
"backoff",
")",
"\n",
"backoff",
"*=",
"2",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"reached maximum number of retries (%d) checking mergeability\"",
",",
"maxTries",
")",
"\n",
"}"
] |
// IsMergeable determines if a PR can be merged.
// Mergeability is calculated by a background job on GitHub and is not immediately available when
// new commits are added so the PR must be polled until the background job completes.
|
[
"IsMergeable",
"determines",
"if",
"a",
"PR",
"can",
"be",
"merged",
".",
"Mergeability",
"is",
"calculated",
"by",
"a",
"background",
"job",
"on",
"GitHub",
"and",
"is",
"not",
"immediately",
"available",
"when",
"new",
"commits",
"are",
"added",
"so",
"the",
"PR",
"must",
"be",
"polled",
"until",
"the",
"background",
"job",
"completes",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L2480-L2503
|
test
|
kubernetes/test-infra
|
prow/github/client.go
|
Token
|
func (s *reloadingTokenSource) Token() (*oauth2.Token, error) {
return &oauth2.Token{
AccessToken: string(s.getToken()),
}, nil
}
|
go
|
func (s *reloadingTokenSource) Token() (*oauth2.Token, error) {
return &oauth2.Token{
AccessToken: string(s.getToken()),
}, nil
}
|
[
"func",
"(",
"s",
"*",
"reloadingTokenSource",
")",
"Token",
"(",
")",
"(",
"*",
"oauth2",
".",
"Token",
",",
"error",
")",
"{",
"return",
"&",
"oauth2",
".",
"Token",
"{",
"AccessToken",
":",
"string",
"(",
"s",
".",
"getToken",
"(",
")",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// Token is an implementation for oauth2.TokenSource interface.
|
[
"Token",
"is",
"an",
"implementation",
"for",
"oauth2",
".",
"TokenSource",
"interface",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/github/client.go#L2603-L2607
|
test
|
kubernetes/test-infra
|
prow/spyglass/artifacts.go
|
ListArtifacts
|
func (s *Spyglass) ListArtifacts(src string) ([]string, error) {
keyType, key, err := splitSrc(src)
if err != nil {
return []string{}, fmt.Errorf("error parsing src: %v", err)
}
gcsKey := ""
switch keyType {
case gcsKeyType:
gcsKey = key
case prowKeyType:
if gcsKey, err = s.prowToGCS(key); err != nil {
logrus.Warningf("Failed to get gcs source for prow job: %v", err)
}
default:
return nil, fmt.Errorf("Unrecognized key type for src: %v", src)
}
artifactNames, err := s.GCSArtifactFetcher.artifacts(gcsKey)
logFound := false
for _, name := range artifactNames {
if name == "build-log.txt" {
logFound = true
break
}
}
if err != nil || !logFound {
artifactNames = append(artifactNames, "build-log.txt")
}
return artifactNames, nil
}
|
go
|
func (s *Spyglass) ListArtifacts(src string) ([]string, error) {
keyType, key, err := splitSrc(src)
if err != nil {
return []string{}, fmt.Errorf("error parsing src: %v", err)
}
gcsKey := ""
switch keyType {
case gcsKeyType:
gcsKey = key
case prowKeyType:
if gcsKey, err = s.prowToGCS(key); err != nil {
logrus.Warningf("Failed to get gcs source for prow job: %v", err)
}
default:
return nil, fmt.Errorf("Unrecognized key type for src: %v", src)
}
artifactNames, err := s.GCSArtifactFetcher.artifacts(gcsKey)
logFound := false
for _, name := range artifactNames {
if name == "build-log.txt" {
logFound = true
break
}
}
if err != nil || !logFound {
artifactNames = append(artifactNames, "build-log.txt")
}
return artifactNames, nil
}
|
[
"func",
"(",
"s",
"*",
"Spyglass",
")",
"ListArtifacts",
"(",
"src",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"keyType",
",",
"key",
",",
"err",
":=",
"splitSrc",
"(",
"src",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"[",
"]",
"string",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"error parsing src: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"gcsKey",
":=",
"\"\"",
"\n",
"switch",
"keyType",
"{",
"case",
"gcsKeyType",
":",
"gcsKey",
"=",
"key",
"\n",
"case",
"prowKeyType",
":",
"if",
"gcsKey",
",",
"err",
"=",
"s",
".",
"prowToGCS",
"(",
"key",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warningf",
"(",
"\"Failed to get gcs source for prow job: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"Unrecognized key type for src: %v\"",
",",
"src",
")",
"\n",
"}",
"\n",
"artifactNames",
",",
"err",
":=",
"s",
".",
"GCSArtifactFetcher",
".",
"artifacts",
"(",
"gcsKey",
")",
"\n",
"logFound",
":=",
"false",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"artifactNames",
"{",
"if",
"name",
"==",
"\"build-log.txt\"",
"{",
"logFound",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"!",
"logFound",
"{",
"artifactNames",
"=",
"append",
"(",
"artifactNames",
",",
"\"build-log.txt\"",
")",
"\n",
"}",
"\n",
"return",
"artifactNames",
",",
"nil",
"\n",
"}"
] |
// ListArtifacts gets the names of all artifacts available from the given source
|
[
"ListArtifacts",
"gets",
"the",
"names",
"of",
"all",
"artifacts",
"available",
"from",
"the",
"given",
"source"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/artifacts.go#L29-L58
|
test
|
kubernetes/test-infra
|
prow/spyglass/artifacts.go
|
KeyToJob
|
func (*Spyglass) KeyToJob(src string) (jobName string, buildID string, err error) {
src = strings.Trim(src, "/")
parsed := strings.Split(src, "/")
if len(parsed) < 2 {
return "", "", fmt.Errorf("expected at least two path components in %q", src)
}
jobName = parsed[len(parsed)-2]
buildID = parsed[len(parsed)-1]
return jobName, buildID, nil
}
|
go
|
func (*Spyglass) KeyToJob(src string) (jobName string, buildID string, err error) {
src = strings.Trim(src, "/")
parsed := strings.Split(src, "/")
if len(parsed) < 2 {
return "", "", fmt.Errorf("expected at least two path components in %q", src)
}
jobName = parsed[len(parsed)-2]
buildID = parsed[len(parsed)-1]
return jobName, buildID, nil
}
|
[
"func",
"(",
"*",
"Spyglass",
")",
"KeyToJob",
"(",
"src",
"string",
")",
"(",
"jobName",
"string",
",",
"buildID",
"string",
",",
"err",
"error",
")",
"{",
"src",
"=",
"strings",
".",
"Trim",
"(",
"src",
",",
"\"/\"",
")",
"\n",
"parsed",
":=",
"strings",
".",
"Split",
"(",
"src",
",",
"\"/\"",
")",
"\n",
"if",
"len",
"(",
"parsed",
")",
"<",
"2",
"{",
"return",
"\"\"",
",",
"\"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"expected at least two path components in %q\"",
",",
"src",
")",
"\n",
"}",
"\n",
"jobName",
"=",
"parsed",
"[",
"len",
"(",
"parsed",
")",
"-",
"2",
"]",
"\n",
"buildID",
"=",
"parsed",
"[",
"len",
"(",
"parsed",
")",
"-",
"1",
"]",
"\n",
"return",
"jobName",
",",
"buildID",
",",
"nil",
"\n",
"}"
] |
// KeyToJob takes a spyglass URL and returns the jobName and buildID.
|
[
"KeyToJob",
"takes",
"a",
"spyglass",
"URL",
"and",
"returns",
"the",
"jobName",
"and",
"buildID",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/artifacts.go#L61-L70
|
test
|
kubernetes/test-infra
|
prow/spyglass/artifacts.go
|
prowToGCS
|
func (s *Spyglass) prowToGCS(prowKey string) (string, error) {
jobName, buildID, err := s.KeyToJob(prowKey)
if err != nil {
return "", fmt.Errorf("could not get GCS src: %v", err)
}
job, err := s.jobAgent.GetProwJob(jobName, buildID)
if err != nil {
return "", fmt.Errorf("Failed to get prow job from src %q: %v", prowKey, err)
}
url := job.Status.URL
prefix := s.config().Plank.GetJobURLPrefix(job.Spec.Refs)
if !strings.HasPrefix(url, prefix) {
return "", fmt.Errorf("unexpected job URL %q when finding GCS path: expected something starting with %q", url, prefix)
}
return url[len(prefix):], nil
}
|
go
|
func (s *Spyglass) prowToGCS(prowKey string) (string, error) {
jobName, buildID, err := s.KeyToJob(prowKey)
if err != nil {
return "", fmt.Errorf("could not get GCS src: %v", err)
}
job, err := s.jobAgent.GetProwJob(jobName, buildID)
if err != nil {
return "", fmt.Errorf("Failed to get prow job from src %q: %v", prowKey, err)
}
url := job.Status.URL
prefix := s.config().Plank.GetJobURLPrefix(job.Spec.Refs)
if !strings.HasPrefix(url, prefix) {
return "", fmt.Errorf("unexpected job URL %q when finding GCS path: expected something starting with %q", url, prefix)
}
return url[len(prefix):], nil
}
|
[
"func",
"(",
"s",
"*",
"Spyglass",
")",
"prowToGCS",
"(",
"prowKey",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"jobName",
",",
"buildID",
",",
"err",
":=",
"s",
".",
"KeyToJob",
"(",
"prowKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"could not get GCS src: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"job",
",",
"err",
":=",
"s",
".",
"jobAgent",
".",
"GetProwJob",
"(",
"jobName",
",",
"buildID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"Failed to get prow job from src %q: %v\"",
",",
"prowKey",
",",
"err",
")",
"\n",
"}",
"\n",
"url",
":=",
"job",
".",
"Status",
".",
"URL",
"\n",
"prefix",
":=",
"s",
".",
"config",
"(",
")",
".",
"Plank",
".",
"GetJobURLPrefix",
"(",
"job",
".",
"Spec",
".",
"Refs",
")",
"\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"url",
",",
"prefix",
")",
"{",
"return",
"\"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"unexpected job URL %q when finding GCS path: expected something starting with %q\"",
",",
"url",
",",
"prefix",
")",
"\n",
"}",
"\n",
"return",
"url",
"[",
"len",
"(",
"prefix",
")",
":",
"]",
",",
"nil",
"\n",
"}"
] |
// prowToGCS returns the GCS key corresponding to the given prow key
|
[
"prowToGCS",
"returns",
"the",
"GCS",
"key",
"corresponding",
"to",
"the",
"given",
"prow",
"key"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/artifacts.go#L73-L90
|
test
|
kubernetes/test-infra
|
prow/spyglass/artifacts.go
|
FetchArtifacts
|
func (s *Spyglass) FetchArtifacts(src string, podName string, sizeLimit int64, artifactNames []string) ([]lenses.Artifact, error) {
artStart := time.Now()
arts := []lenses.Artifact{}
keyType, key, err := splitSrc(src)
if err != nil {
return arts, fmt.Errorf("error parsing src: %v", err)
}
jobName, buildID, err := s.KeyToJob(src)
if err != nil {
return arts, fmt.Errorf("could not derive job: %v", err)
}
gcsKey := ""
switch keyType {
case gcsKeyType:
gcsKey = strings.TrimSuffix(key, "/")
case prowKeyType:
if gcsKey, err = s.prowToGCS(key); err != nil {
logrus.Warningln(err)
}
default:
return nil, fmt.Errorf("invalid src: %v", src)
}
podLogNeeded := false
for _, name := range artifactNames {
art, err := s.GCSArtifactFetcher.artifact(gcsKey, name, sizeLimit)
if err == nil {
// Actually try making a request, because calling GCSArtifactFetcher.artifact does no I/O.
// (these files are being explicitly requested and so will presumably soon be accessed, so
// the extra network I/O should not be too problematic).
_, err = art.Size()
}
if err != nil {
if name == "build-log.txt" {
podLogNeeded = true
}
continue
}
arts = append(arts, art)
}
if podLogNeeded {
art, err := s.PodLogArtifactFetcher.artifact(jobName, buildID, sizeLimit)
if err != nil {
logrus.Errorf("Failed to fetch pod log: %v", err)
} else {
arts = append(arts, art)
}
}
logrus.WithField("duration", time.Since(artStart)).Infof("Retrieved artifacts for %v", src)
return arts, nil
}
|
go
|
func (s *Spyglass) FetchArtifacts(src string, podName string, sizeLimit int64, artifactNames []string) ([]lenses.Artifact, error) {
artStart := time.Now()
arts := []lenses.Artifact{}
keyType, key, err := splitSrc(src)
if err != nil {
return arts, fmt.Errorf("error parsing src: %v", err)
}
jobName, buildID, err := s.KeyToJob(src)
if err != nil {
return arts, fmt.Errorf("could not derive job: %v", err)
}
gcsKey := ""
switch keyType {
case gcsKeyType:
gcsKey = strings.TrimSuffix(key, "/")
case prowKeyType:
if gcsKey, err = s.prowToGCS(key); err != nil {
logrus.Warningln(err)
}
default:
return nil, fmt.Errorf("invalid src: %v", src)
}
podLogNeeded := false
for _, name := range artifactNames {
art, err := s.GCSArtifactFetcher.artifact(gcsKey, name, sizeLimit)
if err == nil {
// Actually try making a request, because calling GCSArtifactFetcher.artifact does no I/O.
// (these files are being explicitly requested and so will presumably soon be accessed, so
// the extra network I/O should not be too problematic).
_, err = art.Size()
}
if err != nil {
if name == "build-log.txt" {
podLogNeeded = true
}
continue
}
arts = append(arts, art)
}
if podLogNeeded {
art, err := s.PodLogArtifactFetcher.artifact(jobName, buildID, sizeLimit)
if err != nil {
logrus.Errorf("Failed to fetch pod log: %v", err)
} else {
arts = append(arts, art)
}
}
logrus.WithField("duration", time.Since(artStart)).Infof("Retrieved artifacts for %v", src)
return arts, nil
}
|
[
"func",
"(",
"s",
"*",
"Spyglass",
")",
"FetchArtifacts",
"(",
"src",
"string",
",",
"podName",
"string",
",",
"sizeLimit",
"int64",
",",
"artifactNames",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"lenses",
".",
"Artifact",
",",
"error",
")",
"{",
"artStart",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"arts",
":=",
"[",
"]",
"lenses",
".",
"Artifact",
"{",
"}",
"\n",
"keyType",
",",
"key",
",",
"err",
":=",
"splitSrc",
"(",
"src",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"arts",
",",
"fmt",
".",
"Errorf",
"(",
"\"error parsing src: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"jobName",
",",
"buildID",
",",
"err",
":=",
"s",
".",
"KeyToJob",
"(",
"src",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"arts",
",",
"fmt",
".",
"Errorf",
"(",
"\"could not derive job: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"gcsKey",
":=",
"\"\"",
"\n",
"switch",
"keyType",
"{",
"case",
"gcsKeyType",
":",
"gcsKey",
"=",
"strings",
".",
"TrimSuffix",
"(",
"key",
",",
"\"/\"",
")",
"\n",
"case",
"prowKeyType",
":",
"if",
"gcsKey",
",",
"err",
"=",
"s",
".",
"prowToGCS",
"(",
"key",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warningln",
"(",
"err",
")",
"\n",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"invalid src: %v\"",
",",
"src",
")",
"\n",
"}",
"\n",
"podLogNeeded",
":=",
"false",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"artifactNames",
"{",
"art",
",",
"err",
":=",
"s",
".",
"GCSArtifactFetcher",
".",
"artifact",
"(",
"gcsKey",
",",
"name",
",",
"sizeLimit",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"_",
",",
"err",
"=",
"art",
".",
"Size",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"name",
"==",
"\"build-log.txt\"",
"{",
"podLogNeeded",
"=",
"true",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"arts",
"=",
"append",
"(",
"arts",
",",
"art",
")",
"\n",
"}",
"\n",
"if",
"podLogNeeded",
"{",
"art",
",",
"err",
":=",
"s",
".",
"PodLogArtifactFetcher",
".",
"artifact",
"(",
"jobName",
",",
"buildID",
",",
"sizeLimit",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"Failed to fetch pod log: %v\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"arts",
"=",
"append",
"(",
"arts",
",",
"art",
")",
"\n",
"}",
"\n",
"}",
"\n",
"logrus",
".",
"WithField",
"(",
"\"duration\"",
",",
"time",
".",
"Since",
"(",
"artStart",
")",
")",
".",
"Infof",
"(",
"\"Retrieved artifacts for %v\"",
",",
"src",
")",
"\n",
"return",
"arts",
",",
"nil",
"\n",
"}"
] |
// FetchArtifacts constructs and returns Artifact objects for each artifact name in the list.
// This includes getting any handles needed for read write operations, direct artifact links, etc.
|
[
"FetchArtifacts",
"constructs",
"and",
"returns",
"Artifact",
"objects",
"for",
"each",
"artifact",
"name",
"in",
"the",
"list",
".",
"This",
"includes",
"getting",
"any",
"handles",
"needed",
"for",
"read",
"write",
"operations",
"direct",
"artifact",
"links",
"etc",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/artifacts.go#L94-L146
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *DecorationConfig) DeepCopy() *DecorationConfig {
if in == nil {
return nil
}
out := new(DecorationConfig)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *DecorationConfig) DeepCopy() *DecorationConfig {
if in == nil {
return nil
}
out := new(DecorationConfig)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"DecorationConfig",
")",
"DeepCopy",
"(",
")",
"*",
"DecorationConfig",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"DecorationConfig",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DecorationConfig.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"DecorationConfig",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/zz_generated.deepcopy.go#L64-L71
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *GCSConfiguration) DeepCopy() *GCSConfiguration {
if in == nil {
return nil
}
out := new(GCSConfiguration)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *GCSConfiguration) DeepCopy() *GCSConfiguration {
if in == nil {
return nil
}
out := new(GCSConfiguration)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"GCSConfiguration",
")",
"DeepCopy",
"(",
")",
"*",
"GCSConfiguration",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"GCSConfiguration",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GCSConfiguration.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"GCSConfiguration",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/zz_generated.deepcopy.go#L96-L103
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *JenkinsSpec) DeepCopy() *JenkinsSpec {
if in == nil {
return nil
}
out := new(JenkinsSpec)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *JenkinsSpec) DeepCopy() *JenkinsSpec {
if in == nil {
return nil
}
out := new(JenkinsSpec)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"JenkinsSpec",
")",
"DeepCopy",
"(",
")",
"*",
"JenkinsSpec",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"JenkinsSpec",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JenkinsSpec.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"JenkinsSpec",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/zz_generated.deepcopy.go#L112-L119
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *ProwJob) DeepCopy() *ProwJob {
if in == nil {
return nil
}
out := new(ProwJob)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *ProwJob) DeepCopy() *ProwJob {
if in == nil {
return nil
}
out := new(ProwJob)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"ProwJob",
")",
"DeepCopy",
"(",
")",
"*",
"ProwJob",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"ProwJob",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProwJob.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"ProwJob",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/zz_generated.deepcopy.go#L132-L139
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *ProwJobList) DeepCopy() *ProwJobList {
if in == nil {
return nil
}
out := new(ProwJobList)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *ProwJobList) DeepCopy() *ProwJobList {
if in == nil {
return nil
}
out := new(ProwJobList)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"ProwJobList",
")",
"DeepCopy",
"(",
")",
"*",
"ProwJobList",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"ProwJobList",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProwJobList.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"ProwJobList",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/zz_generated.deepcopy.go#L165-L172
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *ProwJobSpec) DeepCopy() *ProwJobSpec {
if in == nil {
return nil
}
out := new(ProwJobSpec)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *ProwJobSpec) DeepCopy() *ProwJobSpec {
if in == nil {
return nil
}
out := new(ProwJobSpec)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"ProwJobSpec",
")",
"DeepCopy",
"(",
")",
"*",
"ProwJobSpec",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"ProwJobSpec",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProwJobSpec.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"ProwJobSpec",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/zz_generated.deepcopy.go#L226-L233
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *ProwJobStatus) DeepCopy() *ProwJobStatus {
if in == nil {
return nil
}
out := new(ProwJobStatus)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *ProwJobStatus) DeepCopy() *ProwJobStatus {
if in == nil {
return nil
}
out := new(ProwJobStatus)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"ProwJobStatus",
")",
"DeepCopy",
"(",
")",
"*",
"ProwJobStatus",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"ProwJobStatus",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProwJobStatus.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"ProwJobStatus",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/zz_generated.deepcopy.go#L254-L261
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *Pull) DeepCopy() *Pull {
if in == nil {
return nil
}
out := new(Pull)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *Pull) DeepCopy() *Pull {
if in == nil {
return nil
}
out := new(Pull)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"Pull",
")",
"DeepCopy",
"(",
")",
"*",
"Pull",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"Pull",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Pull.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"Pull",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/zz_generated.deepcopy.go#L270-L277
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *Refs) DeepCopy() *Refs {
if in == nil {
return nil
}
out := new(Refs)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *Refs) DeepCopy() *Refs {
if in == nil {
return nil
}
out := new(Refs)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"Refs",
")",
"DeepCopy",
"(",
")",
"*",
"Refs",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"Refs",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Refs.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"Refs",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/zz_generated.deepcopy.go#L291-L298
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *UtilityImages) DeepCopy() *UtilityImages {
if in == nil {
return nil
}
out := new(UtilityImages)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *UtilityImages) DeepCopy() *UtilityImages {
if in == nil {
return nil
}
out := new(UtilityImages)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"UtilityImages",
")",
"DeepCopy",
"(",
")",
"*",
"UtilityImages",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"UtilityImages",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UtilityImages.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"UtilityImages",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/zz_generated.deepcopy.go#L307-L314
|
test
|
kubernetes/test-infra
|
experiment/resultstore/upload.go
|
upload
|
func upload(rsClient *resultstore.Client, inv resultstore.Invocation, target resultstore.Target, test resultstore.Test) (string, error) {
targetID := test.Name
const configID = resultstore.Default
invName, err := rsClient.Invocations().Create(inv)
if err != nil {
return "", fmt.Errorf("create invocation: %v", err)
}
targetName, err := rsClient.Targets(invName).Create(targetID, target)
if err != nil {
return resultstore.URL(invName), fmt.Errorf("create target: %v", err)
}
url := resultstore.URL(targetName)
_, err = rsClient.Configurations(invName).Create(configID)
if err != nil {
return url, fmt.Errorf("create configuration: %v", err)
}
ctName, err := rsClient.ConfiguredTargets(targetName, configID).Create(test.Action)
if err != nil {
return url, fmt.Errorf("create configured target: %v", err)
}
_, err = rsClient.Actions(ctName).Create("primary", test)
if err != nil {
return url, fmt.Errorf("create action: %v", err)
}
return url, nil
}
|
go
|
func upload(rsClient *resultstore.Client, inv resultstore.Invocation, target resultstore.Target, test resultstore.Test) (string, error) {
targetID := test.Name
const configID = resultstore.Default
invName, err := rsClient.Invocations().Create(inv)
if err != nil {
return "", fmt.Errorf("create invocation: %v", err)
}
targetName, err := rsClient.Targets(invName).Create(targetID, target)
if err != nil {
return resultstore.URL(invName), fmt.Errorf("create target: %v", err)
}
url := resultstore.URL(targetName)
_, err = rsClient.Configurations(invName).Create(configID)
if err != nil {
return url, fmt.Errorf("create configuration: %v", err)
}
ctName, err := rsClient.ConfiguredTargets(targetName, configID).Create(test.Action)
if err != nil {
return url, fmt.Errorf("create configured target: %v", err)
}
_, err = rsClient.Actions(ctName).Create("primary", test)
if err != nil {
return url, fmt.Errorf("create action: %v", err)
}
return url, nil
}
|
[
"func",
"upload",
"(",
"rsClient",
"*",
"resultstore",
".",
"Client",
",",
"inv",
"resultstore",
".",
"Invocation",
",",
"target",
"resultstore",
".",
"Target",
",",
"test",
"resultstore",
".",
"Test",
")",
"(",
"string",
",",
"error",
")",
"{",
"targetID",
":=",
"test",
".",
"Name",
"\n",
"const",
"configID",
"=",
"resultstore",
".",
"Default",
"\n",
"invName",
",",
"err",
":=",
"rsClient",
".",
"Invocations",
"(",
")",
".",
"Create",
"(",
"inv",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"create invocation: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"targetName",
",",
"err",
":=",
"rsClient",
".",
"Targets",
"(",
"invName",
")",
".",
"Create",
"(",
"targetID",
",",
"target",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"resultstore",
".",
"URL",
"(",
"invName",
")",
",",
"fmt",
".",
"Errorf",
"(",
"\"create target: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"url",
":=",
"resultstore",
".",
"URL",
"(",
"targetName",
")",
"\n",
"_",
",",
"err",
"=",
"rsClient",
".",
"Configurations",
"(",
"invName",
")",
".",
"Create",
"(",
"configID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"url",
",",
"fmt",
".",
"Errorf",
"(",
"\"create configuration: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"ctName",
",",
"err",
":=",
"rsClient",
".",
"ConfiguredTargets",
"(",
"targetName",
",",
"configID",
")",
".",
"Create",
"(",
"test",
".",
"Action",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"url",
",",
"fmt",
".",
"Errorf",
"(",
"\"create configured target: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"rsClient",
".",
"Actions",
"(",
"ctName",
")",
".",
"Create",
"(",
"\"primary\"",
",",
"test",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"url",
",",
"fmt",
".",
"Errorf",
"(",
"\"create action: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"url",
",",
"nil",
"\n",
"}"
] |
// upload the result downloaded from path into project.
|
[
"upload",
"the",
"result",
"downloaded",
"from",
"path",
"into",
"project",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/experiment/resultstore/upload.go#L44-L70
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/types.go
|
ApplyDefault
|
func (d *DecorationConfig) ApplyDefault(def *DecorationConfig) *DecorationConfig {
if d == nil && def == nil {
return nil
}
var merged DecorationConfig
if d != nil {
merged = *d
} else {
merged = *def
}
if d == nil || def == nil {
return &merged
}
merged.UtilityImages = merged.UtilityImages.ApplyDefault(def.UtilityImages)
merged.GCSConfiguration = merged.GCSConfiguration.ApplyDefault(def.GCSConfiguration)
if merged.Timeout.Duration == 0 {
merged.Timeout = def.Timeout
}
if merged.GracePeriod.Duration == 0 {
merged.GracePeriod = def.GracePeriod
}
if merged.GCSCredentialsSecret == "" {
merged.GCSCredentialsSecret = def.GCSCredentialsSecret
}
if len(merged.SSHKeySecrets) == 0 {
merged.SSHKeySecrets = def.SSHKeySecrets
}
if len(merged.SSHHostFingerprints) == 0 {
merged.SSHHostFingerprints = def.SSHHostFingerprints
}
if merged.SkipCloning == nil {
merged.SkipCloning = def.SkipCloning
}
if merged.CookiefileSecret == "" {
merged.CookiefileSecret = def.CookiefileSecret
}
return &merged
}
|
go
|
func (d *DecorationConfig) ApplyDefault(def *DecorationConfig) *DecorationConfig {
if d == nil && def == nil {
return nil
}
var merged DecorationConfig
if d != nil {
merged = *d
} else {
merged = *def
}
if d == nil || def == nil {
return &merged
}
merged.UtilityImages = merged.UtilityImages.ApplyDefault(def.UtilityImages)
merged.GCSConfiguration = merged.GCSConfiguration.ApplyDefault(def.GCSConfiguration)
if merged.Timeout.Duration == 0 {
merged.Timeout = def.Timeout
}
if merged.GracePeriod.Duration == 0 {
merged.GracePeriod = def.GracePeriod
}
if merged.GCSCredentialsSecret == "" {
merged.GCSCredentialsSecret = def.GCSCredentialsSecret
}
if len(merged.SSHKeySecrets) == 0 {
merged.SSHKeySecrets = def.SSHKeySecrets
}
if len(merged.SSHHostFingerprints) == 0 {
merged.SSHHostFingerprints = def.SSHHostFingerprints
}
if merged.SkipCloning == nil {
merged.SkipCloning = def.SkipCloning
}
if merged.CookiefileSecret == "" {
merged.CookiefileSecret = def.CookiefileSecret
}
return &merged
}
|
[
"func",
"(",
"d",
"*",
"DecorationConfig",
")",
"ApplyDefault",
"(",
"def",
"*",
"DecorationConfig",
")",
"*",
"DecorationConfig",
"{",
"if",
"d",
"==",
"nil",
"&&",
"def",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"merged",
"DecorationConfig",
"\n",
"if",
"d",
"!=",
"nil",
"{",
"merged",
"=",
"*",
"d",
"\n",
"}",
"else",
"{",
"merged",
"=",
"*",
"def",
"\n",
"}",
"\n",
"if",
"d",
"==",
"nil",
"||",
"def",
"==",
"nil",
"{",
"return",
"&",
"merged",
"\n",
"}",
"\n",
"merged",
".",
"UtilityImages",
"=",
"merged",
".",
"UtilityImages",
".",
"ApplyDefault",
"(",
"def",
".",
"UtilityImages",
")",
"\n",
"merged",
".",
"GCSConfiguration",
"=",
"merged",
".",
"GCSConfiguration",
".",
"ApplyDefault",
"(",
"def",
".",
"GCSConfiguration",
")",
"\n",
"if",
"merged",
".",
"Timeout",
".",
"Duration",
"==",
"0",
"{",
"merged",
".",
"Timeout",
"=",
"def",
".",
"Timeout",
"\n",
"}",
"\n",
"if",
"merged",
".",
"GracePeriod",
".",
"Duration",
"==",
"0",
"{",
"merged",
".",
"GracePeriod",
"=",
"def",
".",
"GracePeriod",
"\n",
"}",
"\n",
"if",
"merged",
".",
"GCSCredentialsSecret",
"==",
"\"\"",
"{",
"merged",
".",
"GCSCredentialsSecret",
"=",
"def",
".",
"GCSCredentialsSecret",
"\n",
"}",
"\n",
"if",
"len",
"(",
"merged",
".",
"SSHKeySecrets",
")",
"==",
"0",
"{",
"merged",
".",
"SSHKeySecrets",
"=",
"def",
".",
"SSHKeySecrets",
"\n",
"}",
"\n",
"if",
"len",
"(",
"merged",
".",
"SSHHostFingerprints",
")",
"==",
"0",
"{",
"merged",
".",
"SSHHostFingerprints",
"=",
"def",
".",
"SSHHostFingerprints",
"\n",
"}",
"\n",
"if",
"merged",
".",
"SkipCloning",
"==",
"nil",
"{",
"merged",
".",
"SkipCloning",
"=",
"def",
".",
"SkipCloning",
"\n",
"}",
"\n",
"if",
"merged",
".",
"CookiefileSecret",
"==",
"\"\"",
"{",
"merged",
".",
"CookiefileSecret",
"=",
"def",
".",
"CookiefileSecret",
"\n",
"}",
"\n",
"return",
"&",
"merged",
"\n",
"}"
] |
// ApplyDefault applies the defaults for the ProwJob decoration. If a field has a zero value, it
// replaces that with the value set in def.
|
[
"ApplyDefault",
"applies",
"the",
"defaults",
"for",
"the",
"ProwJob",
"decoration",
".",
"If",
"a",
"field",
"has",
"a",
"zero",
"value",
"it",
"replaces",
"that",
"with",
"the",
"value",
"set",
"in",
"def",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/types.go#L233-L272
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/types.go
|
Validate
|
func (d *DecorationConfig) Validate() error {
if d.UtilityImages == nil {
return errors.New("utility image config is not specified")
}
var missing []string
if d.UtilityImages.CloneRefs == "" {
missing = append(missing, "clonerefs")
}
if d.UtilityImages.InitUpload == "" {
missing = append(missing, "initupload")
}
if d.UtilityImages.Entrypoint == "" {
missing = append(missing, "entrypoint")
}
if d.UtilityImages.Sidecar == "" {
missing = append(missing, "sidecar")
}
if len(missing) > 0 {
return fmt.Errorf("the following utility images are not specified: %q", missing)
}
if d.GCSConfiguration == nil {
return errors.New("GCS upload configuration is not specified")
}
if d.GCSCredentialsSecret == "" {
return errors.New("GCS upload credential secret is not specified")
}
if err := d.GCSConfiguration.Validate(); err != nil {
return fmt.Errorf("GCS configuration is invalid: %v", err)
}
return nil
}
|
go
|
func (d *DecorationConfig) Validate() error {
if d.UtilityImages == nil {
return errors.New("utility image config is not specified")
}
var missing []string
if d.UtilityImages.CloneRefs == "" {
missing = append(missing, "clonerefs")
}
if d.UtilityImages.InitUpload == "" {
missing = append(missing, "initupload")
}
if d.UtilityImages.Entrypoint == "" {
missing = append(missing, "entrypoint")
}
if d.UtilityImages.Sidecar == "" {
missing = append(missing, "sidecar")
}
if len(missing) > 0 {
return fmt.Errorf("the following utility images are not specified: %q", missing)
}
if d.GCSConfiguration == nil {
return errors.New("GCS upload configuration is not specified")
}
if d.GCSCredentialsSecret == "" {
return errors.New("GCS upload credential secret is not specified")
}
if err := d.GCSConfiguration.Validate(); err != nil {
return fmt.Errorf("GCS configuration is invalid: %v", err)
}
return nil
}
|
[
"func",
"(",
"d",
"*",
"DecorationConfig",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"d",
".",
"UtilityImages",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"utility image config is not specified\"",
")",
"\n",
"}",
"\n",
"var",
"missing",
"[",
"]",
"string",
"\n",
"if",
"d",
".",
"UtilityImages",
".",
"CloneRefs",
"==",
"\"\"",
"{",
"missing",
"=",
"append",
"(",
"missing",
",",
"\"clonerefs\"",
")",
"\n",
"}",
"\n",
"if",
"d",
".",
"UtilityImages",
".",
"InitUpload",
"==",
"\"\"",
"{",
"missing",
"=",
"append",
"(",
"missing",
",",
"\"initupload\"",
")",
"\n",
"}",
"\n",
"if",
"d",
".",
"UtilityImages",
".",
"Entrypoint",
"==",
"\"\"",
"{",
"missing",
"=",
"append",
"(",
"missing",
",",
"\"entrypoint\"",
")",
"\n",
"}",
"\n",
"if",
"d",
".",
"UtilityImages",
".",
"Sidecar",
"==",
"\"\"",
"{",
"missing",
"=",
"append",
"(",
"missing",
",",
"\"sidecar\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"missing",
")",
">",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"the following utility images are not specified: %q\"",
",",
"missing",
")",
"\n",
"}",
"\n",
"if",
"d",
".",
"GCSConfiguration",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"GCS upload configuration is not specified\"",
")",
"\n",
"}",
"\n",
"if",
"d",
".",
"GCSCredentialsSecret",
"==",
"\"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"GCS upload credential secret is not specified\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"d",
".",
"GCSConfiguration",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"GCS configuration is invalid: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Validate ensures all the values set in the DecorationConfig are valid.
|
[
"Validate",
"ensures",
"all",
"the",
"values",
"set",
"in",
"the",
"DecorationConfig",
"are",
"valid",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/types.go#L275-L306
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/types.go
|
ApplyDefault
|
func (u *UtilityImages) ApplyDefault(def *UtilityImages) *UtilityImages {
if u == nil {
return def
} else if def == nil {
return u
}
merged := *u
if merged.CloneRefs == "" {
merged.CloneRefs = def.CloneRefs
}
if merged.InitUpload == "" {
merged.InitUpload = def.InitUpload
}
if merged.Entrypoint == "" {
merged.Entrypoint = def.Entrypoint
}
if merged.Sidecar == "" {
merged.Sidecar = def.Sidecar
}
return &merged
}
|
go
|
func (u *UtilityImages) ApplyDefault(def *UtilityImages) *UtilityImages {
if u == nil {
return def
} else if def == nil {
return u
}
merged := *u
if merged.CloneRefs == "" {
merged.CloneRefs = def.CloneRefs
}
if merged.InitUpload == "" {
merged.InitUpload = def.InitUpload
}
if merged.Entrypoint == "" {
merged.Entrypoint = def.Entrypoint
}
if merged.Sidecar == "" {
merged.Sidecar = def.Sidecar
}
return &merged
}
|
[
"func",
"(",
"u",
"*",
"UtilityImages",
")",
"ApplyDefault",
"(",
"def",
"*",
"UtilityImages",
")",
"*",
"UtilityImages",
"{",
"if",
"u",
"==",
"nil",
"{",
"return",
"def",
"\n",
"}",
"else",
"if",
"def",
"==",
"nil",
"{",
"return",
"u",
"\n",
"}",
"\n",
"merged",
":=",
"*",
"u",
"\n",
"if",
"merged",
".",
"CloneRefs",
"==",
"\"\"",
"{",
"merged",
".",
"CloneRefs",
"=",
"def",
".",
"CloneRefs",
"\n",
"}",
"\n",
"if",
"merged",
".",
"InitUpload",
"==",
"\"\"",
"{",
"merged",
".",
"InitUpload",
"=",
"def",
".",
"InitUpload",
"\n",
"}",
"\n",
"if",
"merged",
".",
"Entrypoint",
"==",
"\"\"",
"{",
"merged",
".",
"Entrypoint",
"=",
"def",
".",
"Entrypoint",
"\n",
"}",
"\n",
"if",
"merged",
".",
"Sidecar",
"==",
"\"\"",
"{",
"merged",
".",
"Sidecar",
"=",
"def",
".",
"Sidecar",
"\n",
"}",
"\n",
"return",
"&",
"merged",
"\n",
"}"
] |
// ApplyDefault applies the defaults for the UtilityImages decorations. If a field has a zero value,
// it replaces that with the value set in def.
|
[
"ApplyDefault",
"applies",
"the",
"defaults",
"for",
"the",
"UtilityImages",
"decorations",
".",
"If",
"a",
"field",
"has",
"a",
"zero",
"value",
"it",
"replaces",
"that",
"with",
"the",
"value",
"set",
"in",
"def",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/types.go#L323-L344
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/types.go
|
ApplyDefault
|
func (g *GCSConfiguration) ApplyDefault(def *GCSConfiguration) *GCSConfiguration {
if g == nil && def == nil {
return nil
}
var merged GCSConfiguration
if g != nil {
merged = *g
} else {
merged = *def
}
if g == nil || def == nil {
return &merged
}
if merged.Bucket == "" {
merged.Bucket = def.Bucket
}
if merged.PathPrefix == "" {
merged.PathPrefix = def.PathPrefix
}
if merged.PathStrategy == "" {
merged.PathStrategy = def.PathStrategy
}
if merged.DefaultOrg == "" {
merged.DefaultOrg = def.DefaultOrg
}
if merged.DefaultRepo == "" {
merged.DefaultRepo = def.DefaultRepo
}
return &merged
}
|
go
|
func (g *GCSConfiguration) ApplyDefault(def *GCSConfiguration) *GCSConfiguration {
if g == nil && def == nil {
return nil
}
var merged GCSConfiguration
if g != nil {
merged = *g
} else {
merged = *def
}
if g == nil || def == nil {
return &merged
}
if merged.Bucket == "" {
merged.Bucket = def.Bucket
}
if merged.PathPrefix == "" {
merged.PathPrefix = def.PathPrefix
}
if merged.PathStrategy == "" {
merged.PathStrategy = def.PathStrategy
}
if merged.DefaultOrg == "" {
merged.DefaultOrg = def.DefaultOrg
}
if merged.DefaultRepo == "" {
merged.DefaultRepo = def.DefaultRepo
}
return &merged
}
|
[
"func",
"(",
"g",
"*",
"GCSConfiguration",
")",
"ApplyDefault",
"(",
"def",
"*",
"GCSConfiguration",
")",
"*",
"GCSConfiguration",
"{",
"if",
"g",
"==",
"nil",
"&&",
"def",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"merged",
"GCSConfiguration",
"\n",
"if",
"g",
"!=",
"nil",
"{",
"merged",
"=",
"*",
"g",
"\n",
"}",
"else",
"{",
"merged",
"=",
"*",
"def",
"\n",
"}",
"\n",
"if",
"g",
"==",
"nil",
"||",
"def",
"==",
"nil",
"{",
"return",
"&",
"merged",
"\n",
"}",
"\n",
"if",
"merged",
".",
"Bucket",
"==",
"\"\"",
"{",
"merged",
".",
"Bucket",
"=",
"def",
".",
"Bucket",
"\n",
"}",
"\n",
"if",
"merged",
".",
"PathPrefix",
"==",
"\"\"",
"{",
"merged",
".",
"PathPrefix",
"=",
"def",
".",
"PathPrefix",
"\n",
"}",
"\n",
"if",
"merged",
".",
"PathStrategy",
"==",
"\"\"",
"{",
"merged",
".",
"PathStrategy",
"=",
"def",
".",
"PathStrategy",
"\n",
"}",
"\n",
"if",
"merged",
".",
"DefaultOrg",
"==",
"\"\"",
"{",
"merged",
".",
"DefaultOrg",
"=",
"def",
".",
"DefaultOrg",
"\n",
"}",
"\n",
"if",
"merged",
".",
"DefaultRepo",
"==",
"\"\"",
"{",
"merged",
".",
"DefaultRepo",
"=",
"def",
".",
"DefaultRepo",
"\n",
"}",
"\n",
"return",
"&",
"merged",
"\n",
"}"
] |
// ApplyDefault applies the defaults for GCSConfiguration decorations. If a field has a zero value,
// it replaces that with the value set in def.
|
[
"ApplyDefault",
"applies",
"the",
"defaults",
"for",
"GCSConfiguration",
"decorations",
".",
"If",
"a",
"field",
"has",
"a",
"zero",
"value",
"it",
"replaces",
"that",
"with",
"the",
"value",
"set",
"in",
"def",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/types.go#L375-L405
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/types.go
|
Validate
|
func (g *GCSConfiguration) Validate() error {
if g.PathStrategy != PathStrategyLegacy && g.PathStrategy != PathStrategyExplicit && g.PathStrategy != PathStrategySingle {
return fmt.Errorf("gcs_path_strategy must be one of %q, %q, or %q", PathStrategyLegacy, PathStrategyExplicit, PathStrategySingle)
}
if g.PathStrategy != PathStrategyExplicit && (g.DefaultOrg == "" || g.DefaultRepo == "") {
return fmt.Errorf("default org and repo must be provided for GCS strategy %q", g.PathStrategy)
}
return nil
}
|
go
|
func (g *GCSConfiguration) Validate() error {
if g.PathStrategy != PathStrategyLegacy && g.PathStrategy != PathStrategyExplicit && g.PathStrategy != PathStrategySingle {
return fmt.Errorf("gcs_path_strategy must be one of %q, %q, or %q", PathStrategyLegacy, PathStrategyExplicit, PathStrategySingle)
}
if g.PathStrategy != PathStrategyExplicit && (g.DefaultOrg == "" || g.DefaultRepo == "") {
return fmt.Errorf("default org and repo must be provided for GCS strategy %q", g.PathStrategy)
}
return nil
}
|
[
"func",
"(",
"g",
"*",
"GCSConfiguration",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"g",
".",
"PathStrategy",
"!=",
"PathStrategyLegacy",
"&&",
"g",
".",
"PathStrategy",
"!=",
"PathStrategyExplicit",
"&&",
"g",
".",
"PathStrategy",
"!=",
"PathStrategySingle",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"gcs_path_strategy must be one of %q, %q, or %q\"",
",",
"PathStrategyLegacy",
",",
"PathStrategyExplicit",
",",
"PathStrategySingle",
")",
"\n",
"}",
"\n",
"if",
"g",
".",
"PathStrategy",
"!=",
"PathStrategyExplicit",
"&&",
"(",
"g",
".",
"DefaultOrg",
"==",
"\"\"",
"||",
"g",
".",
"DefaultRepo",
"==",
"\"\"",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"default org and repo must be provided for GCS strategy %q\"",
",",
"g",
".",
"PathStrategy",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Validate ensures all the values set in the GCSConfiguration are valid.
|
[
"Validate",
"ensures",
"all",
"the",
"values",
"set",
"in",
"the",
"GCSConfiguration",
"are",
"valid",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/types.go#L408-L416
|
test
|
kubernetes/test-infra
|
prow/apis/prowjobs/v1/types.go
|
ClusterAlias
|
func (j *ProwJob) ClusterAlias() string {
if j.Spec.Cluster == "" {
return DefaultClusterAlias
}
return j.Spec.Cluster
}
|
go
|
func (j *ProwJob) ClusterAlias() string {
if j.Spec.Cluster == "" {
return DefaultClusterAlias
}
return j.Spec.Cluster
}
|
[
"func",
"(",
"j",
"*",
"ProwJob",
")",
"ClusterAlias",
"(",
")",
"string",
"{",
"if",
"j",
".",
"Spec",
".",
"Cluster",
"==",
"\"\"",
"{",
"return",
"DefaultClusterAlias",
"\n",
"}",
"\n",
"return",
"j",
".",
"Spec",
".",
"Cluster",
"\n",
"}"
] |
// ClusterAlias specifies the key in the clusters map to use.
//
// This allows scheduling a prow job somewhere aside from the default build cluster.
|
[
"ClusterAlias",
"specifies",
"the",
"key",
"in",
"the",
"clusters",
"map",
"to",
"use",
".",
"This",
"allows",
"scheduling",
"a",
"prow",
"job",
"somewhere",
"aside",
"from",
"the",
"default",
"build",
"cluster",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/apis/prowjobs/v1/types.go#L465-L470
|
test
|
kubernetes/test-infra
|
boskos/common/common.go
|
NewResource
|
func NewResource(name, rtype, state, owner string, t time.Time) Resource {
return Resource{
Name: name,
Type: rtype,
State: state,
Owner: owner,
LastUpdate: t,
UserData: &UserData{},
}
}
|
go
|
func NewResource(name, rtype, state, owner string, t time.Time) Resource {
return Resource{
Name: name,
Type: rtype,
State: state,
Owner: owner,
LastUpdate: t,
UserData: &UserData{},
}
}
|
[
"func",
"NewResource",
"(",
"name",
",",
"rtype",
",",
"state",
",",
"owner",
"string",
",",
"t",
"time",
".",
"Time",
")",
"Resource",
"{",
"return",
"Resource",
"{",
"Name",
":",
"name",
",",
"Type",
":",
"rtype",
",",
"State",
":",
"state",
",",
"Owner",
":",
"owner",
",",
"LastUpdate",
":",
"t",
",",
"UserData",
":",
"&",
"UserData",
"{",
"}",
",",
"}",
"\n",
"}"
] |
// NewResource creates a new Boskos Resource.
|
[
"NewResource",
"creates",
"a",
"new",
"Boskos",
"Resource",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/common/common.go#L93-L102
|
test
|
kubernetes/test-infra
|
boskos/common/common.go
|
NewResourcesFromConfig
|
func NewResourcesFromConfig(e ResourceEntry) []Resource {
var resources []Resource
for _, name := range e.Names {
resources = append(resources, NewResource(name, e.Type, e.State, "", time.Time{}))
}
return resources
}
|
go
|
func NewResourcesFromConfig(e ResourceEntry) []Resource {
var resources []Resource
for _, name := range e.Names {
resources = append(resources, NewResource(name, e.Type, e.State, "", time.Time{}))
}
return resources
}
|
[
"func",
"NewResourcesFromConfig",
"(",
"e",
"ResourceEntry",
")",
"[",
"]",
"Resource",
"{",
"var",
"resources",
"[",
"]",
"Resource",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"e",
".",
"Names",
"{",
"resources",
"=",
"append",
"(",
"resources",
",",
"NewResource",
"(",
"name",
",",
"e",
".",
"Type",
",",
"e",
".",
"State",
",",
"\"\"",
",",
"time",
".",
"Time",
"{",
"}",
")",
")",
"\n",
"}",
"\n",
"return",
"resources",
"\n",
"}"
] |
// NewResourcesFromConfig parse the a ResourceEntry into a list of resources
|
[
"NewResourcesFromConfig",
"parse",
"the",
"a",
"ResourceEntry",
"into",
"a",
"list",
"of",
"resources"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/common/common.go#L105-L111
|
test
|
kubernetes/test-infra
|
boskos/common/common.go
|
UserDataFromMap
|
func UserDataFromMap(m UserDataMap) *UserData {
ud := &UserData{}
for k, v := range m {
ud.Store(k, v)
}
return ud
}
|
go
|
func UserDataFromMap(m UserDataMap) *UserData {
ud := &UserData{}
for k, v := range m {
ud.Store(k, v)
}
return ud
}
|
[
"func",
"UserDataFromMap",
"(",
"m",
"UserDataMap",
")",
"*",
"UserData",
"{",
"ud",
":=",
"&",
"UserData",
"{",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"m",
"{",
"ud",
".",
"Store",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n",
"return",
"ud",
"\n",
"}"
] |
// UserDataFromMap returns a UserData from a map
|
[
"UserDataFromMap",
"returns",
"a",
"UserData",
"from",
"a",
"map"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/common/common.go#L114-L120
|
test
|
kubernetes/test-infra
|
boskos/common/common.go
|
Set
|
func (r *CommaSeparatedStrings) Set(value string) error {
if len(*r) > 0 {
return errors.New("resTypes flag already set")
}
for _, rtype := range strings.Split(value, ",") {
*r = append(*r, rtype)
}
return nil
}
|
go
|
func (r *CommaSeparatedStrings) Set(value string) error {
if len(*r) > 0 {
return errors.New("resTypes flag already set")
}
for _, rtype := range strings.Split(value, ",") {
*r = append(*r, rtype)
}
return nil
}
|
[
"func",
"(",
"r",
"*",
"CommaSeparatedStrings",
")",
"Set",
"(",
"value",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"*",
"r",
")",
">",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"resTypes flag already set\"",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"rtype",
":=",
"range",
"strings",
".",
"Split",
"(",
"value",
",",
"\",\"",
")",
"{",
"*",
"r",
"=",
"append",
"(",
"*",
"r",
",",
"rtype",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Set parses the flag value into a CommaSeparatedStrings
|
[
"Set",
"parses",
"the",
"flag",
"value",
"into",
"a",
"CommaSeparatedStrings"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/common/common.go#L153-L161
|
test
|
kubernetes/test-infra
|
boskos/common/common.go
|
UnmarshalJSON
|
func (ud *UserData) UnmarshalJSON(data []byte) error {
tmpMap := UserDataMap{}
if err := json.Unmarshal(data, &tmpMap); err != nil {
return err
}
ud.FromMap(tmpMap)
return nil
}
|
go
|
func (ud *UserData) UnmarshalJSON(data []byte) error {
tmpMap := UserDataMap{}
if err := json.Unmarshal(data, &tmpMap); err != nil {
return err
}
ud.FromMap(tmpMap)
return nil
}
|
[
"func",
"(",
"ud",
"*",
"UserData",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"tmpMap",
":=",
"UserDataMap",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"tmpMap",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ud",
".",
"FromMap",
"(",
"tmpMap",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UnmarshalJSON implements JSON Unmarshaler interface
|
[
"UnmarshalJSON",
"implements",
"JSON",
"Unmarshaler",
"interface"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/common/common.go#L171-L178
|
test
|
kubernetes/test-infra
|
boskos/common/common.go
|
Extract
|
func (ud *UserData) Extract(id string, out interface{}) error {
content, ok := ud.Load(id)
if !ok {
return &UserDataNotFound{id}
}
return yaml.Unmarshal([]byte(content.(string)), out)
}
|
go
|
func (ud *UserData) Extract(id string, out interface{}) error {
content, ok := ud.Load(id)
if !ok {
return &UserDataNotFound{id}
}
return yaml.Unmarshal([]byte(content.(string)), out)
}
|
[
"func",
"(",
"ud",
"*",
"UserData",
")",
"Extract",
"(",
"id",
"string",
",",
"out",
"interface",
"{",
"}",
")",
"error",
"{",
"content",
",",
"ok",
":=",
"ud",
".",
"Load",
"(",
"id",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"&",
"UserDataNotFound",
"{",
"id",
"}",
"\n",
"}",
"\n",
"return",
"yaml",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"content",
".",
"(",
"string",
")",
")",
",",
"out",
")",
"\n",
"}"
] |
// Extract unmarshalls a string a given struct if it exists
|
[
"Extract",
"unmarshalls",
"a",
"string",
"a",
"given",
"struct",
"if",
"it",
"exists"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/common/common.go#L186-L192
|
test
|
kubernetes/test-infra
|
boskos/common/common.go
|
Set
|
func (ud *UserData) Set(id string, in interface{}) error {
b, err := yaml.Marshal(in)
if err != nil {
return err
}
ud.Store(id, string(b))
return nil
}
|
go
|
func (ud *UserData) Set(id string, in interface{}) error {
b, err := yaml.Marshal(in)
if err != nil {
return err
}
ud.Store(id, string(b))
return nil
}
|
[
"func",
"(",
"ud",
"*",
"UserData",
")",
"Set",
"(",
"id",
"string",
",",
"in",
"interface",
"{",
"}",
")",
"error",
"{",
"b",
",",
"err",
":=",
"yaml",
".",
"Marshal",
"(",
"in",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ud",
".",
"Store",
"(",
"id",
",",
"string",
"(",
"b",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// User Data are used to store custom information mainly by Mason and Masonable implementation.
// Mason used a LeasedResource keys to store information about other resources that used to
// create the given resource.
// Set marshalls a struct to a string into the UserData
|
[
"User",
"Data",
"are",
"used",
"to",
"store",
"custom",
"information",
"mainly",
"by",
"Mason",
"and",
"Masonable",
"implementation",
".",
"Mason",
"used",
"a",
"LeasedResource",
"keys",
"to",
"store",
"information",
"about",
"other",
"resources",
"that",
"used",
"to",
"create",
"the",
"given",
"resource",
".",
"Set",
"marshalls",
"a",
"struct",
"to",
"a",
"string",
"into",
"the",
"UserData"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/common/common.go#L199-L206
|
test
|
kubernetes/test-infra
|
boskos/common/common.go
|
Update
|
func (ud *UserData) Update(new *UserData) {
if new == nil {
return
}
new.Range(func(key, value interface{}) bool {
if value.(string) != "" {
ud.Store(key, value)
} else {
ud.Delete(key)
}
return true
})
}
|
go
|
func (ud *UserData) Update(new *UserData) {
if new == nil {
return
}
new.Range(func(key, value interface{}) bool {
if value.(string) != "" {
ud.Store(key, value)
} else {
ud.Delete(key)
}
return true
})
}
|
[
"func",
"(",
"ud",
"*",
"UserData",
")",
"Update",
"(",
"new",
"*",
"UserData",
")",
"{",
"if",
"new",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"new",
".",
"Range",
"(",
"func",
"(",
"key",
",",
"value",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"value",
".",
"(",
"string",
")",
"!=",
"\"\"",
"{",
"ud",
".",
"Store",
"(",
"key",
",",
"value",
")",
"\n",
"}",
"else",
"{",
"ud",
".",
"Delete",
"(",
"key",
")",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}",
")",
"\n",
"}"
] |
// Update updates existing UserData with new UserData.
// If a key as an empty string, the key will be deleted
|
[
"Update",
"updates",
"existing",
"UserData",
"with",
"new",
"UserData",
".",
"If",
"a",
"key",
"as",
"an",
"empty",
"string",
"the",
"key",
"will",
"be",
"deleted"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/common/common.go#L210-L222
|
test
|
kubernetes/test-infra
|
boskos/common/common.go
|
ToMap
|
func (ud *UserData) ToMap() UserDataMap {
m := UserDataMap{}
ud.Range(func(key, value interface{}) bool {
m[key.(string)] = value.(string)
return true
})
return m
}
|
go
|
func (ud *UserData) ToMap() UserDataMap {
m := UserDataMap{}
ud.Range(func(key, value interface{}) bool {
m[key.(string)] = value.(string)
return true
})
return m
}
|
[
"func",
"(",
"ud",
"*",
"UserData",
")",
"ToMap",
"(",
")",
"UserDataMap",
"{",
"m",
":=",
"UserDataMap",
"{",
"}",
"\n",
"ud",
".",
"Range",
"(",
"func",
"(",
"key",
",",
"value",
"interface",
"{",
"}",
")",
"bool",
"{",
"m",
"[",
"key",
".",
"(",
"string",
")",
"]",
"=",
"value",
".",
"(",
"string",
")",
"\n",
"return",
"true",
"\n",
"}",
")",
"\n",
"return",
"m",
"\n",
"}"
] |
// ToMap converts a UserData to UserDataMap
|
[
"ToMap",
"converts",
"a",
"UserData",
"to",
"UserDataMap"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/common/common.go#L225-L232
|
test
|
kubernetes/test-infra
|
boskos/common/common.go
|
FromMap
|
func (ud *UserData) FromMap(m UserDataMap) {
for key, value := range m {
ud.Store(key, value)
}
}
|
go
|
func (ud *UserData) FromMap(m UserDataMap) {
for key, value := range m {
ud.Store(key, value)
}
}
|
[
"func",
"(",
"ud",
"*",
"UserData",
")",
"FromMap",
"(",
"m",
"UserDataMap",
")",
"{",
"for",
"key",
",",
"value",
":=",
"range",
"m",
"{",
"ud",
".",
"Store",
"(",
"key",
",",
"value",
")",
"\n",
"}",
"\n",
"}"
] |
// FromMap feels updates user data from a map
|
[
"FromMap",
"feels",
"updates",
"user",
"data",
"from",
"a",
"map"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/common/common.go#L235-L239
|
test
|
kubernetes/test-infra
|
boskos/common/common.go
|
ItemToResource
|
func ItemToResource(i Item) (Resource, error) {
res, ok := i.(Resource)
if !ok {
return Resource{}, fmt.Errorf("cannot construct Resource from received object %v", i)
}
return res, nil
}
|
go
|
func ItemToResource(i Item) (Resource, error) {
res, ok := i.(Resource)
if !ok {
return Resource{}, fmt.Errorf("cannot construct Resource from received object %v", i)
}
return res, nil
}
|
[
"func",
"ItemToResource",
"(",
"i",
"Item",
")",
"(",
"Resource",
",",
"error",
")",
"{",
"res",
",",
"ok",
":=",
"i",
".",
"(",
"Resource",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"Resource",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"cannot construct Resource from received object %v\"",
",",
"i",
")",
"\n",
"}",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// ItemToResource casts a Item back to a Resource
|
[
"ItemToResource",
"casts",
"a",
"Item",
"back",
"to",
"a",
"Resource"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/boskos/common/common.go#L242-L248
|
test
|
kubernetes/test-infra
|
prow/clonerefs/run.go
|
Run
|
func (o Options) Run() error {
var env []string
if len(o.KeyFiles) > 0 {
var err error
env, err = addSSHKeys(o.KeyFiles)
if err != nil {
logrus.WithError(err).Error("Failed to add SSH keys.")
// Continue on error. Clones will fail with an appropriate error message
// that initupload can consume whereas quitting without writing the clone
// record log is silent and results in an errored prow job instead of a
// failed one.
}
}
if len(o.HostFingerprints) > 0 {
if err := addHostFingerprints(o.HostFingerprints); err != nil {
logrus.WithError(err).Error("failed to add host fingerprints")
}
}
var numWorkers int
if o.MaxParallelWorkers != 0 {
numWorkers = o.MaxParallelWorkers
} else {
numWorkers = len(o.GitRefs)
}
wg := &sync.WaitGroup{}
wg.Add(numWorkers)
input := make(chan prowapi.Refs)
output := make(chan clone.Record, len(o.GitRefs))
for i := 0; i < numWorkers; i++ {
go func() {
defer wg.Done()
for ref := range input {
output <- cloneFunc(ref, o.SrcRoot, o.GitUserName, o.GitUserEmail, o.CookiePath, env)
}
}()
}
for _, ref := range o.GitRefs {
input <- ref
}
close(input)
wg.Wait()
close(output)
var results []clone.Record
for record := range output {
results = append(results, record)
}
logData, err := json.Marshal(results)
if err != nil {
return fmt.Errorf("failed to marshal clone records: %v", err)
}
if err := ioutil.WriteFile(o.Log, logData, 0755); err != nil {
return fmt.Errorf("failed to write clone records: %v", err)
}
return nil
}
|
go
|
func (o Options) Run() error {
var env []string
if len(o.KeyFiles) > 0 {
var err error
env, err = addSSHKeys(o.KeyFiles)
if err != nil {
logrus.WithError(err).Error("Failed to add SSH keys.")
// Continue on error. Clones will fail with an appropriate error message
// that initupload can consume whereas quitting without writing the clone
// record log is silent and results in an errored prow job instead of a
// failed one.
}
}
if len(o.HostFingerprints) > 0 {
if err := addHostFingerprints(o.HostFingerprints); err != nil {
logrus.WithError(err).Error("failed to add host fingerprints")
}
}
var numWorkers int
if o.MaxParallelWorkers != 0 {
numWorkers = o.MaxParallelWorkers
} else {
numWorkers = len(o.GitRefs)
}
wg := &sync.WaitGroup{}
wg.Add(numWorkers)
input := make(chan prowapi.Refs)
output := make(chan clone.Record, len(o.GitRefs))
for i := 0; i < numWorkers; i++ {
go func() {
defer wg.Done()
for ref := range input {
output <- cloneFunc(ref, o.SrcRoot, o.GitUserName, o.GitUserEmail, o.CookiePath, env)
}
}()
}
for _, ref := range o.GitRefs {
input <- ref
}
close(input)
wg.Wait()
close(output)
var results []clone.Record
for record := range output {
results = append(results, record)
}
logData, err := json.Marshal(results)
if err != nil {
return fmt.Errorf("failed to marshal clone records: %v", err)
}
if err := ioutil.WriteFile(o.Log, logData, 0755); err != nil {
return fmt.Errorf("failed to write clone records: %v", err)
}
return nil
}
|
[
"func",
"(",
"o",
"Options",
")",
"Run",
"(",
")",
"error",
"{",
"var",
"env",
"[",
"]",
"string",
"\n",
"if",
"len",
"(",
"o",
".",
"KeyFiles",
")",
">",
"0",
"{",
"var",
"err",
"error",
"\n",
"env",
",",
"err",
"=",
"addSSHKeys",
"(",
"o",
".",
"KeyFiles",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"Failed to add SSH keys.\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"o",
".",
"HostFingerprints",
")",
">",
"0",
"{",
"if",
"err",
":=",
"addHostFingerprints",
"(",
"o",
".",
"HostFingerprints",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"failed to add host fingerprints\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"var",
"numWorkers",
"int",
"\n",
"if",
"o",
".",
"MaxParallelWorkers",
"!=",
"0",
"{",
"numWorkers",
"=",
"o",
".",
"MaxParallelWorkers",
"\n",
"}",
"else",
"{",
"numWorkers",
"=",
"len",
"(",
"o",
".",
"GitRefs",
")",
"\n",
"}",
"\n",
"wg",
":=",
"&",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"wg",
".",
"Add",
"(",
"numWorkers",
")",
"\n",
"input",
":=",
"make",
"(",
"chan",
"prowapi",
".",
"Refs",
")",
"\n",
"output",
":=",
"make",
"(",
"chan",
"clone",
".",
"Record",
",",
"len",
"(",
"o",
".",
"GitRefs",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"numWorkers",
";",
"i",
"++",
"{",
"go",
"func",
"(",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"for",
"ref",
":=",
"range",
"input",
"{",
"output",
"<-",
"cloneFunc",
"(",
"ref",
",",
"o",
".",
"SrcRoot",
",",
"o",
".",
"GitUserName",
",",
"o",
".",
"GitUserEmail",
",",
"o",
".",
"CookiePath",
",",
"env",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"ref",
":=",
"range",
"o",
".",
"GitRefs",
"{",
"input",
"<-",
"ref",
"\n",
"}",
"\n",
"close",
"(",
"input",
")",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"close",
"(",
"output",
")",
"\n",
"var",
"results",
"[",
"]",
"clone",
".",
"Record",
"\n",
"for",
"record",
":=",
"range",
"output",
"{",
"results",
"=",
"append",
"(",
"results",
",",
"record",
")",
"\n",
"}",
"\n",
"logData",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to marshal clone records: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"o",
".",
"Log",
",",
"logData",
",",
"0755",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to write clone records: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Run clones the configured refs
|
[
"Run",
"clones",
"the",
"configured",
"refs"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/clonerefs/run.go#L37-L100
|
test
|
kubernetes/test-infra
|
prow/clonerefs/run.go
|
addSSHKeys
|
func addSSHKeys(paths []string) ([]string, error) {
vars, err := exec.Command("ssh-agent").CombinedOutput()
if err != nil {
return []string{}, fmt.Errorf("failed to start ssh-agent: %v", err)
}
logrus.Info("Started SSH agent")
// ssh-agent will output three lines of text, in the form:
// SSH_AUTH_SOCK=xxx; export SSH_AUTH_SOCK;
// SSH_AGENT_PID=xxx; export SSH_AGENT_PID;
// echo Agent pid xxx;
// We need to parse out the environment variables from that.
parts := strings.Split(string(vars), ";")
env := []string{strings.TrimSpace(parts[0]), strings.TrimSpace(parts[2])}
for _, keyPath := range paths {
// we can be given literal paths to keys or paths to dirs
// that are mounted from a secret, so we need to check which
// we have
if err := filepath.Walk(keyPath, func(path string, info os.FileInfo, err error) error {
if strings.HasPrefix(info.Name(), "..") {
// kubernetes volumes also include files we
// should not look be looking into for keys
if info.IsDir() {
return filepath.SkipDir
}
return nil
}
if info.IsDir() {
return nil
}
cmd := exec.Command("ssh-add", path)
cmd.Env = append(cmd.Env, env...)
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("failed to add ssh key at %s: %v: %s", path, err, output)
}
logrus.Infof("Added SSH key at %s", path)
return nil
}); err != nil {
return env, fmt.Errorf("error walking path %q: %v", keyPath, err)
}
}
return env, nil
}
|
go
|
func addSSHKeys(paths []string) ([]string, error) {
vars, err := exec.Command("ssh-agent").CombinedOutput()
if err != nil {
return []string{}, fmt.Errorf("failed to start ssh-agent: %v", err)
}
logrus.Info("Started SSH agent")
// ssh-agent will output three lines of text, in the form:
// SSH_AUTH_SOCK=xxx; export SSH_AUTH_SOCK;
// SSH_AGENT_PID=xxx; export SSH_AGENT_PID;
// echo Agent pid xxx;
// We need to parse out the environment variables from that.
parts := strings.Split(string(vars), ";")
env := []string{strings.TrimSpace(parts[0]), strings.TrimSpace(parts[2])}
for _, keyPath := range paths {
// we can be given literal paths to keys or paths to dirs
// that are mounted from a secret, so we need to check which
// we have
if err := filepath.Walk(keyPath, func(path string, info os.FileInfo, err error) error {
if strings.HasPrefix(info.Name(), "..") {
// kubernetes volumes also include files we
// should not look be looking into for keys
if info.IsDir() {
return filepath.SkipDir
}
return nil
}
if info.IsDir() {
return nil
}
cmd := exec.Command("ssh-add", path)
cmd.Env = append(cmd.Env, env...)
if output, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("failed to add ssh key at %s: %v: %s", path, err, output)
}
logrus.Infof("Added SSH key at %s", path)
return nil
}); err != nil {
return env, fmt.Errorf("error walking path %q: %v", keyPath, err)
}
}
return env, nil
}
|
[
"func",
"addSSHKeys",
"(",
"paths",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"vars",
",",
"err",
":=",
"exec",
".",
"Command",
"(",
"\"ssh-agent\"",
")",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"[",
"]",
"string",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"failed to start ssh-agent: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"logrus",
".",
"Info",
"(",
"\"Started SSH agent\"",
")",
"\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"string",
"(",
"vars",
")",
",",
"\";\"",
")",
"\n",
"env",
":=",
"[",
"]",
"string",
"{",
"strings",
".",
"TrimSpace",
"(",
"parts",
"[",
"0",
"]",
")",
",",
"strings",
".",
"TrimSpace",
"(",
"parts",
"[",
"2",
"]",
")",
"}",
"\n",
"for",
"_",
",",
"keyPath",
":=",
"range",
"paths",
"{",
"if",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"keyPath",
",",
"func",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"info",
".",
"Name",
"(",
")",
",",
"\"..\"",
")",
"{",
"if",
"info",
".",
"IsDir",
"(",
")",
"{",
"return",
"filepath",
".",
"SkipDir",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"info",
".",
"IsDir",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"ssh-add\"",
",",
"path",
")",
"\n",
"cmd",
".",
"Env",
"=",
"append",
"(",
"cmd",
".",
"Env",
",",
"env",
"...",
")",
"\n",
"if",
"output",
",",
"err",
":=",
"cmd",
".",
"CombinedOutput",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"failed to add ssh key at %s: %v: %s\"",
",",
"path",
",",
"err",
",",
"output",
")",
"\n",
"}",
"\n",
"logrus",
".",
"Infof",
"(",
"\"Added SSH key at %s\"",
",",
"path",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"env",
",",
"fmt",
".",
"Errorf",
"(",
"\"error walking path %q: %v\"",
",",
"keyPath",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"env",
",",
"nil",
"\n",
"}"
] |
// addSSHKeys will start the ssh-agent and add all the specified
// keys, returning the ssh-agent environment variables for reuse
|
[
"addSSHKeys",
"will",
"start",
"the",
"ssh",
"-",
"agent",
"and",
"add",
"all",
"the",
"specified",
"keys",
"returning",
"the",
"ssh",
"-",
"agent",
"environment",
"variables",
"for",
"reuse"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/clonerefs/run.go#L119-L161
|
test
|
kubernetes/test-infra
|
robots/issue-creator/sources/triage-filer.go
|
Issues
|
func (f *TriageFiler) Issues(c *creator.IssueCreator) ([]creator.Issue, error) {
f.creator = c
rawjson, err := ReadHTTP(clusterDataURL)
if err != nil {
return nil, err
}
clusters, err := f.loadClusters(rawjson)
if err != nil {
return nil, err
}
topclusters := topClusters(clusters, f.topClustersCount)
issues := make([]creator.Issue, 0, len(topclusters))
for _, clust := range topclusters {
issues = append(issues, clust)
}
return issues, nil
}
|
go
|
func (f *TriageFiler) Issues(c *creator.IssueCreator) ([]creator.Issue, error) {
f.creator = c
rawjson, err := ReadHTTP(clusterDataURL)
if err != nil {
return nil, err
}
clusters, err := f.loadClusters(rawjson)
if err != nil {
return nil, err
}
topclusters := topClusters(clusters, f.topClustersCount)
issues := make([]creator.Issue, 0, len(topclusters))
for _, clust := range topclusters {
issues = append(issues, clust)
}
return issues, nil
}
|
[
"func",
"(",
"f",
"*",
"TriageFiler",
")",
"Issues",
"(",
"c",
"*",
"creator",
".",
"IssueCreator",
")",
"(",
"[",
"]",
"creator",
".",
"Issue",
",",
"error",
")",
"{",
"f",
".",
"creator",
"=",
"c",
"\n",
"rawjson",
",",
"err",
":=",
"ReadHTTP",
"(",
"clusterDataURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"clusters",
",",
"err",
":=",
"f",
".",
"loadClusters",
"(",
"rawjson",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"topclusters",
":=",
"topClusters",
"(",
"clusters",
",",
"f",
".",
"topClustersCount",
")",
"\n",
"issues",
":=",
"make",
"(",
"[",
"]",
"creator",
".",
"Issue",
",",
"0",
",",
"len",
"(",
"topclusters",
")",
")",
"\n",
"for",
"_",
",",
"clust",
":=",
"range",
"topclusters",
"{",
"issues",
"=",
"append",
"(",
"issues",
",",
"clust",
")",
"\n",
"}",
"\n",
"return",
"issues",
",",
"nil",
"\n",
"}"
] |
// Issues is the main work function of the TriageFiler. It fetches and parses cluster data,
// then syncs the top issues to github with the IssueCreator.
|
[
"Issues",
"is",
"the",
"main",
"work",
"function",
"of",
"the",
"TriageFiler",
".",
"It",
"fetches",
"and",
"parses",
"cluster",
"data",
"then",
"syncs",
"the",
"top",
"issues",
"to",
"github",
"with",
"the",
"IssueCreator",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/robots/issue-creator/sources/triage-filer.go#L62-L78
|
test
|
kubernetes/test-infra
|
robots/issue-creator/sources/triage-filer.go
|
loadClusters
|
func (f *TriageFiler) loadClusters(jsonIn []byte) ([]*Cluster, error) {
var err error
f.data, err = parseTriageData(jsonIn)
if err != nil {
return nil, err
}
if err = f.filterAndValidate(f.windowDays); err != nil {
return nil, err
}
// Aggregate failing builds in each cluster by job (independent of tests).
for _, clust := range f.data.Clustered {
clust.filer = f
clust.jobs = make(map[string][]int)
for _, test := range clust.Tests {
for _, job := range test.Jobs {
for _, buildnum := range job.Builds {
found := false
for _, oldBuild := range clust.jobs[job.Name] {
if oldBuild == buildnum {
found = true
break
}
}
if !found {
clust.jobs[job.Name] = append(clust.jobs[job.Name], buildnum)
}
}
}
}
clust.totalJobs = len(clust.jobs)
clust.totalTests = len(clust.Tests)
clust.totalBuilds = 0
for _, builds := range clust.jobs {
clust.totalBuilds += len(builds)
}
}
return f.data.Clustered, nil
}
|
go
|
func (f *TriageFiler) loadClusters(jsonIn []byte) ([]*Cluster, error) {
var err error
f.data, err = parseTriageData(jsonIn)
if err != nil {
return nil, err
}
if err = f.filterAndValidate(f.windowDays); err != nil {
return nil, err
}
// Aggregate failing builds in each cluster by job (independent of tests).
for _, clust := range f.data.Clustered {
clust.filer = f
clust.jobs = make(map[string][]int)
for _, test := range clust.Tests {
for _, job := range test.Jobs {
for _, buildnum := range job.Builds {
found := false
for _, oldBuild := range clust.jobs[job.Name] {
if oldBuild == buildnum {
found = true
break
}
}
if !found {
clust.jobs[job.Name] = append(clust.jobs[job.Name], buildnum)
}
}
}
}
clust.totalJobs = len(clust.jobs)
clust.totalTests = len(clust.Tests)
clust.totalBuilds = 0
for _, builds := range clust.jobs {
clust.totalBuilds += len(builds)
}
}
return f.data.Clustered, nil
}
|
[
"func",
"(",
"f",
"*",
"TriageFiler",
")",
"loadClusters",
"(",
"jsonIn",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"*",
"Cluster",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"f",
".",
"data",
",",
"err",
"=",
"parseTriageData",
"(",
"jsonIn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
"=",
"f",
".",
"filterAndValidate",
"(",
"f",
".",
"windowDays",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"clust",
":=",
"range",
"f",
".",
"data",
".",
"Clustered",
"{",
"clust",
".",
"filer",
"=",
"f",
"\n",
"clust",
".",
"jobs",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"int",
")",
"\n",
"for",
"_",
",",
"test",
":=",
"range",
"clust",
".",
"Tests",
"{",
"for",
"_",
",",
"job",
":=",
"range",
"test",
".",
"Jobs",
"{",
"for",
"_",
",",
"buildnum",
":=",
"range",
"job",
".",
"Builds",
"{",
"found",
":=",
"false",
"\n",
"for",
"_",
",",
"oldBuild",
":=",
"range",
"clust",
".",
"jobs",
"[",
"job",
".",
"Name",
"]",
"{",
"if",
"oldBuild",
"==",
"buildnum",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"clust",
".",
"jobs",
"[",
"job",
".",
"Name",
"]",
"=",
"append",
"(",
"clust",
".",
"jobs",
"[",
"job",
".",
"Name",
"]",
",",
"buildnum",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"clust",
".",
"totalJobs",
"=",
"len",
"(",
"clust",
".",
"jobs",
")",
"\n",
"clust",
".",
"totalTests",
"=",
"len",
"(",
"clust",
".",
"Tests",
")",
"\n",
"clust",
".",
"totalBuilds",
"=",
"0",
"\n",
"for",
"_",
",",
"builds",
":=",
"range",
"clust",
".",
"jobs",
"{",
"clust",
".",
"totalBuilds",
"+=",
"len",
"(",
"builds",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"f",
".",
"data",
".",
"Clustered",
",",
"nil",
"\n",
"}"
] |
// loadClusters parses and filters the json data, then populates every Cluster struct with
// aggregated job data and totals. The job data specifies all jobs that failed in a cluster and the
// builds that failed for each job, independent of which tests the jobs or builds failed.
|
[
"loadClusters",
"parses",
"and",
"filters",
"the",
"json",
"data",
"then",
"populates",
"every",
"Cluster",
"struct",
"with",
"aggregated",
"job",
"data",
"and",
"totals",
".",
"The",
"job",
"data",
"specifies",
"all",
"jobs",
"that",
"failed",
"in",
"a",
"cluster",
"and",
"the",
"builds",
"that",
"failed",
"for",
"each",
"job",
"independent",
"of",
"which",
"tests",
"the",
"jobs",
"or",
"builds",
"failed",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/robots/issue-creator/sources/triage-filer.go#L242-L281
|
test
|
kubernetes/test-infra
|
robots/issue-creator/sources/triage-filer.go
|
parseTriageData
|
func parseTriageData(jsonIn []byte) (*triageData, error) {
var data triageData
if err := json.Unmarshal(jsonIn, &data); err != nil {
return nil, err
}
if data.Builds.Cols.Started == nil {
return nil, fmt.Errorf("triage data json is missing the builds.cols.started key")
}
if data.Builds.JobsRaw == nil {
return nil, fmt.Errorf("triage data is missing the builds.jobs key")
}
if data.Builds.JobPaths == nil {
return nil, fmt.Errorf("triage data is missing the builds.job_paths key")
}
if data.Clustered == nil {
return nil, fmt.Errorf("triage data is missing the clustered key")
}
// Populate 'Jobs' with the BuildIndexer for each job.
data.Builds.Jobs = make(map[string]BuildIndexer)
for jobID, mapper := range data.Builds.JobsRaw {
switch mapper := mapper.(type) {
case []interface{}:
// In this case mapper is a 3 member array. 0:first buildnum, 1:number of builds, 2:start index.
data.Builds.Jobs[jobID] = ContigIndexer{
startBuild: int(mapper[0].(float64)),
count: int(mapper[1].(float64)),
startRow: int(mapper[2].(float64)),
}
case map[string]interface{}:
// In this case mapper is a dictionary.
data.Builds.Jobs[jobID] = DictIndexer(mapper)
default:
return nil, fmt.Errorf("the build number to row index mapping for job '%s' is not an accepted type. Type is: %v", jobID, reflect.TypeOf(mapper))
}
}
return &data, nil
}
|
go
|
func parseTriageData(jsonIn []byte) (*triageData, error) {
var data triageData
if err := json.Unmarshal(jsonIn, &data); err != nil {
return nil, err
}
if data.Builds.Cols.Started == nil {
return nil, fmt.Errorf("triage data json is missing the builds.cols.started key")
}
if data.Builds.JobsRaw == nil {
return nil, fmt.Errorf("triage data is missing the builds.jobs key")
}
if data.Builds.JobPaths == nil {
return nil, fmt.Errorf("triage data is missing the builds.job_paths key")
}
if data.Clustered == nil {
return nil, fmt.Errorf("triage data is missing the clustered key")
}
// Populate 'Jobs' with the BuildIndexer for each job.
data.Builds.Jobs = make(map[string]BuildIndexer)
for jobID, mapper := range data.Builds.JobsRaw {
switch mapper := mapper.(type) {
case []interface{}:
// In this case mapper is a 3 member array. 0:first buildnum, 1:number of builds, 2:start index.
data.Builds.Jobs[jobID] = ContigIndexer{
startBuild: int(mapper[0].(float64)),
count: int(mapper[1].(float64)),
startRow: int(mapper[2].(float64)),
}
case map[string]interface{}:
// In this case mapper is a dictionary.
data.Builds.Jobs[jobID] = DictIndexer(mapper)
default:
return nil, fmt.Errorf("the build number to row index mapping for job '%s' is not an accepted type. Type is: %v", jobID, reflect.TypeOf(mapper))
}
}
return &data, nil
}
|
[
"func",
"parseTriageData",
"(",
"jsonIn",
"[",
"]",
"byte",
")",
"(",
"*",
"triageData",
",",
"error",
")",
"{",
"var",
"data",
"triageData",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"jsonIn",
",",
"&",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"data",
".",
"Builds",
".",
"Cols",
".",
"Started",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"triage data json is missing the builds.cols.started key\"",
")",
"\n",
"}",
"\n",
"if",
"data",
".",
"Builds",
".",
"JobsRaw",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"triage data is missing the builds.jobs key\"",
")",
"\n",
"}",
"\n",
"if",
"data",
".",
"Builds",
".",
"JobPaths",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"triage data is missing the builds.job_paths key\"",
")",
"\n",
"}",
"\n",
"if",
"data",
".",
"Clustered",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"triage data is missing the clustered key\"",
")",
"\n",
"}",
"\n",
"data",
".",
"Builds",
".",
"Jobs",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"BuildIndexer",
")",
"\n",
"for",
"jobID",
",",
"mapper",
":=",
"range",
"data",
".",
"Builds",
".",
"JobsRaw",
"{",
"switch",
"mapper",
":=",
"mapper",
".",
"(",
"type",
")",
"{",
"case",
"[",
"]",
"interface",
"{",
"}",
":",
"data",
".",
"Builds",
".",
"Jobs",
"[",
"jobID",
"]",
"=",
"ContigIndexer",
"{",
"startBuild",
":",
"int",
"(",
"mapper",
"[",
"0",
"]",
".",
"(",
"float64",
")",
")",
",",
"count",
":",
"int",
"(",
"mapper",
"[",
"1",
"]",
".",
"(",
"float64",
")",
")",
",",
"startRow",
":",
"int",
"(",
"mapper",
"[",
"2",
"]",
".",
"(",
"float64",
")",
")",
",",
"}",
"\n",
"case",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
":",
"data",
".",
"Builds",
".",
"Jobs",
"[",
"jobID",
"]",
"=",
"DictIndexer",
"(",
"mapper",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"the build number to row index mapping for job '%s' is not an accepted type. Type is: %v\"",
",",
"jobID",
",",
"reflect",
".",
"TypeOf",
"(",
"mapper",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"data",
",",
"nil",
"\n",
"}"
] |
// parseTriageData unmarshals raw json data into a triageData struct and creates a BuildIndexer for
// every job.
|
[
"parseTriageData",
"unmarshals",
"raw",
"json",
"data",
"into",
"a",
"triageData",
"struct",
"and",
"creates",
"a",
"BuildIndexer",
"for",
"every",
"job",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/robots/issue-creator/sources/triage-filer.go#L285-L322
|
test
|
kubernetes/test-infra
|
robots/issue-creator/sources/triage-filer.go
|
topClusters
|
func topClusters(clusters []*Cluster, count int) []*Cluster {
less := func(i, j int) bool { return clusters[i].totalBuilds > clusters[j].totalBuilds }
sort.SliceStable(clusters, less)
if len(clusters) < count {
count = len(clusters)
}
return clusters[0:count]
}
|
go
|
func topClusters(clusters []*Cluster, count int) []*Cluster {
less := func(i, j int) bool { return clusters[i].totalBuilds > clusters[j].totalBuilds }
sort.SliceStable(clusters, less)
if len(clusters) < count {
count = len(clusters)
}
return clusters[0:count]
}
|
[
"func",
"topClusters",
"(",
"clusters",
"[",
"]",
"*",
"Cluster",
",",
"count",
"int",
")",
"[",
"]",
"*",
"Cluster",
"{",
"less",
":=",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"clusters",
"[",
"i",
"]",
".",
"totalBuilds",
">",
"clusters",
"[",
"j",
"]",
".",
"totalBuilds",
"}",
"\n",
"sort",
".",
"SliceStable",
"(",
"clusters",
",",
"less",
")",
"\n",
"if",
"len",
"(",
"clusters",
")",
"<",
"count",
"{",
"count",
"=",
"len",
"(",
"clusters",
")",
"\n",
"}",
"\n",
"return",
"clusters",
"[",
"0",
":",
"count",
"]",
"\n",
"}"
] |
// topClusters gets the 'count' most important clusters from a slice of clusters based on number of build failures.
|
[
"topClusters",
"gets",
"the",
"count",
"most",
"important",
"clusters",
"from",
"a",
"slice",
"of",
"clusters",
"based",
"on",
"number",
"of",
"build",
"failures",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/robots/issue-creator/sources/triage-filer.go#L325-L333
|
test
|
kubernetes/test-infra
|
robots/issue-creator/sources/triage-filer.go
|
topJobsFailed
|
func (c *Cluster) topJobsFailed(count int) []*Job {
slice := make([]*Job, len(c.jobs))
i := 0
for jobName, builds := range c.jobs {
slice[i] = &Job{Name: jobName, Builds: builds}
i++
}
less := func(i, j int) bool { return len(slice[i].Builds) > len(slice[j].Builds) }
sort.SliceStable(slice, less)
if len(slice) < count {
count = len(slice)
}
return slice[0:count]
}
|
go
|
func (c *Cluster) topJobsFailed(count int) []*Job {
slice := make([]*Job, len(c.jobs))
i := 0
for jobName, builds := range c.jobs {
slice[i] = &Job{Name: jobName, Builds: builds}
i++
}
less := func(i, j int) bool { return len(slice[i].Builds) > len(slice[j].Builds) }
sort.SliceStable(slice, less)
if len(slice) < count {
count = len(slice)
}
return slice[0:count]
}
|
[
"func",
"(",
"c",
"*",
"Cluster",
")",
"topJobsFailed",
"(",
"count",
"int",
")",
"[",
"]",
"*",
"Job",
"{",
"slice",
":=",
"make",
"(",
"[",
"]",
"*",
"Job",
",",
"len",
"(",
"c",
".",
"jobs",
")",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"jobName",
",",
"builds",
":=",
"range",
"c",
".",
"jobs",
"{",
"slice",
"[",
"i",
"]",
"=",
"&",
"Job",
"{",
"Name",
":",
"jobName",
",",
"Builds",
":",
"builds",
"}",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"less",
":=",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"len",
"(",
"slice",
"[",
"i",
"]",
".",
"Builds",
")",
">",
"len",
"(",
"slice",
"[",
"j",
"]",
".",
"Builds",
")",
"}",
"\n",
"sort",
".",
"SliceStable",
"(",
"slice",
",",
"less",
")",
"\n",
"if",
"len",
"(",
"slice",
")",
"<",
"count",
"{",
"count",
"=",
"len",
"(",
"slice",
")",
"\n",
"}",
"\n",
"return",
"slice",
"[",
"0",
":",
"count",
"]",
"\n",
"}"
] |
// topJobsFailed returns the top 'count' job names sorted by number of failing builds.
|
[
"topJobsFailed",
"returns",
"the",
"top",
"count",
"job",
"names",
"sorted",
"by",
"number",
"of",
"failing",
"builds",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/robots/issue-creator/sources/triage-filer.go#L347-L361
|
test
|
kubernetes/test-infra
|
robots/issue-creator/sources/triage-filer.go
|
Title
|
func (c *Cluster) Title() string {
return fmt.Sprintf("Failure cluster [%s...] failed %d builds, %d jobs, and %d tests over %d days",
c.Identifier[0:6],
c.totalBuilds,
c.totalJobs,
c.totalTests,
c.filer.windowDays,
)
}
|
go
|
func (c *Cluster) Title() string {
return fmt.Sprintf("Failure cluster [%s...] failed %d builds, %d jobs, and %d tests over %d days",
c.Identifier[0:6],
c.totalBuilds,
c.totalJobs,
c.totalTests,
c.filer.windowDays,
)
}
|
[
"func",
"(",
"c",
"*",
"Cluster",
")",
"Title",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"Failure cluster [%s...] failed %d builds, %d jobs, and %d tests over %d days\"",
",",
"c",
".",
"Identifier",
"[",
"0",
":",
"6",
"]",
",",
"c",
".",
"totalBuilds",
",",
"c",
".",
"totalJobs",
",",
"c",
".",
"totalTests",
",",
"c",
".",
"filer",
".",
"windowDays",
",",
")",
"\n",
"}"
] |
// Title is the string to use as the github issue title.
|
[
"Title",
"is",
"the",
"string",
"to",
"use",
"as",
"the",
"github",
"issue",
"title",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/robots/issue-creator/sources/triage-filer.go#L364-L372
|
test
|
kubernetes/test-infra
|
robots/issue-creator/sources/triage-filer.go
|
Labels
|
func (c *Cluster) Labels() []string {
labels := []string{"kind/flake"}
topTests := make([]string, len(c.Tests))
for i, test := range c.topTestsFailed(len(c.Tests)) {
topTests[i] = test.Name
}
for sig := range c.filer.creator.TestsSIGs(topTests) {
labels = append(labels, "sig/"+sig)
}
return labels
}
|
go
|
func (c *Cluster) Labels() []string {
labels := []string{"kind/flake"}
topTests := make([]string, len(c.Tests))
for i, test := range c.topTestsFailed(len(c.Tests)) {
topTests[i] = test.Name
}
for sig := range c.filer.creator.TestsSIGs(topTests) {
labels = append(labels, "sig/"+sig)
}
return labels
}
|
[
"func",
"(",
"c",
"*",
"Cluster",
")",
"Labels",
"(",
")",
"[",
"]",
"string",
"{",
"labels",
":=",
"[",
"]",
"string",
"{",
"\"kind/flake\"",
"}",
"\n",
"topTests",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"c",
".",
"Tests",
")",
")",
"\n",
"for",
"i",
",",
"test",
":=",
"range",
"c",
".",
"topTestsFailed",
"(",
"len",
"(",
"c",
".",
"Tests",
")",
")",
"{",
"topTests",
"[",
"i",
"]",
"=",
"test",
".",
"Name",
"\n",
"}",
"\n",
"for",
"sig",
":=",
"range",
"c",
".",
"filer",
".",
"creator",
".",
"TestsSIGs",
"(",
"topTests",
")",
"{",
"labels",
"=",
"append",
"(",
"labels",
",",
"\"sig/\"",
"+",
"sig",
")",
"\n",
"}",
"\n",
"return",
"labels",
"\n",
"}"
] |
// Labels returns the labels to apply to the issue created for this cluster on github.
|
[
"Labels",
"returns",
"the",
"labels",
"to",
"apply",
"to",
"the",
"issue",
"created",
"for",
"this",
"cluster",
"on",
"github",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/robots/issue-creator/sources/triage-filer.go#L460-L472
|
test
|
kubernetes/test-infra
|
prow/cron/cron.go
|
New
|
func New() *Cron {
return &Cron{
cronAgent: cron.New(),
jobs: map[string]*jobStatus{},
logger: logrus.WithField("client", "cron"),
}
}
|
go
|
func New() *Cron {
return &Cron{
cronAgent: cron.New(),
jobs: map[string]*jobStatus{},
logger: logrus.WithField("client", "cron"),
}
}
|
[
"func",
"New",
"(",
")",
"*",
"Cron",
"{",
"return",
"&",
"Cron",
"{",
"cronAgent",
":",
"cron",
".",
"New",
"(",
")",
",",
"jobs",
":",
"map",
"[",
"string",
"]",
"*",
"jobStatus",
"{",
"}",
",",
"logger",
":",
"logrus",
".",
"WithField",
"(",
"\"client\"",
",",
"\"cron\"",
")",
",",
"}",
"\n",
"}"
] |
// New makes a new Cron object
|
[
"New",
"makes",
"a",
"new",
"Cron",
"object"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/cron/cron.go#L53-L59
|
test
|
kubernetes/test-infra
|
prow/cron/cron.go
|
QueuedJobs
|
func (c *Cron) QueuedJobs() []string {
c.lock.Lock()
defer c.lock.Unlock()
res := []string{}
for k, v := range c.jobs {
if v.triggered {
res = append(res, k)
}
c.jobs[k].triggered = false
}
return res
}
|
go
|
func (c *Cron) QueuedJobs() []string {
c.lock.Lock()
defer c.lock.Unlock()
res := []string{}
for k, v := range c.jobs {
if v.triggered {
res = append(res, k)
}
c.jobs[k].triggered = false
}
return res
}
|
[
"func",
"(",
"c",
"*",
"Cron",
")",
"QueuedJobs",
"(",
")",
"[",
"]",
"string",
"{",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"res",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"c",
".",
"jobs",
"{",
"if",
"v",
".",
"triggered",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"k",
")",
"\n",
"}",
"\n",
"c",
".",
"jobs",
"[",
"k",
"]",
".",
"triggered",
"=",
"false",
"\n",
"}",
"\n",
"return",
"res",
"\n",
"}"
] |
// QueuedJobs returns a list of jobs that need to be triggered
// and reset trigger in jobStatus
|
[
"QueuedJobs",
"returns",
"a",
"list",
"of",
"jobs",
"that",
"need",
"to",
"be",
"triggered",
"and",
"reset",
"trigger",
"in",
"jobStatus"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/cron/cron.go#L73-L85
|
test
|
kubernetes/test-infra
|
prow/cron/cron.go
|
HasJob
|
func (c *Cron) HasJob(name string) bool {
c.lock.Lock()
defer c.lock.Unlock()
_, ok := c.jobs[name]
return ok
}
|
go
|
func (c *Cron) HasJob(name string) bool {
c.lock.Lock()
defer c.lock.Unlock()
_, ok := c.jobs[name]
return ok
}
|
[
"func",
"(",
"c",
"*",
"Cron",
")",
"HasJob",
"(",
"name",
"string",
")",
"bool",
"{",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"_",
",",
"ok",
":=",
"c",
".",
"jobs",
"[",
"name",
"]",
"\n",
"return",
"ok",
"\n",
"}"
] |
// HasJob returns if a job has been scheduled in cronAgent or not
|
[
"HasJob",
"returns",
"if",
"a",
"job",
"has",
"been",
"scheduled",
"in",
"cronAgent",
"or",
"not"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/cron/cron.go#L120-L126
|
test
|
kubernetes/test-infra
|
prow/cron/cron.go
|
addJob
|
func (c *Cron) addJob(name, cron string) error {
id, err := c.cronAgent.AddFunc("TZ=UTC "+cron, func() {
c.lock.Lock()
defer c.lock.Unlock()
c.jobs[name].triggered = true
c.logger.Infof("Triggering cron job %s.", name)
})
if err != nil {
return fmt.Errorf("cronAgent fails to add job %s with cron %s: %v", name, cron, err)
}
c.jobs[name] = &jobStatus{
entryID: id,
cronStr: cron,
// try to kick of a periodic trigger right away
triggered: strings.HasPrefix(cron, "@every"),
}
c.logger.Infof("Added new cron job %s with trigger %s.", name, cron)
return nil
}
|
go
|
func (c *Cron) addJob(name, cron string) error {
id, err := c.cronAgent.AddFunc("TZ=UTC "+cron, func() {
c.lock.Lock()
defer c.lock.Unlock()
c.jobs[name].triggered = true
c.logger.Infof("Triggering cron job %s.", name)
})
if err != nil {
return fmt.Errorf("cronAgent fails to add job %s with cron %s: %v", name, cron, err)
}
c.jobs[name] = &jobStatus{
entryID: id,
cronStr: cron,
// try to kick of a periodic trigger right away
triggered: strings.HasPrefix(cron, "@every"),
}
c.logger.Infof("Added new cron job %s with trigger %s.", name, cron)
return nil
}
|
[
"func",
"(",
"c",
"*",
"Cron",
")",
"addJob",
"(",
"name",
",",
"cron",
"string",
")",
"error",
"{",
"id",
",",
"err",
":=",
"c",
".",
"cronAgent",
".",
"AddFunc",
"(",
"\"TZ=UTC \"",
"+",
"cron",
",",
"func",
"(",
")",
"{",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"jobs",
"[",
"name",
"]",
".",
"triggered",
"=",
"true",
"\n",
"c",
".",
"logger",
".",
"Infof",
"(",
"\"Triggering cron job %s.\"",
",",
"name",
")",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"cronAgent fails to add job %s with cron %s: %v\"",
",",
"name",
",",
"cron",
",",
"err",
")",
"\n",
"}",
"\n",
"c",
".",
"jobs",
"[",
"name",
"]",
"=",
"&",
"jobStatus",
"{",
"entryID",
":",
"id",
",",
"cronStr",
":",
"cron",
",",
"triggered",
":",
"strings",
".",
"HasPrefix",
"(",
"cron",
",",
"\"@every\"",
")",
",",
"}",
"\n",
"c",
".",
"logger",
".",
"Infof",
"(",
"\"Added new cron job %s with trigger %s.\"",
",",
"name",
",",
"cron",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// addJob adds a cron entry for a job to cronAgent
|
[
"addJob",
"adds",
"a",
"cron",
"entry",
"for",
"a",
"job",
"to",
"cronAgent"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/cron/cron.go#L151-L173
|
test
|
kubernetes/test-infra
|
prow/cron/cron.go
|
removeJob
|
func (c *Cron) removeJob(name string) error {
job, ok := c.jobs[name]
if !ok {
return fmt.Errorf("job %s has not been added to cronAgent yet", name)
}
c.cronAgent.Remove(job.entryID)
delete(c.jobs, name)
c.logger.Infof("Removed previous cron job %s.", name)
return nil
}
|
go
|
func (c *Cron) removeJob(name string) error {
job, ok := c.jobs[name]
if !ok {
return fmt.Errorf("job %s has not been added to cronAgent yet", name)
}
c.cronAgent.Remove(job.entryID)
delete(c.jobs, name)
c.logger.Infof("Removed previous cron job %s.", name)
return nil
}
|
[
"func",
"(",
"c",
"*",
"Cron",
")",
"removeJob",
"(",
"name",
"string",
")",
"error",
"{",
"job",
",",
"ok",
":=",
"c",
".",
"jobs",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"job %s has not been added to cronAgent yet\"",
",",
"name",
")",
"\n",
"}",
"\n",
"c",
".",
"cronAgent",
".",
"Remove",
"(",
"job",
".",
"entryID",
")",
"\n",
"delete",
"(",
"c",
".",
"jobs",
",",
"name",
")",
"\n",
"c",
".",
"logger",
".",
"Infof",
"(",
"\"Removed previous cron job %s.\"",
",",
"name",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// removeJob removes the job from cronAgent
|
[
"removeJob",
"removes",
"the",
"job",
"from",
"cronAgent"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/cron/cron.go#L176-L185
|
test
|
kubernetes/test-infra
|
velodrome/fetcher/comments.go
|
UpdateComments
|
func UpdateComments(issueID int, pullRequest bool, db *gorm.DB, client ClientInterface) {
latest := findLatestCommentUpdate(issueID, db, client.RepositoryName())
updateIssueComments(issueID, latest, db, client)
if pullRequest {
updatePullComments(issueID, latest, db, client)
}
}
|
go
|
func UpdateComments(issueID int, pullRequest bool, db *gorm.DB, client ClientInterface) {
latest := findLatestCommentUpdate(issueID, db, client.RepositoryName())
updateIssueComments(issueID, latest, db, client)
if pullRequest {
updatePullComments(issueID, latest, db, client)
}
}
|
[
"func",
"UpdateComments",
"(",
"issueID",
"int",
",",
"pullRequest",
"bool",
",",
"db",
"*",
"gorm",
".",
"DB",
",",
"client",
"ClientInterface",
")",
"{",
"latest",
":=",
"findLatestCommentUpdate",
"(",
"issueID",
",",
"db",
",",
"client",
".",
"RepositoryName",
"(",
")",
")",
"\n",
"updateIssueComments",
"(",
"issueID",
",",
"latest",
",",
"db",
",",
"client",
")",
"\n",
"if",
"pullRequest",
"{",
"updatePullComments",
"(",
"issueID",
",",
"latest",
",",
"db",
",",
"client",
")",
"\n",
"}",
"\n",
"}"
] |
// UpdateComments downloads issue and pull-request comments and save in DB
|
[
"UpdateComments",
"downloads",
"issue",
"and",
"pull",
"-",
"request",
"comments",
"and",
"save",
"in",
"DB"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/velodrome/fetcher/comments.go#L80-L87
|
test
|
kubernetes/test-infra
|
prow/kube/metrics.go
|
GatherProwJobMetrics
|
func GatherProwJobMetrics(pjs []prowapi.ProwJob) {
// map of job to job type to state to count
metricMap := make(map[string]map[string]map[string]float64)
for _, pj := range pjs {
if metricMap[pj.Spec.Job] == nil {
metricMap[pj.Spec.Job] = make(map[string]map[string]float64)
}
if metricMap[pj.Spec.Job][string(pj.Spec.Type)] == nil {
metricMap[pj.Spec.Job][string(pj.Spec.Type)] = make(map[string]float64)
}
metricMap[pj.Spec.Job][string(pj.Spec.Type)][string(pj.Status.State)]++
}
// This may be racing with the prometheus server but we need to remove
// stale metrics like triggered or pending jobs that are now complete.
prowJobs.Reset()
for job, jobMap := range metricMap {
for jobType, typeMap := range jobMap {
for state, count := range typeMap {
prowJobs.WithLabelValues(job, jobType, state).Set(count)
}
}
}
}
|
go
|
func GatherProwJobMetrics(pjs []prowapi.ProwJob) {
// map of job to job type to state to count
metricMap := make(map[string]map[string]map[string]float64)
for _, pj := range pjs {
if metricMap[pj.Spec.Job] == nil {
metricMap[pj.Spec.Job] = make(map[string]map[string]float64)
}
if metricMap[pj.Spec.Job][string(pj.Spec.Type)] == nil {
metricMap[pj.Spec.Job][string(pj.Spec.Type)] = make(map[string]float64)
}
metricMap[pj.Spec.Job][string(pj.Spec.Type)][string(pj.Status.State)]++
}
// This may be racing with the prometheus server but we need to remove
// stale metrics like triggered or pending jobs that are now complete.
prowJobs.Reset()
for job, jobMap := range metricMap {
for jobType, typeMap := range jobMap {
for state, count := range typeMap {
prowJobs.WithLabelValues(job, jobType, state).Set(count)
}
}
}
}
|
[
"func",
"GatherProwJobMetrics",
"(",
"pjs",
"[",
"]",
"prowapi",
".",
"ProwJob",
")",
"{",
"metricMap",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"float64",
")",
"\n",
"for",
"_",
",",
"pj",
":=",
"range",
"pjs",
"{",
"if",
"metricMap",
"[",
"pj",
".",
"Spec",
".",
"Job",
"]",
"==",
"nil",
"{",
"metricMap",
"[",
"pj",
".",
"Spec",
".",
"Job",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"float64",
")",
"\n",
"}",
"\n",
"if",
"metricMap",
"[",
"pj",
".",
"Spec",
".",
"Job",
"]",
"[",
"string",
"(",
"pj",
".",
"Spec",
".",
"Type",
")",
"]",
"==",
"nil",
"{",
"metricMap",
"[",
"pj",
".",
"Spec",
".",
"Job",
"]",
"[",
"string",
"(",
"pj",
".",
"Spec",
".",
"Type",
")",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"float64",
")",
"\n",
"}",
"\n",
"metricMap",
"[",
"pj",
".",
"Spec",
".",
"Job",
"]",
"[",
"string",
"(",
"pj",
".",
"Spec",
".",
"Type",
")",
"]",
"[",
"string",
"(",
"pj",
".",
"Status",
".",
"State",
")",
"]",
"++",
"\n",
"}",
"\n",
"prowJobs",
".",
"Reset",
"(",
")",
"\n",
"for",
"job",
",",
"jobMap",
":=",
"range",
"metricMap",
"{",
"for",
"jobType",
",",
"typeMap",
":=",
"range",
"jobMap",
"{",
"for",
"state",
",",
"count",
":=",
"range",
"typeMap",
"{",
"prowJobs",
".",
"WithLabelValues",
"(",
"job",
",",
"jobType",
",",
"state",
")",
".",
"Set",
"(",
"count",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// GatherProwJobMetrics gathers prometheus metrics for prowjobs.
|
[
"GatherProwJobMetrics",
"gathers",
"prometheus",
"metrics",
"for",
"prowjobs",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/kube/metrics.go#L44-L69
|
test
|
kubernetes/test-infra
|
prow/entrypoint/run.go
|
optionOrDefault
|
func optionOrDefault(option, defaultValue time.Duration) time.Duration {
if option == 0 {
return defaultValue
}
return option
}
|
go
|
func optionOrDefault(option, defaultValue time.Duration) time.Duration {
if option == 0 {
return defaultValue
}
return option
}
|
[
"func",
"optionOrDefault",
"(",
"option",
",",
"defaultValue",
"time",
".",
"Duration",
")",
"time",
".",
"Duration",
"{",
"if",
"option",
"==",
"0",
"{",
"return",
"defaultValue",
"\n",
"}",
"\n",
"return",
"option",
"\n",
"}"
] |
// optionOrDefault defaults to a value if option
// is the zero value
|
[
"optionOrDefault",
"defaults",
"to",
"a",
"value",
"if",
"option",
"is",
"the",
"zero",
"value"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/entrypoint/run.go#L223-L229
|
test
|
kubernetes/test-infra
|
prow/spyglass/gcsartifact_fetcher.go
|
newGCSJobSource
|
func newGCSJobSource(src string) (*gcsJobSource, error) {
gcsURL, err := url.Parse(fmt.Sprintf("gs://%s", src))
if err != nil {
return &gcsJobSource{}, ErrCannotParseSource
}
gcsPath := &gcs.Path{}
err = gcsPath.SetURL(gcsURL)
if err != nil {
return &gcsJobSource{}, ErrCannotParseSource
}
tokens := strings.FieldsFunc(gcsPath.Object(), func(c rune) bool { return c == '/' })
if len(tokens) < 2 {
return &gcsJobSource{}, ErrCannotParseSource
}
buildID := tokens[len(tokens)-1]
name := tokens[len(tokens)-2]
return &gcsJobSource{
source: src,
linkPrefix: "gs://",
bucket: gcsPath.Bucket(),
jobPrefix: path.Clean(gcsPath.Object()) + "/",
jobName: name,
buildID: buildID,
}, nil
}
|
go
|
func newGCSJobSource(src string) (*gcsJobSource, error) {
gcsURL, err := url.Parse(fmt.Sprintf("gs://%s", src))
if err != nil {
return &gcsJobSource{}, ErrCannotParseSource
}
gcsPath := &gcs.Path{}
err = gcsPath.SetURL(gcsURL)
if err != nil {
return &gcsJobSource{}, ErrCannotParseSource
}
tokens := strings.FieldsFunc(gcsPath.Object(), func(c rune) bool { return c == '/' })
if len(tokens) < 2 {
return &gcsJobSource{}, ErrCannotParseSource
}
buildID := tokens[len(tokens)-1]
name := tokens[len(tokens)-2]
return &gcsJobSource{
source: src,
linkPrefix: "gs://",
bucket: gcsPath.Bucket(),
jobPrefix: path.Clean(gcsPath.Object()) + "/",
jobName: name,
buildID: buildID,
}, nil
}
|
[
"func",
"newGCSJobSource",
"(",
"src",
"string",
")",
"(",
"*",
"gcsJobSource",
",",
"error",
")",
"{",
"gcsURL",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"gs://%s\"",
",",
"src",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"gcsJobSource",
"{",
"}",
",",
"ErrCannotParseSource",
"\n",
"}",
"\n",
"gcsPath",
":=",
"&",
"gcs",
".",
"Path",
"{",
"}",
"\n",
"err",
"=",
"gcsPath",
".",
"SetURL",
"(",
"gcsURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"gcsJobSource",
"{",
"}",
",",
"ErrCannotParseSource",
"\n",
"}",
"\n",
"tokens",
":=",
"strings",
".",
"FieldsFunc",
"(",
"gcsPath",
".",
"Object",
"(",
")",
",",
"func",
"(",
"c",
"rune",
")",
"bool",
"{",
"return",
"c",
"==",
"'/'",
"}",
")",
"\n",
"if",
"len",
"(",
"tokens",
")",
"<",
"2",
"{",
"return",
"&",
"gcsJobSource",
"{",
"}",
",",
"ErrCannotParseSource",
"\n",
"}",
"\n",
"buildID",
":=",
"tokens",
"[",
"len",
"(",
"tokens",
")",
"-",
"1",
"]",
"\n",
"name",
":=",
"tokens",
"[",
"len",
"(",
"tokens",
")",
"-",
"2",
"]",
"\n",
"return",
"&",
"gcsJobSource",
"{",
"source",
":",
"src",
",",
"linkPrefix",
":",
"\"gs://\"",
",",
"bucket",
":",
"gcsPath",
".",
"Bucket",
"(",
")",
",",
"jobPrefix",
":",
"path",
".",
"Clean",
"(",
"gcsPath",
".",
"Object",
"(",
")",
")",
"+",
"\"/\"",
",",
"jobName",
":",
"name",
",",
"buildID",
":",
"buildID",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// newGCSJobSource creates a new gcsJobSource from a given bucket and jobPrefix
|
[
"newGCSJobSource",
"creates",
"a",
"new",
"gcsJobSource",
"from",
"a",
"given",
"bucket",
"and",
"jobPrefix"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/gcsartifact_fetcher.go#L79-L104
|
test
|
kubernetes/test-infra
|
prow/spyglass/gcsartifact_fetcher.go
|
artifacts
|
func (af *GCSArtifactFetcher) artifacts(key string) ([]string, error) {
src, err := newGCSJobSource(key)
if err != nil {
return nil, fmt.Errorf("Failed to get GCS job source from %s: %v", key, err)
}
listStart := time.Now()
bucketName, prefix := extractBucketPrefixPair(src.jobPath())
artifacts := []string{}
bkt := af.client.Bucket(bucketName)
q := storage.Query{
Prefix: prefix,
Versions: false,
}
objIter := bkt.Objects(context.Background(), &q)
wait := []time.Duration{16, 32, 64, 128, 256, 256, 512, 512}
for i := 0; ; {
oAttrs, err := objIter.Next()
if err == iterator.Done {
break
}
if err != nil {
logrus.WithFields(fieldsForJob(src)).WithError(err).Error("Error accessing GCS artifact.")
if i >= len(wait) {
return artifacts, fmt.Errorf("timed out: error accessing GCS artifact: %v", err)
}
time.Sleep((wait[i] + time.Duration(rand.Intn(10))) * time.Millisecond)
i++
continue
}
artifacts = append(artifacts, strings.TrimPrefix(oAttrs.Name, prefix))
i = 0
}
listElapsed := time.Since(listStart)
logrus.WithField("duration", listElapsed).Infof("Listed %d artifacts.", len(artifacts))
return artifacts, nil
}
|
go
|
func (af *GCSArtifactFetcher) artifacts(key string) ([]string, error) {
src, err := newGCSJobSource(key)
if err != nil {
return nil, fmt.Errorf("Failed to get GCS job source from %s: %v", key, err)
}
listStart := time.Now()
bucketName, prefix := extractBucketPrefixPair(src.jobPath())
artifacts := []string{}
bkt := af.client.Bucket(bucketName)
q := storage.Query{
Prefix: prefix,
Versions: false,
}
objIter := bkt.Objects(context.Background(), &q)
wait := []time.Duration{16, 32, 64, 128, 256, 256, 512, 512}
for i := 0; ; {
oAttrs, err := objIter.Next()
if err == iterator.Done {
break
}
if err != nil {
logrus.WithFields(fieldsForJob(src)).WithError(err).Error("Error accessing GCS artifact.")
if i >= len(wait) {
return artifacts, fmt.Errorf("timed out: error accessing GCS artifact: %v", err)
}
time.Sleep((wait[i] + time.Duration(rand.Intn(10))) * time.Millisecond)
i++
continue
}
artifacts = append(artifacts, strings.TrimPrefix(oAttrs.Name, prefix))
i = 0
}
listElapsed := time.Since(listStart)
logrus.WithField("duration", listElapsed).Infof("Listed %d artifacts.", len(artifacts))
return artifacts, nil
}
|
[
"func",
"(",
"af",
"*",
"GCSArtifactFetcher",
")",
"artifacts",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"src",
",",
"err",
":=",
"newGCSJobSource",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"Failed to get GCS job source from %s: %v\"",
",",
"key",
",",
"err",
")",
"\n",
"}",
"\n",
"listStart",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"bucketName",
",",
"prefix",
":=",
"extractBucketPrefixPair",
"(",
"src",
".",
"jobPath",
"(",
")",
")",
"\n",
"artifacts",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"bkt",
":=",
"af",
".",
"client",
".",
"Bucket",
"(",
"bucketName",
")",
"\n",
"q",
":=",
"storage",
".",
"Query",
"{",
"Prefix",
":",
"prefix",
",",
"Versions",
":",
"false",
",",
"}",
"\n",
"objIter",
":=",
"bkt",
".",
"Objects",
"(",
"context",
".",
"Background",
"(",
")",
",",
"&",
"q",
")",
"\n",
"wait",
":=",
"[",
"]",
"time",
".",
"Duration",
"{",
"16",
",",
"32",
",",
"64",
",",
"128",
",",
"256",
",",
"256",
",",
"512",
",",
"512",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
";",
"{",
"oAttrs",
",",
"err",
":=",
"objIter",
".",
"Next",
"(",
")",
"\n",
"if",
"err",
"==",
"iterator",
".",
"Done",
"{",
"break",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithFields",
"(",
"fieldsForJob",
"(",
"src",
")",
")",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"Error accessing GCS artifact.\"",
")",
"\n",
"if",
"i",
">=",
"len",
"(",
"wait",
")",
"{",
"return",
"artifacts",
",",
"fmt",
".",
"Errorf",
"(",
"\"timed out: error accessing GCS artifact: %v\"",
",",
"err",
")",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"(",
"wait",
"[",
"i",
"]",
"+",
"time",
".",
"Duration",
"(",
"rand",
".",
"Intn",
"(",
"10",
")",
")",
")",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"i",
"++",
"\n",
"continue",
"\n",
"}",
"\n",
"artifacts",
"=",
"append",
"(",
"artifacts",
",",
"strings",
".",
"TrimPrefix",
"(",
"oAttrs",
".",
"Name",
",",
"prefix",
")",
")",
"\n",
"i",
"=",
"0",
"\n",
"}",
"\n",
"listElapsed",
":=",
"time",
".",
"Since",
"(",
"listStart",
")",
"\n",
"logrus",
".",
"WithField",
"(",
"\"duration\"",
",",
"listElapsed",
")",
".",
"Infof",
"(",
"\"Listed %d artifacts.\"",
",",
"len",
"(",
"artifacts",
")",
")",
"\n",
"return",
"artifacts",
",",
"nil",
"\n",
"}"
] |
// Artifacts lists all artifacts available for the given job source
|
[
"Artifacts",
"lists",
"all",
"artifacts",
"available",
"for",
"the",
"given",
"job",
"source"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/gcsartifact_fetcher.go#L107-L143
|
test
|
kubernetes/test-infra
|
prow/spyglass/gcsartifact_fetcher.go
|
canonicalLink
|
func (src *gcsJobSource) canonicalLink() string {
return path.Join(src.linkPrefix, src.bucket, src.jobPrefix)
}
|
go
|
func (src *gcsJobSource) canonicalLink() string {
return path.Join(src.linkPrefix, src.bucket, src.jobPrefix)
}
|
[
"func",
"(",
"src",
"*",
"gcsJobSource",
")",
"canonicalLink",
"(",
")",
"string",
"{",
"return",
"path",
".",
"Join",
"(",
"src",
".",
"linkPrefix",
",",
"src",
".",
"bucket",
",",
"src",
".",
"jobPrefix",
")",
"\n",
"}"
] |
// CanonicalLink gets a link to the location of job-specific artifacts in GCS
|
[
"CanonicalLink",
"gets",
"a",
"link",
"to",
"the",
"location",
"of",
"job",
"-",
"specific",
"artifacts",
"in",
"GCS"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/gcsartifact_fetcher.go#L183-L185
|
test
|
kubernetes/test-infra
|
prow/spyglass/gcsartifact_fetcher.go
|
jobPath
|
func (src *gcsJobSource) jobPath() string {
return fmt.Sprintf("%s/%s", src.bucket, src.jobPrefix)
}
|
go
|
func (src *gcsJobSource) jobPath() string {
return fmt.Sprintf("%s/%s", src.bucket, src.jobPrefix)
}
|
[
"func",
"(",
"src",
"*",
"gcsJobSource",
")",
"jobPath",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"%s/%s\"",
",",
"src",
".",
"bucket",
",",
"src",
".",
"jobPrefix",
")",
"\n",
"}"
] |
// JobPath gets the prefix to all artifacts in GCS in the job
|
[
"JobPath",
"gets",
"the",
"prefix",
"to",
"all",
"artifacts",
"in",
"GCS",
"in",
"the",
"job"
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/spyglass/gcsartifact_fetcher.go#L188-L190
|
test
|
kubernetes/test-infra
|
prow/tide/status.go
|
targetURL
|
func targetURL(c config.Getter, pr *PullRequest, log *logrus.Entry) string {
var link string
if tideURL := c().Tide.TargetURL; tideURL != "" {
link = tideURL
} else if baseURL := c().Tide.PRStatusBaseURL; baseURL != "" {
parseURL, err := url.Parse(baseURL)
if err != nil {
log.WithError(err).Error("Failed to parse PR status base URL")
} else {
prQuery := fmt.Sprintf("is:pr repo:%s author:%s head:%s", pr.Repository.NameWithOwner, pr.Author.Login, pr.HeadRefName)
values := parseURL.Query()
values.Set("query", prQuery)
parseURL.RawQuery = values.Encode()
link = parseURL.String()
}
}
return link
}
|
go
|
func targetURL(c config.Getter, pr *PullRequest, log *logrus.Entry) string {
var link string
if tideURL := c().Tide.TargetURL; tideURL != "" {
link = tideURL
} else if baseURL := c().Tide.PRStatusBaseURL; baseURL != "" {
parseURL, err := url.Parse(baseURL)
if err != nil {
log.WithError(err).Error("Failed to parse PR status base URL")
} else {
prQuery := fmt.Sprintf("is:pr repo:%s author:%s head:%s", pr.Repository.NameWithOwner, pr.Author.Login, pr.HeadRefName)
values := parseURL.Query()
values.Set("query", prQuery)
parseURL.RawQuery = values.Encode()
link = parseURL.String()
}
}
return link
}
|
[
"func",
"targetURL",
"(",
"c",
"config",
".",
"Getter",
",",
"pr",
"*",
"PullRequest",
",",
"log",
"*",
"logrus",
".",
"Entry",
")",
"string",
"{",
"var",
"link",
"string",
"\n",
"if",
"tideURL",
":=",
"c",
"(",
")",
".",
"Tide",
".",
"TargetURL",
";",
"tideURL",
"!=",
"\"\"",
"{",
"link",
"=",
"tideURL",
"\n",
"}",
"else",
"if",
"baseURL",
":=",
"c",
"(",
")",
".",
"Tide",
".",
"PRStatusBaseURL",
";",
"baseURL",
"!=",
"\"\"",
"{",
"parseURL",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"baseURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"Failed to parse PR status base URL\"",
")",
"\n",
"}",
"else",
"{",
"prQuery",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"is:pr repo:%s author:%s head:%s\"",
",",
"pr",
".",
"Repository",
".",
"NameWithOwner",
",",
"pr",
".",
"Author",
".",
"Login",
",",
"pr",
".",
"HeadRefName",
")",
"\n",
"values",
":=",
"parseURL",
".",
"Query",
"(",
")",
"\n",
"values",
".",
"Set",
"(",
"\"query\"",
",",
"prQuery",
")",
"\n",
"parseURL",
".",
"RawQuery",
"=",
"values",
".",
"Encode",
"(",
")",
"\n",
"link",
"=",
"parseURL",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"link",
"\n",
"}"
] |
// targetURL determines the URL used for more details in the status
// context on GitHub. If no PR dashboard is configured, we will use
// the administrative Prow overview.
|
[
"targetURL",
"determines",
"the",
"URL",
"used",
"for",
"more",
"details",
"in",
"the",
"status",
"context",
"on",
"GitHub",
".",
"If",
"no",
"PR",
"dashboard",
"is",
"configured",
"we",
"will",
"use",
"the",
"administrative",
"Prow",
"overview",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/tide/status.go#L242-L259
|
test
|
kubernetes/test-infra
|
prow/cmd/build/main.go
|
newBuildConfig
|
func newBuildConfig(cfg rest.Config, stop chan struct{}) (*buildConfig, error) {
bc, err := buildset.NewForConfig(&cfg)
if err != nil {
return nil, err
}
// Ensure the knative-build CRD is deployed
// TODO(fejta): probably a better way to do this
_, err = bc.BuildV1alpha1().Builds("").List(metav1.ListOptions{Limit: 1})
if err != nil {
return nil, err
}
// Assume watches receive updates, but resync every 30m in case something wonky happens
bif := buildinfo.NewSharedInformerFactory(bc, 30*time.Minute)
bif.Build().V1alpha1().Builds().Lister()
go bif.Start(stop)
return &buildConfig{
client: bc,
informer: bif.Build().V1alpha1().Builds(),
}, nil
}
|
go
|
func newBuildConfig(cfg rest.Config, stop chan struct{}) (*buildConfig, error) {
bc, err := buildset.NewForConfig(&cfg)
if err != nil {
return nil, err
}
// Ensure the knative-build CRD is deployed
// TODO(fejta): probably a better way to do this
_, err = bc.BuildV1alpha1().Builds("").List(metav1.ListOptions{Limit: 1})
if err != nil {
return nil, err
}
// Assume watches receive updates, but resync every 30m in case something wonky happens
bif := buildinfo.NewSharedInformerFactory(bc, 30*time.Minute)
bif.Build().V1alpha1().Builds().Lister()
go bif.Start(stop)
return &buildConfig{
client: bc,
informer: bif.Build().V1alpha1().Builds(),
}, nil
}
|
[
"func",
"newBuildConfig",
"(",
"cfg",
"rest",
".",
"Config",
",",
"stop",
"chan",
"struct",
"{",
"}",
")",
"(",
"*",
"buildConfig",
",",
"error",
")",
"{",
"bc",
",",
"err",
":=",
"buildset",
".",
"NewForConfig",
"(",
"&",
"cfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"bc",
".",
"BuildV1alpha1",
"(",
")",
".",
"Builds",
"(",
"\"\"",
")",
".",
"List",
"(",
"metav1",
".",
"ListOptions",
"{",
"Limit",
":",
"1",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"bif",
":=",
"buildinfo",
".",
"NewSharedInformerFactory",
"(",
"bc",
",",
"30",
"*",
"time",
".",
"Minute",
")",
"\n",
"bif",
".",
"Build",
"(",
")",
".",
"V1alpha1",
"(",
")",
".",
"Builds",
"(",
")",
".",
"Lister",
"(",
")",
"\n",
"go",
"bif",
".",
"Start",
"(",
"stop",
")",
"\n",
"return",
"&",
"buildConfig",
"{",
"client",
":",
"bc",
",",
"informer",
":",
"bif",
".",
"Build",
"(",
")",
".",
"V1alpha1",
"(",
")",
".",
"Builds",
"(",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// newBuildConfig returns a client and informer capable of mutating and monitoring the specified config.
|
[
"newBuildConfig",
"returns",
"a",
"client",
"and",
"informer",
"capable",
"of",
"mutating",
"and",
"monitoring",
"the",
"specified",
"config",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/cmd/build/main.go#L109-L129
|
test
|
kubernetes/test-infra
|
pkg/ghclient/core.go
|
NewClient
|
func NewClient(token string, dryRun bool) *Client {
httpClient := &http.Client{
Transport: &oauth2.Transport{
Base: http.DefaultTransport,
Source: oauth2.ReuseTokenSource(nil, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})),
},
}
client := github.NewClient(httpClient)
return &Client{
issueService: client.Issues,
prService: client.PullRequests,
repoService: client.Repositories,
userService: client.Users,
retries: 5,
retryInitialBackoff: time.Second,
tokenReserve: 50,
dryRun: dryRun,
}
}
|
go
|
func NewClient(token string, dryRun bool) *Client {
httpClient := &http.Client{
Transport: &oauth2.Transport{
Base: http.DefaultTransport,
Source: oauth2.ReuseTokenSource(nil, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})),
},
}
client := github.NewClient(httpClient)
return &Client{
issueService: client.Issues,
prService: client.PullRequests,
repoService: client.Repositories,
userService: client.Users,
retries: 5,
retryInitialBackoff: time.Second,
tokenReserve: 50,
dryRun: dryRun,
}
}
|
[
"func",
"NewClient",
"(",
"token",
"string",
",",
"dryRun",
"bool",
")",
"*",
"Client",
"{",
"httpClient",
":=",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"&",
"oauth2",
".",
"Transport",
"{",
"Base",
":",
"http",
".",
"DefaultTransport",
",",
"Source",
":",
"oauth2",
".",
"ReuseTokenSource",
"(",
"nil",
",",
"oauth2",
".",
"StaticTokenSource",
"(",
"&",
"oauth2",
".",
"Token",
"{",
"AccessToken",
":",
"token",
"}",
")",
")",
",",
"}",
",",
"}",
"\n",
"client",
":=",
"github",
".",
"NewClient",
"(",
"httpClient",
")",
"\n",
"return",
"&",
"Client",
"{",
"issueService",
":",
"client",
".",
"Issues",
",",
"prService",
":",
"client",
".",
"PullRequests",
",",
"repoService",
":",
"client",
".",
"Repositories",
",",
"userService",
":",
"client",
".",
"Users",
",",
"retries",
":",
"5",
",",
"retryInitialBackoff",
":",
"time",
".",
"Second",
",",
"tokenReserve",
":",
"50",
",",
"dryRun",
":",
"dryRun",
",",
"}",
"\n",
"}"
] |
// NewClient makes a new Client with the specified token and dry-run status.
|
[
"NewClient",
"makes",
"a",
"new",
"Client",
"with",
"the",
"specified",
"token",
"and",
"dry",
"-",
"run",
"status",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/pkg/ghclient/core.go#L49-L67
|
test
|
kubernetes/test-infra
|
pkg/ghclient/core.go
|
retry
|
func (c *Client) retry(action string, call func() (*github.Response, error)) (*github.Response, error) {
var err error
var resp *github.Response
for retryCount := 0; retryCount <= c.retries; retryCount++ {
if resp, err = call(); err == nil {
c.limitRate(&resp.Rate)
return resp, nil
}
switch err := err.(type) {
case *github.RateLimitError:
c.limitRate(&err.Rate)
case *github.TwoFactorAuthError:
return resp, err
case *retryAbort:
return resp, err
}
if retryCount == c.retries {
return resp, err
}
glog.Errorf("error %s: %v. Will retry.\n", action, err)
c.sleepForAttempt(retryCount)
}
return resp, err
}
|
go
|
func (c *Client) retry(action string, call func() (*github.Response, error)) (*github.Response, error) {
var err error
var resp *github.Response
for retryCount := 0; retryCount <= c.retries; retryCount++ {
if resp, err = call(); err == nil {
c.limitRate(&resp.Rate)
return resp, nil
}
switch err := err.(type) {
case *github.RateLimitError:
c.limitRate(&err.Rate)
case *github.TwoFactorAuthError:
return resp, err
case *retryAbort:
return resp, err
}
if retryCount == c.retries {
return resp, err
}
glog.Errorf("error %s: %v. Will retry.\n", action, err)
c.sleepForAttempt(retryCount)
}
return resp, err
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"retry",
"(",
"action",
"string",
",",
"call",
"func",
"(",
")",
"(",
"*",
"github",
".",
"Response",
",",
"error",
")",
")",
"(",
"*",
"github",
".",
"Response",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"resp",
"*",
"github",
".",
"Response",
"\n",
"for",
"retryCount",
":=",
"0",
";",
"retryCount",
"<=",
"c",
".",
"retries",
";",
"retryCount",
"++",
"{",
"if",
"resp",
",",
"err",
"=",
"call",
"(",
")",
";",
"err",
"==",
"nil",
"{",
"c",
".",
"limitRate",
"(",
"&",
"resp",
".",
"Rate",
")",
"\n",
"return",
"resp",
",",
"nil",
"\n",
"}",
"\n",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"github",
".",
"RateLimitError",
":",
"c",
".",
"limitRate",
"(",
"&",
"err",
".",
"Rate",
")",
"\n",
"case",
"*",
"github",
".",
"TwoFactorAuthError",
":",
"return",
"resp",
",",
"err",
"\n",
"case",
"*",
"retryAbort",
":",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n",
"if",
"retryCount",
"==",
"c",
".",
"retries",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n",
"glog",
".",
"Errorf",
"(",
"\"error %s: %v. Will retry.\\n\"",
",",
"\\n",
",",
"action",
")",
"\n",
"err",
"\n",
"}",
"\n",
"c",
".",
"sleepForAttempt",
"(",
"retryCount",
")",
"\n",
"}"
] |
// retry handles rate limiting and retry logic for a github API call.
|
[
"retry",
"handles",
"rate",
"limiting",
"and",
"retry",
"logic",
"for",
"a",
"github",
"API",
"call",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/pkg/ghclient/core.go#L95-L120
|
test
|
kubernetes/test-infra
|
pkg/ghclient/core.go
|
depaginate
|
func (c *Client) depaginate(action string, opts *github.ListOptions, call func() ([]interface{}, *github.Response, error)) ([]interface{}, error) {
var allItems []interface{}
wrapper := func() (*github.Response, error) {
items, resp, err := call()
if err == nil {
allItems = append(allItems, items...)
}
return resp, err
}
opts.Page = 1
opts.PerPage = 100
lastPage := 1
for ; opts.Page <= lastPage; opts.Page++ {
resp, err := c.retry(action, wrapper)
if err != nil {
return allItems, fmt.Errorf("error while depaginating page %d/%d: %v", opts.Page, lastPage, err)
}
if resp.LastPage > 0 {
lastPage = resp.LastPage
}
}
return allItems, nil
}
|
go
|
func (c *Client) depaginate(action string, opts *github.ListOptions, call func() ([]interface{}, *github.Response, error)) ([]interface{}, error) {
var allItems []interface{}
wrapper := func() (*github.Response, error) {
items, resp, err := call()
if err == nil {
allItems = append(allItems, items...)
}
return resp, err
}
opts.Page = 1
opts.PerPage = 100
lastPage := 1
for ; opts.Page <= lastPage; opts.Page++ {
resp, err := c.retry(action, wrapper)
if err != nil {
return allItems, fmt.Errorf("error while depaginating page %d/%d: %v", opts.Page, lastPage, err)
}
if resp.LastPage > 0 {
lastPage = resp.LastPage
}
}
return allItems, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"depaginate",
"(",
"action",
"string",
",",
"opts",
"*",
"github",
".",
"ListOptions",
",",
"call",
"func",
"(",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"*",
"github",
".",
"Response",
",",
"error",
")",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"var",
"allItems",
"[",
"]",
"interface",
"{",
"}",
"\n",
"wrapper",
":=",
"func",
"(",
")",
"(",
"*",
"github",
".",
"Response",
",",
"error",
")",
"{",
"items",
",",
"resp",
",",
"err",
":=",
"call",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"allItems",
"=",
"append",
"(",
"allItems",
",",
"items",
"...",
")",
"\n",
"}",
"\n",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n",
"opts",
".",
"Page",
"=",
"1",
"\n",
"opts",
".",
"PerPage",
"=",
"100",
"\n",
"lastPage",
":=",
"1",
"\n",
"for",
";",
"opts",
".",
"Page",
"<=",
"lastPage",
";",
"opts",
".",
"Page",
"++",
"{",
"resp",
",",
"err",
":=",
"c",
".",
"retry",
"(",
"action",
",",
"wrapper",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"allItems",
",",
"fmt",
".",
"Errorf",
"(",
"\"error while depaginating page %d/%d: %v\"",
",",
"opts",
".",
"Page",
",",
"lastPage",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"resp",
".",
"LastPage",
">",
"0",
"{",
"lastPage",
"=",
"resp",
".",
"LastPage",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"allItems",
",",
"nil",
"\n",
"}"
] |
// depaginate adds depagination on top of the retry and rate limiting logic provided by retry.
|
[
"depaginate",
"adds",
"depagination",
"on",
"top",
"of",
"the",
"retry",
"and",
"rate",
"limiting",
"logic",
"provided",
"by",
"retry",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/pkg/ghclient/core.go#L123-L146
|
test
|
kubernetes/test-infra
|
prow/pluginhelp/hook/hook.go
|
NewHelpAgent
|
func NewHelpAgent(pa pluginAgent, ghc githubClient) *HelpAgent {
l := logrus.WithField("client", "plugin-help")
return &HelpAgent{
log: l,
pa: pa,
oa: newOrgAgent(l, ghc, newRepoDetectionLimit),
}
}
|
go
|
func NewHelpAgent(pa pluginAgent, ghc githubClient) *HelpAgent {
l := logrus.WithField("client", "plugin-help")
return &HelpAgent{
log: l,
pa: pa,
oa: newOrgAgent(l, ghc, newRepoDetectionLimit),
}
}
|
[
"func",
"NewHelpAgent",
"(",
"pa",
"pluginAgent",
",",
"ghc",
"githubClient",
")",
"*",
"HelpAgent",
"{",
"l",
":=",
"logrus",
".",
"WithField",
"(",
"\"client\"",
",",
"\"plugin-help\"",
")",
"\n",
"return",
"&",
"HelpAgent",
"{",
"log",
":",
"l",
",",
"pa",
":",
"pa",
",",
"oa",
":",
"newOrgAgent",
"(",
"l",
",",
"ghc",
",",
"newRepoDetectionLimit",
")",
",",
"}",
"\n",
"}"
] |
// NewHelpAgent constructs a new HelpAgent.
|
[
"NewHelpAgent",
"constructs",
"a",
"new",
"HelpAgent",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/pluginhelp/hook/hook.go#L69-L76
|
test
|
kubernetes/test-infra
|
prow/pluginhelp/hook/hook.go
|
GeneratePluginHelp
|
func (ha *HelpAgent) GeneratePluginHelp() *pluginhelp.Help {
config := ha.pa.Config()
orgToRepos := ha.oa.orgToReposMap(config)
normalRevMap, externalRevMap := reversePluginMaps(config, orgToRepos)
allPlugins, pluginHelp := ha.generateNormalPluginHelp(config, normalRevMap)
allExternalPlugins, externalPluginHelp := ha.generateExternalPluginHelp(config, externalRevMap)
// Load repo->plugins maps from config
repoPlugins := map[string][]string{
"": allPlugins,
}
for repo, plugins := range config.Plugins {
repoPlugins[repo] = plugins
}
repoExternalPlugins := map[string][]string{
"": allExternalPlugins,
}
for repo, exts := range config.ExternalPlugins {
for _, ext := range exts {
repoExternalPlugins[repo] = append(repoExternalPlugins[repo], ext.Name)
}
}
return &pluginhelp.Help{
AllRepos: allRepos(config, orgToRepos),
RepoPlugins: repoPlugins,
RepoExternalPlugins: repoExternalPlugins,
PluginHelp: pluginHelp,
ExternalPluginHelp: externalPluginHelp,
}
}
|
go
|
func (ha *HelpAgent) GeneratePluginHelp() *pluginhelp.Help {
config := ha.pa.Config()
orgToRepos := ha.oa.orgToReposMap(config)
normalRevMap, externalRevMap := reversePluginMaps(config, orgToRepos)
allPlugins, pluginHelp := ha.generateNormalPluginHelp(config, normalRevMap)
allExternalPlugins, externalPluginHelp := ha.generateExternalPluginHelp(config, externalRevMap)
// Load repo->plugins maps from config
repoPlugins := map[string][]string{
"": allPlugins,
}
for repo, plugins := range config.Plugins {
repoPlugins[repo] = plugins
}
repoExternalPlugins := map[string][]string{
"": allExternalPlugins,
}
for repo, exts := range config.ExternalPlugins {
for _, ext := range exts {
repoExternalPlugins[repo] = append(repoExternalPlugins[repo], ext.Name)
}
}
return &pluginhelp.Help{
AllRepos: allRepos(config, orgToRepos),
RepoPlugins: repoPlugins,
RepoExternalPlugins: repoExternalPlugins,
PluginHelp: pluginHelp,
ExternalPluginHelp: externalPluginHelp,
}
}
|
[
"func",
"(",
"ha",
"*",
"HelpAgent",
")",
"GeneratePluginHelp",
"(",
")",
"*",
"pluginhelp",
".",
"Help",
"{",
"config",
":=",
"ha",
".",
"pa",
".",
"Config",
"(",
")",
"\n",
"orgToRepos",
":=",
"ha",
".",
"oa",
".",
"orgToReposMap",
"(",
"config",
")",
"\n",
"normalRevMap",
",",
"externalRevMap",
":=",
"reversePluginMaps",
"(",
"config",
",",
"orgToRepos",
")",
"\n",
"allPlugins",
",",
"pluginHelp",
":=",
"ha",
".",
"generateNormalPluginHelp",
"(",
"config",
",",
"normalRevMap",
")",
"\n",
"allExternalPlugins",
",",
"externalPluginHelp",
":=",
"ha",
".",
"generateExternalPluginHelp",
"(",
"config",
",",
"externalRevMap",
")",
"\n",
"repoPlugins",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"\"\"",
":",
"allPlugins",
",",
"}",
"\n",
"for",
"repo",
",",
"plugins",
":=",
"range",
"config",
".",
"Plugins",
"{",
"repoPlugins",
"[",
"repo",
"]",
"=",
"plugins",
"\n",
"}",
"\n",
"repoExternalPlugins",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"\"\"",
":",
"allExternalPlugins",
",",
"}",
"\n",
"for",
"repo",
",",
"exts",
":=",
"range",
"config",
".",
"ExternalPlugins",
"{",
"for",
"_",
",",
"ext",
":=",
"range",
"exts",
"{",
"repoExternalPlugins",
"[",
"repo",
"]",
"=",
"append",
"(",
"repoExternalPlugins",
"[",
"repo",
"]",
",",
"ext",
".",
"Name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"&",
"pluginhelp",
".",
"Help",
"{",
"AllRepos",
":",
"allRepos",
"(",
"config",
",",
"orgToRepos",
")",
",",
"RepoPlugins",
":",
"repoPlugins",
",",
"RepoExternalPlugins",
":",
"repoExternalPlugins",
",",
"PluginHelp",
":",
"pluginHelp",
",",
"ExternalPluginHelp",
":",
"externalPluginHelp",
",",
"}",
"\n",
"}"
] |
// GeneratePluginHelp compiles and returns the help information for all plugins.
|
[
"GeneratePluginHelp",
"compiles",
"and",
"returns",
"the",
"help",
"information",
"for",
"all",
"plugins",
"."
] |
8125fbda10178887be5dff9e901d6a0a519b67bc
|
https://github.com/kubernetes/test-infra/blob/8125fbda10178887be5dff9e901d6a0a519b67bc/prow/pluginhelp/hook/hook.go#L145-L178
|
test
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.