Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #14594 upstream release 1.1 #14877

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions hack/e2e.go
Expand Up @@ -178,6 +178,8 @@ func Up() bool {
}
}

// Enable deployments for e2e tests.
os.Setenv("KUBE_ENABLE_DEPLOYMENTS", "true")
return finishRunning("up", exec.Command(path.Join(*root, "hack/e2e-internal/e2e-up.sh")))
}

Expand Down
5 changes: 5 additions & 0 deletions hack/jenkins/e2e.sh
Expand Up @@ -198,6 +198,7 @@ case ${JOB_NAME} in
)"}
: ${KUBE_GCE_INSTANCE_PREFIX="e2e-gce"}
: ${PROJECT:="k8s-jkns-e2e-gce"}
: ${ENABLE_DEPLOYMENTS:=true}
;;

# Runs only the examples tests on GCE.
Expand Down Expand Up @@ -265,6 +266,7 @@ case ${JOB_NAME} in
: ${KUBE_GCE_INSTANCE_PREFIX:="pull-e2e-${EXECUTOR_NUMBER}"}
: ${KUBE_GCS_STAGING_PATH_SUFFIX:="-${EXECUTOR_NUMBER}"}
: ${PROJECT:="kubernetes-jenkins-pull"}
: ${ENABLE_DEPLOYMENTS:=true}
# Override GCE defaults
NUM_MINIONS=${NUM_MINIONS_PARALLEL}
;;
Expand All @@ -283,6 +285,7 @@ case ${JOB_NAME} in
)"}
: ${KUBE_GCE_INSTANCE_PREFIX:="e2e-test-parallel"}
: ${PROJECT:="kubernetes-jenkins"}
: ${ENABLE_DEPLOYMENTS:=true}
# Override GCE defaults
NUM_MINIONS=${NUM_MINIONS_PARALLEL}
;;
Expand All @@ -298,6 +301,7 @@ case ${JOB_NAME} in
${GCE_FLAKY_TESTS[@]:+${GCE_FLAKY_TESTS[@]}} \
${GCE_PARALLEL_FLAKY_TESTS[@]:+${GCE_PARALLEL_FLAKY_TESTS[@]}} \
)"}
: ${ENABLE_DEPLOYMENTS:=true}
# Override AWS defaults.
NUM_MINIONS="6"
;;
Expand Down Expand Up @@ -526,6 +530,7 @@ fi
export E2E_MIN_STARTUP_PODS=${E2E_MIN_STARTUP_PODS:-}
export KUBE_ENABLE_CLUSTER_MONITORING=${ENABLE_CLUSTER_MONITORING:-}
export KUBE_ENABLE_HORIZONTAL_POD_AUTOSCALER=${ENABLE_HORIZONTAL_POD_AUTOSCALER:-}
export KUBE_ENABLE_DEPLOYMENTS=${ENABLE_DEPLOYMENTS:-}
export MASTER_SIZE=${MASTER_SIZE:-}
export MINION_SIZE=${MINION_SIZE:-}
export NUM_MINIONS=${NUM_MINIONS:-}
Expand Down
169 changes: 169 additions & 0 deletions test/e2e/deployment.go
@@ -0,0 +1,169 @@
/*
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 e2e

import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/experimental"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("Deployment", func() {
f := NewFramework("deployment")

It("deployment should create new pods", func() {
testNewDeployment(f)
})
It("deployment should delete old pods and create new ones", func() {
testDeploymentDeletesOldPods(f)
})
})

func testNewDeployment(f *Framework) {
ns := f.Namespace.Name
c := f.Client
deploymentName := "nginx-deployment"
podLabels := map[string]string{"name": "nginx"}
Logf("Creating simple deployment %s", deploymentName)
_, err := c.Deployments(ns).Create(&experimental.Deployment{
ObjectMeta: api.ObjectMeta{
Name: deploymentName,
},
Spec: experimental.DeploymentSpec{
Replicas: 1,
Selector: podLabels,
UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash",
Template: &api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: podLabels,
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "nginx",
Image: "nginx",
},
},
},
},
},
})
Expect(err).NotTo(HaveOccurred())
defer func() {
Logf("deleting deployment %s", deploymentName)
Expect(c.Deployments(ns).Delete(deploymentName, nil)).NotTo(HaveOccurred())
}()
// Check that deployment is created fine.
deployment, err := c.Deployments(ns).Get(deploymentName)
Expect(err).NotTo(HaveOccurred())
Logf("Deployment: %s", deployment)

// Verify that the required pods have come up.
err = verifyPods(c, ns, "nginx", false, 1)
if err != nil {
Logf("error in waiting for pods to come up: %s", err)
return
}
// DeploymentStatus should be appropriately updated.
deployment, err = c.Deployments(ns).Get(deploymentName)
Expect(err).NotTo(HaveOccurred())
Expect(deployment.Status.Replicas).Should(Equal(1))
Expect(deployment.Status.UpdatedReplicas).Should(Equal(1))
}

func testDeploymentDeletesOldPods(f *Framework) {
ns := f.Namespace.Name
c := f.Client
// Create redis pods.
podLabels := map[string]string{"name": "sample-pod"}
rcName := "redis-controller"
_, err := c.ReplicationControllers(ns).Create(&api.ReplicationController{
ObjectMeta: api.ObjectMeta{
Name: rcName,
},
Spec: api.ReplicationControllerSpec{
Replicas: 1,
Selector: podLabels,
Template: &api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: podLabels,
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "redis",
Image: "redis",
},
},
},
},
},
})
Expect(err).NotTo(HaveOccurred())
defer func() {
Logf("deleting replication controller %s", rcName)
Expect(c.ReplicationControllers(ns).Delete(rcName)).NotTo(HaveOccurred())
}()
// Verify that the required pods have come up.
err = verifyPods(c, ns, "sample-pod", false, 1)
if err != nil {
Logf("error in waiting for pods to come up: %s", err)
return
}

// Create a deployment to delete redis pods and instead bring up nginx pods.
deploymentName := "nginx-deployment"
Logf("Creating deployment %s", deploymentName)
_, err = c.Deployments(ns).Create(&experimental.Deployment{
ObjectMeta: api.ObjectMeta{
Name: deploymentName,
},
Spec: experimental.DeploymentSpec{
Replicas: 1,
Selector: podLabels,
UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash",
Template: &api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: podLabels,
},
Spec: api.PodSpec{
Containers: []api.Container{
{
Name: "nginx",
Image: "nginx",
},
},
},
},
},
})
Expect(err).NotTo(HaveOccurred())
defer func() {
Logf("deleting deployment %s", deploymentName)
Expect(c.Deployments(ns).Delete(deploymentName, nil)).NotTo(HaveOccurred())
}()

// Verify that the required pods have come up.
verifyPods(c, ns, "nginx", false, 1)
// DeploymentStatus should be appropriately updated.
deployment, err := c.Deployments(ns).Get(deploymentName)
Expect(err).NotTo(HaveOccurred())
Expect(deployment.Status.Replicas).Should(Equal(1))
Expect(deployment.Status.UpdatedReplicas).Should(Equal(1))
}
2 changes: 1 addition & 1 deletion test/e2e/resize_nodes.go
Expand Up @@ -226,7 +226,7 @@ func resizeRC(c *client.Client, ns, name string, replicas int) error {
}

func podsCreated(c *client.Client, ns, name string, replicas int) (*api.PodList, error) {
timeout := time.Minute
timeout := 2 * time.Minute
// List the pods, making sure we observe all the replicas.
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": name}))
for start := time.Now(); time.Since(start) < timeout; time.Sleep(5 * time.Second) {
Expand Down