@@ -23,16 +23,16 @@ import (
2323	"strings" 
2424	"time" 
2525
26- 	corev1 "k8s.io/api/core/v1" 
27- 
2826	"github.com/go-logr/logr" 
29- 	"github.com/google/uuid" 
3027	"github.com/packethost/packngo" 
3128	"github.com/pkg/errors" 
32- 
29+ 	corev1  "k8s.io/api/core/v1" 
3330	apierrors "k8s.io/apimachinery/pkg/api/errors" 
3431	"k8s.io/apimachinery/pkg/runtime" 
3532	"k8s.io/client-go/tools/record" 
33+ 	infrastructurev1alpha3 "sigs.k8s.io/cluster-api-provider-packet/api/v1alpha3" 
34+ 	packet "sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet" 
35+ 	"sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet/scope" 
3636	clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" 
3737	capierrors "sigs.k8s.io/cluster-api/errors" 
3838	"sigs.k8s.io/cluster-api/util" 
@@ -42,11 +42,6 @@ import (
4242	"sigs.k8s.io/controller-runtime/pkg/handler" 
4343	"sigs.k8s.io/controller-runtime/pkg/reconcile" 
4444	"sigs.k8s.io/controller-runtime/pkg/source" 
45- 
46- 	packet "sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet" 
47- 	"sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet/scope" 
48- 
49- 	infrastructurev1alpha3 "sigs.k8s.io/cluster-api-provider-packet/api/v1alpha3" 
5045)
5146
5247const  (
@@ -195,6 +190,13 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
195190	}
196191
197192	providerID  :=  machineScope .GetInstanceID ()
193+ 
194+ 	defaultTags  :=  []string {
195+ 		packet .GenerateClusterTag (clusterScope .Name ()),
196+ 		packet .GenerateMachineNameTag (machineScope .Name ()),
197+ 		packet .GenerateNamespaceTag (machineScope .Namespace ()),
198+ 	}
199+ 
198200	var  (
199201		dev                   * packngo.Device 
200202		addrs                 []corev1.NodeAddress 
@@ -208,15 +210,22 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
208210			return  ctrl.Result {}, err 
209211		}
210212	}
213+ 
214+ 	if  dev  ==  nil  {
215+ 		dev , err  =  r .PacketClient .GetDeviceByTags (
216+ 			machineScope .PacketCluster .Spec .ProjectID ,
217+ 			defaultTags ,
218+ 		)
219+ 		if  err  !=  nil  {
220+ 			return  ctrl.Result {}, err 
221+ 		}
222+ 	}
223+ 
211224	if  dev  ==  nil  {
212225		createDeviceReq  :=  packet.CreateDeviceRequest {
226+ 			ExtraTags :    defaultTags ,
213227			MachineScope : machineScope ,
214228		}
215- 		mUID  :=  uuid .New ().String ()
216- 		tags  :=  []string {
217- 			packet .GenerateMachineTag (mUID ),
218- 			packet .GenerateClusterTag (clusterScope .Name ()),
219- 		}
220229
221230		// when the node is a control plan we should check if the elastic ip 
222231		// for this cluster is not assigned. If it is free we can prepare the 
@@ -236,8 +245,6 @@ func (r *PacketMachineReconciler) reconcile(ctx context.Context, machineScope *s
236245			createDeviceReq .ControlPlaneEndpoint  =  controlPlaneEndpoint .Address 
237246		}
238247
239- 		createDeviceReq .ExtraTags  =  tags 
240- 
241248		dev , err  =  r .PacketClient .NewDevice (createDeviceReq )
242249
243250		switch  {
0 commit comments