Skip to content

Commit

Permalink
Move Deployment to ReplicaSet, Merge with another branch: deployment-…
Browse files Browse the repository at this point in the history
…pod-selector, Initial changes for Deployment object pod selector, Changes to scale object, Error strings fix, e2e and everything else, Fix tests, Rebase fixes, Fix tests, Add replicaset to registry.
  • Loading branch information
madhusudancs committed Dec 23, 2015
1 parent 61d171a commit d4ee9a0
Show file tree
Hide file tree
Showing 50 changed files with 4,004 additions and 353 deletions.
11 changes: 11 additions & 0 deletions cmd/kube-controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
persistentvolumecontroller "k8s.io/kubernetes/pkg/controller/persistentvolume"
"k8s.io/kubernetes/pkg/controller/podautoscaler"
"k8s.io/kubernetes/pkg/controller/podautoscaler/metrics"
replicaset "k8s.io/kubernetes/pkg/controller/replicaset"
replicationcontroller "k8s.io/kubernetes/pkg/controller/replication"
resourcequotacontroller "k8s.io/kubernetes/pkg/controller/resourcequota"
routecontroller "k8s.io/kubernetes/pkg/controller/route"
Expand All @@ -71,6 +72,7 @@ type CMServer struct {
CloudConfigFile string
ConcurrentEndpointSyncs int
ConcurrentRCSyncs int
ConcurrentRSSyncs int
ConcurrentDSCSyncs int
ConcurrentJobSyncs int
ConcurrentResourceQuotaSyncs int
Expand Down Expand Up @@ -114,6 +116,7 @@ func NewCMServer() *CMServer {
Address: net.ParseIP("127.0.0.1"),
ConcurrentEndpointSyncs: 5,
ConcurrentRCSyncs: 5,
ConcurrentRSSyncs: 5,
ConcurrentDSCSyncs: 2,
ConcurrentJobSyncs: 5,
ConcurrentResourceQuotaSyncs: 5,
Expand Down Expand Up @@ -190,6 +193,7 @@ func (s *CMServer) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")
fs.IntVar(&s.ConcurrentEndpointSyncs, "concurrent-endpoint-syncs", s.ConcurrentEndpointSyncs, "The number of endpoint syncing operations that will be done concurrently. Larger number = faster endpoint updating, but more CPU (and network) load")
fs.IntVar(&s.ConcurrentRCSyncs, "concurrent_rc_syncs", s.ConcurrentRCSyncs, "The number of replication controllers that are allowed to sync concurrently. Larger number = more reponsive replica management, but more CPU (and network) load")
fs.IntVar(&s.ConcurrentRSSyncs, "concurrent_replicaset_syncs", s.ConcurrentRSSyncs, "The number of ReplicaSets that are allowed to sync concurrently. Larger number = more reponsive replica management, but more CPU (and network) load")
fs.IntVar(&s.ConcurrentResourceQuotaSyncs, "concurrent-resource-quota-syncs", s.ConcurrentResourceQuotaSyncs, "The number of resource quotas that are allowed to sync concurrently. Larger number = more responsive quota management, but more CPU (and network) load")
fs.IntVar(&s.ConcurrentDeploymentSyncs, "concurrent-deployment-syncs", s.ConcurrentDeploymentSyncs, "The number of deployment objects that are allowed to sync concurrently. Larger number = more reponsive deployments, but more CPU (and network) load")
fs.DurationVar(&s.ServiceSyncPeriod, "service-sync-period", s.ServiceSyncPeriod, "The period for syncing services with their external load balancers")
Expand Down Expand Up @@ -389,6 +393,13 @@ func (s *CMServer) Run(_ []string) error {
go deployment.NewDeploymentController(clientForUserAgentOrDie(*kubeconfig, "deployment-controller"), s.ResyncPeriod).
Run(s.ConcurrentDeploymentSyncs, util.NeverStop)
}

if containsResource(resources, "replicasets") {
glog.Infof("Starting ReplicaSet controller")
go replicaset.NewReplicaSetController(kubeClient, s.ResyncPeriod, replicaset.BurstReplicas).
Run(s.ConcurrentRSSyncs, util.NeverStop)
}

}

volumePlugins := ProbeRecyclableVolumePlugins(s.VolumeConfigFlags)
Expand Down
3 changes: 2 additions & 1 deletion examples/extensions/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ metadata:
spec:
replicas: 3
selector:
name: nginx
matchLabels:
name: nginx
template:
metadata:
labels:
Expand Down
16 changes: 16 additions & 0 deletions pkg/apis/extensions/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,19 @@ func ScaleFromDeployment(deployment *Deployment) *Scale {
},
}
}

