Merge pull request #20765 from janetkuo/remove-podtemplate-key

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot 2016-02-06 00:44:47 -08:00
commit b45a94bc78
23 changed files with 12455 additions and 12668 deletions

View File

@ -71,7 +71,7 @@ type DeploymentSpec struct {
// Label selector for pods. Existing ReplicationControllers whose pods are
// selected by this will be scaled down. New ReplicationControllers will be
// created with this selector, with a unique label as defined by UniqueLabelKey.
// created with this selector, with a unique label `pod-template-hash`.
// If Selector is empty, it is defaulted to the labels present on the Pod template.
Selector map[string]string
@ -80,15 +80,6 @@ type DeploymentSpec struct {
// The deployment strategy to use to replace existing pods with new ones.
Strategy DeploymentStrategy
// 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.
UniqueLabelKey *string
}
type DeploymentStrategy struct {
@ -170,7 +161,7 @@ For each pending deployment, it will:
selector to all these RCs (and the corresponding label to their pods) to ensure
that they do not select the newly created pods (or old pods get selected by
new RC).
- The label key will be "deployment.kubernetes.io/podTemplateHash".
- The label key will be "pod-template-hash".
- The label value will be hash of the podTemplateSpec for that RC without
this label. This value will be unique for all RCs, since PodTemplateSpec should be unique.
- If the RCs and pods dont already have this label and selector:
@ -178,10 +169,10 @@ For each pending deployment, it will:
ensure that all new pods that they create will have this label.
- Then we will add this label to their existing pods and then add this as a selector
to that RC.
3. Find if there exists an RC for which value of "deployment.kubernetes.io/podTemplateHash" label
3. Find if there exists an RC for which value of "pod-template-hash" label
is same as hash of DeploymentSpec.PodTemplateSpec. If it exists already, then
this is the RC that will be ramped up. If there is no such RC, then we create
a new one using DeploymentSpec and then add a "deployment.kubernetes.io/podTemplateHash" label
a new one using DeploymentSpec and then add a "pod-template-hash" label
to it. RCSpec.replicas = 0 for a newly created RC.
4. Scale up the new RC and scale down the olds ones as per the DeploymentStrategy.
- Raise an event if we detect an error, like new pods failing to come up.

View File

@ -47,7 +47,6 @@ Documentation for other releases can be found at
- [Pod Template](#pod-template)
- [Replicas](#replicas)
- [Selector](#selector)
- [Unique Label Key](#unique-label-key)
- [Strategy](#strategy)
- [Recreate Deployment](#recreate-deployment)
- [Rolling Update Deployment](#rolling-update-deployment)
@ -153,7 +152,7 @@ Running ```kubectl get rc``` and ```kubectl get pods``` will show the replicatio
$ kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE
REPLICAS AGE
deploymentrc-1975012602 nginx nginx:1.7.9 deployment.kubernetes.io/podTemplateHash=1975012602,app=nginx 3 2m
deploymentrc-1975012602 nginx nginx:1.7.9 pod-template-hash=1975012602,app=nginx 3 2m
```
```console
@ -237,8 +236,8 @@ which it scaled up to 3 replicas, and has scaled down the old RC to 0 replicas.
```console
kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE
deploymentrc-1562004724 nginx nginx:1.9.1 deployment.kubernetes.io/podTemplateHash=1562004724,app=nginx 3 5m
deploymentrc-1975012602 nginx nginx:1.7.9 deployment.kubernetes.io/podTemplateHash=1975012602,app=nginx 0 7m
deploymentrc-1562004724 nginx nginx:1.9.1 pod-template-hash=1562004724,app=nginx 3 5m
deploymentrc-1975012602 nginx nginx:1.7.9 pod-template-hash=1975012602,app=nginx 0 7m
```
Running `get pods` should now show only the new pods:
@ -335,17 +334,6 @@ template is different than `.spec.template` or if the total number of such pods
exceeds `.spec.replicas`. It will bring up new pods with `.spec.template` if
number of pods are less than the desired number.
### Unique Label Key
`.spec.uniqueLabelKey` is an optional field specifying 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, the system uses
`deployment.kubernetes.io/podTemplateHash`.
The value of this key is the hash of `.spec.template`.
No label is added if this is set to the empty string.
### Strategy
`.spec.strategy` specifies the strategy used to replace old pods by new ones.

View File

@ -678,7 +678,7 @@ runTests() {
kube::test::get_object_assert deployment "{{range.items}}{{$id_field}}:{{end}}" 'nginx:'
# Clean up
kubectl delete deployment nginx "${kube_flags[@]}"
kubectl delete rc -l deployment.kubernetes.io/podTemplateHash "${kube_flags[@]}"
kubectl delete rc -l pod-template-hash "${kube_flags[@]}"
##############
# Namespaces #
@ -1102,7 +1102,7 @@ __EOF__
# Clean up
kubectl delete hpa nginx-deployment "${kube_flags[@]}"
kubectl delete deployment nginx-deployment "${kube_flags[@]}"
kubectl delete rc -l deployment.kubernetes.io/podTemplateHash "${kube_flags[@]}"
kubectl delete rc -l pod-template-hash "${kube_flags[@]}"
### Rollback a deployment
# Pre-condition: no deployment exists
@ -1131,7 +1131,7 @@ __EOF__
kube::test::get_object_assert deployment "{{range.items}}{{$deployment_image_field}}:{{end}}" 'nginx:latest:'
# Clean up
kubectl delete deployment nginx-deployment "${kube_flags[@]}"
kubectl delete rc -l deployment.kubernetes.io/podTemplateHash "${kube_flags[@]}"
kubectl delete rc -l pod-template-hash "${kube_flags[@]}"
######################
# ConfigMap #

File diff suppressed because it is too large Load Diff

View File

@ -252,16 +252,6 @@ type DeploymentSpec struct {
// This is a pointer to distinguish between explicit zero and not specified.
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
// deployment controller.
Paused bool `json:"paused,omitempty"`
@ -288,9 +278,8 @@ type RollbackConfig struct {
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"
// to select new pods (and old pods being select by new RC).
DefaultDeploymentUniqueLabelKey string = "pod-template-hash"
)
type DeploymentStrategy struct {

View File

@ -121,8 +121,6 @@ func Convert_extensions_DeploymentSpec_To_v1beta1_DeploymentSpec(in *extensions.
out.RevisionHistoryLimit = new(int32)
*out.RevisionHistoryLimit = int32(*in.RevisionHistoryLimit)
}
out.UniqueLabelKey = new(string)
*out.UniqueLabelKey = in.UniqueLabelKey
out.MinReadySeconds = int32(in.MinReadySeconds)
out.Paused = in.Paused
if in.RollbackTo != nil {
@ -159,9 +157,6 @@ func Convert_v1beta1_DeploymentSpec_To_extensions_DeploymentSpec(in *DeploymentS
out.RevisionHistoryLimit = new(int)
*out.RevisionHistoryLimit = int(*in.RevisionHistoryLimit)
}
if in.UniqueLabelKey != nil {
out.UniqueLabelKey = *in.UniqueLabelKey
}
out.MinReadySeconds = int(in.MinReadySeconds)
out.Paused = in.Paused
if in.RollbackTo != nil {

View File

@ -2830,9 +2830,6 @@ func autoConvert_extensions_DeploymentSpec_To_v1beta1_DeploymentSpec(in *extensi
} else {
out.RevisionHistoryLimit = nil
}
if err := api.Convert_string_To_string_ref(&in.UniqueLabelKey, &out.UniqueLabelKey, s); err != nil {
return err
}
out.Paused = in.Paused
// unable to generate simple pointer conversion for extensions.RollbackConfig -> v1beta1.RollbackConfig
if in.RollbackTo != nil {
@ -4148,9 +4145,6 @@ func autoConvert_v1beta1_DeploymentSpec_To_extensions_DeploymentSpec(in *Deploym
} else {
out.RevisionHistoryLimit = nil
}
if err := api.Convert_string_ref_To_string(&in.UniqueLabelKey, &out.UniqueLabelKey, s); err != nil {
return err
}
out.Paused = in.Paused
// unable to generate simple pointer conversion for v1beta1.RollbackConfig -> extensions.RollbackConfig
if in.RollbackTo != nil {

View File

@ -1190,12 +1190,6 @@ func deepCopy_v1beta1_DeploymentSpec(in DeploymentSpec, out *DeploymentSpec, c *
} else {
out.RevisionHistoryLimit = nil
}
if in.UniqueLabelKey != nil {
out.UniqueLabelKey = new(string)
*out.UniqueLabelKey = *in.UniqueLabelKey
} else {
out.UniqueLabelKey = nil
}
out.Paused = in.Paused
if in.RollbackTo != nil {
out.RollbackTo = new(RollbackConfig)

View File

@ -100,10 +100,6 @@ func addDefaultingFuncs(scheme *runtime.Scheme) {
strategy.RollingUpdate.MaxSurge = &maxSurge
}
}
if obj.Spec.UniqueLabelKey == nil {
obj.Spec.UniqueLabelKey = new(string)
*obj.Spec.UniqueLabelKey = DefaultDeploymentUniqueLabelKey
}
},
func(obj *Job) {
labels := obj.Spec.Template.Labels

View File

@ -198,7 +198,6 @@ func TestSetDefaultDaemonSet(t *testing.T) {
func TestSetDefaultDeployment(t *testing.T) {
defaultIntOrString := intstr.FromInt(1)
differentIntOrString := intstr.FromInt(5)
deploymentLabelKey := DefaultDeploymentUniqueLabelKey
period := int64(v1.DefaultTerminationGracePeriodSeconds)
defaultTemplate := v1.PodTemplateSpec{
Spec: v1.PodSpec{
@ -224,8 +223,7 @@ func TestSetDefaultDeployment(t *testing.T) {
MaxUnavailable: &defaultIntOrString,
},
},
Template: defaultTemplate,
UniqueLabelKey: newString(deploymentLabelKey),
Template: defaultTemplate,
},
},
},
@ -250,8 +248,7 @@ func TestSetDefaultDeployment(t *testing.T) {
MaxUnavailable: &defaultIntOrString,
},
},
Template: defaultTemplate,
UniqueLabelKey: newString(deploymentLabelKey),
Template: defaultTemplate,
},
},
},
@ -270,8 +267,7 @@ func TestSetDefaultDeployment(t *testing.T) {
Strategy: DeploymentStrategy{
Type: RecreateDeploymentStrategyType,
},
Template: defaultTemplate,
UniqueLabelKey: newString(deploymentLabelKey),
Template: defaultTemplate,
},
},
},
@ -282,7 +278,6 @@ func TestSetDefaultDeployment(t *testing.T) {
Strategy: DeploymentStrategy{
Type: RecreateDeploymentStrategyType,
},
UniqueLabelKey: newString("customDeploymentKey"),
},
},
expected: &Deployment{
@ -291,8 +286,7 @@ func TestSetDefaultDeployment(t *testing.T) {
Strategy: DeploymentStrategy{
Type: RecreateDeploymentStrategyType,
},
Template: defaultTemplate,
UniqueLabelKey: newString("customDeploymentKey"),
Template: defaultTemplate,
},
},
},

File diff suppressed because it is too large Load Diff

View File

@ -237,16 +237,6 @@ type DeploymentSpec struct {
// This is a pointer to distinguish between explicit zero and not specified.
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
// deployment controller.
Paused bool `json:"paused,omitempty"`
@ -273,9 +263,8 @@ type RollbackConfig struct {
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"
// to select new pods (and old pods being select by new RC).
DefaultDeploymentUniqueLabelKey string = "pod-template-hash"
)
// DeploymentStrategy describes how to replace existing pods with new ones.

View File

@ -186,7 +186,6 @@ var map_DeploymentSpec = map[string]string{
"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)",
"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.",
"rollbackTo": "The config this deployment is rolling back to. Will be cleared after rollback is done.",
}

View File

@ -328,10 +328,6 @@ func ValidateDeploymentSpec(spec *extensions.DeploymentSpec, fldPath *field.Path
// zero is a valid 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 {
allErrs = append(allErrs, ValidateRollback(spec.RollbackTo, fldPath.Child("rollback"))...)
}

View File

@ -872,7 +872,6 @@ func validDeployment() *extensions.Deployment {
},
},
},
UniqueLabelKey: "my-label",
RollbackTo: &extensions.RollbackConfig{
Revision: 1,
},
@ -908,11 +907,6 @@ func TestValidateDeployment(t *testing.T) {
invalidRestartPolicyDeployment.Spec.Template.Spec.RestartPolicy = api.RestartPolicyNever
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.
invalidRecreateDeployment := validDeployment()
invalidRecreateDeployment.Spec.Strategy = extensions.DeploymentStrategy{

View File

@ -695,8 +695,8 @@ func (dc *DeploymentController) getNewRC(deployment extensions.Deployment, maxOl
namespace := deployment.ObjectMeta.Namespace
podTemplateSpecHash := podutil.GetPodTemplateSpecHash(deployment.Spec.Template)
newRCTemplate := deploymentutil.GetNewRCTemplate(deployment)
// Add podTemplateHash label to selector.
newRCSelector := labelsutil.CloneAndAddLabel(deployment.Spec.Selector, deployment.Spec.UniqueLabelKey, podTemplateSpecHash)
// Add pod-template-hash label to selector.
newRCSelector := labelsutil.CloneAndAddLabel(deployment.Spec.Selector, extensions.DefaultDeploymentUniqueLabelKey, podTemplateSpecHash)
// Set RC expectations (1 rc should be created)
dKey, err = controller.KeyFunc(&deployment)

View File

@ -110,7 +110,6 @@ func (DeploymentV1Beta1) Generate(genericParams map[string]interface{}) (runtime
},
Spec: *podSpec,
},
UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey,
},
}
return &deployment, nil

View File

@ -655,9 +655,8 @@ func TestGenerateDeployment(t *testing.T) {
Labels: map[string]string{"foo": "bar", "baz": "blah"},
},
Spec: extensions.DeploymentSpec{
Replicas: 3,
Selector: map[string]string{"foo": "bar", "baz": "blah"},
UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey,
Replicas: 3,
Selector: map[string]string{"foo": "bar", "baz": "blah"},
Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: map[string]string{"foo": "bar", "baz": "blah"},

View File

@ -67,8 +67,7 @@ func validNewDeployment() *extensions.Deployment {
DNSPolicy: api.DNSClusterFirst,
},
},
UniqueLabelKey: "my-label",
Replicas: 7,
Replicas: 7,
},
Status: extensions.DeploymentStatus{
Replicas: 5,

View File

@ -138,7 +138,7 @@ func GetNewRCTemplate(deployment extensions.Deployment) api.PodTemplateSpec {
}
newRCTemplate.ObjectMeta.Labels = labelsutil.CloneAndAddLabel(
deployment.Spec.Template.ObjectMeta.Labels,
deployment.Spec.UniqueLabelKey,
extensions.DefaultDeploymentUniqueLabelKey,
podutil.GetPodTemplateSpecHash(newRCTemplate))
return newRCTemplate
}
@ -149,7 +149,7 @@ func SetFromRCTemplate(deployment *extensions.Deployment, template api.PodTempla
deployment.Spec.Template.Spec = template.Spec
deployment.Spec.Template.ObjectMeta.Labels = labelsutil.CloneAndRemoveLabel(
deployment.Spec.Template.ObjectMeta.Labels,
deployment.Spec.UniqueLabelKey)
extensions.DefaultDeploymentUniqueLabelKey)
return deployment
}

View File

@ -159,9 +159,8 @@ func generateDeployment(image string) extensions.Deployment {
Name: image,
},
Spec: extensions.DeploymentSpec{
Replicas: 1,
Selector: podLabels,
UniqueLabelKey: "deployment.kubernetes.io/podTemplateHash",
Replicas: 1,
Selector: podLabels,
Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: podLabels,

View File

@ -101,7 +101,6 @@ func newDeployment(deploymentName string, replicas int, podLabels map[string]str
Type: strategyType,
},
RevisionHistoryLimit: revisionHistoryLimit,
UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey,
Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: podLabels,

View File

@ -1527,7 +1527,6 @@ func (config *DeploymentConfig) create() error {
Selector: map[string]string{
"name": config.Name,
},
UniqueLabelKey: extensions.DefaultDeploymentUniqueLabelKey,
Template: api.PodTemplateSpec{
ObjectMeta: api.ObjectMeta{
Labels: map[string]string{"name": config.Name},