@@ -67,15 +67,21 @@ func (p *PacketClient) GetDevice(deviceID string) (*packngo.Device, error) {
6767 return dev , err
6868}
6969
70- func (p * PacketClient ) NewDevice (machineScope * scope.MachineScope , extraTags []string ) (* packngo.Device , error ) {
71- userDataRaw , err := machineScope .GetRawBootstrapData ()
70+ type CreateDeviceRequest struct {
71+ ExtraTags []string
72+ MachineScope * scope.MachineScope
73+ ControlPlaneEndpoint string
74+ }
75+
76+ func (p * PacketClient ) NewDevice (req CreateDeviceRequest ) (* packngo.Device , error ) {
77+ userDataRaw , err := req .MachineScope .GetRawBootstrapData ()
7278 if err != nil {
7379 return nil , errors .Wrap (err , "impossible to retrieve bootstrap data from secret" )
7480 }
7581
7682 userData := string (userDataRaw )
77- tags := append (machineScope . PacketMachine .Spec .Tags , extraTags ... )
78- if machineScope .IsControlPlane () {
83+ tags := append (req . MachineScope . PacketMachine .Spec .Tags , req . ExtraTags ... )
84+ if req . MachineScope .IsControlPlane () {
7985 // control plane machines should get the API key injected
8086 tmpl , err := template .New ("control-plane-user-data" ).Parse (userData )
8187 if err != nil {
@@ -85,6 +91,9 @@ func (p *PacketClient) NewDevice(machineScope *scope.MachineScope, extraTags []s
8591 apiKeyStruct := map [string ]interface {}{
8692 "apiKey" : p .Client .APIKey ,
8793 }
94+ if req .ControlPlaneEndpoint != "" {
95+ apiKeyStruct ["controlPlaneEndpoint" ] = req .ControlPlaneEndpoint
96+ }
8897 if err := tmpl .Execute (stringWriter , apiKeyStruct ); err != nil {
8998 return nil , fmt .Errorf ("error executing control-plane userdata template: %v" , err )
9099 }
@@ -94,24 +103,24 @@ func (p *PacketClient) NewDevice(machineScope *scope.MachineScope, extraTags []s
94103 tags = append (tags , infrastructurev1alpha3 .WorkerTag )
95104 }
96105 serverCreateOpts := & packngo.DeviceCreateRequest {
97- Hostname : machineScope .Name (),
98- ProjectID : machineScope .PacketCluster .Spec .ProjectID ,
99- Facility : []string {machineScope .PacketCluster .Spec .Facility },
100- BillingCycle : machineScope .PacketMachine .Spec .BillingCycle ,
101- HardwareReservationID : machineScope .PacketMachine .Spec .HardwareReservationID ,
102- Plan : machineScope .PacketMachine .Spec .MachineType ,
103- OS : machineScope .PacketMachine .Spec .OS ,
106+ Hostname : req . MachineScope .Name (),
107+ ProjectID : req . MachineScope .PacketCluster .Spec .ProjectID ,
108+ Facility : []string {req . MachineScope .PacketCluster .Spec .Facility },
109+ BillingCycle : req . MachineScope .PacketMachine .Spec .BillingCycle ,
110+ HardwareReservationID : req . MachineScope .PacketMachine .Spec .HardwareReservationID ,
111+ Plan : req . MachineScope .PacketMachine .Spec .MachineType ,
112+ OS : req . MachineScope .PacketMachine .Spec .OS ,
104113 Tags : tags ,
105114 UserData : userData ,
106115 }
107116
108117 // Update server options to pass pxe url if specified
109- if machineScope .PacketMachine .Spec .IPXEUrl != "" {
118+ if req . MachineScope .PacketMachine .Spec .IPXEUrl != "" {
110119 // Error if pxe url and OS conflict
111- if machineScope .PacketMachine .Spec .OS != ipxeOS {
120+ if req . MachineScope .PacketMachine .Spec .OS != ipxeOS {
112121 return nil , fmt .Errorf ("os should be set to custom_pxe when using pxe urls" )
113122 }
114- serverCreateOpts .IPXEScriptURL = machineScope .PacketMachine .Spec .IPXEUrl
123+ serverCreateOpts .IPXEScriptURL = req . MachineScope .PacketMachine .Spec .IPXEUrl
115124 }
116125
117126 dev , _ , err := p .Client .Devices .Create (serverCreateOpts )
0 commit comments