diff --git a/pkg/apis/extensions/types.go b/pkg/apis/extensions/types.go index e2fb806d0e0..147c47ffba0 100644 --- a/pkg/apis/extensions/types.go +++ b/pkg/apis/extensions/types.go @@ -216,12 +216,20 @@ type DeploymentSpec struct { // 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 - // "deployment.kubernetes.io/podTemplateHash". + // 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"` } +const ( + // 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 select new pods (and old pods being select by new RC). See DeploymentSpec's UniqueLabelKey + // field for more information. + DefaultDeploymentUniqueLabelKey string = "deployment.kubernetes.io/podTemplateHash" +) + type DeploymentStrategy struct { // Type of deployment. Can be "Recreate" or "RollingUpdate". Default is RollingUpdate. Type DeploymentStrategyType `json:"type,omitempty"` diff --git a/pkg/apis/extensions/v1beta1/defaults.go b/pkg/apis/extensions/v1beta1/defaults.go index 29a54513c8e..c008a09108f 100644 --- a/pkg/apis/extensions/v1beta1/defaults.go +++ b/pkg/apis/extensions/v1beta1/defaults.go @@ -85,7 +85,7 @@ func addDefaultingFuncs() { } if obj.Spec.UniqueLabelKey == nil { obj.Spec.UniqueLabelKey = new(string) - *obj.Spec.UniqueLabelKey = "deployment.kubernetes.io/podTemplateHash" + *obj.Spec.UniqueLabelKey = DefaultDeploymentUniqueLabelKey } }, func(obj *Job) { diff --git a/pkg/apis/extensions/v1beta1/defaults_test.go b/pkg/apis/extensions/v1beta1/defaults_test.go index 46ebc02f3ab..60f2cb1cc17 100644 --- a/pkg/apis/extensions/v1beta1/defaults_test.go +++ b/pkg/apis/extensions/v1beta1/defaults_test.go @@ -87,7 +87,7 @@ func TestSetDefaultDaemonSet(t *testing.T) { func TestSetDefaultDeployment(t *testing.T) { defaultIntOrString := intstr.FromInt(1) differentIntOrString := intstr.FromInt(5) - deploymentLabelKey := "deployment.kubernetes.io/podTemplateHash" + deploymentLabelKey := DefaultDeploymentUniqueLabelKey period := int64(v1.DefaultTerminationGracePeriodSeconds) defaultTemplate := v1.PodTemplateSpec{ Spec: v1.PodSpec{ diff --git a/pkg/apis/extensions/v1beta1/types.go b/pkg/apis/extensions/v1beta1/types.go index 395bcef15db..0a4465e8e2b 100644 --- a/pkg/apis/extensions/v1beta1/types.go +++ b/pkg/apis/extensions/v1beta1/types.go @@ -209,12 +209,20 @@ type DeploymentSpec struct { // 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 - // "deployment.kubernetes.io/podTemplateHash". + // 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"` } +const ( + // 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 select new pods (and old pods being select by new RC). See DeploymentSpec's UniqueLabelKey + // field for more information. + DefaultDeploymentUniqueLabelKey string = "deployment.kubernetes.io/podTemplateHash" +) + // DeploymentStrategy describes how to replace existing pods with new ones. type DeploymentStrategy struct { // Type of deployment. Can be "Recreate" or "RollingUpdate". Default is RollingUpdate. diff --git a/pkg/apis/extensions/v1beta1/types_swagger_doc_generated.go b/pkg/apis/extensions/v1beta1/types_swagger_doc_generated.go index cdefee08712..50ee043bf86 100644 --- a/pkg/apis/extensions/v1beta1/types_swagger_doc_generated.go +++ b/pkg/apis/extensions/v1beta1/types_swagger_doc_generated.go @@ -143,7 +143,7 @@ var map_DeploymentSpec = map[string]string{ "selector": "Label selector for pods. Existing ReplicationControllers whose pods are selected by this will be the ones affected by this deployment.", "template": "Template describes the pods that will be created.", "strategy": "The deployment strategy to use to replace existing pods with new ones.", - "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 \"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": "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.", } func (DeploymentSpec) SwaggerDoc() map[string]string { diff --git a/pkg/kubectl/run.go b/pkg/kubectl/run.go index 2c378a3680f..eadf3c08cbb 100644 --- a/pkg/kubectl/run.go +++ b/pkg/kubectl/run.go @@ -109,7 +109,7 @@ func (DeploymentV1Beta1) Generate(genericParams map[string]interface{}) (runtime }, Spec: *podSpec, }, - UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash", + UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey, }, } return &deployment, nil diff --git a/pkg/kubectl/run_test.go b/pkg/kubectl/run_test.go index 073ae693ec3..fc7c95c935f 100644 --- a/pkg/kubectl/run_test.go +++ b/pkg/kubectl/run_test.go @@ -656,7 +656,7 @@ func TestGenerateDeployment(t *testing.T) { Spec: extensions.DeploymentSpec{ Replicas: 3, Selector: map[string]string{"foo": "bar", "baz": "blah"}, - UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash", + UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey, Template: api.PodTemplateSpec{ ObjectMeta: api.ObjectMeta{ Labels: map[string]string{"foo": "bar", "baz": "blah"}, diff --git a/test/e2e/deployment.go b/test/e2e/deployment.go index 18a69a64c3b..3a9074b84ed 100644 --- a/test/e2e/deployment.go +++ b/test/e2e/deployment.go @@ -54,7 +54,7 @@ func testNewDeployment(f *Framework) { Spec: extensions.DeploymentSpec{ Replicas: 1, Selector: podLabels, - UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash", + UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey, Template: api.PodTemplateSpec{ ObjectMeta: api.ObjectMeta{ Labels: podLabels, @@ -147,7 +147,7 @@ func testRollingUpdateDeployment(f *Framework) { Spec: extensions.DeploymentSpec{ Replicas: 3, Selector: deploymentPodLabels, - UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash", + UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey, Template: api.PodTemplateSpec{ ObjectMeta: api.ObjectMeta{ Labels: deploymentPodLabels, @@ -228,7 +228,7 @@ func testRollingUpdateDeploymentEvents(f *Framework) { Spec: extensions.DeploymentSpec{ Replicas: 1, Selector: deploymentPodLabels, - UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash", + UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey, Template: api.PodTemplateSpec{ ObjectMeta: api.ObjectMeta{ Labels: deploymentPodLabels, diff --git a/test/e2e/util.go b/test/e2e/util.go index 4bf17a4f742..e27ebdb1a08 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -1383,7 +1383,7 @@ func (config *DeploymentConfig) create() error { Selector: map[string]string{ "name": config.Name, }, - UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash", + UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey, Template: api.PodTemplateSpec{ ObjectMeta: api.ObjectMeta{ Labels: map[string]string{"name": config.Name},