Skip to content

Commit

Permalink
Reimplement apply
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chacin <[email protected]>
  • Loading branch information
pablochacin committed Dec 1, 2022
1 parent 5fca577 commit f3046a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pkg/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func (c *Client) Apply(manifest string) error {
if err != nil {
return err
}

name := uObj.GetName()
namespace := uObj.GetNamespace()
if namespace == "" {
namespace = "default"
Expand All @@ -126,10 +128,13 @@ func (c *Client) Apply(manifest string) error {
return err
}

_, err = resource.Create(
_, err = resource.Apply(
c.ctx,
name,
uObj,
metav1.CreateOptions{},
metav1.ApplyOptions{
FieldManager: "xk6-kubernetes",
},
)
return err
}
Expand Down
18 changes: 16 additions & 2 deletions pkg/resources/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,28 +184,42 @@ spec:
}

func TestApply(t *testing.T) {
// Skip test. see comments on test cases why
t.Skip()
t.Parallel()
testCases := []struct {
test string
manifest string
kind string
name string
ns string
objects []runtime.Object
}{
{
test: "Apply pod manifest",
test: "Apply: create new pod",
manifest: podManifest(),
kind: "Pod",
name: "busybox",
ns: "testns",
objects: []runtime.Object{},
},
{
test: "Apply: existing pod",
manifest: podManifest(),
kind: "Pod",
name: "busybox",
ns: "testns",
objects: []runtime.Object{
buildPod(),
},
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.test, func(t *testing.T) {
t.Parallel()
c, err := newForTest()
c, err := newForTest(tc.objects...)
if err != nil {
t.Errorf("failed %v", err)
return
Expand Down

0 comments on commit f3046a9

Please sign in to comment.