@@ -26,13 +26,14 @@ type MachineScopeParams struct {
26
26
}
27
27
28
28
type MachineScope struct {
29
- Client K8sClient
30
- PatchHelper * patch.Helper
31
- Cluster * clusterv1.Cluster
32
- Machine * clusterv1.Machine
33
- LinodeClient LinodeClient
34
- LinodeCluster * infrav1alpha2.LinodeCluster
35
- LinodeMachine * infrav1alpha1.LinodeMachine
29
+ Client K8sClient
30
+ PatchHelper * patch.Helper
31
+ Cluster * clusterv1.Cluster
32
+ Machine * clusterv1.Machine
33
+ LinodeClient LinodeClient
34
+ LinodeDomainsClient LinodeClient
35
+ LinodeCluster * infrav1alpha2.LinodeCluster
36
+ LinodeMachine * infrav1alpha1.LinodeMachine
36
37
}
37
38
38
39
func validateMachineScopeParams (params MachineScopeParams ) error {
@@ -52,7 +53,7 @@ func validateMachineScopeParams(params MachineScopeParams) error {
52
53
return nil
53
54
}
54
55
55
- func NewMachineScope (ctx context.Context , apiKey string , params MachineScopeParams ) (* MachineScope , error ) {
56
+ func NewMachineScope (ctx context.Context , apiKey , dnsKey string , params MachineScopeParams ) (* MachineScope , error ) {
56
57
if err := validateMachineScopeParams (params ); err != nil {
57
58
return nil , err
58
59
}
@@ -78,32 +79,47 @@ func NewMachineScope(ctx context.Context, apiKey string, params MachineScopePara
78
79
}
79
80
80
81
if credentialRef != nil {
81
- data , err := getCredentialDataFromRef (ctx , params .Client , * credentialRef , defaultNamespace )
82
+ // TODO: This key is hard-coded (for now) to match the externally-managed `manager-credentials` Secret.
83
+ apiToken , err := getCredentialDataFromRef (ctx , params .Client , * credentialRef , defaultNamespace , "apiToken" )
82
84
if err != nil {
83
85
return nil , fmt .Errorf ("credentials from secret ref: %w" , err )
84
86
}
85
- apiKey = string (data )
87
+ apiKey = string (apiToken )
88
+
89
+ dnsToken , err := getCredentialDataFromRef (ctx , params .Client , * credentialRef , defaultNamespace , "dnsToken" )
90
+ if err != nil || len (dnsToken ) == 0 {
91
+ dnsToken = apiToken
92
+ }
93
+ dnsKey = string (dnsToken )
86
94
}
95
+
87
96
linodeClient , err := CreateLinodeClient (apiKey , defaultClientTimeout ,
88
97
WithRetryCount (0 ),
89
98
)
90
99
if err != nil {
91
100
return nil , fmt .Errorf ("failed to create linode client: %w" , err )
92
101
}
102
+ linodeDomainsClient , err := CreateLinodeClient (dnsKey , defaultClientTimeout ,
103
+ WithRetryCount (0 ),
104
+ )
105
+ if err != nil {
106
+ return nil , fmt .Errorf ("failed to create linode client: %w" , err )
107
+ }
93
108
94
109
helper , err := patch .NewHelper (params .LinodeMachine , params .Client )
95
110
if err != nil {
96
111
return nil , fmt .Errorf ("failed to init patch helper: %w" , err )
97
112
}
98
113
99
114
return & MachineScope {
100
- Client : params .Client ,
101
- PatchHelper : helper ,
102
- Cluster : params .Cluster ,
103
- Machine : params .Machine ,
104
- LinodeClient : linodeClient ,
105
- LinodeCluster : params .LinodeCluster ,
106
- LinodeMachine : params .LinodeMachine ,
115
+ Client : params .Client ,
116
+ PatchHelper : helper ,
117
+ Cluster : params .Cluster ,
118
+ Machine : params .Machine ,
119
+ LinodeClient : linodeClient ,
120
+ LinodeDomainsClient : linodeDomainsClient ,
121
+ LinodeCluster : params .LinodeCluster ,
122
+ LinodeMachine : params .LinodeMachine ,
107
123
}, nil
108
124
}
109
125
0 commit comments