Skip to content

Commit

Permalink
Support updated providerid
Browse files Browse the repository at this point in the history
  • Loading branch information
detiber committed Sep 28, 2021
1 parent 5c96390 commit ac8367c
Show file tree
Hide file tree
Showing 7 changed files with 733 additions and 67 deletions.
9 changes: 9 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ rules:
- get
- list
- watch
- apiGroups:
- bootstrap.cluster.x-k8s.io
resources:
- kubeadmconfigs
- kubeadmconfigs/status
verbs:
- get
- list
- watch
- apiGroups:
- cluster.x-k8s.io
resources:
Expand Down
13 changes: 6 additions & 7 deletions controllers/packetmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ package controllers

import (
"context"
"errors"
"fmt"
"net/http"
"strings"
"time"

corev1 "k8s.io/api/core/v1"

"github.com/go-logr/logr"
"github.com/google/uuid"
"github.com/packethost/packngo"
"github.com/pkg/errors"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -65,6 +63,7 @@ type PacketMachineReconciler struct {
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=packetmachines,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=packetmachines/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=machines;machines/status,verbs=get;list;watch
// +kubebuilder:rbac:groups=bootstrap.cluster.x-k8s.io,resources=kubeadmconfigs;kubeadmconfigs/status,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=secrets;,verbs=get;list;watch

func (r *PacketMachineReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, reterr error) {
Expand Down Expand Up @@ -132,7 +131,7 @@ func (r *PacketMachineReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
}

// Create the machine scope
machineScope, err := scope.NewMachineScope(scope.MachineScopeParams{
machineScope, err := scope.NewMachineScope(ctx, scope.MachineScopeParams{
Logger: logger,
Client: r.Client,
Cluster: cluster,
Expand All @@ -141,7 +140,7 @@ func (r *PacketMachineReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
PacketMachine: packetmachine,
})
if err != nil {
return ctrl.Result{}, errors.Errorf("failed to create scope: %+v", err)
return ctrl.Result{}, fmt.Errorf("failed to create scope: %w", err)
}

// Always close the scope when exiting this function so we can persist any PacketMachine changes.
Expand Down Expand Up @@ -298,7 +297,7 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
result = ctrl.Result{}
default:
machineScope.SetErrorReason(capierrors.UpdateMachineError)
machineScope.SetErrorMessage(errors.Errorf("Instance status %q is unexpected", dev.State))
machineScope.SetErrorMessage(fmt.Errorf("Instance status %q is unexpected", dev.State))
result = ctrl.Result{}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ require (
k8s.io/client-go v0.17.17
k8s.io/klog/v2 v2.0.0
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
sigs.k8s.io/cluster-api v0.3.16
sigs.k8s.io/cluster-api v0.3.23
sigs.k8s.io/controller-runtime v0.5.14
)
40 changes: 6 additions & 34 deletions go.sum

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ import (
"time"

"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2/klogr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"

packet "sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet"

infrastructurev1alpha3 "sigs.k8s.io/cluster-api-provider-packet/api/v1alpha3"
"sigs.k8s.io/cluster-api-provider-packet/controllers"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
packet "sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet"
// +kubebuilder:scaffold:imports
)

Expand All @@ -43,9 +44,11 @@ var (
)

func init() {
_ = clientgoscheme.AddToScheme(scheme)
_ = infrastructurev1alpha3.AddToScheme(scheme)
_ = clusterv1.AddToScheme(scheme)
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(infrastructurev1alpha3.AddToScheme(scheme))
utilruntime.Must(clusterv1.AddToScheme(scheme))
utilruntime.Must(bootstrapv1.AddToScheme(scheme))

// +kubebuilder:scaffold:scheme
}

Expand Down
Loading

0 comments on commit ac8367c

Please sign in to comment.