Skip to content

Commit

Permalink
drop old machine controller and build new one
Browse files Browse the repository at this point in the history
  • Loading branch information
enxebre committed Oct 17, 2018
1 parent 69d1882 commit b4dd7a0
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 474 deletions.
38 changes: 0 additions & 38 deletions cmd/machine-controller/Makefile

This file was deleted.

102 changes: 0 additions & 102 deletions cmd/machine-controller/main.go

This file was deleted.

74 changes: 67 additions & 7 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -17,17 +14,41 @@ limitations under the License.
package main

import (
"log"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/cluster-api-provider-aws/migration/pkg/apis"
"sigs.k8s.io/cluster-api-provider-aws/migration/pkg/controller"
"sigs.k8s.io/cluster-api-provider-aws/pkg/apis"
"sigs.k8s.io/cluster-api-provider-aws/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
clusterapis "sigs.k8s.io/cluster-api/pkg/apis"
"sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset"
"k8s.io/client-go/kubernetes"
machineactuator "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/actuators/machine"
//"sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1"
"github.com/golang/glog"
log "github.com/sirupsen/logrus"
awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/client"
"os"
"github.com/spf13/pflag"
)

var (
logLevel string
)

const (
defaultLogLevel = "info"
)

func init() {
pflag.CommandLine.StringVar(&logLevel, "log-level", defaultLogLevel, "Log level (debug,info,warn,error,fatal)")
}

func main() {
// the following line exists to make glog happy, for more information, see: https://github.com/kubernetes/kubernetes/issues/17162
//flag.CommandLine.Parse([]string{})
pflag.Parse()

// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
if err != nil {
Expand All @@ -47,6 +68,11 @@ func main() {
log.Fatal(err)
}

if err := clusterapis.AddToScheme(mgr.GetScheme()); err != nil {
log.Fatal(err)
}

initActuator(mgr)
// Setup all Controllers
if err := controller.AddToManager(mgr); err != nil {
log.Fatal(err)
Expand All @@ -57,3 +83,37 @@ func main() {
// Start the Cmd
log.Fatal(mgr.Start(signals.SetupSignalHandler()))
}

func initActuator(m manager.Manager) {
config := m.GetConfig()
client, err := clientset.NewForConfig(config)
if err != nil {
glog.Fatalf("Could not create client for talking to the apiserver: %v", err)
}

kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
glog.Fatalf("Could not create kubernetes client to talk to the apiserver: %v", err)
}

log.SetOutput(os.Stdout)
if lvl, err := log.ParseLevel(logLevel); err != nil {
log.Panic(err)
} else {
log.SetLevel(lvl)
}

logger := log.WithField("controller", "awsMachine")

params := machineactuator.ActuatorParams{
ClusterClient: client,
KubeClient: kubeClient,
AwsClientBuilder: awsclient.NewClient,
Logger: logger,
}

machineactuator.MachineActuator, err = machineactuator.NewActuator(params)
if err != nil {
glog.Fatalf("Could not create AWS machine actuator: %v", err)
}
}
7 changes: 5 additions & 2 deletions pkg/cloud/aws/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
providerconfigv1 "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/providerconfig/v1alpha1"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
clusterclient "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset"
//clustererror "sigs.k8s.io/cluster-api/pkg/controller/error"
clustererror "sigs.k8s.io/cluster-api/pkg/controller/error"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
Expand All @@ -53,6 +53,8 @@ const (
MachineCreationFailed = "MachineCreationFailed"
)

var MachineActuator *Actuator

// Actuator is the AWS-specific actuator for the Cluster API machine controller
type Actuator struct {
kubeClient kubernetes.Interface
Expand Down Expand Up @@ -117,7 +119,8 @@ func (a *Actuator) updateMachineStatus(machine *clusterv1.Machine, awsStatus *pr

if !equality.Semantic.DeepEqual(machine.Status, machineCopy.Status) {
mLog.Info("machine status has changed, updating")
machineCopy.Status.LastUpdated = metav1.Now()
time := metav1.Now()
machineCopy.Status.LastUpdated = &time

_, err := a.clusterClient.ClusterV1alpha1().Machines(machineCopy.Namespace).UpdateStatus(machineCopy)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/*
Copyright 2018 The Kubernetes Authors.
Copyright 2018 The Kubernetes authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -17,10 +14,22 @@ limitations under the License.
package controller

import (
"sigs.k8s.io/cluster-api-provider-aws/migration/pkg/controller/awsmachineproviderconfig"
"sigs.k8s.io/cluster-api/pkg/controller/machine"
"sigs.k8s.io/controller-runtime/pkg/manager"
machineactuator "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/actuators/machine"
)

var (
logLevel string
)

const (
defaultLogLevel = "info"
)

func init() {
// AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
AddToManagerFuncs = append(AddToManagerFuncs, awsmachineproviderconfig.Add)
}
AddToManagerFuncs = append(AddToManagerFuncs, func(m manager.Manager) error {
return machine.AddWithActuator(m, machineactuator.MachineActuator)
})
}
Loading

0 comments on commit b4dd7a0

Please sign in to comment.