Skip to content

Commit

Permalink
fix(trait): never fallback to client-side apply unless server-side ap…
Browse files Browse the repository at this point in the history
…ply is incombatible

CSA support is mainly kept for compatibility reason and will ultimately be
removed, so it should only be used as fallback when SSA is known to be
unavailable.
  • Loading branch information
tadayosi authored and astefanutti committed Jun 22, 2021
1 parent b6b4798 commit 7ac2aaa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/trait/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package trait

import (
"net/http"
"strings"

"github.com/pkg/errors"

Expand Down Expand Up @@ -96,6 +97,9 @@ func (t *deployerTrait) Apply(e *Environment) error {
} else if isIncompatibleServerError(err) {
t.L.Info("Fallback to client-side apply to patch resources")
hasServerSideApply = false
} else {
// Keep server-side apply unless server is incompatible with it
return err
}
}
if err := t.clientSideApply(env, resource); err != nil {
Expand Down Expand Up @@ -151,6 +155,11 @@ func (t *deployerTrait) clientSideApply(env *Environment, resource ctrl.Object)
}

func isIncompatibleServerError(err error) bool {
// First simpler check for older servers (i.e. OpenShift 3.11)
if strings.Contains(err.Error(), "415: Unsupported Media Type") {
return true
}

// 415: Unsupported media type means we're talking to a server which doesn't
// support server-side apply.
if _, ok := err.(*k8serrors.StatusError); !ok {
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/test/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package test

import (
"context"
"strings"

"github.com/apache/camel-k/pkg/apis"
Expand Down Expand Up @@ -105,6 +106,11 @@ func (c *FakeClient) GetCurrentNamespace(kubeConfig string) (string, error) {
return "", nil
}

// Patch mimicks patch for server-side apply and simply creates the obj
func (c *FakeClient) Patch(ctx context.Context, obj controller.Object, patch controller.Patch, opts ...controller.PatchOption) error {
return c.Create(ctx, obj)
}

func (c *FakeClient) Discovery() discovery.DiscoveryInterface {
return &FakeDiscovery{
DiscoveryInterface: c.Interface.Discovery(),
Expand Down

0 comments on commit 7ac2aaa

Please sign in to comment.