Skip to content

Commit

Permalink
chore: reduce the size of Init Process
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 committed Jul 25, 2024
1 parent 96aacdf commit bc0eb69
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 43 deletions.
5 changes: 2 additions & 3 deletions cmd/testworkflow-init/commands/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/kubeshop/testkube/cmd/testworkflow-init/constants"
"github.com/kubeshop/testkube/cmd/testworkflow-init/data"
"github.com/kubeshop/testkube/cmd/testworkflow-init/output"
"github.com/kubeshop/testkube/cmd/testworkflow-toolkit/env"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/action/actiontypes/lite"
"github.com/kubeshop/testkube/pkg/version"
)
Expand Down Expand Up @@ -52,8 +51,8 @@ func Setup(config lite.ActionSetup) {
"namespace": os.Getenv(constants.EnvNamespaceName),
"serviceAccountName": os.Getenv(constants.EnvServiceAccountName),
"agent": version.Version,
"toolkit": stripCommonImagePrefix(env.Config().Images.Toolkit, "testkube-tw-toolkit"),
"init": stripCommonImagePrefix(env.Config().Images.Init, "testkube-tw-init"),
"toolkit": stripCommonImagePrefix(os.Getenv("TESTKUBE_TW_TOOLKIT_IMAGE"), "testkube-tw-toolkit"),
"init": stripCommonImagePrefix(os.Getenv("TESTKUBE_TW_INIT_IMAGE"), "testkube-tw-init"),
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,5 @@
package lite

import (
"fmt"

corev1 "k8s.io/api/core/v1"
)

func EnvName(group string, computed bool, sensitive bool, name string) string {
suffix := ""
if computed {
suffix = "C"
}
if sensitive {
suffix += "S"
}
return fmt.Sprintf("_%s%s_%s", group, suffix, name)
}

func EnvVar(group string, computed, sensitive bool, name, value string) corev1.EnvVar {
return corev1.EnvVar{
Name: EnvName(group, computed, sensitive, name),
Value: value,
}
}

func EnvVarFrom(group string, computed, sensitive bool, name string, value corev1.EnvVarSource) corev1.EnvVar {
return corev1.EnvVar{
Name: EnvName(group, computed, sensitive, name),
ValueFrom: &value,
}
}

type LiteActionList []LiteAction

func NewLiteActionList() LiteActionList {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
package actiontypes

import (
"fmt"

corev1 "k8s.io/api/core/v1"

testworkflowsv1 "github.com/kubeshop/testkube-operator/api/testworkflows/v1"
"github.com/kubeshop/testkube/cmd/testworkflow-init/data"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/action/actiontypes/lite"
)

func EnvName(group string, computed bool, sensitive bool, name string) string {
suffix := ""
if computed {
suffix = "C"
}
if sensitive {
suffix += "S"
}
return fmt.Sprintf("_%s%s_%s", group, suffix, name)
}

func EnvVar(group string, computed, sensitive bool, name, value string) corev1.EnvVar {
return corev1.EnvVar{
Name: EnvName(group, computed, sensitive, name),
Value: value,
}
}

func EnvVarFrom(group string, computed, sensitive bool, name string, value corev1.EnvVarSource) corev1.EnvVar {
return corev1.EnvVar{
Name: EnvName(group, computed, sensitive, name),
ValueFrom: &value,
}
}

type ActionList []Action

func NewActionList() ActionList {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
testworkflowsv1 "github.com/kubeshop/testkube-operator/api/testworkflows/v1"
constants2 "github.com/kubeshop/testkube/cmd/testworkflow-init/constants"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/action/actiontypes"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/action/actiontypes/lite"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/constants"
stage2 "github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/stage"
)
Expand Down Expand Up @@ -67,13 +66,13 @@ func CreateContainer(groupId int, defaultContainer stage2.Container, actions []a
newEnv := *e.DeepCopy()
computed := strings.Contains(newEnv.Value, "{{")
sensitive := newEnv.ValueFrom != nil && newEnv.ValueFrom.SecretKeyRef != nil
newEnv.Name = lite.EnvName(fmt.Sprintf("%d", i), computed, sensitive, e.Name)
newEnv.Name = actiontypes.EnvName(fmt.Sprintf("%d", i), computed, sensitive, e.Name)
cr.Env = append(cr.Env, newEnv)
}
for _, e := range containerConfigs[i].Container.Config.EnvFrom {
newEnvFrom := *e.DeepCopy()
sensitive := newEnvFrom.SecretRef != nil
newEnvFrom.Prefix = lite.EnvName(fmt.Sprintf("%d", i), false, sensitive, e.Prefix)
newEnvFrom.Prefix = actiontypes.EnvName(fmt.Sprintf("%d", i), false, sensitive, e.Prefix)
cr.EnvFrom = append(cr.EnvFrom, newEnvFrom)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ var (
execMachine = expressions.NewMachine().
Register("resource.root", "dummy-id").
Register("resource.id", "dummy-id-abc")
envInstructions = lite.EnvVarFrom("01", false, false, constants2.EnvActions, corev1.EnvVarSource{
envInstructions = actiontypes.EnvVarFrom("01", false, false, constants2.EnvActions, corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{FieldPath: constants.SpecAnnotationFieldPath},
})
envDebugNode = lite.EnvVarFrom("00", false, false, constants2.EnvNodeName, corev1.EnvVarSource{
envDebugNode = actiontypes.EnvVarFrom("00", false, false, constants2.EnvNodeName, corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{FieldPath: "spec.nodeName"},
})
envDebugPod = lite.EnvVarFrom("00", false, false, constants2.EnvPodName, corev1.EnvVarSource{
envDebugPod = actiontypes.EnvVarFrom("00", false, false, constants2.EnvPodName, corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{FieldPath: "metadata.name"},
})
envDebugNamespace = lite.EnvVarFrom("00", false, false, constants2.EnvNamespaceName, corev1.EnvVarSource{
envDebugNamespace = actiontypes.EnvVarFrom("00", false, false, constants2.EnvNamespaceName, corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{FieldPath: "metadata.namespace"},
})
envDebugServiceAccount = lite.EnvVarFrom("00", false, false, constants2.EnvServiceAccountName, corev1.EnvVarSource{
envDebugServiceAccount = actiontypes.EnvVarFrom("00", false, false, constants2.EnvServiceAccountName, corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{FieldPath: "spec.serviceAccountName"},
})
)

func env(index int, computed bool, name, value string) corev1.EnvVar {
return lite.EnvVar(fmt.Sprintf("%d", index), computed, false, name, value)
return actiontypes.EnvVar(fmt.Sprintf("%d", index), computed, false, name, value)
}

func cmd(values ...string) *[]string {
Expand Down

0 comments on commit bc0eb69

Please sign in to comment.