Skip to content

Commit

Permalink
Update clusterctl, manager, and dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Augustus <saugustus@vmware.com>
  • Loading branch information
justaugustus committed Jan 26, 2019
1 parent a14f123 commit 02aec24
Show file tree
Hide file tree
Showing 95 changed files with 472 additions and 17,834 deletions.
65 changes: 6 additions & 59 deletions Gopkg.lock

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

34 changes: 25 additions & 9 deletions cmd/clusterctl/main.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
/*
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.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"github.com/golang/glog"
"sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/actuators/machine"

"sigs.k8s.io/cluster-api-provider-azure/cmd/versioninfo"
"sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/actuators/cluster"
"sigs.k8s.io/cluster-api/cmd/clusterctl/cmd"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/common"
)

func registerCustomCommands() {
cmd.RootCmd.AddCommand(versioninfo.VersionCmd())
}

func main() {
var err error
machine.Actuator, err = machine.NewMachineActuator(machine.ActuatorParams{})
if err != nil {
glog.Fatalf("Error creating cluster provisioner for azure : %v", err)
}
common.RegisterClusterProvisioner(machine.ProviderName, machine.Actuator)
clusterActuator := cluster.NewActuator(cluster.ActuatorParams{})
common.RegisterClusterProvisioner("azure", clusterActuator)
registerCustomCommands()
cmd.Execute()
}
103 changes: 32 additions & 71 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,107 +17,68 @@ package main

import (
"flag"
"fmt"
"os"

"github.com/joho/godotenv"
"k8s.io/klog"
"sigs.k8s.io/cluster-api-provider-azure/pkg/apis"
"sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/actuators/cluster"
"sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/actuators/machine"
capis "sigs.k8s.io/cluster-api/pkg/apis"
"sigs.k8s.io/cluster-api/pkg/controller"
apicluster "sigs.k8s.io/cluster-api/pkg/controller/cluster"
apimachine "sigs.k8s.io/cluster-api/pkg/controller/machine"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/cluster-api-provider-azure/pkg/record"
clusterapis "sigs.k8s.io/cluster-api/pkg/apis"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/common"
"sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset"
capicluster "sigs.k8s.io/cluster-api/pkg/controller/cluster"
capimachine "sigs.k8s.io/cluster-api/pkg/controller/machine"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
)

func main() {
klog.InitFlags(nil)
flag.Set("logtostderr", "true")
flag.Parse()

logf.SetLogger(logf.ZapLogger(false))
log := logf.Log.WithName("entrypoint")
cfg := config.GetConfigOrDie()

// Get a config to talk to the apiserver
log.Info("setting up client for manager")
cfg, err := config.GetConfig()
// Setup a Manager
mgr, err := manager.New(cfg, manager.Options{})
if err != nil {
log.Error(err, "unable to set up client config")
os.Exit(1)
klog.Fatalf("Failed to set up overall controller manager: %v", err)
}

// Create a new Cmd to provide shared dependencies and start components
log.Info("setting up manager")
mgr, err := manager.New(cfg, manager.Options{})
cs, err := clientset.NewForConfig(cfg)
if err != nil {
log.Error(err, "unable to set up overall controller manager")
os.Exit(1)
klog.Fatalf("Failed to create client from configuration: %v", err)
}

if err := prepareEnvironment(); err != nil {
log.Error(err, "unable to prepare environment for actuators")
os.Exit(1)
}
// Initialize event recorder.
record.InitFromRecorder(mgr.GetRecorder("azure-controller"))

clusterActuator, err := cluster.NewClusterActuator(cluster.ActuatorParams{Client: mgr.GetClient()})
if err != nil {
log.Error(err, "error creating cluster actuator")
os.Exit(1)
}
machine.Actuator, err = machine.NewMachineActuator(machine.ActuatorParams{Client: mgr.GetClient(), Scheme: mgr.GetScheme()})
if err != nil {
log.Error(err, "error creating machine actuator")
os.Exit(1)
}
// Initialize cluster actuator.
clusterActuator := cluster.NewActuator(cluster.ActuatorParams{
Client: cs.ClusterV1alpha1(),
})

log.Info("Registering Components.")
common.RegisterClusterProvisioner(machine.ProviderName, machine.Actuator)
// Initialize machine actuator.
machineActuator := machine.NewActuator(machine.ActuatorParams{
Client: cs.ClusterV1alpha1(),
})

// Setup Scheme for all resources
log.Info("setting up scheme")
// Register our cluster deployer (the interface is in clusterctl and we define the Deployer interface on the actuator)
common.RegisterClusterProvisioner("azure", clusterActuator)

if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "unable add APIs to scheme")
os.Exit(1)
klog.Fatal(err)
}

if err := capis.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "unable add APIs to scheme")
os.Exit(1)
if err := clusterapis.AddToScheme(mgr.GetScheme()); err != nil {
klog.Fatal(err)
}

apimachine.AddWithActuator(mgr, machine.Actuator)
apicluster.AddWithActuator(mgr, clusterActuator)

// Setup all Controllers
if err := controller.AddToManager(mgr); err != nil {
log.Error(err, "unable add AddToManager")
os.Exit(1)
}
capimachine.AddWithActuator(mgr, machineActuator)
capicluster.AddWithActuator(mgr, clusterActuator)

// Start the Cmd
log.Info("Starting the Cmd.")
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
log.Error(err, "unable to run the manager")
os.Exit(1)
}
}

func prepareEnvironment() error {
//Parse in environment variables if necessary
if os.Getenv("AZURE_SUBSCRIPTION_ID") == "" {
err := godotenv.Load()
if err == nil && os.Getenv("AZURE_SUBSCRIPTION_ID") == "" {
return fmt.Errorf("couldn't find environment variable for the Azure subscription: %v", err)
}
if err != nil {
return fmt.Errorf("failed to load environment variables: %v", err)
}
klog.Fatalf("Failed to run manager: %v", err)
}
return nil
}
17 changes: 17 additions & 0 deletions cmd/versioninfo/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = ["versioninfo.go"],
importpath = "sigs.k8s.io/cluster-api-provider-aws/cmd/versioninfo",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/spf13/cobra:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = ["versioninfo_test.go"],
embed = [":go_default_library"],
)
Loading

0 comments on commit 02aec24

Please sign in to comment.