diff --git a/pkg/controller/integration/build_kit.go b/pkg/controller/integration/build_kit.go index beb078cd9d..9f7b20826f 100644 --- a/pkg/controller/integration/build_kit.go +++ b/pkg/controller/integration/build_kit.go @@ -121,7 +121,7 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1alpha1. platformKit.Spec = v1alpha1.IntegrationKitSpec{ Dependencies: integration.Status.Dependencies, Repositories: integration.Spec.Repositories, - Traits: integration.Spec.Traits, + Traits: action.filterKitTraits(ctx, integration.Spec.Traits), } if err := action.client.Create(ctx, &platformKit); err != nil { @@ -134,3 +134,20 @@ func (action *buildKitAction) Handle(ctx context.Context, integration *v1alpha1. return integration, nil } + +func (action *buildKitAction) filterKitTraits(ctx context.Context, in map[string]v1alpha1.TraitSpec) map[string]v1alpha1.TraitSpec { + if len(in) == 0 { + return in + } + catalog := trait.NewCatalog(ctx, action.client) + out := make(map[string]v1alpha1.TraitSpec) + for name, conf := range in { + t := catalog.GetTrait(name) + if t != nil && !t.InfluencesKit() { + // We don't store the trait configuration if the trait cannot influence the kit behavior + continue + } + out[name] = conf + } + return out +} diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go index a017cc236f..0798afbd15 100644 --- a/pkg/trait/builder.go +++ b/pkg/trait/builder.go @@ -66,3 +66,8 @@ func (t *builderTrait) Apply(e *Environment) error { return nil } + +// InfluencesKit overrides base class method +func (t *builderTrait) InfluencesKit() bool { + return true +} diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go index 16d0e6cf27..9aad728b11 100644 --- a/pkg/trait/trait_test.go +++ b/pkg/trait/trait_test.go @@ -361,6 +361,19 @@ func TestConfigureVolumesAndMounts(t *testing.T) { assert.Equal(t, "/foo/bar", m.MountPath) } +func TestOnlySomeKitsInfluenceBuild(t *testing.T) { + c := NewTraitTestCatalog() + buildTraits := []string{"builder"} + + for _, trait := range c.allTraits() { + if trait.InfluencesKit() { + assert.Contains(t, buildTraits, string(trait.ID())) + } else { + assert.NotContains(t, buildTraits, trait.ID()) + } + } +} + func findVolume(vols []corev1.Volume, condition func(corev1.Volume) bool) *corev1.Volume { for _, v := range vols { v := v diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go index 622953e5ea..e7b6201309 100644 --- a/pkg/trait/trait_types.go +++ b/pkg/trait/trait_types.go @@ -66,6 +66,9 @@ type Trait interface { // Apply executes a customization of the Environment Apply(environment *Environment) error + + // InfluencesKit determines if the trait has any influence on Integration Kits + InfluencesKit() bool } /* Base trait */ @@ -101,6 +104,11 @@ func (trait *BaseTrait) InjectContext(ctx context.Context) { trait.ctx = ctx } +// InfluencesKit determines if the trait has any influence on Integration Kits +func (trait *BaseTrait) InfluencesKit() bool { + return false +} + /* Environment */ // A Environment provides the context where the trait is executed