Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move all API related annotations into annotation_key_constants.go #45926

Merged
merged 3 commits into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion hack/.linted_packages
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ hack
hack/boilerplate/test
hack/cmd/teststale
pkg/api
pkg/api/annotations
pkg/api/errors
pkg/api/events
pkg/api/install
Expand Down
1 change: 0 additions & 1 deletion pkg/api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//pkg/api/annotations:all-srcs",
"//pkg/api/endpoints:all-srcs",
"//pkg/api/errors:all-srcs",
"//pkg/api/events:all-srcs",
Expand Down
33 changes: 33 additions & 0 deletions pkg/api/annotation_key_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// This file should be consistent with pkg/api/v1/annotation_key_constants.go.

package api

const (
Expand Down Expand Up @@ -70,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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're going to extract kubectlPrefix why not serviceBetaPrefix

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Yeah we could do that later :)


// 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"
)
30 changes: 0 additions & 30 deletions pkg/api/annotations/BUILD

This file was deleted.

4 changes: 0 additions & 4 deletions pkg/api/annotations/OWNERS

This file was deleted.

23 changes: 0 additions & 23 deletions pkg/api/annotations/annotations.go

This file was deleted.

18 changes: 0 additions & 18 deletions pkg/api/annotations/doc.go

This file was deleted.

5 changes: 1 addition & 4 deletions pkg/api/service/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ load(

go_library(
name = "go_default_library",
srcs = [
"annotations.go",
"util.go",
],
srcs = ["util.go"],
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",
Expand Down
44 changes: 0 additions & 44 deletions pkg/api/service/annotations.go

This file was deleted.

28 changes: 14 additions & 14 deletions pkg/api/service/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ 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
}
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
Expand All @@ -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
}
}
Expand All @@ -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)
Expand All @@ -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 ||
Expand All @@ -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("")
Expand All @@ -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
}
Expand Down