Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): remove camelcase dependency #4366

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ updates:
schedule:
interval: "daily"
ignore:
- dependency-name: "k8s.io/api"
- dependency-name: "k8s.io/api"
- dependency-name: "k8s.io/apiextensions-apiserver"
- dependency-name: "k8s.io/apimachinery"
- dependency-name: "k8s.io/cli-runtime"
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/apache/camel-k/v2/pkg/kamelet/repository v0.0.0
github.com/container-tools/spectrum v0.6.12
github.com/evanphx/json-patch v4.12.0+incompatible
github.com/fatih/camelcase v1.0.0
github.com/fatih/structs v1.1.0
github.com/gertd/go-pluralize v0.2.1
github.com/go-logr/logr v1.2.4
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,6 @@ github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww=
github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
Expand Down
48 changes: 10 additions & 38 deletions pkg/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,18 @@ package cmd
import (
"context"
"fmt"
"regexp"
"strings"

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/util/camel"

"golang.org/x/text/cases"
"golang.org/x/text/language"

k8serrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/Masterminds/semver"
"github.com/fatih/camelcase"
"github.com/spf13/cobra"

"github.com/apache/camel-k/v2/pkg/client"
platformutil "github.com/apache/camel-k/v2/pkg/platform"
"github.com/apache/camel-k/v2/pkg/util/defaults"
"github.com/apache/camel-k/v2/pkg/util/log"
)

// VersionVariant may be overridden at build time.
Expand All @@ -48,8 +41,6 @@ const (
infoVersion = "Version"
)

var replaceRegexp = regexp.MustCompile(`(\s+\.\s*)|(\s+-\s*)`)

func newCmdVersion(rootCmdOptions *RootCmdOptions) (*cobra.Command, *versionCmdOptions) {
options := versionCmdOptions{
RootCmdOptions: rootCmdOptions,
Expand Down Expand Up @@ -150,18 +141,12 @@ func operatorInfo(ctx context.Context, c client.Client, namespace string) (map[s
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
infos["registryAddress"] = platform.Status.Build.Registry.Address

if platform.Status.Info != nil {
for k, v := range platform.Status.Info {
infos[k] = v
}
}
infos["Name"] = platform.Name
infos["Version"] = platform.Status.Version
infos["Publish strategy"] = string(platform.Status.Build.PublishStrategy)
infos["Runtime version"] = platform.Status.Build.RuntimeVersion
infos["Registry address"] = platform.Status.Build.Registry.Address
infos["Git commit"] = platform.Status.Info["gitCommit"]

catalog, err := camel.LoadCatalog(ctx, c, namespace, v1.RuntimeSpec{Version: platform.Status.Build.RuntimeVersion, Provider: platform.Status.Build.RuntimeProvider})
if err != nil {
Expand All @@ -170,25 +155,12 @@ func operatorInfo(ctx context.Context, c client.Client, namespace string) (map[s
if catalog == nil {
return nil, fmt.Errorf("CamelCatalog can't be found in %s namespace", platform.Namespace)
}
for k, v := range catalog.CamelCatalogSpec.Runtime.Metadata {
infos[k] = v
}

ccInfo := fromCamelCase(infos)
log.Debugf("Operator Info for namespace %s: %v", namespace, ccInfo)
return ccInfo, nil
}

func fromCamelCase(infos map[string]string) map[string]string {
textKeys := make(map[string]string)

for k, v := range infos {
key := cases.Title(language.English).String(strings.Join(camelcase.Split(k), " "))
key = replaceRegexp.ReplaceAllString(key, " ")
textKeys[key] = v
}
infos["Camel Quarkus version"] = catalog.CamelCatalogSpec.Runtime.Metadata["camel-quarkus.version"]
infos["Camel version"] = catalog.CamelCatalogSpec.Runtime.Metadata["camel.version"]
infos["Quarkus version"] = catalog.CamelCatalogSpec.Runtime.Metadata["quarkus.version"]

return textKeys
return infos, nil
}

func operatorVersion(ctx context.Context, c client.Client, namespace string) (string, error) {
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func TestOperatorVersionVerbose(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, true, versionCmdOptions.Verbose)
assert.Contains(t, output, fmt.Sprintf("Camel K Operator %s\n", defaults.Version))
assert.Contains(t, output, fmt.Sprintf("Camel Version: %s\n", catalog.Spec.Runtime.Metadata["camel.version"]))
assert.Contains(t, output, fmt.Sprintf("Camel Quarkus Version: %s\n", catalog.Spec.Runtime.Metadata["camel-quarkus.version"]))
assert.Contains(t, output, fmt.Sprintf("Quarkus Version: %s\n", catalog.Spec.Runtime.Metadata["quarkus.version"]))
assert.Contains(t, output, fmt.Sprintf("Camel version: %s\n", catalog.Spec.Runtime.Metadata["camel.version"]))
assert.Contains(t, output, fmt.Sprintf("Camel Quarkus version: %s\n", catalog.Spec.Runtime.Metadata["camel-quarkus.version"]))
assert.Contains(t, output, fmt.Sprintf("Quarkus version: %s\n", catalog.Spec.Runtime.Metadata["quarkus.version"]))
}

func TestCompatibleVersions(t *testing.T) {
Expand Down