astefanutti commented on a change in pull request #1787: URL: https://github.com/apache/camel-k/pull/1787#discussion_r515003366
########## File path: pkg/trait/pod.go ########## @@ -0,0 +1,97 @@ +/* +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 ( + 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" +) + +// The PodDisruptionBudget trait is used to configure the pdb Review comment: The comment should be updated accordingly to the trait name. ########## File path: pkg/trait/pod.go ########## @@ -0,0 +1,97 @@ +/* +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 ( + 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" +) + +// The PodDisruptionBudget trait is used to configure the pdb +// +// +camel-k:trait=pod +type podTrait struct { + BaseTrait `property:",squash"` + MaxUnavailable string `property:"max-unavailable" json:"maxUnavailable,omitempty"` + MinAvailable string `property:"min-available" json:"minAvailable,omitempty"` +} + +func newPodTrait() Trait { + return &podTrait{ + BaseTrait: NewBaseTrait("pod", 900), + } +} + +func (t *podTrait) Configure(e *Environment) (bool, error) { + if t.Enabled != nil && !*t.Enabled { + return false, nil + } + + return e.IntegrationInPhase( + v1.IntegrationPhaseDeploying, + v1.IntegrationPhaseRunning, + ), nil +} + +func (t *podTrait) Apply(e *Environment) error { + pdbName := "pdb-" + e.Integration.Name + "-it" + t.L.Info("PodDisruptionBudget for the integration", e.Integration.Name, "not found") Review comment: I'd suggest to use the Integration name for the PDB. Also the log statement can be removed. ########## File path: pkg/trait/pod.go ########## @@ -0,0 +1,97 @@ +/* +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 ( + 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" +) + +// The PodDisruptionBudget trait is used to configure the pdb +// +// +camel-k:trait=pod +type podTrait struct { + BaseTrait `property:",squash"` + MaxUnavailable string `property:"max-unavailable" json:"maxUnavailable,omitempty"` + MinAvailable string `property:"min-available" json:"minAvailable,omitempty"` +} + +func newPodTrait() Trait { + return &podTrait{ + BaseTrait: NewBaseTrait("pod", 900), + } +} + +func (t *podTrait) Configure(e *Environment) (bool, error) { + if t.Enabled != nil && !*t.Enabled { + return false, nil + } + + return e.IntegrationInPhase( + v1.IntegrationPhaseDeploying, + v1.IntegrationPhaseRunning, + ), nil +} + +func (t *podTrait) Apply(e *Environment) error { + pdbName := "pdb-" + e.Integration.Name + "-it" + t.L.Info("PodDisruptionBudget for the integration", e.Integration.Name, "not found") + pdb := t.generatePodDisruptionBudget(pdbName, e.Integration) + e.Resources.Add(pdb) + + return nil +} + +func (t *podTrait) generatePodDisruptionBudget(pdbName string, integration *v1.Integration) *v1beta1.PodDisruptionBudget { + spec := v1beta1.PodDisruptionBudgetSpec{ + Selector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "camel.apache.org/integration": integration.Name, + }, + }, + } + + var min, max intstr.IntOrString + + if t.MinAvailable == "" && t.MaxUnavailable == "" { Review comment: I'd suggest not to default values for PDB. I see this rather as an advanced feature, that is leveraged by SRE. ########## File path: pkg/trait/pod.go ########## @@ -0,0 +1,97 @@ +/* +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 ( + 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" +) + +// The PodDisruptionBudget trait is used to configure the pdb +// +// +camel-k:trait=pod +type podTrait struct { + BaseTrait `property:",squash"` + MaxUnavailable string `property:"max-unavailable" json:"maxUnavailable,omitempty"` + MinAvailable string `property:"min-available" json:"minAvailable,omitempty"` +} + +func newPodTrait() Trait { + return &podTrait{ + BaseTrait: NewBaseTrait("pod", 900), + } +} + +func (t *podTrait) Configure(e *Environment) (bool, error) { + if t.Enabled != nil && !*t.Enabled { + return false, nil + } + + return e.IntegrationInPhase( + v1.IntegrationPhaseDeploying, + v1.IntegrationPhaseRunning, + ), nil +} + +func (t *podTrait) Apply(e *Environment) error { + pdbName := "pdb-" + e.Integration.Name + "-it" + t.L.Info("PodDisruptionBudget for the integration", e.Integration.Name, "not found") + pdb := t.generatePodDisruptionBudget(pdbName, e.Integration) + e.Resources.Add(pdb) Review comment: I'd proposed that a PDB is created only if at least one of the two parameters is set. ########## File path: pkg/trait/pod.go ########## @@ -0,0 +1,97 @@ +/* +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 ( + 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" +) + +// The PodDisruptionBudget trait is used to configure the pdb +// +// +camel-k:trait=pod +type podTrait struct { + BaseTrait `property:",squash"` + MaxUnavailable string `property:"max-unavailable" json:"maxUnavailable,omitempty"` + MinAvailable string `property:"min-available" json:"minAvailable,omitempty"` +} + +func newPodTrait() Trait { + return &podTrait{ + BaseTrait: NewBaseTrait("pod", 900), + } +} + +func (t *podTrait) Configure(e *Environment) (bool, error) { + if t.Enabled != nil && !*t.Enabled { + return false, nil + } + + return e.IntegrationInPhase( + v1.IntegrationPhaseDeploying, + v1.IntegrationPhaseRunning, + ), nil +} + +func (t *podTrait) Apply(e *Environment) error { + pdbName := "pdb-" + e.Integration.Name + "-it" + t.L.Info("PodDisruptionBudget for the integration", e.Integration.Name, "not found") + pdb := t.generatePodDisruptionBudget(pdbName, e.Integration) + e.Resources.Add(pdb) + + return nil +} + +func (t *podTrait) generatePodDisruptionBudget(pdbName string, integration *v1.Integration) *v1beta1.PodDisruptionBudget { + spec := v1beta1.PodDisruptionBudgetSpec{ + Selector: &metav1.LabelSelector{ + MatchLabels: map[string]string{ + "camel.apache.org/integration": integration.Name, Review comment: the `IntegrationLabel` variable can be used instead of duplicating the label name. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org