mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Move API annotations into annotation_key_constants and remove api/annotations package
This commit is contained in:
parent
a82676a126
commit
c0920f75cf
@ -72,4 +72,35 @@ const (
|
|||||||
|
|
||||||
// annotation key prefix used to identify non-convertible json paths.
|
// annotation key prefix used to identify non-convertible json paths.
|
||||||
NonConvertibleAnnotationPrefix = "non-convertible.kubernetes.io"
|
NonConvertibleAnnotationPrefix = "non-convertible.kubernetes.io"
|
||||||
|
|
||||||
|
kubectlPrefix = "kubectl.kubernetes.io/"
|
||||||
|
|
||||||
|
// LastAppliedConfigAnnotation is the annotation used to store the previous
|
||||||
|
// configuration of a resource for use in a three way diff by UpdateApplyAnnotation.
|
||||||
|
LastAppliedConfigAnnotation = kubectlPrefix + "last-applied-configuration"
|
||||||
|
|
||||||
|
// AnnotationLoadBalancerSourceRangesKey is the key of the annotation on a service to set allowed ingress ranges on their LoadBalancers
|
||||||
|
//
|
||||||
|
// It should be a comma-separated list of CIDRs, e.g. `0.0.0.0/0` to
|
||||||
|
// allow full access (the default) or `18.0.0.0/8,56.0.0.0/8` to allow
|
||||||
|
// access only from the CIDRs currently allocated to MIT & the USPS.
|
||||||
|
//
|
||||||
|
// Not all cloud providers support this annotation, though AWS & GCE do.
|
||||||
|
AnnotationLoadBalancerSourceRangesKey = "service.beta.kubernetes.io/load-balancer-source-ranges"
|
||||||
|
|
||||||
|
// AnnotationValueExternalTrafficLocal Value of annotation to specify local endpoints behavior.
|
||||||
|
AnnotationValueExternalTrafficLocal = "OnlyLocal"
|
||||||
|
// AnnotationValueExternalTrafficGlobal Value of annotation to specify global (legacy) behavior.
|
||||||
|
AnnotationValueExternalTrafficGlobal = "Global"
|
||||||
|
|
||||||
|
// TODO: The beta annotations have been deprecated, remove them when we release k8s 1.8.
|
||||||
|
|
||||||
|
// BetaAnnotationHealthCheckNodePort Annotation specifying the healthcheck nodePort for the service.
|
||||||
|
// If not specified, annotation is created by the service api backend with the allocated nodePort.
|
||||||
|
// Will use user-specified nodePort value if specified by the client.
|
||||||
|
BetaAnnotationHealthCheckNodePort = "service.beta.kubernetes.io/healthcheck-nodeport"
|
||||||
|
|
||||||
|
// BetaAnnotationExternalTraffic An annotation that denotes if this Service desires to route
|
||||||
|
// external traffic to local endpoints only. This preserves Source IP and avoids a second hop.
|
||||||
|
BetaAnnotationExternalTraffic = "service.beta.kubernetes.io/external-traffic"
|
||||||
)
|
)
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
package(default_visibility = ["//visibility:public"])
|
|
||||||
|
|
||||||
licenses(["notice"])
|
|
||||||
|
|
||||||
load(
|
|
||||||
"@io_bazel_rules_go//go:def.bzl",
|
|
||||||
"go_library",
|
|
||||||
)
|
|
||||||
|
|
||||||
go_library(
|
|
||||||
name = "go_default_library",
|
|
||||||
srcs = [
|
|
||||||
"annotations.go",
|
|
||||||
"doc.go",
|
|
||||||
],
|
|
||||||
tags = ["automanaged"],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "package-srcs",
|
|
||||||
srcs = glob(["**"]),
|
|
||||||
tags = ["automanaged"],
|
|
||||||
visibility = ["//visibility:private"],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "all-srcs",
|
|
||||||
srcs = [":package-srcs"],
|
|
||||||
tags = ["automanaged"],
|
|
||||||
)
|
|
@ -1,4 +0,0 @@
|
|||||||
reviewers:
|
|
||||||
- dims
|
|
||||||
- david-mcmahon
|
|
||||||
- jianhuiz
|
|
@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2016 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 annotations
|
|
||||||
|
|
||||||
const kubectlPrefix = "kubectl.kubernetes.io/"
|
|
||||||
|
|
||||||
// LastAppliedConfigAnnotation is the annotation used to store the previous
|
|
||||||
// configuration of a resource for use in a three way diff by UpdateApplyAnnotation.
|
|
||||||
const LastAppliedConfigAnnotation = kubectlPrefix + "last-applied-configuration"
|
|
@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2016 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 annotations defines annotation keys that shared between server and client
|
|
||||||
package annotations // import "k8s.io/kubernetes/pkg/api/annotations"
|
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2016 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 service
|
|
||||||
|
|
||||||
const (
|
|
||||||
// AnnotationLoadBalancerSourceRangesKey is the key of the annotation on a service to set allowed ingress ranges on their LoadBalancers
|
|
||||||
//
|
|
||||||
// It should be a comma-separated list of CIDRs, e.g. `0.0.0.0/0` to
|
|
||||||
// allow full access (the default) or `18.0.0.0/8,56.0.0.0/8` to allow
|
|
||||||
// access only from the CIDRs currently allocated to MIT & the USPS.
|
|
||||||
//
|
|
||||||
// Not all cloud providers support this annotation, though AWS & GCE do.
|
|
||||||
AnnotationLoadBalancerSourceRangesKey = "service.beta.kubernetes.io/load-balancer-source-ranges"
|
|
||||||
|
|
||||||
// AnnotationValueExternalTrafficLocal Value of annotation to specify local endpoints behavior.
|
|
||||||
AnnotationValueExternalTrafficLocal = "OnlyLocal"
|
|
||||||
// AnnotationValueExternalTrafficGlobal Value of annotation to specify global (legacy) behavior.
|
|
||||||
AnnotationValueExternalTrafficGlobal = "Global"
|
|
||||||
|
|
||||||
// TODO: The beta annotations have been deprecated, remove them when we release k8s 1.8.
|
|
||||||
|
|
||||||
// BetaAnnotationHealthCheckNodePort Annotation specifying the healthcheck nodePort for the service.
|
|
||||||
// If not specified, annotation is created by the service api backend with the allocated nodePort.
|
|
||||||
// Will use user-specified nodePort value if specified by the client.
|
|
||||||
BetaAnnotationHealthCheckNodePort = "service.beta.kubernetes.io/healthcheck-nodeport"
|
|
||||||
|
|
||||||
// BetaAnnotationExternalTraffic An annotation that denotes if this Service desires to route
|
|
||||||
// external traffic to local endpoints only. This preserves Source IP and avoids a second hop.
|
|
||||||
BetaAnnotationExternalTraffic = "service.beta.kubernetes.io/external-traffic"
|
|
||||||
)
|
|
@ -56,7 +56,7 @@ func GetLoadBalancerSourceRanges(service *api.Service) (netsets.IPNet, error) {
|
|||||||
return nil, fmt.Errorf("service.Spec.LoadBalancerSourceRanges: %v is not valid. Expecting a list of IP ranges. For example, 10.0.0.0/24. Error msg: %v", specs, err)
|
return nil, fmt.Errorf("service.Spec.LoadBalancerSourceRanges: %v is not valid. Expecting a list of IP ranges. For example, 10.0.0.0/24. Error msg: %v", specs, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val := service.Annotations[AnnotationLoadBalancerSourceRangesKey]
|
val := service.Annotations[api.AnnotationLoadBalancerSourceRangesKey]
|
||||||
val = strings.TrimSpace(val)
|
val = strings.TrimSpace(val)
|
||||||
if val == "" {
|
if val == "" {
|
||||||
val = defaultLoadBalancerSourceRanges
|
val = defaultLoadBalancerSourceRanges
|
||||||
@ -64,7 +64,7 @@ func GetLoadBalancerSourceRanges(service *api.Service) (netsets.IPNet, error) {
|
|||||||
specs := strings.Split(val, ",")
|
specs := strings.Split(val, ",")
|
||||||
ipnets, err = netsets.ParseIPNets(specs...)
|
ipnets, err = netsets.ParseIPNets(specs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %s is not valid. Expecting a comma-separated list of source IP ranges. For example, 10.0.0.0/24,192.168.2.0/24", AnnotationLoadBalancerSourceRangesKey, val)
|
return nil, fmt.Errorf("%s: %s is not valid. Expecting a comma-separated list of source IP ranges. For example, 10.0.0.0/24,192.168.2.0/24", api.AnnotationLoadBalancerSourceRangesKey, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ipnets, nil
|
return ipnets, nil
|
||||||
@ -80,14 +80,14 @@ func RequestsOnlyLocalTraffic(service *api.Service) bool {
|
|||||||
// First check the beta annotation and then the first class field. This is so that
|
// First check the beta annotation and then the first class field. This is so that
|
||||||
// existing Services continue to work till the user decides to transition to the
|
// existing Services continue to work till the user decides to transition to the
|
||||||
// first class field.
|
// first class field.
|
||||||
if l, ok := service.Annotations[BetaAnnotationExternalTraffic]; ok {
|
if l, ok := service.Annotations[api.BetaAnnotationExternalTraffic]; ok {
|
||||||
switch l {
|
switch l {
|
||||||
case AnnotationValueExternalTrafficLocal:
|
case api.AnnotationValueExternalTrafficLocal:
|
||||||
return true
|
return true
|
||||||
case AnnotationValueExternalTrafficGlobal:
|
case api.AnnotationValueExternalTrafficGlobal:
|
||||||
return false
|
return false
|
||||||
default:
|
default:
|
||||||
glog.Errorf("Invalid value for annotation %v: %v", BetaAnnotationExternalTraffic, l)
|
glog.Errorf("Invalid value for annotation %v: %v", api.BetaAnnotationExternalTraffic, l)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,10 +107,10 @@ func GetServiceHealthCheckNodePort(service *api.Service) int32 {
|
|||||||
// First check the beta annotation and then the first class field. This is so that
|
// First check the beta annotation and then the first class field. This is so that
|
||||||
// existing Services continue to work till the user decides to transition to the
|
// existing Services continue to work till the user decides to transition to the
|
||||||
// first class field.
|
// first class field.
|
||||||
if l, ok := service.Annotations[BetaAnnotationHealthCheckNodePort]; ok {
|
if l, ok := service.Annotations[api.BetaAnnotationHealthCheckNodePort]; ok {
|
||||||
p, err := strconv.Atoi(l)
|
p, err := strconv.Atoi(l)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to parse annotation %v: %v", BetaAnnotationHealthCheckNodePort, err)
|
glog.Errorf("Failed to parse annotation %v: %v", api.BetaAnnotationHealthCheckNodePort, err)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return int32(p)
|
return int32(p)
|
||||||
@ -122,7 +122,7 @@ func GetServiceHealthCheckNodePort(service *api.Service) int32 {
|
|||||||
// for NodePort / LoadBalancer service to Global for consistency.
|
// for NodePort / LoadBalancer service to Global for consistency.
|
||||||
// TODO: Move this default logic to default.go once beta annotation is deprecated.
|
// TODO: Move this default logic to default.go once beta annotation is deprecated.
|
||||||
func SetDefaultExternalTrafficPolicyIfNeeded(service *api.Service) {
|
func SetDefaultExternalTrafficPolicyIfNeeded(service *api.Service) {
|
||||||
if _, ok := service.Annotations[BetaAnnotationExternalTraffic]; ok {
|
if _, ok := service.Annotations[api.BetaAnnotationExternalTraffic]; ok {
|
||||||
// Don't default this field if beta annotation exists.
|
// Don't default this field if beta annotation exists.
|
||||||
return
|
return
|
||||||
} else if (service.Spec.Type == api.ServiceTypeNodePort ||
|
} else if (service.Spec.Type == api.ServiceTypeNodePort ||
|
||||||
@ -137,8 +137,8 @@ func ClearExternalTrafficPolicy(service *api.Service) {
|
|||||||
// First check the beta annotation and then the first class field. This is so that
|
// First check the beta annotation and then the first class field. This is so that
|
||||||
// existing Services continue to work till the user decides to transition to the
|
// existing Services continue to work till the user decides to transition to the
|
||||||
// first class field.
|
// first class field.
|
||||||
if _, ok := service.Annotations[BetaAnnotationExternalTraffic]; ok {
|
if _, ok := service.Annotations[api.BetaAnnotationExternalTraffic]; ok {
|
||||||
delete(service.Annotations, BetaAnnotationExternalTraffic)
|
delete(service.Annotations, api.BetaAnnotationExternalTraffic)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
service.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyType("")
|
service.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyType("")
|
||||||
@ -150,11 +150,11 @@ func SetServiceHealthCheckNodePort(service *api.Service, hcNodePort int32) {
|
|||||||
// First check the beta annotation and then the first class field. This is so that
|
// First check the beta annotation and then the first class field. This is so that
|
||||||
// existing Services continue to work till the user decides to transition to the
|
// existing Services continue to work till the user decides to transition to the
|
||||||
// first class field.
|
// first class field.
|
||||||
if _, ok := service.Annotations[BetaAnnotationExternalTraffic]; ok {
|
if _, ok := service.Annotations[api.BetaAnnotationExternalTraffic]; ok {
|
||||||
if hcNodePort == 0 {
|
if hcNodePort == 0 {
|
||||||
delete(service.Annotations, BetaAnnotationHealthCheckNodePort)
|
delete(service.Annotations, api.BetaAnnotationHealthCheckNodePort)
|
||||||
} else {
|
} else {
|
||||||
service.Annotations[BetaAnnotationHealthCheckNodePort] = fmt.Sprintf("%d", hcNodePort)
|
service.Annotations[api.BetaAnnotationHealthCheckNodePort] = fmt.Sprintf("%d", hcNodePort)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ import (
|
|||||||
func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
||||||
checkError := func(v string) {
|
checkError := func(v string) {
|
||||||
annotations := make(map[string]string)
|
annotations := make(map[string]string)
|
||||||
annotations[AnnotationLoadBalancerSourceRangesKey] = v
|
annotations[api.AnnotationLoadBalancerSourceRangesKey] = v
|
||||||
svc := api.Service{}
|
svc := api.Service{}
|
||||||
svc.Annotations = annotations
|
svc.Annotations = annotations
|
||||||
_, err := GetLoadBalancerSourceRanges(&svc)
|
_, err := GetLoadBalancerSourceRanges(&svc)
|
||||||
@ -56,7 +56,7 @@ func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
|||||||
|
|
||||||
checkOK := func(v string) netsets.IPNet {
|
checkOK := func(v string) netsets.IPNet {
|
||||||
annotations := make(map[string]string)
|
annotations := make(map[string]string)
|
||||||
annotations[AnnotationLoadBalancerSourceRangesKey] = v
|
annotations[api.AnnotationLoadBalancerSourceRangesKey] = v
|
||||||
svc := api.Service{}
|
svc := api.Service{}
|
||||||
svc.Annotations = annotations
|
svc.Annotations = annotations
|
||||||
cidrs, err := GetLoadBalancerSourceRanges(&svc)
|
cidrs, err := GetLoadBalancerSourceRanges(&svc)
|
||||||
@ -101,7 +101,7 @@ func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// check SourceRanges annotation is empty
|
// check SourceRanges annotation is empty
|
||||||
annotations := make(map[string]string)
|
annotations := make(map[string]string)
|
||||||
annotations[AnnotationLoadBalancerSourceRangesKey] = ""
|
annotations[api.AnnotationLoadBalancerSourceRangesKey] = ""
|
||||||
svc = api.Service{}
|
svc = api.Service{}
|
||||||
svc.Annotations = annotations
|
svc.Annotations = annotations
|
||||||
cidrs, err = GetLoadBalancerSourceRanges(&svc)
|
cidrs, err = GetLoadBalancerSourceRanges(&svc)
|
||||||
@ -226,7 +226,7 @@ func TestNeedsHealthCheck(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: "invalid",
|
api.BetaAnnotationExternalTraffic: "invalid",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -236,7 +236,7 @@ func TestNeedsHealthCheck(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -246,7 +246,7 @@ func TestNeedsHealthCheck(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -291,8 +291,8 @@ func TestGetServiceHealthCheckNodePort(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||||
BetaAnnotationHealthCheckNodePort: "34567",
|
api.BetaAnnotationHealthCheckNodePort: "34567",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -350,7 +350,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -360,7 +360,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -372,7 +372,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -382,7 +382,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -419,7 +419,7 @@ func TestClearExternalTrafficPolicy(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -428,7 +428,7 @@ func TestClearExternalTrafficPolicy(t *testing.T) {
|
|||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
ClearExternalTrafficPolicy(tc.inputService)
|
ClearExternalTrafficPolicy(tc.inputService)
|
||||||
if _, ok := tc.inputService.Annotations[BetaAnnotationExternalTraffic]; ok ||
|
if _, ok := tc.inputService.Annotations[api.BetaAnnotationExternalTraffic]; ok ||
|
||||||
tc.inputService.Spec.ExternalTrafficPolicy != "" {
|
tc.inputService.Spec.ExternalTrafficPolicy != "" {
|
||||||
t.Errorf("%v: failed to clear ExternalTrafficPolicy", i)
|
t.Errorf("%v: failed to clear ExternalTrafficPolicy", i)
|
||||||
spew.Dump(tc)
|
spew.Dump(tc)
|
||||||
@ -471,7 +471,7 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -485,7 +485,7 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -501,7 +501,7 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
|
|||||||
t.Errorf("%v: got HealthCheckNodePort %v, want %v", i, tc.inputService.Spec.HealthCheckNodePort, tc.hcNodePort)
|
t.Errorf("%v: got HealthCheckNodePort %v, want %v", i, tc.inputService.Spec.HealthCheckNodePort, tc.hcNodePort)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
l, ok := tc.inputService.Annotations[BetaAnnotationHealthCheckNodePort]
|
l, ok := tc.inputService.Annotations[api.BetaAnnotationHealthCheckNodePort]
|
||||||
if tc.hcNodePort == 0 {
|
if tc.hcNodePort == 0 {
|
||||||
if ok {
|
if ok {
|
||||||
t.Errorf("%v: HealthCheckNodePort set, want it to be cleared", i)
|
t.Errorf("%v: HealthCheckNodePort set, want it to be cleared", i)
|
||||||
|
@ -72,4 +72,35 @@ const (
|
|||||||
|
|
||||||
// annotation key prefix used to identify non-convertible json paths.
|
// annotation key prefix used to identify non-convertible json paths.
|
||||||
NonConvertibleAnnotationPrefix = "non-convertible.kubernetes.io"
|
NonConvertibleAnnotationPrefix = "non-convertible.kubernetes.io"
|
||||||
|
|
||||||
|
kubectlPrefix = "kubectl.kubernetes.io/"
|
||||||
|
|
||||||
|
// LastAppliedConfigAnnotation is the annotation used to store the previous
|
||||||
|
// configuration of a resource for use in a three way diff by UpdateApplyAnnotation.
|
||||||
|
LastAppliedConfigAnnotation = kubectlPrefix + "last-applied-configuration"
|
||||||
|
|
||||||
|
// AnnotationLoadBalancerSourceRangesKey is the key of the annotation on a service to set allowed ingress ranges on their LoadBalancers
|
||||||
|
//
|
||||||
|
// It should be a comma-separated list of CIDRs, e.g. `0.0.0.0/0` to
|
||||||
|
// allow full access (the default) or `18.0.0.0/8,56.0.0.0/8` to allow
|
||||||
|
// access only from the CIDRs currently allocated to MIT & the USPS.
|
||||||
|
//
|
||||||
|
// Not all cloud providers support this annotation, though AWS & GCE do.
|
||||||
|
AnnotationLoadBalancerSourceRangesKey = "service.beta.kubernetes.io/load-balancer-source-ranges"
|
||||||
|
|
||||||
|
// AnnotationValueExternalTrafficLocal Value of annotation to specify local endpoints behavior.
|
||||||
|
AnnotationValueExternalTrafficLocal = "OnlyLocal"
|
||||||
|
// AnnotationValueExternalTrafficGlobal Value of annotation to specify global (legacy) behavior.
|
||||||
|
AnnotationValueExternalTrafficGlobal = "Global"
|
||||||
|
|
||||||
|
// TODO: The beta annotations have been deprecated, remove them when we release k8s 1.8.
|
||||||
|
|
||||||
|
// BetaAnnotationHealthCheckNodePort Annotation specifying the healthcheck nodePort for the service.
|
||||||
|
// If not specified, annotation is created by the service api backend with the allocated nodePort.
|
||||||
|
// Will use user-specified nodePort value if specified by the client.
|
||||||
|
BetaAnnotationHealthCheckNodePort = "service.beta.kubernetes.io/healthcheck-nodeport"
|
||||||
|
|
||||||
|
// BetaAnnotationExternalTraffic An annotation that denotes if this Service desires to route
|
||||||
|
// external traffic to local endpoints only. This preserves Source IP and avoids a second hop.
|
||||||
|
BetaAnnotationExternalTraffic = "service.beta.kubernetes.io/external-traffic"
|
||||||
)
|
)
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2016 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 service
|
|
||||||
|
|
||||||
const (
|
|
||||||
// AnnotationLoadBalancerSourceRangesKey is the key of the annotation on a service to set allowed ingress ranges on their LoadBalancers
|
|
||||||
//
|
|
||||||
// It should be a comma-separated list of CIDRs, e.g. `0.0.0.0/0` to
|
|
||||||
// allow full access (the default) or `18.0.0.0/8,56.0.0.0/8` to allow
|
|
||||||
// access only from the CIDRs currently allocated to MIT & the USPS.
|
|
||||||
//
|
|
||||||
// Not all cloud providers support this annotation, though AWS & GCE do.
|
|
||||||
AnnotationLoadBalancerSourceRangesKey = "service.beta.kubernetes.io/load-balancer-source-ranges"
|
|
||||||
|
|
||||||
// AnnotationValueExternalTrafficLocal Value of annotation to specify local endpoints behavior.
|
|
||||||
AnnotationValueExternalTrafficLocal = "OnlyLocal"
|
|
||||||
// AnnotationValueExternalTrafficGlobal Value of annotation to specify global (legacy) behavior.
|
|
||||||
AnnotationValueExternalTrafficGlobal = "Global"
|
|
||||||
|
|
||||||
// TODO: The beta annotations have been deprecated, remove them when we release k8s 1.8.
|
|
||||||
|
|
||||||
// BetaAnnotationHealthCheckNodePort Annotation specifying the healthcheck nodePort for the service.
|
|
||||||
// If not specified, annotation is created by the service api backend with the allocated nodePort.
|
|
||||||
// Will use user-specified nodePort value if specified by the client.
|
|
||||||
BetaAnnotationHealthCheckNodePort = "service.beta.kubernetes.io/healthcheck-nodeport"
|
|
||||||
|
|
||||||
// BetaAnnotationExternalTraffic An annotation that denotes if this Service desires to route
|
|
||||||
// external traffic to local endpoints only. This preserves Source IP and avoids a second hop.
|
|
||||||
BetaAnnotationExternalTraffic = "service.beta.kubernetes.io/external-traffic"
|
|
||||||
)
|
|
@ -56,7 +56,7 @@ func GetLoadBalancerSourceRanges(service *v1.Service) (netsets.IPNet, error) {
|
|||||||
return nil, fmt.Errorf("service.Spec.LoadBalancerSourceRanges: %v is not valid. Expecting a list of IP ranges. For example, 10.0.0.0/24. Error msg: %v", specs, err)
|
return nil, fmt.Errorf("service.Spec.LoadBalancerSourceRanges: %v is not valid. Expecting a list of IP ranges. For example, 10.0.0.0/24. Error msg: %v", specs, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val := service.Annotations[AnnotationLoadBalancerSourceRangesKey]
|
val := service.Annotations[v1.AnnotationLoadBalancerSourceRangesKey]
|
||||||
val = strings.TrimSpace(val)
|
val = strings.TrimSpace(val)
|
||||||
if val == "" {
|
if val == "" {
|
||||||
val = defaultLoadBalancerSourceRanges
|
val = defaultLoadBalancerSourceRanges
|
||||||
@ -64,7 +64,7 @@ func GetLoadBalancerSourceRanges(service *v1.Service) (netsets.IPNet, error) {
|
|||||||
specs := strings.Split(val, ",")
|
specs := strings.Split(val, ",")
|
||||||
ipnets, err = netsets.ParseIPNets(specs...)
|
ipnets, err = netsets.ParseIPNets(specs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %s is not valid. Expecting a comma-separated list of source IP ranges. For example, 10.0.0.0/24,192.168.2.0/24", AnnotationLoadBalancerSourceRangesKey, val)
|
return nil, fmt.Errorf("%s: %s is not valid. Expecting a comma-separated list of source IP ranges. For example, 10.0.0.0/24,192.168.2.0/24", v1.AnnotationLoadBalancerSourceRangesKey, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ipnets, nil
|
return ipnets, nil
|
||||||
@ -80,14 +80,14 @@ func RequestsOnlyLocalTraffic(service *v1.Service) bool {
|
|||||||
// First check the beta annotation and then the first class field. This is so that
|
// First check the beta annotation and then the first class field. This is so that
|
||||||
// existing Services continue to work till the user decides to transition to the
|
// existing Services continue to work till the user decides to transition to the
|
||||||
// first class field.
|
// first class field.
|
||||||
if l, ok := service.Annotations[BetaAnnotationExternalTraffic]; ok {
|
if l, ok := service.Annotations[v1.BetaAnnotationExternalTraffic]; ok {
|
||||||
switch l {
|
switch l {
|
||||||
case AnnotationValueExternalTrafficLocal:
|
case v1.AnnotationValueExternalTrafficLocal:
|
||||||
return true
|
return true
|
||||||
case AnnotationValueExternalTrafficGlobal:
|
case v1.AnnotationValueExternalTrafficGlobal:
|
||||||
return false
|
return false
|
||||||
default:
|
default:
|
||||||
glog.Errorf("Invalid value for annotation %v: %v", BetaAnnotationExternalTraffic, l)
|
glog.Errorf("Invalid value for annotation %v: %v", v1.BetaAnnotationExternalTraffic, l)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,10 +107,10 @@ func GetServiceHealthCheckNodePort(service *v1.Service) int32 {
|
|||||||
// First check the beta annotation and then the first class field. This is so that
|
// First check the beta annotation and then the first class field. This is so that
|
||||||
// existing Services continue to work till the user decides to transition to the
|
// existing Services continue to work till the user decides to transition to the
|
||||||
// first class field.
|
// first class field.
|
||||||
if l, ok := service.Annotations[BetaAnnotationHealthCheckNodePort]; ok {
|
if l, ok := service.Annotations[v1.BetaAnnotationHealthCheckNodePort]; ok {
|
||||||
p, err := strconv.Atoi(l)
|
p, err := strconv.Atoi(l)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to parse annotation %v: %v", BetaAnnotationHealthCheckNodePort, err)
|
glog.Errorf("Failed to parse annotation %v: %v", v1.BetaAnnotationHealthCheckNodePort, err)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return int32(p)
|
return int32(p)
|
||||||
@ -122,7 +122,7 @@ func GetServiceHealthCheckNodePort(service *v1.Service) int32 {
|
|||||||
// for NodePort / LoadBalancer service to Global for consistency.
|
// for NodePort / LoadBalancer service to Global for consistency.
|
||||||
// TODO: Move this default logic to default.go once beta annotation is deprecated.
|
// TODO: Move this default logic to default.go once beta annotation is deprecated.
|
||||||
func SetDefaultExternalTrafficPolicyIfNeeded(service *v1.Service) {
|
func SetDefaultExternalTrafficPolicyIfNeeded(service *v1.Service) {
|
||||||
if _, ok := service.Annotations[BetaAnnotationExternalTraffic]; ok {
|
if _, ok := service.Annotations[v1.BetaAnnotationExternalTraffic]; ok {
|
||||||
// Don't default this field if beta annotation exists.
|
// Don't default this field if beta annotation exists.
|
||||||
return
|
return
|
||||||
} else if (service.Spec.Type == v1.ServiceTypeNodePort ||
|
} else if (service.Spec.Type == v1.ServiceTypeNodePort ||
|
||||||
@ -136,8 +136,8 @@ func SetDefaultExternalTrafficPolicyIfNeeded(service *v1.Service) {
|
|||||||
func ClearExternalTrafficPolicy(service *v1.Service) {
|
func ClearExternalTrafficPolicy(service *v1.Service) {
|
||||||
// First check the beta annotation and then the first class field. This is so existing
|
// First check the beta annotation and then the first class field. This is so existing
|
||||||
// Services continue to work till the user decides to transition to the first class field.
|
// Services continue to work till the user decides to transition to the first class field.
|
||||||
if _, ok := service.Annotations[BetaAnnotationExternalTraffic]; ok {
|
if _, ok := service.Annotations[v1.BetaAnnotationExternalTraffic]; ok {
|
||||||
delete(service.Annotations, BetaAnnotationExternalTraffic)
|
delete(service.Annotations, v1.BetaAnnotationExternalTraffic)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
service.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyType("")
|
service.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyType("")
|
||||||
@ -149,11 +149,11 @@ func SetServiceHealthCheckNodePort(service *v1.Service, hcNodePort int32) {
|
|||||||
// First check the beta annotation and then the first class field. This is so that
|
// First check the beta annotation and then the first class field. This is so that
|
||||||
// existing Services continue to work till the user decides to transition to the
|
// existing Services continue to work till the user decides to transition to the
|
||||||
// first class field.
|
// first class field.
|
||||||
if _, ok := service.Annotations[BetaAnnotationExternalTraffic]; ok {
|
if _, ok := service.Annotations[v1.BetaAnnotationExternalTraffic]; ok {
|
||||||
if hcNodePort == 0 {
|
if hcNodePort == 0 {
|
||||||
delete(service.Annotations, BetaAnnotationHealthCheckNodePort)
|
delete(service.Annotations, v1.BetaAnnotationHealthCheckNodePort)
|
||||||
} else {
|
} else {
|
||||||
service.Annotations[BetaAnnotationHealthCheckNodePort] = fmt.Sprintf("%d", hcNodePort)
|
service.Annotations[v1.BetaAnnotationHealthCheckNodePort] = fmt.Sprintf("%d", hcNodePort)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ import (
|
|||||||
func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
||||||
checkError := func(v string) {
|
checkError := func(v string) {
|
||||||
annotations := make(map[string]string)
|
annotations := make(map[string]string)
|
||||||
annotations[AnnotationLoadBalancerSourceRangesKey] = v
|
annotations[v1.AnnotationLoadBalancerSourceRangesKey] = v
|
||||||
svc := v1.Service{}
|
svc := v1.Service{}
|
||||||
svc.Annotations = annotations
|
svc.Annotations = annotations
|
||||||
_, err := GetLoadBalancerSourceRanges(&svc)
|
_, err := GetLoadBalancerSourceRanges(&svc)
|
||||||
@ -56,7 +56,7 @@ func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
|||||||
|
|
||||||
checkOK := func(v string) netsets.IPNet {
|
checkOK := func(v string) netsets.IPNet {
|
||||||
annotations := make(map[string]string)
|
annotations := make(map[string]string)
|
||||||
annotations[AnnotationLoadBalancerSourceRangesKey] = v
|
annotations[v1.AnnotationLoadBalancerSourceRangesKey] = v
|
||||||
svc := v1.Service{}
|
svc := v1.Service{}
|
||||||
svc.Annotations = annotations
|
svc.Annotations = annotations
|
||||||
cidrs, err := GetLoadBalancerSourceRanges(&svc)
|
cidrs, err := GetLoadBalancerSourceRanges(&svc)
|
||||||
@ -101,7 +101,7 @@ func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// check SourceRanges annotation is empty
|
// check SourceRanges annotation is empty
|
||||||
annotations := make(map[string]string)
|
annotations := make(map[string]string)
|
||||||
annotations[AnnotationLoadBalancerSourceRangesKey] = ""
|
annotations[v1.AnnotationLoadBalancerSourceRangesKey] = ""
|
||||||
svc = v1.Service{}
|
svc = v1.Service{}
|
||||||
svc.Annotations = annotations
|
svc.Annotations = annotations
|
||||||
cidrs, err = GetLoadBalancerSourceRanges(&svc)
|
cidrs, err = GetLoadBalancerSourceRanges(&svc)
|
||||||
@ -226,7 +226,7 @@ func TestNeedsHealthCheck(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: "invalid",
|
v1.BetaAnnotationExternalTraffic: "invalid",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -236,7 +236,7 @@ func TestNeedsHealthCheck(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficGlobal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -246,7 +246,7 @@ func TestNeedsHealthCheck(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -291,8 +291,8 @@ func TestGetServiceHealthCheckNodePort(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal,
|
||||||
BetaAnnotationHealthCheckNodePort: "34567",
|
v1.BetaAnnotationHealthCheckNodePort: "34567",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -350,7 +350,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -360,7 +360,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -372,7 +372,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficGlobal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -382,7 +382,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficGlobal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -419,7 +419,7 @@ func TestClearExternalTrafficPolicy(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -428,7 +428,7 @@ func TestClearExternalTrafficPolicy(t *testing.T) {
|
|||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
ClearExternalTrafficPolicy(tc.inputService)
|
ClearExternalTrafficPolicy(tc.inputService)
|
||||||
if _, ok := tc.inputService.Annotations[BetaAnnotationExternalTraffic]; ok ||
|
if _, ok := tc.inputService.Annotations[v1.BetaAnnotationExternalTraffic]; ok ||
|
||||||
tc.inputService.Spec.ExternalTrafficPolicy != "" {
|
tc.inputService.Spec.ExternalTrafficPolicy != "" {
|
||||||
t.Errorf("%v: failed to clear ExternalTrafficPolicy", i)
|
t.Errorf("%v: failed to clear ExternalTrafficPolicy", i)
|
||||||
spew.Dump(tc)
|
spew.Dump(tc)
|
||||||
@ -471,7 +471,7 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficGlobal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -485,7 +485,7 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficGlobal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -501,7 +501,7 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
|
|||||||
t.Errorf("%v: got HealthCheckNodePort %v, want %v", i, tc.inputService.Spec.HealthCheckNodePort, tc.hcNodePort)
|
t.Errorf("%v: got HealthCheckNodePort %v, want %v", i, tc.inputService.Spec.HealthCheckNodePort, tc.hcNodePort)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
l, ok := tc.inputService.Annotations[BetaAnnotationHealthCheckNodePort]
|
l, ok := tc.inputService.Annotations[v1.BetaAnnotationHealthCheckNodePort]
|
||||||
if tc.hcNodePort == 0 {
|
if tc.hcNodePort == 0 {
|
||||||
if ok {
|
if ok {
|
||||||
t.Errorf("%v: HealthCheckNodePort set, want it to be cleared", i)
|
t.Errorf("%v: HealthCheckNodePort set, want it to be cleared", i)
|
||||||
|
@ -2735,7 +2735,7 @@ func ValidateService(service *api.Service) field.ErrorList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate SourceRange field and annotation
|
// Validate SourceRange field and annotation
|
||||||
_, ok := service.Annotations[apiservice.AnnotationLoadBalancerSourceRangesKey]
|
_, ok := service.Annotations[api.AnnotationLoadBalancerSourceRangesKey]
|
||||||
if len(service.Spec.LoadBalancerSourceRanges) > 0 || ok {
|
if len(service.Spec.LoadBalancerSourceRanges) > 0 || ok {
|
||||||
var fieldPath *field.Path
|
var fieldPath *field.Path
|
||||||
var val string
|
var val string
|
||||||
@ -2743,8 +2743,8 @@ func ValidateService(service *api.Service) field.ErrorList {
|
|||||||
fieldPath = specPath.Child("LoadBalancerSourceRanges")
|
fieldPath = specPath.Child("LoadBalancerSourceRanges")
|
||||||
val = fmt.Sprintf("%v", service.Spec.LoadBalancerSourceRanges)
|
val = fmt.Sprintf("%v", service.Spec.LoadBalancerSourceRanges)
|
||||||
} else {
|
} else {
|
||||||
fieldPath = field.NewPath("metadata", "annotations").Key(apiservice.AnnotationLoadBalancerSourceRangesKey)
|
fieldPath = field.NewPath("metadata", "annotations").Key(api.AnnotationLoadBalancerSourceRangesKey)
|
||||||
val = service.Annotations[apiservice.AnnotationLoadBalancerSourceRangesKey]
|
val = service.Annotations[api.AnnotationLoadBalancerSourceRangesKey]
|
||||||
}
|
}
|
||||||
if service.Spec.Type != api.ServiceTypeLoadBalancer {
|
if service.Spec.Type != api.ServiceTypeLoadBalancer {
|
||||||
allErrs = append(allErrs, field.Invalid(fieldPath, "", "may only be used when `type` is 'LoadBalancer'"))
|
allErrs = append(allErrs, field.Invalid(fieldPath, "", "may only be used when `type` is 'LoadBalancer'"))
|
||||||
@ -2805,20 +2805,20 @@ func validateServiceExternalTrafficFieldsValue(service *api.Service) field.Error
|
|||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
|
|
||||||
// Check beta annotations.
|
// Check beta annotations.
|
||||||
if l, ok := service.Annotations[apiservice.BetaAnnotationExternalTraffic]; ok {
|
if l, ok := service.Annotations[api.BetaAnnotationExternalTraffic]; ok {
|
||||||
if l != apiservice.AnnotationValueExternalTrafficLocal &&
|
if l != api.AnnotationValueExternalTrafficLocal &&
|
||||||
l != apiservice.AnnotationValueExternalTrafficGlobal {
|
l != api.AnnotationValueExternalTrafficGlobal {
|
||||||
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(apiservice.BetaAnnotationExternalTraffic), l,
|
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(api.BetaAnnotationExternalTraffic), l,
|
||||||
fmt.Sprintf("ExternalTraffic must be %v or %v", apiservice.AnnotationValueExternalTrafficLocal, apiservice.AnnotationValueExternalTrafficGlobal)))
|
fmt.Sprintf("ExternalTraffic must be %v or %v", api.AnnotationValueExternalTrafficLocal, api.AnnotationValueExternalTrafficGlobal)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if l, ok := service.Annotations[apiservice.BetaAnnotationHealthCheckNodePort]; ok {
|
if l, ok := service.Annotations[api.BetaAnnotationHealthCheckNodePort]; ok {
|
||||||
p, err := strconv.Atoi(l)
|
p, err := strconv.Atoi(l)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(apiservice.BetaAnnotationHealthCheckNodePort), l,
|
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(api.BetaAnnotationHealthCheckNodePort), l,
|
||||||
"HealthCheckNodePort must be a valid port number"))
|
"HealthCheckNodePort must be a valid port number"))
|
||||||
} else if p <= 0 {
|
} else if p <= 0 {
|
||||||
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(apiservice.BetaAnnotationHealthCheckNodePort), l,
|
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(api.BetaAnnotationHealthCheckNodePort), l,
|
||||||
"HealthCheckNodePort must be greater than 0"))
|
"HealthCheckNodePort must be greater than 0"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2857,8 +2857,8 @@ func (s *serviceExternalTrafficStatus) useBetaHealthCheckWithGA() bool {
|
|||||||
|
|
||||||
func getServiceExternalTrafficStatus(service *api.Service) *serviceExternalTrafficStatus {
|
func getServiceExternalTrafficStatus(service *api.Service) *serviceExternalTrafficStatus {
|
||||||
s := serviceExternalTrafficStatus{}
|
s := serviceExternalTrafficStatus{}
|
||||||
_, s.betaExternalTrafficIsSet = service.Annotations[apiservice.BetaAnnotationExternalTraffic]
|
_, s.betaExternalTrafficIsSet = service.Annotations[api.BetaAnnotationExternalTraffic]
|
||||||
_, s.betaHealthCheckIsSet = service.Annotations[apiservice.BetaAnnotationHealthCheckNodePort]
|
_, s.betaHealthCheckIsSet = service.Annotations[api.BetaAnnotationHealthCheckNodePort]
|
||||||
s.gaExternalTrafficIsSet = service.Spec.ExternalTrafficPolicy != ""
|
s.gaExternalTrafficIsSet = service.Spec.ExternalTrafficPolicy != ""
|
||||||
s.gaHealthCheckIsSet = service.Spec.HealthCheckNodePort != 0
|
s.gaHealthCheckIsSet = service.Spec.HealthCheckNodePort != 0
|
||||||
return &s
|
return &s
|
||||||
@ -2872,15 +2872,15 @@ func validateServiceExternalTrafficAPIVersion(service *api.Service) field.ErrorL
|
|||||||
status := getServiceExternalTrafficStatus(service)
|
status := getServiceExternalTrafficStatus(service)
|
||||||
|
|
||||||
if status.useBetaExternalTrafficWithGA() {
|
if status.useBetaExternalTrafficWithGA() {
|
||||||
fieldPath := field.NewPath("metadata", "annotations").Key(apiservice.BetaAnnotationExternalTraffic)
|
fieldPath := field.NewPath("metadata", "annotations").Key(api.BetaAnnotationExternalTraffic)
|
||||||
msg := fmt.Sprintf("please replace the beta annotation with 'ExternalTrafficPolicy' field")
|
msg := fmt.Sprintf("please replace the beta annotation with 'ExternalTrafficPolicy' field")
|
||||||
allErrs = append(allErrs, field.Invalid(fieldPath, apiservice.BetaAnnotationExternalTraffic, msg))
|
allErrs = append(allErrs, field.Invalid(fieldPath, api.BetaAnnotationExternalTraffic, msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
if status.useBetaHealthCheckWithGA() {
|
if status.useBetaHealthCheckWithGA() {
|
||||||
fieldPath := field.NewPath("metadata", "annotations").Key(apiservice.BetaAnnotationHealthCheckNodePort)
|
fieldPath := field.NewPath("metadata", "annotations").Key(api.BetaAnnotationHealthCheckNodePort)
|
||||||
msg := fmt.Sprintf("please replace the beta annotation with 'HealthCheckNodePort' field")
|
msg := fmt.Sprintf("please replace the beta annotation with 'HealthCheckNodePort' field")
|
||||||
allErrs = append(allErrs, field.Invalid(fieldPath, apiservice.BetaAnnotationHealthCheckNodePort, msg))
|
allErrs = append(allErrs, field.Invalid(fieldPath, api.BetaAnnotationHealthCheckNodePort, msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
return allErrs
|
return allErrs
|
||||||
|
@ -30,7 +30,6 @@ import (
|
|||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/helper"
|
"k8s.io/kubernetes/pkg/api/helper"
|
||||||
"k8s.io/kubernetes/pkg/api/service"
|
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
"k8s.io/kubernetes/pkg/capabilities"
|
"k8s.io/kubernetes/pkg/capabilities"
|
||||||
"k8s.io/kubernetes/pkg/security/apparmor"
|
"k8s.io/kubernetes/pkg/security/apparmor"
|
||||||
@ -5719,7 +5718,7 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "valid LoadBalancer source range annotation",
|
name: "valid LoadBalancer source range annotation",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
s.Annotations[service.AnnotationLoadBalancerSourceRangesKey] = "1.2.3.4/8, 5.6.7.8/16"
|
s.Annotations[api.AnnotationLoadBalancerSourceRangesKey] = "1.2.3.4/8, 5.6.7.8/16"
|
||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
},
|
},
|
||||||
@ -5727,14 +5726,14 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "empty LoadBalancer source range annotation",
|
name: "empty LoadBalancer source range annotation",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
s.Annotations[service.AnnotationLoadBalancerSourceRangesKey] = ""
|
s.Annotations[api.AnnotationLoadBalancerSourceRangesKey] = ""
|
||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid LoadBalancer source range annotation (hostname)",
|
name: "invalid LoadBalancer source range annotation (hostname)",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Annotations[service.AnnotationLoadBalancerSourceRangesKey] = "foo.bar"
|
s.Annotations[api.AnnotationLoadBalancerSourceRangesKey] = "foo.bar"
|
||||||
},
|
},
|
||||||
numErrs: 2,
|
numErrs: 2,
|
||||||
},
|
},
|
||||||
@ -5742,7 +5741,7 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "invalid LoadBalancer source range annotation (invalid CIDR)",
|
name: "invalid LoadBalancer source range annotation (invalid CIDR)",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
s.Annotations[service.AnnotationLoadBalancerSourceRangesKey] = "1.2.3.4/33"
|
s.Annotations[api.AnnotationLoadBalancerSourceRangesKey] = "1.2.3.4/33"
|
||||||
},
|
},
|
||||||
numErrs: 1,
|
numErrs: 1,
|
||||||
},
|
},
|
||||||
@ -5834,7 +5833,7 @@ func TestValidateService(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "LoadBalancer allows onlyLocal beta annotations",
|
name: "LoadBalancer allows onlyLocal beta annotations",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
},
|
},
|
||||||
@ -5842,7 +5841,7 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "invalid externalTraffic beta annotation",
|
name: "invalid externalTraffic beta annotation",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
s.Annotations[service.BetaAnnotationExternalTraffic] = "invalid"
|
s.Annotations[api.BetaAnnotationExternalTraffic] = "invalid"
|
||||||
},
|
},
|
||||||
numErrs: 1,
|
numErrs: 1,
|
||||||
},
|
},
|
||||||
@ -5850,8 +5849,8 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "nagative healthCheckNodePort beta annotation",
|
name: "nagative healthCheckNodePort beta annotation",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
s.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||||
s.Annotations[service.BetaAnnotationHealthCheckNodePort] = "-1"
|
s.Annotations[api.BetaAnnotationHealthCheckNodePort] = "-1"
|
||||||
},
|
},
|
||||||
numErrs: 1,
|
numErrs: 1,
|
||||||
},
|
},
|
||||||
@ -5859,8 +5858,8 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "invalid healthCheckNodePort beta annotation",
|
name: "invalid healthCheckNodePort beta annotation",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
s.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||||
s.Annotations[service.BetaAnnotationHealthCheckNodePort] = "whatisthis"
|
s.Annotations[api.BetaAnnotationHealthCheckNodePort] = "whatisthis"
|
||||||
},
|
},
|
||||||
numErrs: 1,
|
numErrs: 1,
|
||||||
},
|
},
|
||||||
@ -5868,8 +5867,8 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "valid healthCheckNodePort beta annotation",
|
name: "valid healthCheckNodePort beta annotation",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
s.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||||
s.Annotations[service.BetaAnnotationHealthCheckNodePort] = "31100"
|
s.Annotations[api.BetaAnnotationHealthCheckNodePort] = "31100"
|
||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
},
|
},
|
||||||
@ -5903,7 +5902,7 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "disallows use ExternalTraffic beta annotation with first class field",
|
name: "disallows use ExternalTraffic beta annotation with first class field",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
s.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||||
s.Spec.HealthCheckNodePort = 3001
|
s.Spec.HealthCheckNodePort = 3001
|
||||||
},
|
},
|
||||||
numErrs: 1,
|
numErrs: 1,
|
||||||
@ -5912,7 +5911,7 @@ func TestValidateService(t *testing.T) {
|
|||||||
name: "disallows duplicated ExternalTraffic beta annotation with first class field",
|
name: "disallows duplicated ExternalTraffic beta annotation with first class field",
|
||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
s.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||||
s.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
|
s.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
|
||||||
},
|
},
|
||||||
numErrs: 1,
|
numErrs: 1,
|
||||||
@ -5922,7 +5921,7 @@ func TestValidateService(t *testing.T) {
|
|||||||
tweakSvc: func(s *api.Service) {
|
tweakSvc: func(s *api.Service) {
|
||||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
s.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
|
s.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
|
||||||
s.Annotations[service.BetaAnnotationHealthCheckNodePort] = "3001"
|
s.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||||
},
|
},
|
||||||
numErrs: 1,
|
numErrs: 1,
|
||||||
},
|
},
|
||||||
@ -7389,8 +7388,8 @@ func TestValidateServiceUpdate(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Service allows removing onlyLocal beta annotations",
|
name: "Service allows removing onlyLocal beta annotations",
|
||||||
tweakSvc: func(oldSvc, newSvc *api.Service) {
|
tweakSvc: func(oldSvc, newSvc *api.Service) {
|
||||||
oldSvc.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
oldSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||||
oldSvc.Annotations[service.BetaAnnotationHealthCheckNodePort] = "3001"
|
oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
},
|
},
|
||||||
@ -7398,11 +7397,11 @@ func TestValidateServiceUpdate(t *testing.T) {
|
|||||||
name: "Service allows modifying onlyLocal beta annotations",
|
name: "Service allows modifying onlyLocal beta annotations",
|
||||||
tweakSvc: func(oldSvc, newSvc *api.Service) {
|
tweakSvc: func(oldSvc, newSvc *api.Service) {
|
||||||
oldSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
oldSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
oldSvc.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
oldSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||||
oldSvc.Annotations[service.BetaAnnotationHealthCheckNodePort] = "3001"
|
oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||||
newSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
newSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
newSvc.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficGlobal
|
newSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficGlobal
|
||||||
newSvc.Annotations[service.BetaAnnotationHealthCheckNodePort] = oldSvc.Annotations[service.BetaAnnotationHealthCheckNodePort]
|
newSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort]
|
||||||
},
|
},
|
||||||
numErrs: 0,
|
numErrs: 0,
|
||||||
},
|
},
|
||||||
@ -7410,11 +7409,11 @@ func TestValidateServiceUpdate(t *testing.T) {
|
|||||||
name: "Service disallows promoting one of the onlyLocal pair to GA",
|
name: "Service disallows promoting one of the onlyLocal pair to GA",
|
||||||
tweakSvc: func(oldSvc, newSvc *api.Service) {
|
tweakSvc: func(oldSvc, newSvc *api.Service) {
|
||||||
oldSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
oldSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
oldSvc.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
oldSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||||
oldSvc.Annotations[service.BetaAnnotationHealthCheckNodePort] = "3001"
|
oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||||
newSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
newSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
newSvc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
|
newSvc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
|
||||||
newSvc.Annotations[service.BetaAnnotationHealthCheckNodePort] = oldSvc.Annotations[service.BetaAnnotationHealthCheckNodePort]
|
newSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort]
|
||||||
},
|
},
|
||||||
numErrs: 1,
|
numErrs: 1,
|
||||||
},
|
},
|
||||||
@ -7422,8 +7421,8 @@ func TestValidateServiceUpdate(t *testing.T) {
|
|||||||
name: "Service allows changing both onlyLocal annotations from beta to GA",
|
name: "Service allows changing both onlyLocal annotations from beta to GA",
|
||||||
tweakSvc: func(oldSvc, newSvc *api.Service) {
|
tweakSvc: func(oldSvc, newSvc *api.Service) {
|
||||||
oldSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
oldSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
oldSvc.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
oldSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||||
oldSvc.Annotations[service.BetaAnnotationHealthCheckNodePort] = "3001"
|
oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||||
newSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
newSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
newSvc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
|
newSvc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
|
||||||
newSvc.Spec.HealthCheckNodePort = 3001
|
newSvc.Spec.HealthCheckNodePort = 3001
|
||||||
|
@ -35,7 +35,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/client-go/util/integer"
|
"k8s.io/client-go/util/integer"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/annotations"
|
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
internalextensions "k8s.io/kubernetes/pkg/apis/extensions"
|
internalextensions "k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
||||||
@ -285,12 +284,12 @@ func SetNewReplicaSetAnnotations(deployment *extensions.Deployment, newRS *exten
|
|||||||
}
|
}
|
||||||
|
|
||||||
var annotationsToSkip = map[string]bool{
|
var annotationsToSkip = map[string]bool{
|
||||||
annotations.LastAppliedConfigAnnotation: true,
|
v1.LastAppliedConfigAnnotation: true,
|
||||||
RevisionAnnotation: true,
|
RevisionAnnotation: true,
|
||||||
RevisionHistoryAnnotation: true,
|
RevisionHistoryAnnotation: true,
|
||||||
DesiredReplicasAnnotation: true,
|
DesiredReplicasAnnotation: true,
|
||||||
MaxReplicasAnnotation: true,
|
MaxReplicasAnnotation: true,
|
||||||
OverlapAnnotation: true,
|
OverlapAnnotation: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// skipCopyAnnotation returns true if we should skip copying the annotation with the given annotation key
|
// skipCopyAnnotation returns true if we should skip copying the annotation with the given annotation key
|
||||||
|
@ -19,7 +19,7 @@ package kubectl
|
|||||||
import (
|
import (
|
||||||
"k8s.io/apimachinery/pkg/api/meta"
|
"k8s.io/apimachinery/pkg/api/meta"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/kubernetes/pkg/api/annotations"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ func GetOriginalConfiguration(mapping *meta.RESTMapping, obj runtime.Object) ([]
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
original, ok := annots[annotations.LastAppliedConfigAnnotation]
|
original, ok := annots[api.LastAppliedConfigAnnotation]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ func SetOriginalConfiguration(info *resource.Info, original []byte) error {
|
|||||||
annots = map[string]string{}
|
annots = map[string]string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
annots[annotations.LastAppliedConfigAnnotation] = string(original)
|
annots[api.LastAppliedConfigAnnotation] = string(original)
|
||||||
if err := info.Mapping.MetadataAccessor.SetAnnotations(info.Object, annots); err != nil {
|
if err := info.Mapping.MetadataAccessor.SetAnnotations(info.Object, annots); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -89,8 +89,8 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
|||||||
annots = map[string]string{}
|
annots = map[string]string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
original := annots[annotations.LastAppliedConfigAnnotation]
|
original := annots[api.LastAppliedConfigAnnotation]
|
||||||
delete(annots, annotations.LastAppliedConfigAnnotation)
|
delete(annots, api.LastAppliedConfigAnnotation)
|
||||||
accessor.SetAnnotations(annots)
|
accessor.SetAnnotations(annots)
|
||||||
// TODO: this needs to be abstracted - there should be no assumption that versioned object
|
// TODO: this needs to be abstracted - there should be no assumption that versioned object
|
||||||
// can be marshalled to JSON.
|
// can be marshalled to JSON.
|
||||||
@ -100,7 +100,7 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
|||||||
}
|
}
|
||||||
|
|
||||||
if annotate {
|
if annotate {
|
||||||
annots[annotations.LastAppliedConfigAnnotation] = string(modified)
|
annots[api.LastAppliedConfigAnnotation] = string(modified)
|
||||||
accessor.SetAnnotations(annots)
|
accessor.SetAnnotations(annots)
|
||||||
// TODO: this needs to be abstracted - there should be no assumption that versioned object
|
// TODO: this needs to be abstracted - there should be no assumption that versioned object
|
||||||
// can be marshalled to JSON.
|
// can be marshalled to JSON.
|
||||||
@ -111,7 +111,7 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Restore the object to its original condition.
|
// Restore the object to its original condition.
|
||||||
annots[annotations.LastAppliedConfigAnnotation] = original
|
annots[api.LastAppliedConfigAnnotation] = original
|
||||||
accessor.SetAnnotations(annots)
|
accessor.SetAnnotations(annots)
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, use the server side version of the object.
|
// Otherwise, use the server side version of the object.
|
||||||
@ -126,8 +126,8 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
|||||||
annots = map[string]string{}
|
annots = map[string]string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
original := annots[annotations.LastAppliedConfigAnnotation]
|
original := annots[api.LastAppliedConfigAnnotation]
|
||||||
delete(annots, annotations.LastAppliedConfigAnnotation)
|
delete(annots, api.LastAppliedConfigAnnotation)
|
||||||
if err := accessor.SetAnnotations(info.Object, annots); err != nil {
|
if err := accessor.SetAnnotations(info.Object, annots); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
|||||||
}
|
}
|
||||||
|
|
||||||
if annotate {
|
if annotate {
|
||||||
annots[annotations.LastAppliedConfigAnnotation] = string(modified)
|
annots[api.LastAppliedConfigAnnotation] = string(modified)
|
||||||
if err := info.Mapping.MetadataAccessor.SetAnnotations(info.Object, annots); err != nil {
|
if err := info.Mapping.MetadataAccessor.SetAnnotations(info.Object, annots); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Restore the object to its original condition.
|
// Restore the object to its original condition.
|
||||||
annots[annotations.LastAppliedConfigAnnotation] = original
|
annots[api.LastAppliedConfigAnnotation] = original
|
||||||
if err := info.Mapping.MetadataAccessor.SetAnnotations(info.Object, annots); err != nil {
|
if err := info.Mapping.MetadataAccessor.SetAnnotations(info.Object, annots); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/annotations"
|
|
||||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||||
"k8s.io/kubernetes/pkg/kubectl"
|
"k8s.io/kubernetes/pkg/kubectl"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||||
@ -289,7 +288,7 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out, errOut io.Writer, opti
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, ok := annotationMap[annotations.LastAppliedConfigAnnotation]; !ok {
|
if _, ok := annotationMap[api.LastAppliedConfigAnnotation]; !ok {
|
||||||
fmt.Fprintf(errOut, warningNoLastAppliedConfigAnnotation)
|
fmt.Fprintf(errOut, warningNoLastAppliedConfigAnnotation)
|
||||||
}
|
}
|
||||||
overwrite := cmdutil.GetFlagBool(cmd, "overwrite")
|
overwrite := cmdutil.GetFlagBool(cmd, "overwrite")
|
||||||
@ -475,7 +474,7 @@ func (p *pruner) prune(namespace string, mapping *meta.RESTMapping, shortOutput
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, ok := annots[annotations.LastAppliedConfigAnnotation]; !ok {
|
if _, ok := annots[api.LastAppliedConfigAnnotation]; !ok {
|
||||||
// don't prune resources not created with apply
|
// don't prune resources not created with apply
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
apijson "k8s.io/apimachinery/pkg/util/json"
|
apijson "k8s.io/apimachinery/pkg/util/json"
|
||||||
"k8s.io/kubernetes/pkg/api/annotations"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/kubectl"
|
"k8s.io/kubernetes/pkg/kubectl"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
@ -234,7 +234,7 @@ func (o *SetLastAppliedOptions) getPatch(info *resource.Info) ([]byte, []byte, e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, localFile, err
|
return nil, localFile, err
|
||||||
}
|
}
|
||||||
annotationsMap[annotations.LastAppliedConfigAnnotation] = string(localFile)
|
annotationsMap[api.LastAppliedConfigAnnotation] = string(localFile)
|
||||||
metadataMap["annotations"] = annotationsMap
|
metadataMap["annotations"] = annotationsMap
|
||||||
objMap["metadata"] = metadataMap
|
objMap["metadata"] = metadataMap
|
||||||
jsonString, err := apijson.Marshal(objMap)
|
jsonString, err := apijson.Marshal(objMap)
|
||||||
|
@ -35,7 +35,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/client-go/rest/fake"
|
"k8s.io/client-go/rest/fake"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/annotations"
|
|
||||||
"k8s.io/kubernetes/pkg/api/testapi"
|
"k8s.io/kubernetes/pkg/api/testapi"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
||||||
@ -163,7 +162,7 @@ func annotateRuntimeObject(t *testing.T, originalObj, currentObj runtime.Object,
|
|||||||
if currentAnnotations == nil {
|
if currentAnnotations == nil {
|
||||||
currentAnnotations = make(map[string]string)
|
currentAnnotations = make(map[string]string)
|
||||||
}
|
}
|
||||||
currentAnnotations[annotations.LastAppliedConfigAnnotation] = string(original)
|
currentAnnotations[api.LastAppliedConfigAnnotation] = string(original)
|
||||||
currentAccessor.SetAnnotations(currentAnnotations)
|
currentAccessor.SetAnnotations(currentAnnotations)
|
||||||
current, err := runtime.Encode(testapi.Default.Codec(), currentObj)
|
current, err := runtime.Encode(testapi.Default.Codec(), currentObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -203,7 +202,7 @@ func validatePatchApplication(t *testing.T, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
annotationsMap := walkMapPath(t, patchMap, []string{"metadata", "annotations"})
|
annotationsMap := walkMapPath(t, patchMap, []string{"metadata", "annotations"})
|
||||||
if _, ok := annotationsMap[annotations.LastAppliedConfigAnnotation]; !ok {
|
if _, ok := annotationsMap[api.LastAppliedConfigAnnotation]; !ok {
|
||||||
t.Fatalf("patch does not contain annotation:\n%s\n", patch)
|
t.Fatalf("patch does not contain annotation:\n%s\n", patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -706,7 +705,7 @@ func TestApplyNULLPreservation(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
annotationMap := walkMapPath(t, patchMap, []string{"metadata", "annotations"})
|
annotationMap := walkMapPath(t, patchMap, []string{"metadata", "annotations"})
|
||||||
if _, ok := annotationMap[annotations.LastAppliedConfigAnnotation]; !ok {
|
if _, ok := annotationMap[api.LastAppliedConfigAnnotation]; !ok {
|
||||||
t.Fatalf("patch does not contain annotation:\n%s\n", patch)
|
t.Fatalf("patch does not contain annotation:\n%s\n", patch)
|
||||||
}
|
}
|
||||||
strategy := walkMapPath(t, patchMap, []string{"spec", "strategy"})
|
strategy := walkMapPath(t, patchMap, []string{"spec", "strategy"})
|
||||||
@ -1006,7 +1005,7 @@ func checkPatchString(t *testing.T, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
annotationsMap := walkMapPath(t, patchMap, []string{"metadata", "annotations"})
|
annotationsMap := walkMapPath(t, patchMap, []string{"metadata", "annotations"})
|
||||||
if _, ok := annotationsMap[annotations.LastAppliedConfigAnnotation]; !ok {
|
if _, ok := annotationsMap[api.LastAppliedConfigAnnotation]; !ok {
|
||||||
t.Fatalf("patch does not contain annotation:\n%s\n", patch)
|
t.Fatalf("patch does not contain annotation:\n%s\n", patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,6 @@ import (
|
|||||||
"k8s.io/client-go/util/homedir"
|
"k8s.io/client-go/util/homedir"
|
||||||
fedclientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset"
|
fedclientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/service"
|
|
||||||
"k8s.io/kubernetes/pkg/apis/apps"
|
"k8s.io/kubernetes/pkg/apis/apps"
|
||||||
"k8s.io/kubernetes/pkg/apis/batch"
|
"k8s.io/kubernetes/pkg/apis/batch"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
@ -595,7 +594,7 @@ See http://kubernetes.io/docs/user-guide/services-firewalls for more details.
|
|||||||
out.Write([]byte(msg))
|
out.Write([]byte(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := obj.Annotations[service.AnnotationLoadBalancerSourceRangesKey]; ok {
|
if _, ok := obj.Annotations[api.AnnotationLoadBalancerSourceRangesKey]; ok {
|
||||||
msg := fmt.Sprintf(
|
msg := fmt.Sprintf(
|
||||||
`You are using service annotation [service.beta.kubernetes.io/load-balancer-source-ranges].
|
`You are using service annotation [service.beta.kubernetes.io/load-balancer-source-ranges].
|
||||||
It has been promoted to field [loadBalancerSourceRanges] in service spec. This annotation will be deprecated in the future.
|
It has been promoted to field [loadBalancerSourceRanges] in service spec. This annotation will be deprecated in the future.
|
||||||
|
@ -47,7 +47,6 @@ import (
|
|||||||
"k8s.io/kubernetes/federation/apis/federation"
|
"k8s.io/kubernetes/federation/apis/federation"
|
||||||
fedclientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset"
|
fedclientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/annotations"
|
|
||||||
"k8s.io/kubernetes/pkg/api/events"
|
"k8s.io/kubernetes/pkg/api/events"
|
||||||
"k8s.io/kubernetes/pkg/api/helper"
|
"k8s.io/kubernetes/pkg/api/helper"
|
||||||
"k8s.io/kubernetes/pkg/api/ref"
|
"k8s.io/kubernetes/pkg/api/ref"
|
||||||
@ -1702,7 +1701,7 @@ func describeSecret(secret *api.Secret) (string, error) {
|
|||||||
w.Write(LEVEL_0, "Name:\t%s\n", secret.Name)
|
w.Write(LEVEL_0, "Name:\t%s\n", secret.Name)
|
||||||
w.Write(LEVEL_0, "Namespace:\t%s\n", secret.Namespace)
|
w.Write(LEVEL_0, "Namespace:\t%s\n", secret.Namespace)
|
||||||
printLabelsMultiline(w, "Labels", secret.Labels)
|
printLabelsMultiline(w, "Labels", secret.Labels)
|
||||||
skipAnnotations := sets.NewString(annotations.LastAppliedConfigAnnotation)
|
skipAnnotations := sets.NewString(api.LastAppliedConfigAnnotation)
|
||||||
printAnnotationsMultilineWithFilter(w, "Annotations", secret.Annotations, skipAnnotations)
|
printAnnotationsMultilineWithFilter(w, "Annotations", secret.Annotations, skipAnnotations)
|
||||||
|
|
||||||
w.Write(LEVEL_0, "\nType:\t%s\n", secret.Type)
|
w.Write(LEVEL_0, "\nType:\t%s\n", secret.Type)
|
||||||
|
@ -32,7 +32,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/service"
|
|
||||||
"k8s.io/kubernetes/pkg/proxy"
|
"k8s.io/kubernetes/pkg/proxy"
|
||||||
"k8s.io/kubernetes/pkg/util/exec"
|
"k8s.io/kubernetes/pkg/util/exec"
|
||||||
utiliptables "k8s.io/kubernetes/pkg/util/iptables"
|
utiliptables "k8s.io/kubernetes/pkg/util/iptables"
|
||||||
@ -856,7 +855,7 @@ func TestOnlyLocalLoadBalancing(t *testing.T) {
|
|||||||
svc.Status.LoadBalancer.Ingress = []api.LoadBalancerIngress{{
|
svc.Status.LoadBalancer.Ingress = []api.LoadBalancerIngress{{
|
||||||
IP: svcLBIP,
|
IP: svcLBIP,
|
||||||
}}
|
}}
|
||||||
svc.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
svc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -947,7 +946,7 @@ func onlyLocalNodePorts(t *testing.T, fp *Proxier, ipt *iptablestest.FakeIPTable
|
|||||||
Protocol: api.ProtocolTCP,
|
Protocol: api.ProtocolTCP,
|
||||||
NodePort: int32(svcNodePort),
|
NodePort: int32(svcNodePort),
|
||||||
}}
|
}}
|
||||||
svc.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
svc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1059,8 +1058,8 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
makeTestService("somewhere", "only-local-load-balancer", func(svc *api.Service) {
|
makeTestService("somewhere", "only-local-load-balancer", func(svc *api.Service) {
|
||||||
svc.ObjectMeta.Annotations = map[string]string{
|
svc.ObjectMeta.Annotations = map[string]string{
|
||||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||||
service.BetaAnnotationHealthCheckNodePort: "345",
|
api.BetaAnnotationHealthCheckNodePort: "345",
|
||||||
}
|
}
|
||||||
svc.Spec.Type = api.ServiceTypeLoadBalancer
|
svc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
svc.Spec.ClusterIP = "172.16.55.12"
|
svc.Spec.ClusterIP = "172.16.55.12"
|
||||||
@ -1200,8 +1199,8 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
|||||||
})
|
})
|
||||||
servicev2 := makeTestService("somewhere", "some-service", func(svc *api.Service) {
|
servicev2 := makeTestService("somewhere", "some-service", func(svc *api.Service) {
|
||||||
svc.ObjectMeta.Annotations = map[string]string{
|
svc.ObjectMeta.Annotations = map[string]string{
|
||||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||||
service.BetaAnnotationHealthCheckNodePort: "345",
|
api.BetaAnnotationHealthCheckNodePort: "345",
|
||||||
}
|
}
|
||||||
svc.Spec.Type = api.ServiceTypeLoadBalancer
|
svc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||||
svc.Spec.ClusterIP = "172.16.55.4"
|
svc.Spec.ClusterIP = "172.16.55.4"
|
||||||
|
@ -322,8 +322,8 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service) (boo
|
|||||||
if oldHealthCheckNodePort != newHealthCheckNodePort {
|
if oldHealthCheckNodePort != newHealthCheckNodePort {
|
||||||
glog.Warningf("Attempt to change value of health check node port DENIED")
|
glog.Warningf("Attempt to change value of health check node port DENIED")
|
||||||
var fldPath *field.Path
|
var fldPath *field.Path
|
||||||
if _, ok := service.Annotations[apiservice.BetaAnnotationHealthCheckNodePort]; ok {
|
if _, ok := service.Annotations[api.BetaAnnotationHealthCheckNodePort]; ok {
|
||||||
fldPath = field.NewPath("metadata", "annotations").Key(apiservice.BetaAnnotationHealthCheckNodePort)
|
fldPath = field.NewPath("metadata", "annotations").Key(api.BetaAnnotationHealthCheckNodePort)
|
||||||
} else {
|
} else {
|
||||||
fldPath = field.NewPath("spec", "healthCheckNodePort")
|
fldPath = field.NewPath("spec", "healthCheckNodePort")
|
||||||
}
|
}
|
||||||
|
@ -1002,7 +1002,7 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocationBeta(t *test
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "external-lb-esipp",
|
Name: "external-lb-esipp",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
@ -1077,8 +1077,8 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocationBeta(t *
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "external-lb-esipp",
|
Name: "external-lb-esipp",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||||
service.BetaAnnotationHealthCheckNodePort: "30200",
|
api.BetaAnnotationHealthCheckNodePort: "30200",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
@ -1143,8 +1143,8 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortNegativeBeta(t *testin
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "external-lb-esipp",
|
Name: "external-lb-esipp",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||||
service.BetaAnnotationHealthCheckNodePort: "-1",
|
api.BetaAnnotationHealthCheckNodePort: "-1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
@ -1206,7 +1206,7 @@ func TestServiceRegistryExternalTrafficGlobalBeta(t *testing.T) {
|
|||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "external-lb-esipp",
|
Name: "external-lb-esipp",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficGlobal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
@ -1276,7 +1276,7 @@ func TestServiceRegistryExternalTrafficAnnotationClusterIP(t *testing.T) {
|
|||||||
svc := &api.Service{
|
svc := &api.Service{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "external-lb-esipp",
|
ObjectMeta: metav1.ObjectMeta{Name: "external-lb-esipp",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficGlobal,
|
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
@ -1298,6 +1298,6 @@ func TestServiceRegistryExternalTrafficAnnotationClusterIP(t *testing.T) {
|
|||||||
// Make sure that ClusterIP services do not have the health check node port allocated
|
// Make sure that ClusterIP services do not have the health check node port allocated
|
||||||
port := service.GetServiceHealthCheckNodePort(created_service)
|
port := service.GetServiceHealthCheckNodePort(created_service)
|
||||||
if port != 0 {
|
if port != 0 {
|
||||||
t.Errorf("Unexpected allocation of health check node port annotation %s", service.BetaAnnotationHealthCheckNodePort)
|
t.Errorf("Unexpected allocation of health check node port annotation %s", api.BetaAnnotationHealthCheckNodePort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/kubernetes/pkg/api/annotations"
|
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
extensionsinternal "k8s.io/kubernetes/pkg/apis/extensions"
|
extensionsinternal "k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
||||||
@ -202,7 +201,7 @@ func testNewDeployment(f *framework.Framework) {
|
|||||||
replicas := int32(1)
|
replicas := int32(1)
|
||||||
framework.Logf("Creating simple deployment %s", deploymentName)
|
framework.Logf("Creating simple deployment %s", deploymentName)
|
||||||
d := framework.NewDeployment(deploymentName, replicas, podLabels, nginxImageName, nginxImage, extensions.RollingUpdateDeploymentStrategyType)
|
d := framework.NewDeployment(deploymentName, replicas, podLabels, nginxImageName, nginxImage, extensions.RollingUpdateDeploymentStrategyType)
|
||||||
d.Annotations = map[string]string{"test": "should-copy-to-replica-set", annotations.LastAppliedConfigAnnotation: "should-not-copy-to-replica-set"}
|
d.Annotations = map[string]string{"test": "should-copy-to-replica-set", v1.LastAppliedConfigAnnotation: "should-not-copy-to-replica-set"}
|
||||||
deploy, err := c.Extensions().Deployments(ns).Create(d)
|
deploy, err := c.Extensions().Deployments(ns).Create(d)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
@ -219,9 +218,9 @@ func testNewDeployment(f *framework.Framework) {
|
|||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
// Check new RS annotations
|
// Check new RS annotations
|
||||||
Expect(newRS.Annotations["test"]).Should(Equal("should-copy-to-replica-set"))
|
Expect(newRS.Annotations["test"]).Should(Equal("should-copy-to-replica-set"))
|
||||||
Expect(newRS.Annotations[annotations.LastAppliedConfigAnnotation]).Should(Equal(""))
|
Expect(newRS.Annotations[v1.LastAppliedConfigAnnotation]).Should(Equal(""))
|
||||||
Expect(deployment.Annotations["test"]).Should(Equal("should-copy-to-replica-set"))
|
Expect(deployment.Annotations["test"]).Should(Equal("should-copy-to-replica-set"))
|
||||||
Expect(deployment.Annotations[annotations.LastAppliedConfigAnnotation]).Should(Equal("should-not-copy-to-replica-set"))
|
Expect(deployment.Annotations[v1.LastAppliedConfigAnnotation]).Should(Equal("should-not-copy-to-replica-set"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDeleteDeployment(f *framework.Framework) {
|
func testDeleteDeployment(f *framework.Framework) {
|
||||||
@ -234,7 +233,7 @@ func testDeleteDeployment(f *framework.Framework) {
|
|||||||
replicas := int32(1)
|
replicas := int32(1)
|
||||||
framework.Logf("Creating simple deployment %s", deploymentName)
|
framework.Logf("Creating simple deployment %s", deploymentName)
|
||||||
d := framework.NewDeployment(deploymentName, replicas, podLabels, nginxImageName, nginxImage, extensions.RollingUpdateDeploymentStrategyType)
|
d := framework.NewDeployment(deploymentName, replicas, podLabels, nginxImageName, nginxImage, extensions.RollingUpdateDeploymentStrategyType)
|
||||||
d.Annotations = map[string]string{"test": "should-copy-to-replica-set", annotations.LastAppliedConfigAnnotation: "should-not-copy-to-replica-set"}
|
d.Annotations = map[string]string{"test": "should-copy-to-replica-set", v1.LastAppliedConfigAnnotation: "should-not-copy-to-replica-set"}
|
||||||
deploy, err := c.Extensions().Deployments(ns).Create(d)
|
deploy, err := c.Extensions().Deployments(ns).Create(d)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
@ -51,7 +51,6 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/apiserver/pkg/authentication/serviceaccount"
|
"k8s.io/apiserver/pkg/authentication/serviceaccount"
|
||||||
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
|
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
|
||||||
"k8s.io/kubernetes/pkg/api/annotations"
|
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
rbacv1beta1 "k8s.io/kubernetes/pkg/apis/rbac/v1beta1"
|
rbacv1beta1 "k8s.io/kubernetes/pkg/apis/rbac/v1beta1"
|
||||||
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||||
@ -1922,7 +1921,7 @@ func forEachReplicationController(c clientset.Interface, ns, selectorKey, select
|
|||||||
|
|
||||||
func validateReplicationControllerConfiguration(rc v1.ReplicationController) {
|
func validateReplicationControllerConfiguration(rc v1.ReplicationController) {
|
||||||
if rc.Name == "redis-master" {
|
if rc.Name == "redis-master" {
|
||||||
if _, ok := rc.Annotations[annotations.LastAppliedConfigAnnotation]; !ok {
|
if _, ok := rc.Annotations[v1.LastAppliedConfigAnnotation]; !ok {
|
||||||
framework.Failf("Annotation not found in modified configuration:\n%v\n", rc)
|
framework.Failf("Annotation not found in modified configuration:\n%v\n", rc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user