Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pod Disruption Budget implementation #900

Merged
merged 35 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f23a930
Rebasing
triceras Feb 3, 2025
e50bcb6
API docs for PDB
triceras Jan 13, 2025
3e4c534
Removed unnused variables
triceras Jan 13, 2025
0dd532e
Removed unused function
triceras Jan 13, 2025
175b655
Rebasing
triceras Feb 3, 2025
d7eb7a3
fixes
triceras Jan 16, 2025
91fef07
Removed func podLabelsForHumio
triceras Jan 16, 2025
ee28091
Improvements
triceras Jan 17, 2025
ffb9f99
Removed unused function cleanupOrphanedNodePoolPDBs
triceras Jan 17, 2025
f2f9222
Removed comments in the controller pdb functions
triceras Jan 17, 2025
41bc9ad
HumioNodeSpec
triceras Jan 21, 2025
2ce0af3
HumioNodeSpec updates
triceras Jan 21, 2025
2686c52
updated api docs for pdb
triceras Jan 21, 2025
1697cc6
using pdb functions
triceras Jan 21, 2025
460c1b5
removed func ensurePodDisruptionBudgets
triceras Jan 21, 2025
a44c52a
Moved cleanupOrphanedPDBs outside the foor loop in cleanupUnusedResou…
triceras Jan 23, 2025
8881e4d
fixed wrong function placement
triceras Jan 23, 2025
f091795
Adding missing func ensureViewGroupPermissionsConfigMap back to the r…
triceras Jan 23, 2025
b086b65
remove obsolete func shouldCreatePDBForNodePool
triceras Jan 23, 2025
7f9f7ba
Update humiocluster_controller.go
triceras Jan 24, 2025
f75aa91
Update humiocluster_controller_test.go
triceras Jan 24, 2025
a74976b
Update humiocluster_types.go
triceras Jan 24, 2025
28cbed2
Update humiocluster_controller.go
triceras Jan 24, 2025
4972f17
PDB improvements
triceras Jan 24, 2025
a371198
Added API docs
triceras Jan 24, 2025
da48474
Fixed integer overflow conversion
triceras Jan 24, 2025
d4df94e
Using handlePDBFinalizers
triceras Jan 24, 2025
fa91e02
Remobed PDB logic from ensureMismatchedPodsAreDeleted. Improved PDB l…
triceras Jan 28, 2025
3628864
removed unused funcs cleanupOrphanedPDBs, isValidNodePool and isOwned…
triceras Jan 28, 2025
4ff80e9
Rebasing
triceras Feb 3, 2025
7c3871b
Simplified the logic in createOrUpdatePDB to use controllerutil.Creat…
triceras Feb 4, 2025
5cef371
Created helper function MatchingLabelsForHumioNodePool for targetting…
triceras Feb 4, 2025
cff6190
Update controllers/humiocluster_controller.go
triceras Feb 5, 2025
a4bbcb0
Update humiocluster_controller.go
triceras Feb 5, 2025
937152d
Merge branch 'master' into rafael/PodDisruptionBugdet
SaaldjorMike Feb 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 72 additions & 1 deletion api/v1alpha1/humiocluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/validation/field"
)

