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 ad6a749000da3a1bddb114c998d550f632768633 Author: Christoph Deppisch <cdeppi...@redhat.com> AuthorDate: Fri Jun 3 08:46:10 2022 +0200 Fix #2177: Improve operator version lookup - Find local integration platform or try to search for default operator in any namespace instead of just looking for the "camel-k" integration platform in local namespace - Should eliminate nasty "No Integration platform available in current namespace" warnings when using the kamel CLI --- pkg/cmd/version.go | 24 ++++++++++++++---------- pkg/platform/platform.go | 4 ++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/pkg/cmd/version.go b/pkg/cmd/version.go index ec0e493bd..1a6055ffe 100644 --- a/pkg/cmd/version.go +++ b/pkg/cmd/version.go @@ -22,14 +22,14 @@ import ( "fmt" "strings" + k8serrors "k8s.io/apimachinery/pkg/api/errors" + "github.com/Masterminds/semver" "github.com/fatih/camelcase" "github.com/spf13/cobra" - k8sclient "sigs.k8s.io/controller-runtime/pkg/client" - - v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/client" + platformutil "github.com/apache/camel-k/pkg/platform" "github.com/apache/camel-k/pkg/util/defaults" ) @@ -130,16 +130,20 @@ func (o *versionCmdOptions) displayOperatorVersion(cmd *cobra.Command, c client. func operatorInfo(ctx context.Context, c client.Client, namespace string) (map[string]string, error) { infos := make(map[string]string) - platform := v1.NewIntegrationPlatform(namespace, "camel-k") - platformKey := k8sclient.ObjectKey{ - Namespace: namespace, - Name: "camel-k", - } - - if err := c.Get(ctx, platformKey, &platform); err != nil { + platform, err := platformutil.GetOrFindLocal(ctx, c, namespace) + if err != nil && k8serrors.IsNotFound(err) { + // find default operator platform in any namespace + if defaultPlatform, _ := platformutil.LookupForPlatformName(ctx, c, platformutil.DefaultPlatformName); defaultPlatform == nil { + return nil, err + } else { + platform = defaultPlatform + } + } else if err != nil { return nil, err } + // Useful information + infos["name"] = platform.Name infos["version"] = platform.Status.Version infos["publishStrategy"] = string(platform.Status.Build.PublishStrategy) infos["runtimeVersion"] = platform.Status.Build.RuntimeVersion diff --git a/pkg/platform/platform.go b/pkg/platform/platform.go index 8b5f5c9c1..42c88cd82 100644 --- a/pkg/platform/platform.go +++ b/pkg/platform/platform.go @@ -65,6 +65,10 @@ func GetOrFindLocalForResource(ctx context.Context, c k8sclient.Reader, o k8scli return getOrFindForResource(ctx, c, o, active, true) } +func GetOrFindLocal(ctx context.Context, c k8sclient.Reader, namespace string) (*v1.IntegrationPlatform, error) { + return findLocal(ctx, c, namespace, true) +} + func getOrFindForResource(ctx context.Context, c k8sclient.Reader, o k8sclient.Object, active bool, local bool) (*v1.IntegrationPlatform, error) { if selectedPlatform, ok := o.GetAnnotations()[v1.PlatformSelectorAnnotation]; ok { return get(ctx, c, o.GetNamespace(), selectedPlatform)