craigcondit commented on code in PR #472:
URL: https://github.com/apache/yunikorn-k8shim/pull/472#discussion_r1034144429


##########
test/e2e/admission_controller/admission_controller_test.go:
##########
@@ -107,6 +110,139 @@ var _ = ginkgo.Describe("AdmissionController", func() {
                gomega.Ω(invalidCm).ShouldNot(gomega.BeNil())
        })
 
+       ginkgo.It("Check that annotation is added to a pod & cannot be 
modified", func() {
+               ginkgo.By("Create a pod")
+               pod, err := kubeClient.CreatePod(&testPod, ns)
+               gomega.Ω(err).ShouldNot(gomega.HaveOccurred())
+               defer deletePod(pod, ns)
+
+               err = kubeClient.WaitForPodBySelector(ns,
+                       fmt.Sprintf("app=%s", pod.ObjectMeta.Labels["app"]), 
10*time.Second)
+               gomega.Ω(err).ShouldNot(gomega.HaveOccurred())
+               pod, err = kubeClient.GetPod(pod.Name, ns)
+               gomega.Ω(err).ShouldNot(gomega.HaveOccurred())
+               userinfo := pod.Annotations["yunikorn.apache.org/user.info"]
+               gomega.Ω(userinfo).Should(gomega.Not(gomega.BeNil()))
+
+               ginkgo.By("Attempt to update userinfo annotation")
+               _, err = kubeClient.UpdatePodWithAnnotation(pod, ns, 
"yunikorn.apache.org/user.info", "shouldnotsucceed")
+               gomega.Ω(err).Should(gomega.HaveOccurred())
+       })
+
+       ginkgo.It("Check that annotation is added to a deployment", func() {
+               ginkgo.By("Create a deployment")
+               deployment, err := kubeClient.CreateDeployment(&testDeployment, 
ns)
+               gomega.Ω(err).ShouldNot(gomega.HaveOccurred())
+               defer deleteDeployment(deployment, ns)
+               err = kubeClient.WaitForPodBySelector(ns,
+                       fmt.Sprintf("app=%s", 
testDeployment.ObjectMeta.Labels["app"]), 10*time.Second)
+               gomega.Ω(err).ShouldNot(gomega.HaveOccurred())
+
+               ginkgo.By("Get running pod")
+               var pods *v1.PodList
+               pods, err = kubeClient.GetPods(ns)
+               gomega.Ω(err).ShouldNot(gomega.HaveOccurred())
+               fmt.Fprintf(ginkgo.GinkgoWriter, "Found %d pods in namespace 
%s\n", len(pods.Items), ns)
+               gomega.Ω(len(pods.Items)).To(gomega.Equal(1))
+               fmt.Fprintf(ginkgo.GinkgoWriter, "Running pod is %s\n", 
pods.Items[0].Name)
+               pod, err2 := kubeClient.GetPod(pods.Items[0].Name, ns)
+               gomega.Ω(err2).ShouldNot(gomega.HaveOccurred())
+               userinfo := pod.Annotations["yunikorn.apache.org/user.info"]
+               gomega.Ω(userinfo).Should(gomega.Not(gomega.BeNil()))
+       })
+
+       ginkgo.It("Check that deployment is rejected when controller users are 
not trusted", func() {
+               ginkgo.By("Retrieve existing configmap")
+               configMap, err := 
kubeClient.GetConfigMap(constants.ConfigMapName, 
configmanager.YuniKornTestConfig.YkNamespace)
+               gomega.Ω(err).ShouldNot(gomega.HaveOccurred())
+               if configMap.Data == nil {
+                       configMap.Data = make(map[string]string)
+               }
+               configMap.Data[amConf.AMAccessControlTrustControllers] = "false"
+               ginkgo.By("Update configmap")
+               _, err = kubeClient.UpdateConfigMap(configMap, 
configmanager.YuniKornTestConfig.YkNamespace)
+               gomega.Ω(err).ShouldNot(gomega.HaveOccurred())
+               time.Sleep(time.Second) // should be enough to allow the 
admission controller to pick up the changes
+
+               ginkgo.By("Create a deployment")
+               deployment, err2 := 
kubeClient.CreateDeployment(&testDeployment, ns)
+               gomega.Ω(err2).ShouldNot(gomega.HaveOccurred())
+               defer deleteDeployment(deployment, ns)
+
+               // pod is not expected to appear
+               ginkgo.By("Check for sleep pods (should time out)")
+               err = kubeClient.WaitForPodBySelector(ns, fmt.Sprintf("app=%s", 
testDeployment.ObjectMeta.Labels["app"]),
+                       10*time.Second)
+               fmt.Fprintf(ginkgo.GinkgoWriter, "Error: %v\n", err)
+               gomega.Ω(err).Should(gomega.HaveOccurred())
+               ginkgo.By("Check deployment status")
+               deployment, err = kubeClient.GetDeployment(testDeployment.Name, 
ns)
+               gomega.Ω(err).ShouldNot(gomega.HaveOccurred())
+               fmt.Fprintf(ginkgo.GinkgoWriter, "Replicas: %d, 
AvailableReplicas: %d, ReadyReplicas: %d\n",
+                       deployment.Status.Replicas, 
deployment.Status.AvailableReplicas, deployment.Status.ReadyReplicas)
+               gomega.Ω(deployment.Status.Replicas).To(gomega.Equal(int32(0)))
+               
gomega.Ω(deployment.Status.AvailableReplicas).To(gomega.Equal(int32(0)))
+               
gomega.Ω(deployment.Status.ReadyReplicas).To(gomega.Equal(int32(0)))
+
+               // restore setting
+               ginkgo.By("Restore trustController setting")
+               configMap, err = 
kubeClient.GetConfigMap(constants.ConfigMapName, 
configmanager.YuniKornTestConfig.YkNamespace)
+               gomega.Ω(err).ShouldNot(gomega.HaveOccurred())
+               configMap.Data[amConf.AMAccessControlTrustControllers] = "true"
+               _, err = kubeClient.UpdateConfigMap(configMap, 
configmanager.YuniKornTestConfig.YkNamespace)
+               gomega.Ω(err).ShouldNot(gomega.HaveOccurred())
+

Review Comment:
   That will definitely introduce a delay, but doesn't verify that YuniKorn has 
applied the config. We may want to follow-up later with a more comprehensive 
method to check that config has been applied. This is fine for now though.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to