forked from kubeflow/kubeflow
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the Handler when watch on SetContainerImageFromRegistry functi…
…on to check also for update Add test for checking the update of the notebook
- Loading branch information
Showing
4 changed files
with
237 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
components/odh-notebook-controller/e2e/notebook_update_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |