mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-03 23:40:03 +00:00 
			
		
		
		
	add a test for kubectl apply --prune
This commit is contained in:
		@@ -1052,6 +1052,29 @@ __EOF__
 | 
				
			|||||||
  kubectl delete pods selector-test-pod
 | 
					  kubectl delete pods selector-test-pod
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  ## kubectl apply --prune
 | 
				
			||||||
 | 
					  # Pre-Condition: no POD exists
 | 
				
			||||||
 | 
					  kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # apply a
 | 
				
			||||||
 | 
					  kubectl apply --prune -l prune-group=true -f hack/testdata/prune/a.yaml "${kube_flags[@]}"
 | 
				
			||||||
 | 
					  # check right pod exists
 | 
				
			||||||
 | 
					  kube::test::get_object_assert 'pods a' "{{${id_field}}}" 'a'
 | 
				
			||||||
 | 
					  # check wrong pod doesn't exist
 | 
				
			||||||
 | 
					  output_message=$(! kubectl get pods b 2>&1 "${kube_flags[@]}")
 | 
				
			||||||
 | 
					  kube::test::if_has_string "${output_message}" 'pods "b" not found'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # apply b
 | 
				
			||||||
 | 
					  kubectl apply --prune -l prune-group=true -f hack/testdata/prune/b.yaml "${kube_flags[@]}"
 | 
				
			||||||
 | 
					  # check right pod exists
 | 
				
			||||||
 | 
					  kube::test::get_object_assert 'pods b' "{{${id_field}}}" 'b'
 | 
				
			||||||
 | 
					  # check wrong pod doesn't exist
 | 
				
			||||||
 | 
					  output_message=$(! kubectl get pods a 2>&1 "${kube_flags[@]}")
 | 
				
			||||||
 | 
					  kube::test::if_has_string "${output_message}" 'pods "a" not found'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # cleanup
 | 
				
			||||||
 | 
					  kubectl delete pods b
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ## kubectl run should create deployments or jobs
 | 
					  ## kubectl run should create deployments or jobs
 | 
				
			||||||
  # Pre-Condition: no Job exists
 | 
					  # Pre-Condition: no Job exists
 | 
				
			||||||
  kube::test::get_object_assert jobs "{{range.items}}{{$id_field}}:{{end}}" ''
 | 
					  kube::test::get_object_assert jobs "{{range.items}}{{$id_field}}:{{end}}" ''
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										10
									
								
								hack/testdata/prune/a.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								hack/testdata/prune/a.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					apiVersion: v1
 | 
				
			||||||
 | 
					kind: Pod
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: a
 | 
				
			||||||
 | 
					  labels:
 | 
				
			||||||
 | 
					    prune-group: "true"
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  containers:
 | 
				
			||||||
 | 
					  - name: kubernetes-pause
 | 
				
			||||||
 | 
					    image: gcr.io/google-containers/pause:2.0
 | 
				
			||||||
							
								
								
									
										10
									
								
								hack/testdata/prune/b.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								hack/testdata/prune/b.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					apiVersion: v1
 | 
				
			||||||
 | 
					kind: Pod
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: b
 | 
				
			||||||
 | 
					  labels:
 | 
				
			||||||
 | 
					    prune-group: "true"
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  containers:
 | 
				
			||||||
 | 
					  - name: kubernetes-pause
 | 
				
			||||||
 | 
					    image: gcr.io/google-containers/pause:2.0
 | 
				
			||||||
		Reference in New Issue
	
	Block a user