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

feat: [TKC-2309] labels vars #5845

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: labels vars
Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>
  • Loading branch information
vsukhin committed Sep 11, 2024
commit ee236783f3d8ab8f1baacea1c766f34f66f69342
12 changes: 10 additions & 2 deletions cmd/tcl/testworkflow-toolkit/spawn/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ func CreateExecutionMachine(prefix string, index int64) (string, expressions.Mac
}
return id, expressions.NewMachine().
Register("workflow", map[string]string{
"name": env.WorkflowName(),
"name": env.WorkflowName(),
"labels": env.Config().Execution.Labels,
}).
Register("resource", map[string]string{
"root": env.ExecutionId(),
Expand Down Expand Up @@ -293,6 +294,12 @@ func CreateBaseMachine() expressions.Machine {
dashboardUrl = fmt.Sprintf("%s/organization/%s/environment/%s/dashboard",
env.Config().Cloud.UiUrl, env.Config().Cloud.OrgId, env.Config().Cloud.EnvId)
}

var labelMap map[string]string
if labels := env.Config().Execution.Labels; labels != "" {
json.Unmarshal([]byte(labels), &labelMap)
}

return expressions.CombinedMachines(
data.GetBaseTestWorkflowMachine(),
expressions.NewMachine().RegisterStringMap("internal", map[string]string{
Expand Down Expand Up @@ -341,7 +348,8 @@ func CreateBaseMachine() expressions.Machine {
}).
Register("environment", map[string]string{
"id": env.Config().Cloud.EnvId,
}),
}).
RegisterStringMap("labels", labelMap),
)
}

Expand Down
1 change: 1 addition & 0 deletions cmd/testworkflow-toolkit/env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type envExecutionConfig struct {
FSPrefix string `envconfig:"TK_FS"`
DisableWebhooks bool `envconfig:"TK_DWH"`
Tags string `envconfig:"TK_TAG"`
Labels string `envconfig:"TK_LBL"`
}

type envSystemConfig struct {
Expand Down
19 changes: 17 additions & 2 deletions pkg/testworkflows/testworkflowexecutor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package testworkflowexecutor
import (
"bufio"
"context"
"encoding/json"
"fmt"
"io"
"os"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -408,6 +410,16 @@ func (e *executor) Execute(ctx context.Context, workflow testworkflowsv1.TestWor
// Build the basic Execution data
id := primitive.NewObjectID().Hex()
now := time.Now()
labels := make(map[string]string)
for key, value := range workflow.Labels {
labels[strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(key, ".", "_"), "-", "_"), "/", "_")] = value
}

labelMap, err := json.Marshal(labels)
if err != nil {
return execution, errors.Wrap(err, "marsalling labels error")
}

machine := expressions.NewMachine().
RegisterStringMap("internal", map[string]string{
"storage.url": os.Getenv("STORAGE_ENDPOINT"),
Expand Down Expand Up @@ -448,7 +460,8 @@ func (e *executor) Execute(ctx context.Context, workflow testworkflowsv1.TestWor
"images.cache.ttl": common.GetOr(os.Getenv("TESTKUBE_IMAGE_CREDENTIALS_CACHE_TTL"), "30m"),
}).
Register("workflow", map[string]string{
"name": workflow.Name,
"name": workflow.Name,
"labels": string(labelMap),
}).
Register("resource", map[string]string{
"id": id,
Expand All @@ -463,7 +476,9 @@ func (e *executor) Execute(ctx context.Context, workflow testworkflowsv1.TestWor
}).
Register("environment", map[string]string{
"id": cloudEnvId,
})
}).
RegisterStringMap("labels", labels)

mockExecutionMachine := expressions.NewMachine().Register("execution", map[string]interface{}{
"id": id,
"name": "<mock_name>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ func (c *container) EnableToolkit(ref string) Container {
"TK_IMG_P": "{{internal.images.persistence.enabled}}",
"TK_IMG_PK": "{{internal.images.persistence.key}}",
"TK_IMG_CRED_TTL": "{{internal.images.cache.ttl}}",
"TK_LBL": "{{workflow.labels}}",
})
}

Expand Down
Loading