-
Notifications
You must be signed in to change notification settings - Fork 1
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
Parameterize gateway namespace used by nb-ctrlr #14
Conversation
There was a problem hiding this 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 :)
ossmEnv := filepath.Join(kfnotebookControllerServiceMeshPath, "ossm.env") | ||
namespace := dscispec.ApplicationsNamespace | ||
|
||
pattern := `ISTIO_GATEWAY=(.*)/odh-gateway` |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
pkg/common/common.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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 func
s 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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
290f1b1
to
e0f68b7
Compare
dc96a6e
to
5c07176
Compare
@@ -0,0 +1,19 @@ | |||
package ossmcommon |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
e015bb4
to
876e587
Compare
- intialization of Service Mesh Auth(z) as part of DSCI - support for Dashboard and Workbenches components
876e587
to
454edb4
Compare
Update components/workbenches/workbenches.go Co-authored-by: Bartosz Majsak <bartosz.majsak@gmail.com> 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
3127fe6
to
e16c812
Compare
454edb4
to
724837d
Compare
Merged in 724837d |
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.