This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new a9ff49a feat: Add progress-deadline-seconds option to deployment trait
a9ff49a is described below
commit a9ff49a3e19bee6f6e82afff4a3cfc0bcb2b956f
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Tue Oct 5 10:09:34 2021 +0200
feat: Add progress-deadline-seconds option to deployment trait
---
docs/modules/traits/pages/deployment.adoc | 7 ++++++-
pkg/resources/resources.go | 4 ++--
pkg/trait/deployment.go | 11 ++++++++++-
pkg/trait/deployment_test.go | 27 ++++++++++++++++++++++-----
resources/traits.yaml | 10 +++++++++-
5 files changed, 49 insertions(+), 10 deletions(-)
diff --git a/docs/modules/traits/pages/deployment.adoc
b/docs/modules/traits/pages/deployment.adoc
index de6f174..6f1a0a7 100755
--- a/docs/modules/traits/pages/deployment.adoc
+++ b/docs/modules/traits/pages/deployment.adoc
@@ -16,7 +16,7 @@ WARNING: The deployment trait is a *platform trait*:
disabling it may compromise
Trait properties can be specified when running any integration with the CLI:
[source,console]
----
-$ kamel run --trait deployment.[key]=[value] integration.groovy
+$ kamel run --trait deployment.[key]=[value] --trait
deployment.[key2]=[value2] integration.groovy
----
The following configuration options are available:
@@ -28,6 +28,11 @@ The following configuration options are available:
| bool
| Can be used to enable or disable a trait. All traits share this common
property.
+| deployment.progress-deadline-seconds
+| int32
+| The maximum time in seconds for the deployment to make progress before it
+is considered to be failed. It defaults to 60s.
+
|===
// End of autogenerated code - DO NOT EDIT! (configuration)
diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
index 0564232..9b3f99a 100644
--- a/pkg/resources/resources.go
+++ b/pkg/resources/resources.go
@@ -539,9 +539,9 @@ var assets = func() http.FileSystem {
"/traits.yaml": &vfsgen۰CompressedFileInfo{
name: "traits.yaml",
modTime: time.Time{},
- uncompressedSize: 43087,
+ uncompressedSize: 43417,
- compressedContent:
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7d\x73\x1b\x37\xd2\x20\xfe\xbf\x3f\x05\x8a\xcf\xaf\xca\x92\x8a\xa4\x9c\xdd\x67\x77\xf3\xd3\x9d\x6f\x4b\xb1\x9d\x44\x89\x5f\x74\xb6\x93\xbd\x2d\x5f\x6a\x09\xce\x34\x49\x58\x33\xc0\x2c\x80\x91\xcc\xbd\xe7\xbe\xfb\x15\xba\x1b\x2f\x43\x52\x12\xe5\x58\xb9\xe8\xea\xd9\xfd\x23\x96\x34\x00\x1a\x8d\x46\xbf\x77\xc3\x5b\xa9\xbc\x3b\x79\x34\x11\x5a\xb6\x70\x22\xe4\x62\xa1\xb4\xf2\xeb\x47\x42\x74\x8d\xf4\x0b\x63\xdb\x13\x
[...]
+ compressedContent:
[]byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7d\x73\x1c\xb7\xd1\x20\xfe\xbf\x3e\x05\x6a\x9f\x5f\x95\x48\xd6\xee\x92\x4e\x9e\x24\xfe\xf1\x4e\x97\xa2\x25\x39\xa1\xad\x17\x9e\x24\x3b\x97\xf2\xb9\xb2\xd8\x99\xde\x5d\x88\x33\xc0\x04\xc0\x90\xda\xdc\x73\xdf\xfd\x0a\xdd\x8d\x97\xd9\x5d\x92\x4b\x59\xf4\x99\x57\x4f\xf2\x87\x45\x72\x00\x34\x1a\x8d\x7e\xef\x86\xb7\x52\x79\x77\xfa\x64\x22\xb4\x6c\xe1\x54\xc8\xc5\x42\x69\xe5\xd7\x4f\x84\xe8\x1a\xe9\x17\xc6\xb6\xa7\x
[...]
},
}
fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{
diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index 2460a5c..283c783 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -34,6 +34,9 @@ import (
// +camel-k:trait=deployment
type deploymentTrait struct {
BaseTrait `property:",squash"`
+ // The maximum time in seconds for the deployment to make progress
before it
+ // is considered to be failed. It defaults to 60s.
+ ProgressDeadlineSeconds *int32 `property:"progress-deadline-seconds"
json:"progressDeadlineSeconds,omitempty"`
}
var _ ControllerStrategySelector = &deploymentTrait{}
@@ -126,6 +129,11 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment)
*appsv1.Deployment {
}
}
+ deadline := int32(60)
+ if t.ProgressDeadlineSeconds != nil {
+ deadline = *t.ProgressDeadlineSeconds
+ }
+
deployment := appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
@@ -140,7 +148,8 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment)
*appsv1.Deployment {
Annotations: annotations,
},
Spec: appsv1.DeploymentSpec{
- Replicas: e.Integration.Spec.Replicas,
+ ProgressDeadlineSeconds: &deadline,
+ Replicas: e.Integration.Spec.Replicas,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
v1.IntegrationLabel: e.Integration.Name,
diff --git a/pkg/trait/deployment_test.go b/pkg/trait/deployment_test.go
index efc8456..3e80fb7 100644
--- a/pkg/trait/deployment_test.go
+++ b/pkg/trait/deployment_test.go
@@ -20,15 +20,15 @@ package trait
import (
"testing"
- v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
- "github.com/apache/camel-k/pkg/util/kubernetes"
- "github.com/apache/camel-k/pkg/util/test"
-
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+ v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+ "github.com/apache/camel-k/pkg/util/kubernetes"
+ "github.com/apache/camel-k/pkg/util/test"
)
func TestConfigureDisabledDeploymentTraitDoesNotSucceed(t *testing.T) {
@@ -44,7 +44,7 @@ func TestConfigureDisabledDeploymentTraitDoesNotSucceed(t
*testing.T) {
assert.Equal(t, "explicitly disabled", conditions[0].Message)
}
-func TestConfigureDeploymentTraitWhileIntegrationIsRuningDoesSucceed(t
*testing.T) {
+func TestConfigureDeploymentTraitWhileIntegrationIsRunningDoesSucceed(t
*testing.T) {
deploymentTrait, environment := createNominalDeploymentTest()
environment.Integration.Status.SetCondition(
v1.IntegrationConditionDeploymentAvailable,
@@ -127,6 +127,23 @@ func
TestApplyDeploymentTraitWhileRunningIntegrationDoesSucceed(t *testing.T) {
assert.NotNil(t, deployment)
assert.Equal(t, "integration-name", deployment.Name)
assert.Equal(t, int32(3), *deployment.Spec.Replicas)
+ assert.Equal(t, int32(60), *deployment.Spec.ProgressDeadlineSeconds)
+}
+
+func TestApplyDeploymentTraitWithProgressDeadline(t *testing.T) {
+ deploymentTrait, environment := createNominalDeploymentTest()
+ progressDeadlineSeconds := int32(120)
+ deploymentTrait.ProgressDeadlineSeconds = &progressDeadlineSeconds
+ environment.Integration.Status.Phase = v1.IntegrationPhaseRunning
+
+ err := deploymentTrait.Apply(environment)
+
+ assert.Nil(t, err)
+
+ deployment := environment.Resources.GetDeployment(func(deployment
*appsv1.Deployment) bool { return true })
+ assert.NotNil(t, deployment)
+ assert.Equal(t, "integration-name", deployment.Name)
+ assert.Equal(t, int32(120), *deployment.Spec.ProgressDeadlineSeconds)
}
func createNominalDeploymentTest() (*deploymentTrait, *Environment) {
diff --git a/resources/traits.yaml b/resources/traits.yaml
index 4d0357b..f089928 100755
--- a/resources/traits.yaml
+++ b/resources/traits.yaml
@@ -273,7 +273,15 @@ traits:
- OpenShift
description: The Deployment trait is responsible for generating the
Kubernetes deployment
that will make sure the integration will run in the cluster.
- properties: []
+ properties:
+ - name: enabled
+ type: bool
+ description: Can be used to enable or disable a trait. All traits share
this common
+ property.
+ - name: progress-deadline-seconds
+ type: int32
+ description: The maximum time in seconds for the deployment to make
progress before
+ itis considered to be failed. It defaults to 60s.
- name: environment
platform: true
profiles: