Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e/test: improve TestCaaDaemonsetRollingUpdate #1533

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions test/e2e/ibmcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,17 @@ func (c *IBMRollingUpdateAssert) VerifyOldVmDeleted(t *testing.T) {
options := &vpcv1.GetInstanceOptions{
ID: &id,
}
_, _, err := c.vpc.GetInstance(options)
in, _, err := c.vpc.GetInstance(options)

if err != nil {
log.Printf("Instance %s has been deleted: %v", id, err)
} else {
t.Fatalf("Instance %s still exists", id)
if *in.Status == "deleting" {
log.Printf("Instance %s is being deleting", id)
} else {
log.Printf("Instance %s current status: %s", id, *in.Status)
t.Fatalf("Instance %s still exists", id)
}
}
}
}
Expand Down
55 changes: 39 additions & 16 deletions test/e2e/rolling_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ import (
)

const WAIT_DEPLOYMENT_AVAILABLE_TIMEOUT = time.Second * 180
const OLD_VM_DELETION_TIMEOUT = time.Second * 60
const OLD_VM_DELETION_TIMEOUT = time.Second * 30

func doTestCaaDaemonsetRollingUpdate(t *testing.T, assert RollingUpdateAssert) {
runtimeClassName := "kata-remote"
namespace := envconf.RandomName("default", 7)
deploymentName := "nginx-deployment"
containerName := "nginx"
imageName := "nginx"
serviceName := "nginx-service"
deploymentName := "webserver-deployment"
containerName := "webserver"
imageName := "python:3"
huoqifeng marked this conversation as resolved.
Show resolved Hide resolved
serviceName := "webserver-service"
portName := "port80"
rc := int32(2)
labelsMap := map[string]string{
"app": "nginx",
"app": "webserver-app",
}
verifyPodName := "verify-pod"
verifyContainerName := "verify-container"
Expand All @@ -66,6 +66,11 @@ func doTestCaaDaemonsetRollingUpdate(t *testing.T, assert RollingUpdateAssert) {
Name: containerName,
Image: imageName,
ImagePullPolicy: v1.PullAlways,
Command: []string{
"python",
"-m",
"http.server",
},
},
},
RuntimeClassName: &runtimeClassName,
Expand All @@ -78,7 +83,7 @@ func doTestCaaDaemonsetRollingUpdate(t *testing.T, assert RollingUpdateAssert) {
{
Key: "app",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"nginx"},
Values: []string{"webserver-app"},
},
},
},
Expand All @@ -103,7 +108,7 @@ func doTestCaaDaemonsetRollingUpdate(t *testing.T, assert RollingUpdateAssert) {
{
Name: portName,
Port: int32(80),
TargetPort: intstr.FromInt(80),
TargetPort: intstr.FromInt(8000),
Protocol: v1.ProtocolTCP,
},
},
Expand Down Expand Up @@ -133,28 +138,28 @@ func doTestCaaDaemonsetRollingUpdate(t *testing.T, assert RollingUpdateAssert) {
}

upgradeFeature := features.New("CAA DaemonSet upgrade test").
WithSetup("Create nginx deployment and service", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
WithSetup("Create webserver deployment and service", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
client, err := cfg.NewClient()
if err != nil {
t.Fatal(err)
}

log.Info("Creating nginx deployment...")
log.Info("Creating webserver deployment...")
if err = client.Resources().Create(ctx, deployment); err != nil {
t.Fatal(err)
}
waitForDeploymentAvailable(t, client, deployment, rc)
log.Info("nginx deployment is available now")
log.Info("webserver deployment is available now")

// Cache Pod VM instance IDs before upgrade
assert.CachePodVmIDs(t, deploymentName)

log.Info("Creating nginx Service")
log.Info("Creating webserver Service")
if err = client.Resources().Create(ctx, svc); err != nil {
t.Fatal(err)
}
clusterIP := waitForClusterIP(t, client, svc)
log.Printf("nginx service is available on cluster IP: %s", clusterIP)
log.Printf("webserver service is available on cluster IP: %s", clusterIP)

// Update verify command
verifyPod.Spec.Containers[0].Command = append(
Expand Down Expand Up @@ -198,7 +203,9 @@ func doTestCaaDaemonsetRollingUpdate(t *testing.T, assert RollingUpdateAssert) {
t.Fatal(err)
}

// Wait for nginx deployment available again
waitForCaaDaemonSetUpdated(t, client, ds, rc)

// Wait for webserver deployment available again
waitForDeploymentAvailable(t, client, deployment, rc)

if err = client.Resources().Get(ctx, verifyPodName, namespace, verifyPod); err != nil {
Expand Down Expand Up @@ -246,12 +253,12 @@ func doTestCaaDaemonsetRollingUpdate(t *testing.T, assert RollingUpdateAssert) {
t.Fatal(err)
}

log.Info("Deleting nginx service...")
log.Info("Deleting webserver service...")
if err = client.Resources().Delete(ctx, svc); err != nil {
t.Fatal(err)
}

log.Info("Deleting nginx deployment...")
log.Info("Deleting webserver deployment...")
if err = client.Resources().Delete(ctx, deployment); err != nil {
t.Fatal(err)
}
Expand All @@ -262,6 +269,22 @@ func doTestCaaDaemonsetRollingUpdate(t *testing.T, assert RollingUpdateAssert) {
testEnv.Test(t, upgradeFeature)
}

func waitForCaaDaemonSetUpdated(t *testing.T, client klient.Client, ds *appsv1.DaemonSet, rc int32) {
if err := wait.For(conditions.New(client.Resources()).ResourceMatch(ds, func(object k8s.Object) bool {
dsObj, ok := object.(*appsv1.DaemonSet)
if !ok {
log.Printf("Not a DaemonSet object: %v", object)
return false
}

log.Printf("Current CAA DaemonSet UpdatedNumberScheduled: %d", dsObj.Status.UpdatedNumberScheduled)
log.Printf("Current CAA DaemonSet NumberAvailable: %d", dsObj.Status.NumberAvailable)
return dsObj.Status.UpdatedNumberScheduled == rc && dsObj.Status.NumberAvailable == rc
}), wait.WithTimeout(WAIT_DEPLOYMENT_AVAILABLE_TIMEOUT)); err != nil {
t.Fatal(err)
}
}

func waitForDeploymentAvailable(t *testing.T, client klient.Client, deployment *appsv1.Deployment, rc int32) {
if err := wait.For(conditions.New(client.Resources()).ResourceMatch(deployment, func(object k8s.Object) bool {
deployObj, ok := object.(*appsv1.Deployment)
Expand Down