Skip to content

Commit

Permalink
Merge pull request #299 from buildtool/force_conflicts_apply
Browse files Browse the repository at this point in the history
fix: use --forceConflicts for server-side apply
  • Loading branch information
peter-svensson authored Oct 10, 2022
2 parents bb0ee94 + 9e142a0 commit 9343c09
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (k kubectl) Apply(input string) error {
return err
}

args := append(k.defaultArgs(), "apply", "--server-side", "-f", file)
args := append(k.defaultArgs(), "apply", "--server-side", "--force-conflicts", "-f", file)
c := newKubectlCmd(os.Stdin, k.out, k.out, args)
return c.Execute()
}
Expand Down
11 changes: 8 additions & 3 deletions pkg/kubectl/kubectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestNew_NoNamespace(t *testing.T) {
err := k.Apply("")
assert.NoError(t, err)
assert.Equal(t, 1, len(calls))
assert.Equal(t, []string{"apply", "--context", "missing", "--file", fmt.Sprintf("%s/content.yaml", tempDir), "--v=6", "--server-side"}, calls[0])
assert.Equal(t, []string{"apply", "--context", "missing", "--file", fmt.Sprintf("%s/content.yaml", tempDir), "--v=6", "--server-side", "--force-conflicts"}, calls[0])
logMock.Check(t, []string{})
}
func TestNew_NoContext(t *testing.T) {
Expand All @@ -84,7 +84,7 @@ func TestNew_NoContext(t *testing.T) {
err := k.Apply("")
assert.NoError(t, err)
assert.Equal(t, 1, len(calls))
assert.Equal(t, []string{"apply", "--namespace", "namespace", "--file", fmt.Sprintf("%s/content.yaml", tempDir), "--server-side"}, calls[0])
assert.Equal(t, []string{"apply", "--namespace", "namespace", "--file", fmt.Sprintf("%s/content.yaml", tempDir), "--server-side", "--force-conflicts"}, calls[0])
logMock.Check(t, []string{})
}

Expand All @@ -101,7 +101,7 @@ func TestKubectl_Apply(t *testing.T) {
err := k.Apply("")
assert.NoError(t, err)
assert.Equal(t, 1, len(calls))
assert.Equal(t, []string{"apply", "--context", "missing", "--namespace", "default", "--file", fmt.Sprintf("%s/content.yaml", tempDir), "--server-side"}, calls[0])
assert.Equal(t, []string{"apply", "--context", "missing", "--namespace", "default", "--file", fmt.Sprintf("%s/content.yaml", tempDir), "--server-side", "--force-conflicts"}, calls[0])
logMock.Check(t, []string{})
}

Expand Down Expand Up @@ -433,6 +433,7 @@ func mockCmd(_ io.Reader, out, _ io.Writer, args []string) *cobra.Command {
var kubeconfig *string
var verbose *string
var serverSide *bool
var forceConflicts *bool

cmd := cobra.Command{
Use: "kubectl",
Expand Down Expand Up @@ -468,6 +469,9 @@ func mockCmd(_ io.Reader, out, _ io.Writer, args []string) *cobra.Command {
if *serverSide {
call = append(call, "--server-side")
}
if *forceConflicts {
call = append(call, "--force-conflicts")
}
calls = append(calls, call)
return nil
},
Expand Down Expand Up @@ -495,6 +499,7 @@ func mockCmd(_ io.Reader, out, _ io.Writer, args []string) *cobra.Command {
kubeconfig = cmd.Flags().StringP("kubeconfig", "", "", "")
verbose = cmd.Flags().StringP("v", "v", "0", "")
serverSide = cmd.Flags().BoolP("server-side", "", false, "")
forceConflicts = cmd.Flags().BoolP("force-conflicts", "", false, "")
cmd.SetArgs(args)
return &cmd
}

0 comments on commit 9343c09

Please sign in to comment.