Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
cb53dbbf
Commit
cb53dbbf
authored
Apr 17, 2017
by
Zihong Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move healthcheck util functions to util.go
parent
f96b187f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
110 deletions
+102
-110
annotations.go
pkg/api/service/annotations.go
+0
-49
util.go
pkg/api/service/util.go
+45
-0
annotations.go
pkg/api/v1/service/annotations.go
+0
-61
util.go
pkg/api/v1/service/util.go
+57
-0
No files found.
pkg/api/service/annotations.go
View file @
cb53dbbf
...
@@ -16,13 +16,6 @@ limitations under the License.
...
@@ -16,13 +16,6 @@ limitations under the License.
package
service
package
service
import
(
"strconv"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
)
const
(
const
(
// AnnotationLoadBalancerSourceRangesKey is the key of the annotation on a service to set allowed ingress ranges on their LoadBalancers
// AnnotationLoadBalancerSourceRangesKey is the key of the annotation on a service to set allowed ingress ranges on their LoadBalancers
//
//
...
@@ -55,45 +48,3 @@ const (
...
@@ -55,45 +48,3 @@ const (
// BetaAnnotationExternalTraffic is the beta version of AlphaAnnotationExternalTraffic.
// BetaAnnotationExternalTraffic is the beta version of AlphaAnnotationExternalTraffic.
BetaAnnotationExternalTraffic
=
"service.beta.kubernetes.io/external-traffic"
BetaAnnotationExternalTraffic
=
"service.beta.kubernetes.io/external-traffic"
)
)
// NeedsHealthCheck Check service for health check annotations
func
NeedsHealthCheck
(
service
*
api
.
Service
)
bool
{
// First check the alpha annotation and then the beta. This is so existing
// Services continue to work till the user decides to transition to beta.
// If they transition to beta, there's no way to go back to alpha without
// rolling back the cluster.
for
_
,
annotation
:=
range
[]
string
{
AlphaAnnotationExternalTraffic
,
BetaAnnotationExternalTraffic
}
{
if
l
,
ok
:=
service
.
Annotations
[
annotation
];
ok
{
if
l
==
AnnotationValueExternalTrafficLocal
{
return
true
}
else
if
l
==
AnnotationValueExternalTrafficGlobal
{
return
false
}
else
{
glog
.
Errorf
(
"Invalid value for annotation %v: %v"
,
annotation
,
l
)
}
}
}
return
false
}
// GetServiceHealthCheckNodePort Return health check node port annotation for service, if one exists
func
GetServiceHealthCheckNodePort
(
service
*
api
.
Service
)
int32
{
if
!
NeedsHealthCheck
(
service
)
{
return
0
}
// First check the alpha annotation and then the beta. This is so existing
// Services continue to work till the user decides to transition to beta.
// If they transition to beta, there's no way to go back to alpha without
// rolling back the cluster.
for
_
,
annotation
:=
range
[]
string
{
AlphaAnnotationHealthCheckNodePort
,
BetaAnnotationHealthCheckNodePort
}
{
if
l
,
ok
:=
service
.
Annotations
[
annotation
];
ok
{
p
,
err
:=
strconv
.
Atoi
(
l
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to parse annotation %v: %v"
,
annotation
,
err
)
continue
}
return
int32
(
p
)
}
}
return
0
}
pkg/api/service/util.go
View file @
cb53dbbf
...
@@ -18,10 +18,13 @@ package service
...
@@ -18,10 +18,13 @@ package service
import
(
import
(
"fmt"
"fmt"
"strconv"
"strings"
"strings"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
netsets
"k8s.io/kubernetes/pkg/util/net/sets"
netsets
"k8s.io/kubernetes/pkg/util/net/sets"
"github.com/golang/glog"
)
)
const
(
const
(
...
@@ -66,3 +69,45 @@ func GetLoadBalancerSourceRanges(service *api.Service) (netsets.IPNet, error) {
...
@@ -66,3 +69,45 @@ func GetLoadBalancerSourceRanges(service *api.Service) (netsets.IPNet, error) {
}
}
return
ipnets
,
nil
return
ipnets
,
nil
}
}
// NeedsHealthCheck Check service for health check annotations
func
NeedsHealthCheck
(
service
*
api
.
Service
)
bool
{
// First check the alpha annotation and then the beta. This is so existing
// Services continue to work till the user decides to transition to beta.
// If they transition to beta, there's no way to go back to alpha without
// rolling back the cluster.
for
_
,
annotation
:=
range
[]
string
{
AlphaAnnotationExternalTraffic
,
BetaAnnotationExternalTraffic
}
{
if
l
,
ok
:=
service
.
Annotations
[
annotation
];
ok
{
if
l
==
AnnotationValueExternalTrafficLocal
{
return
true
}
else
if
l
==
AnnotationValueExternalTrafficGlobal
{
return
false
}
else
{
glog
.
Errorf
(
"Invalid value for annotation %v: %v"
,
annotation
,
l
)
}
}
}
return
false
}
// GetServiceHealthCheckNodePort Return health check node port annotation for service, if one exists
func
GetServiceHealthCheckNodePort
(
service
*
api
.
Service
)
int32
{
if
!
NeedsHealthCheck
(
service
)
{
return
0
}
// First check the alpha annotation and then the beta. This is so existing
// Services continue to work till the user decides to transition to beta.
// If they transition to beta, there's no way to go back to alpha without
// rolling back the cluster.
for
_
,
annotation
:=
range
[]
string
{
AlphaAnnotationHealthCheckNodePort
,
BetaAnnotationHealthCheckNodePort
}
{
if
l
,
ok
:=
service
.
Annotations
[
annotation
];
ok
{
p
,
err
:=
strconv
.
Atoi
(
l
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to parse annotation %v: %v"
,
annotation
,
err
)
continue
}
return
int32
(
p
)
}
}
return
0
}
pkg/api/v1/service/annotations.go
View file @
cb53dbbf
...
@@ -16,13 +16,6 @@ limitations under the License.
...
@@ -16,13 +16,6 @@ limitations under the License.
package
service
package
service
import
(
"strconv"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api/v1"
)
const
(
const
(
// AnnotationLoadBalancerSourceRangesKey is the key of the annotation on a service to set allowed ingress ranges on their LoadBalancers
// AnnotationLoadBalancerSourceRangesKey is the key of the annotation on a service to set allowed ingress ranges on their LoadBalancers
//
//
...
@@ -55,57 +48,3 @@ const (
...
@@ -55,57 +48,3 @@ const (
// BetaAnnotationExternalTraffic is the beta version of AlphaAnnotationExternalTraffic.
// BetaAnnotationExternalTraffic is the beta version of AlphaAnnotationExternalTraffic.
BetaAnnotationExternalTraffic
=
"service.beta.kubernetes.io/external-traffic"
BetaAnnotationExternalTraffic
=
"service.beta.kubernetes.io/external-traffic"
)
)
// NeedsHealthCheck Check service for health check annotations
func
NeedsHealthCheck
(
service
*
v1
.
Service
)
bool
{
// First check the alpha annotation and then the beta. This is so existing
// Services continue to work till the user decides to transition to beta.
// If they transition to beta, there's no way to go back to alpha without
// rolling back the cluster.
for
_
,
annotation
:=
range
[]
string
{
AlphaAnnotationExternalTraffic
,
BetaAnnotationExternalTraffic
}
{
if
l
,
ok
:=
service
.
Annotations
[
annotation
];
ok
{
if
l
==
AnnotationValueExternalTrafficLocal
{
return
true
}
else
if
l
==
AnnotationValueExternalTrafficGlobal
{
return
false
}
else
{
glog
.
Errorf
(
"Invalid value for annotation %v: %v"
,
annotation
,
l
)
}
}
}
return
false
}
// GetServiceHealthCheckNodePort Return health check node port annotation for service, if one exists
func
GetServiceHealthCheckNodePort
(
service
*
v1
.
Service
)
int32
{
if
!
NeedsHealthCheck
(
service
)
{
return
0
}
// First check the alpha annotation and then the beta. This is so existing
// Services continue to work till the user decides to transition to beta.
// If they transition to beta, there's no way to go back to alpha without
// rolling back the cluster.
for
_
,
annotation
:=
range
[]
string
{
AlphaAnnotationHealthCheckNodePort
,
BetaAnnotationHealthCheckNodePort
}
{
if
l
,
ok
:=
service
.
Annotations
[
annotation
];
ok
{
p
,
err
:=
strconv
.
Atoi
(
l
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to parse annotation %v: %v"
,
annotation
,
err
)
continue
}
return
int32
(
p
)
}
}
return
0
}
// GetServiceHealthCheckPathPort Return the path and nodePort programmed into the Cloud LB Health Check
func
GetServiceHealthCheckPathPort
(
service
*
v1
.
Service
)
(
string
,
int32
)
{
if
!
NeedsHealthCheck
(
service
)
{
return
""
,
0
}
port
:=
GetServiceHealthCheckNodePort
(
service
)
if
port
==
0
{
return
""
,
0
}
return
"/healthz"
,
port
}
pkg/api/v1/service/util.go
View file @
cb53dbbf
...
@@ -18,10 +18,13 @@ package service
...
@@ -18,10 +18,13 @@ package service
import
(
import
(
"fmt"
"fmt"
"strconv"
"strings"
"strings"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/api/v1"
netsets
"k8s.io/kubernetes/pkg/util/net/sets"
netsets
"k8s.io/kubernetes/pkg/util/net/sets"
"github.com/golang/glog"
)
)
const
(
const
(
...
@@ -66,3 +69,57 @@ func GetLoadBalancerSourceRanges(service *v1.Service) (netsets.IPNet, error) {
...
@@ -66,3 +69,57 @@ func GetLoadBalancerSourceRanges(service *v1.Service) (netsets.IPNet, error) {
}
}
return
ipnets
,
nil
return
ipnets
,
nil
}
}
// NeedsHealthCheck Check service for health check annotations
func
NeedsHealthCheck
(
service
*
v1
.
Service
)
bool
{
// First check the alpha annotation and then the beta. This is so existing
// Services continue to work till the user decides to transition to beta.
// If they transition to beta, there's no way to go back to alpha without
// rolling back the cluster.
for
_
,
annotation
:=
range
[]
string
{
AlphaAnnotationExternalTraffic
,
BetaAnnotationExternalTraffic
}
{
if
l
,
ok
:=
service
.
Annotations
[
annotation
];
ok
{
if
l
==
AnnotationValueExternalTrafficLocal
{
return
true
}
else
if
l
==
AnnotationValueExternalTrafficGlobal
{
return
false
}
else
{
glog
.
Errorf
(
"Invalid value for annotation %v: %v"
,
annotation
,
l
)
}
}
}
return
false
}
// GetServiceHealthCheckNodePort Return health check node port annotation for service, if one exists
func
GetServiceHealthCheckNodePort
(
service
*
v1
.
Service
)
int32
{
if
!
NeedsHealthCheck
(
service
)
{
return
0
}
// First check the alpha annotation and then the beta. This is so existing
// Services continue to work till the user decides to transition to beta.
// If they transition to beta, there's no way to go back to alpha without
// rolling back the cluster.
for
_
,
annotation
:=
range
[]
string
{
AlphaAnnotationHealthCheckNodePort
,
BetaAnnotationHealthCheckNodePort
}
{
if
l
,
ok
:=
service
.
Annotations
[
annotation
];
ok
{
p
,
err
:=
strconv
.
Atoi
(
l
)
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to parse annotation %v: %v"
,
annotation
,
err
)
continue
}
return
int32
(
p
)
}
}
return
0
}
// GetServiceHealthCheckPathPort Return the path and nodePort programmed into the Cloud LB Health Check
func
GetServiceHealthCheckPathPort
(
service
*
v1
.
Service
)
(
string
,
int32
)
{
if
!
NeedsHealthCheck
(
service
)
{
return
""
,
0
}
port
:=
GetServiceHealthCheckNodePort
(
service
)
if
port
==
0
{
return
""
,
0
}
return
"/healthz"
,
port
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment