@@ -67,15 +67,21 @@ func (p *PacketClient) GetDevice(deviceID string) (*packngo.Device, error) {
67
67
return dev , err
68
68
}
69
69
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 ()
72
78
if err != nil {
73
79
return nil , errors .Wrap (err , "impossible to retrieve bootstrap data from secret" )
74
80
}
75
81
76
82
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 () {
79
85
// control plane machines should get the API key injected
80
86
tmpl , err := template .New ("control-plane-user-data" ).Parse (userData )
81
87
if err != nil {
@@ -85,6 +91,9 @@ func (p *PacketClient) NewDevice(machineScope *scope.MachineScope, extraTags []s
85
91
apiKeyStruct := map [string ]interface {}{
86
92
"apiKey" : p .Client .APIKey ,
87
93
}
94
+ if req .ControlPlaneEndpoint != "" {
95
+ apiKeyStruct ["controlPlaneEndpoint" ] = req .ControlPlaneEndpoint
96
+ }
88
97
if err := tmpl .Execute (stringWriter , apiKeyStruct ); err != nil {
89
98
return nil , fmt .Errorf ("error executing control-plane userdata template: %v" , err )
90
99
}
@@ -94,24 +103,24 @@ func (p *PacketClient) NewDevice(machineScope *scope.MachineScope, extraTags []s
94
103
tags = append (tags , infrastructurev1alpha3 .WorkerTag )
95
104
}
96
105
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 ,
104
113
Tags : tags ,
105
114
UserData : userData ,
106
115
}
107
116
108
117
// Update server options to pass pxe url if specified
109
- if machineScope .PacketMachine .Spec .IPXEUrl != "" {
118
+ if req . MachineScope .PacketMachine .Spec .IPXEUrl != "" {
110
119
// Error if pxe url and OS conflict
111
- if machineScope .PacketMachine .Spec .OS != ipxeOS {
120
+ if req . MachineScope .PacketMachine .Spec .OS != ipxeOS {
112
121
return nil , fmt .Errorf ("os should be set to custom_pxe when using pxe urls" )
113
122
}
114
- serverCreateOpts .IPXEScriptURL = machineScope .PacketMachine .Spec .IPXEUrl
123
+ serverCreateOpts .IPXEScriptURL = req . MachineScope .PacketMachine .Spec .IPXEUrl
115
124
}
116
125
117
126
dev , _ , err := p .Client .Devices .Create (serverCreateOpts )
0 commit comments