-
Couldn't load subscription status.
- Fork 2k
Fix job_run to show appropriate namespace in web UI link #26738
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
Open
nipunn1313
wants to merge
3
commits into
hashicorp:main
Choose a base branch
from
nipunn1313:nipunn/fix_job_run
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+66
−3
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ```release-note:bug | ||
| cli: Fixed nomad run web ui link for namespaces | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,10 @@ import ( | |
| "time" | ||
|
|
||
| "github.com/hashicorp/cli" | ||
| "github.com/hashicorp/nomad/api" | ||
| "github.com/hashicorp/nomad/ci" | ||
| "github.com/hashicorp/nomad/command/agent" | ||
| "github.com/hashicorp/nomad/helper/pointer" | ||
| "github.com/hashicorp/nomad/testutil" | ||
| "github.com/shoenig/test/must" | ||
| ) | ||
|
|
@@ -281,3 +284,60 @@ func TestRunCommand_JSON(t *testing.T) { | |
| must.Eq(t, "", stderr) | ||
| must.NotEq(t, "", stdout) | ||
| } | ||
|
|
||
| // TestRunCommand_NamespaceInUILink tests that the UI link uses the job's namespace | ||
| // rather than the CLI namespace when they differ. | ||
| func TestRunCommand_NamespaceInUILink(t *testing.T) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is actually writing to nomad - I don't think this is what we want - going to remove it. |
||
| ci.Parallel(t) | ||
|
|
||
| // Create a server with UI hints enabled | ||
| srv, client, url := testServer(t, true, func(c *agent.Config) { | ||
| c.UI.ShowCLIHints = pointer.Of(true) | ||
| }) | ||
| defer srv.Shutdown() | ||
| waitForNodes(t, client) | ||
|
|
||
| // Create a job with a non-default namespace | ||
| _, err := client.Namespaces().Register(&api.Namespace{Name: "internal"}, nil) | ||
| must.NoError(t, err) | ||
|
|
||
| // Create a job file with the "internal" namespace | ||
| jobFile := filepath.Join(t.TempDir(), "test.nomad") | ||
| jobSpec := ` | ||
| job "test-job" { | ||
| namespace = "internal" | ||
| type = "service" | ||
| datacenters = ["dc1"] | ||
| group "web" { | ||
| count = 1 | ||
| task "web" { | ||
| driver = "exec" | ||
| resources { | ||
| cpu = 100 | ||
| memory = 64 | ||
| } | ||
| } | ||
| } | ||
| }` | ||
| must.NoError(t, os.WriteFile(jobFile, []byte(jobSpec), 0644)) | ||
|
|
||
| ui := cli.NewMockUi() | ||
| cmd := &JobRunCommand{ | ||
| Meta: Meta{ | ||
| Ui: ui, | ||
| flagAddress: url, | ||
| // Deliberately set CLI namespace to "default" to test that | ||
| // the job's namespace ("internal") takes precedence | ||
| namespace: "default", | ||
| }, | ||
| } | ||
|
|
||
| // Run the job in detach mode so we get the UI hint | ||
| code := cmd.Run([]string{"-detach", jobFile}) | ||
| must.Zero(t, code) | ||
|
|
||
| // Verify that the UI link uses the job's namespace ("internal") not the CLI namespace ("default") | ||
| output := ui.ErrorWriter.String() | ||
| must.StrContains(t, output, "/ui/jobs/test-job@internal") | ||
| must.StrNotContains(t, output, "/ui/jobs/test-job@default") | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
heya @nipunn1313, thanks for the PR!
I believe this resolves the issue for jobs that have
namespacedefined within the job specification, but it's also possible to specify the namespace on the CLI:nomad job run -namespace='some-other-ns' job.nomad.hclwhich is what
c.Meta.namespacereflects, so I think this change breaks that case.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.
Yeah - I'm realizing we probably want to prioritize the CLI and then if CLI is missing - use the namespace within the job specification.