Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

Commit

Permalink
Add actuator skeleton.
Browse files Browse the repository at this point in the history
  • Loading branch information
russellb committed Jan 29, 2019
1 parent 071370c commit 1a6848c
Show file tree
Hide file tree
Showing 271 changed files with 20,130 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -10,3 +10,6 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

bin/*
provider-components.yaml
40 changes: 40 additions & 0 deletions Gopkg.lock

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

8 changes: 5 additions & 3 deletions Makefile
Expand Up @@ -22,12 +22,14 @@ install: manifests

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests
kubectl apply -f config/crds
kustomize build config/default | kubectl apply -f -
cat provider-components.yaml | kubectl apply -f -

# Generate manifests e.g. CRD, RBAC etc.
manifests:
go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go all
go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go crd
kustomize build config/default/ > provider-components.yaml
echo "---" >> provider-components.yaml
kustomize build vendor/sigs.k8s.io/cluster-api/config/default/ >> provider-components.yaml

# Run go fmt against code
fmt:
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1 +1 @@
# cluster-api-provider-bare-metal
# cluster-api-provider-baremetal
Binary file removed bin/manager
Binary file not shown.
61 changes: 28 additions & 33 deletions cmd/manager/main.go
Expand Up @@ -18,67 +18,62 @@ package main

import (
"flag"
"fmt"
"os"

"github.com/metalkube/cluster-api-provider-baremetal/pkg/apis"
"github.com/metalkube/cluster-api-provider-baremetal/pkg/controller"
"github.com/metalkube/cluster-api-provider-baremetal/pkg/webhook"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"github.com/metalkube/cluster-api-provider-baremetal/pkg/cloud/baremetal/actuators/machine"
clusterapis "sigs.k8s.io/cluster-api/pkg/apis"
"sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset"
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() {
var metricsAddr string
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
cfg := config.GetConfigOrDie()
if cfg == nil {
panic(fmt.Errorf("GetConfigOrDie didn't die"))
}

flag.Parse()
log := logf.Log.WithName("baremetal-controller-manager")
logf.SetLogger(logf.ZapLogger(false))
log := logf.Log.WithName("entrypoint")
entryLog := log.WithName("entrypoint")

// 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")
entryLog.Error(err, "unable to set up overall controller manager")
os.Exit(1)
}

// Create a new Cmd to provide shared dependencies and start components
log.Info("setting up manager")
mgr, err := manager.New(cfg, manager.Options{MetricsBindAddress: metricsAddr})
cs, err := clientset.NewForConfig(cfg)
if err != nil {
log.Error(err, "unable to set up overall controller manager")
os.Exit(1)
panic(err)
}

log.Info("Registering Components.")
machineActuator, err := machine.NewActuator(machine.ActuatorParams{
MachinesGetter: cs.ClusterV1alpha1(),
})
if err != nil {
panic(err)
}

// Setup Scheme for all resources
log.Info("setting up scheme")
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "unable add APIs to scheme")
os.Exit(1)
panic(err)
}

// Setup all Controllers
log.Info("Setting up controller")
if err := controller.AddToManager(mgr); err != nil {
log.Error(err, "unable to register controllers to the manager")
os.Exit(1)
if err := clusterapis.AddToScheme(mgr.GetScheme()); err != nil {
panic(err)
}

log.Info("setting up webhooks")
if err := webhook.AddToManager(mgr); err != nil {
log.Error(err, "unable to register webhooks to the manager")
os.Exit(1)
}
capimachine.AddWithActuator(mgr, machineActuator)

// Start the Cmd
log.Info("Starting the Cmd.")
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
log.Error(err, "unable to run the manager")
entryLog.Error(err, "unable to run manager")
os.Exit(1)
}
}
87 changes: 87 additions & 0 deletions pkg/cloud/baremetal/actuators/machine/actuator.go
@@ -0,0 +1,87 @@
/*
Copyright 2019 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 machine

import (
"context"
"fmt"
"log"

clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
client "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/typed/cluster/v1alpha1"
)

const (
ProviderName = "solas"
)

// Actuator is responsible for performing machine reconciliation
type Actuator struct {
machinesGetter client.MachinesGetter
}

// ActuatorParams holds parameter information for Actuator
type ActuatorParams struct {
MachinesGetter client.MachinesGetter
}

// NewActuator creates a new Actuator
func NewActuator(params ActuatorParams) (*Actuator, error) {
return &Actuator{
machinesGetter: params.MachinesGetter,
}, nil
}

// Create creates a machine and is invoked by the Machine Controller
func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
log.Printf("Creating machine %v for cluster %v.", machine.Name, cluster.Name)
return fmt.Errorf("TODO: Not yet implemented")
}

// Delete deletes a machine and is invoked by the Machine Controller
func (a *Actuator) Delete(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
log.Printf("Deleting machine %v for cluster %v.", machine.Name, cluster.Name)
return fmt.Errorf("TODO: Not yet implemented")
}

// Update updates a machine and is invoked by the Machine Controller
func (a *Actuator) Update(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
log.Printf("Updating machine %v for cluster %v.", machine.Name, cluster.Name)
return fmt.Errorf("TODO: Not yet implemented")
}

// Exists tests for the existence of a machine and is invoked by the Machine Controller
func (a *Actuator) Exists(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) (bool, error) {
log.Printf("Checking if machine %v for cluster %v exists.", machine.Name, cluster.Name)
return false, fmt.Errorf("TODO: Not yet implemented")
}

// The Machine Actuator interface must implement GetIP and GetKubeConfig functions as a workaround for issues
// cluster-api#158 (https://github.com/kubernetes-sigs/cluster-api/issues/158) and cluster-api#160
// (https://github.com/kubernetes-sigs/cluster-api/issues/160).

// GetIP returns IP address of the machine in the cluster.
func (a *Actuator) GetIP(cluster *clusterv1.Cluster, machine *clusterv1.Machine) (string, error) {
log.Printf("Getting IP of machine %v for cluster %v.", machine.Name, cluster.Name)
return "", fmt.Errorf("TODO: Not yet implemented")
}

// GetKubeConfig gets a kubeconfig from the running control plane.
func (a *Actuator) GetKubeConfig(cluster *clusterv1.Cluster, controlPlaneMachine *clusterv1.Machine) (string, error) {
log.Printf("Getting IP of machine %v for cluster %v.", controlPlaneMachine.Name, cluster.Name)
return "", fmt.Errorf("TODO: Not yet implemented")
}
31 changes: 31 additions & 0 deletions pkg/controller/add_machine.go
@@ -0,0 +1,31 @@
/*
Copyright 2019 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 controller

import (
"github.com/metalkube/cluster-api-provider-baremetal/pkg/cloud/baremetal/actuators/machine"
capimachine "sigs.k8s.io/cluster-api/pkg/controller/machine"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

//+kubebuilder:rbac:groups=baremetal.k8s.io,resources=baremetalmachineproviderspecs;baremetalmachineproviderstatuses,verbs=get;list;watch;create;update;patch;delete
func init() {
// AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
AddToManagerFuncs = append(AddToManagerFuncs, func(m manager.Manager) error {
return capimachine.AddWithActuator(m, &machine.Actuator{})
})
}

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

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

0 comments on commit 1a6848c

Please sign in to comment.