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
c3caf397
Commit
c3caf397
authored
Apr 17, 2015
by
Vish Kannan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6935 from derekwaynecarr/fix_quota
Fix quota status not updating with change in spec
parents
4b377e2e
ea0ddd4a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
1 deletion
+92
-1
resource_quota_controller.go
pkg/resourcequota/resource_quota_controller.go
+4
-1
resource_quota_controller_test.go
pkg/resourcequota/resource_quota_controller_test.go
+88
-0
No files found.
pkg/resourcequota/resource_quota_controller.go
View file @
c3caf397
...
@@ -108,10 +108,13 @@ func FilterQuotaPods(pods []api.Pod) []api.Pod {
...
@@ -108,10 +108,13 @@ func FilterQuotaPods(pods []api.Pod) []api.Pod {
// syncResourceQuota runs a complete sync of current status
// syncResourceQuota runs a complete sync of current status
func
(
rm
*
ResourceQuotaManager
)
syncResourceQuota
(
quota
api
.
ResourceQuota
)
(
err
error
)
{
func
(
rm
*
ResourceQuotaManager
)
syncResourceQuota
(
quota
api
.
ResourceQuota
)
(
err
error
)
{
// quota is dirty if any part of spec hard limits differs from the status hard limits
dirty
:=
!
api
.
Semantic
.
DeepEqual
(
quota
.
Spec
.
Hard
,
quota
.
Status
.
Hard
)
// dirty tracks if the usage status differs from the previous sync,
// dirty tracks if the usage status differs from the previous sync,
// if so, we send a new usage with latest status
// if so, we send a new usage with latest status
// if this is our first sync, it will be dirty by default, since we need track usage
// if this is our first sync, it will be dirty by default, since we need track usage
dirty
:=
quota
.
Status
.
Hard
==
nil
||
quota
.
Status
.
Used
==
nil
dirty
=
dirty
||
(
quota
.
Status
.
Hard
==
nil
||
quota
.
Status
.
Used
==
nil
)
// Create a usage object that is based on the quota resource version
// Create a usage object that is based on the quota resource version
usage
:=
api
.
ResourceQuota
{
usage
:=
api
.
ResourceQuota
{
...
...
pkg/resourcequota/resource_quota_controller_test.go
View file @
c3caf397
...
@@ -179,3 +179,91 @@ func TestSyncResourceQuota(t *testing.T) {
...
@@ -179,3 +179,91 @@ func TestSyncResourceQuota(t *testing.T) {
}
}
}
}
func
TestSyncResourceQuotaSpecChange
(
t
*
testing
.
T
)
{
quota
:=
api
.
ResourceQuota
{
Spec
:
api
.
ResourceQuotaSpec
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"4"
),
},
},
Status
:
api
.
ResourceQuotaStatus
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"3"
),
},
Used
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"0"
),
},
},
}
expectedUsage
:=
api
.
ResourceQuota
{
Status
:
api
.
ResourceQuotaStatus
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"4"
),
},
Used
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"0"
),
},
},
}
kubeClient
:=
testclient
.
NewSimpleFake
(
&
quota
)
resourceQuotaManager
:=
NewResourceQuotaManager
(
kubeClient
)
err
:=
resourceQuotaManager
.
syncResourceQuota
(
quota
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
usage
:=
kubeClient
.
Actions
[
1
]
.
Value
.
(
*
api
.
ResourceQuota
)
// ensure hard and used limits are what we expected
for
k
,
v
:=
range
expectedUsage
.
Status
.
Hard
{
actual
:=
usage
.
Status
.
Hard
[
k
]
actualValue
:=
actual
.
String
()
expectedValue
:=
v
.
String
()
if
expectedValue
!=
actualValue
{
t
.
Errorf
(
"Usage Hard: Key: %v, Expected: %v, Actual: %v"
,
k
,
expectedValue
,
actualValue
)
}
}
for
k
,
v
:=
range
expectedUsage
.
Status
.
Used
{
actual
:=
usage
.
Status
.
Used
[
k
]
actualValue
:=
actual
.
String
()
expectedValue
:=
v
.
String
()
if
expectedValue
!=
actualValue
{
t
.
Errorf
(
"Usage Used: Key: %v, Expected: %v, Actual: %v"
,
k
,
expectedValue
,
actualValue
)
}
}
}
func
TestSyncResourceQuotaNoChange
(
t
*
testing
.
T
)
{
quota
:=
api
.
ResourceQuota
{
Spec
:
api
.
ResourceQuotaSpec
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"4"
),
},
},
Status
:
api
.
ResourceQuotaStatus
{
Hard
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"4"
),
},
Used
:
api
.
ResourceList
{
api
.
ResourceCPU
:
resource
.
MustParse
(
"0"
),
},
},
}
kubeClient
:=
testclient
.
NewSimpleFake
(
&
api
.
PodList
{},
&
quota
)
resourceQuotaManager
:=
NewResourceQuotaManager
(
kubeClient
)
err
:=
resourceQuotaManager
.
syncResourceQuota
(
quota
)
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error %v"
,
err
)
}
if
len
(
kubeClient
.
Actions
)
!=
1
&&
kubeClient
.
Actions
[
0
]
.
Action
!=
"list-pods"
{
t
.
Errorf
(
"SyncResourceQuota made an unexpected client action when state was not dirty: %v"
,
kubeClient
.
Actions
)
}
}
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