Skip to content

Commit

Permalink
chore(trait): drop support for scanKameletsImplicitLabelSecrets
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Aug 14, 2024
1 parent d6b9b27 commit c1c57cf
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 189 deletions.
5 changes: 1 addition & 4 deletions docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7921,10 +7921,7 @@ bool
|
Deprecated: include your properties in an explicit property file backed by a secret.
Let the operator to scan for secret labeled with `camel.apache.org/kamelet` and `camel.apache.org/kamelet.configuration`.
These secrets are mounted to the application and treated as plain properties file with their key/value list
(ie .spec.data["camel.my-property"] = my-value) (default `true`).
Deprecated: no longer available since version 2.5.
|===
Expand Down
5 changes: 1 addition & 4 deletions docs/modules/traits/pages/mount.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ changes in metadata.

| mount.scan-kamelets-implicit-label-secrets
| bool
| Deprecated: include your properties in an explicit property file backed by a secret.
Let the operator to scan for secret labeled with `camel.apache.org/kamelet` and `camel.apache.org/kamelet.configuration`.
These secrets are mounted to the application and treated as plain properties file with their key/value list
(ie .spec.data["camel.my-property"] = my-value) (default `true`).
| Deprecated: no longer available since version 2.5.

|===

Expand Down
5 changes: 1 addition & 4 deletions pkg/apis/camel/v1/trait/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ type MountTrait struct {
// marked with `camel.apache.org/integration` label to be taken in account. The resource will be watched for any kind change, also for
// changes in metadata.
HotReload *bool `property:"hot-reload" json:"hotReload,omitempty"`
// Deprecated: include your properties in an explicit property file backed by a secret.
// Let the operator to scan for secret labeled with `camel.apache.org/kamelet` and `camel.apache.org/kamelet.configuration`.
// These secrets are mounted to the application and treated as plain properties file with their key/value list
// (ie .spec.data["camel.my-property"] = my-value) (default `true`).
// Deprecated: no longer available since version 2.5.
ScanKameletsImplicitLabelSecrets *bool `property:"scan-kamelets-implicit-label-secrets" json:"scanKameletsImplicitLabelSecrets,omitempty"`
}
8 changes: 8 additions & 0 deletions pkg/client/camel/informers/externalversions/factory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1660,11 +1660,8 @@ spec:
type: string
type: array
scanKameletsImplicitLabelSecrets:
description: |-
Deprecated: include your properties in an explicit property file backed by a secret.
Let the operator to scan for secret labeled with `camel.apache.org/kamelet` and `camel.apache.org/kamelet.configuration`.
These secrets are mounted to the application and treated as plain properties file with their key/value list
(ie .spec.data["camel.my-property"] = my-value) (default `true`).
description: 'Deprecated: no longer available since version
2.5.'
type: boolean
volumes:
description: 'A list of Persistent Volume Claims to be mounted.
Expand Down Expand Up @@ -3759,11 +3756,8 @@ spec:
type: string
type: array
scanKameletsImplicitLabelSecrets:
description: |-
Deprecated: include your properties in an explicit property file backed by a secret.
Let the operator to scan for secret labeled with `camel.apache.org/kamelet` and `camel.apache.org/kamelet.configuration`.
These secrets are mounted to the application and treated as plain properties file with their key/value list
(ie .spec.data["camel.my-property"] = my-value) (default `true`).
description: 'Deprecated: no longer available since version
2.5.'
type: boolean
volumes:
description: 'A list of Persistent Volume Claims to be mounted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1535,11 +1535,8 @@ spec:
type: string
type: array
scanKameletsImplicitLabelSecrets:
description: |-
Deprecated: include your properties in an explicit property file backed by a secret.
Let the operator to scan for secret labeled with `camel.apache.org/kamelet` and `camel.apache.org/kamelet.configuration`.
These secrets are mounted to the application and treated as plain properties file with their key/value list
(ie .spec.data["camel.my-property"] = my-value) (default `true`).
description: 'Deprecated: no longer available since version
2.5.'
type: boolean
volumes:
description: 'A list of Persistent Volume Claims to be mounted.
Expand Down Expand Up @@ -3516,11 +3513,8 @@ spec:
type: string
type: array
scanKameletsImplicitLabelSecrets:
description: |-
Deprecated: include your properties in an explicit property file backed by a secret.
Let the operator to scan for secret labeled with `camel.apache.org/kamelet` and `camel.apache.org/kamelet.configuration`.
These secrets are mounted to the application and treated as plain properties file with their key/value list
(ie .spec.data["camel.my-property"] = my-value) (default `true`).
description: 'Deprecated: no longer available since version
2.5.'
type: boolean
volumes:
description: 'A list of Persistent Volume Claims to be mounted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7551,11 +7551,8 @@ spec:
type: string
type: array
scanKameletsImplicitLabelSecrets:
description: |-
Deprecated: include your properties in an explicit property file backed by a secret.
Let the operator to scan for secret labeled with `camel.apache.org/kamelet` and `camel.apache.org/kamelet.configuration`.
These secrets are mounted to the application and treated as plain properties file with their key/value list
(ie .spec.data["camel.my-property"] = my-value) (default `true`).
description: 'Deprecated: no longer available since version
2.5.'
type: boolean
volumes:
description: 'A list of Persistent Volume Claims to be mounted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7623,11 +7623,8 @@ spec:
type: string
type: array
scanKameletsImplicitLabelSecrets:
description: |-
Deprecated: include your properties in an explicit property file backed by a secret.
Let the operator to scan for secret labeled with `camel.apache.org/kamelet` and `camel.apache.org/kamelet.configuration`.
These secrets are mounted to the application and treated as plain properties file with their key/value list
(ie .spec.data["camel.my-property"] = my-value) (default `true`).
description: 'Deprecated: no longer available since version
2.5.'
type: boolean
volumes:
description: 'A list of Persistent Volume Claims to be
Expand Down
7 changes: 2 additions & 5 deletions pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7621,11 +7621,8 @@ spec:
type: string
type: array
scanKameletsImplicitLabelSecrets:
description: |-
Deprecated: include your properties in an explicit property file backed by a secret.
Let the operator to scan for secret labeled with `camel.apache.org/kamelet` and `camel.apache.org/kamelet.configuration`.
These secrets are mounted to the application and treated as plain properties file with their key/value list
(ie .spec.data["camel.my-property"] = my-value) (default `true`).
description: 'Deprecated: no longer available since version
2.5.'
type: boolean
volumes:
description: 'A list of Persistent Volume Claims to be
Expand Down
66 changes: 0 additions & 66 deletions pkg/trait/kamelets.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ const (
kameletMountPointAnnotation = "camel.apache.org/kamelet.mount-point"
)

