@@ -27,6 +27,7 @@ import (
27
27
"github.com/packethost/packngo"
28
28
"github.com/pkg/errors"
29
29
corev1 "k8s.io/api/core/v1"
30
+ "k8s.io/utils/pointer"
30
31
infrastructurev1alpha3 "sigs.k8s.io/cluster-api-provider-packet/api/v1alpha3"
31
32
"sigs.k8s.io/cluster-api-provider-packet/pkg/cloud/packet/scope"
32
33
)
@@ -79,29 +80,38 @@ func (p *PacketClient) NewDevice(req CreateDeviceRequest) (*packngo.Device, erro
79
80
return nil , errors .Wrap (err , "impossible to retrieve bootstrap data from secret" )
80
81
}
81
82
83
+ stringWriter := & strings.Builder {}
82
84
userData := string (userDataRaw )
85
+ userDataValues := map [string ]interface {}{
86
+ "kubernetesVersion" : pointer .StringPtrDerefOr (req .MachineScope .Machine .Spec .Version , "" ),
87
+ }
88
+
83
89
tags := append (req .MachineScope .PacketMachine .Spec .Tags , req .ExtraTags ... )
90
+
91
+ tmpl , err := template .New ("user-data" ).Parse (userData )
92
+ if err != nil {
93
+ return nil , fmt .Errorf ("error parsing userdata template: %v" , err )
94
+ }
95
+
84
96
if req .MachineScope .IsControlPlane () {
85
97
// control plane machines should get the API key injected
86
- tmpl , err := template .New ("control-plane-user-data" ).Parse (userData )
87
- if err != nil {
88
- return nil , fmt .Errorf ("error parsing control-plane userdata template: %v" , err )
89
- }
90
- stringWriter := & strings.Builder {}
91
- apiKeyStruct := map [string ]interface {}{
92
- "apiKey" : p .Client .APIKey ,
93
- }
98
+ userDataValues ["apiKey" ] = p .Client .APIKey
99
+
94
100
if req .ControlPlaneEndpoint != "" {
95
- apiKeyStruct ["controlPlaneEndpoint" ] = req .ControlPlaneEndpoint
96
- }
97
- if err := tmpl .Execute (stringWriter , apiKeyStruct ); err != nil {
98
- return nil , fmt .Errorf ("error executing control-plane userdata template: %v" , err )
101
+ userDataValues ["controlPlaneEndpoint" ] = req .ControlPlaneEndpoint
99
102
}
100
- userData = stringWriter . String ()
103
+
101
104
tags = append (tags , infrastructurev1alpha3 .ControlPlaneTag )
102
105
} else {
103
106
tags = append (tags , infrastructurev1alpha3 .WorkerTag )
104
107
}
108
+
109
+ if err := tmpl .Execute (stringWriter , userDataValues ); err != nil {
110
+ return nil , fmt .Errorf ("error executing userdata template: %v" , err )
111
+ }
112
+
113
+ userData = stringWriter .String ()
114
+
105
115
serverCreateOpts := & packngo.DeviceCreateRequest {
106
116
Hostname : req .MachineScope .Name (),
107
117
ProjectID : req .MachineScope .PacketCluster .Spec .ProjectID ,
0 commit comments