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

[OCPCLOUD-778] Add support for autoscaling to/from zero #112

Merged

Conversation

JoelSpeed
Copy link

What this PR does / why we need it:

This PR adds a new controller to annotate machinesets with information required to enable autoscaling to/from zero

I haven't tested this yet on a real cluster so will look into doing that

I also haven't added any tests for the controller as whole, happy to add some envtest style tests if that would be useful

@openshift-ci-robot openshift-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Mar 9, 2020
@@ -9,6 +9,7 @@ require (
github.com/Azure/go-autorest/autorest/to v0.3.0
github.com/Azure/go-autorest/autorest/validation v0.2.0 // indirect
github.com/ghodss/yaml v1.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be in the vendor commit?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


// This file was copied from
// https://github.com/openshift/kubernetes-autoscaler/blob/95d5f0927b9347635f1720d6748503415e6921cb/cluster-autoscaler/cloudprovider/azure/azure_instance_types.go
// // https://github.com/kubernetes/kubernetes/issues/79384
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra "//"?

@enxebre
Copy link
Member

enxebre commented Mar 10, 2020

can we update all commits to UPSTREAM: <carry>: openshift: blah

@enxebre
Copy link
Member

enxebre commented Mar 10, 2020

units won't pass since there's nothing setting up the environment for envTest yet

}, nil
}

func providerSpecFromMachine(in *machineproviderv1.AzureMachineProviderSpec) (machinev1.ProviderSpec, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any exported method in the actuator machine controller we can reuse for this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exported, but it does already exist in the tests

func providerSpecFromMachine(in *machineproviderv1.AzureMachineProviderSpec) (*machinev1.ProviderSpec, error) {
bytes, err := json.Marshal(in)
if err != nil {
return nil, err
}
return &machinev1.ProviderSpec{
Value: &runtime.RawExtension{Raw: bytes},
}, nil
}
and
func providerSpecFromMachine(in *machineproviderv1.AzureMachineProviderSpec) (*machinev1.ProviderSpec, error) {
bytes, err := yaml.Marshal(in)
if err != nil {
return nil, err
}
return &machinev1.ProviderSpec{
Value: &runtime.RawExtension{Raw: bytes},
}, nil
}

Copy link
Author

@JoelSpeed JoelSpeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All comments fixed

I've added the make test unit which has the external binaries for env test downloaded as part of it, just need to make this run in CI and should be good! (I copied the scripts from the AWS one merged in openshift/cluster-api-provider-aws#289

}, nil
}

func providerSpecFromMachine(in *machineproviderv1.AzureMachineProviderSpec) (machinev1.ProviderSpec, error) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exported, but it does already exist in the tests

func providerSpecFromMachine(in *machineproviderv1.AzureMachineProviderSpec) (*machinev1.ProviderSpec, error) {
bytes, err := json.Marshal(in)
if err != nil {
return nil, err
}
return &machinev1.ProviderSpec{
Value: &runtime.RawExtension{Raw: bytes},
}, nil
}
and
func providerSpecFromMachine(in *machineproviderv1.AzureMachineProviderSpec) (*machinev1.ProviderSpec, error) {
bytes, err := yaml.Marshal(in)
if err != nil {
return nil, err
}
return &machinev1.ProviderSpec{
Value: &runtime.RawExtension{Raw: bytes},
}, nil
}

@@ -9,6 +9,7 @@ require (
github.com/Azure/go-autorest/autorest/to v0.3.0
github.com/Azure/go-autorest/autorest/validation v0.2.0 // indirect
github.com/ghodss/yaml v1.0.0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}

originalMachineSetToPatch := client.MergeFrom(machineSet.DeepCopy())
defer func() {
Copy link
Member

@enxebre enxebre Mar 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to defer here?
what's the benefit over calling this explicitly at the end of this func? I'd find that more readable. wdyt?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this because I had meant to put a return in the if err != nil block on lines 96-99, but I seemingly forgot to do that.
I was following a pattern from upstream but happy to rework it to avoid the defer

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a commit to rework this, gonna squash it before merge, WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm. Please keep revendor commit separate

logger.Error(err, "Failed to reconcile MachineSet")
r.recorder.Eventf(machineSet, corev1.EventTypeWarning, "ReconcileError", "%v", err)
}
return result, nil
Copy link
Member

@enxebre enxebre Mar 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this return err? seems like the err in l94 is ignored otherwise?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed that, I think you saw an outdated version

@JoelSpeed
Copy link
Author

/test unit

@enxebre
Copy link
Member

enxebre commented Mar 12, 2020

/approve

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: enxebre

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 12, 2020
Copy link

@alexander-demicev alexander-demicev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 12, 2020
@openshift-bot
Copy link

/retest

Please review the full test history for this PR and help us cut down flakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants