Skip to content

Commit

Permalink
feat(core): Move jib plugins versions to camelcatalog
Browse files Browse the repository at this point in the history
Ref apache#4703

Extracted jib plugin versions to camel-k-runtime:
* use .spec.runtime.metadata values
* set default values for catalog backward compatibility
  • Loading branch information
gansheer committed Oct 6, 2023
1 parent 09d149a commit e9bf525
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
12 changes: 12 additions & 0 deletions pkg/apis/camel/v1/camelcatalog_types_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ func (c *CamelCatalogSpec) GetQuarkusToolingImage() string {
return c.Runtime.Metadata["quarkus.native-builder-image"]
}

// TODO change comment
// GetQuarkusToolingImage returns the Quarkus tooling image required to build an application based on this catalog.
func (c *CamelCatalogSpec) GetJibMavenPluginVersion() string {
return c.Runtime.Metadata["jib.maven-plugin.version"]
}

// TODO change comment
// GetQuarkusToolingImage returns the Quarkus tooling image required to build an application based on this catalog.
func (c *CamelCatalogSpec) GetJibLayerFilterExtensionMavenVersion() string {
return c.Runtime.Metadata["jib.layer-filter-extension-maven.version"]
}

// HasCapability checks if the given capability is present in the catalog.
func (c *CamelCatalogSpec) HasCapability(capability string) bool {
_, ok := c.Runtime.Capabilities[capability]
Expand Down
2 changes: 1 addition & 1 deletion pkg/trait/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (t *builderTrait) builderTask(e *Environment, taskConf *v1.BuildConfigurati
}

if e.Platform.Status.Build.PublishStrategy == v1.IntegrationPlatformBuildPublishStrategyJib {
if err := jib.CreateProfileConfigmap(e.Ctx, e.Client, e.IntegrationKit); err != nil {
if err := jib.CreateProfileConfigmap(e.Ctx, e.Client, e.CamelCatalog, e.IntegrationKit); err != nil {
return nil, fmt.Errorf("could not create default maven jib profile: %w. ", err)
}
t.MavenProfiles = append(t.MavenProfiles, "configmap:"+e.IntegrationKit.Name+"-publish-jib-profile/profile.xml")
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
Version = "2.1.0-SNAPSHOT"

// DefaultRuntimeVersion --
DefaultRuntimeVersion = "3.2.0"
DefaultRuntimeVersion = "3.4.0-SNAPSHOT"

// BuildahVersion --
BuildahVersion = "1.30.0"
Expand Down
21 changes: 16 additions & 5 deletions pkg/util/jib/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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/util"
"github.com/apache/camel-k/v2/pkg/util/camel"
"github.com/apache/camel-k/v2/pkg/util/maven"

corev1 "k8s.io/api/core/v1"
Expand All @@ -38,6 +39,8 @@ const JibMavenToImageParam = "-Djib.to.image="
const JibMavenFromImageParam = "-Djib.from.image="
const JibMavenInsecureRegistries = "-Djib.allowInsecureRegistries="
const JibDigestFile = "target/jib-image.digest"
const JibMavenPluginVersionDefault = "3.3.2"
const JibLayerFilterExtensionMavenVersionDefault = "0.3.0"

type JibBuild struct {
Plugins []maven.Plugin `xml:"plugins>plugin,omitempty"`
Expand All @@ -50,8 +53,8 @@ type JibProfile struct {
}

// Create a Configmap containing the default jib profile.
func CreateProfileConfigmap(ctx context.Context, c client.Client, kit *v1.IntegrationKit) error {
profile, err := jibMavenProfile()
func CreateProfileConfigmap(ctx context.Context, c client.Client, catalog *camel.RuntimeCatalog, kit *v1.IntegrationKit) error {
profile, err := jibMavenProfile(catalog.GetJibMavenPluginVersion(), catalog.GetJibLayerFilterExtensionMavenVersion())
if err != nil {
return fmt.Errorf("error generating default maven jib profile: %w. ", err)
}
Expand Down Expand Up @@ -93,16 +96,24 @@ func CreateProfileConfigmap(ctx context.Context, c client.Client, kit *v1.Integr
return nil
}

func jibMavenProfile() (string, error) {
func jibMavenProfile(jibMavenPluginVersion string, jibLayerFilterExtensionMavenVersion string) (string, error) {
jibVersion := JibMavenPluginVersionDefault
if jibMavenPluginVersion != "" {
jibVersion = jibMavenPluginVersion
}
layerVersion := JibLayerFilterExtensionMavenVersionDefault
if jibLayerFilterExtensionMavenVersion != "" {
layerVersion = jibLayerFilterExtensionMavenVersion
}
jibPlugin := maven.Plugin{
GroupID: "com.google.cloud.tools",
ArtifactID: "jib-maven-plugin",
Version: "3.3.2",
Version: jibVersion,
Dependencies: []maven.Dependency{
{
GroupID: "com.google.cloud.tools",
ArtifactID: "jib-layer-filter-extension-maven",
Version: "0.3.0",
Version: layerVersion,
},
},
Configuration: v1.PluginConfiguration{
Expand Down
15 changes: 13 additions & 2 deletions pkg/util/jib/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"testing"

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"
"github.com/apache/camel-k/v2/pkg/util/test"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
Expand All @@ -32,7 +34,7 @@ import (
)

func TestJibMavenProfile(t *testing.T) {
profile, err := jibMavenProfile()
profile, err := jibMavenProfile("2.12.12", "3.3.3")

assert.NoError(t, err)
assert.True(t, strings.HasPrefix(profile, "<profile>"))
Expand All @@ -58,7 +60,16 @@ func TestJibConfigMap(t *testing.T) {
},
}

err := CreateProfileConfigmap(ctx, c, kit)
// TODO add jib versions
camelCatalog := v1.NewCamelCatalog("ns", defaults.DefaultRuntimeVersion)
camelCatalog.Spec.Runtime.Metadata = map[string]string{
"camel-quarkus.version": "2.16.0",
"camel.version": "3.20.1",
"quarkus.version": "2.16.0.Final",
}
runtimeCatalog := camel.NewRuntimeCatalog(camelCatalog)

err := CreateProfileConfigmap(ctx, c, runtimeCatalog, kit)
assert.NoError(t, err)

key := ctrl.ObjectKey{
Expand Down

0 comments on commit e9bf525

Please sign in to comment.