// SetAsLabelSelector converts the labels.Set object into a LabelSelector api object.
func SetAsLabelSelector(ls labels.Set) *LabelSelector {
if ls == nil {
return nil
}

selector := &LabelSelector{
MatchLabels: make(map[string]string),
}
for label, value := range ls {
selector.MatchLabels[label] = value
}

return selector
}
4 changes: 2 additions & 2 deletions pkg/apis/extensions/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ func (obj *Ingress) GetObjectKind() unversioned.ObjectKind {
func (obj *IngressList) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
func (obj *ConfigMap) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
func (obj *ConfigMapList) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
func (*ReplicaSet) IsAnAPIObject() { return &obj.TypeMeta }
func (*ReplicaSetList) IsAnAPIObject() { return &obj.TypeMeta }
func (obj *ReplicaSet) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
func (obj *ReplicaSetList) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
14 changes: 7 additions & 7 deletions pkg/apis/extensions/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type ScaleStatus struct {
Replicas int `json:"replicas"`

// label query over pods that should match the replicas count. More info: http://releases.k8s.io/HEAD/docs/user-guide/labels.md#label-selectors
Selector map[string]string `json:"selector,omitempty"`
Selector *LabelSelector `json:"selector,omitempty"`
}

// represents a scaling request for a resource.
Expand Down Expand Up @@ -207,19 +207,19 @@ type DeploymentSpec struct {
// zero and not specified. Defaults to 1.
Replicas int `json:"replicas,omitempty"`

// Label selector for pods. Existing ReplicationControllers whose pods are
// Label selector for pods. Existing ReplicaSets whose pods are
// selected by this will be the ones affected by this deployment.
Selector map[string]string `json:"selector,omitempty"`
Selector *LabelSelector `json:"selector,omitempty"`

// Template describes the pods that will be created.
Template api.PodTemplateSpec `json:"template"`

// The deployment strategy to use to replace existing pods with new ones.
Strategy DeploymentStrategy `json:"strategy,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).
// Key of the selector that is added to existing ReplicaSets (and label key that
// is added to its pods) to prevent the existing ReplicaSets to select new pods
// (and old pods being selected by new ReplicaSet).
// 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").
Expand Down Expand Up @@ -762,7 +762,7 @@ type ReplicaSetSpec struct {
Replicas int `json:"replicas"`

// Selector is a label query over pods that should match the Replicas count.
Selector *PodSelector `json:"selector,omitempty"`
Selector *LabelSelector `json:"selector,omitempty"`

// TemplateRef is a reference to an object that describes the pod that will be created if
// insufficient replicas are detected. This reference is ignored if a Template is set.
Expand Down
21 changes: 11 additions & 10 deletions pkg/apis/extensions/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ func convert_extensions_DeploymentSpec_To_v1beta1_DeploymentSpec(in *extensions.
out.Replicas = new(int32)
*out.Replicas = int32(in.Replicas)
if in.Selector != nil {
out.Selector = make(map[string]string)
for key, val := range in.Selector {
out.Selector[key] = val
out.Selector = new(LabelSelector)
if err := convert_extensions_LabelSelector_To_v1beta1_LabelSelector(in.Selector, out.Selector, s); err != nil {
return err
}
} else {
out.Selector = nil
Expand All @@ -233,10 +233,11 @@ func convert_v1beta1_DeploymentSpec_To_extensions_DeploymentSpec(in *DeploymentS
if in.Replicas != nil {
out.Replicas = int(*in.Replicas)
}

if in.Selector != nil {
out.Selector = make(map[string]string)
for key, val := range in.Selector {
out.Selector[key] = val
out.Selector = new(extensions.LabelSelector)
if err := convert_v1beta1_LabelSelector_To_extensions_LabelSelector(in.Selector, out.Selector, s); err != nil {
return err
}
} else {
out.Selector = nil
Expand Down Expand Up @@ -396,8 +397,8 @@ func convert_extensions_ReplicaSetSpec_To_v1beta1_ReplicaSetSpec(in *extensions.
out.Replicas = new(int)
*out.Replicas = in.Replicas
if in.Selector != nil {
out.Selector = new(PodSelector)
if err := convert_extensions_PodSelector_To_v1beta1_PodSelector(in.Selector, out.Selector, s); err != nil {
out.Selector = new(LabelSelector)
if err := convert_extensions_LabelSelector_To_v1beta1_LabelSelector(in.Selector, out.Selector, s); err != nil {
return err
}
} else {
Expand All @@ -420,8 +421,8 @@ func convert_v1beta1_ReplicaSetSpec_To_extensions_ReplicaSetSpec(in *ReplicaSetS
}
out.Replicas = *in.Replicas
if in.Selector != nil {
out.Selector = new(extensions.PodSelector)
if err := convert_v1beta1_PodSelector_To_extensions_PodSelector(in.Selector, out.Selector, s); err != nil {
out.Selector = new(extensions.LabelSelector)
if err := convert_v1beta1_LabelSelector_To_extensions_LabelSelector(in.Selector, out.Selector, s); err != nil {
return err
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/extensions/v1beta1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func addDefaultingFuncs() {
labels := obj.Spec.Template.Labels

if labels != nil {
if len(obj.Spec.Selector) == 0 {
obj.Spec.Selector = labels
if obj.Spec.Selector == nil {
obj.Spec.Selector = &LabelSelector{MatchLabels: labels}
}
if len(obj.Labels) == 0 {
obj.Labels = labels
Expand Down Expand Up @@ -131,7 +131,7 @@ func addDefaultingFuncs() {
// TODO: support templates defined elsewhere when we support them in the API
if labels != nil {
if obj.Spec.Selector == nil {
obj.Spec.Selector = &PodSelector{
obj.Spec.Selector = &LabelSelector{
MatchLabels: labels,
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/extensions/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ func (obj *IngressList) GetObjectKind() unversioned.ObjectKind {
func (obj *ListOptions) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
func (obj *ConfigMap) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
func (obj *ConfigMapList) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
func (*ReplicaSet) IsAnAPIObject() { return &obj.TypeMeta }
func (*ReplicaSetList) IsAnAPIObject() { return &obj.TypeMeta }
func (obj *ReplicaSet) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
func (obj *ReplicaSetList) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
6 changes: 3 additions & 3 deletions pkg/apis/extensions/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type ScaleStatus struct {
Replicas int32 `json:"replicas"`

// label query over pods that should match the replicas count. More info: http://releases.k8s.io/HEAD/docs/user-guide/labels.md#label-selectors
Selector map[string]string `json:"selector,omitempty"`
Selector *LabelSelector `json:"selector,omitempty"`
}

// represents a scaling request for a resource.
Expand Down Expand Up @@ -196,7 +196,7 @@ type DeploymentSpec struct {

// Label selector for pods. Existing ReplicaSets whose pods are
// selected by this will be the ones affected by this deployment.
Selector map[string]string `json:"selector,omitempty"`
Selector *LabelSelector `json:"selector,omitempty"`

// Template describes the pods that will be created.
Template v1.PodTemplateSpec `json:"template"`
Expand Down Expand Up @@ -804,7 +804,7 @@ type ReplicaSetSpec struct {
// Label keys and values that must match in order to be controlled by this replication
// controller, if empty defaulted to labels on Pod template.
// More info: http://releases.k8s.io/HEAD/docs/user-guide/labels.md#label-selectors
Selector *PodSelector `json:"selector,omitempty"`
Selector *LabelSelector `json:"selector,omitempty"`

// TemplateRef is a reference to an object that describes the pod that will be created if
// insufficient replicas are detected.
Expand Down
Loading

0 comments on commit d4ee9a0

Please sign in to comment.