mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
WIP: RC pods
This commit is contained in:
parent
9af86c5535
commit
7f64bb649b
@ -258,6 +258,10 @@ func DropDisabledAlphaFields(podSpec *api.PodSpec) {
|
|||||||
DropDisabledVolumeDevicesAlphaFields(podSpec)
|
DropDisabledVolumeDevicesAlphaFields(podSpec)
|
||||||
|
|
||||||
DropDisabledRunAsGroupField(podSpec)
|
DropDisabledRunAsGroupField(podSpec)
|
||||||
|
|
||||||
|
if !utilfeature.DefaultFeatureGate.Enabled(features.RuntimeClass) && podSpec.RuntimeClassName != "" {
|
||||||
|
podSpec.RuntimeClassName = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DropDisabledRunAsGroupField removes disabled fields from PodSpec related
|
// DropDisabledRunAsGroupField removes disabled fields from PodSpec related
|
||||||
|
@ -2571,6 +2571,12 @@ type PodSpec struct {
|
|||||||
// More info: https://github.com/kubernetes/community/blob/master/keps/sig-network/0007-pod-ready%2B%2B.md
|
// More info: https://github.com/kubernetes/community/blob/master/keps/sig-network/0007-pod-ready%2B%2B.md
|
||||||
// +optional
|
// +optional
|
||||||
ReadinessGates []PodReadinessGate
|
ReadinessGates []PodReadinessGate
|
||||||
|
// RuntimeClassName refers to a RuntimeClass object with the same name, which should be used to
|
||||||
|
// run this pod. If no RuntimeClass resource matches the named class, the pod will not be run.
|
||||||
|
// More info: https://github.com/kubernetes/community/blob/master/keps/sig-node/0014-runtime-class.md
|
||||||
|
// This is an alpha feature and may change in the future.
|
||||||
|
// +optional
|
||||||
|
RuntimeClassName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the
|
// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the
|
||||||
|
@ -256,6 +256,11 @@ var ValidateClassName = apimachineryvalidation.NameIsDNSSubdomain
|
|||||||
// class name is valid.
|
// class name is valid.
|
||||||
var ValidatePriorityClassName = apimachineryvalidation.NameIsDNSSubdomain
|
var ValidatePriorityClassName = apimachineryvalidation.NameIsDNSSubdomain
|
||||||
|
|
||||||
|
// ValidateRuntimeClassName can be used to check whether the given RuntimeClass name is valid.
|
||||||
|
// Prefix indicates this name will be used as part of generation, in which case
|
||||||
|
// trailing dashes are allowed.
|
||||||
|
var ValidateRuntimeClassName = apimachineryvalidation.NameIsDNSSubdomain
|
||||||
|
|
||||||
// Validates that given value is not negative.
|
// Validates that given value is not negative.
|
||||||
func ValidateNonnegativeField(value int64, fldPath *field.Path) field.ErrorList {
|
func ValidateNonnegativeField(value int64, fldPath *field.Path) field.ErrorList {
|
||||||
return apimachineryvalidation.ValidateNonnegativeField(value, fldPath)
|
return apimachineryvalidation.ValidateNonnegativeField(value, fldPath)
|
||||||
@ -2999,6 +3004,14 @@ func ValidatePodSpec(spec *core.PodSpec, fldPath *field.Path) field.ErrorList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(spec.RuntimeClassName) > 0 {
|
||||||
|
if utilfeature.DefaultFeatureGate.Enabled(features.RuntimeClass) {
|
||||||
|
for _, msg := range ValidateRuntimeClassName(spec.RuntimeClassName, false) {
|
||||||
|
allErrs = append(allErrs, field.Invalid(fldPath.Child("runtimeClassName"), spec.RuntimeClassName, msg))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6032,6 +6032,7 @@ func TestValidatePodSpec(t *testing.T) {
|
|||||||
|
|
||||||
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodPriority, true)()
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodPriority, true)()
|
||||||
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodShareProcessNamespace, true)()
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.PodShareProcessNamespace, true)()
|
||||||
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.RuntimeClass, true)()
|
||||||
|
|
||||||
successCases := []core.PodSpec{
|
successCases := []core.PodSpec{
|
||||||
{ // Populate basic fields, leave defaults for most.
|
{ // Populate basic fields, leave defaults for most.
|
||||||
@ -6166,6 +6167,12 @@ func TestValidatePodSpec(t *testing.T) {
|
|||||||
ShareProcessNamespace: &[]bool{true}[0],
|
ShareProcessNamespace: &[]bool{true}[0],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{ // Populate RuntimeClassName
|
||||||
|
Containers: []core.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}},
|
||||||
|
RestartPolicy: core.RestartPolicyAlways,
|
||||||
|
DNSPolicy: core.DNSClusterFirst,
|
||||||
|
RuntimeClassName: "valid-sandbox",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i := range successCases {
|
for i := range successCases {
|
||||||
if errs := ValidatePodSpec(&successCases[i], field.NewPath("field")); len(errs) != 0 {
|
if errs := ValidatePodSpec(&successCases[i], field.NewPath("field")); len(errs) != 0 {
|
||||||
@ -6347,6 +6354,12 @@ func TestValidatePodSpec(t *testing.T) {
|
|||||||
ShareProcessNamespace: &[]bool{true}[0],
|
ShareProcessNamespace: &[]bool{true}[0],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"bad RuntimeClassName": {
|
||||||
|
Containers: []core.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent", TerminationMessagePolicy: "File"}},
|
||||||
|
RestartPolicy: core.RestartPolicyAlways,
|
||||||
|
DNSPolicy: core.DNSClusterFirst,
|
||||||
|
RuntimeClassName: "invalid/sandbox",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for k, v := range failureCases {
|
for k, v := range failureCases {
|
||||||
if errs := ValidatePodSpec(&v, field.NewPath("field")); len(errs) == 0 {
|
if errs := ValidatePodSpec(&v, field.NewPath("field")); len(errs) == 0 {
|
||||||
|
@ -344,6 +344,12 @@ const (
|
|||||||
//
|
//
|
||||||
// Enables CSI to use raw block storage volumes
|
// Enables CSI to use raw block storage volumes
|
||||||
CSIBlockVolume utilfeature.Feature = "CSIBlockVolume"
|
CSIBlockVolume utilfeature.Feature = "CSIBlockVolume"
|
||||||
|
|
||||||
|
// owner: @tallclair
|
||||||
|
// alpha: v1.12
|
||||||
|
//
|
||||||
|
// Enables RuntimeClass, for selecting between multiple runtimes to run a pod.
|
||||||
|
RuntimeClass utilfeature.Feature = "RuntimeClass"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -402,6 +408,7 @@ var defaultKubernetesFeatureGates = map[utilfeature.Feature]utilfeature.FeatureS
|
|||||||
KubeletPluginsWatcher: {Default: false, PreRelease: utilfeature.Alpha},
|
KubeletPluginsWatcher: {Default: false, PreRelease: utilfeature.Alpha},
|
||||||
ResourceQuotaScopeSelectors: {Default: true, PreRelease: utilfeature.Beta},
|
ResourceQuotaScopeSelectors: {Default: true, PreRelease: utilfeature.Beta},
|
||||||
CSIBlockVolume: {Default: false, PreRelease: utilfeature.Alpha},
|
CSIBlockVolume: {Default: false, PreRelease: utilfeature.Alpha},
|
||||||
|
RuntimeClass: {Default: false, PreRelease: utilfeature.Alpha},
|
||||||
|
|
||||||
// inherited features from generic apiserver, relisted here to get a conflict if it is changed
|
// inherited features from generic apiserver, relisted here to get a conflict if it is changed
|
||||||
// unintentionally on either side:
|
// unintentionally on either side:
|
||||||
|
@ -2865,6 +2865,12 @@ type PodSpec struct {
|
|||||||
// More info: https://github.com/kubernetes/community/blob/master/keps/sig-network/0007-pod-ready%2B%2B.md
|
// More info: https://github.com/kubernetes/community/blob/master/keps/sig-network/0007-pod-ready%2B%2B.md
|
||||||
// +optional
|
// +optional
|
||||||
ReadinessGates []PodReadinessGate `json:"readinessGates,omitempty" protobuf:"bytes,28,opt,name=readinessGates"`
|
ReadinessGates []PodReadinessGate `json:"readinessGates,omitempty" protobuf:"bytes,28,opt,name=readinessGates"`
|
||||||
|
// RuntimeClassName refers to a RuntimeClass object with the same name, which should be used to
|
||||||
|
// run this pod. If no RuntimeClass resource matches the named class, the pod will not be run.
|
||||||
|
// More info: https://github.com/kubernetes/community/blob/master/keps/sig-node/0014-runtime-class.md
|
||||||
|
// This is an alpha feature and may change in the future.
|
||||||
|
// +optional
|
||||||
|
RuntimeClassName string `json:"runtimeClassName,omitempty" protobuf:"bytes,29,opt,name=runtimeClassName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the
|
// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the
|
||||||
|
Loading…
Reference in New Issue
Block a user