Skip to content

Commit

Permalink
fix: use controller namespace by default in MultiContainerRun
Browse files Browse the repository at this point in the history
  • Loading branch information
hairyhum committed Dec 5, 2024
1 parent 0ae0c40 commit a10055b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/function/multi_container_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,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
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 a10055b

Please sign in to comment.