diff --git a/cluster-autoscaler/cloudprovider/packet/examples/cluster-autoscaler-deployment.yaml b/cluster-autoscaler/cloudprovider/packet/examples/cluster-autoscaler-deployment.yaml index 94d066690fc3..3b0254097720 100644 --- a/cluster-autoscaler/cloudprovider/packet/examples/cluster-autoscaler-deployment.yaml +++ b/cluster-autoscaler/cloudprovider/packet/examples/cluster-autoscaler-deployment.yaml @@ -175,7 +175,7 @@ spec: secretKeyRef: name: bootstrap-token-cluster-autoscaler-packet key: token-secret - - name: PACKET_AUTH_TOKEN + - name: METAL_AUTH_TOKEN valueFrom: secretKeyRef: name: cluster-autoscaler-packet diff --git a/cluster-autoscaler/cloudprovider/packet/packet_cloud_provider.go b/cluster-autoscaler/cloudprovider/packet/packet_cloud_provider.go index bafa2fc65744..402713f545a0 100644 --- a/cluster-autoscaler/cloudprovider/packet/packet_cloud_provider.go +++ b/cluster-autoscaler/cloudprovider/packet/packet_cloud_provider.go @@ -42,7 +42,10 @@ const ( // master/controller node. DefaultControllerNodeLabelKey = "node-role.kubernetes.io/master" // ControllerNodeIdentifierEnv is the string for the environment variable. - ControllerNodeIdentifierEnv = "PACKET_CONTROLLER_NODE_IDENTIFIER_LABEL" + // Deprecated: This env var is deprecated in the favour packet's acquisition to equinix. + // Please use 'ControllerNodeIdentifierMetalEnv' + ControllerNodeIdentifierEnv = "PACKET_CONTROLLER_NODE_IDENTIFIER_LABEL" + ControllerNodeIdentifierMetalEnv = "METAL_CONTROLLER_NODE_IDENTIFIER_LABEL" ) var ( @@ -106,10 +109,15 @@ func (pcp *equinixMetalCloudProvider) AddNodeGroup(group equinixMetalNodeGroup) // // Since only a single node group is currently supported, the first node group is always returned. func (pcp *equinixMetalCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovider.NodeGroup, error) { - controllerNodeLabel := os.Getenv(ControllerNodeIdentifierEnv) - if controllerNodeLabel == "" { - klog.V(3).Infof("env %s not set, using default: %s", ControllerNodeIdentifierEnv, DefaultControllerNodeLabelKey) - controllerNodeLabel = DefaultControllerNodeLabelKey + controllerNodeLabel := DefaultControllerNodeLabelKey + value, present := os.LookupEnv(ControllerNodeIdentifierMetalEnv) + if present { + controllerNodeLabel = value + } else { + controllerNodeLabel = os.Getenv(ControllerNodeIdentifierEnv) + if controllerNodeLabel == "" { + klog.V(3).Infof("env %s not set, using default: %s", ControllerNodeIdentifierEnv, DefaultControllerNodeLabelKey) + } } if _, found := node.ObjectMeta.Labels[controllerNodeLabel]; found { diff --git a/cluster-autoscaler/cloudprovider/packet/packet_manager_rest.go b/cluster-autoscaler/cloudprovider/packet/packet_manager_rest.go index c18674852ca0..e0860232639f 100644 --- a/cluster-autoscaler/cloudprovider/packet/packet_manager_rest.go +++ b/cluster-autoscaler/cloudprovider/packet/packet_manager_rest.go @@ -49,6 +49,7 @@ const ( userAgent = "kubernetes/cluster-autoscaler/" + version.ClusterAutoscalerVersion expectedAPIContentTypePrefix = "application/json" prefix = "equinixmetal://" + metalAuthTokenEnv = "METAL_AUTH_TOKEN" ) type instanceType struct { @@ -298,9 +299,15 @@ func createEquinixMetalManagerRest(configReader io.Reader, discoverOpts cloudpro klog.Fatalf("No \"default\" or [Global] nodepool definition was found") } - metalAuthToken := os.Getenv("PACKET_AUTH_TOKEN") - if len(metalAuthToken) == 0 { - klog.Fatalf("PACKET_AUTH_TOKEN is required and missing") + var metalAuthToken string + value, present := os.LookupEnv(metalAuthTokenEnv) + if present { + metalAuthToken = value + } else { + metalAuthToken = os.Getenv("PACKET_AUTH_TOKEN") + if len(metalAuthToken) == 0 { + klog.Fatalf("%s or PACKET_AUTH_TOKEN is required and missing", metalAuthTokenEnv) + } } manager.authToken = metalAuthToken diff --git a/cluster-autoscaler/cloudprovider/packet/packet_manager_rest_test.go b/cluster-autoscaler/cloudprovider/packet/packet_manager_rest_test.go index fe47c22792fe..4518a6dddd6c 100644 --- a/cluster-autoscaler/cloudprovider/packet/packet_manager_rest_test.go +++ b/cluster-autoscaler/cloudprovider/packet/packet_manager_rest_test.go @@ -79,7 +79,7 @@ func TestListMetalDevices(t *testing.T) { var m *equinixMetalManagerRest server := NewHttpServerMock(MockFieldContentType, MockFieldResponse) defer server.Close() - if len(os.Getenv("PACKET_AUTH_TOKEN")) > 0 { + if len(os.Getenv("PACKET_AUTH_TOKEN")) > 0 || len(os.Getenv(metalAuthTokenEnv)) > 0 { // If auth token set in env, hit the actual Packet API m = newTestPacketManagerRest(t, "https://api.equinix.com/metal/v1/") } else { diff --git a/cluster-autoscaler/cloudprovider/packet/packet_node_group_test.go b/cluster-autoscaler/cloudprovider/packet/packet_node_group_test.go index 50c5f5041277..c4e7812752a9 100644 --- a/cluster-autoscaler/cloudprovider/packet/packet_node_group_test.go +++ b/cluster-autoscaler/cloudprovider/packet/packet_node_group_test.go @@ -40,7 +40,7 @@ func TestIncreaseDecreaseSize(t *testing.T) { server := NewHttpServerMock(MockFieldContentType, MockFieldResponse) defer server.Close() assert.Equal(t, true, true) - if len(os.Getenv("PACKET_AUTH_TOKEN")) > 0 { + if len(os.Getenv("PACKET_AUTH_TOKEN")) > 0 || len(os.Getenv(metalAuthTokenEnv)) > 0 { // If auth token set in env, hit the actual Packet API m = newTestPacketManagerRest(t, "https://api.equinix.com") } else { @@ -106,7 +106,7 @@ func TestIncreaseDecreaseSize(t *testing.T) { err = ngPool3.IncreaseSize(1) assert.NoError(t, err) - if len(os.Getenv("PACKET_AUTH_TOKEN")) > 0 { + if len(os.Getenv("PACKET_AUTH_TOKEN")) > 0 || len(os.Getenv(metalAuthTokenEnv)) > 0 { // If testing with actual API give it some time until the nodes bootstrap time.Sleep(420 * time.Second) } @@ -120,7 +120,7 @@ func TestIncreaseDecreaseSize(t *testing.T) { err = ngPool2.IncreaseSize(1) assert.NoError(t, err) - if len(os.Getenv("PACKET_AUTH_TOKEN")) > 0 { + if len(os.Getenv("PACKET_AUTH_TOKEN")) > 0 || len(os.Getenv(metalAuthTokenEnv)) > 0 { // If testing with actual API give it some time until the nodes bootstrap time.Sleep(420 * time.Second) } @@ -151,7 +151,7 @@ func TestIncreaseDecreaseSize(t *testing.T) { assert.NoError(t, err) // Wait a few seconds if talking to the actual Packet API - if len(os.Getenv("PACKET_AUTH_TOKEN")) > 0 { + if len(os.Getenv("PACKET_AUTH_TOKEN")) > 0 || len(os.Getenv(metalAuthTokenEnv)) > 0 { time.Sleep(10 * time.Second) }