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

Commit

Permalink
Rename 'BareMetal' to 'ExistingInfra'
Browse files Browse the repository at this point in the history
Also standardise the import name 'existinginfrav1'
  • Loading branch information
bboreham authored and twelho committed Jul 27, 2020
1 parent 8f84574 commit dc35e6f
Show file tree
Hide file tree
Showing 28 changed files with 237 additions and 236 deletions.
4 changes: 2 additions & 2 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
wks "github.com/weaveworks/wksctl/pkg/apis/wksprovider/controller/wksctl"
baremetalv1 "github.com/weaveworks/wksctl/pkg/baremetal/v1alpha3"
machineutil "github.com/weaveworks/wksctl/pkg/cluster/machine"
existinginfrav1 "github.com/weaveworks/wksctl/pkg/existinginfra/v1alpha3"
"k8s.io/client-go/kubernetes"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -91,7 +91,7 @@ func run(cmd *cobra.Command, args []string) {
}

log.Info("registering scheme for all resources")
if err := baremetalv1.AddToScheme(mgr.GetScheme()); err != nil {
if err := existinginfrav1.AddToScheme(mgr.GetScheme()); err != nil {
log.Fatal(err)
}
if err := clusterv1.AddToScheme(mgr.GetScheme()); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/wksctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/weaveworks/wksctl/cmd/wksctl/registrysynccommands"
"github.com/weaveworks/wksctl/cmd/wksctl/version"
"github.com/weaveworks/wksctl/cmd/wksctl/zshcompletions"
baremetalv1 "github.com/weaveworks/wksctl/pkg/baremetal/v1alpha3"
existinginfrav1 "github.com/weaveworks/wksctl/pkg/existinginfra/v1alpha3"
v "github.com/weaveworks/wksctl/pkg/version"
)

