Bumping k8s dependencies to 1.13
This commit is contained in:
38
vendor/k8s.io/kubernetes/pkg/apis/coordination/validation/BUILD
generated
vendored
Normal file
38
vendor/k8s.io/kubernetes/pkg/apis/coordination/validation/BUILD
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["validation.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/apis/coordination/validation",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//pkg/apis/coordination:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/validation:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["validation_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//pkg/apis/coordination:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
52
vendor/k8s.io/kubernetes/pkg/apis/coordination/validation/validation.go
generated
vendored
Normal file
52
vendor/k8s.io/kubernetes/pkg/apis/coordination/validation/validation.go
generated
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/api/validation"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
"k8s.io/kubernetes/pkg/apis/coordination"
|
||||
)
|
||||
|
||||
// ValidateLease validates a Lease.
|
||||
func ValidateLease(lease *coordination.Lease) field.ErrorList {
|
||||
allErrs := validation.ValidateObjectMeta(&lease.ObjectMeta, true, validation.NameIsDNSSubdomain, field.NewPath("metadata"))
|
||||
allErrs = append(allErrs, ValidateLeaseSpec(&lease.Spec, field.NewPath("spec"))...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
// ValidateLeaseUpdate validates an update of Lease object.
|
||||
func ValidateLeaseUpdate(lease, oldLease *coordination.Lease) field.ErrorList {
|
||||
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.
|
||||
func ValidateLeaseSpec(spec *coordination.LeaseSpec, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
|
||||
if spec.LeaseDurationSeconds != nil && *spec.LeaseDurationSeconds <= 0 {
|
||||
fld := fldPath.Child("leaseDurationSeconds")
|
||||
allErrs = append(allErrs, field.Invalid(fld, spec.LeaseDurationSeconds, "must be greater than 0"))
|
||||
}
|
||||
if spec.LeaseTransitions != nil && *spec.LeaseTransitions < 0 {
|
||||
fld := fldPath.Child("leaseTransitions")
|
||||
allErrs = append(allErrs, field.Invalid(fld, spec.LeaseTransitions, "must to greater or equal than 0"))
|
||||
}
|
||||
return allErrs
|
||||
}
|
104
vendor/k8s.io/kubernetes/pkg/apis/coordination/validation/validation_test.go
generated
vendored
Normal file
104
vendor/k8s.io/kubernetes/pkg/apis/coordination/validation/validation_test.go
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package validation
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
"k8s.io/kubernetes/pkg/apis/coordination"
|
||||
)
|
||||
|
||||
func TestValidateLease(t *testing.T) {
|
||||
lease := &coordination.Lease{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "invalidName++",
|
||||
Namespace: "==invalid_Namespace==",
|
||||
},
|
||||
}
|
||||
errs := ValidateLease(lease)
|
||||
if len(errs) != 2 {
|
||||
t.Errorf("unexpected list of errors: %#v", errs.ToAggregate().Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateLeaseSpec(t *testing.T) {
|
||||
holder := "holder"
|
||||
leaseDuration := int32(0)
|
||||
leaseTransitions := int32(-1)
|
||||
spec := &coordination.LeaseSpec{
|
||||
HolderIdentity: &holder,
|
||||
LeaseDurationSeconds: &leaseDuration,
|
||||
LeaseTransitions: &leaseTransitions,
|
||||
}
|
||||
errs := ValidateLeaseSpec(spec, field.NewPath("foo"))
|
||||
if len(errs) != 2 {
|
||||
t.Errorf("unexpected list of errors: %#v", errs.ToAggregate().Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateLeaseSpecUpdate(t *testing.T) {
|
||||
holder := "holder"
|
||||
leaseDuration := int32(0)
|
||||
leaseTransitions := int32(-1)
|
||||
lease := &coordination.Lease{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "holder",
|
||||
Namespace: "holder-namespace",
|
||||
},
|
||||
Spec: coordination.LeaseSpec{
|
||||
HolderIdentity: &holder,
|
||||
LeaseDurationSeconds: &leaseDuration,
|
||||
LeaseTransitions: &leaseTransitions,
|
||||
},
|
||||
}
|
||||
oldHolder := "oldHolder"
|
||||
oldLeaseDuration := int32(3)
|
||||
oldLeaseTransitions := int32(3)
|
||||
oldLease := &coordination.Lease{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "holder",
|
||||
Namespace: "holder-namespace",
|
||||
},
|
||||
Spec: coordination.LeaseSpec{
|
||||
HolderIdentity: &oldHolder,
|
||||
LeaseDurationSeconds: &oldLeaseDuration,
|
||||
LeaseTransitions: &oldLeaseTransitions,
|
||||
},
|
||||
}
|
||||
errs := ValidateLeaseUpdate(lease, oldLease)
|
||||
if len(errs) != 3 {
|
||||
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())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user