Initial commit

This commit is contained in:
Donny
2019-04-22 20:46:32 +08:00
commit 49ab8aadd1
25441 changed files with 4055000 additions and 0 deletions

39
vendor/k8s.io/test-infra/prow/kube/BUILD.bazel generated vendored Normal file
View File

@@ -0,0 +1,39 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"client.go",
"metrics.go",
"prowjob.go",
"types.go",
],
importpath = "k8s.io/test-infra/prow/kube",
deps = [
"//vendor/github.com/ghodss/yaml:go_default_library",
"//vendor/github.com/prometheus/client_golang/prometheus:go_default_library",
"//vendor/github.com/sirupsen/logrus:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/test-infra/prow/apis/prowjobs/v1:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)

684
vendor/k8s.io/test-infra/prow/kube/client.go generated vendored Normal file
View File

@@ -0,0 +1,684 @@
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kube
import (
"bytes"
"crypto/tls"
"crypto/x509"
"encoding/base64"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
"strconv"
"strings"
"time"
"github.com/ghodss/yaml"
"github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
)
var InClusterBaseURL string
func init() {
flag.StringVar(&InClusterBaseURL, "in-cluster-base-url", "https://kubernetes.default", "the base url to request k8s apiserver in cluster")
}
const (
// TestContainerName specifies the primary container name.
TestContainerName = "test"
https = "https"
maxRetries = 8
retryDelay = 2 * time.Second
requestTimeout = time.Minute
// EmptySelector selects everything
EmptySelector = ""
// DefaultClusterAlias specifies the default cluster key to schedule jobs.
DefaultClusterAlias = "default"
)
// newClient is used to allow mocking out the behavior of 'NewClient' while testing.
var newClient = NewClient
// Logger can print debug messages
type Logger interface {
Debugf(s string, v ...interface{})
}
// Client interacts with the Kubernetes api-server.
type Client struct {
// If logger is non-nil, log all method calls with it.
logger Logger
baseURL string
deckURL string
client *http.Client
token string
namespace string
fake bool
hiddenReposProvider func() []string
hiddenOnly bool
}
// SetHiddenReposProvider takes a continuation that fetches a list of orgs and repos for
// which PJs should not be returned.
// NOTE: This function is not thread safe and should be called before the client is in use.
func (c *Client) SetHiddenReposProvider(p func() []string, hiddenOnly bool) {
c.hiddenReposProvider = p
c.hiddenOnly = hiddenOnly
}
// Namespace returns a copy of the client pointing at the specified namespace.
func (c *Client) Namespace(ns string) *Client {
nc := *c
nc.namespace = ns
return &nc
}
func (c *Client) log(methodName string, args ...interface{}) {
if c.logger == nil {
return
}
var as []string
for _, arg := range args {
as = append(as, fmt.Sprintf("%v", arg))
}
c.logger.Debugf("%s(%s)", methodName, strings.Join(as, ", "))
}
// ConflictError is http 409.
type ConflictError struct {
e error
}
func (e ConflictError) Error() string {
return e.e.Error()
}
// NewConflictError returns an error with the embedded inner error
func NewConflictError(e error) ConflictError {
return ConflictError{e: e}
}
// UnprocessableEntityError happens when the apiserver returns http 422.
type UnprocessableEntityError struct {
e error
}
func (e UnprocessableEntityError) Error() string {
return e.e.Error()
}
// NewUnprocessableEntityError returns an error with the embedded inner error
func NewUnprocessableEntityError(e error) UnprocessableEntityError {
return UnprocessableEntityError{e: e}
}
// NotFoundError happens when the apiserver returns http 404
type NotFoundError struct {
e error
}
func (e NotFoundError) Error() string {
return e.e.Error()
}
// NewNotFoundError returns an error with the embedded inner error
func NewNotFoundError(e error) NotFoundError {
return NotFoundError{e: e}
}
type request struct {
method string
path string
deckPath string
query map[string]string
requestBody interface{}
}
func (c *Client) request(r *request, ret interface{}) error {
out, err := c.requestRetry(r)
if err != nil {
return err
}
if ret != nil {
if err := json.Unmarshal(out, ret); err != nil {
return err
}
}
return nil
}
func (c *Client) retry(r *request) (*http.Response, error) {
var resp *http.Response
var err error
backoff := retryDelay
for retries := 0; retries < maxRetries; retries++ {
resp, err = c.doRequest(r.method, r.deckPath, r.path, r.query, r.requestBody)
if err == nil {
if resp.StatusCode < 500 {
break
}
resp.Body.Close()
}
time.Sleep(backoff)
backoff *= 2
}
return resp, err
}
// Retry on transport failures. Does not retry on 500s.
func (c *Client) requestRetryStream(r *request) (io.ReadCloser, error) {
if c.fake && r.deckPath == "" {
return nil, nil
}
resp, err := c.retry(r)
if err != nil {
return nil, err
}
if resp.StatusCode == 409 {
return nil, NewConflictError(fmt.Errorf("body cannot be streamed"))
} else if resp.StatusCode < 200 || resp.StatusCode > 299 {
return nil, fmt.Errorf("response has status \"%s\"", resp.Status)
}
return resp.Body, nil
}
// Retry on transport failures. Does not retry on 500s.
func (c *Client) requestRetry(r *request) ([]byte, error) {
if c.fake && r.deckPath == "" {
return []byte("{}"), nil
}
resp, err := c.retry(r)
if err != nil {
return nil, err
}
defer resp.Body.Close()
rb, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode == 409 {
return nil, NewConflictError(fmt.Errorf("body: %s", string(rb)))
} else if resp.StatusCode == 422 {
return nil, NewUnprocessableEntityError(fmt.Errorf("body: %s", string(rb)))
} else if resp.StatusCode == 404 {
return nil, NewNotFoundError(fmt.Errorf("body: %s", string(rb)))
} else if resp.StatusCode < 200 || resp.StatusCode > 299 {
return nil, fmt.Errorf("response has status \"%s\" and body \"%s\"", resp.Status, string(rb))
}
return rb, nil
}
func (c *Client) doRequest(method, deckPath, urlPath string, query map[string]string, body interface{}) (*http.Response, error) {
url := c.baseURL + urlPath
if c.deckURL != "" && deckPath != "" {
url = c.deckURL + deckPath
}
var buf io.Reader
if body != nil {
b, err := json.Marshal(body)
if err != nil {
return nil, err
}
buf = bytes.NewBuffer(b)
}
req, err := http.NewRequest(method, url, buf)
if err != nil {
return nil, err
}
if c.token != "" {
req.Header.Set("Authorization", "Bearer "+c.token)
}
if method == http.MethodPatch {
req.Header.Set("Content-Type", "application/strategic-merge-patch+json")
} else {
req.Header.Set("Content-Type", "application/json")
}
q := req.URL.Query()
for k, v := range query {
q.Add(k, v)
}
req.URL.RawQuery = q.Encode()
return c.client.Do(req)
}
// NewFakeClient creates a client that doesn't do anything. If you provide a
// deck URL then the client will hit that for the supported calls.
func NewFakeClient(deckURL string) *Client {
return &Client{
namespace: "default",
deckURL: deckURL,
client: &http.Client{},
fake: true,
}
}
// NewClientInCluster creates a Client that works from within a pod.
func NewClientInCluster(namespace string) (*Client, error) {
tokenFile := "/var/run/secrets/kubernetes.io/serviceaccount/token"
token, err := ioutil.ReadFile(tokenFile)
if err != nil {
return nil, err
}
client := &http.Client{Timeout: requestTimeout}
if strings.HasPrefix(InClusterBaseURL, https) {
rootCAFile := "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
certData, err := ioutil.ReadFile(rootCAFile)
if err != nil {
return nil, err
}
cp := x509.NewCertPool()
cp.AppendCertsFromPEM(certData)
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
RootCAs: cp,
},
}
}
return &Client{
logger: logrus.WithField("client", "kube"),
baseURL: InClusterBaseURL,
client: client,
token: string(token),
namespace: namespace,
}, nil
}
// Cluster represents the information necessary to talk to a Kubernetes
// master endpoint.
// NOTE: if your cluster runs on GKE you can use the following command to get these credentials:
// gcloud --project <gcp_project> container clusters describe --zone <zone> <cluster_name>
type Cluster struct {
// The IP address of the cluster's master endpoint.
Endpoint string `json:"endpoint"`
// Base64-encoded public cert used by clients to authenticate to the
// cluster endpoint.
ClientCertificate string `json:"clientCertificate"`
// Base64-encoded private key used by clients..
ClientKey string `json:"clientKey"`
// Base64-encoded public certificate that is the root of trust for the
// cluster.
ClusterCACertificate string `json:"clusterCaCertificate"`
}
// NewClientFromFile reads a Cluster object at clusterPath and returns an
// authenticated client using the keys within.
func NewClientFromFile(clusterPath, namespace string) (*Client, error) {
data, err := ioutil.ReadFile(clusterPath)
if err != nil {
return nil, err
}
var c Cluster
if err := yaml.Unmarshal(data, &c); err != nil {
return nil, err
}
return NewClient(&c, namespace)
}
// UnmarshalClusterMap reads a map[string]Cluster in yaml bytes.
func UnmarshalClusterMap(data []byte) (map[string]Cluster, error) {
var raw map[string]Cluster
if err := yaml.Unmarshal(data, &raw); err != nil {
// If we failed to unmarshal the multicluster format try the single Cluster format.
var singleConfig Cluster
if err := yaml.Unmarshal(data, &singleConfig); err != nil {
return nil, err
}
raw = map[string]Cluster{DefaultClusterAlias: singleConfig}
}
return raw, nil
}
// MarshalClusterMap writes c as yaml bytes.
func MarshalClusterMap(c map[string]Cluster) ([]byte, error) {
return yaml.Marshal(c)
}
// ClientMapFromFile reads the file at clustersPath and attempts to load a map of cluster aliases
// to authenticated clients to the respective clusters.
// The file at clustersPath is expected to be a yaml map from strings to Cluster structs OR it may
// simply be a single Cluster struct which will be assigned the alias $DefaultClusterAlias.
// If the file is an alias map, it must include the alias $DefaultClusterAlias.
func ClientMapFromFile(clustersPath, namespace string) (map[string]*Client, error) {
data, err := ioutil.ReadFile(clustersPath)
if err != nil {
return nil, fmt.Errorf("read error: %v", err)
}
raw, err := UnmarshalClusterMap(data)
if err != nil {
return nil, fmt.Errorf("unmarshal error: %v", err)
}
foundDefault := false
result := map[string]*Client{}
for alias, config := range raw {
client, err := newClient(&config, namespace)
if err != nil {
return nil, fmt.Errorf("failed to load config for build cluster alias %q in file %q: %v", alias, clustersPath, err)
}
result[alias] = client
if alias == DefaultClusterAlias {
foundDefault = true
}
}
if !foundDefault {
return nil, fmt.Errorf("failed to find the required %q alias in build cluster config %q", DefaultClusterAlias, clustersPath)
}
return result, nil
}
// NewClient returns an authenticated Client using the keys in the Cluster.
func NewClient(c *Cluster, namespace string) (*Client, error) {
cc, err := base64.StdEncoding.DecodeString(c.ClientCertificate)
if err != nil {
return nil, err
}
ck, err := base64.StdEncoding.DecodeString(c.ClientKey)
if err != nil {
return nil, err
}
ca, err := base64.StdEncoding.DecodeString(c.ClusterCACertificate)
if err != nil {
return nil, err
}
cert, err := tls.X509KeyPair(cc, ck)
if err != nil {
return nil, err
}
cp := x509.NewCertPool()
cp.AppendCertsFromPEM(ca)
tr := &http.Transport{
TLSClientConfig: &tls.Config{
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{cert},
RootCAs: cp,
},
}
return &Client{
logger: logrus.WithField("client", "kube"),
baseURL: c.Endpoint,
client: &http.Client{Transport: tr, Timeout: requestTimeout},
namespace: namespace,
}, nil
}
// GetPod is analogous to kubectl get pods/NAME namespace=client.namespace
func (c *Client) GetPod(name string) (Pod, error) {
c.log("GetPod", name)
var retPod Pod
err := c.request(&request{
path: fmt.Sprintf("/api/v1/namespaces/%s/pods/%s", c.namespace, name),
}, &retPod)
return retPod, err
}
// ListPods is analogous to kubectl get pods --selector=SELECTOR --namespace=client.namespace
func (c *Client) ListPods(selector string) ([]Pod, error) {
c.log("ListPods", selector)
var pl struct {
Items []Pod `json:"items"`
}
err := c.request(&request{
path: fmt.Sprintf("/api/v1/namespaces/%s/pods", c.namespace),
query: map[string]string{"labelSelector": selector},
}, &pl)
return pl.Items, err
}
// DeletePod deletes the pod at name in the client's default namespace.
//
// Analogous to kubectl delete pod
func (c *Client) DeletePod(name string) error {
c.log("DeletePod", name)
return c.request(&request{
method: http.MethodDelete,
path: fmt.Sprintf("/api/v1/namespaces/%s/pods/%s", c.namespace, name),
}, nil)
}
// CreateProwJob creates a prowjob in the client's default namespace.
//
// Analogous to kubectl create prowjob
func (c *Client) CreateProwJob(j ProwJob) (ProwJob, error) {
var representation string
if out, err := json.Marshal(j); err == nil {
representation = string(out[:])
} else {
representation = fmt.Sprintf("%v", j)
}
c.log("CreateProwJob", representation)
var retJob ProwJob
err := c.request(&request{
method: http.MethodPost,
path: fmt.Sprintf("/apis/prow.k8s.io/v1/namespaces/%s/prowjobs", c.namespace),
requestBody: &j,
}, &retJob)
return retJob, err
}
func (c *Client) getHiddenRepos() sets.String {
if c.hiddenReposProvider == nil {
return nil
}
return sets.NewString(c.hiddenReposProvider()...)
}
func shouldHide(pj *ProwJob, hiddenRepos sets.String, showHiddenOnly bool) bool {
if pj.Spec.Refs == nil {
// periodic jobs do not have refs and therefore cannot be
// hidden by the org/repo mechanism
return false
}
shouldHide := hiddenRepos.HasAny(fmt.Sprintf("%s/%s", pj.Spec.Refs.Org, pj.Spec.Refs.Repo), pj.Spec.Refs.Org)
if showHiddenOnly {
return !shouldHide
}
return shouldHide
}
// GetProwJob returns the prowjob at name in the client's default namespace.
//
// Analogous to kubectl get prowjob/NAME
func (c *Client) GetProwJob(name string) (ProwJob, error) {
c.log("GetProwJob", name)
var pj ProwJob
err := c.request(&request{
path: fmt.Sprintf("/apis/prow.k8s.io/v1/namespaces/%s/prowjobs/%s", c.namespace, name),
}, &pj)
if err == nil && shouldHide(&pj, c.getHiddenRepos(), c.hiddenOnly) {
pj = ProwJob{}
// Revealing the existence of this prow job is ok because the pj name cannot be used to
// retrieve the pj itself. Furthermore, a timing attack could differentiate true 404s from
// 404s returned when a hidden pj is queried so returning a 404 wouldn't hide the pj's existence.
err = errors.New("403 ProwJob is hidden")
}
return pj, err
}
// ListProwJobs lists prowjobs using the specified labelSelector in the client's default namespace.
//
// Analogous to kubectl get prowjobs --selector=SELECTOR
func (c *Client) ListProwJobs(selector string) ([]ProwJob, error) {
c.log("ListProwJobs", selector)
var jl struct {
Items []ProwJob `json:"items"`
}
err := c.request(&request{
path: fmt.Sprintf("/apis/prow.k8s.io/v1/namespaces/%s/prowjobs", c.namespace),
deckPath: "/prowjobs.js",
query: map[string]string{"labelSelector": selector},
}, &jl)
if err == nil {
hidden := c.getHiddenRepos()
var pjs []ProwJob
for _, pj := range jl.Items {
if !shouldHide(&pj, hidden, c.hiddenOnly) {
pjs = append(pjs, pj)
}
}
jl.Items = pjs
}
return jl.Items, err
}
// DeleteProwJob deletes the prowjob at name in the client's default namespace.
func (c *Client) DeleteProwJob(name string) error {
c.log("DeleteProwJob", name)
return c.request(&request{
method: http.MethodDelete,
path: fmt.Sprintf("/apis/prow.k8s.io/v1/namespaces/%s/prowjobs/%s", c.namespace, name),
}, nil)
}
// ReplaceProwJob will replace name with job in the client's default namespace.
//
// Analogous to kubectl replace prowjobs/NAME
func (c *Client) ReplaceProwJob(name string, job ProwJob) (ProwJob, error) {
c.log("ReplaceProwJob", name, job)
var retJob ProwJob
err := c.request(&request{
method: http.MethodPut,
path: fmt.Sprintf("/apis/prow.k8s.io/v1/namespaces/%s/prowjobs/%s", c.namespace, name),
requestBody: &job,
}, &retJob)
return retJob, err
}
// CreatePod creates a pod in the client's default namespace.
//
// Analogous to kubectl create pod
func (c *Client) CreatePod(p v1.Pod) (Pod, error) {
c.log("CreatePod", p)
var retPod Pod
err := c.request(&request{
method: http.MethodPost,
path: fmt.Sprintf("/api/v1/namespaces/%s/pods", c.namespace),
requestBody: &p,
}, &retPod)
return retPod, err
}
// GetLog returns the log of the default container in the specified pod, in the client's default namespace.
//
// Analogous to kubectl logs pod
func (c *Client) GetLog(pod string) ([]byte, error) {
c.log("GetLog", pod)
return c.requestRetry(&request{
path: fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/log", c.namespace, pod),
})
}
// GetLogTail returns the last n bytes of the log of the specified container in the specified pod,
// in the client's default namespace.
//
// Analogous to kubectl logs pod --tail -1 --limit-bytes n -c container
func (c *Client) GetLogTail(pod, container string, n int64) ([]byte, error) {
c.log("GetLogTail", pod, n)
return c.requestRetry(&request{
path: fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/log", c.namespace, pod),
query: map[string]string{ // Because we want last n bytes, we fetch all lines and then limit to n bytes
"tailLines": "-1",
"container": container,
"limitBytes": strconv.FormatInt(n, 10),
},
})
}
// GetContainerLog returns the log of a container in the specified pod, in the client's default namespace.
//
// Analogous to kubectl logs pod -c container
func (c *Client) GetContainerLog(pod, container string) ([]byte, error) {
c.log("GetContainerLog", pod)
return c.requestRetry(&request{
path: fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/log", c.namespace, pod),
query: map[string]string{"container": container},
})
}
// CreateConfigMap creates a configmap.
//
// Analogous to kubectl create configmap
func (c *Client) CreateConfigMap(content ConfigMap) (ConfigMap, error) {
c.log("CreateConfigMap")
var retConfigMap ConfigMap
err := c.request(&request{
method: http.MethodPost,
path: fmt.Sprintf("/api/v1/namespaces/%s/configmaps", c.namespace),
requestBody: &content,
}, &retConfigMap)
return retConfigMap, err
}
// GetConfigMap gets the configmap identified.
func (c *Client) GetConfigMap(name, namespace string) (ConfigMap, error) {
c.log("GetConfigMap", name)
if namespace == "" {
namespace = c.namespace
}
var retConfigMap ConfigMap
err := c.request(&request{
path: fmt.Sprintf("/api/v1/namespaces/%s/configmaps/%s", namespace, name),
}, &retConfigMap)
return retConfigMap, err
}
// ReplaceConfigMap puts the configmap into name.
//
// Analogous to kubectl replace configmap
//
// If config.Namespace is empty, the client's default namespace is used.
// Returns the content returned by the apiserver
func (c *Client) ReplaceConfigMap(name string, config ConfigMap) (ConfigMap, error) {
c.log("ReplaceConfigMap", name)
namespace := c.namespace
if config.Namespace != "" {
namespace = config.Namespace
}
var retConfigMap ConfigMap
err := c.request(&request{
method: http.MethodPut,
path: fmt.Sprintf("/api/v1/namespaces/%s/configmaps/%s", namespace, name),
requestBody: &config,
}, &retConfigMap)
return retConfigMap, err
}

