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

Commit 75d950b

Browse files
committed
Do not add annotations to Machine until it has an IP
1 parent 46b5a7f commit 75d950b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cloud/packet/actuators/machine/actuator.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"log"
2323
"strings"
24+
"time"
2425

2526
"github.com/packethost/cluster-api-provider-packet/pkg/cloud/packet"
2627
"github.com/packethost/cluster-api-provider-packet/pkg/cloud/packet/actuators/machine/machineconfig"
@@ -29,10 +30,13 @@ import (
2930
"github.com/packethost/packngo"
3031
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
3132
client "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/typed/cluster/v1alpha1"
33+
capiutil "sigs.k8s.io/cluster-api/pkg/util"
3234
)
3335

3436
const (
35-
ProviderName = "packet"
37+
ProviderName = "packet"
38+
retryIntervalMachineReady = 10 * time.Second
39+
timeoutMachineReady = 10 * time.Minute
3640
)
3741

3842
// Add RBAC rules to access cluster-api resources
@@ -138,11 +142,15 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
138142
Tags: tags,
139143
}
140144

141-
_, _, err = a.packetClient.Devices.Create(serverCreateOpts)
145+
device, _, err := a.packetClient.Devices.Create(serverCreateOpts)
142146
if err != nil {
143147
return fmt.Errorf("failed to create server: %v", err)
144148
}
145149

150+
// we need to loop here until the device exists and has an IP address
151+
log.Printf("Created device, waiting for it to be ready")
152+
a.waitForMachineReady(device)
153+
146154
// add the annotations so that cluster-api knows it is there (also, because it is useful to have)
147155
if machine.Annotations == nil {
148156
machine.Annotations = map[string]string{}
@@ -274,6 +282,21 @@ func (a *Actuator) updateMachine(cluster *clusterv1.Cluster, machine *clusterv1.
274282
return updatedMachine, nil
275283
}
276284

285+
func (a *Actuator) waitForMachineReady(device *packngo.Device) error {
286+
err := capiutil.PollImmediate(retryIntervalMachineReady, timeoutMachineReady, func() (bool, error) {
287+
fmt.Printf("Waiting for device %v to become ready...", device.ID)
288+
dev, _, err := a.packetClient.Devices.Get(device.ID, nil)
289+
if err != nil {
290+
return false, nil
291+
}
292+
293+
ready := dev.Network == nil || len(dev.Network) == 0 || dev.Network[0].Address == ""
294+
return ready, nil
295+
})
296+
297+
return err
298+
}
299+
277300
func changedImmutable(projectID string, device *packngo.Device, machine *clusterv1.Machine) error {
278301
errors := []string{}
279302
machineConfig, err := util.MachineProviderFromProviderConfig(machine.Spec.ProviderSpec)

0 commit comments

Comments
 (0)