Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit e59d076

Browse files
authored
Merge pull request #29 from packethost/creation-id
handle no ID on creation
2 parents b430e34 + b0bbc4b commit e59d076

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

controllers/packetmachine_controller.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/go-logr/logr"
2626
"github.com/google/uuid"
27+
"github.com/packethost/packngo"
2728
"github.com/pkg/errors"
2829

2930
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -184,9 +185,17 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
184185
return ctrl.Result{}, nil
185186
}
186187

187-
dev, err := r.PacketClient.GetDevice(machineScope.GetInstanceID())
188-
if err != nil {
189-
return ctrl.Result{}, err
188+
providerID := machineScope.GetInstanceID()
189+
var (
190+
dev *packngo.Device
191+
err error
192+
)
193+
// if we have no provider ID, then we are creating
194+
if providerID != "" {
195+
dev, err = r.PacketClient.GetDevice(providerID)
196+
if err != nil {
197+
return ctrl.Result{}, err
198+
}
190199
}
191200
if dev == nil {
192201
// generate a unique UID that will survive pivot, i.e. is not tied to the cluster itself
@@ -210,7 +219,8 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
210219
}
211220
}
212221

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

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

0 commit comments

Comments
 (0)