Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPSTREAM: <carry>: openshift: Implement scale from zero #137

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,13 @@ func (c *machineController) machineSetNodeGroups() ([]*nodegroup, error) {
if err != nil {
return err
}
if ng.MaxSize()-ng.MinSize() > 0 && pointer.Int32PtrDerefOr(machineSet.Spec.Replicas, 0) > 0 {
nodegroups = append(nodegroups, ng)

if ng.MaxSize()-ng.MinSize() > 0 {
if ng.scalableResource.CanScaleFromZero() {
nodegroups = append(nodegroups, ng)
} else if pointer.Int32PtrDerefOr(machineSet.Spec.Replicas, 0) > 0 {
nodegroups = append(nodegroups, ng)
}
}
return nil
}); err != nil {
Expand All @@ -496,8 +501,12 @@ func (c *machineController) machineDeploymentNodeGroups() ([]*nodegroup, error)
return nil, err
}
// add nodegroup iff it has the capacity to scale
if ng.MaxSize()-ng.MinSize() > 0 && pointer.Int32PtrDerefOr(md.Spec.Replicas, 0) > 0 {
nodegroups = append(nodegroups, ng)
if ng.MaxSize()-ng.MinSize() > 0 {
if ng.scalableResource.CanScaleFromZero() {
nodegroups = append(nodegroups, ng)
} else if pointer.Int32PtrDerefOr(md.Spec.Replicas, 0) > 0 {
nodegroups = append(nodegroups, ng)
}
}
}

Expand Down Expand Up @@ -551,9 +560,6 @@ func (c *machineController) nodeGroupForNode(node *corev1.Node) (*nodegroup, err
if err != nil {
return nil, fmt.Errorf("failed to build nodegroup for node %q: %v", node.Name, err)
}
// We don't scale from 0 so nodes must belong
// to a nodegroup that has a scale size of at
// least 1.
if nodegroup.MaxSize()-nodegroup.MinSize() < 1 {
return nil, nil
}
Expand All @@ -566,8 +572,6 @@ func (c *machineController) nodeGroupForNode(node *corev1.Node) (*nodegroup, err
return nil, fmt.Errorf("failed to build nodegroup for node %q: %v", node.Name, err)
}

// We don't scale from 0 so nodes must belong to a nodegroup
// that has a scale size of at least 1.
if nodegroup.MaxSize()-nodegroup.MinSize() < 1 {
return nil, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,38 @@ limitations under the License.
package clusterapi

import (
"time"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/utils/pointer"
)

func newTaintFromInterface(t interface{}) corev1.Taint {
taint := corev1.Taint{}
if tt, ok := t.(map[string]interface{}); ok {
if tmap, found, _ := unstructured.NestedMap(tt); found {
if val, ok := tmap["key"].(string); ok {
taint.Key = val
}
if val, ok := tmap["effect"].(string); ok {
taint.Effect = corev1.TaintEffect(val)
}
if val, ok := tmap["value"].(string); ok {
taint.Value = val
}
if val, ok := tmap["timeAdded"].(string); ok {
ta := time.Time{}
ta.UnmarshalText([]byte(val))
nta := metav1.NewTime(ta)
taint.TimeAdded = &nta
}
}
}
return taint
}

func newMachineDeploymentFromUnstructured(u *unstructured.Unstructured) *MachineDeployment {
machineDeployment := MachineDeployment{
TypeMeta: metav1.TypeMeta{
Expand All @@ -42,6 +68,20 @@ func newMachineDeploymentFromUnstructured(u *unstructured.Unstructured) *Machine
Status: MachineDeploymentStatus{},
}

machineSpec, found, err := unstructured.NestedMap(u.Object, "spec", "template", "spec")
elmiko marked this conversation as resolved.
Show resolved Hide resolved
if err == nil && found {
machineSpecUnstructured := unstructured.Unstructured{Object: machineSpec}
machineDeployment.Spec.Template.Spec.Labels = machineSpecUnstructured.GetLabels()
taints, _, _ := unstructured.NestedSlice(machineSpec, "taints")
if taints != nil {
taintobjlist := make([]corev1.Taint, len(taints))
for i, t := range taints {
taintobjlist[i] = newTaintFromInterface(t)
}
machineDeployment.Spec.Template.Spec.Taints = taintobjlist
}
}

replicas, found, err := unstructured.NestedInt64(u.Object, "spec", "replicas")
if err == nil && found {
machineDeployment.Spec.Replicas = pointer.Int32Ptr(int32(replicas))
Expand Down Expand Up @@ -69,6 +109,20 @@ func newMachineSetFromUnstructured(u *unstructured.Unstructured) *MachineSet {
Status: MachineSetStatus{},
}

machineSpec, found, err := unstructured.NestedMap(u.Object, "spec", "template", "spec")
if err == nil && found {
machineSpecUnstructured := unstructured.Unstructured{Object: machineSpec}
machineSet.Spec.Template.Spec.Labels = machineSpecUnstructured.GetLabels()
taints, _, _ := unstructured.NestedSlice(machineSpec, "taints")
if taints != nil {
taintobjlist := make([]corev1.Taint, len(taints))
for i, t := range taints {
taintobjlist[i] = newTaintFromInterface(t)
}
machineSet.Spec.Template.Spec.Taints = taintobjlist
}
}

replicas, found, err := unstructured.NestedInt64(u.Object, "spec", "replicas")
if err == nil && found {
machineSet.Spec.Replicas = pointer.Int32Ptr(int32(replicas))
Expand Down