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
d3c63630
Commit
d3c63630
authored
Apr 08, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use single writer to improve quota performance
parent
daf6be1a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
205 additions
and
0 deletions
+205
-0
admission.go
plugin/pkg/admission/resourcequota/admission.go
+0
-0
admission_test.go
plugin/pkg/admission/resourcequota/admission_test.go
+0
-0
controller.go
plugin/pkg/admission/resourcequota/controller.go
+0
-0
quota_test.go
test/integration/quota_test.go
+205
-0
No files found.
plugin/pkg/admission/resourcequota/admission.go
View file @
d3c63630
This diff is collapsed.
Click to expand it.
plugin/pkg/admission/resourcequota/admission_test.go
View file @
d3c63630
This diff is collapsed.
Click to expand it.
plugin/pkg/admission/resourcequota/controller.go
0 → 100644
View file @
d3c63630
This diff is collapsed.
Click to expand it.
test/integration/quota_test.go
0 → 100644
View file @
d3c63630
// +build integration,!no-etcd
/*
Copyright 2015 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
integration
import
(
"net/http"
"net/http/httptest"
"testing"
"time"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/api/unversioned"
clientset
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/controller"
replicationcontroller
"k8s.io/kubernetes/pkg/controller/replication"
resourcequotacontroller
"k8s.io/kubernetes/pkg/controller/resourcequota"
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/master"
quotainstall
"k8s.io/kubernetes/pkg/quota/install"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/plugin/pkg/admission/resourcequota"
"k8s.io/kubernetes/test/integration/framework"
)
// 1.2 code gets:
// quota_test.go:95: Took 4.218619579s to scale up without quota
// quota_test.go:199: unexpected error: timed out waiting for the condition, ended with 342 pods (1 minute)
// 1.3+ code gets:
// quota_test.go:100: Took 4.196205966s to scale up without quota
// quota_test.go:115: Took 12.021640372s to scale up with quota
func
TestQuota
(
t
*
testing
.
T
)
{
framework
.
DeleteAllEtcdKeys
()
// Set up a master
var
m
*
master
.
Master
s
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
m
.
Handler
.
ServeHTTP
(
w
,
req
)
}))
// TODO: Uncomment when fix #19254
// defer s.Close()
clientset
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
QPS
:
-
1
,
Host
:
s
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
admission
,
err
:=
resourcequota
.
NewResourceQuota
(
clientset
,
quotainstall
.
NewRegistry
(
clientset
),
5
)
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
masterConfig
:=
framework
.
NewIntegrationTestMasterConfig
()
masterConfig
.
AdmissionControl
=
admission
m
,
err
=
master
.
New
(
masterConfig
)
if
err
!=
nil
{
t
.
Fatalf
(
"Error in bringing up the master: %v"
,
err
)
}
go
replicationcontroller
.
NewReplicationManagerFromClient
(
clientset
,
controller
.
NoResyncPeriodFunc
,
replicationcontroller
.
BurstReplicas
,
4096
)
.
Run
(
3
,
wait
.
NeverStop
)
resourceQuotaRegistry
:=
quotainstall
.
NewRegistry
(
clientset
)
groupKindsToReplenish
:=
[]
unversioned
.
GroupKind
{
api
.
Kind
(
"Pod"
),
api
.
Kind
(
"Service"
),
api
.
Kind
(
"ReplicationController"
),
api
.
Kind
(
"PersistentVolumeClaim"
),
api
.
Kind
(
"Secret"
),
}
resourceQuotaControllerOptions
:=
&
resourcequotacontroller
.
ResourceQuotaControllerOptions
{
KubeClient
:
clientset
,
ResyncPeriod
:
controller
.
NoResyncPeriodFunc
,
Registry
:
resourceQuotaRegistry
,
GroupKindsToReplenish
:
groupKindsToReplenish
,
ReplenishmentResyncPeriod
:
controller
.
NoResyncPeriodFunc
,
ControllerFactory
:
resourcequotacontroller
.
NewReplenishmentControllerFactoryFromClient
(
clientset
),
}
go
resourcequotacontroller
.
NewResourceQuotaController
(
resourceQuotaControllerOptions
)
.
Run
(
2
,
wait
.
NeverStop
)
startTime
:=
time
.
Now
()
scale
(
t
,
api
.
NamespaceDefault
,
clientset
)
endTime
:=
time
.
Now
()
t
.
Logf
(
"Took %v to scale up without quota"
,
endTime
.
Sub
(
startTime
))
quota
:=
&
api
.
ResourceQuota
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"quota"
},
Spec
:
api
.
ResourceQuotaSpec
{
Hard
:
api
.
ResourceList
{
api
.
ResourcePods
:
resource
.
MustParse
(
"1000"
),
},
},
}
waitForQuota
(
t
,
quota
,
clientset
)
startTime
=
time
.
Now
()
scale
(
t
,
"quotaed"
,
clientset
)
endTime
=
time
.
Now
()
t
.
Logf
(
"Took %v to scale up with quota"
,
endTime
.
Sub
(
startTime
))
}
func
waitForQuota
(
t
*
testing
.
T
,
quota
*
api
.
ResourceQuota
,
clientset
*
clientset
.
Clientset
)
{
w
,
err
:=
clientset
.
Core
()
.
ResourceQuotas
(
quota
.
Namespace
)
.
Watch
(
api
.
SingleObject
(
api
.
ObjectMeta
{
Name
:
quota
.
Name
}))
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
err
:=
clientset
.
Core
()
.
ResourceQuotas
(
"quotaed"
)
.
Create
(
quota
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
_
,
err
=
watch
.
Until
(
1
*
time
.
Minute
,
w
,
func
(
event
watch
.
Event
)
(
bool
,
error
)
{
switch
event
.
Type
{
case
watch
.
Modified
:
default
:
return
false
,
nil
}
switch
cast
:=
event
.
Object
.
(
type
)
{
case
*
api
.
ResourceQuota
:
if
len
(
cast
.
Status
.
Hard
)
>
0
{
return
true
,
nil
}
}
return
false
,
nil
})
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
}
func
scale
(
t
*
testing
.
T
,
namespace
string
,
clientset
*
clientset
.
Clientset
)
{
target
:=
1000
rc
:=
&
api
.
ReplicationController
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
namespace
,
},
Spec
:
api
.
ReplicationControllerSpec
{
Replicas
:
target
,
Selector
:
map
[
string
]
string
{
"foo"
:
"bar"
},
Template
:
&
api
.
PodTemplateSpec
{
ObjectMeta
:
api
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"foo"
:
"bar"
,
},
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"container"
,
Image
:
"busybox"
,
},
},
},
},
},
}
w
,
err
:=
clientset
.
Core
()
.
ReplicationControllers
(
namespace
)
.
Watch
(
api
.
SingleObject
(
api
.
ObjectMeta
{
Name
:
rc
.
Name
}))
if
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
if
_
,
err
:=
clientset
.
Core
()
.
ReplicationControllers
(
namespace
)
.
Create
(
rc
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error: %v"
,
err
)
}
_
,
err
=
watch
.
Until
(
3
*
time
.
Minute
,
w
,
func
(
event
watch
.
Event
)
(
bool
,
error
)
{
switch
event
.
Type
{
case
watch
.
Modified
:
default
:
return
false
,
nil
}
switch
cast
:=
event
.
Object
.
(
type
)
{
case
*
api
.
ReplicationController
:
if
cast
.
Status
.
Replicas
==
target
{
return
true
,
nil
}
}
return
false
,
nil
})
if
err
!=
nil
{
pods
,
_
:=
clientset
.
Core
()
.
Pods
(
namespace
)
.
List
(
api
.
ListOptions
{
LabelSelector
:
labels
.
Everything
(),
FieldSelector
:
fields
.
Everything
()})
t
.
Fatalf
(
"unexpected error: %v, ended with %v pods"
,
err
,
len
(
pods
.
Items
))
}
}
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