You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2019/05/15 08:53:22 UTC
[camel-k] branch master updated: drop support for knative < 0.4 #552
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/master by this push:
new fade137 drop support for knative < 0.4 #552
fade137 is described below
commit fade137818befafa32622508ccbb18e8fc9b1cab
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Tue May 14 11:18:40 2019 +0200
drop support for knative < 0.4 #552
---
pkg/trait/deployment.go | 1 +
pkg/trait/knative_service.go | 35 +--
pkg/trait/knative_service_env.go | 160 -------------
pkg/trait/knative_service_env_test.go | 247 ---------------------
...service_vol_test.go => knative_service_test.go} | 4 +-
pkg/trait/knative_service_vol.go | 39 ----
6 files changed, 21 insertions(+), 465 deletions(-)
diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index 2ae00db..64320a0 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -131,6 +131,7 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
if annotations == nil {
annotations = make(map[string]string)
}
+
// Resolve registry host names when used
annotations["alpha.image.policy.openshift.io/resolve-names"] = "*"
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index e5c6dee..4731353 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -19,6 +19,7 @@ package trait
import (
"strconv"
+ "strings"
"github.com/apache/camel-k/pkg/util/kubernetes"
@@ -40,15 +41,14 @@ const (
)
type knativeServiceTrait struct {
- BaseTrait `property:",squash"`
- Class string `property:"autoscaling-class"`
- Metric string `property:"autoscaling-metric"`
- Target *int `property:"autoscaling-target"`
- MinScale *int `property:"min-scale"`
- MaxScale *int `property:"max-scale"`
- Auto *bool `property:"auto"`
- ConfigurationType string `property:"configuration-type"`
- deployer deployerTrait
+ BaseTrait `property:",squash"`
+ Class string `property:"autoscaling-class"`
+ Metric string `property:"autoscaling-metric"`
+ Target *int `property:"autoscaling-target"`
+ MinScale *int `property:"min-scale"`
+ MaxScale *int `property:"max-scale"`
+ Auto *bool `property:"auto"`
+ deployer deployerTrait
}
func newKnativeServiceTrait() *knativeServiceTrait {
@@ -183,6 +183,7 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) (*serving.Service, e
},
}
+ paths := e.ComputeSourcesURI()
environment := &svc.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Container.Env
// combine Environment of integration with context, integration
@@ -197,19 +198,19 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) (*serving.Service, e
// has been changed
envvar.SetVal(environment, "CAMEL_K_DIGEST", e.Integration.Status.Digest)
- // optimizations
- envvar.SetVal(environment, "AB_JOLOKIA_OFF", True)
-
- if t.ConfigurationType == "volume" {
- t.bindToVolumes(e, &svc)
- } else if err := t.bindToEnvVar(e, &svc); err != nil {
- return nil, err
- }
+ envvar.SetVal(environment, "CAMEL_K_ROUTES", strings.Join(paths, ","))
+ envvar.SetVal(environment, "CAMEL_K_CONF", "/etc/camel/conf/application.properties")
+ envvar.SetVal(environment, "CAMEL_K_CONF_D", "/etc/camel/conf.d")
// add env vars from traits
for _, envVar := range e.EnvVars {
envvar.SetVar(&svc.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Container.Env, envVar)
}
+ e.ConfigureVolumesAndMounts(
+ &svc.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Volumes,
+ &svc.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Container.VolumeMounts,
+ )
+
return &svc, nil
}
diff --git a/pkg/trait/knative_service_env.go b/pkg/trait/knative_service_env.go
deleted file mode 100644
index 7dd6339..0000000
--- a/pkg/trait/knative_service_env.go
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements. See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package trait
-
-import (
- "fmt"
- "strings"
-
- "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
- "github.com/apache/camel-k/pkg/util"
- "github.com/apache/camel-k/pkg/util/envvar"
- "github.com/apache/camel-k/pkg/util/kubernetes"
-
- serving "github.com/knative/serving/pkg/apis/serving/v1alpha1"
-)
-
-func (t *knativeServiceTrait) bindToEnvVar(e *Environment, service *serving.Service) error {
- environment := &service.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Container.Env
-
- //
- // Properties
- //
- properties := make(map[string]string)
-
- for _, cmName := range e.CollectConfigurationValues("configmap") {
- cm, err := kubernetes.GetConfigMap(e.C, e.Client, cmName, e.Integration.Namespace)
- if err != nil {
- t.L.Errorf(err, "failed to lookup ConfigMap %s", cmName)
- }
- if cm != nil {
- err = util.ExtractApplicationPropertiesString(cm.Data, func(key string, val string) {
- properties[key] = val
- })
- if err != nil {
- t.L.Errorf(err, "failed to extract properties from ConfigMap %s", cmName)
- }
- }
- }
-
- for _, secretName := range e.CollectConfigurationValues("secret") {
- cm, err := kubernetes.GetSecret(e.C, e.Client, secretName, e.Integration.Namespace)
- if err != nil {
- t.L.Errorf(err, "failed to lookup Secret %s", secretName)
- }
- if cm != nil {
- err = util.ExtractApplicationPropertiesBytes(cm.Data, func(key string, val string) {
- properties[key] = val
- })
- if err != nil {
- t.L.Errorf(err, "failed to extract properties from Secret %s", secretName)
- }
- }
- }
-
- for key, value := range e.CollectConfigurationPairs("property") {
- properties[key] = value
- }
-
- p := ""
-
- for k, v := range properties {
- p += fmt.Sprintf("%s=%s\n", k, v)
- }
-
- envvar.SetVal(environment, "CAMEL_K_CONF", "env:CAMEL_K_PROPERTIES")
- envvar.SetVal(environment, "CAMEL_K_PROPERTIES", p)
-
- //
- // Sources
- //
-
- sourcesSpecs, err := kubernetes.ResolveIntegrationSources(t.ctx, t.client, e.Integration, e.Resources)
- if err != nil {
- return err
- }
-
- sources := make([]string, 0, len(e.Integration.Spec.Sources))
-
- for i, s := range sourcesSpecs {
- if s.Content == "" {
- t.L.Debug("Source %s has and empty content", s.Name)
- }
-
- envName := fmt.Sprintf("CAMEL_K_ROUTE_%03d", i)
- envvar.SetVal(environment, envName, s.Content)
-
- params := make([]string, 0)
- params = append(params, "name="+s.Name)
-
- if s.InferLanguage() != "" {
- params = append(params, "language="+string(s.InferLanguage()))
- }
- if s.Compression {
- params = append(params, "compression=true")
- }
-
- src := fmt.Sprintf("env:%s", envName)
- if len(params) > 0 {
- src = fmt.Sprintf("%s?%s", src, strings.Join(params, "&"))
- }
-
- sources = append(sources, src)
- }
-
- // camel-k runtime
- envvar.SetVal(environment, "CAMEL_K_ROUTES", strings.Join(sources, ","))
-
- //
- // Resources
- //
-
- resourcesSpecs, err := kubernetes.ResolveIntegrationResources(t.ctx, t.client, e.Integration, e.Resources)
- if err != nil {
- return err
- }
-
- for i, r := range resourcesSpecs {
- if r.Type != v1alpha1.ResourceTypeData {
- continue
- }
-
- envName := fmt.Sprintf("CAMEL_K_RESOURCE_%03d", i)
- envvar.SetVal(environment, envName, r.Content)
-
- params := make([]string, 0)
- if r.Compression {
- params = append(params, "compression=true")
- }
-
- envValue := fmt.Sprintf("env:%s", envName)
- if len(params) > 0 {
- envValue = fmt.Sprintf("%s?%s", envValue, strings.Join(params, "&"))
- }
-
- envName = r.Name
- envName = strings.ToUpper(envName)
- envName = strings.Replace(envName, "-", "_", -1)
- envName = strings.Replace(envName, ".", "_", -1)
- envName = strings.Replace(envName, " ", "_", -1)
-
- envvar.SetVal(environment, envName, envValue)
- }
-
- return nil
-}
diff --git a/pkg/trait/knative_service_env_test.go b/pkg/trait/knative_service_env_test.go
deleted file mode 100644
index 8396aa8..0000000
--- a/pkg/trait/knative_service_env_test.go
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements. See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package trait
-
-import (
- "context"
- "testing"
-
- "github.com/scylladb/go-set/strset"
-
- "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
- "github.com/apache/camel-k/pkg/util"
- "github.com/apache/camel-k/pkg/util/envvar"
- "github.com/apache/camel-k/pkg/util/kubernetes"
- "github.com/apache/camel-k/pkg/util/test"
-
- serving "github.com/knative/serving/pkg/apis/serving/v1alpha1"
- corev1 "k8s.io/api/core/v1"
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestKnativeTraitWithCompressedSources(t *testing.T) {
- content := "H4sIAOJoQFwAA+NKK8rP1VAqzUtJLSrJL7fKKCkpsNLXN9ADQysLAwsD/YLEkgwlTS4FINAryddQz8lPt8rMS8tX1+TiAgAya2XzQAAAAA=="
-
- catalog, err := test.DefaultCatalog()
- assert.Nil(t, err)
-
- traitCatalog := NewCatalog(context.TODO(), nil)
-
- environment := Environment{
- CamelCatalog: catalog,
- Catalog: traitCatalog,
- Integration: &v1alpha1.Integration{
- ObjectMeta: metav1.ObjectMeta{
- Name: "test",
- Namespace: "ns",
- },
- Status: v1alpha1.IntegrationStatus{
- Phase: v1alpha1.IntegrationPhaseDeploying,
- },
- Spec: v1alpha1.IntegrationSpec{
- Profile: v1alpha1.TraitProfileKnative,
- Sources: []v1alpha1.SourceSpec{
- {
- DataSpec: v1alpha1.DataSpec{
- Name: "routes.js",
- Content: content,
- Compression: true,
- },
- Language: v1alpha1.LanguageJavaScript,
- },
- },
- Resources: []v1alpha1.ResourceSpec{
- {
- DataSpec: v1alpha1.DataSpec{
- Name: "my-resource.txt",
- Content: content,
- Compression: false,
- },
- Type: v1alpha1.ResourceTypeData,
- },
- {
- DataSpec: v1alpha1.DataSpec{
- Name: "my-resource.gz",
- Content: content,
- Compression: true,
- },
- Type: v1alpha1.ResourceTypeData,
- },
- },
- },
- },
- IntegrationContext: &v1alpha1.IntegrationContext{
- Status: v1alpha1.IntegrationContextStatus{
- Phase: v1alpha1.IntegrationContextPhaseReady,
- },
- },
- Platform: &v1alpha1.IntegrationPlatform{
- Spec: v1alpha1.IntegrationPlatformSpec{
- Cluster: v1alpha1.IntegrationPlatformClusterOpenShift,
- Build: v1alpha1.IntegrationPlatformBuildSpec{
- PublishStrategy: v1alpha1.IntegrationPlatformBuildPublishStrategyS2I,
- Registry: v1alpha1.IntegrationPlatformRegistrySpec{Address: "registry"},
- },
- },
- },
- EnvVars: make([]corev1.EnvVar, 0),
- ExecutedTraits: make([]Trait, 0),
- Resources: kubernetes.NewCollection(),
- Classpath: strset.New(),
- }
-
- err = traitCatalog.apply(&environment)
-
- assert.Nil(t, err)
- assert.NotEmpty(t, environment.ExecutedTraits)
- assert.NotNil(t, environment.GetTrait(ID("knative")))
- assert.NotNil(t, envvar.Get(environment.EnvVars, "CAMEL_KNATIVE_CONFIGURATION"))
-
- services := 0
- environment.Resources.VisitKnativeService(func(service *serving.Service) {
- services++
-
- vars := service.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Container.Env
-
- routes := util.LookupEnvVar(vars, "CAMEL_K_ROUTES")
- assert.NotNil(t, routes)
- assert.Equal(t, "env:CAMEL_K_ROUTE_000?name=routes.js&language=js&compression=true", routes.Value)
-
- route := util.LookupEnvVar(vars, "CAMEL_K_ROUTE_000")
- assert.NotNil(t, route)
- assert.Equal(t, content, route.Value)
-
- resource := util.LookupEnvVar(vars, "MY_RESOURCE_TXT")
- assert.NotNil(t, resource)
- assert.Equal(t, "env:CAMEL_K_RESOURCE_000", resource.Value)
-
- resource = util.LookupEnvVar(vars, "CAMEL_K_RESOURCE_000")
- assert.NotNil(t, resource)
- assert.Equal(t, content, resource.Value)
-
- resource = util.LookupEnvVar(vars, "MY_RESOURCE_GZ")
- assert.NotNil(t, resource)
- assert.Equal(t, "env:CAMEL_K_RESOURCE_001?compression=true", resource.Value)
-
- resource = util.LookupEnvVar(vars, "CAMEL_K_RESOURCE_001")
- assert.NotNil(t, resource)
- assert.Equal(t, content, resource.Value)
-
- resource = util.LookupEnvVar(vars, "JAVA_CLASSPATH")
- assert.NotNil(t, resource)
- })
-
- assert.True(t, services > 0)
- assert.True(t, environment.Resources.Size() > 0)
-}
-
-func TestKnativeTraitWithConfigMapSources(t *testing.T) {
- content := "H4sIAOJoQFwAA+NKK8rP1VAqzUtJLSrJL7fKKCkpsNLXN9ADQysLAwsD/YLEkgwlTS4FINAryddQz8lPt8rMS8tX1+TiAgAya2XzQAAAAA=="
-
- catalog, err := test.DefaultCatalog()
- assert.Nil(t, err)
-
- traitCatalog := NewCatalog(context.TODO(), nil)
-
- environment := Environment{
- CamelCatalog: catalog,
- Catalog: traitCatalog,
- Integration: &v1alpha1.Integration{
- ObjectMeta: metav1.ObjectMeta{
- Name: "test",
- Namespace: "ns",
- },
- Status: v1alpha1.IntegrationStatus{
- Phase: v1alpha1.IntegrationPhaseDeploying,
- },
- Spec: v1alpha1.IntegrationSpec{
- Profile: v1alpha1.TraitProfileKnative,
- Sources: []v1alpha1.SourceSpec{
- {
- DataSpec: v1alpha1.DataSpec{
- Name: "routes.js",
- ContentRef: "my-cm",
- Compression: true,
- },
- Language: v1alpha1.LanguageJavaScript,
- },
- },
- },
- },
- IntegrationContext: &v1alpha1.IntegrationContext{
- Status: v1alpha1.IntegrationContextStatus{
- Phase: v1alpha1.IntegrationContextPhaseReady,
- },
- },
- Platform: &v1alpha1.IntegrationPlatform{
- Spec: v1alpha1.IntegrationPlatformSpec{
- Cluster: v1alpha1.IntegrationPlatformClusterOpenShift,
- Build: v1alpha1.IntegrationPlatformBuildSpec{
- PublishStrategy: v1alpha1.IntegrationPlatformBuildPublishStrategyS2I,
- Registry: v1alpha1.IntegrationPlatformRegistrySpec{Address: "registry"},
- },
- },
- },
- EnvVars: make([]corev1.EnvVar, 0),
- ExecutedTraits: make([]Trait, 0),
- Resources: kubernetes.NewCollection(&corev1.ConfigMap{
- TypeMeta: metav1.TypeMeta{
- Kind: "ConfigMap",
- APIVersion: "v1",
- },
- ObjectMeta: metav1.ObjectMeta{
- Name: "my-cm",
- Namespace: "ns",
- },
- Data: map[string]string{
- "content": content,
- },
- }),
- Classpath: strset.New(),
- }
-
- err = traitCatalog.apply(&environment)
-
- assert.Nil(t, err)
- assert.NotEmpty(t, environment.ExecutedTraits)
- assert.NotNil(t, environment.GetTrait(ID("knative")))
- assert.NotNil(t, envvar.Get(environment.EnvVars, "CAMEL_KNATIVE_CONFIGURATION"))
-
- services := 0
- environment.Resources.VisitKnativeService(func(service *serving.Service) {
- services++
-
- vars := service.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Container.Env
-
- routes := util.LookupEnvVar(vars, "CAMEL_K_ROUTES")
- assert.NotNil(t, routes)
- assert.Equal(t, "env:CAMEL_K_ROUTE_000?name=routes.js&language=js&compression=true", routes.Value)
-
- route := util.LookupEnvVar(vars, "CAMEL_K_ROUTE_000")
- assert.NotNil(t, route)
- assert.Equal(t, content, route.Value)
-
- resource := util.LookupEnvVar(vars, "JAVA_CLASSPATH")
- assert.NotNil(t, resource)
- })
-
- assert.True(t, services > 0)
- assert.True(t, environment.Resources.Size() > 0)
-}
diff --git a/pkg/trait/knative_service_vol_test.go b/pkg/trait/knative_service_test.go
similarity index 98%
rename from pkg/trait/knative_service_vol_test.go
rename to pkg/trait/knative_service_test.go
index 81cf388..4a33982 100644
--- a/pkg/trait/knative_service_vol_test.go
+++ b/pkg/trait/knative_service_test.go
@@ -35,7 +35,7 @@ import (
"github.com/stretchr/testify/assert"
)
-func TestKnativeWithVolumeBinding(t *testing.T) {
+func TestKnativeService(t *testing.T) {
catalog, err := test.DefaultCatalog()
assert.Nil(t, err)
@@ -82,7 +82,7 @@ func TestKnativeWithVolumeBinding(t *testing.T) {
Traits: map[string]v1alpha1.TraitSpec{
"knative-service": {
Configuration: map[string]string{
- "configuration-type": "volume",
+ "enabled": "true",
},
},
},
diff --git a/pkg/trait/knative_service_vol.go b/pkg/trait/knative_service_vol.go
deleted file mode 100644
index 03c95bb..0000000
--- a/pkg/trait/knative_service_vol.go
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements. See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package trait
-
-import (
- "strings"
-
- "github.com/apache/camel-k/pkg/util/envvar"
- serving "github.com/knative/serving/pkg/apis/serving/v1alpha1"
-)
-
-func (t *knativeServiceTrait) bindToVolumes(e *Environment, service *serving.Service) {
- e.ConfigureVolumesAndMounts(
- &service.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Volumes,
- &service.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Container.VolumeMounts,
- )
-
- paths := e.ComputeSourcesURI()
- environment := &service.Spec.RunLatest.Configuration.RevisionTemplate.Spec.Container.Env
-
- envvar.SetVal(environment, "CAMEL_K_ROUTES", strings.Join(paths, ","))
- envvar.SetVal(environment, "CAMEL_K_CONF", "/etc/camel/conf/application.properties")
- envvar.SetVal(environment, "CAMEL_K_CONF_D", "/etc/camel/conf.d")
-}