2017-02-01 00:45:59 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2017-09-26 14:23:09 +00:00
|
|
|
"k8s.io/api/core/v1"
|
2017-02-01 00:45:59 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
2017-06-06 07:19:04 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/intstr"
|
2017-02-01 00:45:59 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/parsers"
|
2017-09-26 14:23:09 +00:00
|
|
|
utilpointer "k8s.io/kubernetes/pkg/util/pointer"
|
2017-02-01 00:45:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func addDefaultingFuncs(scheme *runtime.Scheme) error {
|
2017-08-04 11:13:19 +00:00
|
|
|
return RegisterDefaults(scheme)
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_ResourceList(obj *v1.ResourceList) {
|
2017-02-01 00:45:59 +00:00
|
|
|
for key, val := range *obj {
|
|
|
|
// TODO(#18538): We round up resource values to milli scale to maintain API compatibility.
|
|
|
|
// In the future, we should instead reject values that need rounding.
|
|
|
|
const milliScale = -3
|
|
|
|
val.RoundUp(milliScale)
|
|
|
|
|
2017-09-26 14:23:09 +00:00
|
|
|
(*obj)[v1.ResourceName(key)] = val
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_PodExecOptions(obj *v1.PodExecOptions) {
|
2017-02-01 00:45:59 +00:00
|
|
|
obj.Stdout = true
|
|
|
|
obj.Stderr = true
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_PodAttachOptions(obj *v1.PodAttachOptions) {
|
2017-02-01 00:45:59 +00:00
|
|
|
obj.Stdout = true
|
|
|
|
obj.Stderr = true
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_ReplicationController(obj *v1.ReplicationController) {
|
2017-02-01 00:45:59 +00:00
|
|
|
var labels map[string]string
|
|
|
|
if obj.Spec.Template != nil {
|
|
|
|
labels = obj.Spec.Template.Labels
|
|
|
|
}
|
|
|
|
// TODO: support templates defined elsewhere when we support them in the API
|
|
|
|
if labels != nil {
|
|
|
|
if len(obj.Spec.Selector) == 0 {
|
|
|
|
obj.Spec.Selector = labels
|
|
|
|
}
|
|
|
|
if len(obj.Labels) == 0 {
|
|
|
|
obj.Labels = labels
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if obj.Spec.Replicas == nil {
|
|
|
|
obj.Spec.Replicas = new(int32)
|
|
|
|
*obj.Spec.Replicas = 1
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_Volume(obj *v1.Volume) {
|
|
|
|
if utilpointer.AllPtrFieldsNil(&obj.VolumeSource) {
|
|
|
|
obj.VolumeSource = v1.VolumeSource{
|
|
|
|
EmptyDir: &v1.EmptyDirVolumeSource{},
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_ContainerPort(obj *v1.ContainerPort) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.Protocol == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Protocol = v1.ProtocolTCP
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_Container(obj *v1.Container) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.ImagePullPolicy == "" {
|
|
|
|
// Ignore error and assume it has been validated elsewhere
|
|
|
|
_, tag, _, _ := parsers.ParseImageName(obj.Image)
|
|
|
|
|
|
|
|
// Check image tag
|
|
|
|
if tag == "latest" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.ImagePullPolicy = v1.PullAlways
|
2017-02-01 00:45:59 +00:00
|
|
|
} else {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.ImagePullPolicy = v1.PullIfNotPresent
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if obj.TerminationMessagePath == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.TerminationMessagePath = v1.TerminationMessagePathDefault
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
2017-02-03 13:41:32 +00:00
|
|
|
if obj.TerminationMessagePolicy == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.TerminationMessagePolicy = v1.TerminationMessageReadFile
|
2017-02-03 13:41:32 +00:00
|
|
|
}
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_Service(obj *v1.Service) {
|
2017-08-04 11:13:19 +00:00
|
|
|
if obj.Spec.SessionAffinity == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Spec.SessionAffinity = v1.ServiceAffinityNone
|
|
|
|
}
|
|
|
|
if obj.Spec.SessionAffinity == v1.ServiceAffinityNone {
|
|
|
|
obj.Spec.SessionAffinityConfig = nil
|
|
|
|
}
|
|
|
|
if obj.Spec.SessionAffinity == v1.ServiceAffinityClientIP {
|
|
|
|
if obj.Spec.SessionAffinityConfig == nil || obj.Spec.SessionAffinityConfig.ClientIP == nil || obj.Spec.SessionAffinityConfig.ClientIP.TimeoutSeconds == nil {
|
|
|
|
timeoutSeconds := v1.DefaultClientIPServiceAffinitySeconds
|
|
|
|
obj.Spec.SessionAffinityConfig = &v1.SessionAffinityConfig{
|
|
|
|
ClientIP: &v1.ClientIPConfig{
|
|
|
|
TimeoutSeconds: &timeoutSeconds,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
2017-08-04 11:13:19 +00:00
|
|
|
if obj.Spec.Type == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Spec.Type = v1.ServiceTypeClusterIP
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
2017-08-04 11:13:19 +00:00
|
|
|
for i := range obj.Spec.Ports {
|
|
|
|
sp := &obj.Spec.Ports[i]
|
2017-02-01 00:45:59 +00:00
|
|
|
if sp.Protocol == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
sp.Protocol = v1.ProtocolTCP
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
if sp.TargetPort == intstr.FromInt(0) || sp.TargetPort == intstr.FromString("") {
|
|
|
|
sp.TargetPort = intstr.FromInt(int(sp.Port))
|
|
|
|
}
|
|
|
|
}
|
2017-08-04 11:13:19 +00:00
|
|
|
// Defaults ExternalTrafficPolicy field for NodePort / LoadBalancer service
|
|
|
|
// to Global for consistency.
|
2017-09-26 14:23:09 +00:00
|
|
|
if (obj.Spec.Type == v1.ServiceTypeNodePort ||
|
|
|
|
obj.Spec.Type == v1.ServiceTypeLoadBalancer) &&
|
2017-08-04 11:13:19 +00:00
|
|
|
obj.Spec.ExternalTrafficPolicy == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyTypeCluster
|
2017-08-04 11:13:19 +00:00
|
|
|
}
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_Pod(obj *v1.Pod) {
|
2017-02-01 00:45:59 +00:00
|
|
|
// If limits are specified, but requests are not, default requests to limits
|
2017-09-26 14:23:09 +00:00
|
|
|
// This is done here rather than a more specific defaulting pass on v1.ResourceRequirements
|
|
|
|
// because we only want this defaulting semantic to take place on a v1.Pod and not a v1.PodTemplate
|
2017-02-01 00:45:59 +00:00
|
|
|
for i := range obj.Spec.Containers {
|
|
|
|
// set requests to limits if requests are not specified, but limits are
|
|
|
|
if obj.Spec.Containers[i].Resources.Limits != nil {
|
|
|
|
if obj.Spec.Containers[i].Resources.Requests == nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Spec.Containers[i].Resources.Requests = make(v1.ResourceList)
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
for key, value := range obj.Spec.Containers[i].Resources.Limits {
|
|
|
|
if _, exists := obj.Spec.Containers[i].Resources.Requests[key]; !exists {
|
|
|
|
obj.Spec.Containers[i].Resources.Requests[key] = *(value.Copy())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-06 07:19:04 +00:00
|
|
|
for i := range obj.Spec.InitContainers {
|
|
|
|
if obj.Spec.InitContainers[i].Resources.Limits != nil {
|
|
|
|
if obj.Spec.InitContainers[i].Resources.Requests == nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Spec.InitContainers[i].Resources.Requests = make(v1.ResourceList)
|
2017-06-06 07:19:04 +00:00
|
|
|
}
|
|
|
|
for key, value := range obj.Spec.InitContainers[i].Resources.Limits {
|
|
|
|
if _, exists := obj.Spec.InitContainers[i].Resources.Requests[key]; !exists {
|
|
|
|
obj.Spec.InitContainers[i].Resources.Requests[key] = *(value.Copy())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_PodSpec(obj *v1.PodSpec) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.DNSPolicy == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.DNSPolicy = v1.DNSClusterFirst
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
if obj.RestartPolicy == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.RestartPolicy = v1.RestartPolicyAlways
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
if obj.HostNetwork {
|
|
|
|
defaultHostNetworkPorts(&obj.Containers)
|
2017-06-06 07:19:04 +00:00
|
|
|
defaultHostNetworkPorts(&obj.InitContainers)
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
if obj.SecurityContext == nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.SecurityContext = &v1.PodSecurityContext{}
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
if obj.TerminationGracePeriodSeconds == nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
period := int64(v1.DefaultTerminationGracePeriodSeconds)
|
2017-02-01 00:45:59 +00:00
|
|
|
obj.TerminationGracePeriodSeconds = &period
|
|
|
|
}
|
2017-02-03 13:41:32 +00:00
|
|
|
if obj.SchedulerName == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.SchedulerName = v1.DefaultSchedulerName
|
2017-02-03 13:41:32 +00:00
|
|
|
}
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_Probe(obj *v1.Probe) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.TimeoutSeconds == 0 {
|
|
|
|
obj.TimeoutSeconds = 1
|
|
|
|
}
|
|
|
|
if obj.PeriodSeconds == 0 {
|
|
|
|
obj.PeriodSeconds = 10
|
|
|
|
}
|
|
|
|
if obj.SuccessThreshold == 0 {
|
|
|
|
obj.SuccessThreshold = 1
|
|
|
|
}
|
|
|
|
if obj.FailureThreshold == 0 {
|
|
|
|
obj.FailureThreshold = 3
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_SecretVolumeSource(obj *v1.SecretVolumeSource) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.DefaultMode == nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
perm := int32(v1.SecretVolumeSourceDefaultMode)
|
2017-02-01 00:45:59 +00:00
|
|
|
obj.DefaultMode = &perm
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_ConfigMapVolumeSource(obj *v1.ConfigMapVolumeSource) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.DefaultMode == nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
perm := int32(v1.ConfigMapVolumeSourceDefaultMode)
|
2017-02-01 00:45:59 +00:00
|
|
|
obj.DefaultMode = &perm
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_DownwardAPIVolumeSource(obj *v1.DownwardAPIVolumeSource) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.DefaultMode == nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
perm := int32(v1.DownwardAPIVolumeSourceDefaultMode)
|
2017-02-01 00:45:59 +00:00
|
|
|
obj.DefaultMode = &perm
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_Secret(obj *v1.Secret) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.Type == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Type = v1.SecretTypeOpaque
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_ProjectedVolumeSource(obj *v1.ProjectedVolumeSource) {
|
2017-06-06 07:19:04 +00:00
|
|
|
if obj.DefaultMode == nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
perm := int32(v1.ProjectedVolumeSourceDefaultMode)
|
2017-06-06 07:19:04 +00:00
|
|
|
obj.DefaultMode = &perm
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_PersistentVolume(obj *v1.PersistentVolume) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.Status.Phase == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Status.Phase = v1.VolumePending
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
if obj.Spec.PersistentVolumeReclaimPolicy == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Spec.PersistentVolumeReclaimPolicy = v1.PersistentVolumeReclaimRetain
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_PersistentVolumeClaim(obj *v1.PersistentVolumeClaim) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.Status.Phase == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Status.Phase = v1.ClaimPending
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_ISCSIVolumeSource(obj *v1.ISCSIVolumeSource) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.ISCSIInterface == "" {
|
|
|
|
obj.ISCSIInterface = "default"
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_AzureDiskVolumeSource(obj *v1.AzureDiskVolumeSource) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.CachingMode == nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.CachingMode = new(v1.AzureDataDiskCachingMode)
|
|
|
|
*obj.CachingMode = v1.AzureDataDiskCachingReadWrite
|
2017-08-04 11:13:19 +00:00
|
|
|
}
|
|
|
|
if obj.Kind == nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Kind = new(v1.AzureDataDiskKind)
|
|
|
|
*obj.Kind = v1.AzureSharedBlobDisk
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
if obj.FSType == nil {
|
|
|
|
obj.FSType = new(string)
|
|
|
|
*obj.FSType = "ext4"
|
|
|
|
}
|
|
|
|
if obj.ReadOnly == nil {
|
|
|
|
obj.ReadOnly = new(bool)
|
|
|
|
*obj.ReadOnly = false
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_Endpoints(obj *v1.Endpoints) {
|
2017-02-01 00:45:59 +00:00
|
|
|
for i := range obj.Subsets {
|
|
|
|
ss := &obj.Subsets[i]
|
|
|
|
for i := range ss.Ports {
|
|
|
|
ep := &ss.Ports[i]
|
|
|
|
if ep.Protocol == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
ep.Protocol = v1.ProtocolTCP
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_HTTPGetAction(obj *v1.HTTPGetAction) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.Path == "" {
|
|
|
|
obj.Path = "/"
|
|
|
|
}
|
|
|
|
if obj.Scheme == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Scheme = v1.URISchemeHTTP
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_NamespaceStatus(obj *v1.NamespaceStatus) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.Phase == "" {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Phase = v1.NamespaceActive
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_Node(obj *v1.Node) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.Spec.ExternalID == "" {
|
|
|
|
obj.Spec.ExternalID = obj.Name
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_NodeStatus(obj *v1.NodeStatus) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.Allocatable == nil && obj.Capacity != nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Allocatable = make(v1.ResourceList, len(obj.Capacity))
|
2017-02-01 00:45:59 +00:00
|
|
|
for key, value := range obj.Capacity {
|
|
|
|
obj.Allocatable[key] = *(value.Copy())
|
|
|
|
}
|
|
|
|
obj.Allocatable = obj.Capacity
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_ObjectFieldSelector(obj *v1.ObjectFieldSelector) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.APIVersion == "" {
|
|
|
|
obj.APIVersion = "v1"
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_LimitRangeItem(obj *v1.LimitRangeItem) {
|
2017-02-01 00:45:59 +00:00
|
|
|
// for container limits, we apply default values
|
2017-09-26 14:23:09 +00:00
|
|
|
if obj.Type == v1.LimitTypeContainer {
|
2017-02-01 00:45:59 +00:00
|
|
|
|
|
|
|
if obj.Default == nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.Default = make(v1.ResourceList)
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
if obj.DefaultRequest == nil {
|
2017-09-26 14:23:09 +00:00
|
|
|
obj.DefaultRequest = make(v1.ResourceList)
|
2017-02-01 00:45:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If a default limit is unspecified, but the max is specified, default the limit to the max
|
|
|
|
for key, value := range obj.Max {
|
|
|
|
if _, exists := obj.Default[key]; !exists {
|
|
|
|
obj.Default[key] = *(value.Copy())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If a default limit is specified, but the default request is not, default request to limit
|
|
|
|
for key, value := range obj.Default {
|
|
|
|
if _, exists := obj.DefaultRequest[key]; !exists {
|
|
|
|
obj.DefaultRequest[key] = *(value.Copy())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If a default request is not specified, but the min is provided, default request to the min
|
|
|
|
for key, value := range obj.Min {
|
|
|
|
if _, exists := obj.DefaultRequest[key]; !exists {
|
|
|
|
obj.DefaultRequest[key] = *(value.Copy())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_ConfigMap(obj *v1.ConfigMap) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.Data == nil {
|
|
|
|
obj.Data = make(map[string]string)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// With host networking default all container ports to host ports.
|
2017-09-26 14:23:09 +00:00
|
|
|
func defaultHostNetworkPorts(containers *[]v1.Container) {
|
2017-02-01 00:45:59 +00:00
|
|
|
for i := range *containers {
|
|
|
|
for j := range (*containers)[i].Ports {
|
|
|
|
if (*containers)[i].Ports[j].HostPort == 0 {
|
|
|
|
(*containers)[i].Ports[j].HostPort = (*containers)[i].Ports[j].ContainerPort
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_RBDVolumeSource(obj *v1.RBDVolumeSource) {
|
2017-02-01 00:45:59 +00:00
|
|
|
if obj.RBDPool == "" {
|
|
|
|
obj.RBDPool = "rbd"
|
|
|
|
}
|
|
|
|
if obj.RadosUser == "" {
|
|
|
|
obj.RadosUser = "admin"
|
|
|
|
}
|
|
|
|
if obj.Keyring == "" {
|
|
|
|
obj.Keyring = "/etc/ceph/keyring"
|
|
|
|
}
|
|
|
|
}
|
2017-06-06 07:19:04 +00:00
|
|
|
|
2017-11-13 10:33:25 +00:00
|
|
|
func SetDefaults_RBDPersistentVolumeSource(obj *v1.RBDPersistentVolumeSource) {
|
|
|
|
if obj.RBDPool == "" {
|
|
|
|
obj.RBDPool = "rbd"
|
|
|
|
}
|
|
|
|
if obj.RadosUser == "" {
|
|
|
|
obj.RadosUser = "admin"
|
|
|
|
}
|
|
|
|
if obj.Keyring == "" {
|
|
|
|
obj.Keyring = "/etc/ceph/keyring"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 14:23:09 +00:00
|
|
|
func SetDefaults_ScaleIOVolumeSource(obj *v1.ScaleIOVolumeSource) {
|
2017-11-13 10:33:25 +00:00
|
|
|
if obj.StorageMode == "" {
|
|
|
|
obj.StorageMode = "ThinProvisioned"
|
2017-06-06 07:19:04 +00:00
|
|
|
}
|
2017-11-13 10:33:25 +00:00
|
|
|
if obj.FSType == "" {
|
|
|
|
obj.FSType = "xfs"
|
2017-06-06 07:19:04 +00:00
|
|
|
}
|
2017-11-13 10:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func SetDefaults_ScaleIOPersistentVolumeSource(obj *v1.ScaleIOPersistentVolumeSource) {
|
2017-06-06 07:19:04 +00:00
|
|
|
if obj.StorageMode == "" {
|
|
|
|
obj.StorageMode = "ThinProvisioned"
|
|
|
|
}
|
|
|
|
if obj.FSType == "" {
|
|
|
|
obj.FSType = "xfs"
|
|
|
|
}
|
|
|
|
}
|
2017-09-26 14:23:09 +00:00
|
|
|
|
|
|
|
func SetDefaults_HostPathVolumeSource(obj *v1.HostPathVolumeSource) {
|
|
|
|
typeVol := v1.HostPathUnset
|
|
|
|
if obj.Type == nil {
|
|
|
|
obj.Type = &typeVol
|
|
|
|
}
|
|
|
|
}
|