mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 03:38:15 +00:00 
			
		
		
		
	Fixing the selector for new RC created by deployment
This commit is contained in:
		@@ -140,6 +140,9 @@ func (d *DeploymentController) getNewRC(deployment extensions.Deployment) (*api.
 | 
				
			|||||||
	podTemplateSpecHash := deploymentUtil.GetPodTemplateSpecHash(deployment.Spec.Template)
 | 
						podTemplateSpecHash := deploymentUtil.GetPodTemplateSpecHash(deployment.Spec.Template)
 | 
				
			||||||
	rcName := fmt.Sprintf("deploymentrc-%d", podTemplateSpecHash)
 | 
						rcName := fmt.Sprintf("deploymentrc-%d", podTemplateSpecHash)
 | 
				
			||||||
	newRCTemplate := deploymentUtil.GetNewRCTemplate(deployment)
 | 
						newRCTemplate := deploymentUtil.GetNewRCTemplate(deployment)
 | 
				
			||||||
 | 
						// Add podTemplateHash label to selector.
 | 
				
			||||||
 | 
						newRCSelector := deploymentUtil.CloneAndAddLabel(deployment.Spec.Selector, deployment.Spec.UniqueLabelKey, podTemplateSpecHash)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	newRC := api.ReplicationController{
 | 
						newRC := api.ReplicationController{
 | 
				
			||||||
		ObjectMeta: api.ObjectMeta{
 | 
							ObjectMeta: api.ObjectMeta{
 | 
				
			||||||
			Name:      rcName,
 | 
								Name:      rcName,
 | 
				
			||||||
@@ -147,7 +150,7 @@ func (d *DeploymentController) getNewRC(deployment extensions.Deployment) (*api.
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
		Spec: api.ReplicationControllerSpec{
 | 
							Spec: api.ReplicationControllerSpec{
 | 
				
			||||||
			Replicas: 0,
 | 
								Replicas: 0,
 | 
				
			||||||
			Selector: newRCTemplate.ObjectMeta.Labels,
 | 
								Selector: newRCSelector,
 | 
				
			||||||
			Template: newRCTemplate,
 | 
								Template: newRCTemplate,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -90,16 +90,27 @@ func GetNewRCTemplate(deployment extensions.Deployment) *api.PodTemplateSpec {
 | 
				
			|||||||
		ObjectMeta: deployment.Spec.Template.ObjectMeta,
 | 
							ObjectMeta: deployment.Spec.Template.ObjectMeta,
 | 
				
			||||||
		Spec:       deployment.Spec.Template.Spec,
 | 
							Spec:       deployment.Spec.Template.Spec,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	podTemplateSpecHash := GetPodTemplateSpecHash(newRCTemplate)
 | 
						newRCTemplate.ObjectMeta.Labels = CloneAndAddLabel(
 | 
				
			||||||
	if deployment.Spec.UniqueLabelKey != "" {
 | 
							deployment.Spec.Template.ObjectMeta.Labels,
 | 
				
			||||||
 | 
							deployment.Spec.UniqueLabelKey,
 | 
				
			||||||
 | 
							GetPodTemplateSpecHash(newRCTemplate))
 | 
				
			||||||
 | 
						return newRCTemplate
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Clones the given map and returns a new map with the given key and value added.
 | 
				
			||||||
 | 
					// Returns the given map, if labelKey is empty.
 | 
				
			||||||
 | 
					func CloneAndAddLabel(labels map[string]string, labelKey string, labelValue uint32) map[string]string {
 | 
				
			||||||
 | 
						if labelKey == "" {
 | 
				
			||||||
 | 
							// Dont need to add a label.
 | 
				
			||||||
 | 
							return labels
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// Clone.
 | 
				
			||||||
	newLabels := map[string]string{}
 | 
						newLabels := map[string]string{}
 | 
				
			||||||
		for key, value := range deployment.Spec.Template.ObjectMeta.Labels {
 | 
						for key, value := range labels {
 | 
				
			||||||
		newLabels[key] = value
 | 
							newLabels[key] = value
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		newLabels[deployment.Spec.UniqueLabelKey] = fmt.Sprintf("%d", podTemplateSpecHash)
 | 
						newLabels[labelKey] = fmt.Sprintf("%d", labelValue)
 | 
				
			||||||
		newRCTemplate.ObjectMeta.Labels = newLabels
 | 
						return newLabels
 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return newRCTemplate
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func GetPodTemplateSpecHash(template *api.PodTemplateSpec) uint32 {
 | 
					func GetPodTemplateSpecHash(template *api.PodTemplateSpec) uint32 {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user