Skip to content

Commit

Permalink
controller: skip PDB creation when nginx object status is empty (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
morpheu authored Mar 24, 2022
1 parent 81e356a commit c6dc109
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ func (r *RpaasInstanceReconciler) reconcileHPA(ctx context.Context, instance *v1
}

func (r *RpaasInstanceReconciler) reconcilePDB(ctx context.Context, instance *v1alpha1.RpaasInstance, nginx *nginxv1alpha1.Nginx) error {
if nginx.Status.PodSelector == "" {
return nil
}
pdb, err := newPDB(instance, nginx)
if err != nil {
return err
Expand Down
25 changes: 25 additions & 0 deletions controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,31 @@ func Test_reconcilePDB(t *testing.T) {
assert.True(t, k8serrors.IsNotFound(err))
},
},

"skip PDB creation when nginx status is empty": {
instance: &v1alpha1.RpaasInstance{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
Namespace: "rpaasv2",
},
Spec: v1alpha1.RpaasInstanceSpec{
EnablePodDisruptionBudget: func(b bool) *bool { return &b }(true),
Replicas: func(n int32) *int32 { return &n }(10),
},
},
nginx: &nginxv1alpha1.Nginx{
ObjectMeta: metav1.ObjectMeta{
Name: "my-instance",
Namespace: "rpaasv2",
},
},
assert: func(t *testing.T, c client.Client) {
var pdb policyv1beta1.PodDisruptionBudget
err := c.Get(context.TODO(), client.ObjectKey{Name: "my-instance", Namespace: "rpaasv2"}, &pdb)
require.Error(t, err)
assert.True(t, k8serrors.IsNotFound(err))
},
},
}

for name, tt := range tests {
Expand Down

0 comments on commit c6dc109

Please sign in to comment.