mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Merge pull request #93389 from fisherxu/return-err
Return err directly when nodename in node object is not consistent with in cert
This commit is contained in:
commit
bb9ae50888
@ -390,6 +390,11 @@ func (p *Plugin) admitPVCStatus(nodeName string, a admission.Attributes) error {
|
|||||||
|
|
||||||
func (p *Plugin) admitNode(nodeName string, a admission.Attributes) error {
|
func (p *Plugin) admitNode(nodeName string, a admission.Attributes) error {
|
||||||
requestedName := a.GetName()
|
requestedName := a.GetName()
|
||||||
|
|
||||||
|
if requestedName != nodeName {
|
||||||
|
return admission.NewForbidden(a, fmt.Errorf("node %q is not allowed to modify node %q", nodeName, requestedName))
|
||||||
|
}
|
||||||
|
|
||||||
if a.GetOperation() == admission.Create {
|
if a.GetOperation() == admission.Create {
|
||||||
node, ok := a.GetObject().(*api.Node)
|
node, ok := a.GetObject().(*api.Node)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -409,9 +414,6 @@ func (p *Plugin) admitNode(nodeName string, a admission.Attributes) error {
|
|||||||
return admission.NewForbidden(a, fmt.Errorf("node %q is not allowed to set the following labels: %s", nodeName, strings.Join(forbiddenLabels.List(), ", ")))
|
return admission.NewForbidden(a, fmt.Errorf("node %q is not allowed to set the following labels: %s", nodeName, strings.Join(forbiddenLabels.List(), ", ")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if requestedName != nodeName {
|
|
||||||
return admission.NewForbidden(a, fmt.Errorf("node %q is not allowed to modify node %q", nodeName, requestedName))
|
|
||||||
}
|
|
||||||
|
|
||||||
if a.GetOperation() == admission.Update {
|
if a.GetOperation() == admission.Update {
|
||||||
node, ok := a.GetObject().(*api.Node)
|
node, ok := a.GetObject().(*api.Node)
|
||||||
|
@ -920,7 +920,7 @@ func Test_nodePlugin_Admit(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "forbid create of my node with forbidden labels",
|
name: "forbid create of my node with forbidden labels",
|
||||||
podsGetter: noExistingPods,
|
podsGetter: noExistingPods,
|
||||||
attributes: admission.NewAttributesRecord(setForbiddenCreateLabels(mynodeObj, ""), nil, nodeKind, mynodeObj.Namespace, "", nodeResource, "", admission.Create, &metav1.CreateOptions{}, false, mynode),
|
attributes: admission.NewAttributesRecord(setForbiddenCreateLabels(mynodeObj, ""), nil, nodeKind, mynodeObj.Namespace, "mynode", nodeResource, "", admission.Create, &metav1.CreateOptions{}, false, mynode),
|
||||||
err: `is not allowed to set the following labels: foo.node-restriction.kubernetes.io/foo, node-restriction.kubernetes.io/foo, other.k8s.io/foo, other.kubernetes.io/foo`,
|
err: `is not allowed to set the following labels: foo.node-restriction.kubernetes.io/foo, node-restriction.kubernetes.io/foo, other.k8s.io/foo, other.kubernetes.io/foo`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user