Skip to content

Commit 514d60b

Browse files
committed
Error on startup if PACKET_AUTH_TOKEN is not set
1 parent 22cc140 commit 514d60b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cluster-autoscaler/cloudprovider/packet/packet_manager_rest.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ type packetManagerNodePool struct {
173173
}
174174

175175
type packetManagerRest struct {
176+
authToken string
176177
packetManagerNodePools map[string]*packetManagerNodePool
177178
}
178179

@@ -304,6 +305,13 @@ func createPacketManagerRest(configReader io.Reader, discoverOpts cloudprovider.
304305
klog.Fatalf("No \"default\" or [Global] nodepool definition was found")
305306
}
306307

308+
packetAuthToken := os.Getenv("PACKET_AUTH_TOKEN")
309+
if len(packetAuthToken) == 0 {
310+
klog.Fatalf("PACKET_AUTH_TOKEN is required and missing")
311+
}
312+
313+
manager.authToken = packetAuthToken
314+
307315
for nodepool := range cfg.Nodegroupdef {
308316
if opts.ClusterName == "" && cfg.Nodegroupdef[nodepool].ClusterName == "" {
309317
klog.Fatalf("The cluster-name parameter must be set")
@@ -330,14 +338,12 @@ func createPacketManagerRest(configReader io.Reader, discoverOpts cloudprovider.
330338
}
331339

332340
func (mgr *packetManagerRest) request(ctx context.Context, method, url string, jsonData []byte) ([]byte, error) {
333-
packetAuthToken := os.Getenv("PACKET_AUTH_TOKEN")
334-
335341
req, err := http.NewRequestWithContext(ctx, method, url, bytes.NewBuffer(jsonData))
336342
if err != nil {
337343
return nil, fmt.Errorf("failed to create request: %w", err)
338344
}
339345

340-
req.Header.Set("X-Auth-Token", packetAuthToken)
346+
req.Header.Set("X-Auth-Token", mgr.authToken)
341347
req.Header.Set("Content-Type", "application/json")
342348

343349
client := &http.Client{}

0 commit comments

Comments
 (0)