Merge pull request #16330 from mikedanese/deploy-ptr

Auto commit by PR queue bot
pull/6/head
k8s-merge-robot 2015-11-02 20:41:34 -08:00
commit 990c0184be
18 changed files with 7411 additions and 7470 deletions

View File

@ -1049,14 +1049,9 @@ func deepCopy_extensions_DeploymentSpec(in DeploymentSpec, out *DeploymentSpec,
} else { } else {
out.Selector = nil out.Selector = nil
} }
if in.Template != nil { if err := deepCopy_api_PodTemplateSpec(in.Template, &out.Template, c); err != nil {
out.Template = new(api.PodTemplateSpec)
if err := deepCopy_api_PodTemplateSpec(*in.Template, out.Template, c); err != nil {
return err return err
} }
} else {
out.Template = nil
}
if err := deepCopy_extensions_DeploymentStrategy(in.Strategy, &out.Strategy, c); err != nil { if err := deepCopy_extensions_DeploymentStrategy(in.Strategy, &out.Strategy, c); err != nil {
return err return err
} }

File diff suppressed because it is too large Load Diff

View File

@ -208,7 +208,7 @@ type DeploymentSpec struct {
Selector map[string]string `json:"selector,omitempty"` Selector map[string]string `json:"selector,omitempty"`
// Template describes the pods that will be created. // Template describes the pods that will be created.
Template *api.PodTemplateSpec `json:"template,omitempty"` Template api.PodTemplateSpec `json:"template"`
// The deployment strategy to use to replace existing pods with new ones. // The deployment strategy to use to replace existing pods with new ones.
Strategy DeploymentStrategy `json:"strategy,omitempty"` Strategy DeploymentStrategy `json:"strategy,omitempty"`

View File

@ -213,14 +213,9 @@ func convert_extensions_DeploymentSpec_To_v1beta1_DeploymentSpec(in *extensions.
} else { } else {
out.Selector = nil out.Selector = nil
} }
if in.Template != nil { if err := convert_api_PodTemplateSpec_To_v1_PodTemplateSpec(&in.Template, &out.Template, s); err != nil {
out.Template = new(v1.PodTemplateSpec)
if err := convert_api_PodTemplateSpec_To_v1_PodTemplateSpec(in.Template, out.Template, s); err != nil {
return err return err
} }
} else {
out.Template = nil
}
if err := convert_extensions_DeploymentStrategy_To_v1beta1_DeploymentStrategy(&in.Strategy, &out.Strategy, s); err != nil { if err := convert_extensions_DeploymentStrategy_To_v1beta1_DeploymentStrategy(&in.Strategy, &out.Strategy, s); err != nil {
return err return err
} }
@ -244,14 +239,9 @@ func convert_v1beta1_DeploymentSpec_To_extensions_DeploymentSpec(in *DeploymentS
} else { } else {
out.Selector = nil out.Selector = nil
} }
if in.Template != nil { if err := convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(&in.Template, &out.Template, s); err != nil {
out.Template = new(api.PodTemplateSpec)
if err := convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(in.Template, out.Template, s); err != nil {
return err return err
} }
} else {
out.Template = nil
}
if err := convert_v1beta1_DeploymentStrategy_To_extensions_DeploymentStrategy(&in.Strategy, &out.Strategy, s); err != nil { if err := convert_v1beta1_DeploymentStrategy_To_extensions_DeploymentStrategy(&in.Strategy, &out.Strategy, s); err != nil {
return err return err
} }

View File

@ -2395,14 +2395,9 @@ func autoconvert_extensions_DeploymentSpec_To_v1beta1_DeploymentSpec(in *extensi
} else { } else {
out.Selector = nil out.Selector = nil
} }
if in.Template != nil { if err := convert_api_PodTemplateSpec_To_v1_PodTemplateSpec(&in.Template, &out.Template, s); err != nil {
out.Template = new(v1.PodTemplateSpec)
if err := convert_api_PodTemplateSpec_To_v1_PodTemplateSpec(in.Template, out.Template, s); err != nil {
return err return err
} }
} else {
out.Template = nil
}
if err := convert_extensions_DeploymentStrategy_To_v1beta1_DeploymentStrategy(&in.Strategy, &out.Strategy, s); err != nil { if err := convert_extensions_DeploymentStrategy_To_v1beta1_DeploymentStrategy(&in.Strategy, &out.Strategy, s); err != nil {
return err return err
} }
@ -3386,14 +3381,9 @@ func autoconvert_v1beta1_DeploymentSpec_To_extensions_DeploymentSpec(in *Deploym
} else { } else {
out.Selector = nil out.Selector = nil
} }
if in.Template != nil { if err := convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(&in.Template, &out.Template, s); err != nil {
out.Template = new(api.PodTemplateSpec)
if err := convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(in.Template, out.Template, s); err != nil {
return err return err
} }
} else {
out.Template = nil
}
if err := convert_v1beta1_DeploymentStrategy_To_extensions_DeploymentStrategy(&in.Strategy, &out.Strategy, s); err != nil { if err := convert_v1beta1_DeploymentStrategy_To_extensions_DeploymentStrategy(&in.Strategy, &out.Strategy, s); err != nil {
return err return err
} }

