2015-07-29 23:15:24 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2015-10-09 22:06:28 +00:00
|
|
|
package v1beta1
|
2015-07-29 23:15:24 +00:00
|
|
|
|
2015-09-01 09:48:53 +00:00
|
|
|
import (
|
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-11-10 06:28:45 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/intstr"
|
2015-09-01 09:48:53 +00:00
|
|
|
)
|
2015-08-15 05:10:15 +00:00
|
|
|
|
2015-08-06 16:53:34 +00:00
|
|
|
func addDefaultingFuncs() {
|
2015-08-15 05:10:15 +00:00
|
|
|
api.Scheme.AddDefaultingFuncs(
|
|
|
|
func(obj *APIVersion) {
|
|
|
|
if len(obj.APIGroup) == 0 {
|
2015-10-09 22:14:03 +00:00
|
|
|
obj.APIGroup = "extensions"
|
2015-08-15 05:10:15 +00:00
|
|
|
}
|
2015-08-27 17:17:41 +00:00
|
|
|
},
|
2015-09-08 23:58:25 +00:00
|
|
|
func(obj *DaemonSet) {
|
2015-08-27 17:17:41 +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 {
|
2015-10-26 06:11:09 +00:00
|
|
|
if obj.Spec.Selector == nil {
|
|
|
|
obj.Spec.Selector = &PodSelector{
|
|
|
|
MatchLabels: labels,
|
|
|
|
}
|
2015-08-27 17:17:41 +00:00
|
|
|
}
|
|
|
|
if len(obj.Labels) == 0 {
|
|
|
|
obj.Labels = labels
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2015-09-01 09:48:53 +00:00
|
|
|
func(obj *Deployment) {
|
2015-10-08 21:03:32 +00:00
|
|
|
// Default labels and selector to labels from pod template spec.
|
2015-10-26 23:20:43 +00:00
|
|
|
labels := obj.Spec.Template.Labels
|
|
|
|
|
2015-10-08 21:03:32 +00:00
|
|
|
if labels != nil {
|
|
|
|
if len(obj.Spec.Selector) == 0 {
|
|
|
|
obj.Spec.Selector = labels
|
|
|
|
}
|
|
|
|
if len(obj.Labels) == 0 {
|
|
|
|
obj.Labels = labels
|
|
|
|
}
|
|
|
|
}
|
2015-09-01 09:48:53 +00:00
|
|
|
// Set DeploymentSpec.Replicas to 1 if it is not set.
|
|
|
|
if obj.Spec.Replicas == nil {
|
2015-11-18 18:15:16 +00:00
|
|
|
obj.Spec.Replicas = new(int32)
|
2015-09-01 09:48:53 +00:00
|
|
|
*obj.Spec.Replicas = 1
|
|
|
|
}
|
|
|
|
strategy := &obj.Spec.Strategy
|
2015-09-15 21:46:41 +00:00
|
|
|
// Set default DeploymentStrategyType as RollingUpdate.
|
2015-09-01 09:48:53 +00:00
|
|
|
if strategy.Type == "" {
|
2015-09-15 21:46:41 +00:00
|
|
|
strategy.Type = RollingUpdateDeploymentStrategyType
|
2015-09-01 09:48:53 +00:00
|
|
|
}
|
2015-09-15 21:46:41 +00:00
|
|
|
if strategy.Type == RollingUpdateDeploymentStrategyType {
|
2015-09-01 09:48:53 +00:00
|
|
|
if strategy.RollingUpdate == nil {
|
|
|
|
rollingUpdate := RollingUpdateDeployment{}
|
|
|
|
strategy.RollingUpdate = &rollingUpdate
|
|
|
|
}
|
|
|
|
if strategy.RollingUpdate.MaxUnavailable == nil {
|
|
|
|
// Set default MaxUnavailable as 1 by default.
|
2015-11-10 06:28:45 +00:00
|
|
|
maxUnavailable := intstr.FromInt(1)
|
2015-09-01 09:48:53 +00:00
|
|
|
strategy.RollingUpdate.MaxUnavailable = &maxUnavailable
|
|
|
|
}
|
|
|
|
if strategy.RollingUpdate.MaxSurge == nil {
|
|
|
|
// Set default MaxSurge as 1 by default.
|
2015-11-10 06:28:45 +00:00
|
|
|
maxSurge := intstr.FromInt(1)
|
2015-09-01 09:48:53 +00:00
|
|
|
strategy.RollingUpdate.MaxSurge = &maxSurge
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if obj.Spec.UniqueLabelKey == nil {
|
|
|
|
obj.Spec.UniqueLabelKey = new(string)
|
|
|
|
*obj.Spec.UniqueLabelKey = "deployment.kubernetes.io/podTemplateHash"
|
|
|
|
}
|
|
|
|
},
|
2015-08-27 12:19:35 +00:00
|
|
|
func(obj *Job) {
|
2015-09-25 19:07:06 +00:00
|
|
|
labels := obj.Spec.Template.Labels
|
2015-09-21 10:53:25 +00:00
|
|
|
// TODO: support templates defined elsewhere when we support them in the API
|
|
|
|
if labels != nil {
|
2015-10-14 18:03:59 +00:00
|
|
|
if obj.Spec.Selector == nil {
|
|
|
|
obj.Spec.Selector = &PodSelector{
|
|
|
|
MatchLabels: labels,
|
|
|
|
}
|
2015-09-21 10:53:25 +00:00
|
|
|
}
|
|
|
|
if len(obj.Labels) == 0 {
|
|
|
|
obj.Labels = labels
|
|
|
|
}
|
|
|
|
}
|
2015-08-27 12:19:35 +00:00
|
|
|
if obj.Spec.Completions == nil {
|
2015-11-18 18:15:16 +00:00
|
|
|
completions := int32(1)
|
2015-08-27 12:19:35 +00:00
|
|
|
obj.Spec.Completions = &completions
|
|
|
|
}
|
|
|
|
if obj.Spec.Parallelism == nil {
|
2015-09-23 11:25:58 +00:00
|
|
|
obj.Spec.Parallelism = obj.Spec.Completions
|
2015-08-27 12:19:35 +00:00
|
|
|
}
|
|
|
|
},
|
2015-10-13 15:24:23 +00:00
|
|
|
func(obj *HorizontalPodAutoscaler) {
|
|
|
|
if obj.Spec.MinReplicas == nil {
|
2015-11-18 18:15:16 +00:00
|
|
|
minReplicas := int32(1)
|
2015-10-13 15:24:23 +00:00
|
|
|
obj.Spec.MinReplicas = &minReplicas
|
|
|
|
}
|
|
|
|
if obj.Spec.CPUUtilization == nil {
|
|
|
|
obj.Spec.CPUUtilization = &CPUTargetUtilization{TargetPercentage: 80}
|
|
|
|
}
|
|
|
|
},
|
2015-08-27 17:17:41 +00:00
|
|
|
)
|
2015-08-06 16:53:34 +00:00
|
|
|
}
|