mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Fix coordination.Lease validation
This commit is contained in:
parent
d949315649
commit
9bb8dd9ca5
@ -24,14 +24,16 @@ import (
|
|||||||
|
|
||||||
// ValidateLease validates a Lease.
|
// ValidateLease validates a Lease.
|
||||||
func ValidateLease(lease *coordination.Lease) field.ErrorList {
|
func ValidateLease(lease *coordination.Lease) field.ErrorList {
|
||||||
allErrs := validation.ValidateObjectMeta(&lease.ObjectMeta, true, validation.NameIsDNSSubdomain, field.NewPath("objectMeta"))
|
allErrs := validation.ValidateObjectMeta(&lease.ObjectMeta, true, validation.NameIsDNSSubdomain, field.NewPath("metadata"))
|
||||||
allErrs = append(allErrs, ValidateLeaseSpec(&lease.Spec, field.NewPath("spec"))...)
|
allErrs = append(allErrs, ValidateLeaseSpec(&lease.Spec, field.NewPath("spec"))...)
|
||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateLeaseUpdate validates an update of Lease object.
|
// ValidateLeaseUpdate validates an update of Lease object.
|
||||||
func ValidateLeaseUpdate(lease, oldLease *coordination.Lease) field.ErrorList {
|
func ValidateLeaseUpdate(lease, oldLease *coordination.Lease) field.ErrorList {
|
||||||
return ValidateLease(lease)
|
allErrs := validation.ValidateObjectMetaUpdate(&lease.ObjectMeta, &oldLease.ObjectMeta, field.NewPath("metadata"))
|
||||||
|
allErrs = append(allErrs, ValidateLeaseSpec(&lease.Spec, field.NewPath("spec"))...)
|
||||||
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateLeaseSpec validates spec of Lease.
|
// ValidateLeaseSpec validates spec of Lease.
|
||||||
|
@ -71,6 +71,10 @@ func TestValidateLeaseSpecUpdate(t *testing.T) {
|
|||||||
oldLeaseDuration := int32(3)
|
oldLeaseDuration := int32(3)
|
||||||
oldLeaseTransitions := int32(3)
|
oldLeaseTransitions := int32(3)
|
||||||
oldLease := &coordination.Lease{
|
oldLease := &coordination.Lease{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "holder",
|
||||||
|
Namespace: "holder-namespace",
|
||||||
|
},
|
||||||
Spec: coordination.LeaseSpec{
|
Spec: coordination.LeaseSpec{
|
||||||
HolderIdentity: &oldHolder,
|
HolderIdentity: &oldHolder,
|
||||||
LeaseDurationSeconds: &oldLeaseDuration,
|
LeaseDurationSeconds: &oldLeaseDuration,
|
||||||
@ -78,7 +82,23 @@ func TestValidateLeaseSpecUpdate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
errs := ValidateLeaseUpdate(lease, oldLease)
|
errs := ValidateLeaseUpdate(lease, oldLease)
|
||||||
if len(errs) != 2 {
|
if len(errs) != 3 {
|
||||||
t.Errorf("unexpected list of errors: %#v", errs.ToAggregate().Error())
|
t.Errorf("unexpected list of errors: %#v", errs.ToAggregate().Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validLeaseDuration := int32(10)
|
||||||
|
validLeaseTransitions := int32(20)
|
||||||
|
validLease := &coordination.Lease{
|
||||||
|
ObjectMeta: oldLease.ObjectMeta,
|
||||||
|
Spec: coordination.LeaseSpec{
|
||||||
|
HolderIdentity: &holder,
|
||||||
|
LeaseDurationSeconds: &validLeaseDuration,
|
||||||
|
LeaseTransitions: &validLeaseTransitions,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
validLease.ObjectMeta.ResourceVersion = "2"
|
||||||
|
errs = ValidateLeaseUpdate(validLease, oldLease)
|
||||||
|
if len(errs) != 0 {
|
||||||
|
t.Errorf("unexpected list of errors for valid update: %#v", errs.ToAggregate().Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user