mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Update checks and status messages; Remove asserting of status values
This commit is contained in:
parent
3149247932
commit
e719b723f7
@ -144,6 +144,7 @@ var _ = SIGDescribe("Deployment", func() {
|
|||||||
|
|
||||||
ginkgo.It("should run the lifecycle of a Deployment", func() {
|
ginkgo.It("should run the lifecycle of a Deployment", func() {
|
||||||
deploymentResource := schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}
|
deploymentResource := schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}
|
||||||
|
testNamespaceName := f.Namespace.Name
|
||||||
testDeploymentName := "test-deployment"
|
testDeploymentName := "test-deployment"
|
||||||
testDeploymentInitialImage := "nginx"
|
testDeploymentInitialImage := "nginx"
|
||||||
testDeploymentPatchImage := "alpine"
|
testDeploymentPatchImage := "alpine"
|
||||||
@ -151,14 +152,13 @@ var _ = SIGDescribe("Deployment", func() {
|
|||||||
testDeploymentDefaultReplicas := int32(3)
|
testDeploymentDefaultReplicas := int32(3)
|
||||||
testDeploymentMinimumReplicas := int32(1)
|
testDeploymentMinimumReplicas := int32(1)
|
||||||
testDeploymentNoReplicas := int32(0)
|
testDeploymentNoReplicas := int32(0)
|
||||||
// TODO labels
|
testDeploymentLabels := map[string]string{"test-deployment-static": "true"}
|
||||||
// TODO flat labels
|
testDeploymentLabelsFlat := "test-deployment-static=true"
|
||||||
testDeploymentLabelSelectors := metav1.LabelSelector{
|
testDeploymentLabelSelectors := metav1.LabelSelector{
|
||||||
MatchLabels: map[string]string{"app": "test-deployment"},
|
MatchLabels: testDeploymentLabels,
|
||||||
}
|
}
|
||||||
testNamespaceName := "default"
|
|
||||||
|
|
||||||
fmt.Println("creating a Deployment")
|
ginkgo.By("creating a Deployment")
|
||||||
testDeployment := appsv1.Deployment{
|
testDeployment := appsv1.Deployment{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: testDeploymentName,
|
Name: testDeploymentName,
|
||||||
@ -180,19 +180,14 @@ var _ = SIGDescribe("Deployment", func() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// TODO add watch tooling
|
||||||
_, err := f.ClientSet.AppsV1().Deployments(testNamespaceName).Create(context.TODO(), &testDeployment, metav1.CreateOptions{})
|
_, err := f.ClientSet.AppsV1().Deployments(testNamespaceName).Create(context.TODO(), &testDeployment, metav1.CreateOptions{})
|
||||||
if err != nil {
|
framework.ExpectNoError(err, "failed to create Deployment %v in namespace %v", testDeploymentName, testNamespaceName)
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("watching for the Deployment to be added")
|
ginkgo.By("watching for the Deployment to be added")
|
||||||
dplmtWatchTimeoutSeconds := int64(180)
|
dplmtWatchTimeoutSeconds := int64(180)
|
||||||
dplmtWatch, err := f.ClientSet.AppsV1().Deployments(testNamespaceName).Watch(context.TODO(), metav1.ListOptions{LabelSelector: "test-deployment-static=true", TimeoutSeconds: &dplmtWatchTimeoutSeconds})
|
dplmtWatch, err := f.ClientSet.AppsV1().Deployments(testNamespaceName).Watch(context.TODO(), metav1.ListOptions{LabelSelector: testDeploymentLabelsFlat, TimeoutSeconds: &dplmtWatchTimeoutSeconds})
|
||||||
if err != nil {
|
framework.ExpectNoError(err, "Failed to setup watch on newly created Deployment")
|
||||||
fmt.Println(err, "Failed to setup watch on newly created Deployment")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
dplmtWatchChan := dplmtWatch.ResultChan()
|
dplmtWatchChan := dplmtWatch.ResultChan()
|
||||||
for event := range dplmtWatchChan {
|
for event := range dplmtWatchChan {
|
||||||
@ -200,38 +195,17 @@ var _ = SIGDescribe("Deployment", func() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defer func() {
|
ginkgo.By("waiting for all Replicas to be Ready")
|
||||||
fmt.Println("deleting the Deployment")
|
|
||||||
err = f.ClientSet.AppsV1().Deployments(testNamespaceName).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "test-deployment-static=true"})
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for event := range dplmtWatchChan {
|
|
||||||
deployment, ok := event.Object.(*appsv1.Deployment)
|
|
||||||
if ok != true {
|
|
||||||
fmt.Println("unable to convert event.Object type")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if event.Type == watch.Deleted && deployment.ObjectMeta.Name == testDeploymentName {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fmt.Println("waiting for all Replicas to be Ready")
|
|
||||||
for event := range dplmtWatchChan {
|
for event := range dplmtWatchChan {
|
||||||
deployment, ok := event.Object.(*appsv1.Deployment)
|
deployment, ok := event.Object.(*appsv1.Deployment)
|
||||||
if ok != true {
|
framework.ExpectEqual(ok, true, "unable to convert event.Object type")
|
||||||
fmt.Println("unable to convert event.Object type")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if deployment.Status.AvailableReplicas == testDeploymentDefaultReplicas &&
|
if deployment.Status.AvailableReplicas == testDeploymentDefaultReplicas &&
|
||||||
deployment.Status.ReadyReplicas == testDeploymentDefaultReplicas {
|
deployment.Status.ReadyReplicas == testDeploymentDefaultReplicas {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("patching the Deployment")
|
ginkgo.By("patching the Deployment")
|
||||||
deploymentPatch, err := json.Marshal(map[string]interface{}{
|
deploymentPatch, err := json.Marshal(map[string]interface{}{
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
"labels": map[string]string{"test-deployment": "patched"},
|
"labels": map[string]string{"test-deployment": "patched"},
|
||||||
@ -240,7 +214,7 @@ var _ = SIGDescribe("Deployment", func() {
|
|||||||
"replicas": testDeploymentMinimumReplicas,
|
"replicas": testDeploymentMinimumReplicas,
|
||||||
"template": map[string]interface{}{
|
"template": map[string]interface{}{
|
||||||
"spec": map[string]interface{}{
|
"spec": map[string]interface{}{
|
||||||
"containers": []map[string]interface{}{{
|
"containers": [1]map[string]interface{}{{
|
||||||
"name": testDeploymentName,
|
"name": testDeploymentName,
|
||||||
"image": testDeploymentPatchImage,
|
"image": testDeploymentPatchImage,
|
||||||
"command": []string{"/bin/sleep", "100000"},
|
"command": []string{"/bin/sleep", "100000"},
|
||||||
@ -249,40 +223,28 @@ var _ = SIGDescribe("Deployment", func() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
framework.ExpectNoError(err, "failed to Marshal Deployment JSON patch")
|
||||||
fmt.Println(err, "failed to Marshal Deployment JSON patch")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
_, err = f.ClientSet.AppsV1().Deployments(testNamespaceName).Patch(context.TODO(), testDeploymentName, types.StrategicMergePatchType, []byte(deploymentPatch), metav1.PatchOptions{})
|
_, err = f.ClientSet.AppsV1().Deployments(testNamespaceName).Patch(context.TODO(), testDeploymentName, types.StrategicMergePatchType, []byte(deploymentPatch), metav1.PatchOptions{})
|
||||||
if err != nil {
|
framework.ExpectNoError(err, "failed to patch Deployment")
|
||||||
fmt.Println(err, "failed to patch Deployment")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for event := range dplmtWatchChan {
|
for event := range dplmtWatchChan {
|
||||||
if event.Type == watch.Modified {
|
if event.Type == watch.Modified {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("waiting for Replicas to scale")
|
ginkgo.By("waiting for Replicas to scale")
|
||||||
for event := range dplmtWatchChan {
|
for event := range dplmtWatchChan {
|
||||||
deployment, ok := event.Object.(*appsv1.Deployment)
|
deployment, ok := event.Object.(*appsv1.Deployment)
|
||||||
if ok != true {
|
framework.ExpectEqual(ok, true, "unable to convert event.Object type")
|
||||||
fmt.Println("unable to convert event.Object type")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if deployment.Status.AvailableReplicas == testDeploymentMinimumReplicas &&
|
if deployment.Status.AvailableReplicas == testDeploymentMinimumReplicas &&
|
||||||
deployment.Status.ReadyReplicas == testDeploymentMinimumReplicas {
|
deployment.Status.ReadyReplicas == testDeploymentMinimumReplicas {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("listing Deployments")
|
ginkgo.By("listing Deployments")
|
||||||
deploymentsList, err := f.ClientSet.AppsV1().Deployments("").List(context.TODO(), metav1.ListOptions{LabelSelector: "test-deployment-static=true"})
|
deploymentsList, err := f.ClientSet.AppsV1().Deployments("").List(context.TODO(), metav1.ListOptions{LabelSelector: testDeploymentLabelsFlat})
|
||||||
if err != nil {
|
framework.ExpectNoError(err, "failed to list Deployments")
|
||||||
fmt.Println(err, "failed to list Deployments")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
foundDeployment := false
|
foundDeployment := false
|
||||||
for _, deploymentItem := range deploymentsList.Items {
|
for _, deploymentItem := range deploymentsList.Items {
|
||||||
if deploymentItem.ObjectMeta.Name == testDeploymentName &&
|
if deploymentItem.ObjectMeta.Name == testDeploymentName &&
|
||||||
@ -294,53 +256,36 @@ var _ = SIGDescribe("Deployment", func() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if foundDeployment != true {
|
framework.ExpectEqual(foundDeployment, true, "unable to find the Deployment in list", deploymentsList)
|
||||||
fmt.Println("unable to find the Deployment in list")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("updating the DeploymentStatus")
|
ginkgo.By("updating the DeploymentStatus")
|
||||||
testDeploymentUpdate := testDeployment
|
testDeploymentUpdate := testDeployment
|
||||||
testDeploymentUpdate.ObjectMeta.Labels["test-deployment"] = "updated"
|
testDeploymentUpdate.ObjectMeta.Labels["test-deployment"] = "updated"
|
||||||
testDeploymentUpdate.Spec.Template.Spec.Containers[0].Image = testDeploymentUpdateImage
|
testDeploymentUpdate.Spec.Template.Spec.Containers[0].Image = testDeploymentUpdateImage
|
||||||
testDeploymentDefaultReplicasPointer := &testDeploymentDefaultReplicas
|
testDeploymentDefaultReplicasPointer := &testDeploymentDefaultReplicas
|
||||||
testDeploymentUpdate.Spec.Replicas = testDeploymentDefaultReplicasPointer
|
testDeploymentUpdate.Spec.Replicas = testDeploymentDefaultReplicasPointer
|
||||||
testDeploymentUpdate.Status.ReadyReplicas = testDeploymentNoReplicas
|
|
||||||
testDeploymentUpdateUnstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&testDeploymentUpdate)
|
testDeploymentUpdateUnstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&testDeploymentUpdate)
|
||||||
if err != nil {
|
framework.ExpectNoError(err, "failed to convert to unstructured")
|
||||||
fmt.Println(err, "failed to convert to unstructured")
|
|
||||||
}
|
|
||||||
testDeploymentUpdateUnstructured := unstructuredv1.Unstructured{
|
testDeploymentUpdateUnstructured := unstructuredv1.Unstructured{
|
||||||
Object: testDeploymentUpdateUnstructuredMap,
|
Object: testDeploymentUpdateUnstructuredMap,
|
||||||
}
|
}
|
||||||
// currently this hasn't been able to hit the endpoint replaceAppsV1NamespacedDeploymentStatus
|
// currently this hasn't been able to hit the endpoint replaceAppsV1NamespacedDeploymentStatus
|
||||||
_, err = dc.Resource(deploymentResource).Namespace(testNamespaceName).Update(context.TODO(), &testDeploymentUpdateUnstructured, metav1.UpdateOptions{}) //, "status")
|
_, err = dc.Resource(deploymentResource).Namespace(testNamespaceName).Update(context.TODO(), &testDeploymentUpdateUnstructured, metav1.UpdateOptions{}) //, "status")
|
||||||
if err != nil {
|
framework.ExpectNoError(err, "failed to update the DeploymentStatus")
|
||||||
fmt.Println(err, "failed to update the DeploymentStatus")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for event := range dplmtWatchChan {
|
for event := range dplmtWatchChan {
|
||||||
if event.Type == watch.Modified {
|
if event.Type == watch.Modified {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("fetching the DeploymentStatus")
|
ginkgo.By("fetching the DeploymentStatus")
|
||||||
deploymentGetUnstructured, err := dc.Resource(deploymentResource).Namespace(testNamespaceName).Get(context.TODO(), testDeploymentName, metav1.GetOptions{}, "status")
|
deploymentGetUnstructured, err := dc.Resource(deploymentResource).Namespace(testNamespaceName).Get(context.TODO(), testDeploymentName, metav1.GetOptions{}, "status")
|
||||||
if err != nil {
|
framework.ExpectNoError(err, "failed to fetch the Deployment")
|
||||||
fmt.Println(err, "failed to fetch the Deployment")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
deploymentGet := appsv1.Deployment{}
|
deploymentGet := appsv1.Deployment{}
|
||||||
err = runtime.DefaultUnstructuredConverter.FromUnstructured(deploymentGetUnstructured.Object, &deploymentGet)
|
err = runtime.DefaultUnstructuredConverter.FromUnstructured(deploymentGetUnstructured.Object, &deploymentGet)
|
||||||
if err != nil {
|
framework.ExpectNoError(err, "failed to convert the unstructured response to a Deployment")
|
||||||
fmt.Println(err, "failed to convert the unstructured response to a Deployment")
|
framework.ExpectEqual(deploymentGet.Spec.Template.Spec.Containers[0].Image, testDeploymentUpdateImage, "failed to update image")
|
||||||
return
|
framework.ExpectEqual(deploymentGet.ObjectMeta.Labels["test-deployment"], "updated", "failed to update labels")
|
||||||
}
|
|
||||||
if !(deploymentGet.Spec.Template.Spec.Containers[0].Image == testDeploymentUpdateImage || deploymentGet.Status.ReadyReplicas == testDeploymentNoReplicas || deploymentGet.ObjectMeta.Labels["test-deployment"] == "updated") {
|
|
||||||
fmt.Println("failed to update the Deployment (did not return correct values)")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for event := range dplmtWatchChan {
|
for event := range dplmtWatchChan {
|
||||||
if event.Type == watch.Modified {
|
if event.Type == watch.Modified {
|
||||||
break
|
break
|
||||||
@ -348,16 +293,13 @@ var _ = SIGDescribe("Deployment", func() {
|
|||||||
}
|
}
|
||||||
for event := range dplmtWatchChan {
|
for event := range dplmtWatchChan {
|
||||||
deployment, ok := event.Object.(*appsv1.Deployment)
|
deployment, ok := event.Object.(*appsv1.Deployment)
|
||||||
if ok != true {
|
framework.ExpectEqual(ok, true, "unable to convert event.Object type")
|
||||||
fmt.Println("failed to convert event Object to a Deployment")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if deployment.Status.ReadyReplicas == testDeploymentDefaultReplicas {
|
if deployment.Status.ReadyReplicas == testDeploymentDefaultReplicas {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("patching the DeploymentStatus")
|
ginkgo.By("patching the DeploymentStatus")
|
||||||
deploymentStatusPatch, err := json.Marshal(map[string]interface{}{
|
deploymentStatusPatch, err := json.Marshal(map[string]interface{}{
|
||||||
"metadata": map[string]interface{}{
|
"metadata": map[string]interface{}{
|
||||||
"labels": map[string]string{"test-deployment": "patched-status"},
|
"labels": map[string]string{"test-deployment": "patched-status"},
|
||||||
@ -366,29 +308,17 @@ var _ = SIGDescribe("Deployment", func() {
|
|||||||
"readyReplicas": testDeploymentNoReplicas,
|
"readyReplicas": testDeploymentNoReplicas,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
framework.ExpectNoError(err, "failed to Marshal Deployment JSON patch")
|
||||||
fmt.Println(err, "failed to Marshal Deployment JSON patch")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
dc.Resource(deploymentResource).Namespace(testNamespaceName).Patch(context.TODO(), testDeploymentName, types.StrategicMergePatchType, []byte(deploymentStatusPatch), metav1.PatchOptions{}, "status")
|
dc.Resource(deploymentResource).Namespace(testNamespaceName).Patch(context.TODO(), testDeploymentName, types.StrategicMergePatchType, []byte(deploymentStatusPatch), metav1.PatchOptions{}, "status")
|
||||||
|
|
||||||
fmt.Println("fetching the DeploymentStatus")
|
ginkgo.By("fetching the DeploymentStatus")
|
||||||
deploymentGetUnstructured, err = dc.Resource(deploymentResource).Namespace(testNamespaceName).Get(context.TODO(), testDeploymentName, metav1.GetOptions{}, "status")
|
deploymentGetUnstructured, err = dc.Resource(deploymentResource).Namespace(testNamespaceName).Get(context.TODO(), testDeploymentName, metav1.GetOptions{}, "status")
|
||||||
|
framework.ExpectNoError(err, "failed to fetch the DeploymentStatus")
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err, "failed to fetch the DeploymentStatus")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
deploymentGet = appsv1.Deployment{}
|
deploymentGet = appsv1.Deployment{}
|
||||||
err = runtime.DefaultUnstructuredConverter.FromUnstructured(deploymentGetUnstructured.Object, &deploymentGet)
|
err = runtime.DefaultUnstructuredConverter.FromUnstructured(deploymentGetUnstructured.Object, &deploymentGet)
|
||||||
if err != nil {
|
framework.ExpectNoError(err, "failed to convert the unstructured response to a Deployment")
|
||||||
fmt.Println(err, "failed to convert the unstructured response to a Deployment")
|
framework.ExpectEqual(deploymentGet.Spec.Template.Spec.Containers[0].Image, testDeploymentUpdateImage, "failed to update image")
|
||||||
return
|
framework.ExpectEqual(deploymentGet.ObjectMeta.Labels["test-deployment"], "updated", "failed to update labels")
|
||||||
}
|
|
||||||
if !(deploymentGet.Spec.Template.Spec.Containers[0].Image == testDeploymentUpdateImage || deploymentGet.Status.ReadyReplicas == 0 || deploymentGet.ObjectMeta.Labels["test-deployment"] == "patched-status") {
|
|
||||||
fmt.Println("failed to update the Deployment (did not return correct values)")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for event := range dplmtWatchChan {
|
for event := range dplmtWatchChan {
|
||||||
if event.Type == watch.Modified {
|
if event.Type == watch.Modified {
|
||||||
break
|
break
|
||||||
@ -396,14 +326,22 @@ var _ = SIGDescribe("Deployment", func() {
|
|||||||
}
|
}
|
||||||
for event := range dplmtWatchChan {
|
for event := range dplmtWatchChan {
|
||||||
deployment, ok := event.Object.(*appsv1.Deployment)
|
deployment, ok := event.Object.(*appsv1.Deployment)
|
||||||
if ok != true {
|
framework.ExpectEqual(ok, true, "unable to convert event.Object type")
|
||||||
fmt.Println("failed to convert event Object to a Deployment")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if deployment.Status.ReadyReplicas == testDeploymentDefaultReplicas {
|
if deployment.Status.ReadyReplicas == testDeploymentDefaultReplicas {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ginkgo.By("deleting the Deployment")
|
||||||
|
err = f.ClientSet.AppsV1().Deployments(testNamespaceName).DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: testDeploymentLabelsFlat})
|
||||||
|
framework.ExpectNoError(err, "failed to delete Deployment via collection")
|
||||||
|
for event := range dplmtWatchChan {
|
||||||
|
deployment, ok := event.Object.(*appsv1.Deployment)
|
||||||
|
framework.ExpectEqual(ok, true, "unable to convert event.Object type")
|
||||||
|
if event.Type == watch.Deleted && deployment.ObjectMeta.Name == testDeploymentName {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user