mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +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.
|
||||
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)
|
||||
}
|
||||
} else {
|
||||
val := service.Annotations[AnnotationLoadBalancerSourceRangesKey]
|
||||
val := service.Annotations[api.AnnotationLoadBalancerSourceRangesKey]
|
||||
val = strings.TrimSpace(val)
|
||||
if val == "" {
|
||||
val = defaultLoadBalancerSourceRanges
|
||||
@ -64,7 +64,7 @@ func GetLoadBalancerSourceRanges(service *api.Service) (netsets.IPNet, error) {
|
||||
specs := strings.Split(val, ",")
|
||||
ipnets, err = netsets.ParseIPNets(specs...)
|
||||
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
|
||||
@ -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
|
||||
// existing Services continue to work till the user decides to transition to the
|
||||
// first class field.
|
||||
if l, ok := service.Annotations[BetaAnnotationExternalTraffic]; ok {
|
||||
if l, ok := service.Annotations[api.BetaAnnotationExternalTraffic]; ok {
|
||||
switch l {
|
||||
case AnnotationValueExternalTrafficLocal:
|
||||
case api.AnnotationValueExternalTrafficLocal:
|
||||
return true
|
||||
case AnnotationValueExternalTrafficGlobal:
|
||||
case api.AnnotationValueExternalTrafficGlobal:
|
||||
return false
|
||||
default:
|
||||
glog.Errorf("Invalid value for annotation %v: %v", BetaAnnotationExternalTraffic, l)
|
||||
glog.Errorf("Invalid value for annotation %v: %v", api.BetaAnnotationExternalTraffic, l)
|
||||
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
|
||||
// existing Services continue to work till the user decides to transition to the
|
||||
// first class field.
|
||||
if l, ok := service.Annotations[BetaAnnotationHealthCheckNodePort]; ok {
|
||||
if l, ok := service.Annotations[api.BetaAnnotationHealthCheckNodePort]; ok {
|
||||
p, err := strconv.Atoi(l)
|
||||
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 int32(p)
|
||||
@ -122,7 +122,7 @@ func GetServiceHealthCheckNodePort(service *api.Service) int32 {
|
||||
// for NodePort / LoadBalancer service to Global for consistency.
|
||||
// TODO: Move this default logic to default.go once beta annotation is deprecated.
|
||||
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.
|
||||
return
|
||||
} 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
|
||||
// existing Services continue to work till the user decides to transition to the
|
||||
// first class field.
|
||||
if _, ok := service.Annotations[BetaAnnotationExternalTraffic]; ok {
|
||||
delete(service.Annotations, BetaAnnotationExternalTraffic)
|
||||
if _, ok := service.Annotations[api.BetaAnnotationExternalTraffic]; ok {
|
||||
delete(service.Annotations, api.BetaAnnotationExternalTraffic)
|
||||
return
|
||||
}
|
||||
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
|
||||
// existing 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[api.BetaAnnotationExternalTraffic]; ok {
|
||||
if hcNodePort == 0 {
|
||||
delete(service.Annotations, BetaAnnotationHealthCheckNodePort)
|
||||
delete(service.Annotations, api.BetaAnnotationHealthCheckNodePort)
|
||||
} else {
|
||||
service.Annotations[BetaAnnotationHealthCheckNodePort] = fmt.Sprintf("%d", hcNodePort)
|
||||
service.Annotations[api.BetaAnnotationHealthCheckNodePort] = fmt.Sprintf("%d", hcNodePort)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import (
|
||||
func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
||||
checkError := func(v string) {
|
||||
annotations := make(map[string]string)
|
||||
annotations[AnnotationLoadBalancerSourceRangesKey] = v
|
||||
annotations[api.AnnotationLoadBalancerSourceRangesKey] = v
|
||||
svc := api.Service{}
|
||||
svc.Annotations = annotations
|
||||
_, err := GetLoadBalancerSourceRanges(&svc)
|
||||
@ -56,7 +56,7 @@ func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
||||
|
||||
checkOK := func(v string) netsets.IPNet {
|
||||
annotations := make(map[string]string)
|
||||
annotations[AnnotationLoadBalancerSourceRangesKey] = v
|
||||
annotations[api.AnnotationLoadBalancerSourceRangesKey] = v
|
||||
svc := api.Service{}
|
||||
svc.Annotations = annotations
|
||||
cidrs, err := GetLoadBalancerSourceRanges(&svc)
|
||||
@ -101,7 +101,7 @@ func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
||||
}
|
||||
// check SourceRanges annotation is empty
|
||||
annotations := make(map[string]string)
|
||||
annotations[AnnotationLoadBalancerSourceRangesKey] = ""
|
||||
annotations[api.AnnotationLoadBalancerSourceRangesKey] = ""
|
||||
svc = api.Service{}
|
||||
svc.Annotations = annotations
|
||||
cidrs, err = GetLoadBalancerSourceRanges(&svc)
|
||||
@ -226,7 +226,7 @@ func TestNeedsHealthCheck(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: "invalid",
|
||||
api.BetaAnnotationExternalTraffic: "invalid",
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -236,7 +236,7 @@ func TestNeedsHealthCheck(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -246,7 +246,7 @@ func TestNeedsHealthCheck(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -291,8 +291,8 @@ func TestGetServiceHealthCheckNodePort(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
||||
BetaAnnotationHealthCheckNodePort: "34567",
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||
api.BetaAnnotationHealthCheckNodePort: "34567",
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -350,7 +350,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -360,7 +360,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -372,7 +372,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -382,7 +382,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -419,7 +419,7 @@ func TestClearExternalTrafficPolicy(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -428,7 +428,7 @@ func TestClearExternalTrafficPolicy(t *testing.T) {
|
||||
|
||||
for i, tc := range testCases {
|
||||
ClearExternalTrafficPolicy(tc.inputService)
|
||||
if _, ok := tc.inputService.Annotations[BetaAnnotationExternalTraffic]; ok ||
|
||||
if _, ok := tc.inputService.Annotations[api.BetaAnnotationExternalTraffic]; ok ||
|
||||
tc.inputService.Spec.ExternalTrafficPolicy != "" {
|
||||
t.Errorf("%v: failed to clear ExternalTrafficPolicy", i)
|
||||
spew.Dump(tc)
|
||||
@ -471,7 +471,7 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -485,7 +485,7 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
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)
|
||||
}
|
||||
} else {
|
||||
l, ok := tc.inputService.Annotations[BetaAnnotationHealthCheckNodePort]
|
||||
l, ok := tc.inputService.Annotations[api.BetaAnnotationHealthCheckNodePort]
|
||||
if tc.hcNodePort == 0 {
|
||||
if ok {
|
||||
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.
|
||||
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)
|
||||
}
|
||||
} else {
|
||||
val := service.Annotations[AnnotationLoadBalancerSourceRangesKey]
|
||||
val := service.Annotations[v1.AnnotationLoadBalancerSourceRangesKey]
|
||||
val = strings.TrimSpace(val)
|
||||
if val == "" {
|
||||
val = defaultLoadBalancerSourceRanges
|
||||
@ -64,7 +64,7 @@ func GetLoadBalancerSourceRanges(service *v1.Service) (netsets.IPNet, error) {
|
||||
specs := strings.Split(val, ",")
|
||||
ipnets, err = netsets.ParseIPNets(specs...)
|
||||
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
|
||||
@ -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
|
||||
// existing Services continue to work till the user decides to transition to the
|
||||
// first class field.
|
||||
if l, ok := service.Annotations[BetaAnnotationExternalTraffic]; ok {
|
||||
if l, ok := service.Annotations[v1.BetaAnnotationExternalTraffic]; ok {
|
||||
switch l {
|
||||
case AnnotationValueExternalTrafficLocal:
|
||||
case v1.AnnotationValueExternalTrafficLocal:
|
||||
return true
|
||||
case AnnotationValueExternalTrafficGlobal:
|
||||
case v1.AnnotationValueExternalTrafficGlobal:
|
||||
return false
|
||||
default:
|
||||
glog.Errorf("Invalid value for annotation %v: %v", BetaAnnotationExternalTraffic, l)
|
||||
glog.Errorf("Invalid value for annotation %v: %v", v1.BetaAnnotationExternalTraffic, l)
|
||||
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
|
||||
// existing Services continue to work till the user decides to transition to the
|
||||
// first class field.
|
||||
if l, ok := service.Annotations[BetaAnnotationHealthCheckNodePort]; ok {
|
||||
if l, ok := service.Annotations[v1.BetaAnnotationHealthCheckNodePort]; ok {
|
||||
p, err := strconv.Atoi(l)
|
||||
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 int32(p)
|
||||
@ -122,7 +122,7 @@ func GetServiceHealthCheckNodePort(service *v1.Service) int32 {
|
||||
// for NodePort / LoadBalancer service to Global for consistency.
|
||||
// TODO: Move this default logic to default.go once beta annotation is deprecated.
|
||||
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.
|
||||
return
|
||||
} else if (service.Spec.Type == v1.ServiceTypeNodePort ||
|
||||
@ -136,8 +136,8 @@ func SetDefaultExternalTrafficPolicyIfNeeded(service *v1.Service) {
|
||||
func ClearExternalTrafficPolicy(service *v1.Service) {
|
||||
// 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.
|
||||
if _, ok := service.Annotations[BetaAnnotationExternalTraffic]; ok {
|
||||
delete(service.Annotations, BetaAnnotationExternalTraffic)
|
||||
if _, ok := service.Annotations[v1.BetaAnnotationExternalTraffic]; ok {
|
||||
delete(service.Annotations, v1.BetaAnnotationExternalTraffic)
|
||||
return
|
||||
}
|
||||
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
|
||||
// existing 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 {
|
||||
if hcNodePort == 0 {
|
||||
delete(service.Annotations, BetaAnnotationHealthCheckNodePort)
|
||||
delete(service.Annotations, v1.BetaAnnotationHealthCheckNodePort)
|
||||
} else {
|
||||
service.Annotations[BetaAnnotationHealthCheckNodePort] = fmt.Sprintf("%d", hcNodePort)
|
||||
service.Annotations[v1.BetaAnnotationHealthCheckNodePort] = fmt.Sprintf("%d", hcNodePort)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import (
|
||||
func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
||||
checkError := func(v string) {
|
||||
annotations := make(map[string]string)
|
||||
annotations[AnnotationLoadBalancerSourceRangesKey] = v
|
||||
annotations[v1.AnnotationLoadBalancerSourceRangesKey] = v
|
||||
svc := v1.Service{}
|
||||
svc.Annotations = annotations
|
||||
_, err := GetLoadBalancerSourceRanges(&svc)
|
||||
@ -56,7 +56,7 @@ func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
||||
|
||||
checkOK := func(v string) netsets.IPNet {
|
||||
annotations := make(map[string]string)
|
||||
annotations[AnnotationLoadBalancerSourceRangesKey] = v
|
||||
annotations[v1.AnnotationLoadBalancerSourceRangesKey] = v
|
||||
svc := v1.Service{}
|
||||
svc.Annotations = annotations
|
||||
cidrs, err := GetLoadBalancerSourceRanges(&svc)
|
||||
@ -101,7 +101,7 @@ func TestGetLoadBalancerSourceRanges(t *testing.T) {
|
||||
}
|
||||
// check SourceRanges annotation is empty
|
||||
annotations := make(map[string]string)
|
||||
annotations[AnnotationLoadBalancerSourceRangesKey] = ""
|
||||
annotations[v1.AnnotationLoadBalancerSourceRangesKey] = ""
|
||||
svc = v1.Service{}
|
||||
svc.Annotations = annotations
|
||||
cidrs, err = GetLoadBalancerSourceRanges(&svc)
|
||||
@ -226,7 +226,7 @@ func TestNeedsHealthCheck(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: "invalid",
|
||||
v1.BetaAnnotationExternalTraffic: "invalid",
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -236,7 +236,7 @@ func TestNeedsHealthCheck(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
||||
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficGlobal,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -246,7 +246,7 @@ func TestNeedsHealthCheck(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
||||
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -291,8 +291,8 @@ func TestGetServiceHealthCheckNodePort(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
||||
BetaAnnotationHealthCheckNodePort: "34567",
|
||||
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal,
|
||||
v1.BetaAnnotationHealthCheckNodePort: "34567",
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -350,7 +350,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
||||
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -360,7 +360,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
||||
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -372,7 +372,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
||||
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficGlobal,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -382,7 +382,7 @@ func TestSetDefaultExternalTrafficPolicyIfNeeded(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
||||
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficGlobal,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -419,7 +419,7 @@ func TestClearExternalTrafficPolicy(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficLocal,
|
||||
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficLocal,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -428,7 +428,7 @@ func TestClearExternalTrafficPolicy(t *testing.T) {
|
||||
|
||||
for i, tc := range testCases {
|
||||
ClearExternalTrafficPolicy(tc.inputService)
|
||||
if _, ok := tc.inputService.Annotations[BetaAnnotationExternalTraffic]; ok ||
|
||||
if _, ok := tc.inputService.Annotations[v1.BetaAnnotationExternalTraffic]; ok ||
|
||||
tc.inputService.Spec.ExternalTrafficPolicy != "" {
|
||||
t.Errorf("%v: failed to clear ExternalTrafficPolicy", i)
|
||||
spew.Dump(tc)
|
||||
@ -471,7 +471,7 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
BetaAnnotationExternalTraffic: AnnotationValueExternalTrafficGlobal,
|
||||
v1.BetaAnnotationExternalTraffic: v1.AnnotationValueExternalTrafficGlobal,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -485,7 +485,7 @@ func TestSetServiceHealthCheckNodePort(t *testing.T) {
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
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)
|
||||
}
|
||||
} else {
|
||||
l, ok := tc.inputService.Annotations[BetaAnnotationHealthCheckNodePort]
|
||||
l, ok := tc.inputService.Annotations[v1.BetaAnnotationHealthCheckNodePort]
|
||||
if tc.hcNodePort == 0 {
|
||||
if ok {
|
||||
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
|
||||
_, ok := service.Annotations[apiservice.AnnotationLoadBalancerSourceRangesKey]
|
||||
_, ok := service.Annotations[api.AnnotationLoadBalancerSourceRangesKey]
|
||||
if len(service.Spec.LoadBalancerSourceRanges) > 0 || ok {
|
||||
var fieldPath *field.Path
|
||||
var val string
|
||||
@ -2743,8 +2743,8 @@ func ValidateService(service *api.Service) field.ErrorList {
|
||||
fieldPath = specPath.Child("LoadBalancerSourceRanges")
|
||||
val = fmt.Sprintf("%v", service.Spec.LoadBalancerSourceRanges)
|
||||
} else {
|
||||
fieldPath = field.NewPath("metadata", "annotations").Key(apiservice.AnnotationLoadBalancerSourceRangesKey)
|
||||
val = service.Annotations[apiservice.AnnotationLoadBalancerSourceRangesKey]
|
||||
fieldPath = field.NewPath("metadata", "annotations").Key(api.AnnotationLoadBalancerSourceRangesKey)
|
||||
val = service.Annotations[api.AnnotationLoadBalancerSourceRangesKey]
|
||||
}
|
||||
if service.Spec.Type != api.ServiceTypeLoadBalancer {
|
||||
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{}
|
||||
|
||||
// Check beta annotations.
|
||||
if l, ok := service.Annotations[apiservice.BetaAnnotationExternalTraffic]; ok {
|
||||
if l != apiservice.AnnotationValueExternalTrafficLocal &&
|
||||
l != apiservice.AnnotationValueExternalTrafficGlobal {
|
||||
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(apiservice.BetaAnnotationExternalTraffic), l,
|
||||
fmt.Sprintf("ExternalTraffic must be %v or %v", apiservice.AnnotationValueExternalTrafficLocal, apiservice.AnnotationValueExternalTrafficGlobal)))
|
||||
if l, ok := service.Annotations[api.BetaAnnotationExternalTraffic]; ok {
|
||||
if l != api.AnnotationValueExternalTrafficLocal &&
|
||||
l != api.AnnotationValueExternalTrafficGlobal {
|
||||
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "annotations").Key(api.BetaAnnotationExternalTraffic), l,
|
||||
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)
|
||||
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"))
|
||||
} 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"))
|
||||
}
|
||||
}
|
||||
@ -2857,8 +2857,8 @@ func (s *serviceExternalTrafficStatus) useBetaHealthCheckWithGA() bool {
|
||||
|
||||
func getServiceExternalTrafficStatus(service *api.Service) *serviceExternalTrafficStatus {
|
||||
s := serviceExternalTrafficStatus{}
|
||||
_, s.betaExternalTrafficIsSet = service.Annotations[apiservice.BetaAnnotationExternalTraffic]
|
||||
_, s.betaHealthCheckIsSet = service.Annotations[apiservice.BetaAnnotationHealthCheckNodePort]
|
||||
_, s.betaExternalTrafficIsSet = service.Annotations[api.BetaAnnotationExternalTraffic]
|
||||
_, s.betaHealthCheckIsSet = service.Annotations[api.BetaAnnotationHealthCheckNodePort]
|
||||
s.gaExternalTrafficIsSet = service.Spec.ExternalTrafficPolicy != ""
|
||||
s.gaHealthCheckIsSet = service.Spec.HealthCheckNodePort != 0
|
||||
return &s
|
||||
@ -2872,15 +2872,15 @@ func validateServiceExternalTrafficAPIVersion(service *api.Service) field.ErrorL
|
||||
status := getServiceExternalTrafficStatus(service)
|
||||
|
||||
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")
|
||||
allErrs = append(allErrs, field.Invalid(fieldPath, apiservice.BetaAnnotationExternalTraffic, msg))
|
||||
allErrs = append(allErrs, field.Invalid(fieldPath, api.BetaAnnotationExternalTraffic, msg))
|
||||
}
|
||||
|
||||
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")
|
||||
allErrs = append(allErrs, field.Invalid(fieldPath, apiservice.BetaAnnotationHealthCheckNodePort, msg))
|
||||
allErrs = append(allErrs, field.Invalid(fieldPath, api.BetaAnnotationHealthCheckNodePort, msg))
|
||||
}
|
||||
|
||||
return allErrs
|
||||
|
@ -30,7 +30,6 @@ import (
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/helper"
|
||||
"k8s.io/kubernetes/pkg/api/service"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
"k8s.io/kubernetes/pkg/capabilities"
|
||||
"k8s.io/kubernetes/pkg/security/apparmor"
|
||||
@ -5719,7 +5718,7 @@ func TestValidateService(t *testing.T) {
|
||||
name: "valid LoadBalancer source range annotation",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
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,
|
||||
},
|
||||
@ -5727,14 +5726,14 @@ func TestValidateService(t *testing.T) {
|
||||
name: "empty LoadBalancer source range annotation",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
s.Annotations[service.AnnotationLoadBalancerSourceRangesKey] = ""
|
||||
s.Annotations[api.AnnotationLoadBalancerSourceRangesKey] = ""
|
||||
},
|
||||
numErrs: 0,
|
||||
},
|
||||
{
|
||||
name: "invalid LoadBalancer source range annotation (hostname)",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Annotations[service.AnnotationLoadBalancerSourceRangesKey] = "foo.bar"
|
||||
s.Annotations[api.AnnotationLoadBalancerSourceRangesKey] = "foo.bar"
|
||||
},
|
||||
numErrs: 2,
|
||||
},
|
||||
@ -5742,7 +5741,7 @@ func TestValidateService(t *testing.T) {
|
||||
name: "invalid LoadBalancer source range annotation (invalid CIDR)",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
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,
|
||||
},
|
||||
@ -5834,7 +5833,7 @@ func TestValidateService(t *testing.T) {
|
||||
{
|
||||
name: "LoadBalancer allows onlyLocal beta annotations",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
||||
s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||
},
|
||||
numErrs: 0,
|
||||
},
|
||||
@ -5842,7 +5841,7 @@ func TestValidateService(t *testing.T) {
|
||||
name: "invalid externalTraffic beta annotation",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
s.Annotations[service.BetaAnnotationExternalTraffic] = "invalid"
|
||||
s.Annotations[api.BetaAnnotationExternalTraffic] = "invalid"
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
@ -5850,8 +5849,8 @@ func TestValidateService(t *testing.T) {
|
||||
name: "nagative healthCheckNodePort beta annotation",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
s.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
||||
s.Annotations[service.BetaAnnotationHealthCheckNodePort] = "-1"
|
||||
s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||
s.Annotations[api.BetaAnnotationHealthCheckNodePort] = "-1"
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
@ -5859,8 +5858,8 @@ func TestValidateService(t *testing.T) {
|
||||
name: "invalid healthCheckNodePort beta annotation",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
s.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
||||
s.Annotations[service.BetaAnnotationHealthCheckNodePort] = "whatisthis"
|
||||
s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||
s.Annotations[api.BetaAnnotationHealthCheckNodePort] = "whatisthis"
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
@ -5868,8 +5867,8 @@ func TestValidateService(t *testing.T) {
|
||||
name: "valid healthCheckNodePort beta annotation",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
s.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
||||
s.Annotations[service.BetaAnnotationHealthCheckNodePort] = "31100"
|
||||
s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||
s.Annotations[api.BetaAnnotationHealthCheckNodePort] = "31100"
|
||||
},
|
||||
numErrs: 0,
|
||||
},
|
||||
@ -5903,7 +5902,7 @@ func TestValidateService(t *testing.T) {
|
||||
name: "disallows use ExternalTraffic beta annotation with first class field",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
s.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
||||
s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||
s.Spec.HealthCheckNodePort = 3001
|
||||
},
|
||||
numErrs: 1,
|
||||
@ -5912,7 +5911,7 @@ func TestValidateService(t *testing.T) {
|
||||
name: "disallows duplicated ExternalTraffic beta annotation with first class field",
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
s.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
||||
s.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||
s.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
|
||||
},
|
||||
numErrs: 1,
|
||||
@ -5922,7 +5921,7 @@ func TestValidateService(t *testing.T) {
|
||||
tweakSvc: func(s *api.Service) {
|
||||
s.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
s.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
|
||||
s.Annotations[service.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||
s.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
@ -7389,8 +7388,8 @@ func TestValidateServiceUpdate(t *testing.T) {
|
||||
{
|
||||
name: "Service allows removing onlyLocal beta annotations",
|
||||
tweakSvc: func(oldSvc, newSvc *api.Service) {
|
||||
oldSvc.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
||||
oldSvc.Annotations[service.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||
oldSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||
oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||
},
|
||||
numErrs: 0,
|
||||
},
|
||||
@ -7398,11 +7397,11 @@ func TestValidateServiceUpdate(t *testing.T) {
|
||||
name: "Service allows modifying onlyLocal beta annotations",
|
||||
tweakSvc: func(oldSvc, newSvc *api.Service) {
|
||||
oldSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
oldSvc.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
||||
oldSvc.Annotations[service.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||
oldSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||
oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||
newSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
newSvc.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficGlobal
|
||||
newSvc.Annotations[service.BetaAnnotationHealthCheckNodePort] = oldSvc.Annotations[service.BetaAnnotationHealthCheckNodePort]
|
||||
newSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficGlobal
|
||||
newSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort]
|
||||
},
|
||||
numErrs: 0,
|
||||
},
|
||||
@ -7410,11 +7409,11 @@ func TestValidateServiceUpdate(t *testing.T) {
|
||||
name: "Service disallows promoting one of the onlyLocal pair to GA",
|
||||
tweakSvc: func(oldSvc, newSvc *api.Service) {
|
||||
oldSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
oldSvc.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
||||
oldSvc.Annotations[service.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||
oldSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||
oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||
newSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
newSvc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
|
||||
newSvc.Annotations[service.BetaAnnotationHealthCheckNodePort] = oldSvc.Annotations[service.BetaAnnotationHealthCheckNodePort]
|
||||
newSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort]
|
||||
},
|
||||
numErrs: 1,
|
||||
},
|
||||
@ -7422,8 +7421,8 @@ func TestValidateServiceUpdate(t *testing.T) {
|
||||
name: "Service allows changing both onlyLocal annotations from beta to GA",
|
||||
tweakSvc: func(oldSvc, newSvc *api.Service) {
|
||||
oldSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
oldSvc.Annotations[service.BetaAnnotationExternalTraffic] = service.AnnotationValueExternalTrafficLocal
|
||||
oldSvc.Annotations[service.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||
oldSvc.Annotations[api.BetaAnnotationExternalTraffic] = api.AnnotationValueExternalTrafficLocal
|
||||
oldSvc.Annotations[api.BetaAnnotationHealthCheckNodePort] = "3001"
|
||||
newSvc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
newSvc.Spec.ExternalTrafficPolicy = api.ServiceExternalTrafficPolicyTypeLocal
|
||||
newSvc.Spec.HealthCheckNodePort = 3001
|
||||
|
@ -35,7 +35,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/client-go/util/integer"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/annotations"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
internalextensions "k8s.io/kubernetes/pkg/apis/extensions"
|
||||
extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
||||
@ -285,12 +284,12 @@ func SetNewReplicaSetAnnotations(deployment *extensions.Deployment, newRS *exten
|
||||
}
|
||||
|
||||
var annotationsToSkip = map[string]bool{
|
||||
annotations.LastAppliedConfigAnnotation: true,
|
||||
RevisionAnnotation: true,
|
||||
RevisionHistoryAnnotation: true,
|
||||
DesiredReplicasAnnotation: true,
|
||||
MaxReplicasAnnotation: true,
|
||||
OverlapAnnotation: true,
|
||||
v1.LastAppliedConfigAnnotation: true,
|
||||
RevisionAnnotation: true,
|
||||
RevisionHistoryAnnotation: true,
|
||||
DesiredReplicasAnnotation: true,
|
||||
MaxReplicasAnnotation: true,
|
||||
OverlapAnnotation: true,
|
||||
}
|
||||
|
||||
// skipCopyAnnotation returns true if we should skip copying the annotation with the given annotation key
|
||||
|
@ -19,7 +19,7 @@ package kubectl
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/api/annotations"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||
)
|
||||
|
||||
@ -35,7 +35,7 @@ func GetOriginalConfiguration(mapping *meta.RESTMapping, obj runtime.Object) ([]
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
original, ok := annots[annotations.LastAppliedConfigAnnotation]
|
||||
original, ok := annots[api.LastAppliedConfigAnnotation]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
@ -60,7 +60,7 @@ func SetOriginalConfiguration(info *resource.Info, original []byte) error {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@ -89,8 +89,8 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
||||
annots = map[string]string{}
|
||||
}
|
||||
|
||||
original := annots[annotations.LastAppliedConfigAnnotation]
|
||||
delete(annots, annotations.LastAppliedConfigAnnotation)
|
||||
original := annots[api.LastAppliedConfigAnnotation]
|
||||
delete(annots, api.LastAppliedConfigAnnotation)
|
||||
accessor.SetAnnotations(annots)
|
||||
// TODO: this needs to be abstracted - there should be no assumption that versioned object
|
||||
// can be marshalled to JSON.
|
||||
@ -100,7 +100,7 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
||||
}
|
||||
|
||||
if annotate {
|
||||
annots[annotations.LastAppliedConfigAnnotation] = string(modified)
|
||||
annots[api.LastAppliedConfigAnnotation] = string(modified)
|
||||
accessor.SetAnnotations(annots)
|
||||
// TODO: this needs to be abstracted - there should be no assumption that versioned object
|
||||
// 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.
|
||||
annots[annotations.LastAppliedConfigAnnotation] = original
|
||||
annots[api.LastAppliedConfigAnnotation] = original
|
||||
accessor.SetAnnotations(annots)
|
||||
} else {
|
||||
// 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{}
|
||||
}
|
||||
|
||||
original := annots[annotations.LastAppliedConfigAnnotation]
|
||||
delete(annots, annotations.LastAppliedConfigAnnotation)
|
||||
original := annots[api.LastAppliedConfigAnnotation]
|
||||
delete(annots, api.LastAppliedConfigAnnotation)
|
||||
if err := accessor.SetAnnotations(info.Object, annots); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -138,7 +138,7 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
||||
}
|
||||
|
||||
if annotate {
|
||||
annots[annotations.LastAppliedConfigAnnotation] = string(modified)
|
||||
annots[api.LastAppliedConfigAnnotation] = string(modified)
|
||||
if err := info.Mapping.MetadataAccessor.SetAnnotations(info.Object, annots); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -150,7 +150,7 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -40,7 +40,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/annotations"
|
||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||
"k8s.io/kubernetes/pkg/kubectl"
|
||||
"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 {
|
||||
return err
|
||||
}
|
||||
if _, ok := annotationMap[annotations.LastAppliedConfigAnnotation]; !ok {
|
||||
if _, ok := annotationMap[api.LastAppliedConfigAnnotation]; !ok {
|
||||
fmt.Fprintf(errOut, warningNoLastAppliedConfigAnnotation)
|
||||
}
|
||||
overwrite := cmdutil.GetFlagBool(cmd, "overwrite")
|
||||
@ -475,7 +474,7 @@ func (p *pruner) prune(namespace string, mapping *meta.RESTMapping, shortOutput
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, ok := annots[annotations.LastAppliedConfigAnnotation]; !ok {
|
||||
if _, ok := annots[api.LastAppliedConfigAnnotation]; !ok {
|
||||
// don't prune resources not created with apply
|
||||
continue
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
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/cmd/templates"
|
||||
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 {
|
||||
return nil, localFile, err
|
||||
}
|
||||
annotationsMap[annotations.LastAppliedConfigAnnotation] = string(localFile)
|
||||
annotationsMap[api.LastAppliedConfigAnnotation] = string(localFile)
|
||||
metadataMap["annotations"] = annotationsMap
|
||||
objMap["metadata"] = metadataMap
|
||||
jsonString, err := apijson.Marshal(objMap)
|
||||
|
@ -35,7 +35,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/rest/fake"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/annotations"
|
||||
"k8s.io/kubernetes/pkg/api/testapi"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
cmdtesting "k8s.io/kubernetes/pkg/kubectl/cmd/testing"
|
||||
@ -163,7 +162,7 @@ func annotateRuntimeObject(t *testing.T, originalObj, currentObj runtime.Object,
|
||||
if currentAnnotations == nil {
|
||||
currentAnnotations = make(map[string]string)
|
||||
}
|
||||
currentAnnotations[annotations.LastAppliedConfigAnnotation] = string(original)
|
||||
currentAnnotations[api.LastAppliedConfigAnnotation] = string(original)
|
||||
currentAccessor.SetAnnotations(currentAnnotations)
|
||||
current, err := runtime.Encode(testapi.Default.Codec(), currentObj)
|
||||
if err != nil {
|
||||
@ -203,7 +202,7 @@ func validatePatchApplication(t *testing.T, req *http.Request) {
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@ -706,7 +705,7 @@ func TestApplyNULLPreservation(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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"})
|
||||
if _, ok := annotationsMap[annotations.LastAppliedConfigAnnotation]; !ok {
|
||||
if _, ok := annotationsMap[api.LastAppliedConfigAnnotation]; !ok {
|
||||
t.Fatalf("patch does not contain annotation:\n%s\n", patch)
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,6 @@ import (
|
||||
"k8s.io/client-go/util/homedir"
|
||||
fedclientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/service"
|
||||
"k8s.io/kubernetes/pkg/apis/apps"
|
||||
"k8s.io/kubernetes/pkg/apis/batch"
|
||||
"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))
|
||||
}
|
||||
|
||||
if _, ok := obj.Annotations[service.AnnotationLoadBalancerSourceRangesKey]; ok {
|
||||
if _, ok := obj.Annotations[api.AnnotationLoadBalancerSourceRangesKey]; ok {
|
||||
msg := fmt.Sprintf(
|
||||
`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.
|
||||
|
@ -47,7 +47,6 @@ import (
|
||||
"k8s.io/kubernetes/federation/apis/federation"
|
||||
fedclientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_internalclientset"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/annotations"
|
||||
"k8s.io/kubernetes/pkg/api/events"
|
||||
"k8s.io/kubernetes/pkg/api/helper"
|
||||
"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, "Namespace:\t%s\n", secret.Namespace)
|
||||
printLabelsMultiline(w, "Labels", secret.Labels)
|
||||
skipAnnotations := sets.NewString(annotations.LastAppliedConfigAnnotation)
|
||||
skipAnnotations := sets.NewString(api.LastAppliedConfigAnnotation)
|
||||
printAnnotationsMultilineWithFilter(w, "Annotations", secret.Annotations, skipAnnotations)
|
||||
|
||||
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/sets"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/service"
|
||||
"k8s.io/kubernetes/pkg/proxy"
|
||||
"k8s.io/kubernetes/pkg/util/exec"
|
||||
utiliptables "k8s.io/kubernetes/pkg/util/iptables"
|
||||
@ -856,7 +855,7 @@ func TestOnlyLocalLoadBalancing(t *testing.T) {
|
||||
svc.Status.LoadBalancer.Ingress = []api.LoadBalancerIngress{{
|
||||
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,
|
||||
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) {
|
||||
svc.ObjectMeta.Annotations = map[string]string{
|
||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
||||
service.BetaAnnotationHealthCheckNodePort: "345",
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||
api.BetaAnnotationHealthCheckNodePort: "345",
|
||||
}
|
||||
svc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
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) {
|
||||
svc.ObjectMeta.Annotations = map[string]string{
|
||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
||||
service.BetaAnnotationHealthCheckNodePort: "345",
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||
api.BetaAnnotationHealthCheckNodePort: "345",
|
||||
}
|
||||
svc.Spec.Type = api.ServiceTypeLoadBalancer
|
||||
svc.Spec.ClusterIP = "172.16.55.4"
|
||||
|
@ -322,8 +322,8 @@ func (rs *REST) healthCheckNodePortUpdate(oldService, service *api.Service) (boo
|
||||
if oldHealthCheckNodePort != newHealthCheckNodePort {
|
||||
glog.Warningf("Attempt to change value of health check node port DENIED")
|
||||
var fldPath *field.Path
|
||||
if _, ok := service.Annotations[apiservice.BetaAnnotationHealthCheckNodePort]; ok {
|
||||
fldPath = field.NewPath("metadata", "annotations").Key(apiservice.BetaAnnotationHealthCheckNodePort)
|
||||
if _, ok := service.Annotations[api.BetaAnnotationHealthCheckNodePort]; ok {
|
||||
fldPath = field.NewPath("metadata", "annotations").Key(api.BetaAnnotationHealthCheckNodePort)
|
||||
} else {
|
||||
fldPath = field.NewPath("spec", "healthCheckNodePort")
|
||||
}
|
||||
|
@ -1002,7 +1002,7 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortAllocationBeta(t *test
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "external-lb-esipp",
|
||||
Annotations: map[string]string{
|
||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -1077,8 +1077,8 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortUserAllocationBeta(t *
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "external-lb-esipp",
|
||||
Annotations: map[string]string{
|
||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
||||
service.BetaAnnotationHealthCheckNodePort: "30200",
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||
api.BetaAnnotationHealthCheckNodePort: "30200",
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -1143,8 +1143,8 @@ func TestServiceRegistryExternalTrafficHealthCheckNodePortNegativeBeta(t *testin
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "external-lb-esipp",
|
||||
Annotations: map[string]string{
|
||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficLocal,
|
||||
service.BetaAnnotationHealthCheckNodePort: "-1",
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficLocal,
|
||||
api.BetaAnnotationHealthCheckNodePort: "-1",
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -1206,7 +1206,7 @@ func TestServiceRegistryExternalTrafficGlobalBeta(t *testing.T) {
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "external-lb-esipp",
|
||||
Annotations: map[string]string{
|
||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficGlobal,
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||
},
|
||||
},
|
||||
Spec: api.ServiceSpec{
|
||||
@ -1276,7 +1276,7 @@ func TestServiceRegistryExternalTrafficAnnotationClusterIP(t *testing.T) {
|
||||
svc := &api.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "external-lb-esipp",
|
||||
Annotations: map[string]string{
|
||||
service.BetaAnnotationExternalTraffic: service.AnnotationValueExternalTrafficGlobal,
|
||||
api.BetaAnnotationExternalTraffic: api.AnnotationValueExternalTrafficGlobal,
|
||||
},
|
||||
},
|
||||
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
|
||||
port := service.GetServiceHealthCheckNodePort(created_service)
|
||||
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/wait"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
"k8s.io/kubernetes/pkg/api/annotations"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
extensionsinternal "k8s.io/kubernetes/pkg/apis/extensions"
|
||||
extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
||||
@ -202,7 +201,7 @@ func testNewDeployment(f *framework.Framework) {
|
||||
replicas := int32(1)
|
||||
framework.Logf("Creating simple deployment %s", deploymentName)
|
||||
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)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
@ -219,9 +218,9 @@ func testNewDeployment(f *framework.Framework) {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
// Check new RS annotations
|
||||
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[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) {
|
||||
@ -234,7 +233,7 @@ func testDeleteDeployment(f *framework.Framework) {
|
||||
replicas := int32(1)
|
||||
framework.Logf("Creating simple deployment %s", deploymentName)
|
||||
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)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
|
@ -51,7 +51,6 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/apiserver/pkg/authentication/serviceaccount"
|
||||
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
|
||||
"k8s.io/kubernetes/pkg/api/annotations"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
rbacv1beta1 "k8s.io/kubernetes/pkg/apis/rbac/v1beta1"
|
||||
"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) {
|
||||
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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user