View File

@ -1056,14 +1056,9 @@ func deepCopy_v1beta1_DeploymentSpec(in DeploymentSpec, out *DeploymentSpec, c *
} else { } else {
out.Selector = nil out.Selector = nil
} }
if in.Template != nil { if err := deepCopy_v1_PodTemplateSpec(in.Template, &out.Template, c); err != nil {
out.Template = new(v1.PodTemplateSpec)
if err := deepCopy_v1_PodTemplateSpec(*in.Template, out.Template, c); err != nil {
return err return err
} }
} else {
out.Template = nil
}
if err := deepCopy_v1beta1_DeploymentStrategy(in.Strategy, &out.Strategy, c); err != nil { if err := deepCopy_v1beta1_DeploymentStrategy(in.Strategy, &out.Strategy, c); err != nil {
return err return err
} }

View File

@ -45,10 +45,8 @@ func addDefaultingFuncs() {
}, },
func(obj *Deployment) { func(obj *Deployment) {
// Default labels and selector to labels from pod template spec. // Default labels and selector to labels from pod template spec.
var labels map[string]string labels := obj.Spec.Template.Labels
if obj.Spec.Template != nil {
labels = obj.Spec.Template.Labels
}
if labels != nil { if labels != nil {
if len(obj.Spec.Selector) == 0 { if len(obj.Spec.Selector) == 0 {
obj.Spec.Selector = labels obj.Spec.Selector = labels

View File

@ -88,6 +88,15 @@ func TestSetDefaultDeployment(t *testing.T) {
defaultIntOrString := util.NewIntOrStringFromInt(1) defaultIntOrString := util.NewIntOrStringFromInt(1)
differentIntOrString := util.NewIntOrStringFromInt(5) differentIntOrString := util.NewIntOrStringFromInt(5)
deploymentLabelKey := "deployment.kubernetes.io/podTemplateHash" deploymentLabelKey := "deployment.kubernetes.io/podTemplateHash"
period := int64(v1.DefaultTerminationGracePeriodSeconds)
defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{
DNSPolicy: v1.DNSClusterFirst,
RestartPolicy: v1.RestartPolicyAlways,
SecurityContext: &v1.PodSecurityContext{},
TerminationGracePeriodSeconds: &period,
},
}
tests := []struct { tests := []struct {
original *Deployment original *Deployment
expected *Deployment expected *Deployment
@ -104,6 +113,7 @@ func TestSetDefaultDeployment(t *testing.T) {
MaxUnavailable: &defaultIntOrString, MaxUnavailable: &defaultIntOrString,
}, },
}, },
Template: defaultTemplate,
UniqueLabelKey: newString(deploymentLabelKey), UniqueLabelKey: newString(deploymentLabelKey),
}, },
}, },
@ -129,6 +139,7 @@ func TestSetDefaultDeployment(t *testing.T) {
MaxUnavailable: &defaultIntOrString, MaxUnavailable: &defaultIntOrString,
}, },
}, },
Template: defaultTemplate,
UniqueLabelKey: newString(deploymentLabelKey), UniqueLabelKey: newString(deploymentLabelKey),
}, },
}, },
@ -148,6 +159,7 @@ func TestSetDefaultDeployment(t *testing.T) {
Strategy: DeploymentStrategy{ Strategy: DeploymentStrategy{
Type: RecreateDeploymentStrategyType, Type: RecreateDeploymentStrategyType,
}, },
Template: defaultTemplate,
UniqueLabelKey: newString(deploymentLabelKey), UniqueLabelKey: newString(deploymentLabelKey),
}, },
}, },
@ -168,6 +180,7 @@ func TestSetDefaultDeployment(t *testing.T) {
Strategy: DeploymentStrategy{ Strategy: DeploymentStrategy{
Type: RecreateDeploymentStrategyType, Type: RecreateDeploymentStrategyType,
}, },
Template: defaultTemplate,
UniqueLabelKey: newString("customDeploymentKey"), UniqueLabelKey: newString("customDeploymentKey"),
}, },
}, },
@ -184,7 +197,7 @@ func TestSetDefaultDeployment(t *testing.T) {
t.FailNow() t.FailNow()
} }
if !reflect.DeepEqual(got.Spec, expected.Spec) { if !reflect.DeepEqual(got.Spec, expected.Spec) {
t.Errorf("got different than expected: %v, %v", got, expected) t.Errorf("got different than expected:\n\t%+v\ngot:\n\t%+v", got.Spec, expected.Spec)
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -201,7 +201,7 @@ type DeploymentSpec struct {
Selector map[string]string `json:"selector,omitempty"` Selector map[string]string `json:"selector,omitempty"`
// Template describes the pods that will be created. // Template describes the pods that will be created.
Template *v1.PodTemplateSpec `json:"template,omitempty"` Template v1.PodTemplateSpec `json:"template"`
// The deployment strategy to use to replace existing pods with new ones. // The deployment strategy to use to replace existing pods with new ones.
Strategy DeploymentStrategy `json:"strategy,omitempty"` Strategy DeploymentStrategy `json:"strategy,omitempty"`

View File

@ -265,7 +265,7 @@ func ValidateDeploymentSpec(spec *extensions.DeploymentSpec) errs.ValidationErro
allErrs := errs.ValidationErrorList{} allErrs := errs.ValidationErrorList{}
allErrs = append(allErrs, apivalidation.ValidateNonEmptySelector(spec.Selector, "selector")...) allErrs = append(allErrs, apivalidation.ValidateNonEmptySelector(spec.Selector, "selector")...)
allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(spec.Replicas), "replicas")...) allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(spec.Replicas), "replicas")...)
allErrs = append(allErrs, apivalidation.ValidatePodTemplateSpecForRC(spec.Template, spec.Selector, spec.Replicas, "template")...) allErrs = append(allErrs, apivalidation.ValidatePodTemplateSpecForRC(&spec.Template, spec.Selector, spec.Replicas, "template")...)
allErrs = append(allErrs, ValidateDeploymentStrategy(&spec.Strategy, "strategy")...) allErrs = append(allErrs, ValidateDeploymentStrategy(&spec.Strategy, "strategy")...)
allErrs = append(allErrs, apivalidation.ValidateLabelName(spec.UniqueLabelKey, "uniqueLabel")...) allErrs = append(allErrs, apivalidation.ValidateLabelName(spec.UniqueLabelKey, "uniqueLabel")...)
return allErrs return allErrs

