Skip to content
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

allow for configurable update stream #101

Merged
4 commits merged into from
Jan 18, 2023
Merged

allow for configurable update stream #101

4 commits merged into from
Jan 18, 2023

Conversation

ghost
Copy link

@ghost ghost commented Jan 18, 2023

This commit has a few components:

  1. Some YAML utils: one for inserting values into generic YAML using dot-notation keys, and one for validating that YAML can be deserialized as a given object type.
  2. Introduces a new ~/.klotho/options.yaml for CLI options. These are strictly typed within the code, but we're more lenient in terms of configs we allow setting. In particular, we allow setting configs that we don't yet know about; this can be helpful in cases where you want to set a config that's available in a subsequent version, before you upgrade to that version. We do warn on this though: in manual testing, I had done "upgrade.stream" instead of "update.stream" and was confused why this didn't work, so I figured I'd help out the next person who runs into that.
  3. KlothoMain introduces a new flag, --set-option name=value. You can use it on its own, or inline it with --update.

I'm also getting rid of updater.go's DefaultStream var, because that really needs to be specified only by the KlothoMain instantiation.

This resolves #78

Standard checks

  • Unit tests: Note that I added a slightly ugly mockableLog to cli_options.go, so that I could test the warning messages. I consider these to be important from a usability perspective, but I'm open to opinions here — especially on how else to do it (would a func be better? or I could actually tap into the zap logger — it's possible to do that, though it's a bit messy)
  • Docs: This introduces new functionality. We'd probably want to document it at some point, but not yet. It is available in the --help text
  • Backwards compatibility: no issues

This commit has a few components:

1. Some YAML utils: one for inserting values into generic YAML using
   dot-notation keys, and one for validating that YAML can be
   deserialized as a given object type.
2. Introduces a new ~/.klotho/options.yaml for CLI options. These are
   strictly typed within the code, but we're more lenient in terms of
   configs we allow setting. In particular, we allow setting configs
   that we don't yet know about; this can be helpful in cases where you
   want to set a config that's available in a subsequent version, before
   you upgrade to that version. We do warn on this though: in manual
   testing, I had done "upgrade.stream" instead of "update.stream" and
   was confused why this didn't work, so I figured I'd help out the next
   person who runs into that.
3. KlothoMain introduces a new flag, `--set-option name=value`. You can
   use it on its own, or inline it with `--update`.

I'm also getting rid of updater.go's DefaultStream var, because that
really needs to be specified only by the KlothoMain instantiation.

This resolves #78
warns []string
}

func (ml *mockedLogger) Warn(msg string, fields ...zap.Field) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/klothoplatform/klotho/blob/main/pkg/validation/validation_test.go#L503

I use a zap observer to test log output if you think its less ugly. I think its personally a bit cleaner than this implementation, but up to you

Yuval Shavit added 2 commits January 18, 2023 10:34
This was just me trying to remind myself how errors.Is works.
Version string
VersionQualifier string
PluginSetup func(*PluginSetBuilder) error
DefaultUpdateStream string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is this the default if they have set it in their config?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so? It's the default, which they can then override in their options. (It's actually not overridable on a one-invocation-only basis, only via persisted options.)

(As an aside: I'm trying to use "options" for the CLI-wide stuff [which is currently only the update stream], to differentiate it from the klotho project configs -c.)

topNode = tree.Content[0] // the tree's root is a DocumentNode; we assume one document
}
setOptionAtNode := topNode
for _, segment := range segments[:len(segments)-1] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for 2a) are we finding the value at the non leaf path? ie up to bar in this scenario? I assume thats the intention, just making sure

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. We want the node right before the last segment, and then in 2b we set its value at that last segment.

So in fizz.buzz.foo = 123, the 2a loop gets you the fizz.buzz node, and then 2b sets *buzzNode["foo"] => 123

} else if warns := yaml_util.CheckValid[Options](optionsYaml, yaml_util.Strict); warns != nil {
logger.Warn(`Existing options contain extra parameters:`)
for _, e := range yaml_util.YamlErrors(warns) {
logger.Warnf(`▸ %s`, e)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why only warn instead of raising actual errors? Wouldnt this signal an incorrect usage of the set-options flag?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably signals incorrect usage, yes. But the incorrectness is just that it won't have any effect, not that it will have the wrong effect. So I figure a nice yellow warning is sufficient for that.

From previous experience, I've found that occasionally you want the ability to set a config that doesn't yet exist, which will take effect on the next update. For example, the next version of the tool may have an automatic migration that you want to modify. In cases like this, being able to specify a not-yet-existent config can be very useful. This approach also means that if you temporarily downgrade your version (once we have version pinning), you won't break your options file if you had set an option in 0.5.21 that doesn't exist in the 0.5.20 you've downgraded to.

Basically, I've found that being strict about "no unknown options" can get people into sticky situations, and that a nice clear warning is sufficient for catching typos.

@github-actions
Copy link

Package Line Rate Health
github.com/klothoplatform/klotho/pkg/analytics 2%
github.com/klothoplatform/klotho/pkg/annotation 23%
github.com/klothoplatform/klotho/pkg/cli 4%
github.com/klothoplatform/klotho/pkg/core 20%
github.com/klothoplatform/klotho/pkg/env_var 82%
github.com/klothoplatform/klotho/pkg/exec_unit 45%
github.com/klothoplatform/klotho/pkg/infra/kubernetes 58%
github.com/klothoplatform/klotho/pkg/infra/kubernetes/helm 52%
github.com/klothoplatform/klotho/pkg/input 63%
github.com/klothoplatform/klotho/pkg/lang 37%
github.com/klothoplatform/klotho/pkg/lang/dockerfile 0%
github.com/klothoplatform/klotho/pkg/lang/golang 9%
github.com/klothoplatform/klotho/pkg/lang/javascript 47%
github.com/klothoplatform/klotho/pkg/lang/python 60%
github.com/klothoplatform/klotho/pkg/lang/yaml 0%
github.com/klothoplatform/klotho/pkg/logging 7%
github.com/klothoplatform/klotho/pkg/multierr 95%
github.com/klothoplatform/klotho/pkg/provider/aws 60%
github.com/klothoplatform/klotho/pkg/runtime 75%
github.com/klothoplatform/klotho/pkg/static_unit 32%
github.com/klothoplatform/klotho/pkg/validation 73%
github.com/klothoplatform/klotho/pkg/yaml_util 79%
Summary 40% (3683 / 9308)

@ghost ghost merged commit d14a7c7 into main Jan 18, 2023
@ghost ghost deleted the editable-release-streams branch January 18, 2023 20:26
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Klotho CLI to specify release stream to update from
1 participant