From dab74ed085d66187d583262869fbd77beb1e52ee Mon Sep 17 00:00:00 2001 From: Luca Burgazzoli Date: Fri, 10 May 2024 17:07:51 +0200 Subject: [PATCH] feat(lint): enabe goconst linter --- .golangci.yml | 2 +- addons/telemetry/telemetry.go | 8 ++++--- addons/telemetry/telemetry_test.go | 3 ++- addons/vault/aws/aws_secrets_manager_test.go | 9 ++++---- addons/vault/gcp/gcp_secret_manager_test.go | 5 ++-- e2e/advanced/main_test.go | 5 ++-- e2e/common/cli/main_test.go | 3 ++- e2e/common/main_test.go | 7 +++--- e2e/common/traits/health_test.go | 2 +- e2e/support/test_support.go | 9 ++++---- pkg/builder/project_test.go | 6 +++-- pkg/builder/quarkus.go | 6 +++-- pkg/builder/quarkus_test.go | 8 ++++--- pkg/cmd/bind.go | 1 + .../integrationplatform/catalog_test.go | 6 +++-- pkg/install/common.go | 1 + pkg/install/operator.go | 3 ++- pkg/trait/builder.go | 4 +++- pkg/trait/camel_test.go | 7 +++--- pkg/trait/istio.go | 4 +++- pkg/trait/istio_test.go | 9 ++++---- pkg/trait/jolokia_test.go | 3 ++- pkg/trait/jvm.go | 4 +++- pkg/trait/kamelets.go | 3 ++- pkg/trait/kamelets_support.go | 3 ++- pkg/trait/knative.go | 8 ++++--- pkg/trait/knative_service.go | 3 ++- pkg/trait/knative_service_test.go | 7 +++--- pkg/trait/knative_test.go | 5 ++-- pkg/trait/logging.go | 17 +++++++------- pkg/trait/logging_test.go | 9 ++++---- pkg/trait/mount.go | 3 ++- pkg/trait/openapi.go | 5 ++-- pkg/trait/platform.go | 3 ++- pkg/trait/platform_test.go | 3 ++- pkg/trait/quarkus.go | 5 ++-- pkg/trait/quarkus_test.go | 20 ++++++++-------- pkg/trait/route_test.go | 5 ++-- pkg/trait/service_binding.go | 7 +++--- pkg/trait/service_binding_test.go | 3 ++- pkg/trait/trait_configure_test.go | 5 ++-- pkg/trait/trait_test.go | 5 ++-- pkg/trait/trait_types.go | 6 ++--- pkg/util/boolean/boolean.go | 23 +++++++++++++++++++ pkg/util/camel/camel_runtime_test.go | 4 +++- pkg/util/source/inspector_xml.go | 2 ++ 46 files changed, 172 insertions(+), 97 deletions(-) create mode 100644 pkg/util/boolean/boolean.go diff --git a/.golangci.yml b/.golangci.yml index 02d8810a12..cd187f18d2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -99,4 +99,4 @@ linters: # TODO: too much work at this stage as many files are impacted by the lint suggestions, however the reported # lint violation make a lot of sense so we should re-enable the lints below and work to fix the findings - perfsprint - - goconst + #- goconst diff --git a/addons/telemetry/telemetry.go b/addons/telemetry/telemetry.go index d6363a868a..ff0ca9fa14 100644 --- a/addons/telemetry/telemetry.go +++ b/addons/telemetry/telemetry.go @@ -20,6 +20,8 @@ package telemetry import ( "fmt" + "github.com/apache/camel-k/v2/pkg/util/boolean" + "k8s.io/utils/pointer" corev1 "k8s.io/api/core/v1" @@ -161,9 +163,9 @@ func (t *telemetryTrait) setCatalogConfiguration(e *trait.Environment) { e.ApplicationProperties["camel.k.telemetry.samplerRatio"] = t.SamplerRatio } if pointer.BoolDeref(t.SamplerParentBased, true) { - e.ApplicationProperties["camel.k.telemetry.samplerParentBased"] = "true" + e.ApplicationProperties["camel.k.telemetry.samplerParentBased"] = boolean.TrueString } else { - e.ApplicationProperties["camel.k.telemetry.samplerParentBased"] = "false" + e.ApplicationProperties["camel.k.telemetry.samplerParentBased"] = boolean.FalseString } for _, cp := range e.CamelCatalog.Runtime.Capabilities["telemetry"].RuntimeProperties { @@ -195,7 +197,7 @@ func (t *telemetryTrait) setProperties(e *trait.Environment) { if pointer.BoolDeref(t.SamplerParentBased, true) { e.ApplicationProperties[appPropSamplerParentBased] = "true" } else { - e.ApplicationProperties[appPropSamplerParentBased] = "false" + e.ApplicationProperties[appPropSamplerParentBased] = boolean.FalseString } } } diff --git a/addons/telemetry/telemetry_test.go b/addons/telemetry/telemetry_test.go index 82820b4ff8..0613377ea7 100644 --- a/addons/telemetry/telemetry_test.go +++ b/addons/telemetry/telemetry_test.go @@ -18,6 +18,7 @@ limitations under the License. package telemetry import ( + "github.com/apache/camel-k/v2/pkg/util/boolean" "testing" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -81,7 +82,7 @@ func TestTelemetryTraitWithValues(t *testing.T) { assert.Equal(t, "service.name=Test", e.ApplicationProperties["camel.k.telemetry.serviceName"]) assert.Equal(t, "ratio", e.ApplicationProperties["camel.k.telemetry.sampler"]) assert.Equal(t, "0.001", e.ApplicationProperties["camel.k.telemetry.samplerRatio"]) - assert.Equal(t, "false", e.ApplicationProperties["camel.k.telemetry.samplerParentBased"]) + assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.k.telemetry.samplerParentBased"]) assert.Equal(t, "${camel.k.telemetry.endpoint}", e.ApplicationProperties["quarkus.opentelemetry.tracer.exporter.otlp.endpoint"]) assert.Equal(t, "${camel.k.telemetry.serviceName}", e.ApplicationProperties["quarkus.opentelemetry.tracer.resource-attributes"]) assert.Equal(t, "${camel.k.telemetry.sampler}", e.ApplicationProperties["quarkus.opentelemetry.tracer.sampler"]) diff --git a/addons/vault/aws/aws_secrets_manager_test.go b/addons/vault/aws/aws_secrets_manager_test.go index 443c257779..6a14ad5d5f 100644 --- a/addons/vault/aws/aws_secrets_manager_test.go +++ b/addons/vault/aws/aws_secrets_manager_test.go @@ -18,6 +18,7 @@ limitations under the License. package aws import ( + "github.com/apache/camel-k/v2/pkg/util/boolean" "testing" "github.com/apache/camel-k/v2/pkg/util/test" @@ -56,7 +57,7 @@ func TestAwsSecretsManagerTraitApply(t *testing.T) { assert.Equal(t, "eu-west-1", e.ApplicationProperties["camel.vault.aws.region"]) assert.Equal(t, "access-key", e.ApplicationProperties["camel.vault.aws.accessKey"]) assert.Equal(t, "secret-key", e.ApplicationProperties["camel.vault.aws.secretKey"]) - assert.Equal(t, "false", e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"]) + assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"]) } func TestAwsSecretsManagerTraitNoDefaultCreds(t *testing.T) { @@ -79,7 +80,7 @@ func TestAwsSecretsManagerTraitNoDefaultCreds(t *testing.T) { assert.Equal(t, "eu-west-1", e.ApplicationProperties["camel.vault.aws.region"]) assert.Equal(t, "access-key", e.ApplicationProperties["camel.vault.aws.accessKey"]) assert.Equal(t, "secret-key", e.ApplicationProperties["camel.vault.aws.secretKey"]) - assert.Equal(t, "false", e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"]) + assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"]) } func TestAwsSecretsManagerTraitWithSecrets(t *testing.T) { @@ -119,7 +120,7 @@ func TestAwsSecretsManagerTraitWithSecrets(t *testing.T) { assert.Equal(t, "eu-west-1", e.ApplicationProperties["camel.vault.aws.region"]) assert.Equal(t, "my-access-key", e.ApplicationProperties["camel.vault.aws.accessKey"]) assert.Equal(t, "my-secret-key", e.ApplicationProperties["camel.vault.aws.secretKey"]) - assert.Equal(t, "false", e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"]) + assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"]) } func TestAwsSecretsManagerTraitWithConfigMap(t *testing.T) { @@ -159,7 +160,7 @@ func TestAwsSecretsManagerTraitWithConfigMap(t *testing.T) { assert.Equal(t, "eu-west-1", e.ApplicationProperties["camel.vault.aws.region"]) assert.Equal(t, "my-access-key", e.ApplicationProperties["camel.vault.aws.accessKey"]) assert.Equal(t, "my-secret-key", e.ApplicationProperties["camel.vault.aws.secretKey"]) - assert.Equal(t, "false", e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"]) + assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.vault.aws.defaultCredentialsProvider"]) } func createEnvironment(t *testing.T, catalogGen func() (*camel.RuntimeCatalog, error), objects ...runtime.Object) *trait.Environment { diff --git a/addons/vault/gcp/gcp_secret_manager_test.go b/addons/vault/gcp/gcp_secret_manager_test.go index 47001eaca8..aa748f1599 100644 --- a/addons/vault/gcp/gcp_secret_manager_test.go +++ b/addons/vault/gcp/gcp_secret_manager_test.go @@ -18,6 +18,7 @@ limitations under the License. package gcp import ( + "github.com/apache/camel-k/v2/pkg/util/boolean" "testing" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -49,7 +50,7 @@ func TestGcpSecretManagerTraitApply(t *testing.T) { assert.Equal(t, "project-gcp", e.ApplicationProperties["camel.vault.gcp.projectId"]) assert.Equal(t, "file:////usr/local/serviceaccount.json", e.ApplicationProperties["camel.vault.gcp.serviceAccountKey"]) - assert.Equal(t, "false", e.ApplicationProperties["camel.vault.gcp.useDefaultInstance"]) + assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.vault.gcp.useDefaultInstance"]) } func TestGcpSecretManagerTraitNoDefaultCreds(t *testing.T) { @@ -70,7 +71,7 @@ func TestGcpSecretManagerTraitNoDefaultCreds(t *testing.T) { assert.Equal(t, "project-gcp", e.ApplicationProperties["camel.vault.gcp.projectId"]) assert.Equal(t, "file:////usr/local/serviceaccount.json", e.ApplicationProperties["camel.vault.gcp.serviceAccountKey"]) - assert.Equal(t, "false", e.ApplicationProperties["camel.vault.gcp.useDefaultInstance"]) + assert.Equal(t, boolean.FalseString, e.ApplicationProperties["camel.vault.gcp.useDefaultInstance"]) } func createEnvironment(t *testing.T, catalogGen func() (*camel.RuntimeCatalog, error)) *trait.Environment { diff --git a/e2e/advanced/main_test.go b/e2e/advanced/main_test.go index dd14d866d6..72958a168f 100644 --- a/e2e/advanced/main_test.go +++ b/e2e/advanced/main_test.go @@ -24,6 +24,7 @@ package advanced import ( "fmt" + "github.com/apache/camel-k/v2/pkg/util/boolean" "os" "testing" @@ -37,12 +38,12 @@ import ( ) func TestMain(m *testing.M) { - justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", "false") + justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", boolean.FalseString) if justCompile == "true" { os.Exit(m.Run()) } - fastSetup := GetEnvOrDefault("CAMEL_K_E2E_FAST_SETUP", "false") + fastSetup := GetEnvOrDefault("CAMEL_K_E2E_FAST_SETUP", boolean.FalseString) if fastSetup == "true" { operatorID := platform.DefaultPlatformName ns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace) diff --git a/e2e/common/cli/main_test.go b/e2e/common/cli/main_test.go index fafad4f139..cfaba5b76c 100644 --- a/e2e/common/cli/main_test.go +++ b/e2e/common/cli/main_test.go @@ -24,6 +24,7 @@ package cli import ( "fmt" + "github.com/apache/camel-k/v2/pkg/util/boolean" "os" "testing" @@ -34,7 +35,7 @@ import ( ) func TestMain(m *testing.M) { - justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", "false") + justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", boolean.FalseString) if justCompile == "true" { os.Exit(m.Run()) } diff --git a/e2e/common/main_test.go b/e2e/common/main_test.go index c077ae4b0c..e67575c32d 100644 --- a/e2e/common/main_test.go +++ b/e2e/common/main_test.go @@ -33,15 +33,16 @@ import ( . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "github.com/apache/camel-k/v2/pkg/platform" + "github.com/apache/camel-k/v2/pkg/util/boolean" ) func TestMain(m *testing.M) { - justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", "false") - if justCompile == "true" { + justCompile := GetEnvOrDefault("CAMEL_K_E2E_JUST_COMPILE", boolean.FalseString) + if justCompile == boolean.TrueString { os.Exit(m.Run()) } - fastSetup := GetEnvOrDefault("CAMEL_K_E2E_FAST_SETUP", "false") + fastSetup := GetEnvOrDefault("CAMEL_K_E2E_FAST_SETUP", boolean.FalseString) if fastSetup == "true" { operatorID := platform.DefaultPlatformName ns := GetEnvOrDefault("CAMEL_K_GLOBAL_OPERATOR_NS", TestDefaultNamespace) diff --git a/e2e/common/traits/health_test.go b/e2e/common/traits/health_test.go index b2bc4f5eb7..e49bd75efa 100644 --- a/e2e/common/traits/health_test.go +++ b/e2e/common/traits/health_test.go @@ -198,7 +198,7 @@ func TestHealthTrait(t *testing.T) { // lastTransitionTime: "2021-12-08T20:12:14Z" // message: 'containers with unready status: [integration]' // reason: ContainersNotReady - // status: "False" + // status: False // type: Ready // g.Eventually(IntegrationCondition(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(And( diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go index 3cde54a750..ac8a6bbe08 100644 --- a/e2e/support/test_support.go +++ b/e2e/support/test_support.go @@ -87,6 +87,7 @@ import ( "github.com/apache/camel-k/v2/pkg/platform" pkgutil "github.com/apache/camel-k/v2/pkg/util" v2util "github.com/apache/camel-k/v2/pkg/util" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/defaults" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/log" @@ -285,10 +286,10 @@ func kamelInstallWithContext(t *testing.T, ctx context.Context, operatorID strin installArgs = []string{"install", "-n", namespace, "--operator-id", operatorID, "--skip-cluster-setup"} if !pkgutil.StringSliceExists(args, "--build-timeout") { - //if --build-timeout is not explicitly passed as an argument, try to configure it + // if --build-timeout is not explicitly passed as an argument, try to configure it buildTimeout := os.Getenv("CAMEL_K_TEST_BUILD_TIMEOUT") if buildTimeout == "" { - //default Build Timeout for tests + // default Build Timeout for tests buildTimeout = "10m" } fmt.Printf("Setting build timeout to %s\n", buildTimeout) @@ -2011,7 +2012,7 @@ func PlatformByName(t *testing.T, ctx context.Context, ns string, name string) f } func CopyIntegrationKits(t *testing.T, ctx context.Context, ns, operatorID string) error { - if value, ok := os.LookupEnv("CAMEL_K_TEST_COPY_INTEGRATION_KITS"); ok && value == "false" { + if value, ok := os.LookupEnv("CAMEL_K_TEST_COPY_INTEGRATION_KITS"); ok && value == boolean.FalseString { fmt.Println("Copy integration kits optimization is disabled") return nil } @@ -2046,7 +2047,7 @@ func CopyIntegrationKits(t *testing.T, ctx context.Context, ns, operatorID strin } func CopyCamelCatalog(t *testing.T, ctx context.Context, ns, operatorID string) error { - if value, ok := os.LookupEnv("CAMEL_K_TEST_COPY_CATALOG"); ok && value == "false" { + if value, ok := os.LookupEnv("CAMEL_K_TEST_COPY_CATALOG"); ok && value == boolean.FalseString { fmt.Println("Copy catalog optimization is disabled") return nil } diff --git a/pkg/builder/project_test.go b/pkg/builder/project_test.go index 00a948ef1b..53e378962d 100644 --- a/pkg/builder/project_test.go +++ b/pkg/builder/project_test.go @@ -21,6 +21,8 @@ import ( "regexp" "testing" + "github.com/apache/camel-k/v2/pkg/util/boolean" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -454,7 +456,7 @@ func TestInjectServersIntoDefaultMavenSettings(t *testing.T) { Username: "jpoth", Password: "changeit", Configuration: v1.Properties{ - "allowInsecureRegistries": "false", + "allowInsecureRegistries": boolean.FalseString, }, }, } @@ -480,7 +482,7 @@ func TestInjectServersIntoCustomMavenSettings(t *testing.T) { Username: "jpoth", Password: "changeit", Configuration: v1.Properties{ - "allowInsecureRegistries": "false", + "allowInsecureRegistries": boolean.FalseString, }, }, } diff --git a/pkg/builder/quarkus.go b/pkg/builder/quarkus.go index 49611466b6..ab1f51b089 100644 --- a/pkg/builder/quarkus.go +++ b/pkg/builder/quarkus.go @@ -24,6 +24,8 @@ import ( "path/filepath" "strings" + "github.com/apache/camel-k/v2/pkg/util/boolean" + "github.com/apache/camel-k/v2/pkg/util/io" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -236,12 +238,12 @@ func computeApplicationProperties(appPropertiesPath string, applicationPropertie applicationProperties = make(map[string]string) } // disable quarkus banner - applicationProperties["quarkus.banner.enabled"] = "false" + applicationProperties["quarkus.banner.enabled"] = boolean.FalseString // camel-quarkus does route discovery at startup, but we don't want // this to happen as routes are loaded at runtime and looking for // routes at build time may try to load camel-k-runtime routes builder // proxies which in some case may fail. - applicationProperties["quarkus.camel.routes-discovery.enabled"] = "false" + applicationProperties["quarkus.camel.routes-discovery.enabled"] = boolean.FalseString // required for to resolve data type transformers at runtime with service discovery // the different Camel runtimes use different resource paths for the service lookup applicationProperties["quarkus.camel.service.discovery.include-patterns"] = "META-INF/services/org/apache/camel/datatype/converter/*,META-INF/services/org/apache/camel/datatype/transformer/*,META-INF/services/org/apache/camel/transformer/*" diff --git a/pkg/builder/quarkus_test.go b/pkg/builder/quarkus_test.go index ad5d188344..a302ef1a6c 100644 --- a/pkg/builder/quarkus_test.go +++ b/pkg/builder/quarkus_test.go @@ -25,6 +25,8 @@ import ( "strings" "testing" + "github.com/apache/camel-k/v2/pkg/util/boolean" + v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/defaults" @@ -146,7 +148,7 @@ func TestGenerateQuarkusProjectWithBuildTimeProperties(t *testing.T) { err = generateQuarkusProject(&builderContext) require.NoError(t, err) // use local Maven executable in tests - t.Setenv("MAVEN_WRAPPER", "false") + t.Setenv("MAVEN_WRAPPER", boolean.FalseString) _, ok := os.LookupEnv("MAVEN_CMD") if !ok { t.Setenv("MAVEN_CMD", "mvn") @@ -205,7 +207,7 @@ func TestGenerateQuarkusProjectWithNativeSources(t *testing.T) { err = generateQuarkusProject(&builderContext) require.NoError(t, err) // use local Maven executable in tests - t.Setenv("MAVEN_WRAPPER", "false") + t.Setenv("MAVEN_WRAPPER", boolean.FalseString) _, ok := os.LookupEnv("MAVEN_CMD") if !ok { t.Setenv("MAVEN_CMD", "mvn") @@ -281,7 +283,7 @@ func TestBuildQuarkusRunner(t *testing.T) { err = sanitizeDependencies(&builderContext) require.NoError(t, err) // use local Maven executable in tests - t.Setenv("MAVEN_WRAPPER", "false") + t.Setenv("MAVEN_WRAPPER", boolean.FalseString) _, ok := os.LookupEnv("MAVEN_CMD") if !ok { t.Setenv("MAVEN_CMD", "mvn") diff --git a/pkg/cmd/bind.go b/pkg/cmd/bind.go index 938a023890..d8b66be139 100644 --- a/pkg/cmd/bind.go +++ b/pkg/cmd/bind.go @@ -15,6 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +//nolint:goconst package cmd import ( diff --git a/pkg/controller/integrationplatform/catalog_test.go b/pkg/controller/integrationplatform/catalog_test.go index 9451f7a4e3..9e4d863f21 100644 --- a/pkg/controller/integrationplatform/catalog_test.go +++ b/pkg/controller/integrationplatform/catalog_test.go @@ -25,6 +25,8 @@ import ( "strings" "testing" + "github.com/apache/camel-k/v2/pkg/util/boolean" + v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "github.com/apache/camel-k/v2/pkg/platform" "github.com/apache/camel-k/v2/pkg/resources" @@ -91,7 +93,7 @@ func TestCreateCatalog(t *testing.T) { require.NoError(t, err) // use local Maven executable in tests - t.Setenv("MAVEN_WRAPPER", "false") + t.Setenv("MAVEN_WRAPPER", boolean.FalseString) _, ok := os.LookupEnv("MAVEN_CMD") if !ok { t.Setenv("MAVEN_CMD", "mvn") @@ -194,7 +196,7 @@ func TestCreateCatalogError(t *testing.T) { require.NoError(t, err) // use local Maven executable in tests - t.Setenv("MAVEN_WRAPPER", "false") + t.Setenv("MAVEN_WRAPPER", boolean.FalseString) _, ok := os.LookupEnv("MAVEN_CMD") if !ok { t.Setenv("MAVEN_CMD", "mvn") diff --git a/pkg/install/common.go b/pkg/install/common.go index 78b1601496..1c0b715a8d 100644 --- a/pkg/install/common.go +++ b/pkg/install/common.go @@ -15,6 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +//nolint:goconst package install import ( diff --git a/pkg/install/operator.go b/pkg/install/operator.go index 4dba69bb8e..731d967e8d 100644 --- a/pkg/install/operator.go +++ b/pkg/install/operator.go @@ -87,7 +87,8 @@ type OperatorStorageConfiguration struct { } // OperatorOrCollect installs the operator resources or adds them to the collector if present. -// nolint: maintidx // TODO: refactor the code +// +//nolint:maintidx,goconst func OperatorOrCollect(ctx context.Context, cmd *cobra.Command, c client.Client, cfg OperatorConfiguration, collection *kubernetes.Collection, force bool) error { isOpenShift, err := isOpenShift(c, cfg.ClusterType) if err != nil { diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go index a97d41f714..4755397af3 100644 --- a/pkg/trait/builder.go +++ b/pkg/trait/builder.go @@ -25,6 +25,8 @@ import ( "strconv" "strings" + "github.com/apache/camel-k/v2/pkg/util/boolean" + corev1 "k8s.io/api/core/v1" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -406,7 +408,7 @@ func (t *builderTrait) builderTask(e *Environment, taskConf *v1.BuildConfigurati // Build time property required by master capability if e.IntegrationKit.HasCapability("master") && e.CamelCatalog.Runtime.Capabilities["master"].BuildTimeProperties != nil { - task.Maven.Properties["camel.k.master.enabled"] = "true" + task.Maven.Properties["camel.k.master.enabled"] = boolean.TrueString for _, cp := range e.CamelCatalog.Runtime.Capabilities["master"].BuildTimeProperties { task.Maven.Properties[CapabilityPropertyKey(cp.Key, task.Maven.Properties)] = cp.Value } diff --git a/pkg/trait/camel_test.go b/pkg/trait/camel_test.go index 175f154c35..452f4972e4 100644 --- a/pkg/trait/camel_test.go +++ b/pkg/trait/camel_test.go @@ -26,6 +26,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/test" @@ -134,8 +135,8 @@ func createNominalCamelTest(withSources bool) (*camelTrait, *Environment) { Loaders: map[string]v1.CamelLoader{ "java": { Metadata: map[string]string{ - "native": "true", - "sources-required-at-build-time": "true", + "native": boolean.TrueString, + "sources-required-at-build-time": boolean.TrueString, }, }, }, @@ -269,7 +270,7 @@ func TestCamelTraitSyntheticIntegration(t *testing.T) { trait, environment := createNominalCamelTest(true) environment.Integration.Status = v1.IntegrationStatus{} environment.Integration.Annotations = make(map[string]string) - environment.Integration.Annotations[v1.IntegrationSyntheticLabel] = "true" + environment.Integration.Annotations[v1.IntegrationSyntheticLabel] = boolean.TrueString configured, condition, err := trait.Configure(environment) require.NoError(t, err) diff --git a/pkg/trait/istio.go b/pkg/trait/istio.go index 2951bf71d1..a3d2a85e57 100644 --- a/pkg/trait/istio.go +++ b/pkg/trait/istio.go @@ -20,6 +20,8 @@ package trait import ( "strconv" + "github.com/apache/camel-k/v2/pkg/util/boolean" + appsv1 "k8s.io/api/apps/v1" "k8s.io/utils/pointer" @@ -78,7 +80,7 @@ func (t *istioTrait) injectIstioAnnotation(annotations map[string]string, includ } annotations[istioOutboundIPRangesAnnotation] = t.Allow if includeInject { - annotations[istioSidecarInjectAnnotation] = True + annotations[istioSidecarInjectAnnotation] = boolean.TrueString } if t.Inject != nil { annotations[istioSidecarInjectAnnotation] = strconv.FormatBool(*t.Inject) diff --git a/pkg/trait/istio_test.go b/pkg/trait/istio_test.go index 1e758bb4da..3b34f4ff48 100644 --- a/pkg/trait/istio_test.go +++ b/pkg/trait/istio_test.go @@ -32,6 +32,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/test" @@ -128,8 +129,8 @@ func TestIstioForcedInjectTrue(t *testing.T) { conditions, err := env.Catalog.apply(&env) require.NoError(t, err) assert.NotEmpty(t, conditions) - assert.Equal(t, "true", s.Spec.ConfigurationSpec.Template.Annotations[istioSidecarInjectAnnotation]) - assert.Equal(t, "true", d.Spec.Template.Annotations[istioSidecarInjectAnnotation]) + assert.Equal(t, boolean.TrueString, s.Spec.ConfigurationSpec.Template.Annotations[istioSidecarInjectAnnotation]) + assert.Equal(t, boolean.TrueString, d.Spec.Template.Annotations[istioSidecarInjectAnnotation]) } func TestIstioForcedInjectFalse(t *testing.T) { @@ -153,8 +154,8 @@ func TestIstioForcedInjectFalse(t *testing.T) { conditions, err := env.Catalog.apply(&env) require.NoError(t, err) assert.NotEmpty(t, conditions) - assert.Equal(t, "false", s.Spec.ConfigurationSpec.Template.Annotations[istioSidecarInjectAnnotation]) - assert.Equal(t, "false", d.Spec.Template.Annotations[istioSidecarInjectAnnotation]) + assert.Equal(t, boolean.FalseString, s.Spec.ConfigurationSpec.Template.Annotations[istioSidecarInjectAnnotation]) + assert.Equal(t, boolean.FalseString, d.Spec.Template.Annotations[istioSidecarInjectAnnotation]) } func TestIstioDisabled(t *testing.T) { diff --git a/pkg/trait/jolokia_test.go b/pkg/trait/jolokia_test.go index 307ae10359..c5c685cc59 100644 --- a/pkg/trait/jolokia_test.go +++ b/pkg/trait/jolokia_test.go @@ -28,6 +28,7 @@ import ( "k8s.io/utils/pointer" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/kubernetes" ) @@ -256,7 +257,7 @@ func TestAddBoolPointerOptionToJolokiaOptions(t *testing.T) { trait.addToJolokiaOptions(options, "key", pointer.Bool(false)) assert.Len(t, options, 1) - assert.Equal(t, "false", options["key"]) + assert.Equal(t, boolean.FalseString, options["key"]) } func TestAddWrongTypeOptionToJolokiaOptionsDoesNothing(t *testing.T) { diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go index 01d478852a..08e56d1511 100644 --- a/pkg/trait/jvm.go +++ b/pkg/trait/jvm.go @@ -24,6 +24,8 @@ import ( "sort" "strings" + "github.com/apache/camel-k/v2/pkg/util/boolean" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -162,7 +164,7 @@ func (t *jvmTrait) Apply(e *Environment) error { if meta.Labels == nil { meta.Labels = make(map[string]string) } - meta.Labels["camel.apache.org/debug"] = "true" + meta.Labels["camel.apache.org/debug"] = boolean.TrueString }) } diff --git a/pkg/trait/kamelets.go b/pkg/trait/kamelets.go index f1b444680c..f5d148fbc3 100644 --- a/pkg/trait/kamelets.go +++ b/pkg/trait/kamelets.go @@ -34,6 +34,7 @@ import ( "github.com/apache/camel-k/v2/pkg/kamelet/repository" "github.com/apache/camel-k/v2/pkg/platform" "github.com/apache/camel-k/v2/pkg/util" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/digest" "github.com/apache/camel-k/v2/pkg/util/dsl" @@ -376,7 +377,7 @@ func initializeConfigmapKameletSource(source v1.SourceSpec, hash, name, namespac sourceLanguageAnnotation: string(source.Language), sourceNameAnnotation: name, sourceCompressionAnnotation: strconv.FormatBool(source.Compression), - "camel.apache.org/source.generated": "true", + "camel.apache.org/source.generated": boolean.TrueString, "camel.apache.org/source.type": string(source.Type), "camel.apache.org/source.digest": hash, }, diff --git a/pkg/trait/kamelets_support.go b/pkg/trait/kamelets_support.go index c0a5724324..c55c0c3237 100644 --- a/pkg/trait/kamelets_support.go +++ b/pkg/trait/kamelets_support.go @@ -22,6 +22,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "github.com/apache/camel-k/v2/pkg/cmd/source" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/kubernetes" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -85,7 +86,7 @@ func newBundleConfigmap(name, namespace string, id int) *corev1.ConfigMap { kubernetes.ConfigMapTypeLabel: KameletBundleType, }, Annotations: map[string]string{ - kubernetes.ConfigMapAutogenLabel: "true", + kubernetes.ConfigMapAutogenLabel: boolean.TrueString, }, }, Data: map[string]string{}, diff --git a/pkg/trait/knative.go b/pkg/trait/knative.go index d936630c7f..e16239e98b 100644 --- a/pkg/trait/knative.go +++ b/pkg/trait/knative.go @@ -24,6 +24,8 @@ import ( "sort" "strings" + "github.com/apache/camel-k/v2/pkg/util/boolean" + corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" @@ -220,7 +222,7 @@ func (t *knativeTrait) configureChannels(e *Environment, env *knativeapi.CamelEn knativeapi.CamelMetaEndpointKind: string(knativeapi.CamelEndpointKindSource), knativeapi.CamelMetaKnativeAPIVersion: ref.APIVersion, knativeapi.CamelMetaKnativeKind: ref.Kind, - knativeapi.CamelMetaKnativeReply: "false", + knativeapi.CamelMetaKnativeReply: boolean.FalseString, } if pointer.BoolDeref(t.FilterSourceChannels, false) { meta[knativeapi.CamelMetaFilterPrefix+knativeHistoryHeader] = loc.Host @@ -294,7 +296,7 @@ func (t *knativeTrait) configureEndpoints(e *Environment, env *knativeapi.CamelE knativeapi.CamelMetaEndpointKind: string(knativeapi.CamelEndpointKindSource), knativeapi.CamelMetaKnativeAPIVersion: serving.SchemeGroupVersion.String(), knativeapi.CamelMetaKnativeKind: "Service", - // knative.reply is left to default ("true") in case of simple service + // knative.reply is left to default (boolean.TrueString) in case of simple service }, } env.Services = append(env.Services, svc) @@ -347,7 +349,7 @@ func (t *knativeTrait) configureEvents(e *Environment, env *knativeapi.CamelEnvi knativeapi.CamelMetaKnativeAPIVersion: ref.APIVersion, knativeapi.CamelMetaKnativeKind: ref.Kind, knativeapi.CamelMetaKnativeName: ref.Name, - knativeapi.CamelMetaKnativeReply: "false", + knativeapi.CamelMetaKnativeReply: boolean.FalseString, }, } env.Services = append(env.Services, svc) diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go index 38da720aac..d7ded440a5 100644 --- a/pkg/trait/knative_service.go +++ b/pkg/trait/knative_service.go @@ -30,6 +30,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" "github.com/apache/camel-k/v2/pkg/metadata" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/knative" "github.com/apache/camel-k/v2/pkg/util/kubernetes" ) @@ -227,7 +228,7 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) (*serving.Service, e // See: // - https://knative.dev/v1.3-docs/eventing/custom-event-source/sinkbinding/create-a-sinkbinding/#optional-choose-sinkbinding-namespace-selection-behavior // - https://github.com/knative/operator/blob/release-1.2/docs/configuration.md#specsinkbindingselectionmode - "bindings.knative.dev/include": "true", + "bindings.knative.dev/include": boolean.TrueString, } if t.Visibility != "" { serviceLabels[knativeServingVisibilityLabel] = t.Visibility diff --git a/pkg/trait/knative_service_test.go b/pkg/trait/knative_service_test.go index 658b3101e7..a084f4e29d 100644 --- a/pkg/trait/knative_service_test.go +++ b/pkg/trait/knative_service_test.go @@ -34,6 +34,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/gzip" "github.com/apache/camel-k/v2/pkg/util/kubernetes" @@ -178,7 +179,7 @@ func TestKnativeService(t *testing.T) { assert.Equal(t, "file:/etc/camel/sources/routes.js", environment.ApplicationProperties["camel.k.sources[0].location"]) assert.Equal(t, "js", environment.ApplicationProperties["camel.k.sources[0].language"]) - assert.Equal(t, "true", environment.ApplicationProperties["camel.k.sources[0].compressed"]) + assert.Equal(t, boolean.TrueString, environment.ApplicationProperties["camel.k.sources[0].compressed"]) test.EnvVarHasValue(t, spec.Containers[0].Env, "CAMEL_K_CONF", filepath.FromSlash("/etc/camel/application.properties")) test.EnvVarHasValue(t, spec.Containers[0].Env, "CAMEL_K_CONF_D", filepath.FromSlash("/etc/camel/conf.d")) } @@ -590,10 +591,10 @@ func createKnativeServiceTestEnvironment(t *testing.T, trait *traitv1.KnativeSer return environment } func TestServiceAnnotation(t *testing.T) { - annotationsTest := map[string]string{"haproxy.router.openshift.io/balance": "true"} + annotationsTest := map[string]string{"haproxy.router.openshift.io/balance": boolean.TrueString} environment := createKnativeServiceTestEnvironment(t, &traitv1.KnativeServiceTrait{ - Annotations: map[string]string{"haproxy.router.openshift.io/balance": "true"}, + Annotations: map[string]string{"haproxy.router.openshift.io/balance": boolean.TrueString}, }) traitsCatalog := environment.Catalog diff --git a/pkg/trait/knative_test.go b/pkg/trait/knative_test.go index 454331ecfe..6486ac8fe9 100644 --- a/pkg/trait/knative_test.go +++ b/pkg/trait/knative_test.go @@ -41,6 +41,7 @@ import ( knativeapi "github.com/apache/camel-k/v2/pkg/apis/camel/v1/knative" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" "github.com/apache/camel-k/v2/pkg/client" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/camel" k8sutils "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/test" @@ -256,11 +257,11 @@ func TestKnativeEnvConfigurationFromSource(t *testing.T) { channel := ne.FindService("channel-source-1", knativeapi.CamelEndpointKindSource, knativeapi.CamelServiceTypeChannel, "", "") assert.NotNil(t, channel) - assert.Equal(t, "false", channel.Metadata[knativeapi.CamelMetaKnativeReply]) + assert.Equal(t, boolean.FalseString, channel.Metadata[knativeapi.CamelMetaKnativeReply]) broker := ne.FindService("evt.type", knativeapi.CamelEndpointKindSource, knativeapi.CamelServiceTypeEvent, "", "") assert.NotNil(t, broker) - assert.Equal(t, "false", broker.Metadata[knativeapi.CamelMetaKnativeReply]) + assert.Equal(t, boolean.FalseString, broker.Metadata[knativeapi.CamelMetaKnativeReply]) assert.NotNil(t, environment.Resources.GetKnativeSubscription(func(subscription *messaging.Subscription) bool { return assert.Equal(t, "channel-source-1-test", subscription.Name) diff --git a/pkg/trait/logging.go b/pkg/trait/logging.go index 0da531f195..5c725ded60 100644 --- a/pkg/trait/logging.go +++ b/pkg/trait/logging.go @@ -21,6 +21,7 @@ import ( "k8s.io/utils/pointer" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/envvar" ) @@ -84,16 +85,16 @@ func (l loggingTrait) setEnvConfiguration(e *Environment) { } if pointer.BoolDeref(l.JSON, false) { - envvar.SetVal(&e.EnvVars, envVarQuarkusLogConsoleJSON, True) + envvar.SetVal(&e.EnvVars, envVarQuarkusLogConsoleJSON, boolean.TrueString) if pointer.BoolDeref(l.JSONPrettyPrint, false) { - envvar.SetVal(&e.EnvVars, envVarQuarkusLogConsoleJSONPrettyPrint, True) + envvar.SetVal(&e.EnvVars, envVarQuarkusLogConsoleJSONPrettyPrint, boolean.TrueString) } } else { // If the trait is false OR unset, we default to false. - envvar.SetVal(&e.EnvVars, envVarQuarkusLogConsoleJSON, False) + envvar.SetVal(&e.EnvVars, envVarQuarkusLogConsoleJSON, boolean.FalseString) if pointer.BoolDeref(l.Color, true) { - envvar.SetVal(&e.EnvVars, envVarQuarkusConsoleColor, True) + envvar.SetVal(&e.EnvVars, envVarQuarkusConsoleColor, boolean.TrueString) } } } @@ -107,15 +108,15 @@ func (l loggingTrait) setCatalogConfiguration(e *Environment) { e.ApplicationProperties["camel.k.logging.format"] = l.Format } if pointer.BoolDeref(l.JSON, false) { - e.ApplicationProperties["camel.k.logging.json"] = True + e.ApplicationProperties["camel.k.logging.json"] = boolean.TrueString if pointer.BoolDeref(l.JSONPrettyPrint, false) { - e.ApplicationProperties["camel.k.logging.jsonPrettyPrint"] = True + e.ApplicationProperties["camel.k.logging.jsonPrettyPrint"] = boolean.TrueString } } else { // If the trait is false OR unset, we default to false. - e.ApplicationProperties["camel.k.logging.json"] = False + e.ApplicationProperties["camel.k.logging.json"] = boolean.FalseString if pointer.BoolDeref(l.Color, true) { - e.ApplicationProperties["camel.k.logging.color"] = True + e.ApplicationProperties["camel.k.logging.color"] = boolean.TrueString } } diff --git a/pkg/trait/logging_test.go b/pkg/trait/logging_test.go index 507cb2b46f..2ff847ac6c 100644 --- a/pkg/trait/logging_test.go +++ b/pkg/trait/logging_test.go @@ -30,6 +30,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/test" @@ -119,9 +120,9 @@ func TestEmptyLoggingTrait(t *testing.T) { assert.Equal(t, "INFO", env.ApplicationProperties["camel.k.logging.level"]) assert.Equal(t, "", env.ApplicationProperties["camel.k.logging.format"]) - assert.Equal(t, "false", env.ApplicationProperties["camel.k.logging.json"]) + assert.Equal(t, boolean.FalseString, env.ApplicationProperties["camel.k.logging.json"]) assert.Equal(t, "", env.ApplicationProperties["camel.k.logging.jsonPrettyPrint"]) - assert.Equal(t, "true", env.ApplicationProperties["camel.k.logging.color"]) + assert.Equal(t, boolean.TrueString, env.ApplicationProperties["camel.k.logging.color"]) assert.Equal(t, "${camel.k.logging.level}", env.ApplicationProperties["quarkus.log.level"]) assert.Equal(t, "", env.ApplicationProperties["quarkus.log.console.format"]) @@ -141,8 +142,8 @@ func TestJsonLoggingTrait(t *testing.T) { assert.Equal(t, "TRACE", env.ApplicationProperties["camel.k.logging.level"]) assert.Equal(t, "%d{HH:mm:ss} %-5p (%t) %s%e%n", env.ApplicationProperties["camel.k.logging.format"]) - assert.Equal(t, "true", env.ApplicationProperties["camel.k.logging.json"]) - assert.Equal(t, "true", env.ApplicationProperties["camel.k.logging.jsonPrettyPrint"]) + assert.Equal(t, boolean.TrueString, env.ApplicationProperties["camel.k.logging.json"]) + assert.Equal(t, boolean.TrueString, env.ApplicationProperties["camel.k.logging.jsonPrettyPrint"]) assert.Equal(t, "", env.ApplicationProperties["camel.k.logging.color"]) assert.Equal(t, "${camel.k.logging.level}", env.ApplicationProperties["quarkus.log.level"]) diff --git a/pkg/trait/mount.go b/pkg/trait/mount.go index d999fbea0f..3a3af3ab9f 100644 --- a/pkg/trait/mount.go +++ b/pkg/trait/mount.go @@ -31,6 +31,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/kubernetes" utilResource "github.com/apache/camel-k/v2/pkg/util/resource" ) @@ -183,7 +184,7 @@ func (t *mountTrait) mountResource(vols *[]corev1.Volume, mnts *[]corev1.VolumeM func (t *mountTrait) addServiceBindingSecret(e *Environment) { e.Resources.VisitSecret(func(secret *corev1.Secret) { - if secret.Labels[serviceBindingLabel] == "true" { + if secret.Labels[serviceBindingLabel] == boolean.TrueString { t.Configs = append(t.Configs, "secret:"+secret.Name) } }) diff --git a/pkg/trait/openapi.go b/pkg/trait/openapi.go index 94772cb0ca..2f2d351cc9 100644 --- a/pkg/trait/openapi.go +++ b/pkg/trait/openapi.go @@ -26,6 +26,7 @@ import ( "strconv" "strings" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/io" corev1 "k8s.io/api/core/v1" @@ -106,7 +107,7 @@ func (t *openAPITrait) generateFromConfigmaps(e *Environment, tmpDir string) ([] // verify if it was autogenerated cm, err := kubernetes.GetUnstructured(e.Ctx, e.Client, schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ConfigMap"}, configmap, e.Integration.Namespace) - if err == nil && cm != nil && cm.GetLabels()[kubernetes.ConfigMapAutogenLabel] == "true" { + if err == nil && cm != nil && cm.GetLabels()[kubernetes.ConfigMapAutogenLabel] == boolean.TrueString { refCm := kubernetes.NewConfigMap(e.Integration.Namespace, configmap, "", "", "", nil) e.Resources.Add(refCm) } @@ -305,7 +306,7 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e *Environment, resource v1.Dat sourceLanguageAnnotation: string(v1.LanguageXML), sourceNameAnnotation: resource.Name, sourceCompressionAnnotation: strconv.FormatBool(resource.Compression), - "camel.apache.org/source.generated": "true", + "camel.apache.org/source.generated": boolean.TrueString, "camel.apache.org/source.type": "openapi", "camel.apache.org/source.digest": hash, }, diff --git a/pkg/trait/platform.go b/pkg/trait/platform.go index 397bc13fc8..60c752dff3 100644 --- a/pkg/trait/platform.go +++ b/pkg/trait/platform.go @@ -27,6 +27,7 @@ import ( traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" "github.com/apache/camel-k/v2/pkg/install" "github.com/apache/camel-k/v2/pkg/platform" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/defaults" "github.com/apache/camel-k/v2/pkg/util/openshift" image "github.com/apache/camel-k/v2/pkg/util/registry" @@ -136,7 +137,7 @@ func (t *platformTrait) getOrCreatePlatform(e *Environment) (*v1.IntegrationPlat defaultPlatform.Labels = make(map[string]string) } defaultPlatform.Labels["app"] = "camel-k" - defaultPlatform.Labels["camel.apache.org/platform.generated"] = True + defaultPlatform.Labels["camel.apache.org/platform.generated"] = boolean.TrueString // Cascade the operator id in charge to reconcile the Integration if v1.GetOperatorIDAnnotation(e.Integration) != "" { defaultPlatform.SetOperatorID(v1.GetOperatorIDAnnotation(e.Integration)) diff --git a/pkg/trait/platform_test.go b/pkg/trait/platform_test.go index 11211df065..0965773ffc 100644 --- a/pkg/trait/platform_test.go +++ b/pkg/trait/platform_test.go @@ -22,6 +22,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "github.com/apache/camel-k/v2/pkg/platform" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/test" @@ -112,7 +113,7 @@ func TestPlatformTraitCreatesDefaultPlatform(t *testing.T) { assert.Equal(t, v1.IntegrationPhaseWaitingForPlatform, e.Integration.Status.Phase) assert.Equal(t, 1, len(e.Resources.Items())) defPlatform := v1.NewIntegrationPlatform("ns1", platform.DefaultPlatformName) - defPlatform.Labels = map[string]string{"app": "camel-k", "camel.apache.org/platform.generated": True} + defPlatform.Labels = map[string]string{"app": "camel-k", "camel.apache.org/platform.generated": boolean.TrueString} assert.Contains(t, e.Resources.Items(), &defPlatform) } diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go index 0d8694e787..0581f99353 100644 --- a/pkg/trait/quarkus.go +++ b/pkg/trait/quarkus.go @@ -30,6 +30,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" "github.com/apache/camel-k/v2/pkg/builder" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/defaults" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/log" @@ -80,8 +81,8 @@ func getLanguageSettings(e *Environment, language v1.Language) languageSettings } sourcesRequiredAtBuildTime, sExists := loader.Metadata["sources-required-at-build-time"] return languageSettings{ - native: native == "true", - sourcesRequiredAtBuildTime: sExists && sourcesRequiredAtBuildTime == "true", + native: native == boolean.TrueString, + sourcesRequiredAtBuildTime: sExists && sourcesRequiredAtBuildTime == boolean.TrueString, } } log.Debugf("No loader could be found for the language %q, the legacy language settings are applied", string(language)) diff --git a/pkg/trait/quarkus_test.go b/pkg/trait/quarkus_test.go index 5d681a3097..473da5c449 100644 --- a/pkg/trait/quarkus_test.go +++ b/pkg/trait/quarkus_test.go @@ -20,6 +20,8 @@ package trait import ( "testing" + "github.com/apache/camel-k/v2/pkg/util/boolean" + traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" "github.com/stretchr/testify/assert" @@ -188,31 +190,31 @@ func TestGetLanguageSettingsWithLoaders(t *testing.T) { Loaders: map[string]v1.CamelLoader{ "java": { Metadata: map[string]string{ - "native": "true", - "sources-required-at-build-time": "true", + "native": boolean.TrueString, + "sources-required-at-build-time": boolean.TrueString, }, }, "groovy": { Metadata: map[string]string{ - "native": "false", - "sources-required-at-build-time": "false", + "native": boolean.FalseString, + "sources-required-at-build-time": boolean.FalseString, }, }, "js": { Metadata: map[string]string{ - "native": "true", - "sources-required-at-build-time": "false", + "native": boolean.TrueString, + "sources-required-at-build-time": boolean.FalseString, }, }, "kts": { Metadata: map[string]string{ - "native": "false", - "sources-required-at-build-time": "true", + "native": boolean.FalseString, + "sources-required-at-build-time": boolean.TrueString, }, }, "jsh": { Metadata: map[string]string{ - "native": "true", + "native": boolean.TrueString, }, }, }, diff --git a/pkg/trait/route_test.go b/pkg/trait/route_test.go index 0c1bd22381..9279986780 100644 --- a/pkg/trait/route_test.go +++ b/pkg/trait/route_test.go @@ -33,6 +33,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/test" @@ -552,13 +553,13 @@ func TestRoute_WithCustomServicePort(t *testing.T) { } func TestRouteAnnotation(t *testing.T) { - annotationsTest := map[string]string{"haproxy.router.openshift.io/balance": "true"} + annotationsTest := map[string]string{"haproxy.router.openshift.io/balance": boolean.TrueString} name := xid.New().String() environment := createTestRouteEnvironment(t, name) environment.Integration.Spec.Traits = v1.Traits{ Route: &traitv1.RouteTrait{ - Annotations: map[string]string{"haproxy.router.openshift.io/balance": "true"}, + Annotations: map[string]string{"haproxy.router.openshift.io/balance": boolean.TrueString}, }, } diff --git a/pkg/trait/service_binding.go b/pkg/trait/service_binding.go index 86e08c5418..7e328772a3 100644 --- a/pkg/trait/service_binding.go +++ b/pkg/trait/service_binding.go @@ -33,6 +33,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/reference" ) @@ -112,7 +113,7 @@ func (t *serviceBindingTrait) setCatalogConfiguration(e *Environment) { if e.ApplicationProperties == nil { e.ApplicationProperties = make(map[string]string) } - e.ApplicationProperties["camel.k.serviceBinding.enabled"] = True + e.ApplicationProperties["camel.k.serviceBinding.enabled"] = boolean.TrueString for _, cp := range e.CamelCatalog.Runtime.Capabilities["service-binding"].RuntimeProperties { e.ApplicationProperties[CapabilityPropertyKey(cp.Key, e.ApplicationProperties)] = cp.Value } @@ -123,7 +124,7 @@ func (t *serviceBindingTrait) setProperties(e *Environment) { if e.ApplicationProperties == nil { e.ApplicationProperties = make(map[string]string) } - e.ApplicationProperties["quarkus.kubernetes-service-binding.enabled"] = "true" + e.ApplicationProperties["quarkus.kubernetes-service-binding.enabled"] = boolean.TrueString } func (t *serviceBindingTrait) getContext(e *Environment) (pipeline.Context, error) { @@ -224,7 +225,7 @@ func createSecret(ctx pipeline.Context, ns, integrationName string) *corev1.Secr Name: name, Labels: map[string]string{ v1.IntegrationLabel: integrationName, - serviceBindingLabel: "true", + serviceBindingLabel: boolean.TrueString, }, Annotations: map[string]string{ serviceBindingMountPointAnnotation: camel.ServiceBindingsMountPath, diff --git a/pkg/trait/service_binding_test.go b/pkg/trait/service_binding_test.go index 407646639f..81831d0f19 100644 --- a/pkg/trait/service_binding_test.go +++ b/pkg/trait/service_binding_test.go @@ -25,6 +25,7 @@ import ( "github.com/stretchr/testify/require" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/test" ) @@ -44,7 +45,7 @@ func TestServiceBinding(t *testing.T) { handlers = []pipeline.Handler{} err = sbTrait.Apply(environment) require.NoError(t, err) - assert.Equal(t, "true", environment.ApplicationProperties["camel.k.serviceBinding.enabled"]) + assert.Equal(t, boolean.TrueString, environment.ApplicationProperties["camel.k.serviceBinding.enabled"]) assert.Equal(t, "${camel.k.serviceBinding.enabled}", environment.ApplicationProperties["quarkus.kubernetes-service-binding.enabled"]) // TODO we should make the service binding trait to easily work with fake client // and test the apply secret in the environment accordingly. diff --git a/pkg/trait/trait_configure_test.go b/pkg/trait/trait_configure_test.go index eaac55f5bf..15d599346a 100644 --- a/pkg/trait/trait_configure_test.go +++ b/pkg/trait/trait_configure_test.go @@ -28,6 +28,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/v2/pkg/util/boolean" ) func TestTraitConfiguration(t *testing.T) { @@ -70,7 +71,7 @@ func TestTraitConfigurationFromAnnotations(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "trait.camel.apache.org/cron.concurrency-policy": "annotated-policy", - "trait.camel.apache.org/environment.container-meta": "true", + "trait.camel.apache.org/environment.container-meta": boolean.TrueString, }, }, Spec: v1.IntegrationSpec{ @@ -134,7 +135,7 @@ func TestTraitConfigurationOverrideRulesFromAnnotations(t *testing.T) { Annotations: map[string]string{ "trait.camel.apache.org/cron.components": "cmp3", "trait.camel.apache.org/cron.concurrency-policy": "policy2", - "trait.camel.apache.org/builder.verbose": "true", + "trait.camel.apache.org/builder.verbose": boolean.TrueString, }, }, Spec: v1.IntegrationKitSpec{ diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go index a32fade6f0..0b003abe8c 100644 --- a/pkg/trait/trait_test.go +++ b/pkg/trait/trait_test.go @@ -33,6 +33,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" traitv1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1/trait" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/test" @@ -382,8 +383,8 @@ func TestConfigureVolumesAndMountsSourcesInNativeMode(t *testing.T) { Loaders: map[string]v1.CamelLoader{ "java": { Metadata: map[string]string{ - "native": "true", - "sources-required-at-build-time": "true", + "native": boolean.TrueString, + "sources-required-at-build-time": boolean.TrueString, }, }, }, diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go index 2527ebe6f6..b11487d673 100644 --- a/pkg/trait/trait_types.go +++ b/pkg/trait/trait_types.go @@ -36,6 +36,7 @@ import ( v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "github.com/apache/camel-k/v2/pkg/client" "github.com/apache/camel-k/v2/pkg/platform" + "github.com/apache/camel-k/v2/pkg/util/boolean" "github.com/apache/camel-k/v2/pkg/util/camel" "github.com/apache/camel-k/v2/pkg/util/kubernetes" "github.com/apache/camel-k/v2/pkg/util/log" @@ -43,9 +44,6 @@ import ( ) const ( - True = "true" - False = "false" - sourceLanguageAnnotation = "camel.apache.org/source.language" sourceLoaderAnnotation = "camel.apache.org/source.loader" sourceNameAnnotation = "camel.apache.org/source.name" @@ -482,7 +480,7 @@ func (e *Environment) addSourcesProperties() { e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].loader", idx)] = s.Loader } if s.Compression { - e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].compressed", idx)] = "true" + e.ApplicationProperties[fmt.Sprintf("camel.k.sources[%d].compressed", idx)] = boolean.TrueString } interceptors := make([]string, 0, len(s.Interceptors)) diff --git a/pkg/util/boolean/boolean.go b/pkg/util/boolean/boolean.go new file mode 100644 index 0000000000..62df2c521e --- /dev/null +++ b/pkg/util/boolean/boolean.go @@ -0,0 +1,23 @@ +/* +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 boolean + +const ( + TrueString = "true" + FalseString = "false" +) diff --git a/pkg/util/camel/camel_runtime_test.go b/pkg/util/camel/camel_runtime_test.go index 6e6c18a845..35bfc219d9 100644 --- a/pkg/util/camel/camel_runtime_test.go +++ b/pkg/util/camel/camel_runtime_test.go @@ -24,6 +24,8 @@ import ( "testing" "time" + "github.com/apache/camel-k/v2/pkg/util/boolean" + v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "github.com/apache/camel-k/v2/pkg/util/defaults" "github.com/apache/camel-k/v2/pkg/util/maven" @@ -41,7 +43,7 @@ func TestCreateCatalog(t *testing.T) { c, err := test.NewFakeClient() require.NoError(t, err) // use local Maven executable in tests - t.Setenv("MAVEN_WRAPPER", "false") + t.Setenv("MAVEN_WRAPPER", boolean.FalseString) _, ok := os.LookupEnv("MAVEN_CMD") if !ok { t.Setenv("MAVEN_CMD", "mvn") diff --git a/pkg/util/source/inspector_xml.go b/pkg/util/source/inspector_xml.go index 6197a36e64..f5c862b658 100644 --- a/pkg/util/source/inspector_xml.go +++ b/pkg/util/source/inspector_xml.go @@ -30,6 +30,8 @@ type XMLInspector struct { } // Extract --. +// +//nolint:goconst func (i XMLInspector) Extract(source v1.SourceSpec, meta *Metadata) error { content := strings.NewReader(source.Content) decoder := xml.NewDecoder(content)