Create List and DelectCollection ReplicaSet Test
Co-Authored-By: Riaan Kleinhans <riaan@ii.coop> e2e test validates the following 2 extra endpoints - listAppsV1NamespacedReplicaSet - deleteAppsV1CollectionNamespacedReplicaSet
This commit is contained in:
		
				
					committed by
					
						
						Stephen Heywood
					
				
			
			
				
	
			
			
			
						parent
						
							0ed8ee6fd7
						
					
				
				
					commit
					8c7cef2621
				
			@@ -31,6 +31,7 @@ import (
 | 
				
			|||||||
	"k8s.io/apimachinery/pkg/api/resource"
 | 
						"k8s.io/apimachinery/pkg/api/resource"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/labels"
 | 
						"k8s.io/apimachinery/pkg/labels"
 | 
				
			||||||
 | 
						"k8s.io/apimachinery/pkg/util/rand"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/uuid"
 | 
						"k8s.io/apimachinery/pkg/util/uuid"
 | 
				
			||||||
	"k8s.io/apimachinery/pkg/util/wait"
 | 
						"k8s.io/apimachinery/pkg/util/wait"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/controller/replicaset"
 | 
						"k8s.io/kubernetes/pkg/controller/replicaset"
 | 
				
			||||||
@@ -141,6 +142,12 @@ var _ = SIGDescribe("ReplicaSet", func() {
 | 
				
			|||||||
	framework.ConformanceIt("Replace and Patch tests", func() {
 | 
						framework.ConformanceIt("Replace and Patch tests", func() {
 | 
				
			||||||
		testRSLifeCycle(f)
 | 
							testRSLifeCycle(f)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ginkgo.It("should list and delete a collection of ReplicaSets", func() {
 | 
				
			||||||
 | 
							listRSDeleteCollection(f)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// A basic test to check the deployment of an image using a ReplicaSet. The
 | 
					// A basic test to check the deployment of an image using a ReplicaSet. The
 | 
				
			||||||
@@ -495,3 +502,48 @@ func testRSLifeCycle(f *framework.Framework) {
 | 
				
			|||||||
	framework.ExpectEqual(*(rs.Spec.Replicas), rsPatchReplicas, "replicaset should have 3 replicas")
 | 
						framework.ExpectEqual(*(rs.Spec.Replicas), rsPatchReplicas, "replicaset should have 3 replicas")
 | 
				
			||||||
	framework.ExpectEqual(rs.Spec.Template.Spec.Containers[0].Image, rsPatchImage, "replicaset not using rsPatchImage. Is using %v", rs.Spec.Template.Spec.Containers[0].Image)
 | 
						framework.ExpectEqual(rs.Spec.Template.Spec.Containers[0].Image, rsPatchImage, "replicaset not using rsPatchImage. Is using %v", rs.Spec.Template.Spec.Containers[0].Image)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// List and DeleteCollection operations
 | 
				
			||||||
 | 
					func listRSDeleteCollection(f *framework.Framework) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ns := f.Namespace.Name
 | 
				
			||||||
 | 
						c := f.ClientSet
 | 
				
			||||||
 | 
						rsClient := f.ClientSet.AppsV1().ReplicaSets(ns)
 | 
				
			||||||
 | 
						zero := int64(0)
 | 
				
			||||||
 | 
						rsName := "test-rs"
 | 
				
			||||||
 | 
						replicas := int32(3)
 | 
				
			||||||
 | 
						e2eValue := rand.String(5)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Define ReplicaSet Labels
 | 
				
			||||||
 | 
						rsPodLabels := map[string]string{
 | 
				
			||||||
 | 
							"name": "sample-pod",
 | 
				
			||||||
 | 
							"pod":  WebserverImageName,
 | 
				
			||||||
 | 
							"e2e":  e2eValue,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ginkgo.By("Create a ReplicaSet")
 | 
				
			||||||
 | 
						rs := newRS(rsName, replicas, rsPodLabels, WebserverImageName, WebserverImage, nil)
 | 
				
			||||||
 | 
						_, err := rsClient.Create(context.TODO(), rs, metav1.CreateOptions{})
 | 
				
			||||||
 | 
						framework.ExpectNoError(err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ginkgo.By("Verify that the required pods have come up")
 | 
				
			||||||
 | 
						err = e2epod.VerifyPodsRunning(c, ns, "sample-pod", false, replicas)
 | 
				
			||||||
 | 
						framework.ExpectNoError(err, "Failed to create pods: %s", err)
 | 
				
			||||||
 | 
						r, err := rsClient.Get(context.TODO(), rsName, metav1.GetOptions{})
 | 
				
			||||||
 | 
						framework.ExpectNoError(err, "failed to get ReplicaSets")
 | 
				
			||||||
 | 
						framework.Logf("Replica Status: %+v", r.Status)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ginkgo.By("Listing all ReplicaSets")
 | 
				
			||||||
 | 
						rsList, err := c.AppsV1().ReplicaSets("").List(context.TODO(), metav1.ListOptions{LabelSelector: "e2e=" + e2eValue})
 | 
				
			||||||
 | 
						framework.ExpectNoError(err, "failed to list ReplicaSets")
 | 
				
			||||||
 | 
						framework.ExpectEqual(len(rsList.Items), 1, "filtered list wasn't found")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ginkgo.By("DeleteCollection of the ReplicaSets")
 | 
				
			||||||
 | 
						err = rsClient.DeleteCollection(context.TODO(), metav1.DeleteOptions{GracePeriodSeconds: &zero}, metav1.ListOptions{LabelSelector: "e2e=" + e2eValue})
 | 
				
			||||||
 | 
						framework.ExpectNoError(err, "failed to delete ReplicaSets")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ginkgo.By("After DeleteCollection verify that ReplicaSets have been deleted")
 | 
				
			||||||
 | 
						rsList, err = c.AppsV1().ReplicaSets("").List(context.TODO(), metav1.ListOptions{LabelSelector: "e2e=" + e2eValue})
 | 
				
			||||||
 | 
						framework.ExpectNoError(err, "failed to list ReplicaSets")
 | 
				
			||||||
 | 
						framework.ExpectEqual(len(rsList.Items), 0, "filtered list should have no replicas")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user