From a65940830c4c92d53e55df9258a4bcc0a0a72abe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Julian=20T=C3=B6lle?= <julian.toelle@hetzner-cloud.de>
Date: Wed, 25 Oct 2023 14:08:06 +0200
Subject: [PATCH] feat: remove unused variable NODE_NAME (#545)

This variable is unused. It does not matter where HCCM is running, as
long as it can talk to the Kubernetes & Hetzner Cloud APIs.
---
 .gitlab-ci.yml           | 2 --
 chart/values.yaml        | 4 ----
 deploy/ccm-networks.yaml | 4 ----
 deploy/ccm.yaml          | 4 ----
 hcloud/cloud.go          | 5 -----
 hcloud/cloud_test.go     | 4 ----
 6 files changed, 23 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c111775c..333d40cf 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -32,8 +32,6 @@ test:lint:
 test:unit:
   stage: test
   image: golang:1.21
-  variables:
-    NODE_NAME: "test"
   script:
     - go test ./... -v
 
diff --git a/chart/values.yaml b/chart/values.yaml
index ae7197c7..c7fc4518 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -29,10 +29,6 @@ env:
       secretKeyRef:
         name: hcloud
         key: token
-  NODE_NAME:
-    valueFrom:
-      fieldRef:
-        fieldPath: spec.nodeName
 
 image:
   repository: hetznercloud/hcloud-cloud-controller-manager
diff --git a/deploy/ccm-networks.yaml b/deploy/ccm-networks.yaml
index 5f7ff36a..b227a2a3 100644
--- a/deploy/ccm-networks.yaml
+++ b/deploy/ccm-networks.yaml
@@ -75,10 +75,6 @@ spec:
                 secretKeyRef:
                   key: token
                   name: hcloud
-            - name: NODE_NAME
-              valueFrom:
-                fieldRef:
-                  fieldPath: spec.nodeName
             - name: HCLOUD_NETWORK
               valueFrom:
                 secretKeyRef:
diff --git a/deploy/ccm.yaml b/deploy/ccm.yaml
index f8bd00c3..60c38d78 100644
--- a/deploy/ccm.yaml
+++ b/deploy/ccm.yaml
@@ -72,10 +72,6 @@ spec:
                 secretKeyRef:
                   key: token
                   name: hcloud
-            - name: NODE_NAME
-              valueFrom:
-                fieldRef:
-                  fieldPath: spec.nodeName
           image: hetznercloud/hcloud-cloud-controller-manager:v1.18.0 # x-release-please-version
           ports:
             - name: metrics
diff --git a/hcloud/cloud.go b/hcloud/cloud.go
index 1eb8105d..d6553820 100644
--- a/hcloud/cloud.go
+++ b/hcloud/cloud.go
@@ -51,7 +51,6 @@ const (
 	hcloudLoadBalancersDisableIPv6           = "HCLOUD_LOAD_BALANCERS_DISABLE_IPV6"
 	hcloudMetricsEnabledENVVar               = "HCLOUD_METRICS_ENABLED"
 	hcloudMetricsAddress                     = ":8233"
-	nodeNameENVVar                           = "NODE_NAME"
 	providerName                             = "hcloud"
 )
 
@@ -76,10 +75,6 @@ func newCloud(_ io.Reader) (cloudprovider.Interface, error) {
 	if len(token) != 64 {
 		return nil, fmt.Errorf("entered token is invalid (must be exactly 64 characters long)")
 	}
-	nodeName := os.Getenv(nodeNameENVVar)
-	if nodeName == "" {
-		return nil, fmt.Errorf("environment variable %q is required", nodeNameENVVar)
-	}
 
 	opts := []hcloud.ClientOption{
 		hcloud.WithToken(token),
diff --git a/hcloud/cloud_test.go b/hcloud/cloud_test.go
index e04f6b1b..0b69fc18 100644
--- a/hcloud/cloud_test.go
+++ b/hcloud/cloud_test.go
@@ -68,7 +68,6 @@ func TestNewCloud(t *testing.T) {
 	resetEnv := Setenv(t,
 		"HCLOUD_ENDPOINT", env.Server.URL,
 		"HCLOUD_TOKEN", "jr5g7ZHpPptyhJzZyHw2Pqu4g9gTqDvEceYpngPf79jN_NOT_VALID_dzhepnahq",
-		"NODE_NAME", "test",
 		"HCLOUD_METRICS_ENABLED", "false",
 	)
 	defer resetEnv()
@@ -104,7 +103,6 @@ func TestNewCloudConnectionNotPossible(t *testing.T) {
 	resetEnv := Setenv(t,
 		"HCLOUD_ENDPOINT", "http://127.0.0.1:4711/v1",
 		"HCLOUD_TOKEN", "jr5g7ZHpPptyhJzZyHw2Pqu4g9gTqDvEceYpngPf79jN_NOT_VALID_dzhepnahq",
-		"NODE_NAME", "test",
 		"HCLOUD_METRICS_ENABLED", "false",
 	)
 	defer resetEnv()
@@ -121,7 +119,6 @@ func TestNewCloudInvalidToken(t *testing.T) {
 	resetEnv := Setenv(t,
 		"HCLOUD_ENDPOINT", env.Server.URL,
 		"HCLOUD_TOKEN", "jr5g7ZHpPptyhJzZyHw2Pqu4g9gTqDvEceYpngPf79jN_NOT_VALID_dzhepnahq",
-		"NODE_NAME", "test",
 		"HCLOUD_METRICS_ENABLED", "false",
 	)
 	defer resetEnv()
@@ -149,7 +146,6 @@ func TestCloud(t *testing.T) {
 	resetEnv := Setenv(t,
 		"HCLOUD_ENDPOINT", env.Server.URL,
 		"HCLOUD_TOKEN", "jr5g7ZHpPptyhJzZyHw2Pqu4g9gTqDvEceYpngPf79jN_NOT_VALID_dzhepnahq",
-		"NODE_NAME", "test",
 		"HCLOUD_METRICS_ENABLED", "false",
 	)
 	defer resetEnv()
-- 
GitLab