Skip to content

Commit

Permalink
chore(trait): check for deprecate languages
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Sep 11, 2024
1 parent 194ad1d commit a55574a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
33 changes: 29 additions & 4 deletions pkg/trait/quarkus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -65,26 +67,26 @@ 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.
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)
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
56 changes: 56 additions & 0 deletions pkg/trait/quarkus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit a55574a

Please sign in to comment.