@@ -28,6 +28,7 @@ import (
28
28
"github.com/packethost/cluster-api-provider-packet/pkg/cloud/packet/util"
29
29
"github.com/packethost/packngo"
30
30
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
31
+ client "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/typed/cluster/v1alpha1"
31
32
)
32
33
33
34
const (
@@ -41,6 +42,7 @@ const (
41
42
42
43
// Actuator is responsible for performing machine reconciliation
43
44
type Actuator struct {
45
+ machinesGetter client.MachinesGetter
44
46
packetClient * packet.PacketClient
45
47
machineConfigGetter machineconfig.Getter
46
48
deployer * deployer.Deployer
@@ -49,6 +51,7 @@ type Actuator struct {
49
51
50
52
// ActuatorParams holds parameter information for Actuator
51
53
type ActuatorParams struct {
54
+ MachinesGetter client.MachinesGetter
52
55
MachineConfigGetter machineconfig.Getter
53
56
Client * packet.PacketClient
54
57
Deployer * deployer.Deployer
@@ -58,6 +61,7 @@ type ActuatorParams struct {
58
61
// NewActuator creates a new Actuator
59
62
func NewActuator (params ActuatorParams ) (* Actuator , error ) {
60
63
return & Actuator {
64
+ machinesGetter : params .MachinesGetter ,
61
65
packetClient : params .Client ,
62
66
machineConfigGetter : params .MachineConfigGetter ,
63
67
deployer : params .Deployer ,
@@ -133,6 +137,18 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
133
137
return fmt .Errorf ("failed to create server: %v" , err )
134
138
}
135
139
140
+ // add the annotations so that cluster-api knows it is there (also, because it is useful to have)
141
+ if machine .Annotations == nil {
142
+ machine .Annotations = map [string ]string {}
143
+ }
144
+
145
+ machine .Annotations ["cluster-api-provider-packet" ] = "true"
146
+ machine .Annotations ["cluster.k8s.io/machine" ] = cluster .Name
147
+
148
+ if _ , err = a .updateMachine (cluster , machine ); err != nil {
149
+ return fmt .Errorf ("error updating Machine object with annotations: %v" , err )
150
+ }
151
+
136
152
return nil
137
153
}
138
154
@@ -237,6 +253,21 @@ func (a *Actuator) get(machine *clusterv1.Machine) (*packngo.Device, error) {
237
253
return nil , fmt .Errorf ("Device %s not found" , machine .UID )
238
254
}
239
255
256
+ func (a * Actuator ) updateMachine (cluster * clusterv1.Cluster , machine * clusterv1.Machine ) (* clusterv1.Machine , error ) {
257
+ var (
258
+ machineClient client.MachineInterface
259
+ updatedMachine * clusterv1.Machine
260
+ err error
261
+ )
262
+ if a .machinesGetter != nil {
263
+ machineClient = a .machinesGetter .Machines (cluster .Namespace )
264
+ }
265
+ if updatedMachine , err = machineClient .Update (machine ); err != nil {
266
+ return nil , err
267
+ }
268
+ return updatedMachine , nil
269
+ }
270
+
240
271
func changedImmutable (projectID string , device * packngo.Device , machine * clusterv1.Machine ) error {
241
272
errors := []string {}
242
273
machineConfig , err := util .MachineProviderFromProviderConfig (machine .Spec .ProviderSpec )
0 commit comments