mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
move deployment PodTemplate to be not a pointer
This commit is contained in:
@@ -208,7 +208,7 @@ type DeploymentSpec struct {
|
||||
Selector map[string]string `json:"selector,omitempty"`
|
||||
|
||||
// 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.
|
||||
Strategy DeploymentStrategy `json:"strategy,omitempty"`
|
||||
|
||||
@@ -213,13 +213,8 @@ func convert_extensions_DeploymentSpec_To_v1beta1_DeploymentSpec(in *extensions.
|
||||
} else {
|
||||
out.Selector = nil
|
||||
}
|
||||
if in.Template != nil {
|
||||
out.Template = new(v1.PodTemplateSpec)
|
||||
if err := convert_api_PodTemplateSpec_To_v1_PodTemplateSpec(in.Template, out.Template, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.Template = nil
|
||||
if err := convert_api_PodTemplateSpec_To_v1_PodTemplateSpec(&in.Template, &out.Template, s); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := convert_extensions_DeploymentStrategy_To_v1beta1_DeploymentStrategy(&in.Strategy, &out.Strategy, s); err != nil {
|
||||
return err
|
||||
@@ -244,13 +239,8 @@ func convert_v1beta1_DeploymentSpec_To_extensions_DeploymentSpec(in *DeploymentS
|
||||
} else {
|
||||
out.Selector = nil
|
||||
}
|
||||
if in.Template != nil {
|
||||
out.Template = new(api.PodTemplateSpec)
|
||||
if err := convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(in.Template, out.Template, s); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.Template = nil
|
||||
if err := convert_v1_PodTemplateSpec_To_api_PodTemplateSpec(&in.Template, &out.Template, s); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := convert_v1beta1_DeploymentStrategy_To_extensions_DeploymentStrategy(&in.Strategy, &out.Strategy, s); err != nil {
|
||||
return err
|
||||
|
||||
@@ -45,10 +45,8 @@ func addDefaultingFuncs() {
|
||||
},
|
||||
func(obj *Deployment) {
|
||||
// Default labels and selector to labels from pod template spec.
|
||||
var labels map[string]string
|
||||
if obj.Spec.Template != nil {
|
||||
labels = obj.Spec.Template.Labels
|
||||
}
|
||||
labels := obj.Spec.Template.Labels
|
||||
|
||||
if labels != nil {
|
||||
if len(obj.Spec.Selector) == 0 {
|
||||
obj.Spec.Selector = labels
|
||||
|
||||
@@ -88,6 +88,15 @@ func TestSetDefaultDeployment(t *testing.T) {
|
||||
defaultIntOrString := util.NewIntOrStringFromInt(1)
|
||||
differentIntOrString := util.NewIntOrStringFromInt(5)
|
||||
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 {
|
||||
original *Deployment
|
||||
expected *Deployment
|
||||
@@ -104,6 +113,7 @@ func TestSetDefaultDeployment(t *testing.T) {
|
||||
MaxUnavailable: &defaultIntOrString,
|
||||
},
|
||||
},
|
||||
Template: defaultTemplate,
|
||||
UniqueLabelKey: newString(deploymentLabelKey),
|
||||
},
|
||||
},
|
||||
@@ -129,6 +139,7 @@ func TestSetDefaultDeployment(t *testing.T) {
|
||||
MaxUnavailable: &defaultIntOrString,
|
||||
},
|
||||
},
|
||||
Template: defaultTemplate,
|
||||
UniqueLabelKey: newString(deploymentLabelKey),
|
||||
},
|
||||
},
|
||||
@@ -148,6 +159,7 @@ func TestSetDefaultDeployment(t *testing.T) {
|
||||
Strategy: DeploymentStrategy{
|
||||
Type: RecreateDeploymentStrategyType,
|
||||
},
|
||||
Template: defaultTemplate,
|
||||
UniqueLabelKey: newString(deploymentLabelKey),
|
||||
},
|
||||
},
|
||||
@@ -168,6 +180,7 @@ func TestSetDefaultDeployment(t *testing.T) {
|
||||
Strategy: DeploymentStrategy{
|
||||
Type: RecreateDeploymentStrategyType,
|
||||
},
|
||||
Template: defaultTemplate,
|
||||
UniqueLabelKey: newString("customDeploymentKey"),
|
||||
},
|
||||
},
|
||||
@@ -184,7 +197,7 @@ func TestSetDefaultDeployment(t *testing.T) {
|
||||
t.FailNow()
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ type DeploymentSpec struct {
|
||||
Selector map[string]string `json:"selector,omitempty"`
|
||||
|
||||
// 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.
|
||||
Strategy DeploymentStrategy `json:"strategy,omitempty"`
|
||||
|
||||
@@ -265,7 +265,7 @@ func ValidateDeploymentSpec(spec *extensions.DeploymentSpec) errs.ValidationErro
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
allErrs = append(allErrs, apivalidation.ValidateNonEmptySelector(spec.Selector, "selector")...)
|
||||
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, apivalidation.ValidateLabelName(spec.UniqueLabelKey, "uniqueLabel")...)
|
||||
return allErrs
|
||||
|
||||
@@ -613,7 +613,7 @@ func validDeployment() *extensions.Deployment {
|
||||
Selector: map[string]string{
|
||||
"name": "abc",
|
||||
},
|
||||
Template: &api.PodTemplateSpec{
|
||||
Template: api.PodTemplateSpec{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "abc",
|
||||
Namespace: api.NamespaceDefault,
|
||||
|
||||
Reference in New Issue
Block a user