Commit 7e9fb97b authored by Janet Kuo's avatar Janet Kuo

Remove UniqueLabelKey from deployment spec

parent 8f3eb936
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -252,16 +252,6 @@ type DeploymentSpec struct { ...@@ -252,16 +252,6 @@ type DeploymentSpec struct {
// This is a pointer to distinguish between explicit zero and not specified. // This is a pointer to distinguish between explicit zero and not specified.
RevisionHistoryLimit *int `json:"revisionHistoryLimit,omitempty"` RevisionHistoryLimit *int `json:"revisionHistoryLimit,omitempty"`
// Key of the selector that is added to existing RCs (and label key that is
// added to its pods) to prevent the existing RCs to select new pods (and old
// pods being selected by new RC).
// Users can set this to an empty string to indicate that the system should
// not add any selector and label. If unspecified, system uses
// DefaultDeploymentUniqueLabelKey("deployment.kubernetes.io/podTemplateHash").
// Value of this key is hash of DeploymentSpec.PodTemplateSpec.
// No label is added if this is set to empty string.
UniqueLabelKey string `json:"uniqueLabelKey,omitempty"`
// Indicates that the deployment is paused and will not be processed by the // Indicates that the deployment is paused and will not be processed by the
// deployment controller. // deployment controller.
Paused bool `json:"paused,omitempty"` Paused bool `json:"paused,omitempty"`
...@@ -288,9 +278,8 @@ type RollbackConfig struct { ...@@ -288,9 +278,8 @@ type RollbackConfig struct {
const ( const (
// DefaultDeploymentUniqueLabelKey is the default key of the selector that is added // DefaultDeploymentUniqueLabelKey is the default key of the selector that is added
// to existing RCs (and label key that is added to its pods) to prevent the existing RCs // to existing RCs (and label key that is added to its pods) to prevent the existing RCs
// to select new pods (and old pods being select by new RC). See DeploymentSpec's UniqueLabelKey // to select new pods (and old pods being select by new RC).
// field for more information. DefaultDeploymentUniqueLabelKey string = "pod-template-hash"
DefaultDeploymentUniqueLabelKey string = "deployment.kubernetes.io/podTemplateHash"
) )
type DeploymentStrategy struct { type DeploymentStrategy struct {
......
...@@ -121,8 +121,6 @@ func Convert_extensions_DeploymentSpec_To_v1beta1_DeploymentSpec(in *extensions. ...@@ -121,8 +121,6 @@ func Convert_extensions_DeploymentSpec_To_v1beta1_DeploymentSpec(in *extensions.
out.RevisionHistoryLimit = new(int32) out.RevisionHistoryLimit = new(int32)
*out.RevisionHistoryLimit = int32(*in.RevisionHistoryLimit) *out.RevisionHistoryLimit = int32(*in.RevisionHistoryLimit)
} }
out.UniqueLabelKey = new(string)
*out.UniqueLabelKey = in.UniqueLabelKey
out.MinReadySeconds = int32(in.MinReadySeconds) out.MinReadySeconds = int32(in.MinReadySeconds)
out.Paused = in.Paused out.Paused = in.Paused
if in.RollbackTo != nil { if in.RollbackTo != nil {
...@@ -159,9 +157,6 @@ func Convert_v1beta1_DeploymentSpec_To_extensions_DeploymentSpec(in *DeploymentS ...@@ -159,9 +157,6 @@ func Convert_v1beta1_DeploymentSpec_To_extensions_DeploymentSpec(in *DeploymentS
out.RevisionHistoryLimit = new(int) out.RevisionHistoryLimit = new(int)
*out.RevisionHistoryLimit = int(*in.RevisionHistoryLimit) *out.RevisionHistoryLimit = int(*in.RevisionHistoryLimit)
} }
if in.UniqueLabelKey != nil {
out.UniqueLabelKey = *in.UniqueLabelKey
}
out.MinReadySeconds = int(in.MinReadySeconds) out.MinReadySeconds = int(in.MinReadySeconds)
out.Paused = in.Paused out.Paused = in.Paused
if in.RollbackTo != nil { if in.RollbackTo != nil {
......
...@@ -2830,9 +2830,6 @@ func autoConvert_extensions_DeploymentSpec_To_v1beta1_DeploymentSpec(in *extensi ...@@ -2830,9 +2830,6 @@ func autoConvert_extensions_DeploymentSpec_To_v1beta1_DeploymentSpec(in *extensi
} else { } else {
out.RevisionHistoryLimit = nil out.RevisionHistoryLimit = nil
} }
if err := api.Convert_string_To_string_ref(&in.UniqueLabelKey, &out.UniqueLabelKey, s); err != nil {
return err
}
out.Paused = in.Paused out.Paused = in.Paused
// unable to generate simple pointer conversion for extensions.RollbackConfig -> v1beta1.RollbackConfig // unable to generate simple pointer conversion for extensions.RollbackConfig -> v1beta1.RollbackConfig
if in.RollbackTo != nil { if in.RollbackTo != nil {
...@@ -4148,9 +4145,6 @@ func autoConvert_v1beta1_DeploymentSpec_To_extensions_DeploymentSpec(in *Deploym ...@@ -4148,9 +4145,6 @@ func autoConvert_v1beta1_DeploymentSpec_To_extensions_DeploymentSpec(in *Deploym
} else { } else {
out.RevisionHistoryLimit = nil out.RevisionHistoryLimit = nil
} }
if err := api.Convert_string_ref_To_string(&in.UniqueLabelKey, &out.UniqueLabelKey, s); err != nil {
return err
}
out.Paused = in.Paused out.Paused = in.Paused
// unable to generate simple pointer conversion for v1beta1.RollbackConfig -> extensions.RollbackConfig // unable to generate simple pointer conversion for v1beta1.RollbackConfig -> extensions.RollbackConfig
if in.RollbackTo != nil { if in.RollbackTo != nil {
......
...@@ -1190,12 +1190,6 @@ func deepCopy_v1beta1_DeploymentSpec(in DeploymentSpec, out *DeploymentSpec, c * ...@@ -1190,12 +1190,6 @@ func deepCopy_v1beta1_DeploymentSpec(in DeploymentSpec, out *DeploymentSpec, c *
} else { } else {
out.RevisionHistoryLimit = nil out.RevisionHistoryLimit = nil
} }
if in.UniqueLabelKey != nil {
out.UniqueLabelKey = new(string)
*out.UniqueLabelKey = *in.UniqueLabelKey
} else {
out.UniqueLabelKey = nil
}
out.Paused = in.Paused out.Paused = in.Paused
if in.RollbackTo != nil { if in.RollbackTo != nil {
out.RollbackTo = new(RollbackConfig) out.RollbackTo = new(RollbackConfig)
......
...@@ -100,10 +100,6 @@ func addDefaultingFuncs(scheme *runtime.Scheme) { ...@@ -100,10 +100,6 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
strategy.RollingUpdate.MaxSurge = &maxSurge strategy.RollingUpdate.MaxSurge = &maxSurge
} }
} }
if obj.Spec.UniqueLabelKey == nil {
obj.Spec.UniqueLabelKey = new(string)
*obj.Spec.UniqueLabelKey = DefaultDeploymentUniqueLabelKey
}
}, },
func(obj *Job) { func(obj *Job) {
labels := obj.Spec.Template.Labels labels := obj.Spec.Template.Labels
......
...@@ -198,7 +198,6 @@ func TestSetDefaultDaemonSet(t *testing.T) { ...@@ -198,7 +198,6 @@ func TestSetDefaultDaemonSet(t *testing.T) {
func TestSetDefaultDeployment(t *testing.T) { func TestSetDefaultDeployment(t *testing.T) {
defaultIntOrString := intstr.FromInt(1) defaultIntOrString := intstr.FromInt(1)
differentIntOrString := intstr.FromInt(5) differentIntOrString := intstr.FromInt(5)
deploymentLabelKey := DefaultDeploymentUniqueLabelKey
period := int64(v1.DefaultTerminationGracePeriodSeconds) period := int64(v1.DefaultTerminationGracePeriodSeconds)
defaultTemplate := v1.PodTemplateSpec{ defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{ Spec: v1.PodSpec{
...@@ -224,8 +223,7 @@ func TestSetDefaultDeployment(t *testing.T) { ...@@ -224,8 +223,7 @@ func TestSetDefaultDeployment(t *testing.T) {
MaxUnavailable: &defaultIntOrString, MaxUnavailable: &defaultIntOrString,
}, },
}, },
Template: defaultTemplate, Template: defaultTemplate,
UniqueLabelKey: newString(deploymentLabelKey),
}, },
}, },
}, },
...@@ -250,8 +248,7 @@ func TestSetDefaultDeployment(t *testing.T) { ...@@ -250,8 +248,7 @@ func TestSetDefaultDeployment(t *testing.T) {
MaxUnavailable: &defaultIntOrString, MaxUnavailable: &defaultIntOrString,
}, },
}, },
Template: defaultTemplate, Template: defaultTemplate,
UniqueLabelKey: newString(deploymentLabelKey),
}, },
}, },
}, },
...@@ -270,8 +267,7 @@ func TestSetDefaultDeployment(t *testing.T) { ...@@ -270,8 +267,7 @@ func TestSetDefaultDeployment(t *testing.T) {
Strategy: DeploymentStrategy{ Strategy: DeploymentStrategy{
Type: RecreateDeploymentStrategyType, Type: RecreateDeploymentStrategyType,
}, },
Template: defaultTemplate, Template: defaultTemplate,
UniqueLabelKey: newString(deploymentLabelKey),
}, },
}, },
}, },
...@@ -282,7 +278,6 @@ func TestSetDefaultDeployment(t *testing.T) { ...@@ -282,7 +278,6 @@ func TestSetDefaultDeployment(t *testing.T) {
Strategy: DeploymentStrategy{ Strategy: DeploymentStrategy{
Type: RecreateDeploymentStrategyType, Type: RecreateDeploymentStrategyType,
}, },
UniqueLabelKey: newString("customDeploymentKey"),
}, },
}, },
expected: &Deployment{ expected: &Deployment{
...@@ -291,8 +286,7 @@ func TestSetDefaultDeployment(t *testing.T) { ...@@ -291,8 +286,7 @@ func TestSetDefaultDeployment(t *testing.T) {
Strategy: DeploymentStrategy{ Strategy: DeploymentStrategy{
Type: RecreateDeploymentStrategyType, Type: RecreateDeploymentStrategyType,
}, },
Template: defaultTemplate, Template: defaultTemplate,
UniqueLabelKey: newString("customDeploymentKey"),
}, },
}, },
}, },
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -237,16 +237,6 @@ type DeploymentSpec struct { ...@@ -237,16 +237,6 @@ type DeploymentSpec struct {
// This is a pointer to distinguish between explicit zero and not specified. // This is a pointer to distinguish between explicit zero and not specified.
RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"` RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"`
// Key of the selector that is added to existing RCs (and label key that is
// added to its pods) to prevent the existing RCs to select new pods (and old
// pods being selected by new RC).
// Users can set this to an empty string to indicate that the system should
// not add any selector and label. If unspecified, system uses
// DefaultDeploymentUniqueLabelKey("deployment.kubernetes.io/podTemplateHash").
// Value of this key is hash of DeploymentSpec.PodTemplateSpec.
// No label is added if this is set to empty string.
UniqueLabelKey *string `json:"uniqueLabelKey,omitempty"`
// Indicates that the deployment is paused and will not be processed by the // Indicates that the deployment is paused and will not be processed by the
// deployment controller. // deployment controller.
Paused bool `json:"paused,omitempty"` Paused bool `json:"paused,omitempty"`
...@@ -273,9 +263,8 @@ type RollbackConfig struct { ...@@ -273,9 +263,8 @@ type RollbackConfig struct {
const ( const (
// DefaultDeploymentUniqueLabelKey is the default key of the selector that is added // DefaultDeploymentUniqueLabelKey is the default key of the selector that is added
// to existing RCs (and label key that is added to its pods) to prevent the existing RCs // to existing RCs (and label key that is added to its pods) to prevent the existing RCs
// to select new pods (and old pods being select by new RC). See DeploymentSpec's UniqueLabelKey // to select new pods (and old pods being select by new RC).
// field for more information. DefaultDeploymentUniqueLabelKey string = "pod-template-hash"
DefaultDeploymentUniqueLabelKey string = "deployment.kubernetes.io/podTemplateHash"
) )
// DeploymentStrategy describes how to replace existing pods with new ones. // DeploymentStrategy describes how to replace existing pods with new ones.
......
...@@ -186,7 +186,6 @@ var map_DeploymentSpec = map[string]string{ ...@@ -186,7 +186,6 @@ var map_DeploymentSpec = map[string]string{
"strategy": "The deployment strategy to use to replace existing pods with new ones.", "strategy": "The deployment strategy to use to replace existing pods with new ones.",
"minReadySeconds": "Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready)", "minReadySeconds": "Minimum number of seconds for which a newly created pod should be ready without any of its container crashing, for it to be considered available. Defaults to 0 (pod will be considered available as soon as it is ready)",
"revisionHistoryLimit": "The number of old ReplicationControllers to retain to allow rollback. This is a pointer to distinguish between explicit zero and not specified.", "revisionHistoryLimit": "The number of old ReplicationControllers to retain to allow rollback. This is a pointer to distinguish between explicit zero and not specified.",
"uniqueLabelKey": "Key of the selector that is added to existing RCs (and label key that is added to its pods) to prevent the existing RCs to select new pods (and old pods being selected by new RC). Users can set this to an empty string to indicate that the system should not add any selector and label. If unspecified, system uses DefaultDeploymentUniqueLabelKey(\"deployment.kubernetes.io/podTemplateHash\"). Value of this key is hash of DeploymentSpec.PodTemplateSpec. No label is added if this is set to empty string.",
"paused": "Indicates that the deployment is paused and will not be processed by the deployment controller.", "paused": "Indicates that the deployment is paused and will not be processed by the deployment controller.",
"rollbackTo": "The config this deployment is rolling back to. Will be cleared after rollback is done.", "rollbackTo": "The config this deployment is rolling back to. Will be cleared after rollback is done.",
} }
......
...@@ -328,10 +328,6 @@ func ValidateDeploymentSpec(spec *extensions.DeploymentSpec, fldPath *field.Path ...@@ -328,10 +328,6 @@ func ValidateDeploymentSpec(spec *extensions.DeploymentSpec, fldPath *field.Path
// zero is a valid RevisionHistoryLimit // zero is a valid RevisionHistoryLimit
allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(*spec.RevisionHistoryLimit), fldPath.Child("revisionHistoryLimit"))...) allErrs = append(allErrs, apivalidation.ValidateNonnegativeField(int64(*spec.RevisionHistoryLimit), fldPath.Child("revisionHistoryLimit"))...)
} }
// empty string is a valid UniqueLabelKey
if len(spec.UniqueLabelKey) > 0 {
allErrs = append(allErrs, apivalidation.ValidateLabelName(spec.UniqueLabelKey, fldPath.Child("uniqueLabel"))...)
}
if spec.RollbackTo != nil { if spec.RollbackTo != nil {
allErrs = append(allErrs, ValidateRollback(spec.RollbackTo, fldPath.Child("rollback"))...) allErrs = append(allErrs, ValidateRollback(spec.RollbackTo, fldPath.Child("rollback"))...)
} }
......
...@@ -872,7 +872,6 @@ func validDeployment() *extensions.Deployment { ...@@ -872,7 +872,6 @@ func validDeployment() *extensions.Deployment {
}, },
}, },
}, },
UniqueLabelKey: "my-label",
RollbackTo: &extensions.RollbackConfig{ RollbackTo: &extensions.RollbackConfig{
Revision: 1, Revision: 1,
}, },
...@@ -908,11 +907,6 @@ func TestValidateDeployment(t *testing.T) { ...@@ -908,11 +907,6 @@ func TestValidateDeployment(t *testing.T) {
invalidRestartPolicyDeployment.Spec.Template.Spec.RestartPolicy = api.RestartPolicyNever invalidRestartPolicyDeployment.Spec.Template.Spec.RestartPolicy = api.RestartPolicyNever
errorCases["Unsupported value: \"Never\""] = invalidRestartPolicyDeployment errorCases["Unsupported value: \"Never\""] = invalidRestartPolicyDeployment
// invalid unique label key.
invalidUniqueLabelDeployment := validDeployment()
invalidUniqueLabelDeployment.Spec.UniqueLabelKey = "abc/def/ghi"
errorCases["spec.uniqueLabel: Invalid value"] = invalidUniqueLabelDeployment
// rollingUpdate should be nil for recreate. // rollingUpdate should be nil for recreate.
invalidRecreateDeployment := validDeployment() invalidRecreateDeployment := validDeployment()
invalidRecreateDeployment.Spec.Strategy = extensions.DeploymentStrategy{ invalidRecreateDeployment.Spec.Strategy = extensions.DeploymentStrategy{
......
...@@ -696,7 +696,7 @@ func (dc *DeploymentController) getNewRC(deployment extensions.Deployment, maxOl ...@@ -696,7 +696,7 @@ func (dc *DeploymentController) getNewRC(deployment extensions.Deployment, maxOl
podTemplateSpecHash := podutil.GetPodTemplateSpecHash(deployment.Spec.Template) podTemplateSpecHash := podutil.GetPodTemplateSpecHash(deployment.Spec.Template)
newRCTemplate := deploymentutil.GetNewRCTemplate(deployment) newRCTemplate := deploymentutil.GetNewRCTemplate(deployment)
// Add podTemplateHash label to selector. // Add podTemplateHash label to selector.
newRCSelector := labelsutil.CloneAndAddLabel(deployment.Spec.Selector, deployment.Spec.UniqueLabelKey, podTemplateSpecHash) newRCSelector := labelsutil.CloneAndAddLabel(deployment.Spec.Selector, extensions.DefaultDeploymentUniqueLabelKey, podTemplateSpecHash)
// Set RC expectations (1 rc should be created) // Set RC expectations (1 rc should be created)
dKey, err = controller.KeyFunc(&deployment) dKey, err = controller.KeyFunc(&deployment)
......
...@@ -110,7 +110,6 @@ func (DeploymentV1Beta1) Generate(genericParams map[string]interface{}) (runtime ...@@ -110,7 +110,6 @@ func (DeploymentV1Beta1) Generate(genericParams map[string]interface{}) (runtime
}, },
Spec: *podSpec, Spec: *podSpec,
}, },
UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey,
}, },
} }
return &deployment, nil return &deployment, nil
......
...@@ -655,9 +655,8 @@ func TestGenerateDeployment(t *testing.T) { ...@@ -655,9 +655,8 @@ func TestGenerateDeployment(t *testing.T) {
Labels: map[string]string{"foo": "bar", "baz": "blah"}, Labels: map[string]string{"foo": "bar", "baz": "blah"},
}, },
Spec: extensions.DeploymentSpec{ Spec: extensions.DeploymentSpec{
Replicas: 3, Replicas: 3,
Selector: map[string]string{"foo": "bar", "baz": "blah"}, Selector: map[string]string{"foo": "bar", "baz": "blah"},
UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey,
Template: api.PodTemplateSpec{ Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: map[string]string{"foo": "bar", "baz": "blah"}, Labels: map[string]string{"foo": "bar", "baz": "blah"},
......
...@@ -67,8 +67,7 @@ func validNewDeployment() *extensions.Deployment { ...@@ -67,8 +67,7 @@ func validNewDeployment() *extensions.Deployment {
DNSPolicy: api.DNSClusterFirst, DNSPolicy: api.DNSClusterFirst,
}, },
}, },
UniqueLabelKey: "my-label", Replicas: 7,
Replicas: 7,
}, },
Status: extensions.DeploymentStatus{ Status: extensions.DeploymentStatus{
Replicas: 5, Replicas: 5,
......
...@@ -138,7 +138,7 @@ func GetNewRCTemplate(deployment extensions.Deployment) api.PodTemplateSpec { ...@@ -138,7 +138,7 @@ func GetNewRCTemplate(deployment extensions.Deployment) api.PodTemplateSpec {
} }
newRCTemplate.ObjectMeta.Labels = labelsutil.CloneAndAddLabel( newRCTemplate.ObjectMeta.Labels = labelsutil.CloneAndAddLabel(
deployment.Spec.Template.ObjectMeta.Labels, deployment.Spec.Template.ObjectMeta.Labels,
deployment.Spec.UniqueLabelKey, extensions.DefaultDeploymentUniqueLabelKey,
podutil.GetPodTemplateSpecHash(newRCTemplate)) podutil.GetPodTemplateSpecHash(newRCTemplate))
return newRCTemplate return newRCTemplate
} }
...@@ -149,7 +149,7 @@ func SetFromRCTemplate(deployment *extensions.Deployment, template api.PodTempla ...@@ -149,7 +149,7 @@ func SetFromRCTemplate(deployment *extensions.Deployment, template api.PodTempla
deployment.Spec.Template.Spec = template.Spec deployment.Spec.Template.Spec = template.Spec
deployment.Spec.Template.ObjectMeta.Labels = labelsutil.CloneAndRemoveLabel( deployment.Spec.Template.ObjectMeta.Labels = labelsutil.CloneAndRemoveLabel(
deployment.Spec.Template.ObjectMeta.Labels, deployment.Spec.Template.ObjectMeta.Labels,
deployment.Spec.UniqueLabelKey) extensions.DefaultDeploymentUniqueLabelKey)
return deployment return deployment
} }
......
...@@ -159,9 +159,8 @@ func generateDeployment(image string) extensions.Deployment { ...@@ -159,9 +159,8 @@ func generateDeployment(image string) extensions.Deployment {
Name: image, Name: image,
}, },
Spec: extensions.DeploymentSpec{ Spec: extensions.DeploymentSpec{
Replicas: 1, Replicas: 1,
Selector: podLabels, Selector: podLabels,
UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash",
Template: api.PodTemplateSpec{ Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: podLabels, Labels: podLabels,
......
...@@ -101,7 +101,6 @@ func newDeployment(deploymentName string, replicas int, podLabels map[string]str ...@@ -101,7 +101,6 @@ func newDeployment(deploymentName string, replicas int, podLabels map[string]str
Type: strategyType, Type: strategyType,
}, },
RevisionHistoryLimit: revisionHistoryLimit, RevisionHistoryLimit: revisionHistoryLimit,
UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey,
Template: api.PodTemplateSpec{ Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: podLabels, Labels: podLabels,
......
...@@ -1511,7 +1511,6 @@ func (config *DeploymentConfig) create() error { ...@@ -1511,7 +1511,6 @@ func (config *DeploymentConfig) create() error {
Selector: map[string]string{ Selector: map[string]string{
"name": config.Name, "name": config.Name,
}, },
UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey,
Template: api.PodTemplateSpec{ Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{ ObjectMeta: api.ObjectMeta{
Labels: map[string]string{"name": config.Name}, Labels: map[string]string{"name": config.Name},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment