From 032aee7fa0fb4246fefbb0ccca3a3038143a1f0d Mon Sep 17 00:00:00 2001 From: Pasquale Congiusti Date: Wed, 11 Sep 2024 14:42:21 +0200 Subject: [PATCH] chore(trait): check for deprecate languages Ref #5837 --- pkg/trait/quarkus.go | 33 ++++++++++++++++++++--- pkg/trait/quarkus_test.go | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go index b2193b1ec0..50327b22c5 100644 --- a/pkg/trait/quarkus.go +++ b/pkg/trait/quarkus.go @@ -57,6 +57,8 @@ type quarkusTrait struct { traitv1.QuarkusTrait `property:",squash"` } type languageSettings struct { + // indicates whether the language is supported + deprecated bool // indicates whether the native mode is supported native bool // indicates whether the sources are required at build time for native compilation @@ -65,9 +67,9 @@ type languageSettings struct { var ( // settings for an unknown language. - defaultSettings = languageSettings{false, false} + defaultSettings = languageSettings{false, false, false} // settings for languages supporting native mode for old catalogs. - nativeSupportSettings = languageSettings{true, false} + nativeSupportSettings = languageSettings{false, true, false} ) // Retrieves the settings of the given language from the Camel catalog. @@ -75,16 +77,16 @@ func getLanguageSettings(e *Environment, language v1.Language) languageSettings if loader, ok := e.CamelCatalog.Loaders[string(language)]; ok { native, nExists := loader.Metadata["native"] if !nExists { - log.Debug("The metadata 'native' is absent from the Camel catalog, the legacy language settings are applied") return getLegacyLanguageSettings(language) } sourcesRequiredAtBuildTime, sExists := loader.Metadata["sources-required-at-build-time"] + deprecated, dpExists := loader.Metadata["deprecated"] return languageSettings{ native: native == boolean.TrueString, sourcesRequiredAtBuildTime: sExists && sourcesRequiredAtBuildTime == boolean.TrueString, + deprecated: dpExists && deprecated == boolean.TrueString, } } - log.Debugf("No loader could be found for the language %q, the legacy language settings are applied", string(language)) return getLegacyLanguageSettings(language) } @@ -142,6 +144,16 @@ func (t *quarkusTrait) Matches(trait Trait) bool { func (t *quarkusTrait) Configure(e *Environment) (bool, *TraitCondition, error) { condition := t.adaptDeprecatedFields() + if t.languageSettingDeprecated(e) { + message := "The sources contains some language marked as deprecated. This Integration may not be supported in future release." + if condition == nil { + condition = NewIntegrationCondition( + "Quarkus", v1.IntegrationConditionTraitInfo, corev1.ConditionTrue, traitConfigurationReason, message) + } else { + condition.message += message + } + } + if t.containsMode(traitv1.NativeQuarkusMode) && e.IntegrationInPhase(v1.IntegrationPhaseBuildingKit) { // Native compilation is only supported for a subset of languages, // so let's check for compatibility, and fail-fast the Integration, @@ -176,6 +188,19 @@ func (t *quarkusTrait) adaptDeprecatedFields() *TraitCondition { return nil } +func (t *quarkusTrait) languageSettingDeprecated(e *Environment) bool { + if e.Integration == nil { + return false + } + for _, source := range e.Integration.AllSources() { + if language := source.InferLanguage(); getLanguageSettings(e, language).deprecated { + return true + } + } + + return false +} + func (t *quarkusTrait) validateNativeSupport(e *Environment) error { for _, source := range e.Integration.AllSources() { if language := source.InferLanguage(); !getLanguageSettings(e, language).native { diff --git a/pkg/trait/quarkus_test.go b/pkg/trait/quarkus_test.go index 107eecfaa0..8092e3b79b 100644 --- a/pkg/trait/quarkus_test.go +++ b/pkg/trait/quarkus_test.go @@ -256,3 +256,59 @@ func TestQuarkusMatches(t *testing.T) { qt2.NativeBaseImage = "docker.io/my-new-native-base" assert.False(t, qt.Matches(&qt2)) } + +func TestConfigureQuarkusTraitDeprecatedPackageType(t *testing.T) { + quarkusTrait, environment := createNominalQuarkusTest() + quarkusTrait.PackageTypes = []traitv1.QuarkusPackageType{ + traitv1.FastJarPackageType, + } + environment.IntegrationKit.Status.Phase = v1.IntegrationKitPhaseBuildSubmitted + configured, condition, err := quarkusTrait.Configure(environment) + + assert.True(t, configured) + require.NoError(t, err) + assert.NotNil(t, condition) + assert.Equal(t, "The package-type parameter is deprecated and may be removed in future releases. Make sure to use mode parameter instead.", condition.message) + assert.Equal(t, traitv1.JvmQuarkusMode, quarkusTrait.QuarkusTrait.Modes[0]) +} + +func TestConfigureQuarkusTraitSupportedLanguages(t *testing.T) { + quarkusTrait, environment := createNominalQuarkusTest() + environment.CamelCatalog.Loaders = map[string]v1.CamelLoader{ + "supportedLanguage": { + Metadata: map[string]string{ + "deprecated": "false", + "native": "true", + "sources-required-at-build-time": "false", + }, + }, + } + environment.Integration.Spec.Sources[0].Language = v1.Language("supportedLanguage") + environment.IntegrationKit.Status.Phase = v1.IntegrationKitPhaseBuildSubmitted + configured, condition, err := quarkusTrait.Configure(environment) + + assert.True(t, configured) + require.NoError(t, err) + assert.Nil(t, condition) +} + +func TestConfigureQuarkusTraitDeprecatedLanguages(t *testing.T) { + quarkusTrait, environment := createNominalQuarkusTest() + environment.CamelCatalog.Loaders = map[string]v1.CamelLoader{ + "deprecatedLanguage": { + Metadata: map[string]string{ + "deprecated": "true", + "native": "false", + "sources-required-at-build-time": "false", + }, + }, + } + environment.Integration.Spec.Sources[0].Language = v1.Language("deprecatedLanguage") + environment.IntegrationKit.Status.Phase = v1.IntegrationKitPhaseBuildSubmitted + configured, condition, err := quarkusTrait.Configure(environment) + + assert.True(t, configured) + require.NoError(t, err) + assert.NotNil(t, condition) + assert.Equal(t, "The sources contains some language marked as deprecated. This Integration may not be supported in future release.", condition.message) +}