mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 23:15:14 +00:00
inline e2eservice.CreatePausePodDeployment into tests
This isn't a generically-useful helper; it's specific to 2 test cases.
This commit is contained in:
parent
0b9fa1146f
commit
c921c6893b
@ -17,7 +17,6 @@ go_library(
|
||||
deps = [
|
||||
"//pkg/apis/core:go_default_library",
|
||||
"//pkg/registry/core/service/portallocator:go_default_library",
|
||||
"//staging/src/k8s.io/api/apps/v1:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/api/policy/v1beta1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||
|
@ -25,7 +25,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
policyv1beta1 "k8s.io/api/policy/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
@ -53,9 +52,6 @@ import (
|
||||
// NodePortRange should match whatever the default/configured range is
|
||||
var NodePortRange = utilnet.PortRange{Base: 30000, Size: 2768}
|
||||
|
||||
// PauseDeploymentLabels are unique deployment selector labels for pause pod
|
||||
var PauseDeploymentLabels = map[string]string{"deployment": "agnhost-pause"}
|
||||
|
||||
// TestJig is a test jig to help service testing.
|
||||
type TestJig struct {
|
||||
ID string
|
||||
@ -898,53 +894,3 @@ func (j *TestJig) CreateServicePods(c clientset.Interface, ns string, replica in
|
||||
err := framework.RunRC(config)
|
||||
framework.ExpectNoError(err, "Replica must be created")
|
||||
}
|
||||
|
||||
// CreatePausePodDeployment creates a deployment for agnhost-pause pod running in different nodes
|
||||
func (j *TestJig) CreatePausePodDeployment(name, ns string, replica int32) *appsv1.Deployment {
|
||||
// terminationGracePeriod is set to 0 to reduce deployment deletion time for infinitely running pause pod.
|
||||
terminationGracePeriod := int64(0)
|
||||
pauseDeployment := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Labels: PauseDeploymentLabels,
|
||||
},
|
||||
Spec: appsv1.DeploymentSpec{
|
||||
Replicas: &replica,
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: PauseDeploymentLabels,
|
||||
},
|
||||
Strategy: appsv1.DeploymentStrategy{
|
||||
Type: appsv1.RollingUpdateDeploymentStrategyType,
|
||||
},
|
||||
Template: v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: PauseDeploymentLabels,
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
TerminationGracePeriodSeconds: &terminationGracePeriod,
|
||||
Affinity: &v1.Affinity{
|
||||
PodAntiAffinity: &v1.PodAntiAffinity{
|
||||
RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
|
||||
{
|
||||
LabelSelector: &metav1.LabelSelector{MatchLabels: PauseDeploymentLabels},
|
||||
TopologyKey: "kubernetes.io/hostname",
|
||||
Namespaces: []string{ns},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Containers: []v1.Container{
|
||||
{
|
||||
Name: "agnhost-pause",
|
||||
Image: imageutils.GetE2EImage(imageutils.Agnhost),
|
||||
Args: []string{"pause"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
deployment, err := j.Client.AppsV1().Deployments(ns).Create(pauseDeployment)
|
||||
framework.ExpectNoError(err, "Error in creating deployment for pause pod")
|
||||
return deployment
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
|
||||
compute "google.golang.org/api/compute/v1"
|
||||
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
@ -319,7 +320,7 @@ var _ = SIGDescribe("Services", func() {
|
||||
framework.ExpectNoError(err, "failed to validate endpoints for service %s in namespace: %s", serviceName, ns)
|
||||
|
||||
ginkgo.By("Creating pause pod deployment")
|
||||
deployment := jig.CreatePausePodDeployment("pause-pod", ns, int32(nodeCounts))
|
||||
deployment := createPausePodDeployment(cs, "pause-pod", ns, nodeCounts)
|
||||
|
||||
defer func() {
|
||||
e2elog.Logf("Deleting deployment")
|
||||
@ -2256,7 +2257,7 @@ var _ = SIGDescribe("ESIPP [Slow] [DisabledForLargeClusters]", func() {
|
||||
path := fmt.Sprintf("%s/clientip", ipPort)
|
||||
|
||||
ginkgo.By("Creating pause pod deployment to make sure, pausePods are in desired state")
|
||||
deployment := jig.CreatePausePodDeployment("pause-pod-deployment", namespace, int32(1))
|
||||
deployment := createPausePodDeployment(cs, "pause-pod-deployment", namespace, 1)
|
||||
framework.ExpectNoError(e2edeploy.WaitForDeploymentComplete(cs, deployment), "Failed to complete pause pod deployment")
|
||||
|
||||
defer func() {
|
||||
@ -2548,3 +2549,29 @@ func createAndGetExternalServiceFQDN(cs clientset.Interface, ns, serviceName str
|
||||
framework.ExpectNoError(err, "Expected Service %s to be running", serviceName)
|
||||
return fmt.Sprintf("%s.%s.svc.%s", serviceName, ns, framework.TestContext.ClusterDNSDomain)
|
||||
}
|
||||
|
||||
func createPausePodDeployment(cs clientset.Interface, name, ns string, replicas int) *appsv1.Deployment {
|
||||
labels := map[string]string{"deployment": "agnhost-pause"}
|
||||
pauseDeployment := e2edeploy.NewDeployment(name, int32(replicas), labels, "", "", appsv1.RollingUpdateDeploymentStrategyType)
|
||||
|
||||
pauseDeployment.Spec.Template.Spec.Containers[0] = v1.Container{
|
||||
Name: "agnhost-pause",
|
||||
Image: imageutils.GetE2EImage(imageutils.Agnhost),
|
||||
Args: []string{"pause"},
|
||||
}
|
||||
pauseDeployment.Spec.Template.Spec.Affinity = &v1.Affinity{
|
||||
PodAntiAffinity: &v1.PodAntiAffinity{
|
||||
RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
|
||||
{
|
||||
LabelSelector: &metav1.LabelSelector{MatchLabels: labels},
|
||||
TopologyKey: "kubernetes.io/hostname",
|
||||
Namespaces: []string{ns},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
deployment, err := cs.AppsV1().Deployments(ns).Create(pauseDeployment)
|
||||
framework.ExpectNoError(err, "Error in creating deployment for pause pod")
|
||||
return deployment
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user