From 0fd51b9e722880f896ac0a903b7bbc8a1d2de1ec Mon Sep 17 00:00:00 2001 From: mqliang Date: Fri, 27 Nov 2015 10:15:12 +0800 Subject: [PATCH] make 'deployment.kubernetes.io/podTemplateHash' as constant --- pkg/apis/extensions/types.go | 10 +++++++++- pkg/apis/extensions/v1beta1/defaults.go | 2 +- pkg/apis/extensions/v1beta1/defaults_test.go | 2 +- pkg/apis/extensions/v1beta1/types.go | 10 +++++++++- .../extensions/v1beta1/types_swagger_doc_generated.go | 2 +- pkg/kubectl/run.go | 2 +- pkg/kubectl/run_test.go | 2 +- test/e2e/deployment.go | 6 +++--- test/e2e/util.go | 2 +- 9 files changed, 27 insertions(+), 11 deletions(-) diff --git a/pkg/apis/extensions/types.go b/pkg/apis/extensions/types.go index 1a216b011e8..63a880a6158 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 96f7ed10dd1..49670fc93dd 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 9ad2352da2f..40006c4e42a 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 e691e11636f..384b4c70d02 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 2143d034f85..cb052f84214 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 4c59a578b74..ab74ba1ec31 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 59cf53bade4..3603f05f73d 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 85915040435..70bdfbfa11c 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 7a0e6a7eed9..b288eeba7b4 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -1382,7 +1382,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},