Fresh dep ensure

This commit is contained in:
Mike Cronce
2018-11-26 13:23:56 -05:00
parent 93cb8a04d7
commit 407478ab9a
9016 changed files with 551394 additions and 279685 deletions

View File

@ -8,6 +8,7 @@ load(
go_library(
name = "go_default_library",
srcs = [
"audit.go",
"conditions.go",
"create_resources.go",
"delete_resources.go",
@ -31,30 +32,32 @@ go_library(
"//pkg/controller/deployment/util:go_default_library",
"//pkg/kubectl:go_default_library",
"//pkg/util/labels:go_default_library",
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/batch/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/extensions/v1beta1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/apis/audit:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/audit:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/client-go/scale:go_default_library",
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
"//staging/src/k8s.io/client-go/util/workqueue:go_default_library",
"//vendor/github.com/davecgh/go-spew/spew:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/k8s.io/api/apps/v1:go_default_library",
"//vendor/k8s.io/api/batch/v1:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/extensions/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/fields:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/scale:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
"//vendor/k8s.io/client-go/util/workqueue:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
)
@ -69,6 +72,7 @@ filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//test/utils/harness:all-srcs",
"//test/utils/image:all-srcs",
"//test/utils/junit:all-srcs",
],

106
vendor/k8s.io/kubernetes/test/utils/audit.go generated vendored Normal file
View File

@ -0,0 +1,106 @@
/*
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 utils
import (
"bufio"
"fmt"
"io"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
auditinternal "k8s.io/apiserver/pkg/apis/audit"
"k8s.io/apiserver/pkg/audit"
)
type AuditEvent struct {
Level auditinternal.Level
Stage auditinternal.Stage
RequestURI string
Verb string
Code int32
User string
Resource string
Namespace string
RequestObject bool
ResponseObject bool
AuthorizeDecision string
}
// Search the audit log for the expected audit lines.
func CheckAuditLines(stream io.Reader, expected []AuditEvent, version schema.GroupVersion) (missing []AuditEvent, err error) {
expectations := map[AuditEvent]bool{}
for _, event := range expected {
expectations[event] = false
}
scanner := bufio.NewScanner(stream)
for scanner.Scan() {
line := scanner.Text()
event, err := parseAuditLine(line, version)
if err != nil {
return expected, err
}
// If the event was expected, mark it as found.
if _, found := expectations[event]; found {
expectations[event] = true
}
}
if err := scanner.Err(); err != nil {
return expected, err
}
missing = make([]AuditEvent, 0)
for event, found := range expectations {
if !found {
missing = append(missing, event)
}
}
return missing, nil
}
func parseAuditLine(line string, version schema.GroupVersion) (AuditEvent, error) {
e := &auditinternal.Event{}
decoder := audit.Codecs.UniversalDecoder(version)
if err := runtime.DecodeInto(decoder, []byte(line), e); err != nil {
return AuditEvent{}, fmt.Errorf("failed decoding buf: %s, apiVersion: %s", line, version)
}
event := AuditEvent{
Level: e.Level,
Stage: e.Stage,
RequestURI: e.RequestURI,
Verb: e.Verb,
User: e.User.Username,
}
if e.ObjectRef != nil {
event.Namespace = e.ObjectRef.Namespace
event.Resource = e.ObjectRef.Resource
}
if e.ResponseStatus != nil {
event.Code = e.ResponseStatus.Code
}
if e.ResponseObject != nil {
event.ResponseObject = true
}
if e.RequestObject != nil {
event.RequestObject = true
}
event.AuthorizeDecision = e.Annotations["authorization.k8s.io/decision"]
return event, nil
}

View File

@ -21,12 +21,12 @@ import (
"strings"
"time"
"github.com/golang/glog"
"k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/klog"
)
const (
@ -79,7 +79,7 @@ func RemoveLabelOffNode(c clientset.Interface, nodeName string, labelKeys []stri
if !apierrs.IsConflict(err) {
return err
} else {
glog.V(2).Infof("Conflict when trying to remove a labels %v from %v", labelKeys, nodeName)
klog.V(2).Infof("Conflict when trying to remove a labels %v from %v", labelKeys, nodeName)
}
} else {
break

23
vendor/k8s.io/kubernetes/test/utils/harness/BUILD generated vendored Normal file
View File

@ -0,0 +1,23 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["harness.go"],
importpath = "k8s.io/kubernetes/test/utils/harness",
visibility = ["//visibility:public"],
deps = ["//vendor/k8s.io/klog:go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

71
vendor/k8s.io/kubernetes/test/utils/harness/harness.go generated vendored Normal file
View File

@ -0,0 +1,71 @@
/*
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 harness
import (
"io/ioutil"
"os"
"testing"
"k8s.io/klog"
)
// Harness adds some functionality to testing.T, in particular resource cleanup.
// It embeds testing.T, so should have the same signature.
//
// Example usage:
// ```
// func MyTest(tt *testing.T) {
// t := harness.For(tt)
// defer t.Close()
// ...
// }
// ```
type Harness struct {
*testing.T
defers []func() error
}
// For creates a Harness from a testing.T
// Callers must call Close on the Harness so that resources can be cleaned up
func For(t *testing.T) *Harness {
h := &Harness{T: t}
return h
}
// Close cleans up any owned resources, and should be called in a defer block after For
func (h *Harness) Close() {
for _, d := range h.defers {
if err := d(); err != nil {
klog.Warningf("error closing harness: %v", err)
}
}
}
// TempDir is a wrapper around ioutil.TempDir for tests.
// It automatically fails the test if we can't create a temp file,
// and deletes the temp directory when Close is called on the Harness
func (h *Harness) TempDir(baseDir string, prefix string) string {
tempDir, err := ioutil.TempDir(baseDir, prefix)
if err != nil {
h.Fatalf("unable to create tempdir: %v", err)
}
h.defers = append(h.defers, func() error {
return os.RemoveAll(tempDir)
})
return tempDir
}

View File

@ -9,6 +9,9 @@ go_library(
name = "go_default_library",
srcs = ["manifest.go"],
importpath = "k8s.io/kubernetes/test/utils/image",
deps = [
"//vendor/gopkg.in/yaml.v2:go_default_library",
],
)
filegroup(

View File

@ -18,98 +18,129 @@ package image
import (
"fmt"
"runtime"
"io/ioutil"
"os"
yaml "gopkg.in/yaml.v2"
)
const (
e2eRegistry = "gcr.io/kubernetes-e2e-test-images"
gcRegistry = "k8s.gcr.io"
PrivateRegistry = "gcr.io/k8s-authenticated-test"
sampleRegistry = "gcr.io/google-samples"
)
// RegistryList holds public and private image registries
type RegistryList struct {
DockerLibraryRegistry string `yaml:"dockerLibraryRegistry"`
E2eRegistry string `yaml:"e2eRegistry"`
GcRegistry string `yaml:"gcRegistry"`
PrivateRegistry string `yaml:"privateRegistry"`
SampleRegistry string `yaml:"sampleRegistry"`
}
type ImageConfig struct {
// Config holds an images registry, name, and version
type Config struct {
registry string
name string
version string
hasArch bool
}
func (i *ImageConfig) SetRegistry(registry string) {
// SetRegistry sets an image registry in a Config struct
func (i *Config) SetRegistry(registry string) {
i.registry = registry
}
func (i *ImageConfig) SetName(name string) {
// SetName sets an image name in a Config struct
func (i *Config) SetName(name string) {
i.name = name
}
func (i *ImageConfig) SetVersion(version string) {
// SetVersion sets an image version in a Config struct
func (i *Config) SetVersion(version string) {
i.version = version
}
var (
AdmissionWebhook = ImageConfig{e2eRegistry, "k8s-sample-admission-webhook", "1.10v2", true}
APIServer = ImageConfig{e2eRegistry, "k8s-aggregator-sample-apiserver", "1.7v2", true}
AppArmorLoader = ImageConfig{gcRegistry, "apparmor-loader", "0.1", false}
BusyBox = ImageConfig{gcRegistry, "busybox", "1.24", false}
CheckMetadataConcealment = ImageConfig{gcRegistry, "check-metadata-concealment", "v0.0.3", false}
ClusterTester = ImageConfig{e2eRegistry, "clusterapi-tester", "1.0", true}
CudaVectorAdd = ImageConfig{e2eRegistry, "cuda-vector-add", "1.0", true}
Dnsutils = ImageConfig{e2eRegistry, "dnsutils", "1.0", true}
DNSMasq = ImageConfig{gcRegistry, "k8s-dns-dnsmasq", "1.14.5", true}
EchoServer = ImageConfig{gcRegistry, "echoserver", "1.10", false}
EntrypointTester = ImageConfig{e2eRegistry, "entrypoint-tester", "1.0", true}
E2ENet = ImageConfig{gcRegistry, "e2e-net", "1.0", true}
Fakegitserver = ImageConfig{e2eRegistry, "fakegitserver", "1.0", true}
GBFrontend = ImageConfig{sampleRegistry, "gb-frontend", "v5", true}
GBRedisSlave = ImageConfig{sampleRegistry, "gb-redisslave", "v2", true}
Goproxy = ImageConfig{e2eRegistry, "goproxy", "1.0", true}
Hostexec = ImageConfig{e2eRegistry, "hostexec", "1.1", true}
IpcUtils = ImageConfig{e2eRegistry, "ipc-utils", "1.0", true}
Iperf = ImageConfig{e2eRegistry, "iperf", "1.0", true}
JessieDnsutils = ImageConfig{e2eRegistry, "jessie-dnsutils", "1.0", true}
Kitten = ImageConfig{e2eRegistry, "kitten", "1.0", true}
Liveness = ImageConfig{e2eRegistry, "liveness", "1.0", true}
LogsGenerator = ImageConfig{e2eRegistry, "logs-generator", "1.0", true}
Mounttest = ImageConfig{e2eRegistry, "mounttest", "1.0", true}
MounttestUser = ImageConfig{e2eRegistry, "mounttest-user", "1.0", true}
Nautilus = ImageConfig{e2eRegistry, "nautilus", "1.0", true}
Net = ImageConfig{e2eRegistry, "net", "1.0", true}
Netexec = ImageConfig{e2eRegistry, "netexec", "1.0", true}
Nettest = ImageConfig{e2eRegistry, "nettest", "1.0", true}
NginxSlim = ImageConfig{gcRegistry, "nginx-slim", "0.20", true}
NginxSlimNew = ImageConfig{gcRegistry, "nginx-slim", "0.21", true}
Nonewprivs = ImageConfig{e2eRegistry, "nonewprivs", "1.0", true}
NoSnatTest = ImageConfig{e2eRegistry, "no-snat-test", "1.0", true}
NoSnatTestProxy = ImageConfig{e2eRegistry, "no-snat-test-proxy", "1.0", true}
NWayHTTP = ImageConfig{e2eRegistry, "n-way-http", "1.0", true}
// When these values are updated, also update cmd/kubelet/app/options/container_runtime.go
Pause = ImageConfig{gcRegistry, "pause", "3.1", false}
Porter = ImageConfig{e2eRegistry, "porter", "1.0", true}
PortForwardTester = ImageConfig{e2eRegistry, "port-forward-tester", "1.0", true}
Redis = ImageConfig{e2eRegistry, "redis", "1.0", true}
ResourceConsumer = ImageConfig{e2eRegistry, "resource-consumer", "1.3", true}
ResourceController = ImageConfig{e2eRegistry, "resource-consumer/controller", "1.0", true}
SDDummyExporter = ImageConfig{gcRegistry, "sd-dummy-exporter", "v0.1.0", false}
ServeHostname = ImageConfig{e2eRegistry, "serve-hostname", "1.0", true}
TestWebserver = ImageConfig{e2eRegistry, "test-webserver", "1.0", true}
VolumeNFSServer = ImageConfig{e2eRegistry, "volume-nfs", "0.8", false}
VolumeISCSIServer = ImageConfig{e2eRegistry, "volume-iscsi", "0.2", false}
VolumeGlusterServer = ImageConfig{e2eRegistry, "volume-gluster", "0.5", false}
VolumeRBDServer = ImageConfig{e2eRegistry, "volume-rbd", "0.2", false}
)
func initReg() RegistryList {
registry := RegistryList{
DockerLibraryRegistry: "docker.io/library",
E2eRegistry: "gcr.io/kubernetes-e2e-test-images",
GcRegistry: "k8s.gcr.io",
PrivateRegistry: "gcr.io/k8s-authenticated-test",
SampleRegistry: "gcr.io/google-samples",
}
repoList := os.Getenv("KUBE_TEST_REPO_LIST")
if repoList == "" {
return registry
}
func GetE2EImage(image ImageConfig) string {
return GetE2EImageWithArch(image, runtime.GOARCH)
fileContent, err := ioutil.ReadFile(repoList)
if err != nil {
panic(fmt.Errorf("Error reading '%v' file contents: %v", repoList, err))
}
err = yaml.Unmarshal(fileContent, &registry)
if err != nil {
panic(fmt.Errorf("Error unmarshalling '%v' YAML file: %v", repoList, err))
}
return registry
}
func GetE2EImageWithArch(image ImageConfig, arch string) string {
if image.hasArch {
return fmt.Sprintf("%s/%s-%s:%s", image.registry, image.name, arch, image.version)
} else {
return fmt.Sprintf("%s/%s:%s", image.registry, image.name, image.version)
var (
registry = initReg()
dockerLibraryRegistry = registry.DockerLibraryRegistry
e2eRegistry = registry.E2eRegistry
gcRegistry = registry.GcRegistry
// PrivateRegistry is an image repository that requires authentication
PrivateRegistry = registry.PrivateRegistry
sampleRegistry = registry.SampleRegistry
)
}
// Preconfigured image configs
var (
CRDConversionWebhook = Config{e2eRegistry, "crd-conversion-webhook", "1.13rev2"}
AdmissionWebhook = Config{e2eRegistry, "webhook", "1.13v1"}
APIServer = Config{e2eRegistry, "sample-apiserver", "1.10"}
AppArmorLoader = Config{e2eRegistry, "apparmor-loader", "1.0"}
BusyBox = Config{dockerLibraryRegistry, "busybox", "1.29"}
CheckMetadataConcealment = Config{e2eRegistry, "metadata-concealment", "1.1.1"}
CudaVectorAdd = Config{e2eRegistry, "cuda-vector-add", "1.0"}
Dnsutils = Config{e2eRegistry, "dnsutils", "1.1"}
EchoServer = Config{e2eRegistry, "echoserver", "2.2"}
EntrypointTester = Config{e2eRegistry, "entrypoint-tester", "1.0"}
Fakegitserver = Config{e2eRegistry, "fakegitserver", "1.0"}
GBFrontend = Config{sampleRegistry, "gb-frontend", "v6"}
GBRedisSlave = Config{sampleRegistry, "gb-redisslave", "v3"}
Hostexec = Config{e2eRegistry, "hostexec", "1.1"}
IpcUtils = Config{e2eRegistry, "ipc-utils", "1.0"}
Iperf = Config{e2eRegistry, "iperf", "1.0"}
JessieDnsutils = Config{e2eRegistry, "jessie-dnsutils", "1.0"}
Kitten = Config{e2eRegistry, "kitten", "1.0"}
Liveness = Config{e2eRegistry, "liveness", "1.0"}
LogsGenerator = Config{e2eRegistry, "logs-generator", "1.0"}
Mounttest = Config{e2eRegistry, "mounttest", "1.0"}
MounttestUser = Config{e2eRegistry, "mounttest-user", "1.0"}
Nautilus = Config{e2eRegistry, "nautilus", "1.0"}
Net = Config{e2eRegistry, "net", "1.0"}
Netexec = Config{e2eRegistry, "netexec", "1.1"}
Nettest = Config{e2eRegistry, "nettest", "1.0"}
Nginx = Config{dockerLibraryRegistry, "nginx", "1.14-alpine"}
NginxNew = Config{dockerLibraryRegistry, "nginx", "1.15-alpine"}
Nonewprivs = Config{e2eRegistry, "nonewprivs", "1.0"}
NoSnatTest = Config{e2eRegistry, "no-snat-test", "1.0"}
NoSnatTestProxy = Config{e2eRegistry, "no-snat-test-proxy", "1.0"}
// Pause - when these values are updated, also update cmd/kubelet/app/options/container_runtime.go
Pause = Config{gcRegistry, "pause", "3.1"}
Porter = Config{e2eRegistry, "porter", "1.0"}
PortForwardTester = Config{e2eRegistry, "port-forward-tester", "1.0"}
Redis = Config{e2eRegistry, "redis", "1.0"}
ResourceConsumer = Config{e2eRegistry, "resource-consumer", "1.4"}
ResourceController = Config{e2eRegistry, "resource-consumer/controller", "1.0"}
ServeHostname = Config{e2eRegistry, "serve-hostname", "1.1"}
TestWebserver = Config{e2eRegistry, "test-webserver", "1.0"}
VolumeNFSServer = Config{e2eRegistry, "volume/nfs", "1.0"}
VolumeISCSIServer = Config{e2eRegistry, "volume/iscsi", "1.0"}
VolumeGlusterServer = Config{e2eRegistry, "volume/gluster", "1.0"}
VolumeRBDServer = Config{e2eRegistry, "volume/rbd", "1.0.1"}
)
// GetE2EImage returns the fully qualified URI to an image (including version)
func GetE2EImage(image Config) string {
return fmt.Sprintf("%s/%s:%s", image.registry, image.name, image.version)
}
// GetPauseImageName returns the pause image name with proper version

View File

@ -17,9 +17,11 @@ limitations under the License.
package utils
import (
"context"
"fmt"
"math"
"os"
"strings"
"sync"
"time"
@ -45,7 +47,7 @@ import (
extensionsinternal "k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"github.com/golang/glog"
"k8s.io/klog"
)
const (
@ -139,6 +141,9 @@ type RCConfig struct {
// Node selector for pods in the RC.
NodeSelector map[string]string
// Tolerations for pods in the RC.
Tolerations []v1.Toleration
// Ports to declare in the container (map of name to containerPort).
Ports map[string]int
// Ports to declare in the container as host and container ports.
@ -158,7 +163,7 @@ type RCConfig struct {
// If set to false starting RC will print progress, otherwise only errors will be printed.
Silent bool
// If set this function will be used to print log lines instead of glog.
// If set this function will be used to print log lines instead of klog.
LogFunc func(fmt string, args ...interface{})
// If set those functions will be used to gather data from Nodes - in integration tests where no
// kubelets are running those variables should be nil.
@ -168,13 +173,15 @@ type RCConfig struct {
// Names of the secrets and configmaps to mount.
SecretNames []string
ConfigMapNames []string
ServiceAccountTokenProjections int
}
func (rc *RCConfig) RCConfigLog(fmt string, args ...interface{}) {
if rc.LogFunc != nil {
rc.LogFunc(fmt, args...)
}
glog.Infof(fmt, args...)
klog.Infof(fmt, args...)
}
type DeploymentConfig struct {
@ -236,6 +243,18 @@ func (p PodDiff) String(ignorePhases sets.String) string {
return ret
}
// DeletedPods returns a slice of pods that were present at the beginning
// and then disappeared.
func (p PodDiff) DeletedPods() []string {
var deletedPods []string
for podName, podInfo := range p {
if podInfo.hostname == nonExist {
deletedPods = append(deletedPods, podName)
}
}
return deletedPods
}
// Diff computes a PodDiff given 2 lists of pods.
func Diff(oldPods []*v1.Pod, curPods []*v1.Pod) PodDiff {
podInfoMap := PodDiff{}
@ -318,6 +337,10 @@ func (config *DeploymentConfig) create() error {
attachConfigMaps(&deployment.Spec.Template, config.ConfigMapNames)
}
for i := 0; i < config.ServiceAccountTokenProjections; i++ {
attachServiceAccountTokenProjection(&deployment.Spec.Template, fmt.Sprintf("tok-%d", i))
}
config.applyTo(&deployment.Spec.Template)
if err := CreateDeploymentWithRetries(config.Client, config.Namespace, deployment); err != nil {
@ -563,6 +586,7 @@ func (config *RCConfig) create() error {
},
DNSPolicy: *config.DNSPolicy,
NodeSelector: config.NodeSelector,
Tolerations: config.Tolerations,
TerminationGracePeriodSeconds: &one,
PriorityClassName: config.PriorityClassName,
},
@ -604,6 +628,9 @@ func (config *RCConfig) applyTo(template *v1.PodTemplateSpec) {
template.Spec.NodeSelector[k] = v
}
}
if config.Tolerations != nil {
template.Spec.Tolerations = append([]v1.Toleration{}, config.Tolerations...)
}
if config.Ports != nil {
for k, v := range config.Ports {
c := &template.Spec.Containers[0]
@ -751,9 +778,8 @@ func (config *RCConfig) start() error {
pods := ps.List()
startupStatus := ComputeRCStartupStatus(pods, config.Replicas)
pods = startupStatus.Created
if config.CreatedPods != nil {
*config.CreatedPods = pods
*config.CreatedPods = startupStatus.Created
}
if !config.Silent {
config.RCConfigLog(startupStatus.String(config.Name))
@ -773,16 +799,15 @@ func (config *RCConfig) start() error {
}
return fmt.Errorf("%d containers failed which is more than allowed %d", startupStatus.FailedContainers, maxContainerFailures)
}
if len(pods) < len(oldPods) || len(pods) > config.Replicas {
// This failure mode includes:
// kubelet is dead, so node controller deleted pods and rc creates more
// - diagnose by noting the pod diff below.
// pod is unhealthy, so replication controller creates another to take its place
// - diagnose by comparing the previous "2 Pod states" lines for inactive pods
errorStr := fmt.Sprintf("Number of reported pods for %s changed: %d vs %d", config.Name, len(pods), len(oldPods))
config.RCConfigLog("%v, pods that changed since the last iteration:", errorStr)
config.RCConfigLog(Diff(oldPods, pods).String(sets.NewString()))
return fmt.Errorf(errorStr)
diff := Diff(oldPods, pods)
deletedPods := diff.DeletedPods()
if len(deletedPods) != 0 {
// There are some pods that have disappeared.
err := fmt.Errorf("%d pods disappeared for %s: %v", len(deletedPods), config.Name, strings.Join(deletedPods, ", "))
config.RCConfigLog(err.Error())
config.RCConfigLog(diff.String(sets.NewString()))
return err
}
if len(pods) > len(oldPods) || startupStatus.Running > oldRunning {
@ -1019,7 +1044,7 @@ func MakePodSpec() v1.PodSpec {
return v1.PodSpec{
Containers: []v1.Container{{
Name: "pause",
Image: "kubernetes/pause",
Image: "k8s.gcr.io/pause:3.1",
Ports: []v1.ContainerPort{{ContainerPort: 80}},
Resources: v1.ResourceRequirements{
Limits: v1.ResourceList{
@ -1054,9 +1079,9 @@ func CreatePod(client clientset.Interface, namespace string, podCount int, podTe
}
if podCount < 30 {
workqueue.Parallelize(podCount, podCount, createPodFunc)
workqueue.ParallelizeUntil(context.TODO(), podCount, podCount, createPodFunc)
} else {
workqueue.Parallelize(30, podCount, createPodFunc)
workqueue.ParallelizeUntil(context.TODO(), 30, podCount, createPodFunc)
}
return createError
}
@ -1120,7 +1145,7 @@ type SecretConfig struct {
Client clientset.Interface
Name string
Namespace string
// If set this function will be used to print log lines instead of glog.
// If set this function will be used to print log lines instead of klog.
LogFunc func(fmt string, args ...interface{})
}
@ -1178,7 +1203,7 @@ type ConfigMapConfig struct {
Client clientset.Interface
Name string
Namespace string
// If set this function will be used to print log lines instead of glog.
// If set this function will be used to print log lines instead of klog.
LogFunc func(fmt string, args ...interface{})
}
@ -1233,12 +1258,63 @@ func attachConfigMaps(template *v1.PodTemplateSpec, configMapNames []string) {
template.Spec.Containers[0].VolumeMounts = mounts
}
func attachServiceAccountTokenProjection(template *v1.PodTemplateSpec, name string) {
template.Spec.Containers[0].VolumeMounts = append(template.Spec.Containers[0].VolumeMounts,
v1.VolumeMount{
Name: name,
MountPath: "/var/service-account-tokens/" + name,
})
template.Spec.Volumes = append(template.Spec.Volumes,
v1.Volume{
Name: name,
VolumeSource: v1.VolumeSource{
Projected: &v1.ProjectedVolumeSource{
Sources: []v1.VolumeProjection{
{
ServiceAccountToken: &v1.ServiceAccountTokenProjection{
Path: "token",
Audience: name,
},
},
{
ConfigMap: &v1.ConfigMapProjection{
LocalObjectReference: v1.LocalObjectReference{
Name: "kube-root-ca-crt",
},
Items: []v1.KeyToPath{
{
Key: "ca.crt",
Path: "ca.crt",
},
},
},
},
{
DownwardAPI: &v1.DownwardAPIProjection{
Items: []v1.DownwardAPIVolumeFile{
{
Path: "namespace",
FieldRef: &v1.ObjectFieldSelector{
APIVersion: "v1",
FieldPath: "metadata.namespace",
},
},
},
},
},
},
},
},
})
}
type DaemonConfig struct {
Client clientset.Interface
Name string
Namespace string
Image string
// If set this function will be used to print log lines instead of glog.
// If set this function will be used to print log lines instead of klog.
LogFunc func(fmt string, args ...interface{})
// How long we wait for DaemonSet to become running.
Timeout time.Duration
@ -1246,7 +1322,7 @@ type DaemonConfig struct {
func (config *DaemonConfig) Run() error {
if config.Image == "" {
config.Image = "kubernetes/pause"
config.Image = "k8s.gcr.io/pause:3.1"
}
nameLabel := map[string]string{
"name": config.Name + "-daemon",

View File

@ -18,9 +18,8 @@ package utils
import (
"io/ioutil"
"os"
"github.com/golang/glog"
"k8s.io/klog"
)
func MakeTempDirOrDie(prefix string, baseDir string) string {
@ -29,10 +28,7 @@ func MakeTempDirOrDie(prefix string, baseDir string) string {
}
tempDir, err := ioutil.TempDir(baseDir, prefix)
if err != nil {
glog.Fatalf("Can't make a temp rootdir: %v", err)
}
if err = os.MkdirAll(tempDir, 0750); err != nil {
glog.Fatalf("Can't mkdir(%q): %v", tempDir, err)
klog.Fatalf("Can't make a temp rootdir: %v", err)
}
return tempDir
}