Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.
Merged
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
18 changes: 14 additions & 4 deletions controllers/packetmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

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

apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -180,9 +181,17 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
return ctrl.Result{}, nil
}

dev, err := r.PacketClient.GetDevice(machineScope.GetInstanceID())
if err != nil {
return ctrl.Result{}, err
providerID := machineScope.GetInstanceID()
var (
dev *packngo.Device
err error
)
// if we have no provider ID, then we are creating
if providerID != "" {
dev, err = r.PacketClient.GetDevice(providerID)
if err != nil {
return ctrl.Result{}, err
}
}
if dev == nil {
// generate a unique UID that will survive pivot, i.e. is not tied to the cluster itself
Expand All @@ -206,7 +215,8 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
}
}

machineScope.SetProviderID(fmt.Sprintf("%s://%s", providerName, dev.ID))
// we do not need to set this as packet://<id> because SetProviderID() does the formatting for us
machineScope.SetProviderID(dev.ID)
machineScope.SetInstanceStatus(infrastructurev1alpha3.PacketResourceStatus(dev.State))

addrs, err := r.PacketClient.GetDeviceAddresses(dev)
Expand Down