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
7b1b46b9
Commit
7b1b46b9
authored
Apr 26, 2019
by
Mansi Agarwal
Committed by
mansi-a
May 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accept admission request if resource is being deleted
parent
42a89ea8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
0 deletions
+90
-0
admission_test.go
plugin/pkg/admission/resourcequota/admission_test.go
+90
-0
No files found.
plugin/pkg/admission/resourcequota/admission_test.go
View file @
7b1b46b9
...
...
@@ -2163,3 +2163,93 @@ func TestAdmitLimitedScopeWithCoverQuota(t *testing.T) {
}
}
// TestAdmitZeroDeltaUsageWithoutCoveringQuota verifies that resource quota is not required for zero delta requests.
func
TestAdmitZeroDeltaUsageWithoutCoveringQuota
(
t
*
testing
.
T
)
{
kubeClient
:=
fake
.
NewSimpleClientset
()
stopCh
:=
make
(
chan
struct
{})
defer
close
(
stopCh
)
informerFactory
:=
informers
.
NewSharedInformerFactory
(
kubeClient
,
controller
.
NoResyncPeriodFunc
())
quotaAccessor
,
_
:=
newQuotaAccessor
()
quotaAccessor
.
client
=
kubeClient
quotaAccessor
.
lister
=
informerFactory
.
Core
()
.
V1
()
.
ResourceQuotas
()
.
Lister
()
// disable services unless there is a covering quota.
config
:=
&
resourcequotaapi
.
Configuration
{
LimitedResources
:
[]
resourcequotaapi
.
LimitedResource
{
{
Resource
:
"services"
,
MatchContains
:
[]
string
{
"services"
},
},
},
}
quotaConfiguration
:=
install
.
NewQuotaConfigurationForAdmission
()
evaluator
:=
NewQuotaEvaluator
(
quotaAccessor
,
quotaConfiguration
.
IgnoredResources
(),
generic
.
NewRegistry
(
quotaConfiguration
.
Evaluators
()),
nil
,
config
,
5
,
stopCh
)
handler
:=
&
QuotaAdmission
{
Handler
:
admission
.
NewHandler
(
admission
.
Create
,
admission
.
Update
),
evaluator
:
evaluator
,
}
existingService
:=
&
api
.
Service
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"service"
,
Namespace
:
"test"
,
ResourceVersion
:
"1"
},
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeLoadBalancer
},
}
newService
:=
&
api
.
Service
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"service"
,
Namespace
:
"test"
},
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeLoadBalancer
},
}
err
:=
handler
.
Validate
(
admission
.
NewAttributesRecord
(
newService
,
existingService
,
api
.
Kind
(
"Service"
)
.
WithVersion
(
"version"
),
newService
.
Namespace
,
newService
.
Name
,
corev1
.
Resource
(
"services"
)
.
WithVersion
(
"version"
),
""
,
admission
.
Update
,
false
,
nil
),
nil
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
// TestAdmitRejectDeltaUsageWithoutCoveringQuota verifies that resource quota is required for non zero delta requests.
func
TestAdmitRejectDeltaUsageWithoutCoveringQuota
(
t
*
testing
.
T
)
{
kubeClient
:=
fake
.
NewSimpleClientset
()
stopCh
:=
make
(
chan
struct
{})
defer
close
(
stopCh
)
informerFactory
:=
informers
.
NewSharedInformerFactory
(
kubeClient
,
controller
.
NoResyncPeriodFunc
())
quotaAccessor
,
_
:=
newQuotaAccessor
()
quotaAccessor
.
client
=
kubeClient
quotaAccessor
.
lister
=
informerFactory
.
Core
()
.
V1
()
.
ResourceQuotas
()
.
Lister
()
// disable services unless there is a covering quota.
config
:=
&
resourcequotaapi
.
Configuration
{
LimitedResources
:
[]
resourcequotaapi
.
LimitedResource
{
{
Resource
:
"services"
,
MatchContains
:
[]
string
{
"services"
},
},
},
}
quotaConfiguration
:=
install
.
NewQuotaConfigurationForAdmission
()
evaluator
:=
NewQuotaEvaluator
(
quotaAccessor
,
quotaConfiguration
.
IgnoredResources
(),
generic
.
NewRegistry
(
quotaConfiguration
.
Evaluators
()),
nil
,
config
,
5
,
stopCh
)
handler
:=
&
QuotaAdmission
{
Handler
:
admission
.
NewHandler
(
admission
.
Create
,
admission
.
Update
),
evaluator
:
evaluator
,
}
existingService
:=
&
api
.
Service
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"service"
,
Namespace
:
"test"
,
ResourceVersion
:
"1"
},
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeLoadBalancer
},
}
newService
:=
&
api
.
Service
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"service"
,
Namespace
:
"test"
},
Spec
:
api
.
ServiceSpec
{
Type
:
api
.
ServiceTypeNodePort
,
Ports
:
[]
api
.
ServicePort
{{
Port
:
1234
}},
},
}
err
:=
handler
.
Validate
(
admission
.
NewAttributesRecord
(
newService
,
existingService
,
api
.
Kind
(
"Service"
)
.
WithVersion
(
"version"
),
newService
.
Namespace
,
newService
.
Name
,
corev1
.
Resource
(
"services"
)
.
WithVersion
(
"version"
),
""
,
admission
.
Update
,
false
,
nil
),
nil
)
if
err
==
nil
{
t
.
Errorf
(
"Expected an error for consuming a limited resource without 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