You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2023/08/22 12:15:10 UTC
[camel-k] 01/06: chore(trait): remove autogenerated cm code
This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 91c9ff9234f18039cd834f4e51436b1d9d4fb2ac
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri Aug 11 09:22:53 2023 +0200
chore(trait): remove autogenerated cm code
---
pkg/trait/mount.go | 17 -----------------
pkg/util/resource/config.go | 42 ------------------------------------------
2 files changed, 59 deletions(-)
diff --git a/pkg/trait/mount.go b/pkg/trait/mount.go
index 1e5bf19d0..eaf58a9c3 100644
--- a/pkg/trait/mount.go
+++ b/pkg/trait/mount.go
@@ -25,7 +25,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
- "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/utils/pointer"
serving "knative.dev/serving/pkg/apis/serving/v1"
@@ -129,7 +128,6 @@ func (t *mountTrait) Apply(e *Environment) error {
func (t *mountTrait) configureVolumesAndMounts(e *Environment, vols *[]corev1.Volume, mnts *[]corev1.VolumeMount) error {
for _, c := range t.Configs {
if conf, parseErr := utilResource.ParseConfig(c); parseErr == nil {
- t.attachResource(e, conf)
t.mountResource(vols, mnts, conf)
} else {
return parseErr
@@ -137,7 +135,6 @@ func (t *mountTrait) configureVolumesAndMounts(e *Environment, vols *[]corev1.Vo
}
for _, r := range t.Resources {
if res, parseErr := utilResource.ParseResource(r); parseErr == nil {
- t.attachResource(e, res)
t.mountResource(vols, mnts, res)
} else {
return parseErr
@@ -154,20 +151,6 @@ func (t *mountTrait) configureVolumesAndMounts(e *Environment, vols *[]corev1.Vo
return nil
}
-// attachResource is in charge to filter the autogenerated configmap and attach to the Integration resources.
-// The owner trait will be in charge to bind it accordingly.
-func (t *mountTrait) attachResource(e *Environment, conf *utilResource.Config) {
- if conf.StorageType() == utilResource.StorageTypeConfigmap {
- // verify if it was autogenerated
- cm, err := kubernetes.GetUnstructured(e.Ctx, e.Client, schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ConfigMap"},
- conf.Name(), e.Integration.Namespace)
- if err == nil && cm != nil && cm.GetLabels()[kubernetes.ConfigMapAutogenLabel] == "true" {
- refCm := kubernetes.NewConfigMap(e.Integration.Namespace, conf.Name(), "", "", "", nil)
- e.Resources.Add(refCm)
- }
- }
-}
-
func (t *mountTrait) mountResource(vols *[]corev1.Volume, mnts *[]corev1.VolumeMount, conf *utilResource.Config) {
refName := kubernetes.SanitizeLabel(conf.Name())
dstDir := conf.DestinationPath()
diff --git a/pkg/util/resource/config.go b/pkg/util/resource/config.go
index 474c14aee..8f52444ea 100644
--- a/pkg/util/resource/config.go
+++ b/pkg/util/resource/config.go
@@ -18,18 +18,10 @@ limitations under the License.
package resource
import (
- "context"
"crypto/sha1" // nolint: gosec
"fmt"
- "path/filepath"
"regexp"
"strings"
-
- "github.com/apache/camel-k/v2/pkg/client"
- "github.com/apache/camel-k/v2/pkg/util/camel"
- "github.com/apache/camel-k/v2/pkg/util/kubernetes"
- corev1 "k8s.io/api/core/v1"
- k8serrors "k8s.io/apimachinery/pkg/api/errors"
)
// Config represents a config option.
@@ -184,40 +176,6 @@ func parse(item string, contentType ContentType) (*Config, error) {
return newConfig(cot, contentType, value), nil
}
-// ConvertFileToConfigmap convert a local file resource type in a configmap type
-// taking care to create the Configmap on the cluster. The method will change the value of config parameter
-// to reflect the conversion applied transparently.
-func ConvertFileToConfigmap(ctx context.Context, c client.Client, config *Config, namespace string, integrationName string,
- content string, rawContent []byte) (*corev1.ConfigMap, error) {
- filename := filepath.Base(config.Name())
- if config.DestinationPath() == "" {
- config.resourceKey = filename
- // As we are changing the resource to a configmap type
- // we must declare the destination path
- if config.ContentType() == ContentTypeData {
- config.destinationPath = camel.ResourcesDefaultMountPath + "/" + filename
- } else {
- config.destinationPath = camel.ConfigResourcesMountPath + "/" + filename
- }
- } else {
- config.resourceKey = filepath.Base(config.DestinationPath())
- }
- genCmName := fmt.Sprintf("cm-%s", hashFrom([]byte(filename), []byte(integrationName), []byte(content), rawContent))
- cm := kubernetes.NewConfigMap(namespace, genCmName, filename, config.Key(), content, rawContent)
- err := c.Create(ctx, cm)
- if err != nil {
- if k8serrors.IsAlreadyExists(err) {
- // We'll reuse it, as is
- } else {
- return cm, err
- }
- }
- config.storageType = StorageTypeConfigmap
- config.resourceName = cm.Name
-
- return cm, nil
-}
-
func hashFrom(contents ...[]byte) string {
// SHA1 because we need to limit the length to less than 64 chars
hash := sha1.New() // nolint: gosec