@@ -23,6 +23,7 @@ import (
23
23
"strings"
24
24
"time"
25
25
26
+ "github.com/google/uuid"
26
27
"github.com/packethost/cluster-api-provider-packet/pkg/cloud/packet"
27
28
"github.com/packethost/cluster-api-provider-packet/pkg/cloud/packet/actuators/machine/machineconfig"
28
29
"github.com/packethost/cluster-api-provider-packet/pkg/cloud/packet/deployer"
@@ -90,8 +91,11 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
90
91
return fmt .Errorf ("unable to unpack cluster provider: %v" , err )
91
92
}
92
93
94
+ // generate a unique UID that will survive pivot, i.e. is not tied to the cluster itself
95
+ mUID := uuid .New ().String ()
96
+
93
97
tags := []string {
94
- util .GenerateMachineTag (string ( machine . UID ) ),
98
+ util .GenerateMachineTag (mUID ),
95
99
util .GenerateClusterTag (string (cluster .Name )),
96
100
}
97
101
// generate userdata from the template
@@ -158,6 +162,7 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
158
162
159
163
machine .Annotations ["cluster-api-provider-packet" ] = "true"
160
164
machine .Annotations ["cluster.k8s.io/machine" ] = cluster .Name
165
+ machine .Annotations [util .AnnotationUID ] = mUID
161
166
162
167
if _ , err = a .updateMachine (cluster , machine ); err != nil {
163
168
return fmt .Errorf ("error updating Machine object with annotations: %v" , err )
@@ -177,10 +182,10 @@ func (a *Actuator) Delete(ctx context.Context, cluster *clusterv1.Cluster, machi
177
182
log .Printf ("Deleting machine %v for cluster %v." , machine .Name , cluster .Name )
178
183
device , err := a .packetClient .GetDevice (machine )
179
184
if err != nil {
180
- return fmt .Errorf ("error retrieving machine status %s: %v" , machine .UID , err )
185
+ return fmt .Errorf ("error retrieving machine status %s: %v" , machine .Name , err )
181
186
}
182
187
if device == nil {
183
- return fmt .Errorf ("machine does not exist: %s" , machine .UID )
188
+ return fmt .Errorf ("machine does not exist: %s" , machine .Name )
184
189
}
185
190
186
191
_ , err = a .packetClient .Devices .Delete (device .ID )
@@ -211,7 +216,7 @@ func (a *Actuator) Update(ctx context.Context, cluster *clusterv1.Cluster, machi
211
216
// - check if anything mutable has changed, in which case we update the instance
212
217
device , err := a .packetClient .GetDevice (machine )
213
218
if err != nil {
214
- return fmt .Errorf ("error retrieving machine status %s: %v" , machine .UID , err )
219
+ return fmt .Errorf ("error retrieving machine status %s: %v" , machine .Name , err )
215
220
}
216
221
if device == nil {
217
222
return fmt .Errorf ("received nil machine" )
@@ -246,7 +251,7 @@ func (a *Actuator) Exists(ctx context.Context, cluster *clusterv1.Cluster, machi
246
251
log .Printf ("Checking if machine %v for cluster %v exists." , machine .Name , cluster .Name )
247
252
device , err := a .packetClient .GetDevice (machine )
248
253
if err != nil {
249
- return false , fmt .Errorf ("error retrieving machine status %s: %v" , machine .UID , err )
254
+ return false , fmt .Errorf ("error retrieving machine status %s: %v" , machine .Name , err )
250
255
}
251
256
if device == nil {
252
257
return false , nil
@@ -264,7 +269,7 @@ func (a *Actuator) get(machine *clusterv1.Machine) (*packngo.Device, error) {
264
269
return device , nil
265
270
}
266
271
267
- return nil , fmt .Errorf ("Device %s not found" , machine .UID )
272
+ return nil , fmt .Errorf ("Device %s not found" , machine .Name )
268
273
}
269
274
270
275
func (a * Actuator ) updateMachine (cluster * clusterv1.Cluster , machine * clusterv1.Machine ) (* clusterv1.Machine , error ) {
0 commit comments