mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #24907 from smarterclayton/default_inliners
Automatic merge from submit-queue Make all defaulters public Will allow for generating direct accessors in conversion code instead of using reflection. @wojtek-t
This commit is contained in:
commit
46a6cae14e
@ -25,15 +25,40 @@ import (
|
||||
|
||||
func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
scheme.AddDefaultingFuncs(
|
||||
func(obj *PodExecOptions) {
|
||||
SetDefaults_PodExecOptions,
|
||||
SetDefaults_PodAttachOptions,
|
||||
SetDefaults_ReplicationController,
|
||||
SetDefaults_Volume,
|
||||
SetDefaults_ContainerPort,
|
||||
SetDefaults_Container,
|
||||
SetDefaults_ServiceSpec,
|
||||
SetDefaults_Pod,
|
||||
SetDefaults_PodSpec,
|
||||
SetDefaults_Probe,
|
||||
SetDefaults_Secret,
|
||||
SetDefaults_PersistentVolume,
|
||||
SetDefaults_PersistentVolumeClaim,
|
||||
SetDefaults_ISCSIVolumeSource,
|
||||
SetDefaults_Endpoints,
|
||||
SetDefaults_HTTPGetAction,
|
||||
SetDefaults_NamespaceStatus,
|
||||
SetDefaults_Node,
|
||||
SetDefaults_NodeStatus,
|
||||
SetDefaults_ObjectFieldSelector,
|
||||
SetDefaults_LimitRangeItem,
|
||||
SetDefaults_ConfigMap,
|
||||
)
|
||||
}
|
||||
|
||||
func SetDefaults_PodExecOptions(obj *PodExecOptions) {
|
||||
obj.Stdout = true
|
||||
obj.Stderr = true
|
||||
},
|
||||
func(obj *PodAttachOptions) {
|
||||
}
|
||||
func SetDefaults_PodAttachOptions(obj *PodAttachOptions) {
|
||||
obj.Stdout = true
|
||||
obj.Stderr = true
|
||||
},
|
||||
func(obj *ReplicationController) {
|
||||
}
|
||||
func SetDefaults_ReplicationController(obj *ReplicationController) {
|
||||
var labels map[string]string
|
||||
if obj.Spec.Template != nil {
|
||||
labels = obj.Spec.Template.Labels
|
||||
@ -51,20 +76,20 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
obj.Spec.Replicas = new(int32)
|
||||
*obj.Spec.Replicas = 1
|
||||
}
|
||||
},
|
||||
func(obj *Volume) {
|
||||
}
|
||||
func SetDefaults_Volume(obj *Volume) {
|
||||
if util.AllPtrFieldsNil(&obj.VolumeSource) {
|
||||
obj.VolumeSource = VolumeSource{
|
||||
EmptyDir: &EmptyDirVolumeSource{},
|
||||
}
|
||||
}
|
||||
},
|
||||
func(obj *ContainerPort) {
|
||||
}
|
||||
func SetDefaults_ContainerPort(obj *ContainerPort) {
|
||||
if obj.Protocol == "" {
|
||||
obj.Protocol = ProtocolTCP
|
||||
}
|
||||
},
|
||||
func(obj *Container) {
|
||||
}
|
||||
func SetDefaults_Container(obj *Container) {
|
||||
if obj.ImagePullPolicy == "" {
|
||||
// Ignore error and assume it has been validated elsewhere
|
||||
_, tag, _ := parsers.ParseImageName(obj.Image)
|
||||
@ -80,8 +105,8 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
if obj.TerminationMessagePath == "" {
|
||||
obj.TerminationMessagePath = TerminationMessagePathDefault
|
||||
}
|
||||
},
|
||||
func(obj *ServiceSpec) {
|
||||
}
|
||||
func SetDefaults_ServiceSpec(obj *ServiceSpec) {
|
||||
if obj.SessionAffinity == "" {
|
||||
obj.SessionAffinity = ServiceAffinityNone
|
||||
}
|
||||
@ -97,8 +122,8 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
sp.TargetPort = intstr.FromInt(int(sp.Port))
|
||||
}
|
||||
}
|
||||
},
|
||||
func(obj *Pod) {
|
||||
}
|
||||
func SetDefaults_Pod(obj *Pod) {
|
||||
// If limits are specified, but requests are not, default requests to limits
|
||||
// This is done here rather than a more specific defaulting pass on ResourceRequirements
|
||||
// because we only want this defaulting semantic to take place on a Pod and not a PodTemplate
|
||||
@ -115,8 +140,8 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
func(obj *PodSpec) {
|
||||
}
|
||||
func SetDefaults_PodSpec(obj *PodSpec) {
|
||||
if obj.DNSPolicy == "" {
|
||||
obj.DNSPolicy = DNSClusterFirst
|
||||
}
|
||||
@ -133,8 +158,8 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
period := int64(DefaultTerminationGracePeriodSeconds)
|
||||
obj.TerminationGracePeriodSeconds = &period
|
||||
}
|
||||
},
|
||||
func(obj *Probe) {
|
||||
}
|
||||
func SetDefaults_Probe(obj *Probe) {
|
||||
if obj.TimeoutSeconds == 0 {
|
||||
obj.TimeoutSeconds = 1
|
||||
}
|
||||
@ -147,31 +172,31 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
if obj.FailureThreshold == 0 {
|
||||
obj.FailureThreshold = 3
|
||||
}
|
||||
},
|
||||
func(obj *Secret) {
|
||||
}
|
||||
func SetDefaults_Secret(obj *Secret) {
|
||||
if obj.Type == "" {
|
||||
obj.Type = SecretTypeOpaque
|
||||
}
|
||||
},
|
||||
func(obj *PersistentVolume) {
|
||||
}
|
||||
func SetDefaults_PersistentVolume(obj *PersistentVolume) {
|
||||
if obj.Status.Phase == "" {
|
||||
obj.Status.Phase = VolumePending
|
||||
}
|
||||
if obj.Spec.PersistentVolumeReclaimPolicy == "" {
|
||||
obj.Spec.PersistentVolumeReclaimPolicy = PersistentVolumeReclaimRetain
|
||||
}
|
||||
},
|
||||
func(obj *PersistentVolumeClaim) {
|
||||
}
|
||||
func SetDefaults_PersistentVolumeClaim(obj *PersistentVolumeClaim) {
|
||||
if obj.Status.Phase == "" {
|
||||
obj.Status.Phase = ClaimPending
|
||||
}
|
||||
},
|
||||
func(obj *ISCSIVolumeSource) {
|
||||
}
|
||||
func SetDefaults_ISCSIVolumeSource(obj *ISCSIVolumeSource) {
|
||||
if obj.ISCSIInterface == "" {
|
||||
obj.ISCSIInterface = "default"
|
||||
}
|
||||
},
|
||||
func(obj *Endpoints) {
|
||||
}
|
||||
func SetDefaults_Endpoints(obj *Endpoints) {
|
||||
for i := range obj.Subsets {
|
||||
ss := &obj.Subsets[i]
|
||||
for i := range ss.Ports {
|
||||
@ -181,26 +206,26 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
func(obj *HTTPGetAction) {
|
||||
}
|
||||
func SetDefaults_HTTPGetAction(obj *HTTPGetAction) {
|
||||
if obj.Path == "" {
|
||||
obj.Path = "/"
|
||||
}
|
||||
if obj.Scheme == "" {
|
||||
obj.Scheme = URISchemeHTTP
|
||||
}
|
||||
},
|
||||
func(obj *NamespaceStatus) {
|
||||
}
|
||||
func SetDefaults_NamespaceStatus(obj *NamespaceStatus) {
|
||||
if obj.Phase == "" {
|
||||
obj.Phase = NamespaceActive
|
||||
}
|
||||
},
|
||||
func(obj *Node) {
|
||||
}
|
||||
func SetDefaults_Node(obj *Node) {
|
||||
if obj.Spec.ExternalID == "" {
|
||||
obj.Spec.ExternalID = obj.Name
|
||||
}
|
||||
},
|
||||
func(obj *NodeStatus) {
|
||||
}
|
||||
func SetDefaults_NodeStatus(obj *NodeStatus) {
|
||||
if obj.Allocatable == nil && obj.Capacity != nil {
|
||||
obj.Allocatable = make(ResourceList, len(obj.Capacity))
|
||||
for key, value := range obj.Capacity {
|
||||
@ -208,13 +233,13 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
}
|
||||
obj.Allocatable = obj.Capacity
|
||||
}
|
||||
},
|
||||
func(obj *ObjectFieldSelector) {
|
||||
}
|
||||
func SetDefaults_ObjectFieldSelector(obj *ObjectFieldSelector) {
|
||||
if obj.APIVersion == "" {
|
||||
obj.APIVersion = "v1"
|
||||
}
|
||||
},
|
||||
func(obj *LimitRangeItem) {
|
||||
}
|
||||
func SetDefaults_LimitRangeItem(obj *LimitRangeItem) {
|
||||
// for container limits, we apply default values
|
||||
if obj.Type == LimitTypeContainer {
|
||||
|
||||
@ -244,13 +269,11 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
func(obj *ConfigMap) {
|
||||
}
|
||||
func SetDefaults_ConfigMap(obj *ConfigMap) {
|
||||
if obj.Data == nil {
|
||||
obj.Data = make(map[string]string)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// With host networking default all container ports to host ports.
|
||||
|
@ -23,7 +23,11 @@ import (
|
||||
|
||||
func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
scheme.AddDefaultingFuncs(
|
||||
func(obj *PetSet) {
|
||||
SetDefaults_PetSet,
|
||||
)
|
||||
}
|
||||
|
||||
func SetDefaults_PetSet(obj *PetSet) {
|
||||
labels := obj.Spec.Template.Labels
|
||||
if labels != nil {
|
||||
if obj.Spec.Selector == nil {
|
||||
@ -39,6 +43,4 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
obj.Spec.Replicas = new(int32)
|
||||
*obj.Spec.Replicas = 1
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
@ -22,11 +22,13 @@ import (
|
||||
|
||||
func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
scheme.AddDefaultingFuncs(
|
||||
func(obj *HorizontalPodAutoscaler) {
|
||||
SetDefaults_HorizontalPodAutoscaler,
|
||||
)
|
||||
}
|
||||
|
||||
func SetDefaults_HorizontalPodAutoscaler(obj *HorizontalPodAutoscaler) {
|
||||
if obj.Spec.MinReplicas == nil {
|
||||
minReplicas := int32(1)
|
||||
obj.Spec.MinReplicas = &minReplicas
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -22,7 +22,11 @@ import (
|
||||
|
||||
func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
scheme.AddDefaultingFuncs(
|
||||
func(obj *Job) {
|
||||
SetDefaults_Job,
|
||||
)
|
||||
}
|
||||
|
||||
func SetDefaults_Job(obj *Job) {
|
||||
// For a non-parallel job, you can leave both `.spec.completions` and
|
||||
// `.spec.parallelism` unset. When both are unset, both are defaulted to 1.
|
||||
if obj.Spec.Completions == nil && obj.Spec.Parallelism == nil {
|
||||
@ -35,6 +39,4 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
obj.Spec.Parallelism = new(int32)
|
||||
*obj.Spec.Parallelism = 1
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -28,7 +28,13 @@ import (
|
||||
|
||||
func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
scheme.AddDefaultingFuncs(
|
||||
func(obj *KubeProxyConfiguration) {
|
||||
SetDefaults_KubeProxyConfiguration,
|
||||
SetDefaults_KubeSchedulerConfiguration,
|
||||
SetDefaults_LeaderElectionConfiguration,
|
||||
)
|
||||
}
|
||||
|
||||
func SetDefaults_KubeProxyConfiguration(obj *KubeProxyConfiguration) {
|
||||
if obj.BindAddress == "" {
|
||||
obj.BindAddress = "0.0.0.0"
|
||||
}
|
||||
@ -62,8 +68,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
if obj.ConntrackTCPEstablishedTimeout == zero {
|
||||
obj.ConntrackTCPEstablishedTimeout = unversioned.Duration{Duration: 24 * time.Hour} // 1 day (1/5 default)
|
||||
}
|
||||
},
|
||||
func(obj *KubeSchedulerConfiguration) {
|
||||
}
|
||||
|
||||
func SetDefaults_KubeSchedulerConfiguration(obj *KubeSchedulerConfiguration) {
|
||||
if obj.Port == 0 {
|
||||
obj.Port = ports.SchedulerPort
|
||||
}
|
||||
@ -82,8 +89,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
if obj.SchedulerName == "" {
|
||||
obj.SchedulerName = api.DefaultSchedulerName
|
||||
}
|
||||
},
|
||||
func(obj *LeaderElectionConfiguration) {
|
||||
}
|
||||
|
||||
func SetDefaults_LeaderElectionConfiguration(obj *LeaderElectionConfiguration) {
|
||||
zero := unversioned.Duration{}
|
||||
if obj.LeaseDuration == zero {
|
||||
obj.LeaseDuration = unversioned.Duration{Duration: 15 * time.Second}
|
||||
@ -94,6 +102,4 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
if obj.RetryPeriod == zero {
|
||||
obj.RetryPeriod = unversioned.Duration{Duration: 2 * time.Second}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -23,9 +23,15 @@ import (
|
||||
|
||||
func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
scheme.AddDefaultingFuncs(
|
||||
func(obj *APIVersion) {
|
||||
},
|
||||
func(obj *DaemonSet) {
|
||||
SetDefaults_DaemonSet,
|
||||
SetDefaults_Deployment,
|
||||
SetDefaults_Job,
|
||||
SetDefaults_HorizontalPodAutoscaler,
|
||||
SetDefaults_ReplicaSet,
|
||||
)
|
||||
}
|
||||
|
||||
func SetDefaults_DaemonSet(obj *DaemonSet) {
|
||||
labels := obj.Spec.Template.Labels
|
||||
|
||||
// TODO: support templates defined elsewhere when we support them in the API
|
||||
@ -39,8 +45,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
obj.Labels = labels
|
||||
}
|
||||
}
|
||||
},
|
||||
func(obj *Deployment) {
|
||||
}
|
||||
|
||||
func SetDefaults_Deployment(obj *Deployment) {
|
||||
// Default labels and selector to labels from pod template spec.
|
||||
labels := obj.Spec.Template.Labels
|
||||
|
||||
@ -78,8 +85,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
strategy.RollingUpdate.MaxSurge = &maxSurge
|
||||
}
|
||||
}
|
||||
},
|
||||
func(obj *Job) {
|
||||
}
|
||||
|
||||
func SetDefaults_Job(obj *Job) {
|
||||
labels := obj.Spec.Template.Labels
|
||||
// TODO: support templates defined elsewhere when we support them in the API
|
||||
if labels != nil {
|
||||
@ -111,8 +119,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
obj.Spec.Parallelism = new(int32)
|
||||
*obj.Spec.Parallelism = 1
|
||||
}
|
||||
},
|
||||
func(obj *HorizontalPodAutoscaler) {
|
||||
}
|
||||
|
||||
func SetDefaults_HorizontalPodAutoscaler(obj *HorizontalPodAutoscaler) {
|
||||
if obj.Spec.MinReplicas == nil {
|
||||
minReplicas := int32(1)
|
||||
obj.Spec.MinReplicas = &minReplicas
|
||||
@ -120,8 +129,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
if obj.Spec.CPUUtilization == nil {
|
||||
obj.Spec.CPUUtilization = &CPUTargetUtilization{TargetPercentage: 80}
|
||||
}
|
||||
},
|
||||
func(obj *ReplicaSet) {
|
||||
}
|
||||
|
||||
func SetDefaults_ReplicaSet(obj *ReplicaSet) {
|
||||
labels := obj.Spec.Template.Labels
|
||||
|
||||
// TODO: support templates defined elsewhere when we support them in the API
|
||||
@ -139,6 +149,4 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
|
||||
obj.Spec.Replicas = new(int32)
|
||||
*obj.Spec.Replicas = 1
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user