const (
Expand Down Expand Up @@ -263,6 +267,9 @@ type HumioNodeSpec struct {

// HumioNodePoolFeatures defines the features that are allowed by the node pool
NodePoolFeatures HumioNodePoolFeatures `json:"nodePoolFeatures,omitempty"`

// PodDisruptionBudget defines the PDB configuration for this node spec
PodDisruptionBudget *HumioPodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"`
}

type HumioNodePoolFeatures struct {
Expand Down Expand Up @@ -304,7 +311,6 @@ type HumioUpdateStrategy struct {
//+kubebuilder:default=1
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`
}

type HumioNodePoolSpec struct {
//+kubebuilder:validation:MinLength:=1
//+required
Expand All @@ -313,6 +319,33 @@ type HumioNodePoolSpec struct {
HumioNodeSpec `json:"spec,omitempty"`
}

// PodDisruptionBudgetSpec defines the desired pod disruption budget configuration
type HumioPodDisruptionBudgetSpec struct {
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=int-or-string
// MinAvailable is the minimum number of pods that must be available during a disruption.
MinAvailable *intstr.IntOrString `json:"minAvailable,omitempty"`

// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=int-or-string
// MaxUnavailable is the maximum number of pods that can be unavailable during a disruption.
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`

// +kubebuilder:validation:Enum=IfHealthyBudget;AlwaysAllow
// +kubebuilder:validation:default="IfHealthyBudget"
// UnhealthyPodEvictionPolicy defines the policy for evicting unhealthy pods.
// Requires Kubernetes 1.26+.
// +optional
UnhealthyPodEvictionPolicy *string `json:"unhealthyPodEvictionPolicy,omitempty"`

// +kubebuilder:validation:Xor={"minAvailable","maxUnavailable"}
// +kubebuilder:validation:Required

// Enabled indicates whether PodDisruptionBudget is enabled for this NodePool.
// +optional
Enabled bool `json:"enabled,omitempty"`
}

// HumioHostnameSource is the possible references to a hostname value that is stored outside of the HumioCluster resource
type HumioHostnameSource struct {
// SecretKeyRef contains the secret key reference when a hostname is pulled from a secret
Expand Down Expand Up @@ -476,3 +509,41 @@ func (l HumioPodStatusList) Swap(i, j int) {
func init() {
SchemeBuilder.Register(&HumioCluster{}, &HumioClusterList{})
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (hc *HumioCluster) ValidateCreate() error {
return hc.validateMutualExclusivity()
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (hc *HumioCluster) ValidateUpdate(old runtime.Object) error {
return hc.validateMutualExclusivity()
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type.
func (hc *HumioCluster) ValidateDelete() error {
return nil
}

// validateMutualExclusivity validates that within each NodePool, only one of minAvailable or maxUnavailable is set.
func (hc *HumioCluster) validateMutualExclusivity() error {
var allErrs field.ErrorList

// Validate PodDisruptionBudget of each NodePool.
for i, np := range hc.Spec.NodePools {
if np.PodDisruptionBudget != nil {
pdbPath := field.NewPath("spec", "nodePools").Index(i).Child("podDisruptionBudget")
if np.PodDisruptionBudget.MinAvailable != nil && np.PodDisruptionBudget.MaxUnavailable != nil {
allErrs = append(allErrs, field.Forbidden(
pdbPath.Child("minAvailable"),
"cannot set both minAvailable and maxUnavailable in PodDisruptionBudget; choose one"))
}
}
}

if len(allErrs) > 0 {
gk := schema.GroupKind{Group: "humio.com", Kind: "HumioCluster"}
return apierrors.NewInvalid(gk, hc.Name, allErrs)
}
return nil
}
37 changes: 36 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions charts/humio-operator/crds/core.humio.com_humioclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11250,6 +11250,41 @@ spec:
description: PodAnnotations can be used to specify annotations
that will be added to the Humio pods
type: object
podDisruptionBudget:
description: PodDisruptionBudget defines the PDB configuration
for this node spec
properties:
enabled:
description: Enabled indicates whether PodDisruptionBudget
is enabled for this NodePool.
type: boolean
maxUnavailable:
anyOf:
- type: integer
- type: string
description: MaxUnavailable is the maximum number of
pods that can be unavailable during a disruption.
format: int-or-string
type: string
x-kubernetes-int-or-string: true
minAvailable:
anyOf:
- type: integer
- type: string
description: MinAvailable is the minimum number of pods
that must be available during a disruption.
format: int-or-string
type: string
x-kubernetes-int-or-string: true
unhealthyPodEvictionPolicy:
description: |-
UnhealthyPodEvictionPolicy defines the policy for evicting unhealthy pods.
Requires Kubernetes 1.26+.
enum:
- IfHealthyBudget
- AlwaysAllow
type: string
type: object
podLabels:
additionalProperties:
type: string
Expand Down Expand Up @@ -13164,6 +13199,41 @@ spec:
description: PodAnnotations can be used to specify annotations that
will be added to the Humio pods
type: object
podDisruptionBudget:
description: PodDisruptionBudget defines the PDB configuration for
this node spec
properties:
enabled:
description: Enabled indicates whether PodDisruptionBudget is
enabled for this NodePool.
type: boolean
maxUnavailable:
anyOf:
- type: integer
- type: string
description: MaxUnavailable is the maximum number of pods that
can be unavailable during a disruption.
format: int-or-string
type: string
x-kubernetes-int-or-string: true
minAvailable:
anyOf:
- type: integer
- type: string
description: MinAvailable is the minimum number of pods that must
be available during a disruption.
format: int-or-string
type: string
x-kubernetes-int-or-string: true
unhealthyPodEvictionPolicy:
description: |-
UnhealthyPodEvictionPolicy defines the policy for evicting unhealthy pods.
Requires Kubernetes 1.26+.
enum:
- IfHealthyBudget
- AlwaysAllow
type: string
type: object
podLabels:
additionalProperties:
type: string
Expand Down
70 changes: 70 additions & 0 deletions config/crd/bases/core.humio.com_humioclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11250,6 +11250,41 @@ spec:
description: PodAnnotations can be used to specify annotations
that will be added to the Humio pods
type: object
podDisruptionBudget:
description: PodDisruptionBudget defines the PDB configuration
for this node spec
properties:
enabled:
description: Enabled indicates whether PodDisruptionBudget
is enabled for this NodePool.
type: boolean
maxUnavailable:
anyOf:
- type: integer
- type: string
description: MaxUnavailable is the maximum number of
pods that can be unavailable during a disruption.
format: int-or-string
type: string
x-kubernetes-int-or-string: true
minAvailable:
anyOf:
- type: integer
- type: string
description: MinAvailable is the minimum number of pods
that must be available during a disruption.
format: int-or-string
type: string
x-kubernetes-int-or-string: true
unhealthyPodEvictionPolicy:
description: |-
UnhealthyPodEvictionPolicy defines the policy for evicting unhealthy pods.
Requires Kubernetes 1.26+.
enum:
- IfHealthyBudget
- AlwaysAllow
type: string
type: object
podLabels:
additionalProperties:
type: string
Expand Down Expand Up @@ -13164,6 +13199,41 @@ spec:
description: PodAnnotations can be used to specify annotations that
will be added to the Humio pods
type: object
podDisruptionBudget:
description: PodDisruptionBudget defines the PDB configuration for
this node spec
properties:
enabled:
description: Enabled indicates whether PodDisruptionBudget is
enabled for this NodePool.
type: boolean
maxUnavailable:
anyOf:
- type: integer
- type: string
description: MaxUnavailable is the maximum number of pods that
can be unavailable during a disruption.
format: int-or-string
type: string
x-kubernetes-int-or-string: true
minAvailable:
anyOf:
- type: integer
- type: string
description: MinAvailable is the minimum number of pods that must
be available during a disruption.
format: int-or-string
type: string
x-kubernetes-int-or-string: true
unhealthyPodEvictionPolicy:
description: |-
UnhealthyPodEvictionPolicy defines the policy for evicting unhealthy pods.
Requires Kubernetes 1.26+.
enum:
- IfHealthyBudget
- AlwaysAllow
type: string
type: object
podLabels:
additionalProperties:
type: string
Expand Down
Loading
Loading