Skip to content

Commit

Permalink
fixup move user creation as early as possible, and explain test verbo…
Browse files Browse the repository at this point in the history
…sity
  • Loading branch information
jiridanek committed Nov 19, 2024
1 parent 7e939f1 commit b642e51
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
8 changes: 8 additions & 0 deletions components/odh-notebook-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ Run the following command to execute them:
make test
```

Useful options for running tests (that are already included in the above `make` command) are

| Option | Description |
|----------------------------|-----------------------------------------------------------------------------------------------|
| KUBEBUILDER_ASSETS= | Environment variable that specifies path to where Kubebuilder has downloaded envtest binaries |
| -ginkgo.v -ginkgo.progress | Enables verbose output from Ginkgo |
| -test.v | Enables verbose output from Go tests (*testing.T) |

The following environment variables are used to enable additional debug options for the tests

| Environment variable | Description |
Expand Down
26 changes: 13 additions & 13 deletions components/odh-notebook-controller/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
Expect(cfg).NotTo(BeNil())

if kubeconfigPath, found := os.LookupEnv("DEBUG_WRITE_KUBECONFIG"); found {
user := envtest.User{Name: "MasterOfTheSystems", Groups: []string{"system:masters"}}
authedUser, err := envTest.ControlPlane.AddUser(user, nil)
Expect(err).NotTo(HaveOccurred())
config, err := authedUser.KubeConfig()
Expect(err).NotTo(HaveOccurred())
err = os.WriteFile(kubeconfigPath, config, 0600)
Expect(err).NotTo(HaveOccurred())
GinkgoT().Logf("DEBUG_WRITE_KUBECONFIG is set, writing system:masters' Kubeconfig to %s", kubeconfigPath)
} else {
GinkgoT().Logf("DEBUG_WRITE_KUBECONFIG environment variable was not provided")
}

// Register API objects
scheme := runtime.NewScheme()
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
Expand Down Expand Up @@ -130,19 +143,6 @@ var _ = BeforeSuite(func() {
})
Expect(err).NotTo(HaveOccurred())

if kubeconfigPath, found := os.LookupEnv("DEBUG_WRITE_KUBECONFIG"); found {
user := envtest.User{Name: "MasterOfTheSystems", Groups: []string{"system:masters"}}
authedUser, err := envTest.ControlPlane.AddUser(user, nil)
Expect(err).NotTo(HaveOccurred())
config, err := authedUser.KubeConfig()
Expect(err).NotTo(HaveOccurred())
err = os.WriteFile(kubeconfigPath, config, 0600)
Expect(err).NotTo(HaveOccurred())
GinkgoT().Logf("DEBUG_WRITE_KUBECONFIG is set, writing system:masters' Kubeconfig to %s", kubeconfigPath)
} else {
GinkgoT().Logf("DEBUG_WRITE_KUBECONFIG environment variable was not provided")
}

// Setup notebook controller
err = (&OpenshiftNotebookReconciler{
Client: mgr.GetClient(),
Expand Down

0 comments on commit b642e51

Please sign in to comment.