-
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
Design changes prog4 #2
Conversation
…ve unnecessary conditional checks
…ents based on db type
…generation based on DB type
api/v1alpha1/ndb_api_helpers.go
Outdated
// Setting action arguments based on database type | ||
dbTypeActionArgs := GetActionArgumentsByDatabaseType(dbSpec.Instance.Type) | ||
if dbTypeActionArgs != nil { | ||
req.ActionArguments = append(req.ActionArguments, dbTypeActionArgs.GetActionArguments(dbSpec)...) | ||
} else { | ||
var errStatement string | ||
err = errors.New("Invalid Database Type") | ||
errStatement = "Invalid Database Type: supported values: mysql, postgres, mongodb" | ||
log.Error(err, errStatement) |
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.
Would it make sense to return th error from the function GetActionArgumentsByDatabaseType()
instead?
Thinking about extensibility with the current code - if we add another DB engine / type in the future then we might have to change code at two places: GetActionArgumentsByDatabaseType and this code block (error statement). Returning an error from the default case and checking the return values of the GetActionArgumentsByDatabaseType() call might be a cleaner approach.
Something like:
dbTypeActionArgs, err := GetActionArgumentsByDatabaseType(dbSpec.Instance.Type)
if err != nil {
log.Error(err, "Error occurred while getting dbTypeActionArgs", "database type", dbSpec.Instance.Type)
return
}
What do you think?
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.
Hi Manav,
Updated the same PR with your suggested changes.
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.
Changes look good to me! Unit test covers the scenarios too.
Left a comment about an idea, let me know what you guys think about it.
Thanks!
What this PR does / why we need it:
To modularise the GenerateProvisioningRequest API by incorporating DRY principles and removing unwieldy conditional checks.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #
How Has This Been Tested?:
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and test output
Special notes for your reviewer:
Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.
Release note: