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:
k8s-merge-robot 2016-04-29 06:36:09 -07:00
commit 46a6cae14e
6 changed files with 489 additions and 446 deletions

View File

@ -25,15 +25,40 @@ import (
func addDefaultingFuncs(scheme *runtime.Scheme) { func addDefaultingFuncs(scheme *runtime.Scheme) {
scheme.AddDefaultingFuncs( 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.Stdout = true
obj.Stderr = true obj.Stderr = true
}, }
func(obj *PodAttachOptions) { func SetDefaults_PodAttachOptions(obj *PodAttachOptions) {
obj.Stdout = true obj.Stdout = true
obj.Stderr = true obj.Stderr = true
}, }
func(obj *ReplicationController) { func SetDefaults_ReplicationController(obj *ReplicationController) {
var labels map[string]string var labels map[string]string
if obj.Spec.Template != nil { if obj.Spec.Template != nil {
labels = obj.Spec.Template.Labels labels = obj.Spec.Template.Labels
@ -51,20 +76,20 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
obj.Spec.Replicas = new(int32) obj.Spec.Replicas = new(int32)
*obj.Spec.Replicas = 1 *obj.Spec.Replicas = 1
} }
}, }
func(obj *Volume) { func SetDefaults_Volume(obj *Volume) {
if util.AllPtrFieldsNil(&obj.VolumeSource) { if util.AllPtrFieldsNil(&obj.VolumeSource) {
obj.VolumeSource = VolumeSource{ obj.VolumeSource = VolumeSource{
EmptyDir: &EmptyDirVolumeSource{}, EmptyDir: &EmptyDirVolumeSource{},
} }
} }
}, }
func(obj *ContainerPort) { func SetDefaults_ContainerPort(obj *ContainerPort) {
if obj.Protocol == "" { if obj.Protocol == "" {
obj.Protocol = ProtocolTCP obj.Protocol = ProtocolTCP
} }
}, }
func(obj *Container) { func SetDefaults_Container(obj *Container) {
if obj.ImagePullPolicy == "" { if obj.ImagePullPolicy == "" {
// Ignore error and assume it has been validated elsewhere // Ignore error and assume it has been validated elsewhere
_, tag, _ := parsers.ParseImageName(obj.Image) _, tag, _ := parsers.ParseImageName(obj.Image)
@ -80,8 +105,8 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
if obj.TerminationMessagePath == "" { if obj.TerminationMessagePath == "" {
obj.TerminationMessagePath = TerminationMessagePathDefault obj.TerminationMessagePath = TerminationMessagePathDefault
} }
}, }
func(obj *ServiceSpec) { func SetDefaults_ServiceSpec(obj *ServiceSpec) {
if obj.SessionAffinity == "" { if obj.SessionAffinity == "" {
obj.SessionAffinity = ServiceAffinityNone obj.SessionAffinity = ServiceAffinityNone
} }
@ -97,8 +122,8 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
sp.TargetPort = intstr.FromInt(int(sp.Port)) 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 // 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 // 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 // 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 == "" { if obj.DNSPolicy == "" {
obj.DNSPolicy = DNSClusterFirst obj.DNSPolicy = DNSClusterFirst
} }
@ -133,8 +158,8 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
period := int64(DefaultTerminationGracePeriodSeconds) period := int64(DefaultTerminationGracePeriodSeconds)
obj.TerminationGracePeriodSeconds = &period obj.TerminationGracePeriodSeconds = &period
} }
}, }
func(obj *Probe) { func SetDefaults_Probe(obj *Probe) {
if obj.TimeoutSeconds == 0 { if obj.TimeoutSeconds == 0 {
obj.TimeoutSeconds = 1 obj.TimeoutSeconds = 1
} }
@ -147,31 +172,31 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
if obj.FailureThreshold == 0 { if obj.FailureThreshold == 0 {
obj.FailureThreshold = 3 obj.FailureThreshold = 3
} }
}, }
func(obj *Secret) { func SetDefaults_Secret(obj *Secret) {
if obj.Type == "" { if obj.Type == "" {
obj.Type = SecretTypeOpaque obj.Type = SecretTypeOpaque
} }
}, }
func(obj *PersistentVolume) { func SetDefaults_PersistentVolume(obj *PersistentVolume) {
if obj.Status.Phase == "" { if obj.Status.Phase == "" {
obj.Status.Phase = VolumePending obj.Status.Phase = VolumePending
} }
if obj.Spec.PersistentVolumeReclaimPolicy == "" { if obj.Spec.PersistentVolumeReclaimPolicy == "" {
obj.Spec.PersistentVolumeReclaimPolicy = PersistentVolumeReclaimRetain obj.Spec.PersistentVolumeReclaimPolicy = PersistentVolumeReclaimRetain
} }
}, }
func(obj *PersistentVolumeClaim) { func SetDefaults_PersistentVolumeClaim(obj *PersistentVolumeClaim) {
if obj.Status.Phase == "" { if obj.Status.Phase == "" {
obj.Status.Phase = ClaimPending obj.Status.Phase = ClaimPending
} }
}, }
func(obj *ISCSIVolumeSource) { func SetDefaults_ISCSIVolumeSource(obj *ISCSIVolumeSource) {
if obj.ISCSIInterface == "" { if obj.ISCSIInterface == "" {
obj.ISCSIInterface = "default" obj.ISCSIInterface = "default"
} }
}, }
func(obj *Endpoints) { func SetDefaults_Endpoints(obj *Endpoints) {
for i := range obj.Subsets { for i := range obj.Subsets {
ss := &obj.Subsets[i] ss := &obj.Subsets[i]
for i := range ss.Ports { 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 == "" { if obj.Path == "" {
obj.Path = "/" obj.Path = "/"
} }
if obj.Scheme == "" { if obj.Scheme == "" {
obj.Scheme = URISchemeHTTP obj.Scheme = URISchemeHTTP
} }
}, }
func(obj *NamespaceStatus) { func SetDefaults_NamespaceStatus(obj *NamespaceStatus) {
if obj.Phase == "" { if obj.Phase == "" {
obj.Phase = NamespaceActive obj.Phase = NamespaceActive
} }
}, }
func(obj *Node) { func SetDefaults_Node(obj *Node) {
if obj.Spec.ExternalID == "" { if obj.Spec.ExternalID == "" {
obj.Spec.ExternalID = obj.Name obj.Spec.ExternalID = obj.Name
} }
}, }
func(obj *NodeStatus) { func SetDefaults_NodeStatus(obj *NodeStatus) {
if obj.Allocatable == nil && obj.Capacity != nil { if obj.Allocatable == nil && obj.Capacity != nil {
obj.Allocatable = make(ResourceList, len(obj.Capacity)) obj.Allocatable = make(ResourceList, len(obj.Capacity))
for key, value := range obj.Capacity { for key, value := range obj.Capacity {
@ -208,13 +233,13 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
} }
obj.Allocatable = obj.Capacity obj.Allocatable = obj.Capacity
} }
}, }
func(obj *ObjectFieldSelector) { func SetDefaults_ObjectFieldSelector(obj *ObjectFieldSelector) {
if obj.APIVersion == "" { if obj.APIVersion == "" {
obj.APIVersion = "v1" obj.APIVersion = "v1"
} }
}, }
func(obj *LimitRangeItem) { func SetDefaults_LimitRangeItem(obj *LimitRangeItem) {
// for container limits, we apply default values // for container limits, we apply default values
if obj.Type == LimitTypeContainer { 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 { if obj.Data == nil {
obj.Data = make(map[string]string) obj.Data = make(map[string]string)
} }
},
)
} }
// With host networking default all container ports to host ports. // With host networking default all container ports to host ports.

View File

@ -23,7 +23,11 @@ import (
func addDefaultingFuncs(scheme *runtime.Scheme) { func addDefaultingFuncs(scheme *runtime.Scheme) {
scheme.AddDefaultingFuncs( scheme.AddDefaultingFuncs(
func(obj *PetSet) { SetDefaults_PetSet,
)
}
func SetDefaults_PetSet(obj *PetSet) {
labels := obj.Spec.Template.Labels labels := obj.Spec.Template.Labels
if labels != nil { if labels != nil {
if obj.Spec.Selector == nil { if obj.Spec.Selector == nil {
@ -39,6 +43,4 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
obj.Spec.Replicas = new(int32) obj.Spec.Replicas = new(int32)
*obj.Spec.Replicas = 1 *obj.Spec.Replicas = 1
} }
},
)
} }

View File

@ -22,11 +22,13 @@ import (
func addDefaultingFuncs(scheme *runtime.Scheme) { func addDefaultingFuncs(scheme *runtime.Scheme) {
scheme.AddDefaultingFuncs( scheme.AddDefaultingFuncs(
func(obj *HorizontalPodAutoscaler) { SetDefaults_HorizontalPodAutoscaler,
)
}
func SetDefaults_HorizontalPodAutoscaler(obj *HorizontalPodAutoscaler) {
if obj.Spec.MinReplicas == nil { if obj.Spec.MinReplicas == nil {
minReplicas := int32(1) minReplicas := int32(1)
obj.Spec.MinReplicas = &minReplicas obj.Spec.MinReplicas = &minReplicas
} }
},
)
} }

View File

@ -22,7 +22,11 @@ import (
func addDefaultingFuncs(scheme *runtime.Scheme) { func addDefaultingFuncs(scheme *runtime.Scheme) {
scheme.AddDefaultingFuncs( scheme.AddDefaultingFuncs(
func(obj *Job) { SetDefaults_Job,
)
}
func SetDefaults_Job(obj *Job) {
// For a non-parallel job, you can leave both `.spec.completions` and // For a non-parallel job, you can leave both `.spec.completions` and
// `.spec.parallelism` unset. When both are unset, both are defaulted to 1. // `.spec.parallelism` unset. When both are unset, both are defaulted to 1.
if obj.Spec.Completions == nil && obj.Spec.Parallelism == nil { 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 = new(int32)
*obj.Spec.Parallelism = 1 *obj.Spec.Parallelism = 1
} }
},
)
} }

View File

@ -28,7 +28,13 @@ import (
func addDefaultingFuncs(scheme *runtime.Scheme) { func addDefaultingFuncs(scheme *runtime.Scheme) {
scheme.AddDefaultingFuncs( scheme.AddDefaultingFuncs(
func(obj *KubeProxyConfiguration) { SetDefaults_KubeProxyConfiguration,
SetDefaults_KubeSchedulerConfiguration,
SetDefaults_LeaderElectionConfiguration,
)
}
func SetDefaults_KubeProxyConfiguration(obj *KubeProxyConfiguration) {
if obj.BindAddress == "" { if obj.BindAddress == "" {
obj.BindAddress = "0.0.0.0" obj.BindAddress = "0.0.0.0"
} }
@ -62,8 +68,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
if obj.ConntrackTCPEstablishedTimeout == zero { if obj.ConntrackTCPEstablishedTimeout == zero {
obj.ConntrackTCPEstablishedTimeout = unversioned.Duration{Duration: 24 * time.Hour} // 1 day (1/5 default) 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 { if obj.Port == 0 {
obj.Port = ports.SchedulerPort obj.Port = ports.SchedulerPort
} }
@ -82,8 +89,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
if obj.SchedulerName == "" { if obj.SchedulerName == "" {
obj.SchedulerName = api.DefaultSchedulerName obj.SchedulerName = api.DefaultSchedulerName
} }
}, }
func(obj *LeaderElectionConfiguration) {
func SetDefaults_LeaderElectionConfiguration(obj *LeaderElectionConfiguration) {
zero := unversioned.Duration{} zero := unversioned.Duration{}
if obj.LeaseDuration == zero { if obj.LeaseDuration == zero {
obj.LeaseDuration = unversioned.Duration{Duration: 15 * time.Second} obj.LeaseDuration = unversioned.Duration{Duration: 15 * time.Second}
@ -94,6 +102,4 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
if obj.RetryPeriod == zero { if obj.RetryPeriod == zero {
obj.RetryPeriod = unversioned.Duration{Duration: 2 * time.Second} obj.RetryPeriod = unversioned.Duration{Duration: 2 * time.Second}
} }
},
)
} }

View File

@ -23,9 +23,15 @@ import (
func addDefaultingFuncs(scheme *runtime.Scheme) { func addDefaultingFuncs(scheme *runtime.Scheme) {
scheme.AddDefaultingFuncs( scheme.AddDefaultingFuncs(
func(obj *APIVersion) { SetDefaults_DaemonSet,
}, SetDefaults_Deployment,
func(obj *DaemonSet) { SetDefaults_Job,
SetDefaults_HorizontalPodAutoscaler,
SetDefaults_ReplicaSet,
)
}
func SetDefaults_DaemonSet(obj *DaemonSet) {
labels := obj.Spec.Template.Labels labels := obj.Spec.Template.Labels
// TODO: support templates defined elsewhere when we support them in the API // TODO: support templates defined elsewhere when we support them in the API
@ -39,8 +45,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
obj.Labels = labels obj.Labels = labels
} }
} }
}, }
func(obj *Deployment) {
func SetDefaults_Deployment(obj *Deployment) {
// Default labels and selector to labels from pod template spec. // Default labels and selector to labels from pod template spec.
labels := obj.Spec.Template.Labels labels := obj.Spec.Template.Labels
@ -78,8 +85,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
strategy.RollingUpdate.MaxSurge = &maxSurge strategy.RollingUpdate.MaxSurge = &maxSurge
} }
} }
}, }
func(obj *Job) {
func SetDefaults_Job(obj *Job) {
labels := obj.Spec.Template.Labels labels := obj.Spec.Template.Labels
// TODO: support templates defined elsewhere when we support them in the API // TODO: support templates defined elsewhere when we support them in the API
if labels != nil { if labels != nil {
@ -111,8 +119,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
obj.Spec.Parallelism = new(int32) obj.Spec.Parallelism = new(int32)
*obj.Spec.Parallelism = 1 *obj.Spec.Parallelism = 1
} }
}, }
func(obj *HorizontalPodAutoscaler) {
func SetDefaults_HorizontalPodAutoscaler(obj *HorizontalPodAutoscaler) {
if obj.Spec.MinReplicas == nil { if obj.Spec.MinReplicas == nil {
minReplicas := int32(1) minReplicas := int32(1)
obj.Spec.MinReplicas = &minReplicas obj.Spec.MinReplicas = &minReplicas
@ -120,8 +129,9 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
if obj.Spec.CPUUtilization == nil { if obj.Spec.CPUUtilization == nil {
obj.Spec.CPUUtilization = &CPUTargetUtilization{TargetPercentage: 80} obj.Spec.CPUUtilization = &CPUTargetUtilization{TargetPercentage: 80}
} }
}, }
func(obj *ReplicaSet) {
func SetDefaults_ReplicaSet(obj *ReplicaSet) {
labels := obj.Spec.Template.Labels labels := obj.Spec.Template.Labels
// TODO: support templates defined elsewhere when we support them in the API // 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 = new(int32)
*obj.Spec.Replicas = 1 *obj.Spec.Replicas = 1
} }
},
)
} }