View File

@ -613,7 +613,7 @@ func validDeployment() *extensions.Deployment {
Selector: map[string]string{ Selector: map[string]string{
"name": "abc", "name": "abc",
}, },
Template: &api.PodTemplateSpec{ Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Name: "abc", Name: "abc",
Namespace: api.NamespaceDefault, Namespace: api.NamespaceDefault,

View File

@ -151,7 +151,7 @@ func (d *DeploymentController) getNewRC(deployment extensions.Deployment) (*api.
Spec: api.ReplicationControllerSpec{ Spec: api.ReplicationControllerSpec{
Replicas: 0, Replicas: 0,
Selector: newRCSelector, Selector: newRCSelector,
Template: newRCTemplate, Template: &newRCTemplate,
}, },
} }
createdRC, err := d.client.ReplicationControllers(namespace).Create(&newRC) createdRC, err := d.client.ReplicationControllers(namespace).Create(&newRC)

View File

@ -503,7 +503,7 @@ func TestDescribeDeployment(t *testing.T) {
Namespace: "foo", Namespace: "foo",
}, },
Spec: extensions.DeploymentSpec{ Spec: extensions.DeploymentSpec{
Template: &api.PodTemplateSpec{}, Template: api.PodTemplateSpec{},
}, },
}) })
c := &describeClient{T: t, Namespace: "foo", Interface: fake} c := &describeClient{T: t, Namespace: "foo", Interface: fake}

View File

@ -1237,7 +1237,7 @@ func TestPrintDeployment(t *testing.T) {
}, },
Spec: extensions.DeploymentSpec{ Spec: extensions.DeploymentSpec{
Replicas: 5, Replicas: 5,
Template: &api.PodTemplateSpec{ Template: api.PodTemplateSpec{
Spec: api.PodSpec{Containers: make([]api.Container, 2)}, Spec: api.PodSpec{Containers: make([]api.Container, 2)},
}, },
}, },

View File

