From d74c2d9478d17d84a693b14588659ee54349ee9b Mon Sep 17 00:00:00 2001 From: Luis Sergio Carneiro Date: Wed, 6 Mar 2024 11:37:45 -0300 Subject: [PATCH] fix(trait): changing data type for rollingUpdateMaxSurge and rollingUpdateMaxUnavailable to strings are also supported --- .../ROOT/partials/apis/camel-k-crds.adoc | 4 +- docs/modules/traits/pages/deployment.adoc | 4 +- .../crds/crd-integration-platform.yaml | 20 +++++++-- .../camel-k/crds/crd-integration-profile.yaml | 20 +++++++-- helm/camel-k/crds/crd-integration.yaml | 10 ++++- helm/camel-k/crds/crd-kamelet-binding.yaml | 10 ++++- helm/camel-k/crds/crd-pipe.yaml | 10 ++++- pkg/apis/camel/v1/trait/deployment.go | 5 ++- .../camel/v1/trait/zz_generated.deepcopy.go | 5 ++- ...camel.apache.org_integrationplatforms.yaml | 20 +++++++-- .../camel.apache.org_integrationprofiles.yaml | 20 +++++++-- .../bases/camel.apache.org_integrations.yaml | 10 ++++- .../camel.apache.org_kameletbindings.yaml | 10 ++++- .../crd/bases/camel.apache.org_pipes.yaml | 10 ++++- pkg/trait/deployment.go | 8 ++-- pkg/trait/deployment_test.go | 41 +++++++++++++++---- 16 files changed, 160 insertions(+), 47 deletions(-) diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc index c90e8e44dc..b81ddd8514 100644 --- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc @@ -6682,7 +6682,7 @@ is considered to be failed. It defaults to `60s`. The deployment strategy to use to replace existing pods with new ones. |`rollingUpdateMaxUnavailable` + -int +k8s.io/apimachinery/pkg/util/intstr.IntOrString | @@ -6693,7 +6693,7 @@ This can not be 0 if MaxSurge is 0. Defaults to `25%`. |`rollingUpdateMaxSurge` + -int +k8s.io/apimachinery/pkg/util/intstr.IntOrString | diff --git a/docs/modules/traits/pages/deployment.adoc b/docs/modules/traits/pages/deployment.adoc index fbae7fc2e3..b7177b3998 100755 --- a/docs/modules/traits/pages/deployment.adoc +++ b/docs/modules/traits/pages/deployment.adoc @@ -38,7 +38,7 @@ is considered to be failed. It defaults to `60s`. | The deployment strategy to use to replace existing pods with new ones. | deployment.rolling-update-max-unavailable -| int +| k8s.io/apimachinery/pkg/util/intstr.IntOrString | The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. @@ -46,7 +46,7 @@ This can not be 0 if MaxSurge is 0. Defaults to `25%`. | deployment.rolling-update-max-surge -| int +| k8s.io/apimachinery/pkg/util/intstr.IntOrString | The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml index 8f6e433503..267189ab88 100644 --- a/helm/camel-k/crds/crd-integration-platform.yaml +++ b/helm/camel-k/crds/crd-integration-platform.yaml @@ -852,20 +852,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. @@ -2736,20 +2742,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. diff --git a/helm/camel-k/crds/crd-integration-profile.yaml b/helm/camel-k/crds/crd-integration-profile.yaml index c8c45ffc5c..51bf3e2c1f 100644 --- a/helm/camel-k/crds/crd-integration-profile.yaml +++ b/helm/camel-k/crds/crd-integration-profile.yaml @@ -734,20 +734,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. @@ -2507,20 +2513,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. diff --git a/helm/camel-k/crds/crd-integration.yaml b/helm/camel-k/crds/crd-integration.yaml index 000da77f6f..0bfd409d7f 100644 --- a/helm/camel-k/crds/crd-integration.yaml +++ b/helm/camel-k/crds/crd-integration.yaml @@ -6753,20 +6753,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml b/helm/camel-k/crds/crd-kamelet-binding.yaml index 71665f1c55..5a4e27d493 100644 --- a/helm/camel-k/crds/crd-kamelet-binding.yaml +++ b/helm/camel-k/crds/crd-kamelet-binding.yaml @@ -7040,20 +7040,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. diff --git a/helm/camel-k/crds/crd-pipe.yaml b/helm/camel-k/crds/crd-pipe.yaml index 64d017136d..a89c4b05da 100644 --- a/helm/camel-k/crds/crd-pipe.yaml +++ b/helm/camel-k/crds/crd-pipe.yaml @@ -7038,20 +7038,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. diff --git a/pkg/apis/camel/v1/trait/deployment.go b/pkg/apis/camel/v1/trait/deployment.go index 3e8092df6c..2be4cab70b 100644 --- a/pkg/apis/camel/v1/trait/deployment.go +++ b/pkg/apis/camel/v1/trait/deployment.go @@ -19,6 +19,7 @@ package trait import ( appsv1 "k8s.io/api/apps/v1" + "k8s.io/apimachinery/pkg/util/intstr" ) // The Deployment trait is responsible for generating the Kubernetes deployment that will make sure @@ -38,12 +39,12 @@ type DeploymentTrait struct { // Absolute number is calculated from percentage by rounding down. // This can not be 0 if MaxSurge is 0. // Defaults to `25%`. - RollingUpdateMaxUnavailable *int `property:"rolling-update-max-unavailable" json:"rollingUpdateMaxUnavailable,omitempty"` + RollingUpdateMaxUnavailable *intstr.IntOrString `property:"rolling-update-max-unavailable" json:"rollingUpdateMaxUnavailable,omitempty"` // The maximum number of pods that can be scheduled above the desired number of // pods. // Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). // This can not be 0 if MaxUnavailable is 0. // Absolute number is calculated from percentage by rounding up. // Defaults to `25%`. - RollingUpdateMaxSurge *int `property:"rolling-update-max-surge" json:"rollingUpdateMaxSurge,omitempty"` + RollingUpdateMaxSurge *intstr.IntOrString `property:"rolling-update-max-surge" json:"rollingUpdateMaxSurge,omitempty"` } diff --git a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go index abe7018091..01e4a5e126 100644 --- a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go @@ -7,6 +7,7 @@ package trait import ( "k8s.io/api/networking/v1" + "k8s.io/apimachinery/pkg/util/intstr" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. @@ -281,12 +282,12 @@ func (in *DeploymentTrait) DeepCopyInto(out *DeploymentTrait) { } if in.RollingUpdateMaxUnavailable != nil { in, out := &in.RollingUpdateMaxUnavailable, &out.RollingUpdateMaxUnavailable - *out = new(int) + *out = new(intstr.IntOrString) **out = **in } if in.RollingUpdateMaxSurge != nil { in, out := &in.RollingUpdateMaxSurge, &out.RollingUpdateMaxSurge - *out = new(int) + *out = new(intstr.IntOrString) **out = **in } } diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml index 8f6e433503..267189ab88 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml @@ -852,20 +852,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. @@ -2736,20 +2742,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml index c8c45ffc5c..51bf3e2c1f 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml @@ -734,20 +734,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. @@ -2507,20 +2513,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml index 000da77f6f..0bfd409d7f 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml @@ -6753,20 +6753,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. diff --git a/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml b/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml index 71665f1c55..5a4e27d493 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml @@ -7040,20 +7040,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. diff --git a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml index 64d017136d..a89c4b05da 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml @@ -7038,20 +7038,26 @@ spec: format: int32 type: integer rollingUpdateMaxSurge: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be scheduled above the desired number of pods. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). This can not be 0 if MaxUnavailable is 0. Absolute number is calculated from percentage by rounding up. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true rollingUpdateMaxUnavailable: + anyOf: + - type: integer + - type: string description: 'The maximum number of pods that can be unavailable during the update. Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%). Absolute number is calculated from percentage by rounding down. This can not be 0 if MaxSurge is 0. Defaults to `25%`.' - type: integer + x-kubernetes-int-or-string: true strategy: description: The deployment strategy to use to replace existing pods with new ones. diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go index c11fff7fb8..84ab52eac6 100644 --- a/pkg/trait/deployment.go +++ b/pkg/trait/deployment.go @@ -163,12 +163,12 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment { var maxUnavailable *intstr.IntOrString if t.RollingUpdateMaxSurge != nil { - v := intstr.FromInt(*t.RollingUpdateMaxSurge) - maxSurge = &v + v := t.RollingUpdateMaxSurge + maxSurge = v } if t.RollingUpdateMaxUnavailable != nil { - v := intstr.FromInt(*t.RollingUpdateMaxUnavailable) - maxUnavailable = &v + v := t.RollingUpdateMaxUnavailable + maxUnavailable = v } deployment.Spec.Strategy.RollingUpdate = &appsv1.RollingUpdateDeployment{ diff --git a/pkg/trait/deployment_test.go b/pkg/trait/deployment_test.go index 1147637ab5..28c2a598f2 100644 --- a/pkg/trait/deployment_test.go +++ b/pkg/trait/deployment_test.go @@ -26,6 +26,7 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" "github.com/apache/camel-k/v2/pkg/util/camel" @@ -137,7 +138,7 @@ func TestApplyDeploymentTraitWithProgressDeadline(t *testing.T) { func TestApplyDeploymentTraitWitRecresteStrategy(t *testing.T) { deploymentTrait, environment := createNominalDeploymentTest() - maxSurge := 10 + maxSurge := intstr.FromInt(10) deploymentTrait.Strategy = appsv1.RecreateDeploymentStrategyType deploymentTrait.RollingUpdateMaxSurge = &maxSurge @@ -177,7 +178,7 @@ func TestApplyDeploymentTraitWitRollingUpdateStrategy(t *testing.T) { t.Run("with surge", func(t *testing.T) { deploymentTrait, environment := createNominalDeploymentTest() - maxSurge := 10 + maxSurge := intstr.FromInt(10) deploymentTrait.Strategy = appsv1.RollingUpdateDeploymentStrategyType deploymentTrait.RollingUpdateMaxSurge = &maxSurge @@ -194,14 +195,14 @@ func TestApplyDeploymentTraitWitRollingUpdateStrategy(t *testing.T) { assert.Equal(t, appsv1.RollingUpdateDeploymentStrategyType, deployment.Spec.Strategy.Type) assert.NotNil(t, deployment.Spec.Strategy.RollingUpdate) assert.Nil(t, deployment.Spec.Strategy.RollingUpdate.MaxUnavailable) - assert.Equal(t, maxSurge, deployment.Spec.Strategy.RollingUpdate.MaxSurge.IntValue()) + assert.Equal(t, maxSurge, *deployment.Spec.Strategy.RollingUpdate.MaxSurge) }) t.Run("with surge and unavailable", func(t *testing.T) { deploymentTrait, environment := createNominalDeploymentTest() - maxSurge := 10 - maxUnavailable := 11 + maxSurge := intstr.FromInt(10) + maxUnavailable := intstr.FromInt(11) deploymentTrait.Strategy = appsv1.RollingUpdateDeploymentStrategyType deploymentTrait.RollingUpdateMaxSurge = &maxSurge @@ -218,9 +219,35 @@ func TestApplyDeploymentTraitWitRollingUpdateStrategy(t *testing.T) { assert.Equal(t, "integration-name", deployment.Name) assert.Equal(t, appsv1.RollingUpdateDeploymentStrategyType, deployment.Spec.Strategy.Type) assert.NotNil(t, deployment.Spec.Strategy.RollingUpdate) - assert.Equal(t, maxUnavailable, deployment.Spec.Strategy.RollingUpdate.MaxUnavailable.IntValue()) - assert.Equal(t, maxSurge, deployment.Spec.Strategy.RollingUpdate.MaxSurge.IntValue()) + assert.Equal(t, maxUnavailable, *deployment.Spec.Strategy.RollingUpdate.MaxUnavailable) + assert.Equal(t, maxSurge, *deployment.Spec.Strategy.RollingUpdate.MaxSurge) }) + + t.Run("with surge and unavailable in percentage values", func(t *testing.T) { + deploymentTrait, environment := createNominalDeploymentTest() + + maxSurge := intstr.FromString("10%") + maxUnavailable := intstr.FromString("11%") + + deploymentTrait.Strategy = appsv1.RollingUpdateDeploymentStrategyType + deploymentTrait.RollingUpdateMaxSurge = &maxSurge + deploymentTrait.RollingUpdateMaxUnavailable = &maxUnavailable + + 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, appsv1.RollingUpdateDeploymentStrategyType, deployment.Spec.Strategy.Type) + assert.NotNil(t, deployment.Spec.Strategy.RollingUpdate) + assert.Equal(t, maxUnavailable, *deployment.Spec.Strategy.RollingUpdate.MaxUnavailable) + assert.Equal(t, maxSurge, *deployment.Spec.Strategy.RollingUpdate.MaxSurge) + }) + } func createNominalDeploymentTest() (*deploymentTrait, *Environment) {