mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-16 23:29:21 +00:00
Add: test to ensure that a set of pod templates can be removed by delete collection
This commit is contained in:
parent
590365cb70
commit
8ccf59027e
@ -25,6 +25,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
"strconv"
|
||||
|
||||
"github.com/onsi/ginkgo"
|
||||
)
|
||||
@ -99,4 +100,79 @@ var _ = ginkgo.Describe("[sig-node] PodTemplates", func() {
|
||||
framework.ExpectNoError(err, "failed to list PodTemplate")
|
||||
framework.ExpectEqual(len(podTemplateList.Items), 0, "PodTemplate list returned items, failed to delete PodTemplate")
|
||||
})
|
||||
|
||||
ginkgo.It("should delete a collection of pod templates", func() {
|
||||
podTemplateNames := []string{"test-podtemplate-1", "test-podtemplate-2", "test-podtemplate-3"}
|
||||
podTemplateNamesCount := len(podTemplateNames)
|
||||
|
||||
ginkgo.By("Create set of pod templates")
|
||||
// create a set of pod templates in test namespace
|
||||
for _, podTemplateName := range podTemplateNames {
|
||||
_, err := f.ClientSet.CoreV1().PodTemplates(f.Namespace.Name).Create(context.TODO(), &v1.PodTemplate{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: podTemplateName,
|
||||
Labels: map[string]string{"podtemplate-set": "true"},
|
||||
},
|
||||
Template: v1.PodTemplateSpec{
|
||||
Spec: v1.PodSpec{
|
||||
Containers: []v1.Container{
|
||||
{Name: "nginx", Image: "nginx"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, metav1.CreateOptions{})
|
||||
framework.ExpectNoError(err, "failed to create pod template")
|
||||
framework.Logf("created %v", podTemplateName)
|
||||
}
|
||||
|
||||
ginkgo.By("get a list of pod templates with a label in the current namespace")
|
||||
// get a list of pod templates
|
||||
podTemplateList, err := f.ClientSet.CoreV1().PodTemplates(f.Namespace.Name).List(context.TODO(), metav1.ListOptions{
|
||||
LabelSelector: "podtemplate-set=true",
|
||||
})
|
||||
framework.ExpectNoError(err, "failed to get a list of pod templates")
|
||||
|
||||
// check that we find all the pod templates created
|
||||
podTemplateListItemsCount := len(podTemplateList.Items)
|
||||
errMsg := "found " + strconv.Itoa(podTemplateListItemsCount) + " pod templates when " + strconv.Itoa(podTemplateNamesCount) + " pod templates where expected"
|
||||
logMsg := "found " + strconv.Itoa(podTemplateListItemsCount) + " pod templates"
|
||||
|
||||
foundCreatedSet := true
|
||||
if podTemplateListItemsCount != podTemplateNamesCount {
|
||||
foundCreatedSet = false
|
||||
} else {
|
||||
framework.Logf(logMsg)
|
||||
}
|
||||
framework.ExpectEqual(foundCreatedSet, true, errMsg)
|
||||
|
||||
ginkgo.By("delete collection of pod templates")
|
||||
// delete collection
|
||||
|
||||
framework.Logf("requesting DeleteCollection of pod templates")
|
||||
err = f.ClientSet.CoreV1().PodTemplates(f.Namespace.Name).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{
|
||||
LabelSelector: "podtemplate-set=true"})
|
||||
framework.ExpectNoError(err, "failed to delete all pod templates")
|
||||
|
||||
ginkgo.By("get a list of pod templates with a label in the current namespace")
|
||||
// get list of pod templates
|
||||
podTemplateList, err = f.ClientSet.CoreV1().PodTemplates(f.Namespace.Name).List(context.TODO(), metav1.ListOptions{
|
||||
LabelSelector: "podtemplate-set=true",
|
||||
})
|
||||
framework.ExpectNoError(err, "failed to get a list of pod templates")
|
||||
|
||||
// check that we don't find any created pod templates
|
||||
podTemplateListItemsCount = len(podTemplateList.Items)
|
||||
errMsg = "found " + strconv.Itoa(podTemplateListItemsCount) + " pod templates when zero pod templates where expected"
|
||||
logMsg = "found " + strconv.Itoa(podTemplateListItemsCount) + " pod templates"
|
||||
|
||||
foundCreatedSet = false
|
||||
if podTemplateListItemsCount != 0 {
|
||||
foundCreatedSet = true
|
||||
} else {
|
||||
framework.Logf(logMsg)
|
||||
}
|
||||
framework.ExpectEqual(foundCreatedSet, false, errMsg)
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user