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

Pivot cloudprovider/cluster-api to machine.openshift.io/v1beta1 #29

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
3,143 changes: 1,589 additions & 1,554 deletions cluster-autoscaler/Godeps/Godeps.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/aws"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/azure"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/clusterapi"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/gce"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/gke"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/kubemark"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider/openshiftmachineapi"
"k8s.io/autoscaler/cluster-autoscaler/config"
"k8s.io/autoscaler/cluster-autoscaler/context"
"k8s.io/client-go/informers"
Expand All @@ -45,7 +45,7 @@ var AvailableCloudProviders = []string{
gce.ProviderNameGCE,
gke.ProviderNameGKE,
kubemark.ProviderName,
clusterapi.ProviderName,
openshiftmachineapi.ProviderName,
}

// DefaultCloudProvider is GCE.
Expand Down Expand Up @@ -78,8 +78,8 @@ func NewCloudProvider(opts config.AutoscalingOptions) cloudprovider.CloudProvide
return buildAzure(opts, do, rl)
case kubemark.ProviderName:
return buildKubemark(opts, do, rl)
case clusterapi.ProviderName:
return buildClusterAPI(clusterapi.ProviderName, opts, do, rl)
case openshiftmachineapi.ProviderName:
return buildClusterAPI(openshiftmachineapi.ProviderName, opts, do, rl)
case "":
// Ideally this would be an error, but several unit tests of the
// StaticAutoscaler depend on this behaviour.
Expand Down Expand Up @@ -225,7 +225,7 @@ func buildKubemark(opts config.AutoscalingOptions, do cloudprovider.NodeGroupDis
}

