Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Support updated providerid #290

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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