mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Remove default admissionReviewVersions in v1, make required in validation
This commit is contained in:
parent
9dcc722d2e
commit
6c3891a25f
@ -48,10 +48,6 @@ func SetDefaults_ValidatingWebhook(obj *admissionregistrationv1.ValidatingWebhoo
|
|||||||
obj.TimeoutSeconds = new(int32)
|
obj.TimeoutSeconds = new(int32)
|
||||||
*obj.TimeoutSeconds = 10
|
*obj.TimeoutSeconds = 10
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(obj.AdmissionReviewVersions) == 0 {
|
|
||||||
obj.AdmissionReviewVersions = []string{admissionregistrationv1.SchemeGroupVersion.Version}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetDefaults_MutatingWebhook(obj *admissionregistrationv1.MutatingWebhook) {
|
func SetDefaults_MutatingWebhook(obj *admissionregistrationv1.MutatingWebhook) {
|
||||||
@ -79,10 +75,6 @@ func SetDefaults_MutatingWebhook(obj *admissionregistrationv1.MutatingWebhook) {
|
|||||||
never := admissionregistrationv1.NeverReinvocationPolicy
|
never := admissionregistrationv1.NeverReinvocationPolicy
|
||||||
obj.ReinvocationPolicy = &never
|
obj.ReinvocationPolicy = &never
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(obj.AdmissionReviewVersions) == 0 {
|
|
||||||
obj.AdmissionReviewVersions = []string{admissionregistrationv1.SchemeGroupVersion.Version}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetDefaults_Rule(obj *admissionregistrationv1.Rule) {
|
func SetDefaults_Rule(obj *admissionregistrationv1.Rule) {
|
||||||
|
@ -167,7 +167,7 @@ func validateAdmissionReviewVersions(versions []string, requireRecognizedVersion
|
|||||||
|
|
||||||
// Currently only v1beta1 accepted in AdmissionReviewVersions
|
// Currently only v1beta1 accepted in AdmissionReviewVersions
|
||||||
if len(versions) < 1 {
|
if len(versions) < 1 {
|
||||||
allErrors = append(allErrors, field.Required(fldPath, ""))
|
allErrors = append(allErrors, field.Required(fldPath, fmt.Sprintf("must specify one of %v", strings.Join(AcceptedAdmissionReviewVersions, ", "))))
|
||||||
} else {
|
} else {
|
||||||
seen := map[string]bool{}
|
seen := map[string]bool{}
|
||||||
hasAcceptedVersion := false
|
hasAcceptedVersion := false
|
||||||
|
@ -58,6 +58,16 @@ func TestValidateValidatingWebhookConfiguration(t *testing.T) {
|
|||||||
expectedError string
|
expectedError string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
name: "AdmissionReviewVersions are required",
|
||||||
|
config: newValidatingWebhookConfiguration([]admissionregistration.ValidatingWebhook{
|
||||||
|
{
|
||||||
|
Name: "webhook.k8s.io",
|
||||||
|
ClientConfig: validClientConfig,
|
||||||
|
SideEffects: validSideEffect,
|
||||||
|
},
|
||||||
|
}, false),
|
||||||
|
expectedError: `webhooks[0].admissionReviewVersions: Required value: must specify one of v1beta1`,
|
||||||
|
}, {
|
||||||
name: "should fail on bad AdmissionReviewVersion value",
|
name: "should fail on bad AdmissionReviewVersion value",
|
||||||
config: newValidatingWebhookConfiguration([]admissionregistration.ValidatingWebhook{
|
config: newValidatingWebhookConfiguration([]admissionregistration.ValidatingWebhook{
|
||||||
{
|
{
|
||||||
@ -358,6 +368,17 @@ func TestValidateValidatingWebhookConfiguration(t *testing.T) {
|
|||||||
}, true),
|
}, true),
|
||||||
expectedError: `webhooks[0].failurePolicy: Unsupported value: "other": supported values: "Fail", "Ignore"`,
|
expectedError: `webhooks[0].failurePolicy: Unsupported value: "other": supported values: "Fail", "Ignore"`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "AdmissionReviewVersions are required",
|
||||||
|
config: newValidatingWebhookConfiguration([]admissionregistration.ValidatingWebhook{
|
||||||
|
{
|
||||||
|
Name: "webhook.k8s.io",
|
||||||
|
ClientConfig: validClientConfig,
|
||||||
|
SideEffects: validSideEffect,
|
||||||
|
},
|
||||||
|
}, false),
|
||||||
|
expectedError: `webhooks[0].admissionReviewVersions: Required value: must specify one of v1beta1`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "SideEffects are required",
|
name: "SideEffects are required",
|
||||||
config: newValidatingWebhookConfiguration([]admissionregistration.ValidatingWebhook{
|
config: newValidatingWebhookConfiguration([]admissionregistration.ValidatingWebhook{
|
||||||
|
@ -296,9 +296,7 @@ type ValidatingWebhook struct {
|
|||||||
// If a persisted webhook configuration specifies allowed versions and does not
|
// If a persisted webhook configuration specifies allowed versions and does not
|
||||||
// include any versions known to the API Server, calls to the webhook will fail
|
// include any versions known to the API Server, calls to the webhook will fail
|
||||||
// and be subject to the failure policy.
|
// and be subject to the failure policy.
|
||||||
// Default to `['v1beta1']`.
|
AdmissionReviewVersions []string `json:"admissionReviewVersions" protobuf:"bytes,8,rep,name=admissionReviewVersions"`
|
||||||
// +optional
|
|
||||||
AdmissionReviewVersions []string `json:"admissionReviewVersions,omitempty" protobuf:"bytes,8,rep,name=admissionReviewVersions"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MutatingWebhook describes an admission webhook and the resources and operations it applies to.
|
// MutatingWebhook describes an admission webhook and the resources and operations it applies to.
|
||||||
@ -427,9 +425,7 @@ type MutatingWebhook struct {
|
|||||||
// If a persisted webhook configuration specifies allowed versions and does not
|
// If a persisted webhook configuration specifies allowed versions and does not
|
||||||
// include any versions known to the API Server, calls to the webhook will fail
|
// include any versions known to the API Server, calls to the webhook will fail
|
||||||
// and be subject to the failure policy.
|
// and be subject to the failure policy.
|
||||||
// Default to `['v1beta1']`.
|
AdmissionReviewVersions []string `json:"admissionReviewVersions" protobuf:"bytes,8,rep,name=admissionReviewVersions"`
|
||||||
// +optional
|
|
||||||
AdmissionReviewVersions []string `json:"admissionReviewVersions,omitempty" protobuf:"bytes,8,rep,name=admissionReviewVersions"`
|
|
||||||
|
|
||||||
// reinvocationPolicy indicates whether this webhook should be called multiple times as part of a single admission evaluation.
|
// reinvocationPolicy indicates whether this webhook should be called multiple times as part of a single admission evaluation.
|
||||||
// Allowed values are "Never" and "IfNeeded".
|
// Allowed values are "Never" and "IfNeeded".
|
||||||
|
Loading…
Reference in New Issue
Block a user