func buildClusterAPI(name string, opts config.AutoscalingOptions, do cloudprovider.NodeGroupDiscoveryOptions, rl *cloudprovider.ResourceLimiter) cloudprovider.CloudProvider {
provider, err := clusterapi.BuildCloudProvider(name, opts, rl)
provider, err := openshiftmachineapi.BuildCloudProvider(name, opts, rl)
if err != nil {
glog.Fatalf("Failed to create %q cloud provider: %v", name, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package clusterapi
package openshiftmachineapi

// Export for testing.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package clusterapi
package openshiftmachineapi

import (
"fmt"

"github.com/golang/glog"
"github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
clusterinformers "github.com/openshift/cluster-api/pkg/client/informers_generated/externalversions"
machinev1beta1 "github.com/openshift/cluster-api/pkg/client/informers_generated/externalversions/machine/v1beta1"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
kubeinformers "k8s.io/client-go/informers"
"k8s.io/client-go/tools/cache"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
clusterinformers "sigs.k8s.io/cluster-api/pkg/client/informers_generated/externalversions"
clusterv1alpha1 "sigs.k8s.io/cluster-api/pkg/client/informers_generated/externalversions/cluster/v1alpha1"
)

const (
nodeProviderIDIndex = "clusterapi-nodeProviderIDIndex"
nodeProviderIDIndex = "openshiftmachineapi-nodeProviderIDIndex"
)

// machineController watches for Nodes, Machines and MachineSets as
Expand All @@ -40,8 +40,8 @@ const (
type machineController struct {
clusterInformerFactory clusterinformers.SharedInformerFactory
kubeInformerFactory kubeinformers.SharedInformerFactory
machineInformer clusterv1alpha1.MachineInformer
machineSetInformer clusterv1alpha1.MachineSetInformer
machineInformer machinev1beta1.MachineInformer
machineSetInformer machinev1beta1.MachineSetInformer
nodeInformer cache.SharedIndexInformer
}

Expand All @@ -52,7 +52,7 @@ func indexNodeByNodeProviderID(obj interface{}) ([]string, error) {
return []string{}, nil
}

func (c *machineController) findMachine(id string) (*v1alpha1.Machine, error) {
func (c *machineController) findMachine(id string) (*v1beta1.Machine, error) {
item, exists, err := c.machineInformer.Informer().GetStore().GetByKey(id)
if err != nil {
return nil, err
Expand All @@ -62,7 +62,7 @@ func (c *machineController) findMachine(id string) (*v1alpha1.Machine, error) {
return nil, nil
}

machine, ok := item.(*v1alpha1.Machine)
machine, ok := item.(*v1beta1.Machine)
if !ok {
return nil, fmt.Errorf("internal error; unexpected type %T", machine)
}
Expand All @@ -73,7 +73,7 @@ func (c *machineController) findMachine(id string) (*v1alpha1.Machine, error) {
// findMachineOwner returns the machine set owner for machine, or nil
// if there is no owner. A DeepCopy() of the object is returned on
// success.
func (c *machineController) findMachineOwner(machine *v1alpha1.Machine) (*v1alpha1.MachineSet, error) {
func (c *machineController) findMachineOwner(machine *v1beta1.Machine) (*v1beta1.MachineSet, error) {
machineOwnerRef := machineOwnerRef(machine)
if machineOwnerRef == nil {
return nil, nil
Expand All @@ -88,7 +88,7 @@ func (c *machineController) findMachineOwner(machine *v1alpha1.Machine) (*v1alph
return nil, nil
}

machineSet, ok := item.(*v1alpha1.MachineSet)
machineSet, ok := item.(*v1beta1.MachineSet)
if !ok {
return nil, fmt.Errorf("internal error; unexpected type: %T", machineSet)
}
Expand Down Expand Up @@ -121,7 +121,7 @@ func (c *machineController) run(stopCh <-chan struct{}) error {
// node.Spec.ProviderID as the key. Returns nil if either the Node by
// node.Spec.ProviderID cannot be found or if the node has no machine
// annotation. A DeepCopy() of the object is returned on success.
func (c *machineController) findMachineByNodeProviderID(node *apiv1.Node) (*v1alpha1.Machine, error) {
func (c *machineController) findMachineByNodeProviderID(node *apiv1.Node) (*v1beta1.Machine, error) {
objs, err := c.nodeInformer.GetIndexer().ByIndex(nodeProviderIDIndex, node.Spec.ProviderID)
if err != nil {
return nil, err
Expand All @@ -144,7 +144,7 @@ func (c *machineController) findMachineByNodeProviderID(node *apiv1.Node) (*v1al
// Reference this annotation key symbolically once the
// following PR merges:
// https://github.com/kubernetes-sigs/cluster-api/pull/663
if machineName, found := node.Annotations["cluster.k8s.io/machine"]; found {
if machineName, found := node.Annotations["machine.openshift.io/machine"]; found {
return c.findMachine(machineName)
}

Expand Down Expand Up @@ -175,14 +175,14 @@ func (c *machineController) findNodeByNodeName(name string) (*apiv1.Node, error)
// MachinesInMachineSet returns all the machines that belong to
// machineSet. For each machine in the set a DeepCopy() of the object
// is returned.
func (c *machineController) MachinesInMachineSet(machineSet *v1alpha1.MachineSet) ([]*v1alpha1.Machine, error) {
func (c *machineController) MachinesInMachineSet(machineSet *v1beta1.MachineSet) ([]*v1beta1.Machine, error) {
listOptions := labels.SelectorFromSet(labels.Set(machineSet.Labels))
machines, err := c.machineInformer.Lister().Machines(machineSet.Namespace).List(listOptions)
if err != nil {
return nil, err
}

var result []*v1alpha1.Machine
var result []*v1beta1.Machine

for _, machine := range machines {
if machineIsOwnedByMachineSet(machine, machineSet) {
Expand All @@ -200,8 +200,8 @@ func newMachineController(
kubeInformerFactory kubeinformers.SharedInformerFactory,
clusterInformerFactory clusterinformers.SharedInformerFactory,
) (*machineController, error) {
machineInformer := clusterInformerFactory.Cluster().V1alpha1().Machines()
machineSetInformer := clusterInformerFactory.Cluster().V1alpha1().MachineSets()
machineInformer := clusterInformerFactory.Machine().V1beta1().Machines()
machineSetInformer := clusterInformerFactory.Machine().V1beta1().MachineSets()

machineInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{})
machineSetInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package clusterapi
package openshiftmachineapi

import (
"fmt"
Expand All @@ -23,15 +23,15 @@ import (
"sort"
"testing"

"github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
fakeclusterapi "github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset/fake"
informers "github.com/openshift/cluster-api/pkg/client/informers_generated/externalversions"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
kubeinformers "k8s.io/client-go/informers"
fakekube "k8s.io/client-go/kubernetes/fake"
"k8s.io/kubernetes/pkg/controller"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
fakeclusterapi "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/fake"
informers "sigs.k8s.io/cluster-api/pkg/client/informers_generated/externalversions"
)

func mustCreateTestController(t *testing.T) *machineController {
Expand All @@ -58,7 +58,7 @@ func mustCreateTestController(t *testing.T) *machineController {
func TestFindMachineByID(t *testing.T) {
controller := mustCreateTestController(t)

testMachine := &v1alpha1.Machine{
testMachine := &v1beta1.Machine{
ObjectMeta: v1.ObjectMeta{
Name: "test",
Namespace: "test-namespace",
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestFindMachineByID(t *testing.T) {
func TestFindMachineOwner(t *testing.T) {
controller := mustCreateTestController(t)

testMachineWithNoOwner := &v1alpha1.Machine{
testMachineWithNoOwner := &v1beta1.Machine{
TypeMeta: v1.TypeMeta{
Kind: "Machine",
},
Expand All @@ -129,7 +129,7 @@ func TestFindMachineOwner(t *testing.T) {
},
}

testMachineWithOwner := &v1alpha1.Machine{
testMachineWithOwner := &v1beta1.Machine{
TypeMeta: v1.TypeMeta{
Kind: "Machine",
},
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestFindMachineOwner(t *testing.T) {
t.Fatalf("expected no owner, got %v", foundMachineSet)
}

testMachineSet := &v1alpha1.MachineSet{
testMachineSet := &v1beta1.MachineSet{
TypeMeta: v1.TypeMeta{
Kind: "MachineSet",
},
Expand Down Expand Up @@ -207,7 +207,7 @@ func TestFindMachineByNodeProviderID(t *testing.T) {
},
}

testMachine := &v1alpha1.Machine{
testMachine := &v1beta1.Machine{
TypeMeta: v1.TypeMeta{
Kind: "Machine",
},
Expand All @@ -232,7 +232,7 @@ func TestFindMachineByNodeProviderID(t *testing.T) {
// Update node with machine linkage.
testNode.Spec.ProviderID = "aws:///us-east-2b/i-03759ec2e4e053f99"
testNode.Annotations = map[string]string{
"cluster.k8s.io/machine": path.Join(testMachine.Namespace, testMachine.Name),
"machine.openshift.io/machine": path.Join(testMachine.Namespace, testMachine.Name),
}

controller.nodeInformer.GetStore().Update(testNode)
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestFindNodeByNodeName(t *testing.T) {
func TestMachinesInMachineSet(t *testing.T) {
controller := mustCreateTestController(t)

testMachineSet1 := &v1alpha1.MachineSet{
testMachineSet1 := &v1beta1.MachineSet{
TypeMeta: v1.TypeMeta{
Kind: "MachineSet",
},
Expand All @@ -311,7 +311,7 @@ func TestMachinesInMachineSet(t *testing.T) {
},
}

testMachineSet2 := &v1alpha1.MachineSet{
testMachineSet2 := &v1beta1.MachineSet{
TypeMeta: v1.TypeMeta{
Kind: "MachineSet",
},
Expand All @@ -325,10 +325,10 @@ func TestMachinesInMachineSet(t *testing.T) {
controller.machineSetInformer.Informer().GetStore().Add(testMachineSet1)
controller.machineSetInformer.Informer().GetStore().Add(testMachineSet2)

testMachines := make([]*v1alpha1.Machine, 10)
testMachines := make([]*v1beta1.Machine, 10)

for i := 0; i < 10; i++ {
testMachines[i] = &v1alpha1.Machine{
testMachines[i] = &v1beta1.Machine{
TypeMeta: v1.TypeMeta{
Kind: "Machine",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package clusterapi
package openshiftmachineapi

import (
"fmt"
"path"
"time"

machinev1beta1 "github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset/typed/machine/v1beta1"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
schedulercache "k8s.io/kubernetes/pkg/scheduler/cache"
clusterv1alpha1 "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/typed/cluster/v1alpha1"
)

const (
machineDeleteAnnotationKey = "sigs.k8s.io/cluster-api-delete-machine"
machineDeleteAnnotationKey = "machine.openshift.io/cluster-api-delete-machine"
)

var _ cloudprovider.NodeGroup = (*nodegroup)(nil)

type nodegroup struct {
machineController *machineController
clusterapiClient clusterv1alpha1.ClusterV1alpha1Interface
machineapiClient machinev1beta1.MachineV1beta1Interface
maxSize int
minSize int
name string
Expand Down Expand Up @@ -66,7 +66,7 @@ func (ng *nodegroup) Replicas() int {
}

func (ng *nodegroup) SetSize(nreplicas int) error {
machineSet, err := ng.clusterapiClient.MachineSets(ng.namespace).Get(ng.name, v1.GetOptions{})
machineSet, err := ng.machineapiClient.MachineSets(ng.namespace).Get(ng.name, v1.GetOptions{})
if err != nil {
return fmt.Errorf("unable to get machineset %q: %v", ng.name, err)
}
Expand All @@ -75,7 +75,7 @@ func (ng *nodegroup) SetSize(nreplicas int) error {
replicas := int32(nreplicas)
machineSet.Spec.Replicas = &replicas

_, err = ng.clusterapiClient.MachineSets(ng.namespace).Update(machineSet)
_, err = ng.machineapiClient.MachineSets(ng.namespace).Update(machineSet)
if err != nil {
return fmt.Errorf("unable to update number of replicas of machineset %q: %v", ng, err)
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func (ng *nodegroup) DeleteNodes(nodes []*apiv1.Node) error {

machine.Annotations[machineDeleteAnnotationKey] = time.Now().String()

if _, err := ng.clusterapiClient.Machines(machine.Namespace).Update(machine); err != nil {
if _, err := ng.machineapiClient.Machines(machine.Namespace).Update(machine); err != nil {
return fmt.Errorf("failed to update machine %s/%s: %v", machine.Namespace, machine.Name, err)
}
}
Expand Down
Loading