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

fix(pdb): fix PDB can not update #1095

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Changes from all commits
Commits
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
22 changes: 6 additions & 16 deletions controllers/apps/v2beta1/add_pdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
"github.com/go-logr/logr"
policyv1 "k8s.io/api/policy/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/discovery"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
kubeConfig "sigs.k8s.io/controller-runtime/pkg/client/config"
)
Expand Down Expand Up @@ -43,15 +40,8 @@
}
}

for _, pdb := range pdbList {
if err := ctrl.SetControllerReference(instance, pdb, a.Scheme); err != nil {
return subResult{err: emperror.Wrap(err, "failed to set controller reference")}
}
if err := a.Client.Create(ctx, pdb); err != nil {
if !k8sErrors.IsAlreadyExists(err) {
return subResult{err: emperror.Wrap(err, "failed to create PDB")}
}
}
if err := a.CreateOrUpdateList(ctx, a.Scheme, logger, instance, pdbList); err != nil {
return subResult{err: emperror.Wrap(err, "failed to create or update PDBs")}

Check warning on line 44 in controllers/apps/v2beta1/add_pdb.go

View check run for this annotation

Codecov / codecov/patch

controllers/apps/v2beta1/add_pdb.go#L44

Added line #L44 was not covered by tests
}
return subResult{}
}
Expand Down Expand Up @@ -111,10 +101,8 @@
instance.Spec.CoreTemplate.Labels,
),
},
MinAvailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
MinAvailable: instance.Spec.CoreTemplate.Spec.MinAvailable,
MaxUnavailable: instance.Spec.CoreTemplate.Spec.MaxUnavailable,

Check warning on line 105 in controllers/apps/v2beta1/add_pdb.go

View check run for this annotation

Codecov / codecov/patch

controllers/apps/v2beta1/add_pdb.go#L104-L105

Added lines #L104 - L105 were not covered by tests
},
}
if appsv2beta1.IsExistReplicant(instance) {
Expand All @@ -124,6 +112,8 @@
appsv2beta1.DefaultReplicantLabels(instance),
instance.Spec.ReplicantTemplate.Labels,
)
replPdb.Spec.MinAvailable = instance.Spec.ReplicantTemplate.Spec.MinAvailable
replPdb.Spec.MaxUnavailable = instance.Spec.ReplicantTemplate.Spec.MaxUnavailable

Check warning on line 116 in controllers/apps/v2beta1/add_pdb.go

View check run for this annotation

Codecov / codecov/patch

controllers/apps/v2beta1/add_pdb.go#L115-L116

Added lines #L115 - L116 were not covered by tests
return corePdb, replPdb
}
return corePdb, nil
Expand Down
Loading