67
vendor/k8s.io/test-infra/prow/kube/metrics.go generated vendored Normal file
View File

@@ -0,0 +1,67 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kube
import (
"github.com/prometheus/client_golang/prometheus"
)
var (
prowJobs = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "prowjobs",
Help: "Number of prowjobs in the system",
}, []string{
// name of the job
"job_name",
// type of the prowjob: presubmit, postsubmit, periodic, batch
"type",
// state of the prowjob: triggered, pending, success, failure, aborted, error
"state",
})
)
func init() {
prometheus.MustRegister(prowJobs)
}
// GatherProwJobMetrics gathers prometheus metrics for prowjobs.
func GatherProwJobMetrics(pjs []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)
}
}
}
}

143
vendor/k8s.io/test-infra/prow/kube/prowjob.go generated vendored Normal file
View File

@@ -0,0 +1,143 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kube
import (
"k8s.io/test-infra/prow/apis/prowjobs/v1"
)
// The following are aliases to aid in the refactoring while we move
// API definitions under prow/apis/
// ProwJobType specifies how the job is triggered.
type ProwJobType = v1.ProwJobType
// ProwJobState specifies whether the job is running
type ProwJobState = v1.ProwJobState
// ProwJobAgent specifies the controller (such as plank or jenkins-agent) that runs the job.
type ProwJobAgent = v1.ProwJobAgent
// Various job types.
const (
// PresubmitJob means it runs on unmerged PRs.
PresubmitJob = v1.PresubmitJob
// PostsubmitJob means it runs on each new commit.
PostsubmitJob = v1.PostsubmitJob
// Periodic job means it runs on a time-basis, unrelated to git changes.
PeriodicJob = v1.PeriodicJob
// BatchJob tests multiple unmerged PRs at the same time.
BatchJob = v1.BatchJob
)
// Various job states.
const (
// TriggeredState means the job has been created but not yet scheduled.
TriggeredState = v1.TriggeredState
// PendingState means the job is scheduled but not yet running.
PendingState = v1.PendingState
// SuccessState means the job completed without error (exit 0)
SuccessState = v1.SuccessState
// FailureState means the job completed with errors (exit non-zero)
FailureState = v1.FailureState
// AbortedState means prow killed the job early (new commit pushed, perhaps).
AbortedState = v1.AbortedState
// ErrorState means the job could not schedule (bad config, perhaps).
ErrorState = v1.ErrorState
)
const (
// KubernetesAgent means prow will create a pod to run this job.
KubernetesAgent = v1.KubernetesAgent
// JenkinsAgent means prow will schedule the job on jenkins.
JenkinsAgent = v1.JenkinsAgent
)
const (
// CreatedByProw is added on pods created by prow. We cannot
// really use owner references because pods may reside on a
// different namespace from the namespace parent prowjobs
// live and that would cause the k8s garbage collector to
// identify those prow pods as orphans and delete them
// instantly.
// TODO: Namespace this label.
CreatedByProw = "created-by-prow"
// ProwJobTypeLabel is added in pods created by prow and
// carries the job type (presubmit, postsubmit, periodic, batch)
// that the pod is running.
ProwJobTypeLabel = "prow.k8s.io/type"
// ProwJobIDLabel is added in pods created by prow and
// carries the ID of the ProwJob that the pod is fulfilling.
// We also name pods after the ProwJob that spawned them but
// this allows for multiple resources to be linked to one
// ProwJob.
ProwJobIDLabel = "prow.k8s.io/id"
// ProwJobAnnotation is added in pods created by prow and
// carries the name of the job that the pod is running. Since
// job names can be arbitrarily long, this is added as
// an annotation instead of a label.
ProwJobAnnotation = "prow.k8s.io/job"
// OrgLabel is added in resources created by prow and
// carries the org associated with the job, eg kubernetes-sigs.
OrgLabel = "prow.k8s.io/refs.org"
// RepoLabel is added in resources created by prow and
// carries the repo associated with the job, eg test-infra
RepoLabel = "prow.k8s.io/refs.repo"
// PullLabel is added in resources created by prow and
// carries the PR number associated with the job, eg 321.
PullLabel = "prow.k8s.io/refs.pull"
)
// ProwJob contains the spec as well as runtime metadata.
type ProwJob = v1.ProwJob
// ProwJobSpec configures the details of the prow job.
//
// Details include the podspec, code to clone, the cluster it runs
// any child jobs, concurrency limitations, etc.
type ProwJobSpec = v1.ProwJobSpec
// DecorationConfig specifies how to augment pods.
//
// This is primarily used to provide automatic integration with gubernator
// and testgrid.
type DecorationConfig = v1.DecorationConfig
// UtilityImages holds pull specs for the utility images
// to be used for a job
type UtilityImages = v1.UtilityImages
// PathStrategy specifies minutia about how to contruct the url.
// Usually consumed by gubernator/testgrid.
const (
PathStrategyLegacy = v1.PathStrategyLegacy
PathStrategySingle = v1.PathStrategySingle
PathStrategyExplicit = v1.PathStrategyExplicit
)
// GCSConfiguration holds options for pushing logs and
// artifacts to GCS from a job.
type GCSConfiguration = v1.GCSConfiguration
// ProwJobStatus provides runtime metadata, such as when it finished, whether it is running, etc.
type ProwJobStatus = v1.ProwJobStatus
// Pull describes a pull request at a particular point in time.
type Pull = v1.Pull
// Refs describes how the repo was constructed.
type Refs = v1.Refs

