You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/12/21 17:45:28 UTC

[GitHub] [camel-k] nicolaferraro commented on a change in pull request #2838: Add support for KEDA

nicolaferraro commented on a change in pull request #2838:
URL: https://github.com/apache/camel-k/pull/2838#discussion_r773331872



##########
File path: pkg/client/serverside.go
##########
@@ -0,0 +1,130 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package client
+
+import (
+	"context"
+	"fmt"
+	"net/http"
+	"strings"
+	"sync"
+	"sync/atomic"
+
+	"github.com/apache/camel-k/pkg/util/log"
+	"github.com/apache/camel-k/pkg/util/patch"
+	"github.com/pkg/errors"
+	k8serrors "k8s.io/apimachinery/pkg/api/errors"
+	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
+	"k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/apimachinery/pkg/types"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+type ServerOrClientSideApplier struct {
+	Client             ctrl.Client
+	hasServerSideApply atomic.Value
+	tryServerSideApply sync.Once
+}
+
+func (c *defaultClient) ServerOrClientSideApplier() ServerOrClientSideApplier {
+	return ServerOrClientSideApplier{
+		Client: c,
+	}
+}
+
+func (a *ServerOrClientSideApplier) Apply(ctx context.Context, object ctrl.Object) error {
+	once := false
+	var err error
+	// nolint: ifshort
+	needsRetry := false
+	a.tryServerSideApply.Do(func() {
+		once = true
+		if err = a.serverSideApply(ctx, object); err != nil {
+			if isIncompatibleServerError(err) {
+				log.Info("Fallback to client-side apply for installing resources")
+				a.hasServerSideApply.Store(false)
+				err = nil
+			} else {
+				needsRetry = true

Review comment:
       So, the reset was actually replacing the object holding the critical section state with another one (same memory location, different data). When that happened, the finalizer at the exit of the critical section found an inconsistent state and went into panic. Moving it out fixes the issue (even if I'm not sure if it's 100% safe in case of highly concurrent calls)...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org