Skip to content

Commit

Permalink
Merge branch 'master' into dockerfile-in-dependabot
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Dec 13, 2024
2 parents d1529a3 + 2e102a3 commit f518569
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 33 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ require (
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.starlark.net v0.0.0-20240314022150-ee8ed142361c // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -656,8 +656,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -686,13 +686,13 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand All @@ -701,8 +701,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
67 changes: 49 additions & 18 deletions pkg/function/multi_container_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ func (*multiContainerRunFunc) Name() string {
return MultiContainerRunFuncName
}

func (ktpf *multiContainerRunFunc) run(
ctx context.Context,
cli kubernetes.Interface,
) (map[string]interface{}, error) {
func (ktpf *multiContainerRunFunc) run(ctx context.Context) (map[string]interface{}, error) {
cli, err := kube.NewClient()
if err != nil {
return nil, errkit.Wrap(err, "Failed to create Kubernetes client")
}

volumeMounts := []corev1.VolumeMount{
{
Name: ktpSharedVolumeName,
Expand Down Expand Up @@ -141,7 +143,7 @@ func (ktpf *multiContainerRunFunc) run(
},
}

podSpec, err := kube.PatchDefaultPodSpecs(podSpec, ktpf.podOverride)
podSpec, err = kube.PatchDefaultPodSpecs(podSpec, ktpf.podOverride)
if err != nil {
return nil, errkit.Wrap(err, "Unable to apply podOverride", "podSpec", podSpec, "podOverride", ktpf.podOverride)
}
Expand All @@ -162,6 +164,11 @@ func (ktpf *multiContainerRunFunc) run(
// FIXME: this doesn't work with pod controller currently so we have to reorder containers
ktpf.annotations[defaultContainerAnn] = ktpOutputContainer

err = setPodSpecServiceAccount(&podSpec, ktpf.namespace, cli)
if err != nil {
return nil, errkit.Wrap(err, "Failed to set serviceaccount for pod")
}

pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: jobPrefix,
Expand Down Expand Up @@ -194,6 +201,23 @@ func (ktpf *multiContainerRunFunc) run(
return getPodOutput(ctx, pc)
}

func setPodSpecServiceAccount(podSpec *corev1.PodSpec, ns string, cli kubernetes.Interface) error {
sa := podSpec.ServiceAccountName
controllerNamespace, err := kube.GetControllerNamespace()
if err != nil {
return errkit.Wrap(err, "Failed to get controller namespace")
}

if sa == "" && ns == controllerNamespace {
sa, err = kube.GetControllerServiceAccount(cli)
if err != nil {
return errkit.Wrap(err, "Failed to get Controller Service Account")
}
}
podSpec.ServiceAccountName = sa
return nil
}

// This function is similar to kubeTaskPodFunc
func getPodOutput(ctx context.Context, pc kube.PodController) (map[string]interface{}, error) {
if err := pc.WaitForPodReady(ctx); err != nil {
Expand Down Expand Up @@ -242,9 +266,19 @@ func (ktpf *multiContainerRunFunc) Exec(ctx context.Context, tp param.TemplatePa
if err = OptArg(args, MultiContainerRunInitCommandArg, &ktpf.initCommand, nil); err != nil {
return nil, err
}

if err = OptArg(args, MultiContainerRunNamespaceArg, &ktpf.namespace, ""); err != nil {
return nil, err
}

if ktpf.namespace == "" {
controllerNamespace, err := kube.GetControllerNamespace()
if err != nil {
return nil, errkit.Wrap(err, "Failed to get controller namespace")
}
ktpf.namespace = controllerNamespace
}

if err = OptArg(args, MultiContainerRunVolumeMediumArg, &ktpf.storageMedium, ""); err != nil {
return nil, err
}
Expand Down Expand Up @@ -273,28 +307,25 @@ func (ktpf *multiContainerRunFunc) Exec(ctx context.Context, tp param.TemplatePa
return nil, err
}

ktpf.labels = bpLabels
ktpf.annotations = bpAnnotations
ktpf.setLabelsAndAnnotations(tp, bpLabels, bpAnnotations)

return ktpf.run(ctx)
}

func (ktpf *multiContainerRunFunc) setLabelsAndAnnotations(tp param.TemplateParams, labels, annotation map[string]string) {
ktpf.labels = labels
ktpf.annotations = annotation
if tp.PodAnnotations != nil {
// merge the actionset annotations with blueprint annotations
var actionSetAnn ActionSetAnnotations = tp.PodAnnotations
ktpf.annotations = actionSetAnn.MergeBPAnnotations(bpAnnotations)
ktpf.annotations = actionSetAnn.MergeBPAnnotations(annotation)
}

if tp.PodLabels != nil {
// merge the actionset labels with blueprint labels
var actionSetLabels ActionSetLabels = tp.PodLabels
ktpf.labels = actionSetLabels.MergeBPLabels(bpLabels)
}

cli, err := kube.NewClient()
if err != nil {
return nil, errkit.Wrap(err, "Failed to create Kubernetes client")
ktpf.labels = actionSetLabels.MergeBPLabels(labels)
}
return ktpf.run(
ctx,
cli,
)
}

func (*multiContainerRunFunc) RequiredArgs() []string {
Expand Down
66 changes: 66 additions & 0 deletions pkg/function/multi_container_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,69 @@ func (s *MultiContainerRunSuite) TestMultiContainerRunWithInit(c *C) {
}
}
}

func multiContainerRunPhaseWithoutNamespace() crv1alpha1.BlueprintPhase {
return crv1alpha1.BlueprintPhase{
Name: "testMultiContainerRun",
Func: MultiContainerRunFuncName,
Args: map[string]interface{}{
MultiContainerRunBackgroundImageArg: consts.LatestKanisterToolsImage,
MultiContainerRunBackgroundCommandArg: []string{
"sh",
"-c",
"echo foo > /tmp/file",
},
MultiContainerRunOutputImageArg: consts.LatestKanisterToolsImage,
MultiContainerRunOutputCommandArg: []string{
"sh",
"-c",
"while [ ! -e /tmp/file ]; do sleep 1; done; kando output value $(cat /tmp/file)",
},
},
}
}

func (s *MultiContainerRunSuite) TestMultiContainerRunWithoutNamespace(c *C) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()
tp := param.TemplateParams{
StatefulSet: &param.StatefulSetParams{
Namespace: s.namespace,
},
PodOverride: crv1alpha1.JSONMap{
"containers": []map[string]interface{}{
{
"name": "background",
"imagePullPolicy": "Always",
},
{
"name": "output",
"imagePullPolicy": "Always",
},
},
},
}
action := "test"
for _, tc := range []struct {
bp *crv1alpha1.Blueprint
outs []map[string]interface{}
}{
{
bp: newTaskBlueprint(multiContainerRunPhaseWithoutNamespace()),
outs: []map[string]interface{}{
{
"value": "foo",
},
},
},
} {
phases, err := kanister.GetPhases(*tc.bp, action, kanister.DefaultVersion, tp)
c.Assert(err, IsNil)
c.Assert(phases, HasLen, len(tc.outs))
for i, p := range phases {
out, err := p.Exec(ctx, *tc.bp, action, tp)
c.Assert(err, IsNil, Commentf("Phase %s failed", p.Name()))
c.Assert(out, DeepEquals, tc.outs[i])
}
}
}

0 comments on commit f518569

Please sign in to comment.