-
Notifications
You must be signed in to change notification settings - Fork 875
fix: make template push a superset of template create #11299
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
Conversation
Before I go too far into making tests work and cleaning up the PR, I'd like @sreya to take a look and make sure this approach is sound. Thanks |
@f0ssel, this is great work. 👍🏼 This PR is a bit out of scope, but do you think we can also pull all template values, including metadata, using |
982def3
to
ff704ed
Compare
5934621
to
132efda
Compare
@matifali That all seems possible in a separate issue from my understanding but is out of scope for this PR. Can look into it next though. |
@f0ssel sounds fine. |
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.
My hope with the original issue was that we would reduce overall code complexity and quantity. Do you see a path to doing that here?
Also, I'm surprised we're checking entitlements in the CLI. It seems like we could separate concerns (and simplify the code) by just checking for entitlements on the server?
_, _ = fmt.Fprintln(inv.Stdout, "\n"+pretty.Sprint(cliui.DefaultStyles.Wrap, | ||
pretty.Sprint( | ||
cliui.DefaultStyles.Warn, "DEPRECATION WARNING: The `coder templates push` command should be used instead. This command will be removed in a future release. ")+"\n")) | ||
time.Sleep(1 * time.Second) |
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.
Love the sleep-based incentive, but we should tell the user that it's sleeping for a moment in the deprecation message so that the user doesn't just think our CLI is slow.
return xerrors.Errorf("get experiments: %w", exErr) | ||
} | ||
|
||
if !experiments.Enabled(codersdk.ExperimentWorkspaceActions) { |
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.
} | ||
} | ||
} | ||
|
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 splitting out this code.
allowUserAutostop: allowUserAutostop, | ||
requireActiveVersion: requireActiveVersion, | ||
deprecationMessage: deprecationMessage, | ||
}) |
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.
These mega structs are big code smells. It's not your PR's fault, but would enjoy seeing someone clean it up.
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.
On second thought, why don't we use the codersdk
types when validating entitlements?
requireActiveVersion bool | ||
} | ||
|
||
func checkEditTemplateEntitlements(ctx context.Context, args checkEditTemplateEntitlementsArgs) (bool, 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.
A bit surprised that we can't reuse much of the code between checking edit and checking create entitlements?
disableEveryone bool | ||
} | ||
|
||
func updateTemplateMetaRequest(args updateTemplateMetaArgs) codersdk.UpdateTemplateMeta { |
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.
See above comments on code reuse.
allowUserAutostart bool | ||
allowUserAutostop bool | ||
allowUserCancelWorkspaceJobs bool | ||
deprecationMessage string |
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 expect all these variable declarations to live in a struct somewhere so we weren't constantly repeating them.
@@ -188,10 +241,15 @@ func (r *RootCmd) templatePush() *clibase.Cmd { | |||
return err | |||
} | |||
|
|||
if utf8.RuneCountInString(name) > 31 { |
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:
if utf8.RuneCountInString(name) > 31 { | |
if utf8.RuneCountInString(name) >= 32 { |
less cognitive overhead to read the if statement and comment this way
@ammario Thanks for the review. There will be some code reduction once If API and code clarity are what we are really valuing here, I would almost suggest the opposite of this approach and make In addition to other comments I'll address, I can look into the entitlement stuff getting checked on the server, I also felt the issue with separation of concerns here. |
A major perceived benefit of combining the commands was idempotency. For example, in CI, you could write a script that iterates all folders and runs I like to think the best solution for the user and the codebase is the same thing. As an aside, we mistakenly call a lot of these fields "metadata" when in fact there's nothing "meta" about it. We should instead call it the template configuration. What do think about combining |
We call "config","metadata",whatever "settings" in the UI. So we should probably either follow that or change it everywhere. |
@ammario So there's where the difficulty is in these changes lie - we want to support flags that the create API accepts, but we don't always use the template create API because it could just be a version update. In the case where we update, we need to then use the template edit API to apply those flags as a supplement. This is where the template edit code comes into the
All 3 of these template commands do pretty different things and rely on different APIs, so we just need to figure out where to unify them. My favorite is #1, which comes at the cost of a less useful Secondly, I looked and after removing the |
I've mocked up a PR of what option 1 would look like here - #11390 basically we strip the settings flags from create and combine as much code as possible between the two commands for now. This would allow us to lead users to only using the |
OK thanks for the explanation. I'll leave a comment within #11390. |
Closing in favor of #11390 |
Closes #9318
The goal of this PR is to deprecate
template create
and have all options available fortemplate push
.--create
flag has been removed.coder templates push
command now has all the flag options of both create and edit.coder templates create
suggestion to now usepush
.coder template edit
does not, we think we should keep them both for now.Help: