make 'deployment.kubernetes.io/podTemplateHash' as constant

pull/6/head
mqliang 2015-11-27 10:15:12 +08:00
parent c55b136ae2
commit 0fd51b9e72
9 changed files with 27 additions and 11 deletions

View File

@ -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"`

View File

@ -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) {

View File

@ -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{

View File

@ -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.

View File

@ -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 {

View File

@ -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

View File

@ -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"},

View File

@ -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,

View File

@ -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},