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
23dfe56b
Commit
23dfe56b
authored
Jun 06, 2017
by
Zihong Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make firewall test get tag from config instead of instance and fix multi-zone issue
parent
0acdc89d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
31 deletions
+26
-31
firewall.go
test/e2e/firewall.go
+15
-13
firewall_util.go
test/e2e/framework/firewall_util.go
+6
-14
ingress_utils.go
test/e2e/framework/ingress_utils.go
+2
-3
ingress.go
test/e2e/ingress.go
+3
-1
No files found.
test/e2e/firewall.go
View file @
23dfe56b
...
...
@@ -24,6 +24,7 @@ import (
"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
"k8s.io/kubernetes/pkg/cloudprovider"
gcecloud
"k8s.io/kubernetes/pkg/cloudprovider/providers/gce"
kubeletapis
"k8s.io/kubernetes/pkg/kubelet/apis"
"k8s.io/kubernetes/pkg/master/ports"
"k8s.io/kubernetes/test/e2e/framework"
...
...
@@ -59,6 +60,8 @@ var _ = framework.KubeDescribe("Firewall rule", func() {
framework
.
Logf
(
"Got cluster ID: %v"
,
clusterID
)
jig
:=
framework
.
NewServiceTestJig
(
cs
,
serviceName
)
nodeList
:=
jig
.
GetNodes
(
framework
.
MaxNodesForEndpointsTests
)
Expect
(
nodeList
)
.
NotTo
(
BeNil
())
nodesNames
:=
jig
.
GetNodesNames
(
framework
.
MaxNodesForEndpointsTests
)
if
len
(
nodesNames
)
<=
0
{
framework
.
Failf
(
"Expect at least 1 node, got: %v"
,
nodesNames
)
...
...
@@ -84,14 +87,13 @@ var _ = framework.KubeDescribe("Firewall rule", func() {
svcExternalIP
:=
svc
.
Status
.
LoadBalancer
.
Ingress
[
0
]
.
IP
By
(
"Checking if service's firewall rule is correct"
)
nodeTags
:=
framework
.
GetInstanceTags
(
cloudConfig
,
nodesNames
[
0
])
lbFw
:=
framework
.
ConstructFirewallForLBService
(
svc
,
nodeTags
.
Items
)
lbFw
:=
framework
.
ConstructFirewallForLBService
(
svc
,
cloudConfig
.
NodeTag
)
fw
,
err
:=
gceCloud
.
GetFirewall
(
lbFw
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
framework
.
VerifyFirewallRule
(
fw
,
lbFw
,
cloudConfig
.
Network
,
false
))
.
NotTo
(
HaveOccurred
())
By
(
"Checking if service's nodes health check firewall rule is correct"
)
nodesHCFw
:=
framework
.
ConstructHealthCheckFirewallForLBService
(
clusterID
,
svc
,
nodeTags
.
Items
,
true
)
nodesHCFw
:=
framework
.
ConstructHealthCheckFirewallForLBService
(
clusterID
,
svc
,
cloudConfig
.
NodeTag
,
true
)
fw
,
err
=
gceCloud
.
GetFirewall
(
nodesHCFw
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
framework
.
VerifyFirewallRule
(
fw
,
nodesHCFw
,
cloudConfig
.
Network
,
false
))
.
NotTo
(
HaveOccurred
())
...
...
@@ -107,7 +109,7 @@ var _ = framework.KubeDescribe("Firewall rule", func() {
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Waiting for the correct local traffic health check firewall rule to be created"
)
localHCFw
:=
framework
.
ConstructHealthCheckFirewallForLBService
(
clusterID
,
svc
,
nodeTags
.
Items
,
false
)
localHCFw
:=
framework
.
ConstructHealthCheckFirewallForLBService
(
clusterID
,
svc
,
cloudConfig
.
NodeTag
,
false
)
fw
,
err
=
framework
.
WaitForFirewallRule
(
gceCloud
,
localHCFw
.
Name
,
true
,
framework
.
LoadBalancerCreateTimeoutDefault
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
framework
.
VerifyFirewallRule
(
fw
,
localHCFw
,
cloudConfig
.
Network
,
false
))
.
NotTo
(
HaveOccurred
())
...
...
@@ -132,11 +134,17 @@ var _ = framework.KubeDescribe("Firewall rule", func() {
// that's much harder to do in the current e2e framework.
By
(
fmt
.
Sprintf
(
"Removing tags from one of the nodes: %v"
,
nodesNames
[
0
]))
nodesSet
.
Delete
(
nodesNames
[
0
])
removedTags
:=
framework
.
SetInstanceTags
(
cloudConfig
,
nodesNames
[
0
],
[]
string
{})
// Instance could run in a different zone in multi-zone test. Figure out which zone
// it is in before proceeding.
zone
:=
cloudConfig
.
Zone
if
zoneInLabel
,
ok
:=
nodeList
.
Items
[
0
]
.
Labels
[
kubeletapis
.
LabelZoneFailureDomain
];
ok
{
zone
=
zoneInLabel
}
removedTags
:=
framework
.
SetInstanceTags
(
cloudConfig
,
nodesNames
[
0
],
zone
,
[]
string
{})
defer
func
()
{
By
(
"Adding tags back to the node and wait till the traffic is recovered"
)
nodesSet
.
Insert
(
nodesNames
[
0
])
framework
.
SetInstanceTags
(
cloudConfig
,
nodesNames
[
0
],
removedTags
)
framework
.
SetInstanceTags
(
cloudConfig
,
nodesNames
[
0
],
zone
,
removedTags
)
// Make sure traffic is recovered before exit
Expect
(
framework
.
TestHitNodesFromOutside
(
svcExternalIP
,
framework
.
FirewallTestHttpPort
,
framework
.
FirewallTimeoutDefault
,
nodesSet
))
.
NotTo
(
HaveOccurred
())
}()
...
...
@@ -146,19 +154,13 @@ var _ = framework.KubeDescribe("Firewall rule", func() {
})
It
(
"should have correct firewall rules for e2e cluster"
,
func
()
{
By
(
"Gathering firewall related information"
)
masterTags
:=
framework
.
GetInstanceTags
(
cloudConfig
,
cloudConfig
.
MasterName
)
Expect
(
len
(
masterTags
.
Items
))
.
Should
(
Equal
(
1
))
nodes
:=
framework
.
GetReadySchedulableNodesOrDie
(
cs
)
if
len
(
nodes
.
Items
)
<=
0
{
framework
.
Failf
(
"Expect at least 1 node, got: %v"
,
len
(
nodes
.
Items
))
}
nodeTags
:=
framework
.
GetInstanceTags
(
cloudConfig
,
nodes
.
Items
[
0
]
.
Name
)
Expect
(
len
(
nodeTags
.
Items
))
.
Should
(
Equal
(
1
))
By
(
"Checking if e2e firewall rules are correct"
)
for
_
,
expFw
:=
range
framework
.
GetE2eFirewalls
(
cloudConfig
.
MasterName
,
masterTags
.
Items
[
0
],
nodeTags
.
Items
[
0
]
,
cloudConfig
.
Network
)
{
for
_
,
expFw
:=
range
framework
.
GetE2eFirewalls
(
cloudConfig
.
MasterName
,
cloudConfig
.
MasterTag
,
cloudConfig
.
NodeTag
,
cloudConfig
.
Network
)
{
fw
,
err
:=
gceCloud
.
GetFirewall
(
expFw
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
framework
.
VerifyFirewallRule
(
fw
,
expFw
,
cloudConfig
.
Network
,
false
))
.
NotTo
(
HaveOccurred
())
...
...
test/e2e/framework/firewall_util.go
View file @
23dfe56b
...
...
@@ -51,13 +51,13 @@ func MakeFirewallNameForLBService(name string) string {
}
// ConstructFirewallForLBService returns the expected GCE firewall rule for a loadbalancer type service
func
ConstructFirewallForLBService
(
svc
*
v1
.
Service
,
node
sTags
[]
string
)
*
compute
.
Firewall
{
func
ConstructFirewallForLBService
(
svc
*
v1
.
Service
,
node
Tag
string
)
*
compute
.
Firewall
{
if
svc
.
Spec
.
Type
!=
v1
.
ServiceTypeLoadBalancer
{
Failf
(
"can not construct firewall rule for non-loadbalancer type service"
)
}
fw
:=
compute
.
Firewall
{}
fw
.
Name
=
MakeFirewallNameForLBService
(
cloudprovider
.
GetLoadBalancerName
(
svc
))
fw
.
TargetTags
=
nodesTags
fw
.
TargetTags
=
[]
string
{
nodeTag
}
if
svc
.
Spec
.
LoadBalancerSourceRanges
==
nil
{
fw
.
SourceRanges
=
[]
string
{
"0.0.0.0/0"
}
}
else
{
...
...
@@ -77,13 +77,13 @@ func MakeHealthCheckFirewallNameForLBService(clusterID, name string, isNodesHeal
}
// ConstructHealthCheckFirewallForLBService returns the expected GCE firewall rule for a loadbalancer type service
func
ConstructHealthCheckFirewallForLBService
(
clusterID
string
,
svc
*
v1
.
Service
,
node
sTags
[]
string
,
isNodesHealthCheck
bool
)
*
compute
.
Firewall
{
func
ConstructHealthCheckFirewallForLBService
(
clusterID
string
,
svc
*
v1
.
Service
,
node
Tag
string
,
isNodesHealthCheck
bool
)
*
compute
.
Firewall
{
if
svc
.
Spec
.
Type
!=
v1
.
ServiceTypeLoadBalancer
{
Failf
(
"can not construct firewall rule for non-loadbalancer type service"
)
}
fw
:=
compute
.
Firewall
{}
fw
.
Name
=
MakeHealthCheckFirewallNameForLBService
(
clusterID
,
cloudprovider
.
GetLoadBalancerName
(
svc
),
isNodesHealthCheck
)
fw
.
TargetTags
=
nodesTags
fw
.
TargetTags
=
[]
string
{
nodeTag
}
fw
.
SourceRanges
=
gcecloud
.
LoadBalancerSrcRanges
()
healthCheckPort
:=
gcecloud
.
GetNodesHealthCheckPort
()
if
!
isNodesHealthCheck
{
...
...
@@ -98,14 +98,6 @@ func ConstructHealthCheckFirewallForLBService(clusterID string, svc *v1.Service,
return
&
fw
}
// GetNodeTags gets tags from one of the Kubernetes nodes
func
GetNodeTags
(
c
clientset
.
Interface
,
cloudConfig
CloudConfig
)
*
compute
.
Tags
{
nodes
:=
GetReadySchedulableNodesOrDie
(
c
)
Expect
(
len
(
nodes
.
Items
)
>
0
)
.
Should
(
BeTrue
())
nodeTags
:=
GetInstanceTags
(
cloudConfig
,
nodes
.
Items
[
0
]
.
Name
)
return
nodeTags
}
// GetInstanceTags gets tags from GCE instance with given name.
func
GetInstanceTags
(
cloudConfig
CloudConfig
,
instanceName
string
)
*
compute
.
Tags
{
gceCloud
:=
cloudConfig
.
Provider
.
(
*
gcecloud
.
GCECloud
)
...
...
@@ -118,12 +110,12 @@ func GetInstanceTags(cloudConfig CloudConfig, instanceName string) *compute.Tags
}
// SetInstanceTags sets tags on GCE instance with given name.
func
SetInstanceTags
(
cloudConfig
CloudConfig
,
instanceName
string
,
tags
[]
string
)
[]
string
{
func
SetInstanceTags
(
cloudConfig
CloudConfig
,
instanceName
,
zone
string
,
tags
[]
string
)
[]
string
{
gceCloud
:=
cloudConfig
.
Provider
.
(
*
gcecloud
.
GCECloud
)
// Re-get instance everytime because we need the latest fingerprint for updating metadata
resTags
:=
GetInstanceTags
(
cloudConfig
,
instanceName
)
_
,
err
:=
gceCloud
.
GetComputeService
()
.
Instances
.
SetTags
(
cloudConfig
.
ProjectID
,
cloudConfig
.
Z
one
,
instanceName
,
cloudConfig
.
ProjectID
,
z
one
,
instanceName
,
&
compute
.
Tags
{
Fingerprint
:
resTags
.
Fingerprint
,
Items
:
tags
})
.
Do
()
if
err
!=
nil
{
Failf
(
"failed to set instance tags: %v"
,
err
)
...
...
test/e2e/framework/ingress_utils.go
View file @
23dfe56b
...
...
@@ -974,14 +974,13 @@ func (j *IngressTestJig) GetIngressNodePorts() []string {
}
// ConstructFirewallForIngress returns the expected GCE firewall rule for the ingress resource
func
(
j
*
IngressTestJig
)
ConstructFirewallForIngress
(
gceController
*
GCEIngressController
)
*
compute
.
Firewall
{
nodeTags
:=
GetNodeTags
(
j
.
Client
,
gceController
.
Cloud
)
func
(
j
*
IngressTestJig
)
ConstructFirewallForIngress
(
gceController
*
GCEIngressController
,
nodeTag
string
)
*
compute
.
Firewall
{
nodePorts
:=
j
.
GetIngressNodePorts
()
fw
:=
compute
.
Firewall
{}
fw
.
Name
=
gceController
.
GetFirewallRuleName
()
fw
.
SourceRanges
=
gcecloud
.
LoadBalancerSrcRanges
()
fw
.
TargetTags
=
nodeTags
.
Items
fw
.
TargetTags
=
[]
string
{
nodeTag
}
fw
.
Allowed
=
[]
*
compute
.
FirewallAllowed
{
{
IPProtocol
:
"tcp"
,
...
...
test/e2e/ingress.go
View file @
23dfe56b
...
...
@@ -36,6 +36,7 @@ var _ = framework.KubeDescribe("Loadbalancing: L7", func() {
ns
string
jig
*
framework
.
IngressTestJig
conformanceTests
[]
framework
.
IngressConformanceTests
cloudConfig
framework
.
CloudConfig
)
f
:=
framework
.
NewDefaultFramework
(
"ingress"
)
...
...
@@ -43,6 +44,7 @@ var _ = framework.KubeDescribe("Loadbalancing: L7", func() {
f
.
BeforeEach
()
jig
=
framework
.
NewIngressTestJig
(
f
.
ClientSet
)
ns
=
f
.
Namespace
.
Name
cloudConfig
=
framework
.
TestContext
.
CloudConfig
// this test wants powerful permissions. Since the namespace names are unique, we can leave this
// lying around so we don't have to race any caches
...
...
@@ -122,7 +124,7 @@ var _ = framework.KubeDescribe("Loadbalancing: L7", func() {
By
(
"should have correct firewall rule for ingress"
)
fw
:=
gceController
.
GetFirewallRule
()
expFw
:=
jig
.
ConstructFirewallForIngress
(
gceController
)
expFw
:=
jig
.
ConstructFirewallForIngress
(
gceController
,
cloudConfig
.
NodeTag
)
// Passed the last argument as `true` to verify the backend ports is a subset
// of the allowed ports in firewall rule, given there may be other existing
// ingress resources and backends we are not aware of.
...
...
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