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

Commit 65da610

Browse files
committed
record annotations on machine
1 parent d8effdd commit 65da610

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

cmd/manager/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ func main() {
8585
klog.Fatalf(err.Error())
8686
}
8787

88+
clusterInterface := cs.ClusterV1alpha1()
8889
clusterActuator, err := cluster.NewActuator(cluster.ActuatorParams{
89-
ClustersGetter: cs.ClusterV1alpha1(),
90+
ClustersGetter: clusterInterface,
9091
Deployer: deployer,
9192
})
9293
if err != nil {
@@ -100,6 +101,7 @@ func main() {
100101
}
101102

102103
machineActuator, err := machine.NewActuator(machine.ActuatorParams{
104+
MachinesGetter: clusterInterface,
103105
MachineConfigGetter: getter,
104106
Client: client,
105107
Deployer: deployer,

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/packethost/cluster-api-provider-packet/pkg/cloud/packet/util"
2929
"github.com/packethost/packngo"
3030
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"
3132
)
3233

3334
const (
@@ -41,6 +42,7 @@ const (
4142

4243
// Actuator is responsible for performing machine reconciliation
4344
type Actuator struct {
45+
machinesGetter client.MachinesGetter
4446
packetClient *packet.PacketClient
4547
machineConfigGetter machineconfig.Getter
4648
deployer *deployer.Deployer
@@ -49,6 +51,7 @@ type Actuator struct {
4951

5052
// ActuatorParams holds parameter information for Actuator
5153
type ActuatorParams struct {
54+
MachinesGetter client.MachinesGetter
5255
MachineConfigGetter machineconfig.Getter
5356
Client *packet.PacketClient
5457
Deployer *deployer.Deployer
@@ -58,6 +61,7 @@ type ActuatorParams struct {
5861
// NewActuator creates a new Actuator
5962
func NewActuator(params ActuatorParams) (*Actuator, error) {
6063
return &Actuator{
64+
machinesGetter: params.MachinesGetter,
6165
packetClient: params.Client,
6266
machineConfigGetter: params.MachineConfigGetter,
6367
deployer: params.Deployer,
@@ -133,6 +137,18 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
133137
return fmt.Errorf("failed to create server: %v", err)
134138
}
135139

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+
136152
return nil
137153
}
138154

@@ -237,6 +253,21 @@ func (a *Actuator) get(machine *clusterv1.Machine) (*packngo.Device, error) {
237253
return nil, fmt.Errorf("Device %s not found", machine.UID)
238254
}
239255

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+
240271
func changedImmutable(projectID string, device *packngo.Device, machine *clusterv1.Machine) error {
241272
errors := []string{}
242273
machineConfig, err := util.MachineProviderFromProviderConfig(machine.Spec.ProviderSpec)

0 commit comments

Comments
 (0)