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

Implemented PodDisruptionBudget #896

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

triceras
Copy link
Contributor

@triceras triceras commented Dec 20, 2024

Implementing PodDisruptionBugdet to the operator and added unittests.
This implements #104

@triceras triceras marked this pull request as ready for review December 22, 2024 23:33
@triceras triceras requested a review from a team as a code owner December 22, 2024 23:33
Copy link
Contributor

@bsocaciu bsocaciu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve the comments above and fell free to merge afterwards 🚀

}
} else {
// Set default values if not specified in the CR
defaultMinAvailable := intstr.FromInt(2) // Example default: at least 2 pods available
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use FromInt32 as FromInt is deprecated

})

It("Should create PDB with user-specified minAvailable", func() {
minAvailable := intstr.FromInt(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use FromInt32 as FromInt is deprecated

})

It("Should create PDB with user-specified maxUnavailable", func() {
maxUnavailable := intstr.FromInt(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use FromInt32 as FromInt is deprecated

Expect(k8sClient.Get(ctx, key, updatedHumioCluster)).Should(Succeed())

// Update HumioCluster with new PDB spec
minAvailable := intstr.FromInt(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use FromInt32 as FromInt is deprecated

// Check if the PodDisruptionBudget already exists
foundPdb := &policyv1.PodDisruptionBudget{}
err := r.Client.Get(ctx, types.NamespacedName{Name: pdb.Name, Namespace: pdb.Namespace}, foundPdb)
if err != nil && k8serrors.IsNotFound(err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would streamline the error check like this:

	if err != nil {
		return err
	}
	if k8serrors.IsNotFound(err) {
		// Create the PodDisruptionBudget
		r.Log.Info("Creating a new PodDisruptionBudget", "PDB.Namespace", pdb.Namespace, "PDB.Name", pdb.Name)
		err = r.Client.Create(ctx, pdb)
		if err != nil {
			return err
		}
		return nil
	} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants