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

chore(cli): Adding support for Variable Sets #3018

Merged
merged 6 commits into from
Aug 3, 2023

Conversation

xoscar
Copy link
Collaborator

@xoscar xoscar commented Aug 1, 2023

This PR updates the CLI and fixes all of the automated tests to work with the new variable set changes

Changes

  • Updates CLI resources from environments to variable sets
  • Changes the environment flag for the vars flag when used when running a test
  • Fixes CLI e2e tests and trace-based testing

Fixes

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

https://www.loom.com/share/ccd34203368e4b9ba921ce8530cfb258

@xoscar xoscar self-assigned this Aug 1, 2023
@xoscar xoscar marked this pull request as ready for review August 1, 2023 18:52
@xoscar xoscar added the CLI label Aug 1, 2023
Copy link
Contributor

@danielbdias danielbdias left a comment

Choose a reason for hiding this comment

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

The overall PR is ok, but I'm missing one CLI e2e test: we should have a scenario to run a test using vars in the old format and the new one, just to guarantee that we are not breaking existing tests for our customers.
One example of test that does that is here: https://github.com/kubeshop/tracetest/blob/main/testing/cli-e2etest/testscenarios/test/run_test_test.go#L40

@@ -63,7 +63,7 @@ func init() {

runCmd.Flags().StringVarP(&runParams.DefinitionFile, "file", "f", "", "path to the definition file")
runCmd.Flags().StringVar(&runParams.ID, "id", "", "id of the resource to run")
runCmd.Flags().StringVarP(&runParams.EnvID, "environment", "e", "", "environment file or ID to be used")
runCmd.Flags().StringVarP(&runParams.VarsID, "vars", "", "", "variable set file or ID to be used")
Copy link
Contributor

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 be variableset here?

Suggested change
runCmd.Flags().StringVarP(&runParams.VarsID, "vars", "", "", "variable set file or ID to be used")
runCmd.Flags().StringVarP(&runParams.VarsID, "variableset", "", "", "variable set file or ID to be used")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As we were using a shorthand for environments, I thought we could continue using the same approach

@@ -84,8 +82,8 @@ func (p *resourceParameters) Validate(cmd *cobra.Command, args []string) []error

p.ResourceName = args[0]

_, err := resources.Get(p.ResourceName)
if errors.Is(err, resourcemanager.ErrResourceNotFound) {
exists := resources.Exists(p.ResourceName)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed this to use a different function because Get now writes the warning to the console if deprecated

@@ -63,7 +63,7 @@ func init() {

runCmd.Flags().StringVarP(&runParams.DefinitionFile, "file", "f", "", "path to the definition file")
runCmd.Flags().StringVar(&runParams.ID, "id", "", "id of the resource to run")
runCmd.Flags().StringVarP(&runParams.EnvID, "environment", "e", "", "environment file or ID to be used")
runCmd.Flags().StringVarP(&runParams.VarsID, "vars", "", "", "variable set file or ID to be used")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As we were using a shorthand for environments, I thought we could continue using the same approach

runCmd.Flags().BoolVarP(&runParams.SkipResultWait, "skip-result-wait", "W", false, "do not wait for results. exit immediately after test run started")
runCmd.Flags().StringVarP(&runParams.JUnitOuptutFile, "junit", "j", "", "file path to save test results in junit format")
runCmd.Flags().StringSliceVar(&runParams.RequriedGates, "required-gates", []string{}, "override default required gate. "+validRequiredGatesMsg())

//deprecated
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Still supporting this in case users need it

resourcemanager.WithTableConfig(resourcemanager.TableConfig{
Cells: []resourcemanager.TableCellConfig{
{Header: "ID", Path: "spec.id"},
{Header: "NAME", Path: "spec.name"},
{Header: "DESCRIPTION", Path: "spec.description"},
},
}),
resourcemanager.WithResourceType("VariableSet"),
resourcemanager.WithApplyPreProcessor(variableSetPreprocessor.Preprocess),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Preprocessor to switch Environment to VariableSet and DeprecatedAlias to pass the resourceType validations

deprecatedEnvironmentClient = resourcemanager.NewClient(
httpClient, cliLogger,
"environment", "environments",
resourcemanager.WithProxyResource("variableset"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Used to create an entry in the registry that will point to the variable set client

@@ -30,13 +31,33 @@ func (r *Registry) Get(resourceName string) (Client, error) {
return Client{}, ErrResourceNotFound
}

if c.options.proxyResource != "" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If proxy, check if the proxied resource exists

for k := range r.resources {
resources = append(resources, k)
for k, c := range r.resources {
if c.options.proxyResource == "" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Deleting the proxy resources from the list

return input, fmt.Errorf("could not unmarshal test yaml: %w", err)
}

if resource.Type == "Environment" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updates Environment to VariableSet

Copy link
Contributor

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 add a //TODO comment saying that this mapping will be removed in future versions?

@@ -17,6 +18,14 @@ test: # run tests for this application
go clean -testcache; \
go test -v -timeout 300s -p 1 ./...;

test/scenario: # run tests for this application
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will allows us execute a single testscenario

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea! 🎉

@@ -85,20 +85,47 @@ func TestRunTestWithHttpTriggerAndEnvironmentFile(t *testing.T) {
require.Equal("https://assets.pokemon.com/assets/cms2/img/pokedex/full/143.png", environmentVars.Spec.Values[1].Value)
})

t.Run("should pass when using environment id", func(t *testing.T) {
t.Run("should pass when using the deprecated environment definition file", func(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding a test to validate that the old way still works as expected

@xoscar
Copy link
Collaborator Author

xoscar commented Aug 2, 2023

return input, fmt.Errorf("could not unmarshal test yaml: %w", err)
}

if resource.Type == "Environment" {
Copy link
Contributor

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 add a //TODO comment saying that this mapping will be removed in future versions?

@@ -17,6 +18,14 @@ test: # run tests for this application
go clean -testcache; \
go test -v -timeout 300s -p 1 ./...;

test/scenario: # run tests for this application
Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea! 🎉

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can we name these files with smallcaps? (variableset instead of variableSet)

@xoscar xoscar merged commit 7dbc458 into 3000-rename-environments-to-variables Aug 3, 2023
29 of 30 checks passed
@xoscar xoscar deleted the 3014-update-the-cli branch August 3, 2023 13:49
xoscar added a commit that referenced this pull request Aug 3, 2023
* chore(backend) Updating Environment to Variable Set (#3007)

* chore(backend) Updating Environment to Variable Set

* Updating open api

* chore(frotend): Updating Environment to Variable Set (#3012)

* chore(backend) Updating Environment to Variable Set

* chore(frotend): Updating Environment to Variable Set

* PR comments

* chore(cli): Adding support for Variable Sets (#3018)

* chore(cli): Adding support for Variable Sets

* chore(cli): Fixing automated tests

* chore(cli): Updating UI

* adding environment backwards compability and tests

* adding environment backwards compability and tests

* PR review update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants