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
7a5412a2
Commit
7a5412a2
authored
Jun 03, 2016
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move quota usage testing for loadbalancers into unit tests
parent
7476d977
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
178 deletions
+88
-178
services_test.go
pkg/quota/evaluator/core/services_test.go
+88
-0
resource_quota.go
test/e2e/resource_quota.go
+0
-178
No files found.
pkg/quota/evaluator/core/services_test.go
0 → 100644
View file @
7a5412a2
/*
Copyright 2016 The Kubernetes Authors All rights reserved.
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
core
import
(
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
"k8s.io/kubernetes/pkg/quota"
)
func
TestServiceEvaluatorMatchesResources
(
t
*
testing
.
T
)
{
kubeClient
:=
fake
.
NewSimpleClientset
()
evaluator
:=
NewServiceEvaluator
(
kubeClient
)
expected
:=
quota
.
ToSet
([]
api
.
ResourceName
{
api
.
ResourceServices
,
api
.
ResourceServicesNodePorts
,
api
.
ResourceServicesLoadBalancers
,
})
actual
:=
quota
.
ToSet
(
evaluator
.
MatchesResources
())
if
!
expected
.
Equal
(
actual
)
{
t
.
Errorf
(
"expected: %v, actual: %v"
,
expected
,
actual
)
}
}
func
TestServiceEvaluatorUsage
(
t
*
testing
.
T
)
{
kubeClient
:=
fake
.
NewSimpleClientset
()
evaluator
:=
NewServiceEvaluator
(
kubeClient
)
testCases
:=
map
[
string
]
struct
{
service
*
api
.
Service
usage
api
.
ResourceList
}{
"loadbalancer"
:
{
service
:
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeLoadBalancer
,
},
},
usage
:
api
.
ResourceList
{
api
.
ResourceServicesLoadBalancers
:
resource
.
MustParse
(
"1"
),
api
.
ResourceServices
:
resource
.
MustParse
(
"1"
),
},
},
"clusterip"
:
{
service
:
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeClusterIP
,
},
},
usage
:
api
.
ResourceList
{
api
.
ResourceServices
:
resource
.
MustParse
(
"1"
),
},
},
"nodeports"
:
{
service
:
&
api
.
Service
{
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeNodePort
,
},
},
usage
:
api
.
ResourceList
{
api
.
ResourceServices
:
resource
.
MustParse
(
"1"
),
api
.
ResourceServicesNodePorts
:
resource
.
MustParse
(
"1"
),
},
},
}
for
testName
,
testCase
:=
range
testCases
{
actual
:=
evaluator
.
Usage
(
testCase
.
service
)
if
!
quota
.
Equals
(
testCase
.
usage
,
actual
)
{
t
.
Errorf
(
"%s expected: %v, actual: %v"
,
testName
,
testCase
.
usage
,
actual
)
}
}
}
test/e2e/resource_quota.go
View file @
7a5412a2
...
...
@@ -132,184 +132,6 @@ var _ = framework.KubeDescribe("ResourceQuota", func() {
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
})
It
(
"should create a ResourceQuota and capture the life of a nodePort service."
,
func
()
{
By
(
"Creating a ResourceQuota"
)
quotaName
:=
"test-quota"
resourceQuota
:=
newTestResourceQuota
(
quotaName
)
resourceQuota
,
err
:=
createResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
resourceQuota
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring resource quota status is calculated"
)
usedResources
:=
api
.
ResourceList
{}
usedResources
[
api
.
ResourceQuotas
]
=
resource
.
MustParse
(
"1"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Creating a NodePort type Service"
)
service
:=
newTestServiceForQuota
(
"test-service"
,
api
.
ServiceTypeNodePort
)
service
,
err
=
f
.
Client
.
Services
(
f
.
Namespace
.
Name
)
.
Create
(
service
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring resource quota status captures service creation"
)
usedResources
=
api
.
ResourceList
{}
usedResources
[
api
.
ResourceQuotas
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServices
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServicesNodePorts
]
=
resource
.
MustParse
(
"1"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Deleting a Service"
)
err
=
f
.
Client
.
Services
(
f
.
Namespace
.
Name
)
.
Delete
(
service
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring resource quota status released usage"
)
usedResources
[
api
.
ResourceServices
]
=
resource
.
MustParse
(
"0"
)
usedResources
[
api
.
ResourceServicesNodePorts
]
=
resource
.
MustParse
(
"0"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
})
It
(
"should create a ResourceQuota and capture the life of a nodePort service updated to clusterIP."
,
func
()
{
By
(
"Creating a ResourceQuota"
)
quotaName
:=
"test-quota"
resourceQuota
:=
newTestResourceQuota
(
quotaName
)
resourceQuota
,
err
:=
createResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
resourceQuota
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring resource quota status is calculated"
)
usedResources
:=
api
.
ResourceList
{}
usedResources
[
api
.
ResourceQuotas
]
=
resource
.
MustParse
(
"1"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Creating a NodePort type Service"
)
service
:=
newTestServiceForQuota
(
"test-service"
,
api
.
ServiceTypeNodePort
)
service
,
err
=
f
.
Client
.
Services
(
f
.
Namespace
.
Name
)
.
Create
(
service
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring resource quota status captures service creation"
)
usedResources
=
api
.
ResourceList
{}
usedResources
[
api
.
ResourceQuotas
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServices
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServicesNodePorts
]
=
resource
.
MustParse
(
"1"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Updating the service type to clusterIP"
)
service
.
Spec
.
Type
=
api
.
ServiceTypeClusterIP
service
.
Spec
.
Ports
[
0
]
.
NodePort
=
0
_
,
err
=
f
.
Client
.
Services
(
f
.
Namespace
.
Name
)
.
Update
(
service
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Checking resource quota status capture service update"
)
usedResources
=
api
.
ResourceList
{}
usedResources
[
api
.
ResourceQuotas
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServices
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServicesNodePorts
]
=
resource
.
MustParse
(
"0"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Deleting a Service"
)
err
=
f
.
Client
.
Services
(
f
.
Namespace
.
Name
)
.
Delete
(
service
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring resource quota status released usage"
)
usedResources
[
api
.
ResourceServices
]
=
resource
.
MustParse
(
"0"
)
usedResources
[
api
.
ResourceServicesNodePorts
]
=
resource
.
MustParse
(
"0"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
})
It
(
"should create a ResourceQuota and capture the life of a loadBalancer service."
,
func
()
{
By
(
"Creating a ResourceQuota"
)
quotaName
:=
"test-quota"
resourceQuota
:=
newTestResourceQuota
(
quotaName
)
resourceQuota
,
err
:=
createResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
resourceQuota
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring resource quota status is calculated"
)
usedResources
:=
api
.
ResourceList
{}
usedResources
[
api
.
ResourceQuotas
]
=
resource
.
MustParse
(
"1"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Creating a loadBalancer type Service"
)
service
:=
newTestServiceForQuota
(
"test-service"
,
api
.
ServiceTypeLoadBalancer
)
service
,
err
=
f
.
Client
.
Services
(
f
.
Namespace
.
Name
)
.
Create
(
service
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring resource quota status captures service creation"
)
usedResources
=
api
.
ResourceList
{}
usedResources
[
api
.
ResourceQuotas
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServices
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServicesLoadBalancers
]
=
resource
.
MustParse
(
"1"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Deleting a Service"
)
err
=
f
.
Client
.
Services
(
f
.
Namespace
.
Name
)
.
Delete
(
service
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring resource quota status released usage"
)
usedResources
[
api
.
ResourceServices
]
=
resource
.
MustParse
(
"0"
)
usedResources
[
api
.
ResourceServicesLoadBalancers
]
=
resource
.
MustParse
(
"0"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
})
It
(
"should create a ResourceQuota and capture the life of a nodePort service updated to loadBalancer."
,
func
()
{
By
(
"Creating a ResourceQuota"
)
quotaName
:=
"test-quota"
resourceQuota
:=
newTestResourceQuota
(
quotaName
)
resourceQuota
,
err
:=
createResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
resourceQuota
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring resource quota status is calculated"
)
usedResources
:=
api
.
ResourceList
{}
usedResources
[
api
.
ResourceQuotas
]
=
resource
.
MustParse
(
"1"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Creating a nodePort type Service"
)
service
:=
newTestServiceForQuota
(
"test-service"
,
api
.
ServiceTypeNodePort
)
service
,
err
=
f
.
Client
.
Services
(
f
.
Namespace
.
Name
)
.
Create
(
service
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring resource quota status captures service creation"
)
usedResources
=
api
.
ResourceList
{}
usedResources
[
api
.
ResourceQuotas
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServices
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServicesLoadBalancers
]
=
resource
.
MustParse
(
"0"
)
usedResources
[
api
.
ResourceServicesNodePorts
]
=
resource
.
MustParse
(
"1"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Updating the service type to loadBalancer"
)
service
.
Spec
.
Type
=
api
.
ServiceTypeLoadBalancer
service
.
Spec
.
Ports
[
0
]
.
NodePort
=
0
_
,
err
=
f
.
Client
.
Services
(
f
.
Namespace
.
Name
)
.
Update
(
service
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Checking resource quota status capture service update"
)
usedResources
=
api
.
ResourceList
{}
usedResources
[
api
.
ResourceQuotas
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServices
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServicesLoadBalancers
]
=
resource
.
MustParse
(
"1"
)
usedResources
[
api
.
ResourceServicesNodePorts
]
=
resource
.
MustParse
(
"0"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Deleting a Service"
)
err
=
f
.
Client
.
Services
(
f
.
Namespace
.
Name
)
.
Delete
(
service
.
Name
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring resource quota status released usage"
)
usedResources
[
api
.
ResourceServices
]
=
resource
.
MustParse
(
"0"
)
usedResources
[
api
.
ResourceServicesLoadBalancers
]
=
resource
.
MustParse
(
"0"
)
err
=
waitForResourceQuota
(
f
.
Client
,
f
.
Namespace
.
Name
,
quotaName
,
usedResources
)
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
})
It
(
"should create a ResourceQuota and capture the life of a pod."
,
func
()
{
By
(
"Creating a ResourceQuota"
)
quotaName
:=
"test-quota"
...
...
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