Skip to content

Commit

Permalink
Add test for checking the update of the notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
atheo89 committed May 31, 2024
1 parent f070290 commit 6109c51
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"flag"
"fmt"
netv1 "k8s.io/api/networking/v1"
"os"
"testing"
"time"

netv1 "k8s.io/api/networking/v1"

nbv1 "github.com/kubeflow/kubeflow/components/notebook-controller/api/v1"
routev1 "github.com/openshift/api/route/v1"
"github.com/pkg/errors"
Expand Down Expand Up @@ -135,8 +136,9 @@ func TestE2ENotebookController(t *testing.T) {
if !t.Run("validate controllers", testNotebookControllerValidation) {
return
}
// Run create and delete tests for all the test notebooks
// Run create, update and delete tests for all the test notebooks
t.Run("create", creationTestSuite)
t.Run("update", updateTestSuite)
if !skipDeletion {
t.Run("delete", deletionTestSuite)
}
Expand Down
92 changes: 92 additions & 0 deletions components/odh-notebook-controller/e2e/notebook_update_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package e2e

import (
"fmt"
"testing"

nbv1 "github.com/kubeflow/kubeflow/components/notebook-controller/api/v1"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
)

func updateTestSuite(t *testing.T) {
testCtx, err := NewTestContext()
require.NoError(t, err)
notebooksForSelectedDeploymentMode := notebooksForScenario(testCtx.testNotebooks, deploymentMode)
for _, nbContext := range notebooksForSelectedDeploymentMode {
// prepend Notebook name to every subtest
t.Run(nbContext.nbObjectMeta.Name, func(t *testing.T) {
t.Run("Update Notebook instance", func(t *testing.T) {
err = testCtx.testNotebookUpdate(nbContext)
require.NoError(t, err, "error updating Notebook object ")
})
t.Run("Notebook Route Validation After Update", func(t *testing.T) {
if deploymentMode == ServiceMesh {
t.Skipf("Skipping as it's not relevant for Service Mesh scenario")
}
err = testCtx.testNotebookRouteCreation(nbContext.nbObjectMeta)
require.NoError(t, err, "error testing Route for Notebook after update ")
})

t.Run("Notebook Network Policies Validation After Update", func(t *testing.T) {
err = testCtx.testNetworkPolicyCreation(nbContext.nbObjectMeta)
require.NoError(t, err, "error testing Network Policies for Notebook after update ")
})

t.Run("Notebook Statefulset Validation After Update", func(t *testing.T) {
err = testCtx.testNotebookValidation(nbContext.nbObjectMeta)
require.NoError(t, err, "error testing StatefulSet for Notebook after update ")
})

t.Run("Notebook OAuth sidecar Validation After Update", func(t *testing.T) {
if deploymentMode == ServiceMesh {
t.Skipf("Skipping as it's not relevant for Service Mesh scenario")
}
err = testCtx.testNotebookOAuthSidecar(nbContext.nbObjectMeta)
require.NoError(t, err, "error testing sidecar for Notebook after update ")
})

t.Run("Verify Notebook Traffic After Update", func(t *testing.T) {
err = testCtx.testNotebookTraffic(nbContext.nbObjectMeta)
require.NoError(t, err, "error testing Notebook traffic after update ")
})
})
}
}

func (tc *testContext) testNotebookUpdate(nbContext notebookContext) error {
notebookLookupKey := types.NamespacedName{Name: nbContext.nbObjectMeta.Name, Namespace: nbContext.nbObjectMeta.Namespace}
updatedNotebook := &nbv1.Notebook{}

err := tc.customClient.Get(tc.ctx, notebookLookupKey, updatedNotebook)
if err != nil {
return fmt.Errorf("error getting Notebook %s: %v", nbContext.nbObjectMeta.Name, err)
}

// Example update: Change the Notebook image
updatedNotebook.Spec.Template.Spec.Containers[0].Image = "new-image:latest"

err = tc.customClient.Update(tc.ctx, updatedNotebook)
if err != nil {
return fmt.Errorf("error updating Notebook %s: %v", updatedNotebook.Name, err)
}

// Wait for the update to be applied
err = wait.Poll(tc.resourceRetryInterval, tc.resourceCreationTimeout, func() (done bool, err error) {
note := &nbv1.Notebook{}
err = tc.customClient.Get(tc.ctx, notebookLookupKey, note)
if err != nil {
return false, err
}
if note.Spec.Template.Spec.Containers[0].Image == "new-image:latest" {
return true, nil
}
return false, nil
})

if err != nil {
return fmt.Errorf("error validating notebook update: %s", err)
}
return nil
}

0 comments on commit 6109c51

Please sign in to comment.