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

Updating Environment to Variable Set #3016

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/expressions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ components:
type: string
selector:
type: string
environmentId:
variableSetId:
type: string
ResolveResponseInfo:
type: object
Expand Down
78 changes: 39 additions & 39 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1028,14 +1028,14 @@ paths:
"204":
description: OK

# Environments
/environments:
# VariableSets
/variableSets:
get:
tags:
- resource-api
summary: "List environments"
description: "List environments available in Tracetest."
operationId: listEnvironments
summary: "List VariableSets"
description: "List VariableSets available in Tracetest."
operationId: listVariableSets
parameters:
- $ref: "./parameters.yaml#/components/parameters/take"
- $ref: "./parameters.yaml#/components/parameters/skip"
Expand All @@ -1047,7 +1047,7 @@ paths:
content:
application/json:
schema:
$ref: "./environments.yaml#/components/schemas/EnvironmentResourceList"
$ref: "./variableSets.yaml#/components/schemas/VariableSetResourceList"
text/yaml:
schema:
type: object
Expand All @@ -1057,93 +1057,93 @@ paths:
items:
type: array
items:
$ref: "./environments.yaml#/components/schemas/EnvironmentResource"
$ref: "./variableSets.yaml#/components/schemas/VariableSetResource"
400:
description: "invalid query for environments, some data was sent in incorrect format."
description: "invalid query for VariableSets, some data was sent in incorrect format."
500:
description: "problem listing environments"
description: "problem listing VariableSets"
post:
tags:
- resource-api
summary: "Create an environment"
description: "Create an environment that can be used by tests and transactions"
operationId: createEnvironment
summary: "Create a VariableSet"
description: "Create a VariableSet that can be used by tests and transactions"
operationId: createVariableSet
requestBody:
content:
application/json:
schema:
$ref: "./environments.yaml#/components/schemas/EnvironmentResource"
$ref: "./variableSets.yaml#/components/schemas/VariableSetResource"
text/yaml:
schema:
$ref: "./environments.yaml#/components/schemas/EnvironmentResource"
$ref: "./variableSets.yaml#/components/schemas/VariableSetResource"
responses:
201:
description: successful operation
content:
application/json:
schema:
$ref: "./environments.yaml#/components/schemas/EnvironmentResource"
$ref: "./variableSets.yaml#/components/schemas/VariableSetResource"
text/yaml:
schema:
$ref: "./environments.yaml#/components/schemas/EnvironmentResource"
$ref: "./variableSets.yaml#/components/schemas/VariableSetResource"
500:
description: "problem creating an environment"
description: "problem creating an VariableSet"

/environments/{environmentId}:
/variableSets/{variableSetId}:
get:
tags:
- resource-api
parameters:
- $ref: "./parameters.yaml#/components/parameters/environmentId"
summary: "Get a specific environment"
description: "Get one environment by its id"
operationId: getEnvironment
- $ref: "./parameters.yaml#/components/parameters/variableSetId"
summary: "Get a specific VariableSet"
description: "Get one VariableSet by its id"
operationId: getVariableSet
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: "./environments.yaml#/components/schemas/EnvironmentResource"
$ref: "./variableSets.yaml#/components/schemas/VariableSetResource"
text/yaml:
schema:
$ref: "./environments.yaml#/components/schemas/EnvironmentResource"
$ref: "./variableSets.yaml#/components/schemas/VariableSetResource"
404:
description: "environment not found"
description: "VariableSet not found"
500:
description: "problem getting an environment"
description: "problem getting an VariableSet"
put:
tags:
- resource-api
parameters:
- $ref: "./parameters.yaml#/components/parameters/environmentId"
summary: "Update an environment"
description: "Update an environment used on Tracetest"
operationId: updateEnvironment
- $ref: "./parameters.yaml#/components/parameters/variableSetId"
summary: "Update a VariableSet"
description: "Update a VariableSet used on Tracetest"
operationId: updateVariableSet
requestBody:
content:
application/json:
schema:
$ref: "./environments.yaml#/components/schemas/EnvironmentResource"
$ref: "./variableSets.yaml#/components/schemas/VariableSetResource"
text/yaml:
schema:
$ref: "./environments.yaml#/components/schemas/EnvironmentResource"
$ref: "./variableSets.yaml#/components/schemas/VariableSetResource"
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: "./environments.yaml#/components/schemas/EnvironmentResource"
$ref: "./variableSets.yaml#/components/schemas/VariableSetResource"
text/yaml:
schema:
$ref: "./environments.yaml#/components/schemas/EnvironmentResource"
$ref: "./variableSets.yaml#/components/schemas/VariableSetResource"
400:
description: "invalid environment, some data was sent in incorrect format."
description: "invalid VariableSet, some data was sent in incorrect format."
404:
description: "environment not found"
description: "VariableSet not found"
500:
description: "problem updating an environment"
description: "problem updating an VariableSet"
delete:
tags:
- resource-api
Expand All @@ -1156,9 +1156,9 @@ paths:
204:
description: successful operation
400:
description: "invalid environment, some data was sent in incorrect format."
description: "invalid VariableSet, some data was sent in incorrect format."
404:
description: "environment not found"
description: "VariableSet not found"
500:
description: "problem deleting an environment"