type configurationKey struct {
kamelet string
configurationID string
}

func newConfigurationKey(kamelet, configurationID string) configurationKey {
return configurationKey{
kamelet: kamelet,
configurationID: configurationID,
}
}

type kameletsTrait struct {
BaseTrait
traitv1.KameletsTrait `property:",squash"`
Expand Down Expand Up @@ -267,30 +255,6 @@ func (t *kameletsTrait) addKameletAsSource(e *Environment, kamelet *v1.Kamelet)
return nil
}

// Deprecated: use explicit secret configuration instead.
func (t *kameletsTrait) listConfigurationSecrets(e *Environment) ([]string, error) {
listConfigurationSecrets := make([]string, 0)
for _, k := range t.getConfigurationKeys() {
options := metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", kameletLabel, k.kamelet),
}
if k.configurationID != "" {
options.LabelSelector = fmt.Sprintf("%s=%s,%s=%s", kameletLabel, k.kamelet, kameletConfigurationLabel, k.configurationID)
}
secrets, err := t.Client.CoreV1().Secrets(e.Integration.Namespace).List(e.Ctx, options)
if err != nil {
return nil, err
}
for _, item := range secrets.Items {
if item.Labels != nil && item.Labels[kameletConfigurationLabel] != k.configurationID {
continue
}
listConfigurationSecrets = append(listConfigurationSecrets, item.Name)
}
}
return listConfigurationSecrets, nil
}

