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

Openshift machine api #1175

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ ignored = [
version = "9.0.0"

[[constraint]]
name = "sigs.k8s.io/cluster-api"
branch = "master"
name = "github.com/openshift/cluster-api"
revision = "91fca585a85b163ddfd119fd09c128c9feadddca"

[[constraint]]
name = "sigs.k8s.io/cluster-api-provider-aws"
source = "https://github.com/openshift/cluster-api-provider-aws.git"
branch = "master"
revision = "9a983a5c6c12b27169c57e4c8948cb554e4d6b6c"

[[constraint]]
name = "github.com/openshift/cluster-api-provider-libvirt"
Expand Down
16 changes: 8 additions & 8 deletions pkg/asset/machines/aws/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ package aws
import (
"fmt"

machineapi "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/pointer"
awsprovider "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1"
clusterapi "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"

"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/aws"
)

// Machines returns a list of machines for a machinepool.
func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string) ([]clusterapi.Machine, error) {
func Machines(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string) ([]machineapi.Machine, error) {
if configPlatform := config.Platform.Name(); configPlatform != aws.Name {
return nil, fmt.Errorf("non-AWS configuration: %q", configPlatform)
}
Expand All @@ -34,16 +34,16 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
if pool.Replicas != nil {
total = *pool.Replicas
}
var machines []clusterapi.Machine
var machines []machineapi.Machine
for idx := int64(0); idx < total; idx++ {
azIndex := int(idx) % len(azs)
provider, err := provider(clusterID, clustername, platform, mpool, osImage, azIndex, role, userDataSecret)
if err != nil {
return nil, errors.Wrap(err, "failed to create provider")
}
machine := clusterapi.Machine{
machine := machineapi.Machine{
TypeMeta: metav1.TypeMeta{
APIVersion: "cluster.k8s.io/v1alpha1",
APIVersion: "machine.openshift.io/v1beta1",
Kind: "Machine",
},
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -55,8 +55,8 @@ func Machines(clusterID string, config *types.InstallConfig, pool *types.Machine
"sigs.k8s.io/cluster-api-machine-type": role,
},
},
Spec: clusterapi.MachineSpec{
ProviderSpec: clusterapi.ProviderSpec{
Spec: machineapi.MachineSpec{
ProviderSpec: machineapi.ProviderSpec{
Value: &runtime.RawExtension{Object: provider},
},
// we don't need to set Versions, because we control those via operators.
Expand Down Expand Up @@ -130,7 +130,7 @@ func tagsFromUserTags(clusterID, clusterName string, usertags map[string]string)
}

// ConfigMasters sets the PublicIP flag and assigns a set of load balancers to the given machines
func ConfigMasters(machines []clusterapi.Machine, clusterName string) {
func ConfigMasters(machines []machineapi.Machine, clusterName string) {
for _, machine := range machines {
providerSpec := machine.Spec.ProviderSpec.Value.Object.(*awsprovider.AWSMachineProviderConfig)
providerSpec.PublicIP = pointer.BoolPtr(true)
Expand Down
18 changes: 9 additions & 9 deletions pkg/asset/machines/aws/machinesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ package aws
import (
"fmt"

machineapi "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
clusterapi "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"

"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/aws"
"github.com/pkg/errors"
)

// MachineSets returns a list of machinesets for a machinepool.
func MachineSets(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string) ([]clusterapi.MachineSet, error) {
func MachineSets(clusterID string, config *types.InstallConfig, pool *types.MachinePool, osImage, role, userDataSecret string) ([]machineapi.MachineSet, error) {
if configPlatform := config.Platform.Name(); configPlatform != aws.Name {
return nil, fmt.Errorf("non-AWS configuration: %q", configPlatform)
}
Expand All @@ -31,7 +31,7 @@ func MachineSets(clusterID string, config *types.InstallConfig, pool *types.Mach
total = *pool.Replicas
}
numOfAZs := int64(len(azs))
var machinesets []clusterapi.MachineSet
var machinesets []machineapi.MachineSet
for idx, az := range azs {
replicas := int32(total / numOfAZs)
if int64(idx) < total%numOfAZs {
Expand All @@ -43,9 +43,9 @@ func MachineSets(clusterID string, config *types.InstallConfig, pool *types.Mach
return nil, errors.Wrap(err, "failed to create provider")
}
name := fmt.Sprintf("%s-%s-%s", clustername, pool.Name, az)
mset := clusterapi.MachineSet{
mset := machineapi.MachineSet{
TypeMeta: metav1.TypeMeta{
APIVersion: "cluster.k8s.io/v1alpha1",
APIVersion: "machine.openshift.io/v1beta1",
Kind: "MachineSet",
},
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -57,15 +57,15 @@ func MachineSets(clusterID string, config *types.InstallConfig, pool *types.Mach
"sigs.k8s.io/cluster-api-machine-type": role,
},
},
Spec: clusterapi.MachineSetSpec{
Spec: machineapi.MachineSetSpec{
Replicas: &replicas,
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
"sigs.k8s.io/cluster-api-machineset": name,
"sigs.k8s.io/cluster-api-cluster": clustername,
},
},
Template: clusterapi.MachineTemplateSpec{
Template: machineapi.MachineTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"sigs.k8s.io/cluster-api-machineset": name,
Expand All @@ -74,8 +74,8 @@ func MachineSets(clusterID string, config *types.InstallConfig, pool *types.Mach
"sigs.k8s.io/cluster-api-machine-type": role,
},
},
Spec: clusterapi.MachineSpec{
ProviderSpec: clusterapi.ProviderSpec{
Spec: machineapi.MachineSpec{
ProviderSpec: machineapi.ProviderSpec{
Value: &runtime.RawExtension{Object: provider},
},
// we don't need to set Versions, because we control those via cluster operators.
Expand Down
20 changes: 17 additions & 3 deletions pkg/asset/machines/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/ghodss/yaml"
machineapi "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -104,7 +105,7 @@ func (m *Master) Generate(dependencies asset.Parents) error {
return errors.Wrap(err, "failed to create master machine objects")
}

list := listFromMachines(machines)
list := listFromMachinesDeprecated(machines)
raw, err := yaml.Marshal(list)
if err != nil {
return errors.Wrap(err, "failed to marshal")
Expand All @@ -127,7 +128,7 @@ func (m *Master) Generate(dependencies asset.Parents) error {
}
openstack.ConfigMasters(machines, ic.ObjectMeta.Name)

list := listFromMachines(machines)
list := listFromMachinesDeprecated(machines)
m.MachinesRaw, err = yaml.Marshal(list)
if err != nil {
return errors.Wrap(err, "failed to marshal")
Expand All @@ -148,7 +149,20 @@ func masterPool(pools []types.MachinePool) types.MachinePool {
return types.MachinePool{}
}

func listFromMachines(objs []clusterapi.Machine) *metav1.List {
func listFromMachines(objs []machineapi.Machine) *metav1.List {
Copy link
Contributor

Choose a reason for hiding this comment

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

why this change.. ?

Copy link
Member Author

@enxebre enxebre Feb 5, 2019

Choose a reason for hiding this comment

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

because machines now belong to machine.openshift.io API group, hence the machineapi.Machine type. See relevant references in the description. Please let me know if this is not clear

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry wrong line, more as to why keep the deprecated one too? It that bring used?

Copy link
Member Author

@enxebre enxebre Feb 5, 2019

Choose a reason for hiding this comment

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

@abhinavdahiya we are providing a backward compatible pivoting path for any actuator openshift/machine-api-operator#192 This PR finalises the pivot for aws. We'll put a follow up for libvirt right away and once the openstack actuator is updated to rely on machine.openshift.io and they put a PR analogous to this one for Opensatck we will fully drop support for cluster.k8s.io either here and on the machine api operator openshift/machine-api-operator#195

list := &metav1.List{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "List",
},
}
for idx := range objs {
list.Items = append(list.Items, runtime.RawExtension{Object: &objs[idx]})
}
return list
}

func listFromMachinesDeprecated(objs []clusterapi.Machine) *metav1.List {
list := &metav1.List{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand Down
20 changes: 17 additions & 3 deletions pkg/asset/machines/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"text/template"

"github.com/ghodss/yaml"
machineapi "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -124,7 +125,7 @@ func (w *Worker) Generate(dependencies asset.Parents) error {
return errors.Wrap(err, "failed to create worker machine objects")
}

list := listFromMachineSets(sets)
list := listFromMachineDeprecated(sets)
raw, err := yaml.Marshal(list)
if err != nil {
return errors.Wrap(err, "failed to marshal")
Expand All @@ -146,7 +147,7 @@ func (w *Worker) Generate(dependencies asset.Parents) error {
return errors.Wrap(err, "failed to create master machine objects")
}

list := listFromMachineSets(sets)
list := listFromMachineDeprecated(sets)
w.MachineSetRaw, err = yaml.Marshal(list)
if err != nil {
return errors.Wrap(err, "failed to marshal")
Expand Down Expand Up @@ -174,7 +175,20 @@ func applyTemplateData(template *template.Template, templateData interface{}) []
return buf.Bytes()
}

func listFromMachineSets(objs []clusterapi.MachineSet) *metav1.List {
func listFromMachineSets(objs []machineapi.MachineSet) *metav1.List {
list := &metav1.List{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "List",
},
}
for idx := range objs {
list.Items = append(list.Items, runtime.RawExtension{Object: &objs[idx]})
}
return list
}

func listFromMachineDeprecated(objs []clusterapi.MachineSet) *metav1.List {
list := &metav1.List{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Expand Down
Loading