mirror of https://github.com/k3s-io/k3s
Merge pull request #10090 from GoogleCloudPlatform/revert-10083-revert-9688-validate_pod_spec
Revert "Revert "Validate service account name in pod spec""pull/6/head
commit
864412334f
|
@ -963,6 +963,11 @@ func ValidatePodSpec(spec *api.PodSpec) errs.ValidationErrorList {
|
|||
allErrs = append(allErrs, ValidateLabels(spec.NodeSelector, "nodeSelector")...)
|
||||
allErrs = append(allErrs, validateHostNetwork(spec.HostNetwork, spec.Containers).Prefix("hostNetwork")...)
|
||||
allErrs = append(allErrs, validateImagePullSecrets(spec.ImagePullSecrets).Prefix("imagePullSecrets")...)
|
||||
if len(spec.ServiceAccount) > 0 {
|
||||
if ok, msg := ValidateServiceAccountName(spec.ServiceAccount, false); !ok {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("serviceAccount", spec.ServiceAccount, msg))
|
||||
}
|
||||
}
|
||||
|
||||
if spec.ActiveDeadlineSeconds != nil {
|
||||
if *spec.ActiveDeadlineSeconds <= 0 {
|
||||
|
|
|
@ -1052,6 +1052,7 @@ func TestValidatePodSpec(t *testing.T) {
|
|||
NodeName: "foobar",
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
ActiveDeadlineSeconds: &activeDeadlineSeconds,
|
||||
ServiceAccount: "acct",
|
||||
},
|
||||
{ // Populate HostNetwork.
|
||||
Containers: []api.Container{
|
||||
|
@ -1092,6 +1093,12 @@ func TestValidatePodSpec(t *testing.T) {
|
|||
RestartPolicy: api.RestartPolicyAlways,
|
||||
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
|
||||
},
|
||||
"bad service account name": {
|
||||
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
|
||||
RestartPolicy: api.RestartPolicyAlways,
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
ServiceAccount: "invalidName",
|
||||
},
|
||||
"bad restart policy": {
|
||||
RestartPolicy: "UnknowPolicy",
|
||||
DNSPolicy: api.DNSClusterFirst,
|
||||
|
|
Loading…
Reference in New Issue