func (t *kameletsTrait) getKameletKeys() []string {
answer := make([]string, 0)
for _, item := range strings.Split(t.List, ",") {
Expand All @@ -306,36 +270,6 @@ func (t *kameletsTrait) getKameletKeys() []string {
return answer
}

func (t *kameletsTrait) getConfigurationKeys() []configurationKey {
answer := make([]configurationKey, 0)
for _, item := range t.getKameletKeys() {
answer = append(answer, newConfigurationKey(item, ""))
}
for _, item := range strings.Split(t.List, ",") {
i := strings.Trim(item, " \t\"")
if strings.Contains(i, "/") {
parts := strings.SplitN(i, "/", 2)
newKey := newConfigurationKey(parts[0], parts[1])
alreadyPresent := false
for _, existing := range answer {
if existing == newKey {
alreadyPresent = true
break
}
}
if !alreadyPresent {
answer = append(answer, newKey)
}
}
}
sort.Slice(answer, func(i, j int) bool {
o1 := answer[i]
o2 := answer[j]
return o1.kamelet < o2.kamelet || (o1.kamelet == o2.kamelet && o1.configurationID < o2.configurationID)
})
return answer
}

func integrationSourceFromKameletSource(e *Environment, kamelet *v1.Kamelet, source v1.SourceSpec, name string) (v1.SourceSpec, error) {
if source.Type == v1.SourceTypeTemplate {
// Kamelets must be named "<kamelet-name>.extension"
Expand Down
25 changes: 0 additions & 25 deletions pkg/trait/kamelets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ func TestConfigurationWithKamelets(t *testing.T) {
assert.True(t, enabled)
assert.Nil(t, condition)
assert.Equal(t, []string{"c0", "c1", "c2", "complex-.-.-1a", "complex-.-.-1b", "complex-.-.-1c"}, trait.getKameletKeys())
assert.Equal(t, []configurationKey{
newConfigurationKey("c0", ""),
newConfigurationKey("c1", ""),
newConfigurationKey("c2", ""),
newConfigurationKey("complex-.-.-1a", ""),
newConfigurationKey("complex-.-.-1b", ""),
newConfigurationKey("complex-.-.-1b", "a"),
newConfigurationKey("complex-.-.-1c", ""),
newConfigurationKey("complex-.-.-1c", "b"),
}, trait.getConfigurationKeys())
}

func TestKameletLookup(t *testing.T) {
Expand Down Expand Up @@ -369,12 +359,6 @@ func TestKameletConfigLookup(t *testing.T) {
assert.True(t, enabled)
assert.Nil(t, condition)
assert.Equal(t, []string{"timer"}, trait.getKameletKeys())
assert.Equal(t, []configurationKey{newConfigurationKey("timer", "")}, trait.getConfigurationKeys())

list, err := trait.listConfigurationSecrets(environment)
require.NoError(t, err)
assert.Contains(t, list, "my-secret", "my-secret3")
assert.NotContains(t, list, "my-secret2")
}

func TestKameletNamedConfigLookup(t *testing.T) {
Expand Down Expand Up @@ -431,15 +415,6 @@ func TestKameletNamedConfigLookup(t *testing.T) {
assert.True(t, enabled)
assert.Nil(t, condition)
assert.Equal(t, []string{"timer"}, trait.getKameletKeys())
assert.Equal(t, []configurationKey{
newConfigurationKey("timer", ""),
newConfigurationKey("timer", "id2"),
}, trait.getConfigurationKeys())

list, err := trait.listConfigurationSecrets(environment)
require.NoError(t, err)
assert.Contains(t, list, "my-secret", "my-secret2")
assert.NotContains(t, list, "my-secret3")
}

func TestKameletConditionFalse(t *testing.T) {
Expand Down
52 changes: 1 addition & 51 deletions pkg/trait/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ import (
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

serving "knative.dev/serving/pkg/apis/serving/v1"

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"
Expand Down Expand Up @@ -60,9 +58,6 @@ func (t *mountTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
// Look for secrets which may have been created by service binding trait
t.addServiceBindingSecret(e)

// Look for implicit secrets which may be required by kamelets
condition := t.addImplicitKameletsSecrets(e)

// Validate resources and pvcs
for _, c := range t.Configs {
if !strings.HasPrefix(c, "configmap:") && !strings.HasPrefix(c, "secret:") {
Expand All @@ -75,7 +70,7 @@ func (t *mountTrait) Configure(e *Environment) (bool, *TraitCondition, error) {
}
}

return true, condition, nil
return true, nil, nil
}

func (t *mountTrait) Apply(e *Environment) error {
Expand Down Expand Up @@ -191,48 +186,3 @@ func (t *mountTrait) addServiceBindingSecret(e *Environment) {
}
})
}

// Deprecated: to be removed in future releases.
func (t *mountTrait) addImplicitKameletsSecrets(e *Environment) *TraitCondition {
featureUsed := false
if trait := e.Catalog.GetTrait(kameletsTraitID); trait != nil {
kamelets, ok := trait.(*kameletsTrait)
if !ok {
return NewIntegrationCondition(
"Mount",
v1.IntegrationConditionTraitInfo,
corev1.ConditionTrue,
traitConfigurationReason,
"Unexpected error happened while casting to kamelets trait",
)
}
if !ptr.Deref(t.ScanKameletsImplicitLabelSecrets, true) {
return nil
}
implicitKameletSecrets, err := kamelets.listConfigurationSecrets(e)
if err != nil {
return NewIntegrationCondition(
"Mount",
v1.IntegrationConditionTraitInfo,
corev1.ConditionTrue,
traitConfigurationReason,
err.Error(),
)
}
for _, secret := range implicitKameletSecrets {
featureUsed = true
t.Configs = append(t.Configs, "secret:"+secret)
}
}

if featureUsed {
return NewIntegrationCondition(
"Mount",
v1.IntegrationConditionTraitInfo,
corev1.ConditionTrue,
traitConfigurationReason,
"Implicit Kamelet labelling secrets are deprecated and may be removed in future releases. Make sure to use explicit mount.config secrets instead.",
)
}
return nil
}

0 comments on commit c1c57cf

Please sign in to comment.