@ -48,7 +48,7 @@ func validNewDeployment() *extensions.Deployment {
}, },
Spec: extensions.DeploymentSpec{ Spec: extensions.DeploymentSpec{
Selector: map[string]string{"a": "b"}, Selector: map[string]string{"a": "b"},
Template: &api.PodTemplateSpec{ Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: map[string]string{"a": "b"}, Labels: map[string]string{"a": "b"},
}, },

View File

@ -49,7 +49,8 @@ func GetOldRCs(deployment extensions.Deployment, c client.Interface) ([]*api.Rep
rcLabelsSelector := labels.SelectorFromSet(rc.Spec.Selector) rcLabelsSelector := labels.SelectorFromSet(rc.Spec.Selector)
if rcLabelsSelector.Matches(podLabelsSelector) { if rcLabelsSelector.Matches(podLabelsSelector) {
// Filter out RC that has the same pod template spec as the deployment - that is the new RC. // Filter out RC that has the same pod template spec as the deployment - that is the new RC.
if api.Semantic.DeepEqual(rc.Spec.Template, GetNewRCTemplate(deployment)) { newRCTemplate := GetNewRCTemplate(deployment)
if api.Semantic.DeepEqual(rc.Spec.Template, &newRCTemplate) {
continue continue
} }
oldRCs[rc.ObjectMeta.Name] = rc oldRCs[rc.ObjectMeta.Name] = rc
@ -74,7 +75,7 @@ func GetNewRC(deployment extensions.Deployment, c client.Interface) (*api.Replic
newRCTemplate := GetNewRCTemplate(deployment) newRCTemplate := GetNewRCTemplate(deployment)
for _, rc := range rcList.Items { for _, rc := range rcList.Items {
if api.Semantic.DeepEqual(rc.Spec.Template, newRCTemplate) { if api.Semantic.DeepEqual(rc.Spec.Template, &newRCTemplate) {
// This is the new RC. // This is the new RC.
return &rc, nil return &rc, nil
} }
@ -84,9 +85,9 @@ func GetNewRC(deployment extensions.Deployment, c client.Interface) (*api.Replic
} }
// Returns the desired PodTemplateSpec for the new RC corresponding to the given RC. // Returns the desired PodTemplateSpec for the new RC corresponding to the given RC.
func GetNewRCTemplate(deployment extensions.Deployment) *api.PodTemplateSpec { func GetNewRCTemplate(deployment extensions.Deployment) api.PodTemplateSpec {
// newRC will have the same template as in deployment spec, plus a unique label in some cases. // newRC will have the same template as in deployment spec, plus a unique label in some cases.
newRCTemplate := &api.PodTemplateSpec{ newRCTemplate := api.PodTemplateSpec{
ObjectMeta: deployment.Spec.Template.ObjectMeta, ObjectMeta: deployment.Spec.Template.ObjectMeta,
Spec: deployment.Spec.Template.Spec, Spec: deployment.Spec.Template.Spec,
} }
@ -113,7 +114,7 @@ func CloneAndAddLabel(labels map[string]string, labelKey string, labelValue uint
return newLabels return newLabels
} }
func GetPodTemplateSpecHash(template *api.PodTemplateSpec) uint32 { func GetPodTemplateSpecHash(template api.PodTemplateSpec) uint32 {
podTemplateSpecHasher := adler32.New() podTemplateSpecHasher := adler32.New()
util.DeepHashObject(podTemplateSpecHasher, template) util.DeepHashObject(podTemplateSpecHasher, template)
return podTemplateSpecHasher.Sum32() return podTemplateSpecHasher.Sum32()

View File

@ -18,6 +18,7 @@ package e2e
import ( import (
"fmt" "fmt"
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/extensions"
deploymentutil "k8s.io/kubernetes/pkg/util/deployment" deploymentutil "k8s.io/kubernetes/pkg/util/deployment"
@ -54,7 +55,7 @@ func testNewDeployment(f *Framework) {
Replicas: 1, Replicas: 1,
Selector: podLabels, Selector: podLabels,
UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash", UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash",
Template: &api.PodTemplateSpec{ Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: podLabels, Labels: podLabels,
}, },
@ -147,7 +148,7 @@ func testRollingUpdateDeployment(f *Framework) {
Replicas: 3, Replicas: 3,
Selector: deploymentPodLabels, Selector: deploymentPodLabels,
UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash", UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash",
Template: &api.PodTemplateSpec{ Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: deploymentPodLabels, Labels: deploymentPodLabels,
}, },
@ -228,7 +229,7 @@ func testRollingUpdateDeploymentEvents(f *Framework) {
Replicas: 1, Replicas: 1,
Selector: deploymentPodLabels, Selector: deploymentPodLabels,
UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash", UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash",
Template: &api.PodTemplateSpec{ Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: deploymentPodLabels, Labels: deploymentPodLabels,
}, },