Skip to content

Commit

Permalink
fix: use pro context for determining organization/environment ID in T…
Browse files Browse the repository at this point in the history
…est Workflow executor
  • Loading branch information
rangoo94 committed Oct 14, 2024
1 parent c46c4ec commit bc8e938
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
13 changes: 7 additions & 6 deletions cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"google.golang.org/protobuf/types/known/emptypb"

"github.com/kubeshop/testkube/pkg/cache"
executionworker2 "github.com/kubeshop/testkube/pkg/testworkflows/executionworker"
"github.com/kubeshop/testkube/pkg/testworkflows/executionworker"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowconfig"

executorsclientv1 "github.com/kubeshop/testkube-operator/pkg/client/executors/v1"
Expand Down Expand Up @@ -589,9 +589,9 @@ func main() {
}

// Build internal execution worker
namespacesConfig := map[string]executionworker2.NamespaceConfig{}
namespacesConfig := map[string]executionworker.NamespaceConfig{}
for n, s := range serviceAccountNames {
namespacesConfig[n] = executionworker2.NamespaceConfig{DefaultServiceAccountName: s}
namespacesConfig[n] = executionworker.NamespaceConfig{DefaultServiceAccountName: s}
}
cloudUrl := cfg.TestkubeProURL
cloudApiKey := cfg.TestkubeProAPIKey
Expand All @@ -612,14 +612,14 @@ func main() {
CAFile: cfg.StorageCAFile,
}
}
executionWorker := executionworker2.New(clientset, testWorkflowProcessor, executionworker2.Config{
Cluster: executionworker2.ClusterConfig{
executionWorker := executionworker.New(clientset, testWorkflowProcessor, executionworker.Config{
Cluster: executionworker.ClusterConfig{
Id: clusterId,
DefaultNamespace: cfg.TestkubeNamespace,
DefaultRegistry: cfg.TestkubeRegistry,
Namespaces: namespacesConfig,
},
ImageInspector: executionworker2.ImageInspectorConfig{
ImageInspector: executionworker.ImageInspectorConfig{
CacheEnabled: cfg.EnableImageDataPersistentCache,
CacheKey: cfg.ImageDataPersistentCacheKey,
CacheTTL: cfg.TestkubeImageCredentialsCacheTTL,
Expand Down Expand Up @@ -650,6 +650,7 @@ func main() {
secretManager,
cfg.GlobalWorkflowTemplateName,
cfg.TestkubeDashboardURI,
&proContext,
)

go testWorkflowExecutor.Recover(context.Background())
Expand Down
13 changes: 8 additions & 5 deletions pkg/testworkflows/testworkflowexecutor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/kubeshop/testkube/cmd/testworkflow-init/instructions"
v1 "github.com/kubeshop/testkube/internal/app/api/metrics"
"github.com/kubeshop/testkube/internal/common"
"github.com/kubeshop/testkube/internal/config"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/event"
"github.com/kubeshop/testkube/pkg/expressions"
Expand Down Expand Up @@ -67,6 +68,7 @@ type executor struct {
globalTemplateName string
dashboardURI string
workerClient executionworker.Worker
proContext *config.ProContext
}

func New(emitter *event.Emitter,
Expand All @@ -81,7 +83,8 @@ func New(emitter *event.Emitter,
metrics v1.Metrics,
secretManager secretmanager.SecretManager,
globalTemplateName string,
dashboardURI string) TestWorkflowExecutor {
dashboardURI string,
proContext *config.ProContext) TestWorkflowExecutor {
return &executor{
emitter: emitter,
clientSet: clientSet,
Expand All @@ -96,6 +99,7 @@ func New(emitter *event.Emitter,
globalTemplateName: globalTemplateName,
dashboardURI: dashboardURI,
workerClient: workerClient,
proContext: proContext,
}
}

Expand Down Expand Up @@ -485,10 +489,9 @@ func (e *executor) initialize(ctx context.Context, workflow *testworkflowsv1.Tes
execution.ResolvedWorkflow = testworkflowmappers.MapKubeToAPI(resolvedWorkflow)

// Determine the organization/environment
cloudApiKey := common.GetOr(os.Getenv("TESTKUBE_PRO_API_KEY"), os.Getenv("TESTKUBE_CLOUD_API_KEY"))
environmentId := common.GetOr(os.Getenv("TESTKUBE_PRO_ENV_ID"), os.Getenv("TESTKUBE_CLOUD_ENV_ID"))
organizationId := common.GetOr(os.Getenv("TESTKUBE_PRO_ORG_ID"), os.Getenv("TESTKUBE_CLOUD_ORG_ID"))
if cloudApiKey == "" {
organizationId := e.proContext.OrgID
environmentId := e.proContext.EnvID
if e.proContext.APIKey == "" {
organizationId = ""
environmentId = ""
}
Expand Down

0 comments on commit bc8e938

Please sign in to comment.