-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(TKC-3368): use global template in new architecture when it's not …
…inline too (#6229)
- Loading branch information
Showing
4 changed files
with
81 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package runner | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
testworkflowsv1 "github.com/kubeshop/testkube-operator/api/testworkflows/v1" | ||
"github.com/kubeshop/testkube/internal/crdcommon" | ||
"github.com/kubeshop/testkube/pkg/log" | ||
"github.com/kubeshop/testkube/pkg/mapper/testworkflows" | ||
"github.com/kubeshop/testkube/pkg/newclients/testworkflowtemplateclient" | ||
) | ||
|
||
type GlobalTemplateFactory func(environmentId string) (*testworkflowsv1.TestWorkflowTemplate, error) | ||
|
||
func GlobalTemplateInline(yaml string) GlobalTemplateFactory { | ||
var globalTemplateInline *testworkflowsv1.TestWorkflowTemplate | ||
if yaml != "" { | ||
globalTemplateInline = new(testworkflowsv1.TestWorkflowTemplate) | ||
err := crdcommon.DeserializeCRD(globalTemplateInline, []byte("spec:\n "+strings.ReplaceAll(yaml, "\n", "\n "))) | ||
globalTemplateInline.Name = inlinedGlobalTemplateName | ||
if err != nil { | ||
log.DefaultLogger.Errorw("failed to unmarshal inlined global template", "error", err) | ||
globalTemplateInline = nil | ||
} | ||
} | ||
return func(_ string) (*testworkflowsv1.TestWorkflowTemplate, error) { | ||
return globalTemplateInline, nil | ||
} | ||
} | ||
|
||
func GlobalTemplateSourced(client testworkflowtemplateclient.TestWorkflowTemplateClient, name string) GlobalTemplateFactory { | ||
return func(environmentId string) (*testworkflowsv1.TestWorkflowTemplate, error) { | ||
tpl, err := client.Get(context.Background(), environmentId, name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return testworkflows.MapTemplateAPIToKube(tpl), nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters