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

add an API for machinepool -> machinesets #573

Merged
merged 2 commits into from
Nov 2, 2018

Conversation

abhinavdahiya
Copy link
Contributor

https://github.com/openshift/hive/ recommended that installer expose some api so that the machine and machineset generation for machinepool can be reused.

/cc @dgoodwin @rajatchopra

@dgoodwin

  • do you want a platform agnostic API?
  • the API assumes completely valid machinepool definition, no defaulting is applied. (@dgoodwin wanted the api to not consume client for cloud)

builds on #567

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 30, 2018
@openshift-ci-robot openshift-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 30, 2018
pkg/asset/machines/aws/master.go Outdated Show resolved Hide resolved
pkg/asset/machines/aws/master.go Outdated Show resolved Hide resolved
pkg/asset/machines/aws/worker.go Outdated Show resolved Hide resolved
pkg/asset/machines/aws/worker.go Outdated Show resolved Hide resolved
pkg/asset/machines/aws/worker.go Outdated Show resolved Hide resolved
pkg/asset/machines/master.go Show resolved Hide resolved
@abhinavdahiya
Copy link
Contributor Author

abhinavdahiya commented Oct 31, 2018

@dgoodwin
if the all hive does is use install-config give it to the installer to create stuff, all the defaulting is handled by the installer

if hive wants to create new machinsets/machines, later on, this API requires defaulting for that to be handled explicitly. I don't think installer's defaults make sense then?

@dgoodwin
Copy link
Contributor

The problem is Hive would expose an API with fields that are optional and would need defaults, we would convert to InstallConfig and pass to you, but we have no way to know what defaults were applied.

As the cluster lives on and we maintain machine sets, we're still just operating off that config the user specified which may not have all fields set.

Is there a reason this API can't apply the same defaults as it did during install?

Or do we need shared APIs to calculate defaults and apply to an install config?

@dgoodwin
Copy link
Contributor

Thinking about this some more, the AMI specifically can't be a live lookup, it would change over time which we don't want. I think we may need to have Hive explicitly apply defaults that match yours?

@wking
Copy link
Member

wking commented Oct 31, 2018

The problem is Hive would expose an API with fields that are optional and would need defaults, we would convert to InstallConfig and pass to you, but we have no way to know what defaults were applied.

Can you use sentinel values for "I don't care, let the installer choose"? Then just leave those unset in your install-config (related: #263), and we'll fill in our defaults for the unset fields. I'm not sure if we do that at the moment, but it shouldn't be too hard.

@abhinavdahiya
Copy link
Contributor Author

abhinavdahiya commented Oct 31, 2018

@wking

Can you use sentinel values for "I don't care, let the installer choose"? Then just leave those unset in your install-config

we already default.

As the cluster lives on and we maintain machine sets, we're still just operating off that config the user specified which may not have all fields set.

@dgoodwin installer cannot choose sane default after installation. hive will have to create its own merge/update logic.

I think we may need to have Hive explicitly apply defaults that match yours?

thinking hive as an operator; you should fetch the live machineset, use this api with values to create expected state and then merge them based on some logic...

@dgoodwin
Copy link
Contributor

Yes talking about this with @csrwng I think we're going to want to apply our own defaults, possibly with re-used code between our two projects again. The AMI specifically can't change so we can't hand off to have a default reapplied.

@abhinavdahiya abhinavdahiya changed the title WIP: add an API for machinepool -> machinesets add an API for machinepool -> machinesets Oct 31, 2018
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 31, 2018
@abhinavdahiya
Copy link
Contributor Author

Yes talking about this with @csrwng I think we're going to want to apply our own defaults, possibly with re-used code between our two projects again. The AMI specifically can't change so we can't hand off to have a default reapplied.

so this is good to go as-is ?

@dgoodwin
Copy link
Contributor

I think so yes, thanks.

@abhinavdahiya
Copy link
Contributor Author

I think so yes, thanks.

an /lgtm would be appreciated 😇

@@ -49,6 +49,17 @@ ignored = ["github.com/openshift/installer/tests*"]
name = "k8s.io/client-go"
version = "6.0.0"

[[constraint]]
name = "sigs.k8s.io/cluster-api"
branch = "master"
Copy link
Member

Choose a reason for hiding this comment

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

Do we really want these floating with master? Can we pin to their current tips and then manually bump when they make changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

master is fine

},
Versions: clusterapi.MachineVersionInfo{
Kubelet: "",
ControlPlane: "",
Copy link
Member

Choose a reason for hiding this comment

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

I'd still rather leave Versions unset and file issues or set a FIXME about these two parameters. Setting them to empty strings doesn't make sense to me.

Copy link
Contributor Author

@abhinavdahiya abhinavdahiya Oct 31, 2018

Choose a reason for hiding this comment

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

This is explicitly saying don't care about version for these, we have different mechanism for controlling them.

Copy link
Member

@wking wking Oct 31, 2018

Choose a reason for hiding this comment

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

This is explicitly saying don't care about version for these we have diff mechanism for controlling them.

But you can use zero-values for that, no?

$ cat test.go 
package main

import (
	"fmt"
	clusterapi "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)

func main() {
	spec := clusterapi.MachineSpec{}
	fmt.Printf("%q %t\n", spec.Versions.Kubelet, spec.Versions.Kubelet == "")
}
$ go run test.go 
"" true

@dgoodwin
Copy link
Contributor

dgoodwin commented Nov 1, 2018

Sorry @abhinavdahiya didn't know we could, or should, be lgtm'ing in your repo. Going to hold off now though and let @wking

@abhinavdahiya
Copy link
Contributor Author

@wking wants the api to move to this:

$ godoc ./pkg/asset/machines/aws
PACKAGE DOCUMENTATION

package aws
    import "./pkg/asset/machines/aws"

    Package aws generates Machine objects for aws.

FUNCTIONS

func AvailabilityZones(region string) ([]string, error)
    AvailabilityZones retrieves a list of availability zones for the given
    region.

func MachineSets(config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]clusterapi.MachineSet, error)
    MachineSets returns a list of machinesets for a machinepool.

func Machines(config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]clusterapi.Machine, error)
    Machines returns a list of machines for a machinepool.


$ godoc ./pkg/asset/machines/libvirt
PACKAGE DOCUMENTATION

package libvirt
    import "./pkg/asset/machines/libvirt"

    Package libvirt generates Machine objects for libvirt.

FUNCTIONS

func MachineSets(config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]clusterapi.MachineSet, error)
    MachineSets returns a list of machinesets for a machinepool.

func Machines(config *types.InstallConfig, pool *types.MachinePool, role, userDataSecret string) ([]clusterapi.Machine, error)
    Machines returns a list of machines for a machinepool.

pushed commits to match that.

ProviderConfig: clusterapi.ProviderConfig{
Value: &runtime.RawExtension{Object: &provider},
},
Versions: clusterapi.MachineVersionInfo{
Copy link
Member

Choose a reason for hiding this comment

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

Did you not find my zero-value demonstration convincing? ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these values have a meaning upstream, but set them to "" so anybody that sees this code understands that these values to set to "" because we have different mechanics to control them.
From the consumer end it makes no difference.

Copy link
Member

Choose a reason for hiding this comment

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

... anybody that sees this code understands that these values to set to "" because we have different mechanics to control them...

This is not obvious to me from reading the code ;). How about:

Spec: clusterapi.MachineSpec{
  ProviderConfig: clusterapi.ProviderConfig{
    Value: &runtime.RawExtension{Object: &provider},
  },
  // we don't need to set Versions, because we control those via {reference our different mechanism}
}

Copy link
Contributor Author

@abhinavdahiya abhinavdahiya Nov 2, 2018

Choose a reason for hiding this comment

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

This is not obvious to me from reading the code ;).

Well in that case, hopefully // we don't need to set Versions, because we control those via {reference our different mechanism} does the job

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done with d562522 -> 476be07

k8s.io/utils/pointer provider various type to *type converts which are helpful
Currently the Machine and MachineSet objects are go templates. Moving them
to vendored code allows other consumers like openshift/hive to use these public
helpers effectively.

openstack platform still uses go templates because of vendoring problems.
@abhinavdahiya
Copy link
Contributor Author

@wking tests are green :)

Copy link
Member

@wking wking 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 Nov 2, 2018
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abhinavdahiya, wking

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:
  • OWNERS [abhinavdahiya,wking]

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

@openshift-merge-robot openshift-merge-robot merged commit 58486f9 into openshift:master Nov 2, 2018
@abhinavdahiya abhinavdahiya deleted the mp_to_ms branch November 2, 2018 19:07
abhinavdahiya added a commit to abhinavdahiya/installer that referenced this pull request Nov 2, 2018
Empty machinepool is a valid for libvirt because we don't use it.

Fixes the error
```console
FATAL Error executing openshift-install: non-Libvirt machine-pool: ""
``
introduced in openshift#573
abhinavdahiya added a commit to abhinavdahiya/installer that referenced this pull request Nov 5, 2018
openshift#573 had wrong calculation for machine objects
in AWS.
wking added a commit to wking/openshift-installer that referenced this pull request Nov 13, 2018
…orm}.Name

The old *PlatformType are from cccbb37 (Generate installation assets
via a dependency graph, 2018-08-10, openshift#120), but since 476be07
(pkg/asset: use vendored cluster-api instead of go templates,
2018-10-30, openshift#573), we've had variables for the name strings in the
more central pkg/types.  With this commit, we drop the more peripheral
forms.  I've also pushed the types.PlatformName{Platform} variables
down into types.{platform}.Name at Ahbinav's suggestion [1].

I've added a unit test to enforce sorting in PlatformNames, because
the order is required by sort.SearchStrings in queryUserForPlatform.

[1]: openshift#659 (comment)
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.

5 participants