This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 7e71966d16762330a37e86fe3aef85f557fb3d65
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Mon Nov 16 09:50:12 2020 +0100

    chore(doc): Add documentation to PDB trait parameters
---
 pkg/trait/pdb.go | 68 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 35 insertions(+), 33 deletions(-)

diff --git a/pkg/trait/pdb.go b/pkg/trait/pdb.go
index 7b273ce..de1131f 100644
--- a/pkg/trait/pdb.go
+++ b/pkg/trait/pdb.go
@@ -19,19 +19,27 @@ package trait
 
 import (
        "fmt"
-       v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+
        "k8s.io/api/policy/v1beta1"
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
        "k8s.io/apimachinery/pkg/util/intstr"
+
+       v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 )
 
-// The Pdb trait allows to configure the PodDisruptionBudget resource.
+// The PDB trait allows to configure the PodDisruptionBudget resource for the 
Integration pods.
 //
 // +camel-k:trait=pdb
 type pdbTrait struct {
-       BaseTrait      `property:",squash"`
+       BaseTrait `property:",squash"`
+       // The number of pods for the Integration that must still be available 
after an eviction.
+       // It can be either an absolute number or a percentage.
+       // Only one of `min-available` and `max-unavailable` can be specified.
+       MinAvailable string `property:"min-available" 
json:"minAvailable,omitempty"`
+       // The number of pods for the Integration that can be unavailable after 
an eviction.
+       // It can be either an absolute number or a percentage (default `1` if 
`min-available` is also not set).
+       // Only one of `max-unavailable` and `min-available` can be specified.
        MaxUnavailable string `property:"max-unavailable" 
json:"maxUnavailable,omitempty"`
-       MinAvailable   string `property:"min-available" 
json:"minAvailable,omitempty"`
 }
 
 func newPdbTrait() Trait {
@@ -65,45 +73,39 @@ func (t *pdbTrait) Configure(e *Environment) (bool, error) {
 }
 
 func (t *pdbTrait) Apply(e *Environment) error {
-       if pdb, err := t.generatePodDisruptionBudget(e); err == nil {
-               e.Resources.Add(pdb)
-       } else {
-               return err
-       }
-       return nil
-}
-
-func (t *pdbTrait) generatePodDisruptionBudget(e *Environment) 
(*v1beta1.PodDisruptionBudget, error) {
        if t.MaxUnavailable == "" && t.MinAvailable == "" {
                t.MaxUnavailable = "1"
        }
 
-       integration := e.Integration
-       spec := v1beta1.PodDisruptionBudgetSpec{
-               Selector: &metav1.LabelSelector{
-                       MatchLabels: map[string]string{
-                               v1.IntegrationLabel: integration.Name,
+       pdb := t.podDisruptionBudgetFor(e.Integration)
+       e.Resources.Add(pdb)
+
+       return nil
+}
+
+func (t *pdbTrait) podDisruptionBudgetFor(integration *v1.Integration) 
*v1beta1.PodDisruptionBudget {
+       pdb := &v1beta1.PodDisruptionBudget{
+               ObjectMeta: metav1.ObjectMeta{
+                       Name:      integration.Name,
+                       Namespace: integration.Namespace,
+                       Labels:    integration.Labels,
+               },
+               Spec: v1beta1.PodDisruptionBudgetSpec{
+                       Selector: &metav1.LabelSelector{
+                               MatchLabels: map[string]string{
+                                       v1.IntegrationLabel: integration.Name,
+                               },
                        },
                },
        }
 
-       var min, max intstr.IntOrString
-
        if t.MaxUnavailable != "" {
-               max = intstr.Parse(t.MaxUnavailable)
-               spec.MaxUnavailable = &max
-
+               max := intstr.Parse(t.MaxUnavailable)
+               pdb.Spec.MaxUnavailable = &max
        } else {
-               min = intstr.Parse(t.MinAvailable)
-               spec.MinAvailable = &min
+               min := intstr.Parse(t.MinAvailable)
+               pdb.Spec.MinAvailable = &min
        }
 
-       return &v1beta1.PodDisruptionBudget{
-               ObjectMeta: metav1.ObjectMeta{
-                       Name:      integration.Name,
-                       Namespace: integration.Namespace,
-                       Labels:    integration.Labels,
-               },
-               Spec: spec,
-       }, nil
+       return pdb
 }

Reply via email to