mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Fix boilerplate and make stub controller
This commit is contained in:
parent
1e2b995a79
commit
74d2ee69eb
@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
|
|||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
@ -17,19 +17,34 @@ limitations under the License.
|
|||||||
package admission
|
package admission
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
// alwaysAdmitController says yes to all admission control requests, its useful for testing.
|
// stubAdmissionController is capable of either always admitting or always denying incoming requests
|
||||||
type alwaysAdmitController struct{}
|
type stubAdmissionController struct {
|
||||||
|
admit bool
|
||||||
|
}
|
||||||
|
|
||||||
func (alwaysAdmitController) AdmissionControl(operation, kind, namespace string, object runtime.Object) (err error) {
|
func (ac *stubAdmissionController) AdmissionControl(operation, kind, namespace string, object runtime.Object) (err error) {
|
||||||
return nil
|
if !ac.admit {
|
||||||
|
err = errors.New("No changes allowed")
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAlwaysAdmitController() AdmissionControl {
|
func NewAlwaysAdmitController() AdmissionControl {
|
||||||
return new(alwaysAdmitController)
|
return &stubAdmissionController{
|
||||||
|
admit: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAlwaysDenyController() AdmissionControl {
|
||||||
|
return &stubAdmissionController{
|
||||||
|
admit: false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type admissionController struct {
|
type admissionController struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user