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/06/26 09:51:14 UTC
[camel-k] branch master updated (c16ed2c -> c17f0be)
This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git.
from c16ed2c chore: cleanup build
new 5f469ca Add timeout to maven operations #761
new c780221 Add timeout to maven operations #761 (fix findings)
new c17f0be Add timeout to maven operations #761 (add tests)
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
Gopkg.lock | 1 +
pkg/apis/camel/v1alpha1/common_types.go | 3 +-
pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go | 1 +
pkg/builder/builder_steps.go | 6 +-
pkg/builder/builder_types.go | 1 -
pkg/controller/integrationplatform/initialize.go | 33 ++++-
.../integrationplatform/initialize_test.go | 149 +++++++++++++++++++++
pkg/trait/camel.go | 5 +-
pkg/trait/rest-dsl.go | 5 +-
pkg/util/maven/maven.go | 48 ++++---
pkg/util/maven/maven_types.go | 6 +-
11 files changed, 223 insertions(+), 35 deletions(-)
create mode 100644 pkg/controller/integrationplatform/initialize_test.go
[camel-k] 02/03: Add timeout to maven operations #761 (fix findings)
Posted by nf...@apache.org.
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
commit c780221021798005af03797d903cddfefcac2970
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Tue Jun 25 17:24:22 2019 +0200
Add timeout to maven operations #761 (fix findings)
---
pkg/controller/integrationplatform/initialize.go | 27 +++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/pkg/controller/integrationplatform/initialize.go b/pkg/controller/integrationplatform/initialize.go
index 64eeb93..2fc150b 100644
--- a/pkg/controller/integrationplatform/initialize.go
+++ b/pkg/controller/integrationplatform/initialize.go
@@ -126,14 +126,35 @@ func (action *initializeAction) Handle(ctx context.Context, ip *v1alpha1.Integra
if target.Spec.Build.LocalRepository == "" {
target.Spec.Build.LocalRepository = defaults.LocalRepository
}
+ if target.Spec.Build.PersistentVolumeClaim == "" {
+ target.Spec.Build.PersistentVolumeClaim = target.Name
+ }
+
+ if target.Spec.Build.Timeout.Duration != 0 {
+ d := target.Spec.Build.Timeout.Duration.Truncate(time.Second)
+
+ if target.Spec.Build.Timeout.Duration != d {
+ action.L.Infof("Build timeout minimum unit is sec (configured: %s, truncated: %s)", target.Spec.Build.Timeout.Duration, d)
+ }
+
+ target.Spec.Build.Timeout.Duration = d
+ }
if target.Spec.Build.Timeout.Duration == 0 {
target.Spec.Build.Timeout.Duration = 5 * time.Minute
}
- if target.Spec.Build.PersistentVolumeClaim == "" {
- target.Spec.Build.PersistentVolumeClaim = target.Name
+
+ if target.Spec.Build.Maven.Timeout.Duration != 0 {
+ d := target.Spec.Build.Maven.Timeout.Duration.Truncate(time.Second)
+
+ if target.Spec.Build.Maven.Timeout.Duration != d {
+ action.L.Infof("Maven timeout minimum unit is sec (configured: %s, truncated: %s)", target.Spec.Build.Maven.Timeout.Duration, d)
+ }
+
+ target.Spec.Build.Maven.Timeout.Duration = d
}
if target.Spec.Build.Maven.Timeout.Duration == 0 {
- target.Spec.Build.Maven.Timeout.Duration = 2 * time.Minute
+ n := target.Spec.Build.Timeout.Duration.Seconds() * 0.75
+ target.Spec.Build.Maven.Timeout.Duration = (time.Duration(n) * time.Second).Truncate(time.Second)
}
action.L.Infof("CamelVersion set to %s", target.Spec.Build.CamelVersion)
[camel-k] 03/03: Add timeout to maven operations #761 (add tests)
Posted by nf...@apache.org.
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
commit c17f0be7281191b6ccd7cd5f93a6b2dcd00dcd66
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Tue Jun 25 18:16:00 2019 +0200
Add timeout to maven operations #761 (add tests)
---
.../integrationplatform/initialize_test.go | 149 +++++++++++++++++++++
1 file changed, 149 insertions(+)
diff --git a/pkg/controller/integrationplatform/initialize_test.go b/pkg/controller/integrationplatform/initialize_test.go
new file mode 100644
index 0000000..8260f3a
--- /dev/null
+++ b/pkg/controller/integrationplatform/initialize_test.go
@@ -0,0 +1,149 @@
+/*
+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 integrationplatform
+
+import (
+ "context"
+ "testing"
+ "time"
+
+ "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+ "github.com/apache/camel-k/pkg/util/log"
+ "github.com/apache/camel-k/pkg/util/test"
+ "github.com/stretchr/testify/assert"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+ k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
+)
+
+func TestTimeouts_Default(t *testing.T) {
+ ip := v1alpha1.IntegrationPlatform{}
+ ip.Namespace = "ns"
+ ip.Name = "camel-k"
+ ip.Spec.Cluster = v1alpha1.IntegrationPlatformClusterOpenShift
+
+ c, err := test.NewFakeClient(&ip)
+ assert.Nil(t, err)
+
+ h := NewInitializeAction()
+ h.InjectLogger(log.Log)
+ h.InjectClient(c)
+
+ err = h.Handle(context.TODO(), &ip)
+ assert.Nil(t, err)
+
+ key := k8sclient.ObjectKey{
+ Name: ip.Name,
+ Namespace: ip.Namespace,
+ }
+
+ answer := v1alpha1.NewIntegrationPlatform(ip.Name, ip.Namespace)
+
+ err = c.Get(context.TODO(), key, &answer)
+ assert.Nil(t, err)
+
+ n := answer.Spec.Build.Timeout.Duration.Seconds() * 0.75
+ d := (time.Duration(n) * time.Second).Truncate(time.Second)
+
+ assert.Equal(t, d, answer.Spec.Build.Maven.Timeout.Duration)
+ assert.Equal(t, 5*time.Minute, answer.Spec.Build.Timeout.Duration)
+}
+
+func TestTimeouts_MavenComputedFromBuild(t *testing.T) {
+ ip := v1alpha1.IntegrationPlatform{}
+ ip.Namespace = "ns"
+ ip.Name = "camel-k"
+ ip.Spec.Cluster = v1alpha1.IntegrationPlatformClusterOpenShift
+
+ timeout, err := time.ParseDuration("1m1ms")
+ assert.Nil(t, err)
+
+ ip.Spec.Build.Timeout = metav1.Duration{
+ Duration: timeout,
+ }
+
+ c, err := test.NewFakeClient(&ip)
+ assert.Nil(t, err)
+
+ h := NewInitializeAction()
+ h.InjectLogger(log.Log)
+ h.InjectClient(c)
+
+ err = h.Handle(context.TODO(), &ip)
+ assert.Nil(t, err)
+
+ key := k8sclient.ObjectKey{
+ Name: ip.Name,
+ Namespace: ip.Namespace,
+ }
+
+ answer := v1alpha1.NewIntegrationPlatform(ip.Name, ip.Namespace)
+
+ err = c.Get(context.TODO(), key, &answer)
+ assert.Nil(t, err)
+
+ n := answer.Spec.Build.Timeout.Duration.Seconds() * 0.75
+ d := (time.Duration(n) * time.Second).Truncate(time.Second)
+
+ assert.Equal(t, d, answer.Spec.Build.Maven.Timeout.Duration)
+ assert.Equal(t, 1*time.Minute, answer.Spec.Build.Timeout.Duration)
+}
+
+func TestTimeouts_Truncated(t *testing.T) {
+ ip := v1alpha1.IntegrationPlatform{}
+ ip.Namespace = "ns"
+ ip.Name = "camel-k"
+ ip.Spec.Cluster = v1alpha1.IntegrationPlatformClusterOpenShift
+
+ bt, err := time.ParseDuration("5m1ms")
+ assert.Nil(t, err)
+
+ ip.Spec.Build.Timeout = metav1.Duration{
+ Duration: bt,
+ }
+
+ mt, err := time.ParseDuration("2m1ms")
+ assert.Nil(t, err)
+
+ ip.Spec.Build.Maven.Timeout = metav1.Duration{
+ Duration: mt,
+ }
+
+ c, err := test.NewFakeClient(&ip)
+ assert.Nil(t, err)
+
+ h := NewInitializeAction()
+ h.InjectLogger(log.Log)
+ h.InjectClient(c)
+
+ err = h.Handle(context.TODO(), &ip)
+ assert.Nil(t, err)
+
+ key := k8sclient.ObjectKey{
+ Name: ip.Name,
+ Namespace: ip.Namespace,
+ }
+
+ answer := v1alpha1.NewIntegrationPlatform(ip.Name, ip.Namespace)
+
+ err = c.Get(context.TODO(), key, &answer)
+ assert.Nil(t, err)
+
+ assert.Equal(t, time.Duration(2*time.Minute), answer.Spec.Build.Maven.Timeout.Duration)
+ assert.Equal(t, time.Duration(5*time.Minute), answer.Spec.Build.Timeout.Duration)
+}
[camel-k] 01/03: Add timeout to maven operations #761
Posted by nf...@apache.org.
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
commit 5f469ca3c809f22c3426618b63181ffa91ccc4b2
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Fri Jun 21 14:11:21 2019 +0200
Add timeout to maven operations #761
---
Gopkg.lock | 1 +
pkg/apis/camel/v1alpha1/common_types.go | 3 +-
pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go | 1 +
pkg/builder/builder_steps.go | 6 +--
pkg/builder/builder_types.go | 1 -
pkg/controller/integrationplatform/initialize.go | 8 ++++
pkg/trait/camel.go | 5 ++-
pkg/trait/rest-dsl.go | 5 ++-
pkg/util/maven/maven.go | 48 +++++++++++++-----------
pkg/util/maven/maven_types.go | 6 ++-
10 files changed, 51 insertions(+), 33 deletions(-)
diff --git a/Gopkg.lock b/Gopkg.lock
index f5f1eac..4e74fdb 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -1173,6 +1173,7 @@
"k8s.io/api/core/v1",
"k8s.io/api/extensions/v1beta1",
"k8s.io/api/rbac/v1",
+ "k8s.io/api/rbac/v1beta1",
"k8s.io/apimachinery/pkg/api/errors",
"k8s.io/apimachinery/pkg/api/meta",
"k8s.io/apimachinery/pkg/api/resource",
diff --git a/pkg/apis/camel/v1alpha1/common_types.go b/pkg/apis/camel/v1alpha1/common_types.go
index 4a927dd..00a45d1 100644
--- a/pkg/apis/camel/v1alpha1/common_types.go
+++ b/pkg/apis/camel/v1alpha1/common_types.go
@@ -75,7 +75,8 @@ type Configurable interface {
// MavenSpec --
type MavenSpec struct {
- Settings ValueSource `json:"settings,omitempty"`
+ Settings ValueSource `json:"settings,omitempty"`
+ Timeout metav1.Duration `json:"timeout,omitempty"`
}
// ValueSource --
diff --git a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
index 60e0f48..a0f5962 100644
--- a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
@@ -902,6 +902,7 @@ func (in *IntegrationStatus) DeepCopy() *IntegrationStatus {
func (in *MavenSpec) DeepCopyInto(out *MavenSpec) {
*out = *in
in.Settings.DeepCopyInto(&out.Settings)
+ out.Timeout = in.Timeout
return
}
diff --git a/pkg/builder/builder_steps.go b/pkg/builder/builder_steps.go
index 32d0890..1d3499a 100644
--- a/pkg/builder/builder_steps.go
+++ b/pkg/builder/builder_steps.go
@@ -264,9 +264,9 @@ func sanitizeDependencies(ctx *Context) error {
func computeDependencies(ctx *Context) error {
mc := maven.NewContext(path.Join(ctx.Path, "maven"), ctx.Maven.Project)
- mc.Settings = ctx.Maven.Settings
- mc.SettingsData = ctx.Maven.SettingsData
- mc.AddArguments(maven.ExtraOptions(ctx.Build.Platform.Build.LocalRepository)...)
+ mc.SettingsContent = ctx.Maven.SettingsData
+ mc.LocalRepository = ctx.Build.Platform.Build.LocalRepository
+ mc.Timeout = ctx.Build.Platform.Build.Maven.Timeout.Duration
mc.AddArgumentf("org.apache.camel.k:camel-k-maven-plugin:%s:generate-dependency-list", ctx.Build.RuntimeVersion)
if err := maven.Run(mc); err != nil {
diff --git a/pkg/builder/builder_types.go b/pkg/builder/builder_types.go
index 1ad1a19..7574b07 100644
--- a/pkg/builder/builder_types.go
+++ b/pkg/builder/builder_types.go
@@ -115,7 +115,6 @@ type Context struct {
Maven struct {
Project maven.Project
- Settings *maven.Settings
SettingsData []byte
}
}
diff --git a/pkg/controller/integrationplatform/initialize.go b/pkg/controller/integrationplatform/initialize.go
index 6976165..64eeb93 100644
--- a/pkg/controller/integrationplatform/initialize.go
+++ b/pkg/controller/integrationplatform/initialize.go
@@ -132,12 +132,20 @@ func (action *initializeAction) Handle(ctx context.Context, ip *v1alpha1.Integra
if target.Spec.Build.PersistentVolumeClaim == "" {
target.Spec.Build.PersistentVolumeClaim = target.Name
}
+ if target.Spec.Build.Maven.Timeout.Duration == 0 {
+ target.Spec.Build.Maven.Timeout.Duration = 2 * time.Minute
+ }
action.L.Infof("CamelVersion set to %s", target.Spec.Build.CamelVersion)
action.L.Infof("RuntimeVersion set to %s", target.Spec.Build.RuntimeVersion)
action.L.Infof("BaseImage set to %s", target.Spec.Build.BaseImage)
action.L.Infof("LocalRepository set to %s", target.Spec.Build.LocalRepository)
action.L.Infof("Timeout set to %s", target.Spec.Build.Timeout)
+ action.L.Infof("Maven Timeout set to %s", target.Spec.Build.Maven.Timeout.Duration)
+
+ if target.Spec.Build.Maven.Timeout.Duration != 0 {
+ action.L.Infof("Maven Timeout set to %s", target.Spec.Build.Maven.Timeout.Duration)
+ }
err = action.client.Update(ctx, target)
if err != nil {
diff --git a/pkg/trait/camel.go b/pkg/trait/camel.go
index f5564e9..03e0b25 100644
--- a/pkg/trait/camel.go
+++ b/pkg/trait/camel.go
@@ -142,7 +142,8 @@ func (t *camelTrait) GenerateCatalog(e *Environment, version string) (*camel.Run
}
mc := maven.NewContext(tmpDir, project)
- mc.AddArguments(maven.ExtraOptions(e.Platform.Spec.Build.LocalRepository)...)
+ mc.LocalRepository = e.Platform.Spec.Build.LocalRepository
+ mc.Timeout = e.Platform.Spec.Build.Maven.Timeout.Duration
mc.AddSystemProperty("catalog.path", tmpDir)
mc.AddSystemProperty("catalog.file", "catalog.yaml")
@@ -156,7 +157,7 @@ func (t *camelTrait) GenerateCatalog(e *Environment, version string) (*camel.Run
return nil, err
}
if settings != "" {
- mc.SettingsData = []byte(settings)
+ mc.SettingsContent = []byte(settings)
}
err = maven.Run(mc)
diff --git a/pkg/trait/rest-dsl.go b/pkg/trait/rest-dsl.go
index 6e9778d..ab1789d 100644
--- a/pkg/trait/rest-dsl.go
+++ b/pkg/trait/rest-dsl.go
@@ -113,7 +113,8 @@ func (t *restDslTrait) Apply(e *Environment) error {
}
mc := maven.NewContext(tmpDir, project)
- mc.AddArguments(maven.ExtraOptions(e.Platform.Spec.Build.LocalRepository)...)
+ mc.LocalRepository = e.Platform.Spec.Build.LocalRepository
+ mc.Timeout = e.Platform.Spec.Build.Maven.Timeout.Duration
mc.AddArgument("-Dopenapi.spec=" + in)
mc.AddArgument("-Ddsl.out=" + out)
@@ -122,7 +123,7 @@ func (t *restDslTrait) Apply(e *Environment) error {
return err
}
if settings != "" {
- mc.SettingsData = []byte(settings)
+ mc.SettingsContent = []byte(settings)
}
err = maven.Run(mc)
diff --git a/pkg/util/maven/maven.go b/pkg/util/maven/maven.go
index 3e28d18..757df37 100644
--- a/pkg/util/maven/maven.go
+++ b/pkg/util/maven/maven.go
@@ -18,9 +18,11 @@ limitations under the License.
package maven
import (
+ "context"
"fmt"
"io"
"io/ioutil"
+ "math"
"os"
"os/exec"
"path"
@@ -42,12 +44,8 @@ func GenerateProjectStructure(context Context) error {
return err
}
- if context.SettingsData != nil {
- if err := util.WriteFileWithContent(context.Path, "settings.xml", context.SettingsData); err != nil {
- return err
- }
- } else if context.Settings != nil {
- if err := util.WriteFileWithBytesMarshallerContent(context.Path, "settings.xml", context.Settings); err != nil {
+ if context.SettingsContent != nil {
+ if err := util.WriteFileWithContent(context.Path, "settings.xml", context.SettingsContent); err != nil {
return err
}
}
@@ -81,8 +79,8 @@ func GenerateProjectStructure(context Context) error {
}
// Run --
-func Run(context Context) error {
- if err := GenerateProjectStructure(context); err != nil {
+func Run(ctx Context) error {
+ if err := GenerateProjectStructure(ctx); err != nil {
return err
}
@@ -91,9 +89,15 @@ func Run(context Context) error {
mvnCmd = c
}
- args := append(context.AdditionalArguments, "--batch-mode")
+ args := append(ctx.AdditionalArguments, "--batch-mode")
+
+ if ctx.LocalRepository == "" {
+ args = append(ctx.AdditionalArguments, "-Dcamel.noop=true")
+ } else if _, err := os.Stat(ctx.LocalRepository); err == nil {
+ args = append(ctx.AdditionalArguments, "-Dmaven.repo.local="+ctx.LocalRepository)
+ }
- settingsPath := path.Join(context.Path, "settings.xml")
+ settingsPath := path.Join(ctx.Path, "settings.xml")
settingsExists, err := util.FileExists(settingsPath)
if err != nil {
return err
@@ -103,12 +107,20 @@ func Run(context Context) error {
args = append(args, "--settings", settingsPath)
}
- cmd := exec.Command(mvnCmd, args...)
- cmd.Dir = context.Path
- cmd.Stdout = os.Stdout
+ timeout := ctx.Timeout
+ if timeout == 0 {
+ timeout = math.MaxInt64
+ }
+
+ c, cancel := context.WithTimeout(context.Background(), timeout)
+ defer cancel()
+
+ cmd := exec.CommandContext(c, mvnCmd, args...)
+ cmd.Dir = ctx.Path
cmd.Stderr = os.Stderr
+ cmd.Stdout = os.Stdout
- Log.Infof("execute: %s", strings.Join(cmd.Args, " "))
+ Log.WithValues("timeout", timeout.String()).Infof("executing: %s", strings.Join(cmd.Args, " "))
return cmd.Run()
}
@@ -150,11 +162,3 @@ func ParseGAV(gav string) (Dependency, error) {
return dep, nil
}
-
-// ExtraOptions --
-func ExtraOptions(localRepo string) []string {
- if _, err := os.Stat(localRepo); err == nil {
- return []string{"-Dmaven.repo.local=" + localRepo}
- }
- return []string{"-Dcamel.noop=true"}
-}
diff --git a/pkg/util/maven/maven_types.go b/pkg/util/maven/maven_types.go
index c292b13..26e5b3c 100644
--- a/pkg/util/maven/maven_types.go
+++ b/pkg/util/maven/maven_types.go
@@ -21,6 +21,7 @@ import (
"bytes"
"encoding/xml"
"fmt"
+ "time"
)
// Repository --
@@ -102,10 +103,11 @@ func NewContext(buildDir string, project Project) Context {
type Context struct {
Path string
Project Project
- Settings *Settings
- SettingsData []byte
+ SettingsContent []byte
AdditionalArguments []string
AdditionalEntries map[string]interface{}
+ Timeout time.Duration
+ LocalRepository string
}
// AddEntry --