86
vendor/k8s.io/test-infra/prow/kube/types.go generated vendored Normal file
View File

@@ -0,0 +1,86 @@
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package kube
import (
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// TODO: Drop all of these, please!
// ObjectMeta is a kubernetes v1 ObjectMeta
type ObjectMeta = metav1.ObjectMeta
// Pod is a kubernetes v1 Pod
type Pod = v1.Pod
// PodTemplateSpec is a kubernetes v1 PodTemplateSpec
type PodTemplateSpec = v1.PodTemplateSpec
// PodSpec is a kubernetes v1 PodSpec
type PodSpec = v1.PodSpec
// PodStatus is a kubernetes v1 PodStatus
type PodStatus = v1.PodStatus
// Phase constants
const (
PodPending = v1.PodPending
PodRunning = v1.PodRunning
PodSucceeded = v1.PodSucceeded
PodFailed = v1.PodFailed
PodUnknown = v1.PodUnknown
)
// PodStatus constants
const (
Evicted = "Evicted"
)
// Container is a kubernetes v1 Container
type Container = v1.Container
// Port is a kubernetes v1 ContainerPort
type Port = v1.ContainerPort
// EnvVar is a kubernetes v1 EnvVar
type EnvVar = v1.EnvVar
// Volume is a kubernetes v1 Volume
type Volume = v1.Volume
// VolumeMount is a kubernetes v1 VolumeMount
type VolumeMount = v1.VolumeMount
// VolumeSource is a kubernetes v1 VolumeSource
type VolumeSource = v1.VolumeSource
// EmptyDirVolumeSource is a kubernetes v1 EmptyDirVolumeSource
type EmptyDirVolumeSource = v1.EmptyDirVolumeSource
// SecretSource is a kubernetes v1 SecretVolumeSource
type SecretSource = v1.SecretVolumeSource
// ConfigMapSource is a kubernetes v1 ConfigMapVolumeSource
type ConfigMapSource = v1.ConfigMapVolumeSource
// ConfigMap is a kubernetes v1 ConfigMap
type ConfigMap = v1.ConfigMap
// Secret is a kubernetes v1 secret
type Secret = v1.Secret