-
Notifications
You must be signed in to change notification settings - Fork 9
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
cli: add support for environment tags #345
Conversation
57dd82e
to
fb4c819
Compare
Also open to the idea of |
The tag IDs are a bit surprising. We don't typically expose IDs like this--I would have expected this to act exactly like stack tags. infrastructure ❯ pulumi stack tag
Manage stack tags
Stacks have associated metadata in the form of tags. Each tag consists of a name
and value. The `get`, `ls`, `rm`, and `set` commands can be used to manage tags.
Some tags are automatically assigned based on the environment each time a stack
is updated.
Usage:
pulumi stack tag [command]
Available Commands:
get Get a single stack tag value
ls List all stack tags
rm Remove a stack tag
set Set a stack tag
Flags:
-h, --help help for tag
-s, --stack string The name of the stack to operate on. Defaults to the current stack
Global Flags:
--color string Colorize output. Choices are: always, never, raw, auto (default "auto")
-C, --cwd string Run pulumi as if it had been started in another directory
--disable-integrity-checking Disable integrity checking of checkpoint files
-e, --emoji Enable emojis in the output (default true)
-Q, --fully-qualify-stack-names Show fully-qualified stack names
--logflow Flow log settings to child processes (like plugins)
--logtostderr Log to stderr instead of to files
--memprofilerate int Enable more precise (and expensive) memory allocation profiles by setting runtime.MemProfileRate
--non-interactive Disable interactive mode for all commands
--profiling string Emit CPU and memory profiles and an execution trace to '[filename].[pid].{cpu,mem,trace}', respectively
--tracing file: Emit tracing to the specified endpoint. Use the file: scheme to write tracing data to a local file
-v, --verbose int Enable verbose logging (e.g., v=3); anything >3 is very verbose
Use "pulumi stack tag [command] --help" for more information about a command. |
👍 I can change the behavior to mirror stack tags. I intentionally made some tweaks to these commands vs the stack tags for a few reasons:
|
@pgavlin updated these commands to more closely align with stack tags
As an aside there is also a fix to show local time if the UTC flag is not set since most of the timestamps coming back from the server are UTC |
Could you update the PR description with the new command structure? Also--while the example output is nice, it's a bit tough to parse. I think I'd prefer a brief plain-english description of what each command does to the output. |
@pgavlin updated the description |
@@ -627,6 +627,86 @@ func (c *testPulumiClient) GetOpenProperty(ctx context.Context, orgName, envName | |||
return nil, errors.New("NYI") | |||
} | |||
|
|||
func (c *testPulumiClient) GetEnvironmentTag( |
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.
Can you add some tests?
If you add a new file in cli/testdata
, it will be automatically picked up by the test harness:
- The
run
section contains the command(s) to run - The
environments
section contains the environments to define for testing
Once you've filled in those two sections, you can generate the stdout
/stderr
sections by running PULUMI_ACCEPT=1 go test ./cmd/esc/cli
from the repository root.
You'll likely need to revert changes to cmd/esc/cli/testdata/env-login-gh100.yaml
and cmd/esc/cli/testdata/env-set.yaml
as the regeneration process makes undesirable formatting changes to those files.
cmd/esc/cli/cli_test.go
Outdated
var tags cliTestcaseEnvironmentTags | ||
envTags := map[string]string{} | ||
if err := env.Decode(&tags); err == nil { | ||
envTags = tags.Tags | ||
} |
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 that this is what we want. I think that we should add a new field to cliTestcaseRevisions
that contains the environment tags. That will give any test the ability to use environment tags as well as other features.
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.
Sorry do you mean moving the existing tags to cliTestcaseRevisions
instead of renaming them to revisionTags
on the test environment?
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--it looks like as written an environment can either contain a set of tags or a set of revisions (unless I'm reading it wrong?). Feels like instead we want cliTestcaseRevisions
to contain a field of type cliTestcaseEnvironmentTags
.
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.
ah yeah I follow you - will update
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.
actually thinking more about this I feel like it makes sense to keep these at the top level on the env since revision tags must be unique across all revisions. I did adjust the interface of revision tags though to allow for passing a list instead of a single value since that mirrors what the API supports
cmd/esc/cli/testdata/env-tag-mv.yaml
Outdated
run: | | ||
esc env tag ls test-org/env | ||
esc env tag mv test-org/env team esc | ||
esc env tag mv test-org/env team owner pulumi |
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.
what does this do? does this rename the tag and give it a new value?
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.
👍
cmd/esc/cli/testdata/env-tag.yaml
Outdated
run: | | ||
esc env tag ls test-org/env | ||
esc env tag test-org/env owner pulumi | ||
esc env tag get test-org/env owner |
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.
do we need a separate get
command? could tag
w/o a value just return the current value of the tag?
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's not required here since the return value of tag
does that but I added it to the test to demonstrate that it is being persisted
cmd/esc/cli/env_tag_mv.go
Outdated
var utc bool | ||
|
||
cmd := &cobra.Command{ | ||
Use: "mv [<org-name>/]<environment-name> <name> [<newName>] <value>", |
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 would remove the <value>
bit here and make this command purely a "rename" command:
mv [<org-name>/]<environment-name> <name> <newName>
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.
ah ok and keep the value updates under the tag "set" command?
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.
added back the update logic to the implied "set" command
Use: "tag [<org-name>/]<environment-name> <name> <value>", | ||
Args: cobra.ExactArgs(3), |
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 push this functionality under a set
command?
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 is good for consistency since revision tags don't explicitly call it set but instead just rely on tag
@@ -253,13 +253,14 @@ type testEnvironmentRetract struct { | |||
type testEnvironmentRevision struct { | |||
number int | |||
yaml []byte | |||
tag string | |||
tags map[string]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.
curious why this changed? this is tracking the revision's etag, which should be static?
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.
Oh interesting - this was used by the test files as a way to pass in a revision tag so I modified it to take multiple tags to mirror production. I did notice it was also being used as the etag but I figured that was solely out of convenience
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 did notice it was also being used as the etag but I figured that was solely out of convenience
ah interesting--this double duty was unintentional, and this should be the etag. for convenience you can leave these changes if you like and I can straighten things out later
Co-authored-by: Pat Gavlin <pat@pulumi.com>
@@ -253,13 +253,14 @@ type testEnvironmentRetract struct { | |||
type testEnvironmentRevision struct { | |||
number int | |||
yaml []byte | |||
tag string | |||
tags map[string]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.
I did notice it was also being used as the etag but I figured that was solely out of convenience
ah interesting--this double duty was unintentional, and this should be the etag. for convenience you can leave these changes if you like and I can straighten things out later
add new CLI commands for CRUD operations against environment tags