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

Parameterize gateway namespace used by nb-ctrlr #14

Conversation

cam-garrison
Copy link

This PR aims to fix Issue #617 by replacing the default namespace of the gateway with the application namespace before applying the notebook controller manifests.

Copy link

@bartoszmajsak bartoszmajsak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the gateway name dynamic. This way we are 1-1 with the v1 manifests we provided.

One additional thing - adding some tests wouldn't harm :)

components/workbenches/workbenches.go Outdated Show resolved Hide resolved
ossmEnv := filepath.Join(kfnotebookControllerServiceMeshPath, "ossm.env")
namespace := dscispec.ApplicationsNamespace

pattern := `ISTIO_GATEWAY=(.*)/odh-gateway`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be a const.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set as a const here but didnt pull out of the function - will do this when moving into a separate package 9613807

@@ -45,3 +46,29 @@ func ReplaceStringsInFile(fileName string, replacements map[string]string) error

return nil
}

// ReplacePatternsInFile uses regexes to replace patterns with replacements in manifests during runtime.
func ReplacePatternsInFile(fileName string, replacements map[string]string) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need two separate funcs to handle strings or regular expressions. One should suffice. See example https://go.dev/play/p/-5A8-bkarvS

Also, instead of regexp.MustCompile which panics perhaps it's better use regexp.Compile and push the error down the call stack so that it can be managed appropriately at a higher level like in other cases.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, I like this solution, working on implementing this now

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implemented here - consolidated both into one with a helper func 9613807

@@ -180,3 +185,16 @@ func (w *Workbenches) DeepCopyInto(target *Workbenches) {
*target = *w
target.Component = w.Component
}

func (w *Workbenches) SetGatewayName(dscispec *dsci.DSCInitializationSpec) error {
ossmEnv := filepath.Join(kfnotebookControllerServiceMeshPath, "ossm.env")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we fail if the file does not exist?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We fail in the ReplaceInFile helper function if it fails to read file for some reason - don't think it should be in both places.

@@ -180,3 +185,16 @@ func (w *Workbenches) DeepCopyInto(target *Workbenches) {
*target = *w
target.Component = w.Component
}

func (w *Workbenches) SetGatewayName(dscispec *dsci.DSCInitializationSpec) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we need this as exported func. Keeping it private should suffice. This in fact makes me wonder if this really belongs here. It's a specific OSSM manifests customization so perhaps making it its own func and package would be a bit cleaner? That would also simplify testing it.

Copy link
Author

@cam-garrison cam-garrison Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved out into a separate package "ossmcommon" within the servicemesh directory - let me know what you think of location / naming

@@ -0,0 +1,19 @@
package ossmcommon

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a big fan of using generic packages like "common" or "util". It is troublesome on a few fronts.

  • ambiguity: generic names don't convey specific functionality, making it difficult to understand the purpose of the package at a glance.
  • lack of cohesion: they're often dumping ground for anything which we can find a better place for.
  • maintenance: for the reason above they grow out of control with misc utilities, so it's harder to spot redunant code/functionalities, but also any change risks a side effect due to widespread use across the whole code base.

Consider naming more descriptively and grouping related functionalities.


const gatewayPattern = `ISTIO_GATEWAY=(.*)/odh-gateway`

func SetGatewayName(dscispec *dsci.DSCInitializationSpec, kfnotebookControllerServiceMeshPath string) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only need to pass namespace, not the whole dsci.DSCInitializationSpec struct pointer, so perhaps better to keep it smaller/more focused.

I am wondering if we shouldn't name SetGatewayName to OverwriteGatewayName, as that's what is effectively happening.

"strings"
)

var _ = Describe("SetGatewayName", func() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name test after feature/behaviour you want to test, not the func name.

BeforeEach(func() {
var err error

tempDir, err = os.MkdirTemp("", "ossm-test")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting from Go 1.15, the standard testing package includes T.TempDir(), perhaps worth giving a try, especially that it's fully supported by Ginkgo GinkgoT().TempDir(). You will at least save few lines of code for cleanup :)

Expect(err).NotTo(HaveOccurred())

expected := "ISTIO_GATEWAY=testnamespace/odh-gateway"
Expect(strings.Contains(string(updatedContents), expected)).To(BeTrue(), "Expected content to contain %q, got %q", expected, updatedContents)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can leverage built-in Gomega matchers for simplicity https://onsi.github.io/gomega/#working-with-strings-json-and-yaml

@bartoszmajsak bartoszmajsak force-pushed the service-mesh-integration branch 2 times, most recently from e015bb4 to 876e587 Compare October 25, 2023 16:54
- intialization of Service Mesh Auth(z) as part of DSCI
- support for Dashboard and Workbenches components
Update components/workbenches/workbenches.go

Co-authored-by: Bartosz Majsak <[email protected]>

consolidate regex and string replace funcs into one w helper

move to package, add testing

move out gateway const

rename to ossmcommon

clean up unit tests

rename pkg, move io funcs, rename gw func
@bartoszmajsak
Copy link

Merged in 724837d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants