mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #11737 from thockin/cleanup-remove-v1beta3
Remove v1beta3
This commit is contained in:
commit
ae1c8e55ef
@ -1,10 +1,6 @@
|
||||
{
|
||||
"swaggerVersion": "1.2",
|
||||
"apis": [
|
||||
{
|
||||
"path": "/api/v1beta3",
|
||||
"description": "API at /api/v1beta3 version v1beta3"
|
||||
},
|
||||
{
|
||||
"path": "/api/v1",
|
||||
"description": "API at /api/v1 version v1"
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -23,7 +23,6 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||
pkg_runtime "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
|
||||
"github.com/golang/glog"
|
||||
@ -32,7 +31,7 @@ import (
|
||||
|
||||
var (
|
||||
functionDest = flag.StringP("funcDest", "f", "-", "Output for conversion functions; '-' means stdout")
|
||||
version = flag.StringP("version", "v", "v1beta3", "Version for conversion.")
|
||||
version = flag.StringP("version", "v", "v1", "Version for conversion.")
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||
pkg_runtime "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
|
||||
"github.com/golang/glog"
|
||||
@ -33,7 +32,7 @@ import (
|
||||
|
||||
var (
|
||||
functionDest = flag.StringP("func-dest", "f", "-", "Output for deep copy functions; '-' means stdout")
|
||||
version = flag.StringP("version", "v", "v1beta3", "Version for deep copies.")
|
||||
version = flag.StringP("version", "v", "v1", "Version for deep copies.")
|
||||
overwrites = flag.StringP("overwrites", "o", "", "Comma-separated overwrites for package names")
|
||||
)
|
||||
|
||||
|
@ -152,8 +152,6 @@ func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (st
|
||||
glog.Fatalf("no public address for %s", host)
|
||||
}
|
||||
|
||||
// Enable v1beta3 in master only if we are starting the components for that api version.
|
||||
enableV1Beta3 := apiVersion == "v1beta3"
|
||||
// Create a master and install handlers into mux.
|
||||
m := master.New(&master.Config{
|
||||
EtcdHelper: helper,
|
||||
@ -162,7 +160,6 @@ func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (st
|
||||
EnableLogsSupport: false,
|
||||
EnableProfiling: true,
|
||||
APIPrefix: "/api",
|
||||
EnableV1Beta3: enableV1Beta3,
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
ReadWritePort: portNumber,
|
||||
@ -332,7 +329,7 @@ containers:
|
||||
desc: "static-pod-from-spec",
|
||||
fileContents: `{
|
||||
"kind": "Pod",
|
||||
"apiVersion": "v1beta3",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "static-pod-from-spec"
|
||||
},
|
||||
@ -611,23 +608,6 @@ func runPatchTest(c *client.Client) {
|
||||
RemoveLabelBody []byte
|
||||
RemoveAllLabelsBody []byte
|
||||
}{
|
||||
"v1beta3": {
|
||||
api.JSONPatchType: {
|
||||
[]byte(`[{"op":"add","path":"/metadata/labels","value":{"foo":"bar","baz":"qux"}}]`),
|
||||
[]byte(`[{"op":"remove","path":"/metadata/labels/foo"}]`),
|
||||
[]byte(`[{"op":"remove","path":"/metadata/labels"}]`),
|
||||
},
|
||||
api.MergePatchType: {
|
||||
[]byte(`{"metadata":{"labels":{"foo":"bar","baz":"qux"}}}`),
|
||||
[]byte(`{"metadata":{"labels":{"foo":null}}}`),
|
||||
[]byte(`{"metadata":{"labels":null}}`),
|
||||
},
|
||||
api.StrategicMergePatchType: {
|
||||
[]byte(`{"metadata":{"labels":{"foo":"bar","baz":"qux"}}}`),
|
||||
[]byte(`{"metadata":{"labels":{"foo":null}}}`),
|
||||
[]byte(`{"metadata":{"labels":{"$patch":"replace"}}}`),
|
||||
},
|
||||
},
|
||||
"v1": {
|
||||
api.JSONPatchType: {
|
||||
[]byte(`[{"op":"add","path":"/metadata/labels","value":{"foo":"bar","baz":"qux"}}]`),
|
||||
@ -1027,7 +1007,7 @@ func ServeCachedManifestFile(contents string) (servingAddress string) {
|
||||
const (
|
||||
testPodSpecFile = `{
|
||||
"kind": "Pod",
|
||||
"apiVersion": "v1beta3",
|
||||
"apiVersion": "v1",
|
||||
"metadata": {
|
||||
"name": "container-vm-guestbook-pod-spec"
|
||||
},
|
||||
|
@ -1,24 +0,0 @@
|
||||
{
|
||||
"kind": "ReplicationController",
|
||||
"apiVersion": "v1beta3",
|
||||
"metadata": {
|
||||
"name": "nginx-controller",
|
||||
"labels": {"name": "nginx"}
|
||||
},
|
||||
"spec": {
|
||||
"replicas": 2,
|
||||
"selector": {"name": "nginx"},
|
||||
"template": {
|
||||
"metadata": {
|
||||
"labels": {"name": "nginx"}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [{
|
||||
"name": "nginx",
|
||||
"image": "nginx",
|
||||
"ports": [{"containerPort": 80}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -285,9 +285,6 @@ func (s *APIServer) Run(_ []string) error {
|
||||
}
|
||||
_ = disableLegacyAPIs // hush the compiler while we don't have legacy APIs to disable.
|
||||
|
||||
// v1beta3 is disabled by default. Users can enable it using "api/v1beta3=true"
|
||||
enableV1beta3 := s.getRuntimeConfigValue("api/v1beta3", false)
|
||||
|
||||
// "api/v1={true|false} allows users to enable/disable v1 API.
|
||||
// This takes preference over api/all and api/legacy, if specified.
|
||||
disableV1 := disableAllAPIs
|
||||
@ -387,7 +384,6 @@ func (s *APIServer) Run(_ []string) error {
|
||||
SupportsBasicAuth: len(s.BasicAuthFile) > 0,
|
||||
Authorizer: authorizer,
|
||||
AdmissionControl: admissionController,
|
||||
EnableV1Beta3: enableV1beta3,
|
||||
DisableV1: disableV1,
|
||||
MasterServiceNamespace: s.MasterServiceNamespace,
|
||||
ClusterName: s.ClusterName,
|
||||
|
@ -141,8 +141,7 @@ func walkJSONFiles(inDir string, fn func(name, path string, data []byte)) error
|
||||
func TestExampleObjectSchemas(t *testing.T) {
|
||||
cases := map[string]map[string]runtime.Object{
|
||||
"../cmd/integration": {
|
||||
"v1beta3-controller": &api.ReplicationController{},
|
||||
"v1-controller": &api.ReplicationController{},
|
||||
"v1-controller": &api.ReplicationController{},
|
||||
},
|
||||
"../examples/guestbook": {
|
||||
"frontend-controller": &api.ReplicationController{},
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"apiVersion": "v1beta3",
|
||||
"apiVersion": "v1",
|
||||
"kind": "Pod",
|
||||
"metadata": {"name":"etcd-server"},
|
||||
"spec":{
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"apiVersion": "v1beta3",
|
||||
"apiVersion": "v1",
|
||||
"kind": "Pod",
|
||||
"metadata": {"name":"kube-apiserver"},
|
||||
"spec":{
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"apiVersion": "v1beta3",
|
||||
"apiVersion": "v1",
|
||||
"kind": "Pod",
|
||||
"metadata": {"name":"kube-controller-manager"},
|
||||
"spec":{
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"apiVersion": "v1beta3",
|
||||
"apiVersion": "v1",
|
||||
"kind": "Pod",
|
||||
"metadata": {"name":"kube-scheduler"},
|
||||
"spec":{
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"apiVersion": "v1beta3",
|
||||
"apiVersion": "v1",
|
||||
"kind": "Pod",
|
||||
"metadata": {"name":"scheduler-master"},
|
||||
"spec":{
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"apiVersion": "v1beta3",
|
||||
"apiVersion": "v1",
|
||||
"kind": "Pod",
|
||||
"metadata": {"name":"scheduler-master"},
|
||||
"spec":{
|
||||
|
@ -125,16 +125,14 @@ kube::util::wait_for_url "http://127.0.0.1:${KUBELET_HEALTHZ_PORT}/healthz" "kub
|
||||
|
||||
# Start kube-apiserver
|
||||
kube::log::status "Starting kube-apiserver"
|
||||
KUBE_API_VERSIONS="v1,v1beta3" "${KUBE_OUTPUT_HOSTBIN}/kube-apiserver" \
|
||||
KUBE_API_VERSIONS="v1" "${KUBE_OUTPUT_HOSTBIN}/kube-apiserver" \
|
||||
--address="127.0.0.1" \
|
||||
--public_address_override="127.0.0.1" \
|
||||
--port="${API_PORT}" \
|
||||
--etcd_servers="http://${ETCD_HOST}:${ETCD_PORT}" \
|
||||
--public_address_override="127.0.0.1" \
|
||||
--kubelet_port=${KUBELET_PORT} \
|
||||
--runtime_config=api/v1beta3 \
|
||||
--runtime_config=api/v1 \
|
||||
--runtime_config=api/v1beta3 \
|
||||
--cert_dir="${TMPDIR:-/tmp/}" \
|
||||
--service-cluster-ip-range="10.0.0.0/24" 1>&2 &
|
||||
APISERVER_PID=$!
|
||||
@ -237,7 +235,7 @@ runTests() {
|
||||
kube::test::describe_object_assert pods 'valid-pod' "Name:" "Image(s):" "Node:" "Labels:" "Status:" "Replication Controllers"
|
||||
|
||||
### Dump current valid-pod POD
|
||||
output_pod=$(kubectl get pod valid-pod -o yaml --output-version=v1beta3 "${kube_flags[@]}")
|
||||
output_pod=$(kubectl get pod valid-pod -o yaml --output-version=v1 "${kube_flags[@]}")
|
||||
|
||||
### Delete POD valid-pod by id
|
||||
# Pre-condition: valid-pod POD is running
|
||||
@ -456,8 +454,6 @@ runTests() {
|
||||
# Pod templates #
|
||||
#################
|
||||
|
||||
# Note: pod templates exist only in v1beta3 and above, so output will always be in that form
|
||||
|
||||
### Create PODTEMPLATE
|
||||
# Pre-condition: no PODTEMPLATE
|
||||
kube::test::get_object_assert podtemplates "{{range.items}}{{.metadata.name}}:{{end}}" ''
|
||||
@ -496,7 +492,7 @@ runTests() {
|
||||
kube::test::describe_object_assert services 'redis-master' "Name:" "Labels:" "Selector:" "IP:" "Port:" "Endpoints:" "Session Affinity:"
|
||||
|
||||
### Dump current redis-master service
|
||||
output_service=$(kubectl get service redis-master -o json --output-version=v1beta3 "${kube_flags[@]}")
|
||||
output_service=$(kubectl get service redis-master -o json --output-version=v1 "${kube_flags[@]}")
|
||||
|
||||
### Delete redis-master-service by id
|
||||
# Pre-condition: redis-master service is running
|
||||
@ -776,11 +772,10 @@ __EOF__
|
||||
|
||||
kube_api_versions=(
|
||||
""
|
||||
v1beta3
|
||||
v1
|
||||
)
|
||||
for version in "${kube_api_versions[@]}"; do
|
||||
KUBE_API_VERSIONS="v1,v1beta3" runTests "${version}"
|
||||
KUBE_API_VERSIONS="v1" runTests "${version}"
|
||||
done
|
||||
|
||||
kube::log::status "TEST PASSED"
|
||||
|
@ -53,7 +53,7 @@ KUBE_RACE=${KUBE_RACE:-} # use KUBE_RACE="-race" to enable race testing
|
||||
# Set to the goveralls binary path to report coverage results to Coveralls.io.
|
||||
KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-}
|
||||
# Comma separated list of API Versions that should be tested.
|
||||
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,v1beta3"}
|
||||
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1"}
|
||||
# Run tests with the standard (registry) and a custom etcd prefix
|
||||
# (kubernetes.io/registry).
|
||||
KUBE_TEST_ETCD_PREFIXES=${KUBE_TEST_ETCD_PREFIXES:-"registry,kubernetes.io/registry"}
|
||||
@ -218,7 +218,7 @@ for (( i=0, j=0; ; )); do
|
||||
apiVersion=${apiVersions[i]}
|
||||
etcdPrefix=${etcdPrefixes[j]}
|
||||
echo "Running tests for APIVersion: $apiVersion with etcdPrefix: $etcdPrefix"
|
||||
KUBE_API_VERSION="${apiVersion}" KUBE_API_VERSIONS="v1,v1beta3" ETCD_PREFIX=${etcdPrefix} runTests "$@"
|
||||
KUBE_API_VERSION="${apiVersion}" KUBE_API_VERSIONS="v1" ETCD_PREFIX=${etcdPrefix} runTests "$@"
|
||||
i=${i}+1
|
||||
j=${j}+1
|
||||
if [[ i -eq ${apiVersionsCount} ]] && [[ j -eq ${etcdPrefixesCount} ]]; then
|
||||
|
@ -25,7 +25,7 @@ set -o pipefail
|
||||
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
# Comma separated list of API Versions that should be tested.
|
||||
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,v1beta3"}
|
||||
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1"}
|
||||
|
||||
KUBE_INTEGRATION_TEST_MAX_CONCURRENCY=${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY:-"-1"}
|
||||
LOG_LEVEL=${LOG_LEVEL:-2}
|
||||
@ -43,18 +43,18 @@ runTests() {
|
||||
KUBE_GOFLAGS="-tags 'integration no-docker' " \
|
||||
KUBE_RACE="-race" \
|
||||
KUBE_TEST_API_VERSIONS="$1" \
|
||||
KUBE_API_VERSIONS="v1,v1beta3" \
|
||||
KUBE_API_VERSIONS="v1" \
|
||||
"${KUBE_ROOT}/hack/test-go.sh" test/integration
|
||||
|
||||
kube::log::status "Running integration test scenario"
|
||||
|
||||
KUBE_API_VERSIONS="v1,v1beta3" "${KUBE_OUTPUT_HOSTBIN}/integration" --v=${LOG_LEVEL} --api-version="$1" \
|
||||
KUBE_API_VERSIONS="v1" "${KUBE_OUTPUT_HOSTBIN}/integration" --v=${LOG_LEVEL} --api-version="$1" \
|
||||
--max-concurrency="${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY}"
|
||||
|
||||
cleanup
|
||||
}
|
||||
|
||||
KUBE_API_VERSIONS="v1,v1beta3" "${KUBE_ROOT}/hack/build-go.sh" "$@" cmd/integration
|
||||
KUBE_API_VERSIONS="v1" "${KUBE_ROOT}/hack/build-go.sh" "$@" cmd/integration
|
||||
|
||||
# Run cleanup to stop etcd on interrupt or other kill signal.
|
||||
trap cleanup EXIT
|
||||
|
@ -24,7 +24,7 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
|
||||
# The api version in which objects are currently stored in etcd.
|
||||
KUBE_OLD_API_VERSION=${KUBE_OLD_API_VERSION:-"v1beta3"}
|
||||
KUBE_OLD_API_VERSION=${KUBE_OLD_API_VERSION:-"v1"}
|
||||
# The api version in which our etcd objects should be converted to.
|
||||
# The new api version
|
||||
KUBE_NEW_API_VERSION=${KUBE_NEW_API_VERSION:-"v1"}
|
||||
|
@ -53,7 +53,7 @@ EOF
|
||||
mv $TMPFILE pkg/api/${version}/conversion_generated.go
|
||||
}
|
||||
|
||||
VERSIONS="v1beta3 v1"
|
||||
VERSIONS="v1"
|
||||
for ver in $VERSIONS; do
|
||||
# Ensure that the version being processed is registered by setting
|
||||
# KUBE_API_VERSIONS.
|
||||
|
@ -56,7 +56,7 @@ EOF
|
||||
}
|
||||
|
||||
function generate_deep_copies() {
|
||||
local versions="api v1beta3 v1"
|
||||
local versions="api v1"
|
||||
# To avoid compile errors, remove the currently existing files.
|
||||
for ver in ${versions}; do
|
||||
rm -f `result_file_name ${ver}`
|
||||
|
@ -49,14 +49,14 @@ KUBELET_PORT=${KUBELET_PORT:-10250}
|
||||
|
||||
# Start kube-apiserver
|
||||
kube::log::status "Starting kube-apiserver"
|
||||
KUBE_API_VERSIONS="v1,v1beta3" "${KUBE_OUTPUT_HOSTBIN}/kube-apiserver" \
|
||||
KUBE_API_VERSIONS="v1" "${KUBE_OUTPUT_HOSTBIN}/kube-apiserver" \
|
||||
--address="127.0.0.1" \
|
||||
--public_address_override="127.0.0.1" \
|
||||
--port="${API_PORT}" \
|
||||
--etcd_servers="http://${ETCD_HOST}:${ETCD_PORT}" \
|
||||
--public_address_override="127.0.0.1" \
|
||||
--kubelet_port=${KUBELET_PORT} \
|
||||
--runtime_config=api/v1beta3 \
|
||||
--runtime_config=api/v1 \
|
||||
--service-cluster-ip-range="10.0.0.0/24" >/dev/null 2>&1 &
|
||||
APISERVER_PID=$!
|
||||
|
||||
@ -67,7 +67,6 @@ kube::log::status "Updating " ${SWAGGER_ROOT_DIR}
|
||||
curl -fs ${SWAGGER_API_PATH} > ${SWAGGER_ROOT_DIR}/resourceListing.json
|
||||
curl -fs ${SWAGGER_API_PATH}version > ${SWAGGER_ROOT_DIR}/version.json
|
||||
curl -fs ${SWAGGER_API_PATH}api > ${SWAGGER_ROOT_DIR}/api.json
|
||||
curl -fs ${SWAGGER_API_PATH}api/v1beta3 > ${SWAGGER_ROOT_DIR}/v1beta3.json
|
||||
curl -fs ${SWAGGER_API_PATH}api/v1 > ${SWAGGER_ROOT_DIR}/v1.json
|
||||
|
||||
kube::log::status "SUCCESS"
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/registered"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
@ -128,12 +127,6 @@ func init() {
|
||||
// string, or an error if the version is not known.
|
||||
func InterfacesFor(version string) (*meta.VersionInterfaces, error) {
|
||||
switch version {
|
||||
case "v1beta3":
|
||||
return &meta.VersionInterfaces{
|
||||
Codec: v1beta3.Codec,
|
||||
ObjectConvertor: api.Scheme,
|
||||
MetadataAccessor: accessor,
|
||||
}, nil
|
||||
case "v1":
|
||||
return &meta.VersionInterfaces{
|
||||
Codec: v1.Codec,
|
||||
|
@ -108,7 +108,6 @@ func TestKindToResource(t *testing.T) {
|
||||
|
||||
{Kind: "ReplicationController", MixedCase: true, Plural: "replicationControllers", Singular: "replicationController"},
|
||||
{Kind: "ReplicationController", MixedCase: true, Plural: "replicationControllers", Singular: "replicationController"},
|
||||
// API convention changed with regard to capitalization for v1beta3
|
||||
{Kind: "ReplicationController", MixedCase: false, Plural: "replicationcontrollers", Singular: "replicationcontroller"},
|
||||
|
||||
{Kind: "ImageRepository", MixedCase: true, Plural: "imageRepositories", Singular: "imageRepository"},
|
||||
|
@ -30,8 +30,7 @@ var RegisteredVersions []string
|
||||
|
||||
func init() {
|
||||
validAPIVersions := map[string]bool{
|
||||
"v1": true,
|
||||
"v1beta3": true,
|
||||
"v1": true,
|
||||
}
|
||||
|
||||
// The default list of supported api versions, in order of most preferred to the least.
|
||||
|
@ -99,9 +99,8 @@ func ResourcePathWithPrefix(prefix, resource, namespace, name string) string {
|
||||
}
|
||||
|
||||
// Returns the appropriate path for the given resource, namespace and name.
|
||||
// For ex, this is of the form:
|
||||
// /api/v1beta1/pods/pod0 for v1beta1 and
|
||||
// /api/v1beta3/namespaces/foo/pods/pod0 for v1beta3.
|
||||
// For example, this is of the form:
|
||||
// /api/v1/namespaces/foo/pods/pod0 for v1.
|
||||
func ResourcePath(resource, namespace, name string) string {
|
||||
return ResourcePathWithPrefix("", resource, namespace, name)
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
"github.com/google/gofuzz"
|
||||
|
||||
"github.com/google/gofuzz"
|
||||
"speter.net/go/exp/math/dec/inf"
|
||||
)
|
||||
|
||||
|
@ -806,11 +806,10 @@ type ContainerStatus struct {
|
||||
Ready bool `json:"ready"`
|
||||
// Note that this is calculated from dead containers. But those containers are subject to
|
||||
// garbage collection. This value will get capped at 5 by GC.
|
||||
RestartCount int `json:"restartCount"`
|
||||
// TODO(dchen1107): Need to decide how to represent this in v1beta3
|
||||
Image string `json:"image"`
|
||||
ImageID string `json:"imageID"`
|
||||
ContainerID string `json:"containerID,omitempty"`
|
||||
RestartCount int `json:"restartCount"`
|
||||
Image string `json:"image"`
|
||||
ImageID string `json:"imageID"`
|
||||
ContainerID string `json:"containerID,omitempty"`
|
||||
}
|
||||
|
||||
// PodPhase is a label for the condition of a pod at the current time.
|
||||
@ -1009,7 +1008,7 @@ type ReplicationControllerSpec struct {
|
||||
|
||||
// TemplateRef is a reference to an object that describes the pod that will be created if
|
||||
// insufficient replicas are detected. This reference is ignored if a Template is set.
|
||||
// Must be set before converting to a v1beta3 API object
|
||||
// Must be set before converting to a versioned API object
|
||||
//TemplateRef *ObjectReference `json:"templateRef,omitempty"`
|
||||
|
||||
// Template is the object that describes the pod that will be created if
|
||||
@ -1163,10 +1162,8 @@ type ServicePort struct {
|
||||
|
||||
// Optional: The target port on pods selected by this service. If this
|
||||
// is a string, it will be looked up as a named port in the target
|
||||
// Pod's container ports. If this is not specified, the first port on
|
||||
// the destination pod will be used. This behavior is deprecated. As
|
||||
// of v1beta3 the default value is the sames as the Port field (an
|
||||
// identity map).
|
||||
// Pod's container ports. If this is not specified, the default value
|
||||
// is the sames as the Port field (an identity map).
|
||||
TargetPort util.IntOrString `json:"targetPort"`
|
||||
|
||||
// The port on each node on which this service is exposed.
|
||||
|
@ -1,778 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 v1beta3
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion"
|
||||
)
|
||||
|
||||
func addConversionFuncs() {
|
||||
// Add non-generated conversion functions
|
||||
err := api.Scheme.AddConversionFuncs(
|
||||
convert_v1beta3_Container_To_api_Container,
|
||||
convert_api_Container_To_v1beta3_Container,
|
||||
convert_v1beta3_ServiceSpec_To_api_ServiceSpec,
|
||||
convert_api_ServiceSpec_To_v1beta3_ServiceSpec,
|
||||
convert_v1beta3_PodSpec_To_api_PodSpec,
|
||||
convert_api_PodSpec_To_v1beta3_PodSpec,
|
||||
convert_v1beta3_ContainerState_To_api_ContainerState,
|
||||
convert_api_ContainerState_To_v1beta3_ContainerState,
|
||||
convert_api_ContainerStateTerminated_To_v1beta3_ContainerStateTerminated,
|
||||
convert_v1beta3_ContainerStateTerminated_To_api_ContainerStateTerminated,
|
||||
convert_v1beta3_StatusDetails_To_api_StatusDetails,
|
||||
convert_api_StatusDetails_To_v1beta3_StatusDetails,
|
||||
convert_v1beta3_StatusCause_To_api_StatusCause,
|
||||
convert_api_StatusCause_To_v1beta3_StatusCause,
|
||||
convert_api_ReplicationControllerSpec_To_v1beta3_ReplicationControllerSpec,
|
||||
convert_v1beta3_ReplicationControllerSpec_To_api_ReplicationControllerSpec,
|
||||
)
|
||||
if err != nil {
|
||||
// If one of the conversion functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Add field conversion funcs.
|
||||
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Pod",
|
||||
func(label, value string) (string, string, error) {
|
||||
switch label {
|
||||
case "metadata.name",
|
||||
"metadata.namespace",
|
||||
"status.phase":
|
||||
return label, value, nil
|
||||
case "spec.host":
|
||||
return "spec.nodeName", value, nil
|
||||
default:
|
||||
return "", "", fmt.Errorf("field label not supported: %s", label)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
// If one of the conversion functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Node",
|
||||
func(label, value string) (string, string, error) {
|
||||
switch label {
|
||||
case "metadata.name":
|
||||
return label, value, nil
|
||||
case "spec.unschedulable":
|
||||
return label, value, nil
|
||||
default:
|
||||
return "", "", fmt.Errorf("field label not supported: %s", label)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
// If one of the conversion functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "ReplicationController",
|
||||
func(label, value string) (string, string, error) {
|
||||
switch label {
|
||||
case "metadata.name",
|
||||
"status.replicas":
|
||||
return label, value, nil
|
||||
default:
|
||||
return "", "", fmt.Errorf("field label not supported: %s", label)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
// If one of the conversion functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Event",
|
||||
func(label, value string) (string, string, error) {
|
||||
switch label {
|
||||
case "involvedObject.kind",
|
||||
"involvedObject.namespace",
|
||||
"involvedObject.name",
|
||||
"involvedObject.uid",
|
||||
"involvedObject.apiVersion",
|
||||
"involvedObject.resourceVersion",
|
||||
"involvedObject.fieldPath",
|
||||
"reason",
|
||||
"source":
|
||||
return label, value, nil
|
||||
default:
|
||||
return "", "", fmt.Errorf("field label not supported: %s", label)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
// If one of the conversion functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Namespace",
|
||||
func(label, value string) (string, string, error) {
|
||||
switch label {
|
||||
case "status.phase":
|
||||
return label, value, nil
|
||||
default:
|
||||
return "", "", fmt.Errorf("field label not supported: %s", label)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
// If one of the conversion functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Secret",
|
||||
func(label, value string) (string, string, error) {
|
||||
switch label {
|
||||
case "type":
|
||||
return label, value, nil
|
||||
default:
|
||||
return "", "", fmt.Errorf("field label not supported: %s", label)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
// If one of the conversion functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "ServiceAccount",
|
||||
func(label, value string) (string, string, error) {
|
||||
switch label {
|
||||
case "metadata.name":
|
||||
return label, value, nil
|
||||
default:
|
||||
return "", "", fmt.Errorf("field label not supported: %s", label)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
// If one of the conversion functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
err = api.Scheme.AddFieldLabelConversionFunc("v1beta3", "Endpoints",
|
||||
func(label, value string) (string, string, error) {
|
||||
switch label {
|
||||
case "metadata.name":
|
||||
return label, value, nil
|
||||
default:
|
||||
return "", "", fmt.Errorf("field label not supported: %s", label)
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
// If one of the conversion functions is malformed, detect it immediately.
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func convert_v1beta3_Container_To_api_Container(in *Container, out *api.Container, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*Container))(in)
|
||||
}
|
||||
out.Name = in.Name
|
||||
out.Image = in.Image
|
||||
if in.Command != nil {
|
||||
out.Command = make([]string, len(in.Command))
|
||||
for i := range in.Command {
|
||||
out.Command[i] = in.Command[i]
|
||||
}
|
||||
}
|
||||
if in.Args != nil {
|
||||
out.Args = make([]string, len(in.Args))
|
||||
for i := range in.Args {
|
||||
out.Args[i] = in.Args[i]
|
||||
}
|
||||
}
|
||||
out.WorkingDir = in.WorkingDir
|
||||
if in.Ports != nil {
|
||||
out.Ports = make([]api.ContainerPort, len(in.Ports))
|
||||
for i := range in.Ports {
|
||||
if err := convert_v1beta3_ContainerPort_To_api_ContainerPort(&in.Ports[i], &out.Ports[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if in.Env != nil {
|
||||
out.Env = make([]api.EnvVar, len(in.Env))
|
||||
for i := range in.Env {
|
||||
if err := convert_v1beta3_EnvVar_To_api_EnvVar(&in.Env[i], &out.Env[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := s.Convert(&in.Resources, &out.Resources, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if in.VolumeMounts != nil {
|
||||
out.VolumeMounts = make([]api.VolumeMount, len(in.VolumeMounts))
|
||||
for i := range in.VolumeMounts {
|
||||
if err := convert_v1beta3_VolumeMount_To_api_VolumeMount(&in.VolumeMounts[i], &out.VolumeMounts[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if in.LivenessProbe != nil {
|
||||
out.LivenessProbe = new(api.Probe)
|
||||
if err := convert_v1beta3_Probe_To_api_Probe(in.LivenessProbe, out.LivenessProbe, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.LivenessProbe = nil
|
||||
}
|
||||
if in.ReadinessProbe != nil {
|
||||
out.ReadinessProbe = new(api.Probe)
|
||||
if err := convert_v1beta3_Probe_To_api_Probe(in.ReadinessProbe, out.ReadinessProbe, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.ReadinessProbe = nil
|
||||
}
|
||||
if in.Lifecycle != nil {
|
||||
out.Lifecycle = new(api.Lifecycle)
|
||||
if err := convert_v1beta3_Lifecycle_To_api_Lifecycle(in.Lifecycle, out.Lifecycle, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.Lifecycle = nil
|
||||
}
|
||||
out.TerminationMessagePath = in.TerminationMessagePath
|
||||
out.ImagePullPolicy = api.PullPolicy(in.ImagePullPolicy)
|
||||
if in.SecurityContext != nil {
|
||||
if in.SecurityContext.Capabilities != nil {
|
||||
if !reflect.DeepEqual(in.SecurityContext.Capabilities.Add, in.Capabilities.Add) ||
|
||||
!reflect.DeepEqual(in.SecurityContext.Capabilities.Drop, in.Capabilities.Drop) {
|
||||
return fmt.Errorf("container capability settings do not match security context settings, cannot convert")
|
||||
}
|
||||
}
|
||||
if in.SecurityContext.Privileged != nil {
|
||||
if in.Privileged != *in.SecurityContext.Privileged {
|
||||
return fmt.Errorf("container privileged settings do not match security context settings, cannot convert")
|
||||
}
|
||||
}
|
||||
}
|
||||
if in.SecurityContext != nil {
|
||||
out.SecurityContext = new(api.SecurityContext)
|
||||
if err := convert_v1beta3_SecurityContext_To_api_SecurityContext(in.SecurityContext, out.SecurityContext, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.SecurityContext = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_api_Container_To_v1beta3_Container(in *api.Container, out *Container, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*api.Container))(in)
|
||||
}
|
||||
out.Name = in.Name
|
||||
out.Image = in.Image
|
||||
if in.Command != nil {
|
||||
out.Command = make([]string, len(in.Command))
|
||||
for i := range in.Command {
|
||||
out.Command[i] = in.Command[i]
|
||||
}
|
||||
}
|
||||
if in.Args != nil {
|
||||
out.Args = make([]string, len(in.Args))
|
||||
for i := range in.Args {
|
||||
out.Args[i] = in.Args[i]
|
||||
}
|
||||
}
|
||||
out.WorkingDir = in.WorkingDir
|
||||
if in.Ports != nil {
|
||||
out.Ports = make([]ContainerPort, len(in.Ports))
|
||||
for i := range in.Ports {
|
||||
if err := convert_api_ContainerPort_To_v1beta3_ContainerPort(&in.Ports[i], &out.Ports[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if in.Env != nil {
|
||||
out.Env = make([]EnvVar, len(in.Env))
|
||||
for i := range in.Env {
|
||||
if err := convert_api_EnvVar_To_v1beta3_EnvVar(&in.Env[i], &out.Env[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := s.Convert(&in.Resources, &out.Resources, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if in.VolumeMounts != nil {
|
||||
out.VolumeMounts = make([]VolumeMount, len(in.VolumeMounts))
|
||||
for i := range in.VolumeMounts {
|
||||
if err := convert_api_VolumeMount_To_v1beta3_VolumeMount(&in.VolumeMounts[i], &out.VolumeMounts[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if in.LivenessProbe != nil {
|
||||
out.LivenessProbe = new(Probe)
|
||||
if err := convert_api_Probe_To_v1beta3_Probe(in.LivenessProbe, out.LivenessProbe, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.LivenessProbe = nil
|
||||
}
|
||||
if in.ReadinessProbe != nil {
|
||||
out.ReadinessProbe = new(Probe)
|
||||
if err := convert_api_Probe_To_v1beta3_Probe(in.ReadinessProbe, out.ReadinessProbe, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.ReadinessProbe = nil
|
||||
}
|
||||
if in.Lifecycle != nil {
|
||||
out.Lifecycle = new(Lifecycle)
|
||||
if err := convert_api_Lifecycle_To_v1beta3_Lifecycle(in.Lifecycle, out.Lifecycle, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.Lifecycle = nil
|
||||
}
|
||||
out.TerminationMessagePath = in.TerminationMessagePath
|
||||
out.ImagePullPolicy = PullPolicy(in.ImagePullPolicy)
|
||||
if in.SecurityContext != nil {
|
||||
out.SecurityContext = new(SecurityContext)
|
||||
if err := convert_api_SecurityContext_To_v1beta3_SecurityContext(in.SecurityContext, out.SecurityContext, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.SecurityContext = nil
|
||||
}
|
||||
// now that we've converted set the container field from security context
|
||||
if out.SecurityContext != nil && out.SecurityContext.Privileged != nil {
|
||||
out.Privileged = *out.SecurityContext.Privileged
|
||||
}
|
||||
// now that we've converted set the container field from security context
|
||||
if out.SecurityContext != nil && out.SecurityContext.Capabilities != nil {
|
||||
out.Capabilities = *out.SecurityContext.Capabilities
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_v1beta3_ServiceSpec_To_api_ServiceSpec(in *ServiceSpec, out *api.ServiceSpec, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*ServiceSpec))(in)
|
||||
}
|
||||
if in.Ports != nil {
|
||||
out.Ports = make([]api.ServicePort, len(in.Ports))
|
||||
for i := range in.Ports {
|
||||
if err := convert_v1beta3_ServicePort_To_api_ServicePort(&in.Ports[i], &out.Ports[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.Ports = nil
|
||||
}
|
||||
if in.Selector != nil {
|
||||
out.Selector = make(map[string]string)
|
||||
for key, val := range in.Selector {
|
||||
out.Selector[key] = val
|
||||
}
|
||||
} else {
|
||||
out.Selector = nil
|
||||
}
|
||||
out.ClusterIP = in.PortalIP
|
||||
|
||||
typeIn := in.Type
|
||||
if typeIn == "" {
|
||||
if in.CreateExternalLoadBalancer {
|
||||
typeIn = ServiceTypeLoadBalancer
|
||||
} else {
|
||||
typeIn = ServiceTypeClusterIP
|
||||
}
|
||||
}
|
||||
if err := s.Convert(&typeIn, &out.Type, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if in.PublicIPs != nil {
|
||||
out.DeprecatedPublicIPs = make([]string, len(in.PublicIPs))
|
||||
for i := range in.PublicIPs {
|
||||
out.DeprecatedPublicIPs[i] = in.PublicIPs[i]
|
||||
}
|
||||
} else {
|
||||
out.DeprecatedPublicIPs = nil
|
||||
}
|
||||
out.SessionAffinity = api.ServiceAffinity(in.SessionAffinity)
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_api_ServiceSpec_To_v1beta3_ServiceSpec(in *api.ServiceSpec, out *ServiceSpec, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*api.ServiceSpec))(in)
|
||||
}
|
||||
if in.Ports != nil {
|
||||
out.Ports = make([]ServicePort, len(in.Ports))
|
||||
for i := range in.Ports {
|
||||
if err := convert_api_ServicePort_To_v1beta3_ServicePort(&in.Ports[i], &out.Ports[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.Ports = nil
|
||||
}
|
||||
if in.Selector != nil {
|
||||
out.Selector = make(map[string]string)
|
||||
for key, val := range in.Selector {
|
||||
out.Selector[key] = val
|
||||
}
|
||||
} else {
|
||||
out.Selector = nil
|
||||
}
|
||||
out.PortalIP = in.ClusterIP
|
||||
|
||||
if err := s.Convert(&in.Type, &out.Type, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
out.CreateExternalLoadBalancer = in.Type == api.ServiceTypeLoadBalancer
|
||||
|
||||
if in.DeprecatedPublicIPs != nil {
|
||||
out.PublicIPs = make([]string, len(in.DeprecatedPublicIPs))
|
||||
for i := range in.DeprecatedPublicIPs {
|
||||
out.PublicIPs[i] = in.DeprecatedPublicIPs[i]
|
||||
}
|
||||
} else {
|
||||
out.PublicIPs = nil
|
||||
}
|
||||
out.SessionAffinity = ServiceAffinity(in.SessionAffinity)
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_v1beta3_PodSpec_To_api_PodSpec(in *PodSpec, out *api.PodSpec, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*PodSpec))(in)
|
||||
}
|
||||
if in.Volumes != nil {
|
||||
out.Volumes = make([]api.Volume, len(in.Volumes))
|
||||
for i := range in.Volumes {
|
||||
if err := convert_v1beta3_Volume_To_api_Volume(&in.Volumes[i], &out.Volumes[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.Volumes = nil
|
||||
}
|
||||
if in.Containers != nil {
|
||||
out.Containers = make([]api.Container, len(in.Containers))
|
||||
for i := range in.Containers {
|
||||
if err := convert_v1beta3_Container_To_api_Container(&in.Containers[i], &out.Containers[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.Containers = nil
|
||||
}
|
||||
out.RestartPolicy = api.RestartPolicy(in.RestartPolicy)
|
||||
if in.TerminationGracePeriodSeconds != nil {
|
||||
out.TerminationGracePeriodSeconds = new(int64)
|
||||
*out.TerminationGracePeriodSeconds = *in.TerminationGracePeriodSeconds
|
||||
} else {
|
||||
out.TerminationGracePeriodSeconds = nil
|
||||
}
|
||||
if in.ActiveDeadlineSeconds != nil {
|
||||
out.ActiveDeadlineSeconds = new(int64)
|
||||
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
|
||||
} else {
|
||||
out.ActiveDeadlineSeconds = nil
|
||||
}
|
||||
out.DNSPolicy = api.DNSPolicy(in.DNSPolicy)
|
||||
if in.NodeSelector != nil {
|
||||
out.NodeSelector = make(map[string]string)
|
||||
for key, val := range in.NodeSelector {
|
||||
out.NodeSelector[key] = val
|
||||
}
|
||||
} else {
|
||||
out.NodeSelector = nil
|
||||
}
|
||||
out.ServiceAccountName = in.ServiceAccount
|
||||
out.NodeName = in.Host
|
||||
out.HostNetwork = in.HostNetwork
|
||||
if in.ImagePullSecrets != nil {
|
||||
out.ImagePullSecrets = make([]api.LocalObjectReference, len(in.ImagePullSecrets))
|
||||
for i := range in.ImagePullSecrets {
|
||||
if err := convert_v1beta3_LocalObjectReference_To_api_LocalObjectReference(&in.ImagePullSecrets[i], &out.ImagePullSecrets[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.ImagePullSecrets = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_api_PodSpec_To_v1beta3_PodSpec(in *api.PodSpec, out *PodSpec, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*api.PodSpec))(in)
|
||||
}
|
||||
if in.Volumes != nil {
|
||||
out.Volumes = make([]Volume, len(in.Volumes))
|
||||
for i := range in.Volumes {
|
||||
if err := convert_api_Volume_To_v1beta3_Volume(&in.Volumes[i], &out.Volumes[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.Volumes = nil
|
||||
}
|
||||
if in.Containers != nil {
|
||||
out.Containers = make([]Container, len(in.Containers))
|
||||
for i := range in.Containers {
|
||||
if err := convert_api_Container_To_v1beta3_Container(&in.Containers[i], &out.Containers[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.Containers = nil
|
||||
}
|
||||
out.RestartPolicy = RestartPolicy(in.RestartPolicy)
|
||||
if in.TerminationGracePeriodSeconds != nil {
|
||||
out.TerminationGracePeriodSeconds = new(int64)
|
||||
*out.TerminationGracePeriodSeconds = *in.TerminationGracePeriodSeconds
|
||||
} else {
|
||||
out.TerminationGracePeriodSeconds = nil
|
||||
}
|
||||
if in.ActiveDeadlineSeconds != nil {
|
||||
out.ActiveDeadlineSeconds = new(int64)
|
||||
*out.ActiveDeadlineSeconds = *in.ActiveDeadlineSeconds
|
||||
} else {
|
||||
out.ActiveDeadlineSeconds = nil
|
||||
}
|
||||
out.DNSPolicy = DNSPolicy(in.DNSPolicy)
|
||||
if in.NodeSelector != nil {
|
||||
out.NodeSelector = make(map[string]string)
|
||||
for key, val := range in.NodeSelector {
|
||||
out.NodeSelector[key] = val
|
||||
}
|
||||
} else {
|
||||
out.NodeSelector = nil
|
||||
}
|
||||
out.ServiceAccount = in.ServiceAccountName
|
||||
out.Host = in.NodeName
|
||||
out.HostNetwork = in.HostNetwork
|
||||
if in.ImagePullSecrets != nil {
|
||||
out.ImagePullSecrets = make([]LocalObjectReference, len(in.ImagePullSecrets))
|
||||
for i := range in.ImagePullSecrets {
|
||||
if err := convert_api_LocalObjectReference_To_v1beta3_LocalObjectReference(&in.ImagePullSecrets[i], &out.ImagePullSecrets[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.ImagePullSecrets = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_api_ContainerState_To_v1beta3_ContainerState(in *api.ContainerState, out *ContainerState, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*api.ContainerState))(in)
|
||||
}
|
||||
if in.Waiting != nil {
|
||||
out.Waiting = new(ContainerStateWaiting)
|
||||
if err := convert_api_ContainerStateWaiting_To_v1beta3_ContainerStateWaiting(in.Waiting, out.Waiting, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.Waiting = nil
|
||||
}
|
||||
if in.Running != nil {
|
||||
out.Running = new(ContainerStateRunning)
|
||||
if err := convert_api_ContainerStateRunning_To_v1beta3_ContainerStateRunning(in.Running, out.Running, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.Running = nil
|
||||
}
|
||||
if in.Terminated != nil {
|
||||
out.Termination = new(ContainerStateTerminated)
|
||||
if err := convert_api_ContainerStateTerminated_To_v1beta3_ContainerStateTerminated(in.Terminated, out.Termination, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.Termination = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_v1beta3_ContainerState_To_api_ContainerState(in *ContainerState, out *api.ContainerState, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*ContainerState))(in)
|
||||
}
|
||||
if in.Waiting != nil {
|
||||
out.Waiting = new(api.ContainerStateWaiting)
|
||||
if err := convert_v1beta3_ContainerStateWaiting_To_api_ContainerStateWaiting(in.Waiting, out.Waiting, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.Waiting = nil
|
||||
}
|
||||
if in.Running != nil {
|
||||
out.Running = new(api.ContainerStateRunning)
|
||||
if err := convert_v1beta3_ContainerStateRunning_To_api_ContainerStateRunning(in.Running, out.Running, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.Running = nil
|
||||
}
|
||||
if in.Termination != nil {
|
||||
out.Terminated = new(api.ContainerStateTerminated)
|
||||
if err := convert_v1beta3_ContainerStateTerminated_To_api_ContainerStateTerminated(in.Termination, out.Terminated, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.Terminated = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_api_ContainerStateTerminated_To_v1beta3_ContainerStateTerminated(in *api.ContainerStateTerminated, out *ContainerStateTerminated, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*api.ContainerStateTerminated))(in)
|
||||
}
|
||||
out.ExitCode = in.ExitCode
|
||||
out.Signal = in.Signal
|
||||
out.Reason = in.Reason
|
||||
out.Message = in.Message
|
||||
if err := s.Convert(&in.StartedAt, &out.StartedAt, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.Convert(&in.FinishedAt, &out.FinishedAt, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
out.ContainerID = in.ContainerID
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_v1beta3_ContainerStateTerminated_To_api_ContainerStateTerminated(in *ContainerStateTerminated, out *api.ContainerStateTerminated, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*ContainerStateTerminated))(in)
|
||||
}
|
||||
out.ExitCode = in.ExitCode
|
||||
out.Signal = in.Signal
|
||||
out.Reason = in.Reason
|
||||
out.Message = in.Message
|
||||
if err := s.Convert(&in.StartedAt, &out.StartedAt, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.Convert(&in.FinishedAt, &out.FinishedAt, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
out.ContainerID = in.ContainerID
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_v1beta3_StatusDetails_To_api_StatusDetails(in *StatusDetails, out *api.StatusDetails, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*StatusDetails))(in)
|
||||
}
|
||||
out.Name = in.ID
|
||||
out.Kind = in.Kind
|
||||
if in.Causes != nil {
|
||||
out.Causes = make([]api.StatusCause, len(in.Causes))
|
||||
for i := range in.Causes {
|
||||
if err := convert_v1beta3_StatusCause_To_api_StatusCause(&in.Causes[i], &out.Causes[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.Causes = nil
|
||||
}
|
||||
out.RetryAfterSeconds = in.RetryAfterSeconds
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_api_StatusDetails_To_v1beta3_StatusDetails(in *api.StatusDetails, out *StatusDetails, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*api.StatusDetails))(in)
|
||||
}
|
||||
out.ID = in.Name
|
||||
out.Kind = in.Kind
|
||||
if in.Causes != nil {
|
||||
out.Causes = make([]StatusCause, len(in.Causes))
|
||||
for i := range in.Causes {
|
||||
if err := convert_api_StatusCause_To_v1beta3_StatusCause(&in.Causes[i], &out.Causes[i], s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.Causes = nil
|
||||
}
|
||||
out.RetryAfterSeconds = in.RetryAfterSeconds
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_v1beta3_StatusCause_To_api_StatusCause(in *StatusCause, out *api.StatusCause, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*StatusCause))(in)
|
||||
}
|
||||
out.Type = api.CauseType(in.Type)
|
||||
out.Message = in.Message
|
||||
out.Field = in.Field
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_api_StatusCause_To_v1beta3_StatusCause(in *api.StatusCause, out *StatusCause, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*api.StatusCause))(in)
|
||||
}
|
||||
out.Type = CauseType(in.Type)
|
||||
out.Message = in.Message
|
||||
out.Field = in.Field
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_api_ReplicationControllerSpec_To_v1beta3_ReplicationControllerSpec(in *api.ReplicationControllerSpec, out *ReplicationControllerSpec, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*api.ReplicationControllerSpec))(in)
|
||||
}
|
||||
out.Replicas = &in.Replicas
|
||||
if in.Selector != nil {
|
||||
out.Selector = make(map[string]string)
|
||||
for key, val := range in.Selector {
|
||||
out.Selector[key] = val
|
||||
}
|
||||
} else {
|
||||
out.Selector = nil
|
||||
}
|
||||
if in.Template != nil {
|
||||
out.Template = new(PodTemplateSpec)
|
||||
if err := convert_api_PodTemplateSpec_To_v1beta3_PodTemplateSpec(in.Template, out.Template, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.Template = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func convert_v1beta3_ReplicationControllerSpec_To_api_ReplicationControllerSpec(in *ReplicationControllerSpec, out *api.ReplicationControllerSpec, s conversion.Scope) error {
|
||||
if defaulting, found := s.DefaultingInterface(reflect.TypeOf(*in)); found {
|
||||
defaulting.(func(*ReplicationControllerSpec))(in)
|
||||
}
|
||||
out.Replicas = *in.Replicas
|
||||
if in.Selector != nil {
|
||||
out.Selector = make(map[string]string)
|
||||
for key, val := range in.Selector {
|
||||
out.Selector[key] = val
|
||||
}
|
||||
} else {
|
||||
out.Selector = nil
|
||||
}
|
||||
if in.Template != nil {
|
||||
out.Template = new(api.PodTemplateSpec)
|
||||
if err := convert_v1beta3_PodTemplateSpec_To_api_PodTemplateSpec(in.Template, out.Template, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.Template = nil
|
||||
}
|
||||
return nil
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,139 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 v1beta3_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
|
||||
versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||
)
|
||||
|
||||
func TestResourceQuotaStatusConversion(t *testing.T) {
|
||||
// should serialize as "0"
|
||||
expected := resource.NewQuantity(int64(0), resource.DecimalSI)
|
||||
if "0" != expected.String() {
|
||||
t.Errorf("Expected: 0, Actual: %v, do not require units", expected.String())
|
||||
}
|
||||
|
||||
parsed := resource.MustParse("0")
|
||||
if "0" != parsed.String() {
|
||||
t.Errorf("Expected: 0, Actual: %v, do not require units", parsed.String())
|
||||
}
|
||||
|
||||
quota := &api.ResourceQuota{}
|
||||
quota.Status = api.ResourceQuotaStatus{}
|
||||
quota.Status.Hard = api.ResourceList{}
|
||||
quota.Status.Used = api.ResourceList{}
|
||||
quota.Status.Hard[api.ResourcePods] = *expected
|
||||
|
||||
// round-trip the object
|
||||
data, _ := versioned.Codec.Encode(quota)
|
||||
object, _ := versioned.Codec.Decode(data)
|
||||
after := object.(*api.ResourceQuota)
|
||||
actualQuantity := after.Status.Hard[api.ResourcePods]
|
||||
actual := &actualQuantity
|
||||
|
||||
// should be "0", but was "0m"
|
||||
if expected.String() != actual.String() {
|
||||
t.Errorf("Expected %v, Actual %v", expected.String(), actual.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestNodeConversion(t *testing.T) {
|
||||
obj, err := versioned.Codec.Decode([]byte(`{"kind":"Minion","apiVersion":"v1beta3"}`))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if _, ok := obj.(*api.Node); !ok {
|
||||
t.Errorf("unexpected type: %#v", obj)
|
||||
}
|
||||
|
||||
obj, err = versioned.Codec.Decode([]byte(`{"kind":"MinionList","apiVersion":"v1beta3"}`))
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if _, ok := obj.(*api.NodeList); !ok {
|
||||
t.Errorf("unexpected type: %#v", obj)
|
||||
}
|
||||
|
||||
obj = &api.Node{}
|
||||
if err := versioned.Codec.DecodeInto([]byte(`{"kind":"Minion","apiVersion":"v1beta3"}`), obj); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBadSecurityContextConversion(t *testing.T) {
|
||||
priv := false
|
||||
testCases := map[string]struct {
|
||||
c *versioned.Container
|
||||
err string
|
||||
}{
|
||||
// this use case must use true for the container and false for the sc. Otherwise the defaulter
|
||||
// will assume privileged was left undefined (since it is the default value) and copy the
|
||||
// sc setting upwards
|
||||
"mismatched privileged": {
|
||||
c: &versioned.Container{
|
||||
Privileged: true,
|
||||
SecurityContext: &versioned.SecurityContext{
|
||||
Privileged: &priv,
|
||||
},
|
||||
},
|
||||
err: "container privileged settings do not match security context settings, cannot convert",
|
||||
},
|
||||
"mismatched caps add": {
|
||||
c: &versioned.Container{
|
||||
Capabilities: versioned.Capabilities{
|
||||
Add: []versioned.Capability{"foo"},
|
||||
},
|
||||
SecurityContext: &versioned.SecurityContext{
|
||||
Capabilities: &versioned.Capabilities{
|
||||
Add: []versioned.Capability{"bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
err: "container capability settings do not match security context settings, cannot convert",
|
||||
},
|
||||
"mismatched caps drop": {
|
||||
c: &versioned.Container{
|
||||
Capabilities: versioned.Capabilities{
|
||||
Drop: []versioned.Capability{"foo"},
|
||||
},
|
||||
SecurityContext: &versioned.SecurityContext{
|
||||
Capabilities: &versioned.Capabilities{
|
||||
Drop: []versioned.Capability{"bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
err: "container capability settings do not match security context settings, cannot convert",
|
||||
},
|
||||
}
|
||||
|
||||
for k, v := range testCases {
|
||||
got := api.Container{}
|
||||
err := api.Scheme.Convert(v.c, &got)
|
||||
if err == nil {
|
||||
t.Errorf("expected error for case %s but got none", k)
|
||||
} else {
|
||||
if err.Error() != v.err {
|
||||
t.Errorf("unexpected error for case %s. Expected: %s but got: %s", k, v.err, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,218 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 v1beta3
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
func addDefaultingFuncs() {
|
||||
api.Scheme.AddDefaultingFuncs(
|
||||
func(obj *ReplicationController) {
|
||||
var labels map[string]string
|
||||
if obj.Spec.Template != nil {
|
||||
labels = obj.Spec.Template.Labels
|
||||
}
|
||||
// TODO: support templates defined elsewhere when we support them in the API
|
||||
if labels != nil {
|
||||
if len(obj.Spec.Selector) == 0 {
|
||||
obj.Spec.Selector = labels
|
||||
}
|
||||
if len(obj.Labels) == 0 {
|
||||
obj.Labels = labels
|
||||
}
|
||||
}
|
||||
if obj.Spec.Replicas == nil {
|
||||
obj.Spec.Replicas = new(int)
|
||||
*obj.Spec.Replicas = 0
|
||||
}
|
||||
},
|
||||
func(obj *Volume) {
|
||||
if util.AllPtrFieldsNil(&obj.VolumeSource) {
|
||||
obj.VolumeSource = VolumeSource{
|
||||
EmptyDir: &EmptyDirVolumeSource{},
|
||||
}
|
||||
}
|
||||
},
|
||||
func(obj *ContainerPort) {
|
||||
if obj.Protocol == "" {
|
||||
obj.Protocol = ProtocolTCP
|
||||
}
|
||||
},
|
||||
func(obj *Container) {
|
||||
if obj.ImagePullPolicy == "" {
|
||||
// TODO(dchen1107): Move ParseImageName code to pkg/util
|
||||
parts := strings.Split(obj.Image, ":")
|
||||
// Check image tag
|
||||
if parts[len(parts)-1] == "latest" {
|
||||
obj.ImagePullPolicy = PullAlways
|
||||
} else {
|
||||
obj.ImagePullPolicy = PullIfNotPresent
|
||||
}
|
||||
}
|
||||
if obj.TerminationMessagePath == "" {
|
||||
obj.TerminationMessagePath = TerminationMessagePathDefault
|
||||
}
|
||||
defaultSecurityContext(obj)
|
||||
},
|
||||
func(obj *ServiceSpec) {
|
||||
if obj.SessionAffinity == "" {
|
||||
obj.SessionAffinity = ServiceAffinityNone
|
||||
}
|
||||
if obj.Type == "" {
|
||||
if obj.CreateExternalLoadBalancer {
|
||||
obj.Type = ServiceTypeLoadBalancer
|
||||
} else {
|
||||
obj.Type = ServiceTypeClusterIP
|
||||
}
|
||||
} else if obj.Type == ServiceTypeLoadBalancer {
|
||||
obj.CreateExternalLoadBalancer = true
|
||||
}
|
||||
for i := range obj.Ports {
|
||||
sp := &obj.Ports[i]
|
||||
if sp.Protocol == "" {
|
||||
sp.Protocol = ProtocolTCP
|
||||
}
|
||||
if sp.TargetPort == util.NewIntOrStringFromInt(0) || sp.TargetPort == util.NewIntOrStringFromString("") {
|
||||
sp.TargetPort = util.NewIntOrStringFromInt(sp.Port)
|
||||
}
|
||||
}
|
||||
},
|
||||
func(obj *PodSpec) {
|
||||
if obj.DNSPolicy == "" {
|
||||
obj.DNSPolicy = DNSClusterFirst
|
||||
}
|
||||
if obj.RestartPolicy == "" {
|
||||
obj.RestartPolicy = RestartPolicyAlways
|
||||
}
|
||||
if obj.HostNetwork {
|
||||
defaultHostNetworkPorts(&obj.Containers)
|
||||
}
|
||||
},
|
||||
func(obj *Probe) {
|
||||
if obj.TimeoutSeconds == 0 {
|
||||
obj.TimeoutSeconds = 1
|
||||
}
|
||||
},
|
||||
func(obj *Secret) {
|
||||
if obj.Type == "" {
|
||||
obj.Type = SecretTypeOpaque
|
||||
}
|
||||
},
|
||||
func(obj *PersistentVolume) {
|
||||
if obj.Status.Phase == "" {
|
||||
obj.Status.Phase = VolumePending
|
||||
}
|
||||
if obj.Spec.PersistentVolumeReclaimPolicy == "" {
|
||||
obj.Spec.PersistentVolumeReclaimPolicy = PersistentVolumeReclaimRetain
|
||||
}
|
||||
},
|
||||
func(obj *PersistentVolumeClaim) {
|
||||
if obj.Status.Phase == "" {
|
||||
obj.Status.Phase = ClaimPending
|
||||
}
|
||||
},
|
||||
func(obj *Endpoints) {
|
||||
for i := range obj.Subsets {
|
||||
ss := &obj.Subsets[i]
|
||||
for i := range ss.Ports {
|
||||
ep := &ss.Ports[i]
|
||||
if ep.Protocol == "" {
|
||||
ep.Protocol = ProtocolTCP
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
func(obj *HTTPGetAction) {
|
||||
if obj.Path == "" {
|
||||
obj.Path = "/"
|
||||
}
|
||||
if obj.Scheme == "" {
|
||||
obj.Scheme = URISchemeHTTP
|
||||
}
|
||||
},
|
||||
func(obj *NamespaceStatus) {
|
||||
if obj.Phase == "" {
|
||||
obj.Phase = NamespaceActive
|
||||
}
|
||||
},
|
||||
func(obj *Node) {
|
||||
if obj.Spec.ExternalID == "" {
|
||||
obj.Spec.ExternalID = obj.Name
|
||||
}
|
||||
},
|
||||
func(obj *ObjectFieldSelector) {
|
||||
if obj.APIVersion == "" {
|
||||
obj.APIVersion = "v1beta3"
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// With host networking default all container ports to host ports.
|
||||
func defaultHostNetworkPorts(containers *[]Container) {
|
||||
for i := range *containers {
|
||||
for j := range (*containers)[i].Ports {
|
||||
if (*containers)[i].Ports[j].HostPort == 0 {
|
||||
(*containers)[i].Ports[j].HostPort = (*containers)[i].Ports[j].ContainerPort
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// defaultSecurityContext performs the downward and upward merges of a pod definition
|
||||
func defaultSecurityContext(container *Container) {
|
||||
if container.SecurityContext == nil {
|
||||
if (len(container.Capabilities.Add) == 0) && (len(container.Capabilities.Drop) == 0) && (container.Privileged == false) {
|
||||
return
|
||||
}
|
||||
glog.V(5).Infof("creating security context for container %s", container.Name)
|
||||
container.SecurityContext = &SecurityContext{}
|
||||
}
|
||||
// if there are no capabilities defined on the SecurityContext then copy the container settings
|
||||
if container.SecurityContext.Capabilities == nil {
|
||||
container.SecurityContext.Capabilities = &container.Capabilities
|
||||
} else {
|
||||
// if there are capabilities defined on the security context and the container setting is
|
||||
// empty then assume that it was left off the pod definition and ensure that the container
|
||||
// settings match the security context settings (checked by the convert functions). If
|
||||
// there are settings in both then don't touch it, the converter will error if they don't
|
||||
// match
|
||||
if len(container.Capabilities.Add) == 0 {
|
||||
container.Capabilities.Add = container.SecurityContext.Capabilities.Add
|
||||
}
|
||||
if len(container.Capabilities.Drop) == 0 {
|
||||
container.Capabilities.Drop = container.SecurityContext.Capabilities.Drop
|
||||
}
|
||||
}
|
||||
// if there are no privileged settings on the security context then copy the container settings
|
||||
if container.SecurityContext.Privileged == nil {
|
||||
container.SecurityContext.Privileged = &container.Privileged
|
||||
} else {
|
||||
// we don't have a good way to know if container.Privileged was set or just defaulted to false
|
||||
// so the best we can do here is check if the securityContext is set to true and the
|
||||
// container is set to false and assume that the Privileged field was left off the container
|
||||
// definition and not an intentional mismatch
|
||||
if *container.SecurityContext.Privileged && !container.Privileged {
|
||||
container.Privileged = *container.SecurityContext.Privileged
|
||||
}
|
||||
}
|
||||
}
|
@ -1,471 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 v1beta3_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
versioned "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
)
|
||||
|
||||
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
|
||||
data, err := versioned.Codec.Encode(obj)
|
||||
if err != nil {
|
||||
t.Errorf("%v\n %#v", err, obj)
|
||||
return nil
|
||||
}
|
||||
obj2, err := api.Codec.Decode(data)
|
||||
if err != nil {
|
||||
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
|
||||
return nil
|
||||
}
|
||||
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
|
||||
err = api.Scheme.Convert(obj2, obj3)
|
||||
if err != nil {
|
||||
t.Errorf("%v\nSource: %#v", err, obj2)
|
||||
return nil
|
||||
}
|
||||
return obj3
|
||||
}
|
||||
|
||||
func TestSetDefaultReplicationController(t *testing.T) {
|
||||
tests := []struct {
|
||||
rc *versioned.ReplicationController
|
||||
expectLabels bool
|
||||
expectSelector bool
|
||||
}{
|
||||
{
|
||||
rc: &versioned.ReplicationController{
|
||||
Spec: versioned.ReplicationControllerSpec{
|
||||
Template: &versioned.PodTemplateSpec{
|
||||
ObjectMeta: versioned.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
expectSelector: true,
|
||||
},
|
||||
{
|
||||
rc: &versioned.ReplicationController{
|
||||
ObjectMeta: versioned.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"bar": "foo",
|
||||
},
|
||||
},
|
||||
Spec: versioned.ReplicationControllerSpec{
|
||||
Template: &versioned.PodTemplateSpec{
|
||||
ObjectMeta: versioned.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectLabels: false,
|
||||
expectSelector: true,
|
||||
},
|
||||
{
|
||||
rc: &versioned.ReplicationController{
|
||||
ObjectMeta: versioned.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"bar": "foo",
|
||||
},
|
||||
},
|
||||
Spec: versioned.ReplicationControllerSpec{
|
||||
Selector: map[string]string{
|
||||
"some": "other",
|
||||
},
|
||||
Template: &versioned.PodTemplateSpec{
|
||||
ObjectMeta: versioned.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectLabels: false,
|
||||
expectSelector: false,
|
||||
},
|
||||
{
|
||||
rc: &versioned.ReplicationController{
|
||||
Spec: versioned.ReplicationControllerSpec{
|
||||
Selector: map[string]string{
|
||||
"some": "other",
|
||||
},
|
||||
Template: &versioned.PodTemplateSpec{
|
||||
ObjectMeta: versioned.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectLabels: true,
|
||||
expectSelector: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
rc := test.rc
|
||||
obj2 := roundTrip(t, runtime.Object(rc))
|
||||
rc2, ok := obj2.(*versioned.ReplicationController)
|
||||
if !ok {
|
||||
t.Errorf("unexpected object: %v", rc2)
|
||||
t.FailNow()
|
||||
}
|
||||
if test.expectSelector != reflect.DeepEqual(rc2.Spec.Selector, rc2.Spec.Template.Labels) {
|
||||
if test.expectSelector {
|
||||
t.Errorf("expected: %v, got: %v", rc2.Spec.Template.Labels, rc2.Spec.Selector)
|
||||
} else {
|
||||
t.Errorf("unexpected equality: %v", rc.Spec.Selector)
|
||||
}
|
||||
}
|
||||
if test.expectLabels != reflect.DeepEqual(rc2.Labels, rc2.Spec.Template.Labels) {
|
||||
if test.expectLabels {
|
||||
t.Errorf("expected: %v, got: %v", rc2.Spec.Template.Labels, rc2.Labels)
|
||||
} else {
|
||||
t.Errorf("unexpected equality: %v", rc.Labels)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultService(t *testing.T) {
|
||||
svc := &versioned.Service{}
|
||||
obj2 := roundTrip(t, runtime.Object(svc))
|
||||
svc2 := obj2.(*versioned.Service)
|
||||
if svc2.Spec.SessionAffinity != versioned.ServiceAffinityNone {
|
||||
t.Errorf("Expected default session affinity type:%s, got: %s", versioned.ServiceAffinityNone, svc2.Spec.SessionAffinity)
|
||||
}
|
||||
if svc2.Spec.Type != versioned.ServiceTypeClusterIP {
|
||||
t.Errorf("Expected default type:%s, got: %s", versioned.ServiceTypeClusterIP, svc2.Spec.Type)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultServiceWithLoadbalancer(t *testing.T) {
|
||||
svc := &versioned.Service{}
|
||||
svc.Spec.CreateExternalLoadBalancer = true
|
||||
obj2 := roundTrip(t, runtime.Object(svc))
|
||||
svc2 := obj2.(*versioned.Service)
|
||||
if svc2.Spec.Type != versioned.ServiceTypeLoadBalancer {
|
||||
t.Errorf("Expected default type:%s, got: %s", versioned.ServiceTypeLoadBalancer, svc2.Spec.Type)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultSecret(t *testing.T) {
|
||||
s := &versioned.Secret{}
|
||||
obj2 := roundTrip(t, runtime.Object(s))
|
||||
s2 := obj2.(*versioned.Secret)
|
||||
|
||||
if s2.Type != versioned.SecretTypeOpaque {
|
||||
t.Errorf("Expected secret type %v, got %v", versioned.SecretTypeOpaque, s2.Type)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultPersistentVolume(t *testing.T) {
|
||||
pv := &versioned.PersistentVolume{}
|
||||
obj2 := roundTrip(t, runtime.Object(pv))
|
||||
pv2 := obj2.(*versioned.PersistentVolume)
|
||||
|
||||
if pv2.Status.Phase != versioned.VolumePending {
|
||||
t.Errorf("Expected volume phase %v, got %v", versioned.VolumePending, pv2.Status.Phase)
|
||||
}
|
||||
if pv2.Spec.PersistentVolumeReclaimPolicy != versioned.PersistentVolumeReclaimRetain {
|
||||
t.Errorf("Expected pv reclaim policy %v, got %v", versioned.PersistentVolumeReclaimRetain, pv2.Spec.PersistentVolumeReclaimPolicy)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultPersistentVolumeClaim(t *testing.T) {
|
||||
pvc := &versioned.PersistentVolumeClaim{}
|
||||
obj2 := roundTrip(t, runtime.Object(pvc))
|
||||
pvc2 := obj2.(*versioned.PersistentVolumeClaim)
|
||||
|
||||
if pvc2.Status.Phase != versioned.ClaimPending {
|
||||
t.Errorf("Expected claim phase %v, got %v", versioned.ClaimPending, pvc2.Status.Phase)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaulEndpointsProtocol(t *testing.T) {
|
||||
in := &versioned.Endpoints{Subsets: []versioned.EndpointSubset{
|
||||
{Ports: []versioned.EndpointPort{{}, {Protocol: "UDP"}, {}}},
|
||||
}}
|
||||
obj := roundTrip(t, runtime.Object(in))
|
||||
out := obj.(*versioned.Endpoints)
|
||||
|
||||
for i := range out.Subsets {
|
||||
for j := range out.Subsets[i].Ports {
|
||||
if in.Subsets[i].Ports[j].Protocol == "" {
|
||||
if out.Subsets[i].Ports[j].Protocol != versioned.ProtocolTCP {
|
||||
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Subsets[i].Ports[j].Protocol)
|
||||
}
|
||||
} else {
|
||||
if out.Subsets[i].Ports[j].Protocol != in.Subsets[i].Ports[j].Protocol {
|
||||
t.Errorf("Expected protocol %s, got %s", in.Subsets[i].Ports[j].Protocol, out.Subsets[i].Ports[j].Protocol)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaulServiceTargetPort(t *testing.T) {
|
||||
in := &versioned.Service{Spec: versioned.ServiceSpec{Ports: []versioned.ServicePort{{Port: 1234}}}}
|
||||
obj := roundTrip(t, runtime.Object(in))
|
||||
out := obj.(*versioned.Service)
|
||||
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(1234) {
|
||||
t.Errorf("Expected TargetPort to be defaulted, got %s", out.Spec.Ports[0].TargetPort)
|
||||
}
|
||||
|
||||
in = &versioned.Service{Spec: versioned.ServiceSpec{Ports: []versioned.ServicePort{{Port: 1234, TargetPort: util.NewIntOrStringFromInt(5678)}}}}
|
||||
obj = roundTrip(t, runtime.Object(in))
|
||||
out = obj.(*versioned.Service)
|
||||
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(5678) {
|
||||
t.Errorf("Expected TargetPort to be unchanged, got %s", out.Spec.Ports[0].TargetPort)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultServicePort(t *testing.T) {
|
||||
// Unchanged if set.
|
||||
in := &versioned.Service{Spec: versioned.ServiceSpec{
|
||||
Ports: []versioned.ServicePort{
|
||||
{Protocol: "UDP", Port: 9376, TargetPort: util.NewIntOrStringFromString("p")},
|
||||
{Protocol: "UDP", Port: 8675, TargetPort: util.NewIntOrStringFromInt(309)},
|
||||
},
|
||||
}}
|
||||
out := roundTrip(t, runtime.Object(in)).(*versioned.Service)
|
||||
if out.Spec.Ports[0].Protocol != versioned.ProtocolUDP {
|
||||
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Spec.Ports[0].Protocol)
|
||||
}
|
||||
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromString("p") {
|
||||
t.Errorf("Expected port %d, got %s", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
|
||||
}
|
||||
if out.Spec.Ports[1].Protocol != versioned.ProtocolUDP {
|
||||
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolUDP, out.Spec.Ports[1].Protocol)
|
||||
}
|
||||
if out.Spec.Ports[1].TargetPort != util.NewIntOrStringFromInt(309) {
|
||||
t.Errorf("Expected port %d, got %s", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
|
||||
}
|
||||
|
||||
// Defaulted.
|
||||
in = &versioned.Service{Spec: versioned.ServiceSpec{
|
||||
Ports: []versioned.ServicePort{
|
||||
{Protocol: "", Port: 9376, TargetPort: util.NewIntOrStringFromString("")},
|
||||
{Protocol: "", Port: 8675, TargetPort: util.NewIntOrStringFromInt(0)},
|
||||
},
|
||||
}}
|
||||
out = roundTrip(t, runtime.Object(in)).(*versioned.Service)
|
||||
if out.Spec.Ports[0].Protocol != versioned.ProtocolTCP {
|
||||
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[0].Protocol)
|
||||
}
|
||||
if out.Spec.Ports[0].TargetPort != util.NewIntOrStringFromInt(in.Spec.Ports[0].Port) {
|
||||
t.Errorf("Expected port %d, got %d", in.Spec.Ports[0].Port, out.Spec.Ports[0].TargetPort)
|
||||
}
|
||||
if out.Spec.Ports[1].Protocol != versioned.ProtocolTCP {
|
||||
t.Errorf("Expected protocol %s, got %s", versioned.ProtocolTCP, out.Spec.Ports[1].Protocol)
|
||||
}
|
||||
if out.Spec.Ports[1].TargetPort != util.NewIntOrStringFromInt(in.Spec.Ports[1].Port) {
|
||||
t.Errorf("Expected port %d, got %d", in.Spec.Ports[1].Port, out.Spec.Ports[1].TargetPort)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultNamespace(t *testing.T) {
|
||||
s := &versioned.Namespace{}
|
||||
obj2 := roundTrip(t, runtime.Object(s))
|
||||
s2 := obj2.(*versioned.Namespace)
|
||||
|
||||
if s2.Status.Phase != versioned.NamespaceActive {
|
||||
t.Errorf("Expected phase %v, got %v", versioned.NamespaceActive, s2.Status.Phase)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultPodSpecHostNetwork(t *testing.T) {
|
||||
portNum := 8080
|
||||
s := versioned.PodSpec{}
|
||||
s.HostNetwork = true
|
||||
s.Containers = []versioned.Container{
|
||||
{
|
||||
Ports: []versioned.ContainerPort{
|
||||
{
|
||||
ContainerPort: portNum,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
pod := &versioned.Pod{
|
||||
Spec: s,
|
||||
}
|
||||
obj2 := roundTrip(t, runtime.Object(pod))
|
||||
pod2 := obj2.(*versioned.Pod)
|
||||
s2 := pod2.Spec
|
||||
|
||||
hostPortNum := s2.Containers[0].Ports[0].HostPort
|
||||
if hostPortNum != portNum {
|
||||
t.Errorf("Expected container port to be defaulted, was made %d instead of %d", hostPortNum, portNum)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultNodeExternalID(t *testing.T) {
|
||||
name := "node0"
|
||||
n := &versioned.Node{}
|
||||
n.Name = name
|
||||
obj2 := roundTrip(t, runtime.Object(n))
|
||||
n2 := obj2.(*versioned.Node)
|
||||
if n2.Spec.ExternalID != name {
|
||||
t.Errorf("Expected default External ID: %s, got: %s", name, n2.Spec.ExternalID)
|
||||
}
|
||||
if n2.Spec.ProviderID != "" {
|
||||
t.Errorf("Expected empty default Cloud Provider ID, got: %s", n2.Spec.ProviderID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultObjectFieldSelectorAPIVersion(t *testing.T) {
|
||||
s := versioned.PodSpec{
|
||||
Containers: []versioned.Container{
|
||||
{
|
||||
Env: []versioned.EnvVar{
|
||||
{
|
||||
ValueFrom: &versioned.EnvVarSource{
|
||||
FieldRef: &versioned.ObjectFieldSelector{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
pod := &versioned.Pod{
|
||||
Spec: s,
|
||||
}
|
||||
obj2 := roundTrip(t, runtime.Object(pod))
|
||||
pod2 := obj2.(*versioned.Pod)
|
||||
s2 := pod2.Spec
|
||||
|
||||
apiVersion := s2.Containers[0].Env[0].ValueFrom.FieldRef.APIVersion
|
||||
if apiVersion != "v1beta3" {
|
||||
t.Errorf("Expected default APIVersion v1beta3, got: %v", apiVersion)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetDefaultSecurityContext(t *testing.T) {
|
||||
priv := false
|
||||
privTrue := true
|
||||
testCases := map[string]struct {
|
||||
c versioned.Container
|
||||
}{
|
||||
"downward defaulting caps": {
|
||||
c: versioned.Container{
|
||||
Privileged: false,
|
||||
Capabilities: versioned.Capabilities{
|
||||
Add: []versioned.Capability{"foo"},
|
||||
Drop: []versioned.Capability{"bar"},
|
||||
},
|
||||
SecurityContext: &versioned.SecurityContext{
|
||||
Privileged: &priv,
|
||||
},
|
||||
},
|
||||
},
|
||||
"downward defaulting priv": {
|
||||
c: versioned.Container{
|
||||
Privileged: false,
|
||||
Capabilities: versioned.Capabilities{
|
||||
Add: []versioned.Capability{"foo"},
|
||||
Drop: []versioned.Capability{"bar"},
|
||||
},
|
||||
SecurityContext: &versioned.SecurityContext{
|
||||
Capabilities: &versioned.Capabilities{
|
||||
Add: []versioned.Capability{"foo"},
|
||||
Drop: []versioned.Capability{"bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"upward defaulting caps": {
|
||||
c: versioned.Container{
|
||||
Privileged: false,
|
||||
SecurityContext: &versioned.SecurityContext{
|
||||
Privileged: &priv,
|
||||
Capabilities: &versioned.Capabilities{
|
||||
Add: []versioned.Capability{"biz"},
|
||||
Drop: []versioned.Capability{"baz"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"upward defaulting priv": {
|
||||
c: versioned.Container{
|
||||
Capabilities: versioned.Capabilities{
|
||||
Add: []versioned.Capability{"foo"},
|
||||
Drop: []versioned.Capability{"bar"},
|
||||
},
|
||||
SecurityContext: &versioned.SecurityContext{
|
||||
Privileged: &privTrue,
|
||||
Capabilities: &versioned.Capabilities{
|
||||
Add: []versioned.Capability{"foo"},
|
||||
Drop: []versioned.Capability{"bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
pod := &versioned.Pod{
|
||||
Spec: versioned.PodSpec{},
|
||||
}
|
||||
|
||||
for k, v := range testCases {
|
||||
pod.Spec.Containers = []versioned.Container{v.c}
|
||||
obj := roundTrip(t, runtime.Object(pod))
|
||||
defaultedPod := obj.(*versioned.Pod)
|
||||
c := defaultedPod.Spec.Containers[0]
|
||||
if isEqual, issues := areSecurityContextAndContainerEqual(&c); !isEqual {
|
||||
t.Errorf("test case %s expected the security context to have the same values as the container but found %#v", k, issues)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func areSecurityContextAndContainerEqual(c *versioned.Container) (bool, []string) {
|
||||
issues := make([]string, 0)
|
||||
equal := true
|
||||
|
||||
if c.SecurityContext == nil || c.SecurityContext.Privileged == nil || c.SecurityContext.Capabilities == nil {
|
||||
equal = false
|
||||
issues = append(issues, "Expected non nil settings for SecurityContext")
|
||||
return equal, issues
|
||||
}
|
||||
if *c.SecurityContext.Privileged != c.Privileged {
|
||||
equal = false
|
||||
issues = append(issues, "The defaulted SecurityContext.Privileged value did not match the container value")
|
||||
}
|
||||
if !reflect.DeepEqual(c.Capabilities.Add, c.Capabilities.Add) {
|
||||
equal = false
|
||||
issues = append(issues, "The defaulted SecurityContext.Capabilities.Add did not match the container settings")
|
||||
}
|
||||
if !reflect.DeepEqual(c.Capabilities.Drop, c.Capabilities.Drop) {
|
||||
equal = false
|
||||
issues = append(issues, "The defaulted SecurityContext.Capabilities.Drop did not match the container settings")
|
||||
}
|
||||
return equal, issues
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 v1beta3 is the v1beta3 version of the API.
|
||||
package v1beta3
|
@ -1,130 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 v1beta3
|
||||
|
||||
import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/registered"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
)
|
||||
|
||||
// Codec encodes internal objects to the v1beta3 scheme
|
||||
var Codec = runtime.CodecFor(api.Scheme, "v1beta3")
|
||||
|
||||
func init() {
|
||||
// Check if v1beta3 is in the list of supported API versions.
|
||||
if !registered.IsRegisteredAPIVersion("v1beta3") {
|
||||
return
|
||||
}
|
||||
|
||||
// Register the API.
|
||||
addKnownTypes()
|
||||
addConversionFuncs()
|
||||
addDefaultingFuncs()
|
||||
}
|
||||
|
||||
// Adds the list of known types to api.Scheme.
|
||||
func addKnownTypes() {
|
||||
api.Scheme.AddKnownTypes("v1beta3",
|
||||
&Pod{},
|
||||
&PodList{},
|
||||
&PodStatusResult{},
|
||||
&PodTemplate{},
|
||||
&PodTemplateList{},
|
||||
&ReplicationController{},
|
||||
&ReplicationControllerList{},
|
||||
&Service{},
|
||||
&ServiceList{},
|
||||
&Endpoints{},
|
||||
&EndpointsList{},
|
||||
&Node{},
|
||||
&NodeList{},
|
||||
&Binding{},
|
||||
&Status{},
|
||||
&Event{},
|
||||
&EventList{},
|
||||
&List{},
|
||||
&LimitRange{},
|
||||
&LimitRangeList{},
|
||||
&ResourceQuota{},
|
||||
&ResourceQuotaList{},
|
||||
&Namespace{},
|
||||
&NamespaceList{},
|
||||
&Secret{},
|
||||
&SecretList{},
|
||||
&ServiceAccount{},
|
||||
&ServiceAccountList{},
|
||||
&PersistentVolume{},
|
||||
&PersistentVolumeList{},
|
||||
&PersistentVolumeClaim{},
|
||||
&PersistentVolumeClaimList{},
|
||||
&DeleteOptions{},
|
||||
&ListOptions{},
|
||||
&PodLogOptions{},
|
||||
&PodExecOptions{},
|
||||
&PodProxyOptions{},
|
||||
&ComponentStatus{},
|
||||
&ComponentStatusList{},
|
||||
&SerializedReference{},
|
||||
&RangeAllocation{},
|
||||
)
|
||||
// Legacy names are supported
|
||||
api.Scheme.AddKnownTypeWithName("v1beta3", "Minion", &Node{})
|
||||
api.Scheme.AddKnownTypeWithName("v1beta3", "MinionList", &NodeList{})
|
||||
}
|
||||
|
||||
func (*Pod) IsAnAPIObject() {}
|
||||
func (*PodList) IsAnAPIObject() {}
|
||||
func (*PodStatusResult) IsAnAPIObject() {}
|
||||
func (*PodTemplate) IsAnAPIObject() {}
|
||||
func (*PodTemplateList) IsAnAPIObject() {}
|
||||
func (*ReplicationController) IsAnAPIObject() {}
|
||||
func (*ReplicationControllerList) IsAnAPIObject() {}
|
||||
func (*Service) IsAnAPIObject() {}
|
||||
func (*ServiceList) IsAnAPIObject() {}
|
||||
func (*Endpoints) IsAnAPIObject() {}
|
||||
func (*EndpointsList) IsAnAPIObject() {}
|
||||
func (*Node) IsAnAPIObject() {}
|
||||
func (*NodeList) IsAnAPIObject() {}
|
||||
func (*Binding) IsAnAPIObject() {}
|
||||
func (*Status) IsAnAPIObject() {}
|
||||
func (*Event) IsAnAPIObject() {}
|
||||
func (*EventList) IsAnAPIObject() {}
|
||||
func (*List) IsAnAPIObject() {}
|
||||
func (*LimitRange) IsAnAPIObject() {}
|
||||
func (*LimitRangeList) IsAnAPIObject() {}
|
||||
func (*ResourceQuota) IsAnAPIObject() {}
|
||||
func (*ResourceQuotaList) IsAnAPIObject() {}
|
||||
func (*Namespace) IsAnAPIObject() {}
|
||||
func (*NamespaceList) IsAnAPIObject() {}
|
||||
func (*Secret) IsAnAPIObject() {}
|
||||
func (*SecretList) IsAnAPIObject() {}
|
||||
func (*ServiceAccount) IsAnAPIObject() {}
|
||||
func (*ServiceAccountList) IsAnAPIObject() {}
|
||||
func (*PersistentVolume) IsAnAPIObject() {}
|
||||
func (*PersistentVolumeList) IsAnAPIObject() {}
|
||||
func (*PersistentVolumeClaim) IsAnAPIObject() {}
|
||||
func (*PersistentVolumeClaimList) IsAnAPIObject() {}
|
||||
func (*DeleteOptions) IsAnAPIObject() {}
|
||||
func (*ListOptions) IsAnAPIObject() {}
|
||||
func (*PodLogOptions) IsAnAPIObject() {}
|
||||
func (*PodExecOptions) IsAnAPIObject() {}
|
||||
func (*PodProxyOptions) IsAnAPIObject() {}
|
||||
func (*ComponentStatus) IsAnAPIObject() {}
|
||||
func (*ComponentStatusList) IsAnAPIObject() {}
|
||||
func (*SerializedReference) IsAnAPIObject() {}
|
||||
func (*RangeAllocation) IsAnAPIObject() {}
|
File diff suppressed because it is too large
Load Diff
@ -1,11 +0,0 @@
|
||||
apiVersion: v1beta3
|
||||
kind: Pod
|
||||
metadata:
|
||||
labels:
|
||||
name: redis-master
|
||||
name: name
|
||||
spec:
|
||||
containers:
|
||||
- args: "this is a bad command"
|
||||
image: redis
|
||||
name: master
|
@ -1,19 +0,0 @@
|
||||
{
|
||||
"kind": "Pod",
|
||||
"apiVersion": "v1beta3",
|
||||
"metadata": {
|
||||
"name": "name",
|
||||
"labels": {
|
||||
"name": "redis-master"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"containers": [
|
||||
{
|
||||
"name": "master",
|
||||
"image": "redis",
|
||||
"args": "this is a bad command"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
{
|
||||
"kind": "Pod",
|
||||
"apiVersion": "v1beta3",
|
||||
"metadata": {
|
||||
"name": "apache-php",
|
||||
"labels": {
|
||||
"name": "apache-php"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"volumes": [{
|
||||
"name": "shared-disk"
|
||||
}],
|
||||
"containers": [
|
||||
{
|
||||
"name": "apache-php",
|
||||
"image": "php:5.6.2-apache",
|
||||
"ports": [
|
||||
{
|
||||
"name": "apache",
|
||||
"hostPort": "13380",
|
||||
"containerPort": 80,
|
||||
"protocol": "TCP"
|
||||
}
|
||||
],
|
||||
"volumeMounts": [
|
||||
{
|
||||
"name": "shared-disk",
|
||||
"mountPath": "/var/www/html"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
{
|
||||
"kind": "Pod",
|
||||
"apiVersion": "v1beta3",
|
||||
"metadata": {
|
||||
"name": "apache-php",
|
||||
"labels": {
|
||||
"name": "apache-php"
|
||||
}
|
||||
},
|
||||
"spec": {
|
||||
"volumes": [
|
||||
"name": "shared-disk"
|
||||
],
|
||||
"containers": [
|
||||
{
|
||||
"name": "apache-php",
|
||||
"image": "php:5.6.2-apache",
|
||||
"ports": [
|
||||
{
|
||||
"name": "apache",
|
||||
"hostPort": 13380,
|
||||
"containerPort": 80,
|
||||
"protocol": "TCP"
|
||||
}
|
||||
],
|
||||
"volumeMounts": [
|
||||
{
|
||||
"name": "shared-disk",
|
||||
"mountPath": "/var/www/html"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
apiVersion: v1beta3
|
||||
kind: Pod
|
||||
metadata:
|
||||
labels:
|
||||
name: redis-master
|
||||
name: name
|
||||
spec:
|
||||
containers:
|
||||
- args:
|
||||
- this
|
||||
- is
|
||||
- an
|
||||
- ok
|
||||
- command
|
||||
image: redis
|
||||
name: master
|
@ -81,7 +81,7 @@ type APIGroupVersion struct {
|
||||
|
||||
// ServerVersion controls the Kubernetes APIVersion used for common objects in the apiserver
|
||||
// schema like api.Status, api.DeleteOptions, and api.ListOptions. Other implementors may
|
||||
// define a version "v1beta1" but want to use the Kubernetes "v1beta3" internal objects. If
|
||||
// define a version "v1beta1" but want to use the Kubernetes "v1" internal objects. If
|
||||
// empty, defaults to Version.
|
||||
ServerVersion string
|
||||
|
||||
|
@ -177,7 +177,7 @@ func handle(storage map[string]rest.Storage) http.Handler {
|
||||
return handleInternal(true, storage, admissionControl, selfLinker)
|
||||
}
|
||||
|
||||
// uses the default settings for a v1beta3 compatible api
|
||||
// uses the default settings for a v1 compatible api
|
||||
func handleNew(storage map[string]rest.Storage) http.Handler {
|
||||
return handleInternal(false, storage, admissionControl, selfLinker)
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ type Cluster struct {
|
||||
LocationOfOrigin string
|
||||
// Server is the address of the kubernetes cluster (https://hostname:port).
|
||||
Server string `json:"server"`
|
||||
// APIVersion is the preferred api version for communicating with the kubernetes cluster (v1beta1, v1beta2, v1beta3, etc).
|
||||
// APIVersion is the preferred api version for communicating with the kubernetes cluster (v1, v2, etc).
|
||||
APIVersion string `json:"api-version,omitempty"`
|
||||
// InsecureSkipTLSVerify skips the validity check for the server's certificate. This will make your HTTPS connections insecure.
|
||||
InsecureSkipTLSVerify bool `json:"insecure-skip-tls-verify,omitempty"`
|
||||
|
@ -54,7 +54,7 @@ type Preferences struct {
|
||||
type Cluster struct {
|
||||
// Server is the address of the kubernetes cluster (https://hostname:port).
|
||||
Server string `json:"server"`
|
||||
// APIVersion is the preferred api version for communicating with the kubernetes cluster (v1beta1, v1beta2, v1beta3, etc).
|
||||
// APIVersion is the preferred api version for communicating with the kubernetes cluster (v1, v2, etc).
|
||||
APIVersion string `json:"api-version,omitempty"`
|
||||
// InsecureSkipTLSVerify skips the validity check for the server's certificate. This will make your HTTPS connections insecure.
|
||||
InsecureSkipTLSVerify bool `json:"insecure-skip-tls-verify,omitempty"`
|
||||
|
@ -312,40 +312,6 @@ func (v versionToResourceToFieldMapping) filterField(apiVersion, resourceType, f
|
||||
}
|
||||
|
||||
var fieldMappings = versionToResourceToFieldMapping{
|
||||
"v1beta3": resourceTypeToFieldMapping{
|
||||
"nodes": clientFieldNameToAPIVersionFieldName{
|
||||
ObjectNameField: "metadata.name",
|
||||
NodeUnschedulable: "spec.unschedulable",
|
||||
},
|
||||
"minions": clientFieldNameToAPIVersionFieldName{
|
||||
ObjectNameField: "metadata.name",
|
||||
NodeUnschedulable: "spec.unschedulable",
|
||||
},
|
||||
"pods": clientFieldNameToAPIVersionFieldName{
|
||||
PodHost: "spec.host",
|
||||
},
|
||||
"secrets": clientFieldNameToAPIVersionFieldName{
|
||||
SecretType: "type",
|
||||
},
|
||||
"serviceAccounts": clientFieldNameToAPIVersionFieldName{
|
||||
ObjectNameField: "metadata.name",
|
||||
},
|
||||
"endpoints": clientFieldNameToAPIVersionFieldName{
|
||||
ObjectNameField: "metadata.name",
|
||||
},
|
||||
"events": clientFieldNameToAPIVersionFieldName{
|
||||
ObjectNameField: "metadata.name",
|
||||
EventReason: "reason",
|
||||
EventSource: "source",
|
||||
EventInvolvedKind: "involvedObject.kind",
|
||||
EventInvolvedNamespace: "involvedObject.namespace",
|
||||
EventInvolvedName: "involvedObject.name",
|
||||
EventInvolvedUID: "involvedObject.uid",
|
||||
EventInvolvedAPIVersion: "involvedObject.apiVersion",
|
||||
EventInvolvedResourceVersion: "involvedObject.resourceVersion",
|
||||
EventInvolvedFieldPath: "involvedObject.fieldPath",
|
||||
},
|
||||
},
|
||||
"v1": resourceTypeToFieldMapping{
|
||||
"nodes": clientFieldNameToAPIVersionFieldName{
|
||||
ObjectNameField: "metadata.name",
|
||||
|
@ -1049,13 +1049,6 @@ func TestUnversionedPath(t *testing.T) {
|
||||
t.Errorf("test case %d failed: unexpected path: %s, expected %s", i+1, r.path, tc.expectedPath)
|
||||
}
|
||||
}
|
||||
for i, tc := range tt {
|
||||
c := NewOrDie(&Config{Host: tc.host, Prefix: tc.prefix, Version: "v1beta3"})
|
||||
r := c.Post().Prefix("/alpha").UnversionedPath(tc.unversioned)
|
||||
if r.path != tc.expectedPath {
|
||||
t.Errorf("test case %d failed: unexpected path: %s, expected %s", i+1, r.path, tc.expectedPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAbsPath(t *testing.T) {
|
||||
|
@ -238,7 +238,7 @@ func TestGetSchemaObject(t *testing.T) {
|
||||
Resp: &http.Response{StatusCode: 200, Body: objBody(codec, &api.ReplicationController{ObjectMeta: api.ObjectMeta{Name: "foo"}})},
|
||||
}
|
||||
tf.Namespace = "test"
|
||||
tf.ClientConfig = &client.Config{Version: "v1beta3"}
|
||||
tf.ClientConfig = &client.Config{Version: "v1"}
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
|
||||
cmd := NewCmdGet(f, buf)
|
||||
|
@ -150,18 +150,10 @@ func TestSelectContainer(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLog(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name, version, podPath, logPath, container string
|
||||
pod *api.Pod
|
||||
}{
|
||||
{
|
||||
name: "v1beta3 - pod log",
|
||||
version: "v1beta3",
|
||||
podPath: "/api/v1beta3/namespaces/test/pods/foo",
|
||||
logPath: "/api/v1beta3/namespaces/test/pods/foo/log",
|
||||
pod: testPod(),
|
||||
},
|
||||
{
|
||||
name: "v1 - pod log",
|
||||
version: "v1",
|
||||
|
@ -27,7 +27,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
|
||||
cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource"
|
||||
@ -305,10 +304,6 @@ func isReplicasDefaulted(info *resource.Info) bool {
|
||||
if rc, ok := info.VersionedObject.(*v1.ReplicationController); ok {
|
||||
return rc.Spec.Replicas == nil
|
||||
}
|
||||
case "v1beta3":
|
||||
if rc, ok := info.VersionedObject.(*v1beta3.ReplicationController); ok {
|
||||
return rc.Spec.Replicas == nil
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authenticator"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/auth/authorizer"
|
||||
@ -98,8 +97,6 @@ type Config struct {
|
||||
EnableUISupport bool
|
||||
// allow downstream consumers to disable swagger
|
||||
EnableSwaggerSupport bool
|
||||
// allow v1beta3 to be conditionally enabled
|
||||
EnableV1Beta3 bool
|
||||
// allow v1 to be conditionally disabled
|
||||
DisableV1 bool
|
||||
// allow downstream consumers to disable the index route
|
||||
@ -187,7 +184,6 @@ type Master struct {
|
||||
authorizer authorizer.Authorizer
|
||||
admissionControl admission.Interface
|
||||
masterCount int
|
||||
v1beta3 bool
|
||||
v1 bool
|
||||
requestContextMapper api.RequestContextMapper
|
||||
|
||||
@ -343,7 +339,6 @@ func New(c *Config) *Master {
|
||||
authenticator: c.Authenticator,
|
||||
authorizer: c.Authorizer,
|
||||
admissionControl: c.AdmissionControl,
|
||||
v1beta3: c.EnableV1Beta3,
|
||||
v1: !c.DisableV1,
|
||||
requestContextMapper: c.RequestContextMapper,
|
||||
|
||||
@ -556,12 +551,6 @@ func (m *Master) init(c *Config) {
|
||||
}
|
||||
|
||||
apiVersions := []string{}
|
||||
if m.v1beta3 {
|
||||
if err := m.api_v1beta3().InstallREST(m.handlerContainer); err != nil {
|
||||
glog.Fatalf("Unable to setup API v1beta3: %v", err)
|
||||
}
|
||||
apiVersions = append(apiVersions, "v1beta3")
|
||||
}
|
||||
if m.v1 {
|
||||
if err := m.api_v1().InstallREST(m.handlerContainer); err != nil {
|
||||
glog.Fatalf("Unable to setup API v1: %v", err)
|
||||
@ -756,19 +745,6 @@ func (m *Master) defaultAPIGroupVersion() *apiserver.APIGroupVersion {
|
||||
}
|
||||
}
|
||||
|
||||
// api_v1beta3 returns the resources and codec for API version v1beta3.
|
||||
func (m *Master) api_v1beta3() *apiserver.APIGroupVersion {
|
||||
storage := make(map[string]rest.Storage)
|
||||
for k, v := range m.storage {
|
||||
storage[strings.ToLower(k)] = v
|
||||
}
|
||||
version := m.defaultAPIGroupVersion()
|
||||
version.Storage = storage
|
||||
version.Version = "v1beta3"
|
||||
version.Codec = v1beta3.Codec
|
||||
return version
|
||||
}
|
||||
|
||||
// api_v1 returns the resources and codec for API version v1.
|
||||
func (m *Master) api_v1() *apiserver.APIGroupVersion {
|
||||
storage := make(map[string]rest.Storage)
|
||||
|
@ -28,7 +28,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
@ -27,7 +27,6 @@ import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/testapi"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
||||
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
|
||||
@ -176,9 +175,7 @@ func IncrementUsage(a admission.Attributes, status *api.ResourceQuotaStatus, cli
|
||||
obj := a.GetObject()
|
||||
// handle max counts for each kind of resource (pods, services, replicationControllers, etc.)
|
||||
if a.GetOperation() == admission.Create {
|
||||
// TODO v1beta1 had camel case, v1beta3 went to all lower, we can remove this line when we deprecate v1beta1
|
||||
resourceNormalized := strings.ToLower(a.GetResource())
|
||||
resourceName := resourceToResourceName[resourceNormalized]
|
||||
resourceName := resourceToResourceName[a.GetResource()]
|
||||
hard, hardFound := status.Hard[resourceName]
|
||||
if hardFound {
|
||||
used, usedFound := status.Used[resourceName]
|
||||
|
@ -423,7 +423,7 @@ func TestIncrementUsageReplicationControllers(t *testing.T) {
|
||||
r := api.ResourceReplicationControllers
|
||||
status.Hard[r] = resource.MustParse("2")
|
||||
status.Used[r] = resource.MustParse("1")
|
||||
dirty, err := IncrementUsage(admission.NewAttributesRecord(&api.ReplicationController{}, "ReplicationController", namespace, "name", "replicationControllers", "", admission.Create, nil), status, client)
|
||||
dirty, err := IncrementUsage(admission.NewAttributesRecord(&api.ReplicationController{}, "ReplicationController", namespace, "name", "replicationcontrollers", "", admission.Create, nil), status, client)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
@ -452,7 +452,7 @@ func TestExceedUsageReplicationControllers(t *testing.T) {
|
||||
r := api.ResourceReplicationControllers
|
||||
status.Hard[r] = resource.MustParse("1")
|
||||
status.Used[r] = resource.MustParse("1")
|
||||
_, err := IncrementUsage(admission.NewAttributesRecord(&api.ReplicationController{}, "ReplicationController", namespace, "name", "replicationControllers", "", admission.Create, nil), status, client)
|
||||
_, err := IncrementUsage(admission.NewAttributesRecord(&api.ReplicationController{}, "ReplicationController", namespace, "name", "replicationcontrollers", "", admission.Create, nil), status, client)
|
||||
if err == nil {
|
||||
t.Errorf("Expected error for exceeding hard limits")
|
||||
}
|
||||
@ -496,7 +496,7 @@ func TestExceedUsagePersistentVolumeClaims(t *testing.T) {
|
||||
r := api.ResourcePersistentVolumeClaims
|
||||
status.Hard[r] = resource.MustParse("1")
|
||||
status.Used[r] = resource.MustParse("1")
|
||||
_, err := IncrementUsage(admission.NewAttributesRecord(&api.PersistentVolumeClaim{}, "PersistentVolumeClaim", namespace, "name", "persistentVolumeClaims", "", admission.Create, nil), status, client)
|
||||
_, err := IncrementUsage(admission.NewAttributesRecord(&api.PersistentVolumeClaim{}, "PersistentVolumeClaim", namespace, "name", "persistentvolumeclaims", "", admission.Create, nil), status, client)
|
||||
if err == nil {
|
||||
t.Errorf("Expected error for exceeding hard limits")
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ limitations under the License.
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1beta3"
|
||||
apiv1 "github.com/GoogleCloudPlatform/kubernetes/pkg/api/v1"
|
||||
)
|
||||
|
||||
type Policy struct {
|
||||
v1beta3.TypeMeta `json:",inline"`
|
||||
apiv1.TypeMeta `json:",inline"`
|
||||
// Holds the information to configure the fit predicate functions
|
||||
Predicates []PredicatePolicy `json:"predicates"`
|
||||
// Holds the information to configure the priority functions
|
||||
|
@ -11,7 +11,7 @@ matrix:
|
||||
- KUBE_TEST_API_VERSIONS=v1 KUBE_TEST_ETCD_PREFIXES=registry
|
||||
- go: 1.3
|
||||
env:
|
||||
- KUBE_TEST_API_VERSIONS=v1beta3 KUBE_TEST_ETCD_PREFIXES=kubernetes.io/registry
|
||||
- KUBE_TEST_API_VERSIONS=v1 KUBE_TEST_ETCD_PREFIXES=kubernetes.io/registry
|
||||
|
||||
before_install:
|
||||
- source $HOME/.gvm/scripts/gvm;
|
||||
|
@ -410,10 +410,8 @@ func TestAuthModeAlwaysAllow(t *testing.T) {
|
||||
EnableUISupport: false,
|
||||
EnableIndex: true,
|
||||
APIPrefix: "/api",
|
||||
// enable v1beta3 if we are testing that api version.
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
})
|
||||
|
||||
transport := http.DefaultTransport
|
||||
@ -528,10 +526,8 @@ func TestAuthModeAlwaysDeny(t *testing.T) {
|
||||
EnableUISupport: false,
|
||||
EnableIndex: true,
|
||||
APIPrefix: "/api",
|
||||
// enable v1beta3 if we are testing that api version.
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authorizer: apiserver.NewAlwaysDenyAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authorizer: apiserver.NewAlwaysDenyAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
})
|
||||
|
||||
transport := http.DefaultTransport
|
||||
@ -597,11 +593,9 @@ func TestAliceNotForbiddenOrUnauthorized(t *testing.T) {
|
||||
EnableUISupport: false,
|
||||
EnableIndex: true,
|
||||
APIPrefix: "/api",
|
||||
// enable v1beta3 if we are testing that api version.
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authenticator: getTestTokenAuth(),
|
||||
Authorizer: allowAliceAuthorizer{},
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authenticator: getTestTokenAuth(),
|
||||
Authorizer: allowAliceAuthorizer{},
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
})
|
||||
|
||||
previousResourceVersion := make(map[string]float64)
|
||||
@ -686,11 +680,9 @@ func TestBobIsForbidden(t *testing.T) {
|
||||
EnableUISupport: false,
|
||||
EnableIndex: true,
|
||||
APIPrefix: "/api",
|
||||
// enable v1beta3 if we are testing that api version.
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authenticator: getTestTokenAuth(),
|
||||
Authorizer: allowAliceAuthorizer{},
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authenticator: getTestTokenAuth(),
|
||||
Authorizer: allowAliceAuthorizer{},
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
})
|
||||
|
||||
transport := http.DefaultTransport
|
||||
@ -749,11 +741,9 @@ func TestUnknownUserIsUnauthorized(t *testing.T) {
|
||||
EnableUISupport: false,
|
||||
EnableIndex: true,
|
||||
APIPrefix: "/api",
|
||||
// enable v1beta3 if we are testing that api version.
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authenticator: getTestTokenAuth(),
|
||||
Authorizer: allowAliceAuthorizer{},
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authenticator: getTestTokenAuth(),
|
||||
Authorizer: allowAliceAuthorizer{},
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
})
|
||||
|
||||
transport := http.DefaultTransport
|
||||
@ -831,11 +821,9 @@ func TestNamespaceAuthorization(t *testing.T) {
|
||||
EnableUISupport: false,
|
||||
EnableIndex: true,
|
||||
APIPrefix: "/api",
|
||||
// enable v1beta3 if we are testing that api version.
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authenticator: getTestTokenAuth(),
|
||||
Authorizer: a,
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authenticator: getTestTokenAuth(),
|
||||
Authorizer: a,
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
})
|
||||
|
||||
previousResourceVersion := make(map[string]float64)
|
||||
@ -948,11 +936,9 @@ func TestKindAuthorization(t *testing.T) {
|
||||
EnableUISupport: false,
|
||||
EnableIndex: true,
|
||||
APIPrefix: "/api",
|
||||
// enable v1beta3 if we are testing that api version.
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authenticator: getTestTokenAuth(),
|
||||
Authorizer: a,
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authenticator: getTestTokenAuth(),
|
||||
Authorizer: a,
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
})
|
||||
|
||||
previousResourceVersion := make(map[string]float64)
|
||||
@ -1052,11 +1038,9 @@ func TestReadOnlyAuthorization(t *testing.T) {
|
||||
EnableUISupport: false,
|
||||
EnableIndex: true,
|
||||
APIPrefix: "/api",
|
||||
// enable v1beta3 if we are testing that api version.
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authenticator: getTestTokenAuth(),
|
||||
Authorizer: a,
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authenticator: getTestTokenAuth(),
|
||||
Authorizer: a,
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
})
|
||||
|
||||
transport := http.DefaultTransport
|
||||
|
@ -139,10 +139,8 @@ func startMasterOrDie(masterConfig *master.Config) (*master.Master, *httptest.Se
|
||||
EnableProfiling: true,
|
||||
EnableUISupport: false,
|
||||
APIPrefix: "/api",
|
||||
// Enable v1bewta3 if we are testing that version
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
}
|
||||
} else {
|
||||
helper = masterConfig.EtcdHelper
|
||||
@ -272,10 +270,8 @@ func RunAMaster(t *testing.T) (*master.Master, *httptest.Server) {
|
||||
EnableProfiling: true,
|
||||
EnableUISupport: false,
|
||||
APIPrefix: "/api",
|
||||
// Enable v1bewta3 if we are testing that version
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
})
|
||||
|
||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
|
@ -73,10 +73,8 @@ func TestUnschedulableNodes(t *testing.T) {
|
||||
EnableUISupport: false,
|
||||
EnableIndex: true,
|
||||
APIPrefix: "/api",
|
||||
// Enable v1beta3 if we are testing that version.
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
})
|
||||
|
||||
restClient := client.NewOrDie(&client.Config{Host: s.URL, Version: testapi.Version()})
|
||||
|
@ -66,10 +66,8 @@ func TestSecrets(t *testing.T) {
|
||||
EnableUISupport: false,
|
||||
EnableIndex: true,
|
||||
APIPrefix: "/api",
|
||||
// Enable v1beta3 if we are testing that version.
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
})
|
||||
|
||||
framework.DeleteAllEtcdKeys()
|
||||
|
@ -416,11 +416,9 @@ func startServiceAccountTestServer(t *testing.T) (*client.Client, client.Config,
|
||||
EnableUISupport: false,
|
||||
EnableIndex: true,
|
||||
APIPrefix: "/api",
|
||||
// Enable v1beta3 if we are testing that version.
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authenticator: authenticator,
|
||||
Authorizer: authorizer,
|
||||
AdmissionControl: serviceAccountAdmission,
|
||||
Authenticator: authenticator,
|
||||
Authorizer: authorizer,
|
||||
AdmissionControl: serviceAccountAdmission,
|
||||
})
|
||||
|
||||
// Start the service account and service account token controllers
|
||||
|
@ -80,10 +80,8 @@ func runAMaster(t *testing.T) (*master.Master, *httptest.Server) {
|
||||
EnableProfiling: true,
|
||||
EnableUISupport: false,
|
||||
APIPrefix: "/api",
|
||||
// Enable v1beta3 if we are testing that version.
|
||||
EnableV1Beta3: testapi.Version() == "v1beta3",
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
Authorizer: apiserver.NewAlwaysAllowAuthorizer(),
|
||||
AdmissionControl: admit.NewAlwaysAdmit(),
|
||||
})
|
||||
|
||||
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
|
Loading…
Reference in New Issue
Block a user