This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit ad9fc483bb7bdffc28aacd92db3c581ce35c8ef1 Author: Antonin Stefanutti <[email protected]> AuthorDate: Wed Dec 8 14:51:39 2021 +0100 chore: Use atomic.Value for client-side apply fallback --- pkg/install/kamelets.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/install/kamelets.go b/pkg/install/kamelets.go index 53d7c2b..5712b55 100644 --- a/pkg/install/kamelets.go +++ b/pkg/install/kamelets.go @@ -27,6 +27,7 @@ import ( "path" "path/filepath" "strings" + "sync/atomic" "golang.org/x/sync/errgroup" @@ -36,6 +37,7 @@ import ( "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime/pkg/client" + logf "sigs.k8s.io/controller-runtime/pkg/log" "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" "github.com/apache/camel-k/pkg/client" @@ -50,7 +52,15 @@ const ( defaultKameletDir = "/kamelets/" ) -var hasServerSideApply = true +var ( + log = logf.Log + + hasServerSideApply atomic.Value +) + +func init() { + hasServerSideApply.Store(true) +} // KameletCatalog installs the bundled Kamelets into the specified namespace. func KameletCatalog(ctx context.Context, c client.Client, namespace string) error { @@ -121,13 +131,14 @@ func applyKamelet(ctx context.Context, c client.Client, path string, namespace s kamelet.GetLabels()[v1alpha1.KameletBundledLabel] = "true" kamelet.GetLabels()[v1alpha1.KameletReadOnlyLabel] = "true" - if hasServerSideApply { + if v := hasServerSideApply.Load(); v.(bool) { err := serverSideApply(ctx, c, kamelet) switch { case err == nil: return nil case isIncompatibleServerError(err): - hasServerSideApply = false + log.Info("Fallback to client-side apply for installing bundled Kamelets") + hasServerSideApply.Store(false) default: return fmt.Errorf("could not apply Kamelet from file %q: %w", path, err) }