Expand Down Expand Up @@ -48,7 +48,7 @@ func main() {
if err := clusterv1.AddToScheme(scheme.Scheme); err != nil {
log.Fatal(err)
}
if err := baremetalv1.AddToScheme(scheme.Scheme); err != nil {
if err := existinginfrav1.AddToScheme(scheme.Scheme); err != nil {
log.Fatal(err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
creationTimestamp: null
name: baremetalclusters.cluster.weave.works
name: existinginfraclusters.cluster.weave.works
labels:
cluster.x-k8s.io/v1alpha3: v1alpha3
spec:
group: cluster.weave.works
names:
kind: BareMetalCluster
listKind: BareMetalClusterList
plural: baremetalclusters
singular: baremetalcluster
kind: ExistingInfraCluster
listKind: ExistingInfraClusterList
plural: existinginfraclusters
singular: existinginfracluster
scope: Namespaced
validation:
openAPIV3Schema:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
creationTimestamp: null
name: baremetalmachines.cluster.weave.works
name: existinginframachines.cluster.weave.works
labels:
cluster.x-k8s.io/v1alpha3: v1alpha3
spec:
group: cluster.weave.works
names:
kind: BareMetalMachine
listKind: BareMetalMachineList
plural: baremetalmachines
singular: baremetalmachine
kind: ExistingInfraMachine
listKind: ExistingInfraMachineList
plural: existinginframachines
singular: existinginframachine
scope: Namespaced
validation:
openAPIV3Schema:
Expand Down
6 changes: 3 additions & 3 deletions docs/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Here's an example of the cluster definition. It is spread across two
objects: a `Cluster` which is defined by Kubernetes ClusterAPI and a
`BareMetalCluster` defined by Weaveworks. Here, both objects have the
`ExistingInfraCluster` defined by Weaveworks. Here, both objects have the
same name `example`, and the field `infrastructureRef` points from one
to the other.

Expand All @@ -20,11 +20,11 @@ spec:
serviceDomain: cluster.local
infrastructureRef:
apiVersion: cluster.weave.works/v1alpha3
kind: BareMetalCluster
kind: ExistingInfraCluster
name: example
---
apiVersion: cluster.weave.works/v1alpha3
kind: BareMetalCluster
kind: ExistingInfraCluster
metadata:
name: example
spec:
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/wksprovider/controller/manifests/yaml/02_rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ rules:
- apiGroups:
- cluster.weave.works
resources:
- baremetalclusters
- baremetalclusters/status
- baremetalmachines
- baremetalmachines/status
- existinginfraclusters
- existinginfraclusters/status
- existinginframachines
- existinginframachines/status
verbs:
- get
- list
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/wksprovider/controller/wksctl/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"

log "github.com/sirupsen/logrus"
baremetalspecv1 "github.com/weaveworks/wksctl/pkg/baremetal/v1alpha3"
existinginfrav1 "github.com/weaveworks/wksctl/pkg/existinginfra/v1alpha3"
corev1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -30,7 +30,7 @@ func (a *ClusterReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr e
contextLog := log.WithField("name", req.NamespacedName)

// request only contains the name of the object, so fetch it from the api-server
bmc := &baremetalspecv1.BareMetalCluster{}
bmc := &existinginfrav1.ExistingInfraCluster{}
err := a.client.Get(ctx, req.NamespacedName, bmc)
if err != nil {
if apierrs.IsNotFound(err) { // isn't there; give in
Expand All @@ -51,7 +51,7 @@ func (a *ClusterReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr e
contextLog = contextLog.WithField("cluster", cluster.Name)

if util.IsPaused(cluster, bmc) {
contextLog.Info("BareMetalCluster or linked Cluster is marked as paused. Won't reconcile")
contextLog.Info("ExistingInfraCluster or linked Cluster is marked as paused. Won't reconcile")
return ctrl.Result{}, nil
}

Expand All @@ -61,10 +61,10 @@ func (a *ClusterReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr e
return ctrl.Result{}, err
}

// Attempt to Patch the BareMetalMachine object and status after each reconciliation.
// Attempt to Patch the ExistingInfraMachine object and status after each reconciliation.
defer func() {
if err := patchHelper.Patch(ctx, bmc); err != nil {
contextLog.Errorf("failed to patch BareMetalCluster: %v", err)
contextLog.Errorf("failed to patch ExistingInfraCluster: %v", err)
if reterr == nil {
reterr = err
}
Expand All @@ -85,7 +85,7 @@ func (a *ClusterReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr e
func (r *ClusterReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
controller, err := ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&baremetalspecv1.BareMetalCluster{}).
For(&existinginfrav1.ExistingInfraCluster{}).
WithEventFilter(pausedPredicates()).
Build(r)

Expand Down
38 changes: 19 additions & 19 deletions pkg/apis/wksprovider/controller/wksctl/machine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
log "github.com/sirupsen/logrus"
"github.com/weaveworks/wksctl/pkg/apis/wksprovider/machine/config"
"github.com/weaveworks/wksctl/pkg/apis/wksprovider/machine/os"
baremetalspecv1 "github.com/weaveworks/wksctl/pkg/baremetal/v1alpha3"
machineutil "github.com/weaveworks/wksctl/pkg/cluster/machine"
existinginfrav1 "github.com/weaveworks/wksctl/pkg/existinginfra/v1alpha3"
"github.com/weaveworks/wksctl/pkg/kubernetes/drain"
"github.com/weaveworks/wksctl/pkg/plan"
"github.com/weaveworks/wksctl/pkg/plan/recipe"
Expand Down Expand Up @@ -70,7 +70,7 @@ func (r *MachineController) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr e
contextLog := log.WithField("name", req.NamespacedName)

// request only contains the name of the object, so fetch it from the api-server
bmm := &baremetalspecv1.BareMetalMachine{}
bmm := &existinginfrav1.ExistingInfraMachine{}
err := r.client.Get(ctx, req.NamespacedName, bmm)
if err != nil {
if apierrs.IsNotFound(err) { // isn't there; give in
Expand Down Expand Up @@ -98,22 +98,22 @@ func (r *MachineController) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr e
}

if util.IsPaused(cluster, bmm) {
contextLog.Info("BareMetalMachine or linked Cluster is marked as paused. Won't reconcile")
contextLog.Info("ExistingInfraMachine or linked Cluster is marked as paused. Won't reconcile")
return ctrl.Result{}, nil
}
contextLog = contextLog.WithField("cluster", cluster.Name)

// Now go from the Cluster to the BareMetalCluster
// Now go from the Cluster to the ExistingInfraCluster
if cluster.Spec.InfrastructureRef == nil || cluster.Spec.InfrastructureRef.Name == "" {
contextLog.Info("Cluster is missing infrastructureRef")
return ctrl.Result{}, nil
}
bmc := &baremetalspecv1.BareMetalCluster{}
bmc := &existinginfrav1.ExistingInfraCluster{}
if err := r.client.Get(ctx, client.ObjectKey{
Namespace: bmm.Namespace,
Name: cluster.Spec.InfrastructureRef.Name,
}, bmc); err != nil {
contextLog.Info("BareMetalCluster is not available yet")
contextLog.Info("ExistingInfraCluster is not available yet")
return ctrl.Result{}, nil
}

Expand All @@ -122,10 +122,10 @@ func (r *MachineController) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr e
if err != nil {
return ctrl.Result{}, err
}
// Attempt to Patch the BareMetalMachine object and status after each reconciliation.
// Attempt to Patch the ExistingInfraMachine object and status after each reconciliation.
defer func() {
if err := patchHelper.Patch(ctx, bmm); err != nil {
contextLog.Errorf("failed to patch BareMetalMachine: %v", err)
contextLog.Errorf("failed to patch ExistingInfraMachine: %v", err)
if reterr == nil {
reterr = err
}
Expand All @@ -148,7 +148,7 @@ func (r *MachineController) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr e
return ctrl.Result{}, err
}

func (a *MachineController) create(ctx context.Context, installer *os.OS, c *baremetalspecv1.BareMetalCluster, machine *clusterv1.Machine, bmm *baremetalspecv1.BareMetalMachine) error {
func (a *MachineController) create(ctx context.Context, installer *os.OS, c *existinginfrav1.ExistingInfraCluster, machine *clusterv1.Machine, bmm *existinginfrav1.ExistingInfraMachine) error {
contextLog := log.WithFields(log.Fields{"machine": machine.Name, "cluster": c.Name})
contextLog.Info("creating machine...")

Expand Down Expand Up @@ -180,7 +180,7 @@ func (a *MachineController) create(ctx context.Context, installer *os.OS, c *bar
return nil
}

func (a *MachineController) connectTo(ctx context.Context, c *baremetalspecv1.BareMetalCluster, m *baremetalspecv1.BareMetalMachine) (*os.OS, io.Closer, error) {
func (a *MachineController) connectTo(ctx context.Context, c *existinginfrav1.ExistingInfraCluster, m *existinginfrav1.ExistingInfraMachine) (*os.OS, io.Closer, error) {
sshKey, err := a.sshKey(ctx)
if err != nil {
return nil, nil, gerrors.Wrap(err, "failed to read SSH key")
Expand Down Expand Up @@ -315,7 +315,7 @@ func (a *MachineController) installNewBootstrapToken(ctx context.Context, ns str
}

// Delete the machine. If no error is returned, it is assumed that all dependent resources have been cleaned up.
func (a *MachineController) delete(ctx context.Context, c *baremetalspecv1.BareMetalCluster, machine *clusterv1.Machine, bmm *baremetalspecv1.BareMetalMachine) error {
func (a *MachineController) delete(ctx context.Context, c *existinginfrav1.ExistingInfraCluster, machine *clusterv1.Machine, bmm *existinginfrav1.ExistingInfraMachine) error {
contextLog := log.WithFields(log.Fields{"machine": machine.Name, "cluster": c.Name})
contextLog.Info("deleting machine ...")

Expand Down Expand Up @@ -356,7 +356,7 @@ func (a *MachineController) delete(ctx context.Context, c *baremetalspecv1.BareM
}

// Update the machine to the provided definition.
func (a *MachineController) update(ctx context.Context, c *baremetalspecv1.BareMetalCluster, machine *clusterv1.Machine, bmm *baremetalspecv1.BareMetalMachine) error {
func (a *MachineController) update(ctx context.Context, c *existinginfrav1.ExistingInfraCluster, machine *clusterv1.Machine, bmm *existinginfrav1.ExistingInfraMachine) error {
contextLog := log.WithFields(log.Fields{"machine": machine.Name, "cluster": c.Name})
contextLog.Info("updating machine...")
installer, closer, err := a.connectTo(ctx, c, bmm)
Expand Down Expand Up @@ -531,7 +531,7 @@ func (a *MachineController) performActualUpdate(
machine *clusterv1.Machine,
node *corev1.Node,
nodePlan *plan.Plan,
cluster *baremetalspecv1.BareMetalCluster) error {
cluster *existinginfrav1.ExistingInfraCluster) error {
if err := drain.Drain(node, a.clientSet, drain.Params{
Force: true,
DeleteLocalData: true,
Expand All @@ -548,7 +548,7 @@ func (a *MachineController) performActualUpdate(
return nil
}

func (a *MachineController) getNodePlan(ctx context.Context, provider *baremetalspecv1.BareMetalCluster, machine *clusterv1.Machine, machineAddress string, installer *os.OS) (*plan.Plan, error) {
func (a *MachineController) getNodePlan(ctx context.Context, provider *existinginfrav1.ExistingInfraCluster, machine *clusterv1.Machine, machineAddress string, installer *os.OS) (*plan.Plan, error) {
namespace := a.controllerNamespace
secrets, err := a.kubeadmJoinSecrets(ctx)
if err != nil {
Expand Down Expand Up @@ -641,7 +641,7 @@ func (a *MachineController) getAuthSecrets(ctx context.Context, authConfigMap *v
return authSecrets, nil
}

func (a *MachineController) getProviderConfigMaps(ctx context.Context, provider *baremetalspecv1.BareMetalCluster) (map[string]*v1.ConfigMap, error) {
func (a *MachineController) getProviderConfigMaps(ctx context.Context, provider *existinginfrav1.ExistingInfraCluster) (map[string]*v1.ConfigMap, error) {
fileSpecs := provider.Spec.OS.Files
client := a.clientSet.CoreV1().ConfigMaps(a.controllerNamespace)
configMaps := map[string]*v1.ConfigMap{}
Expand Down Expand Up @@ -990,18 +990,18 @@ func (a *MachineController) recordEvent(object runtime.Object, eventType, reason
}
}

func (a *MachineController) getMachineAddress(m *baremetalspecv1.BareMetalMachine) string {
func (a *MachineController) getMachineAddress(m *existinginfrav1.ExistingInfraMachine) string {
return m.Spec.Private.Address
}

func (a *MachineController) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
controller, err := ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&baremetalspecv1.BareMetalMachine{}).
For(&existinginfrav1.ExistingInfraMachine{}).
Watches(
&source.Kind{Type: &clusterv1.Machine{}},
&handler.EnqueueRequestsFromMapFunc{
ToRequests: util.MachineToInfrastructureMapFunc(baremetalspecv1.SchemeGroupVersion.WithKind("BareMetalMachine")),
ToRequests: util.MachineToInfrastructureMapFunc(existinginfrav1.SchemeGroupVersion.WithKind("ExistingInfraMachine")),
},
).
// TODO: add watch to reconcile all machines that need it
Expand All @@ -1024,7 +1024,7 @@ type MachineControllerParams struct {
Verbose bool
}

// NewMachineController creates a new baremetal machine reconciler.
// NewMachineController creates a new existinginfra machine reconciler.
func NewMachineController(params MachineControllerParams) (*MachineController, error) {
return &MachineController{
client: params.Client,
Expand Down
Loading

0 comments on commit dc35e6f

Please sign in to comment.