-
Notifications
You must be signed in to change notification settings - Fork 68
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
astro-cli should prompt the user for namespace name input when pre-deployment validation is configured #487
Conversation
…r k8 namespace name to be enter instead of select from available k8 namespaces
func getDeploymentNamespaceName() (string, error) { | ||
namespaceName := input.Text("\nKubernetes Namespace Name: ") | ||
noSpaceString := strings.ReplaceAll(namespaceName, " ", "") | ||
if noSpaceString == "" { |
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.
Does it make sense to do empty string validation?
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.
It does make sense to me to validate the input, but it would also be decent idea to strip unwanted spaces from the input text entered by the user, i.e.
namespaceName = strings.ReplaceAll(namespace, " ", "")
if namespaceName == "" {
return "", ErrKubernetesNamespaceNotSpecified
}
return namespaceName, nil
Codecov Report
@@ Coverage Diff @@
## main #487 +/- ##
==========================================
+ Coverage 66.30% 66.45% +0.14%
==========================================
Files 42 42
Lines 3642 3658 +16
==========================================
+ Hits 2415 2431 +16
Misses 1054 1054
Partials 173 173
Continue to review full report at Codecov.
|
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.
Great work 👍 , have added few minor suggestions
@@ -133,6 +134,14 @@ func CheckPreCreateNamespaceDeployment(client *houston.Client) bool { | |||
return appConfig.Flags.ManualNamespaceNames | |||
} | |||
|
|||
func CheckNamespaceFreeformEntryDeployment(client *houston.Client) bool { |
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.
Nit: CheckNamespaceFreeformEntryDeployment
=> checkNamespaceFreeformEntryDeployment
If the scope of this function is just limited to this package, then we can keep this function private (any field, method or function starting with uppercase letter will be a public function, and if it is starting with lowercase letter then it will be a private function).
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, I think it will make more sense to make it private since I don't see a use case for now where we can call this from outside.
func getDeploymentNamespaceName() (string, error) { | ||
namespaceName := input.Text("\nKubernetes Namespace Name: ") | ||
noSpaceString := strings.ReplaceAll(namespaceName, " ", "") | ||
if noSpaceString == "" { |
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.
It does make sense to me to validate the input, but it would also be decent idea to strip unwanted spaces from the input text entered by the user, i.e.
namespaceName = strings.ReplaceAll(namespace, " ", "")
if namespaceName == "" {
return "", ErrKubernetesNamespaceNotSpecified
}
return namespaceName, nil
@@ -146,14 +155,22 @@ func CheckTriggererEnabled(client *houston.Client) bool { | |||
func Create(label, ws, releaseName, cloudRole, executor, airflowVersion, dagDeploymentType, nfsLocation, gitRepoURL, gitRevision, gitBranchName, gitDAGDir, sshKey, knownHosts string, gitSyncInterval, triggererReplicas int, client *houston.Client, out io.Writer) error { | |||
vars := map[string]interface{}{"label": label, "workspaceId": ws, "executor": executor, "cloudRole": cloudRole} | |||
|
|||
if CheckPreCreateNamespaceDeployment(client) { | |||
if CheckPreCreateNamespaceDeployment(client) && !CheckNamespaceFreeformEntryDeployment(client) { |
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.
nit: we can get rid of individual function call to get a field value from appConfig, but rather have a single call to Houston to get all the appConfig and then directly picking the individual field throughout the Create
method. This will save multiple API calls to Houston to fetch the same appConfig data.
appConfig, err := AppConfig(client)
if err != nil {
fmt.Println("Error fetching feature flags from Houston: %s", err.Error())
}
if appConfig.Flags.ManualNamespaceNames && !appConfig.Flags.NamespaceFreeformEntry {
namespace, err := getDeploymentSelectionNamespaces(client, out)
if err != nil {
return err
}
vars["namespace"] = namespace
}
if appConfig.Flags.ManualNamespaceNames && appConfig.Flags.NamespaceFreeformEntry {
namespace, err := getDeploymentNamespaceName()
if err != nil {
return err
}
vars["namespace"] = namespace
}
if releaseName != "" && appConfig.ManualReleaseNames {
vars["releaseName"] = releaseName
}
.......
if appConfig.Flags.TriggererEnabled {
vars["triggererReplicas"] = triggererReplicas
}
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.
Yes I think it does make sense to do.
@neel-astro Will it be fine If I open another PR with the suggested changes? |
yeah sure 👍, you can reference this issue if you are consolidating all Houston API calls in |
…ployment validation is configured (#487) * based on pre-deployment validation config, user should be prompted for k8 namespace name to be enter instead of select from available k8 namespaces * added test cases for NamespaceFreeformEntry (Pre-Deployment validation webhook) * fixed broken test cases for namespaceFreeformEntry * fixed broken test cases * updated ErrKubernetesNamespaceNotSpecified message changes create client interface and implementation for houston methods fix linter, rename methods
…ployment validation is configured (#487) * based on pre-deployment validation config, user should be prompted for k8 namespace name to be enter instead of select from available k8 namespaces * added test cases for NamespaceFreeformEntry (Pre-Deployment validation webhook) * fixed broken test cases for namespaceFreeformEntry * fixed broken test cases * updated ErrKubernetesNamespaceNotSpecified message changes create client interface and implementation for houston methods fix linter, rename methods
…ployment validation is configured (#487) * based on pre-deployment validation config, user should be prompted for k8 namespace name to be enter instead of select from available k8 namespaces * added test cases for NamespaceFreeformEntry (Pre-Deployment validation webhook) * fixed broken test cases for namespaceFreeformEntry * fixed broken test cases * updated ErrKubernetesNamespaceNotSpecified message changes create client interface and implementation for houston methods fix linter, rename methods
…ion for houston methods) (#490) * create client interface and implementation for houston methods * update controller packages to use new houston client * update cmds and main to use new houston client * change houston variable visiblity * fix linter, rename methods * moved away from pkg/errors (#484) * astro-cli should prompt the user for namespace name input when pre-deployment validation is configured (#487) * based on pre-deployment validation config, user should be prompted for k8 namespace name to be enter instead of select from available k8 namespaces * added test cases for NamespaceFreeformEntry (Pre-Deployment validation webhook) * fixed broken test cases for namespaceFreeformEntry * fixed broken test cases * updated ErrKubernetesNamespaceNotSpecified message changes create client interface and implementation for houston methods fix linter, rename methods * fix airflow upgrade * fix test and add mocks for houston client w/ mockery * fix houston request errors add proper json tags * rename methods according to code review * fix new log_tests, use renamed houston newClient method * deploy test: add assertions on the houston mock client * move houston mocks to houston directory * add tests for houston package Co-authored-by: Neel Dalsania <92356010+neel-astro@users.noreply.github.com> Co-authored-by: Aj <ajayy101@gmail.com>
…ployment validation is configured (#487) * based on pre-deployment validation config, user should be prompted for k8 namespace name to be enter instead of select from available k8 namespaces * added test cases for NamespaceFreeformEntry (Pre-Deployment validation webhook) * fixed broken test cases for namespaceFreeformEntry * fixed broken test cases * updated ErrKubernetesNamespaceNotSpecified message changes create client interface and implementation for houston methods fix linter, rename methods
* create client interface and implementation for houston methods * change houston variable visiblity * fix linter, rename methods * moved away from pkg/errors (#484) * astro-cli should prompt the user for namespace name input when pre-deployment validation is configured (#487) * based on pre-deployment validation config, user should be prompted for k8 namespace name to be enter instead of select from available k8 namespaces * added test cases for NamespaceFreeformEntry (Pre-Deployment validation webhook) * fixed broken test cases for namespaceFreeformEntry * fixed broken test cases * updated ErrKubernetesNamespaceNotSpecified message changes create client interface and implementation for houston methods fix linter, rename methods * fix test and add mocks for houston client w/ mockery * rename methods according to code review * move houston mocks to houston directory * refactor tests to use houston client mock * rename mocks package to use houston_mocks Co-authored-by: Neel Dalsania <92356010+neel-astro@users.noreply.github.com> Co-authored-by: Aj <ajayy101@gmail.com>
Description
🎟 Issue(s)
Related astronomer/issues#4132
🧪 Functional Testing
📸 Screenshots
📋 Checklist
make test
before taking out of draft