Expand Down
6 changes: 3 additions & 3 deletions api/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ components:
schema:
type: string

environmentId:
variableSetId:
in: path
name: environmentId
name: variableSetId
required: true
description: "ID of an environment used on Tracetest to inject values into tests and transactions"
description: "ID of a VariableSet used on Tracetest to inject values into tests and transactions"
schema:
type: string

Expand Down
8 changes: 4 additions & 4 deletions api/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ components:
completedAt:
type: string
format: date-time
environment:
$ref: "./environments.yaml#/components/schemas/Environment"
variableSet:
$ref: "./variableSets.yaml#/components/schemas/VariableSet"
triggerResult:
$ref: "./triggers.yaml#/components/schemas/TriggerResult"
trace:
Expand Down Expand Up @@ -238,12 +238,12 @@ components:
nullable: true
additionalProperties:
type: string
environmentId:
variableSetId:
type: string
variables:
type: array
items:
$ref: "./environments.yaml#/components/schemas/EnvironmentValue"
$ref: "./variableSets.yaml#/components/schemas/VariableSetValue"
requiredGates:
type: array
nullable: true
Expand Down
4 changes: 2 additions & 2 deletions api/transactions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ components:
type: array
items:
$ref: "./tests.yaml#/components/schemas/TestRun"
environment:
$ref: "./environments.yaml#/components/schemas/Environment"
variableSet:
$ref: "./variableSets.yaml#/components/schemas/VariableSet"
metadata:
type: object
additionalProperties:
Expand Down
21 changes: 10 additions & 11 deletions api/environments.yaml → api/variableSets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@ openapi: 3.0.0

components:
schemas:
EnvironmentResourceList:
VariableSetResourceList:
type: object
properties:
count:
type: integer
items:
type: array
items:
$ref: "./environments.yaml#/components/schemas/EnvironmentResource"

EnvironmentResource:
$ref: "#/components/schemas/VariableSetResource"
VariableSetResource:
type: object
description: "Represents an environment structured into the Resources format."
description: "Represents a VariableSet structured into the Resources format."
properties:
type:
type: string
description: "Represents the type of this resource. It should always be set as 'Environment'."
description: "Represents the type of this resource. It should always be set as 'VariableSet'."
enum:
- Environment
- VariableSet
spec:
$ref: "#/components/schemas/Environment"
Environment:
$ref: "#/components/schemas/VariableSet"
VariableSet:
type: object
properties:
id:
Expand All @@ -35,8 +34,8 @@ components:
values:
type: array
items:
$ref: "#/components/schemas/EnvironmentValue"
EnvironmentValue:
$ref: "#/components/schemas/VariableSetValue"
VariableSetValue:
type: object
properties:
key:
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/legacy_test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var testRunCmd = &cobra.Command{
Run: func(_ *cobra.Command, _ []string) {
// map old flags to new ones
runParams.DefinitionFile = runTestFileDefinition
runParams.EnvID = runTestEnvID
runParams.VarsID = runTestEnvID
runParams.SkipResultWait = !runTestWaitForResult
runParams.JUnitOuptutFile = runTestJUnit

Expand Down
6 changes: 2 additions & 4 deletions cli/cmd/middleware.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package cmd

import (
"errors"
"fmt"
"os"

"github.com/kubeshop/tracetest/cli/pkg/resourcemanager"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -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)
if !exists {
suggestion := resources.Suggest(p.ResourceName)
if suggestion != "" {
return []error{
Expand Down
17 changes: 14 additions & 3 deletions cli/cmd/resource_run_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ func init() {
orchestrator := runner.Orchestrator(
cliLogger,
utils.GetAPIClient(cliConfig),
environmentClient,
variableSetClient,
)

if runParams.EnvID != "" {
runParams.VarsID = runParams.EnvID
}

runParams := runner.RunOptions{
ID: runParams.ID,
DefinitionFile: runParams.DefinitionFile,
EnvID: runParams.EnvID,
VarsID: runParams.VarsID,
SkipResultWait: runParams.SkipResultWait,
JUnitOuptutFile: runParams.JUnitOuptutFile,
RequiredGates: runParams.RequriedGates,
Expand All @@ -63,10 +67,16 @@ 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")
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
runCmd.Flags().StringVarP(&runParams.EnvID, "env", "e", "", "environment file or ID to be used")
runCmd.Flags().MarkDeprecated("env", "use --vars instead")
runCmd.Flags().MarkShorthandDeprecated("e", "use --vars instead")

rootCmd.AddCommand(runCmd)
}

Expand All @@ -82,6 +92,7 @@ func validRequiredGatesMsg() string {
type runParameters struct {
ID string
DefinitionFile string
VarsID string
EnvID string
SkipResultWait bool
JUnitOuptutFile string
Expand Down
Loading
Loading