Skip to content

Commit 58efe26

Browse files
authored
Merge pull request #291 from cloudability/filter-cluster-name-again
Fix Cluster Name Parameter (yet again)
2 parents 95a0e17 + e208d50 commit 58efe26

File tree

6 files changed

+38
-7
lines changed

6 files changed

+38
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Cloudability Metrics Agent currently does not support Rancher or On Prem cluster
3939
| Environment Variable | Description |
4040
|------------------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
4141
| CLOUDABILITY_API_KEY | Required: Cloudability api key |
42-
| CLOUDABILITY_CLUSTER_NAME | Required: The cluster name to be used for the cluster the agent is running in. |
42+
| CLOUDABILITY_CLUSTER_NAME | Required: The cluster name to be used for the cluster the agent is running in. Cannot be exclusively whitespace. |
4343
| CLOUDABILITY_POLL_INTERVAL | Optional: The interval (Seconds) to poll metrics. Default: 180 |
4444
| CLOUDABILITY_OUTBOUND_PROXY | Optional: The URL of an outbound HTTP/HTTPS proxy for the agent to use (eg: http://x.x.x.x:8080). The URL must contain the scheme prefix (http:// or https://) |
4545
| CLOUDABILITY_OUTBOUND_PROXY_AUTH | Optional: Basic Authentication credentials to be used with the defined outbound proxy. If your outbound proxy requires basic authentication credentials can be defined in the form username:password |

charts/metrics-agent/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ type: application
1414

1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
17-
version: 2.11.38
17+
version: 2.11.39
1818

1919
# This is the version number of the application being deployed. This version number should be
2020
# incremented each time you make changes to the application.
21-
appVersion: 2.11.38
21+
appVersion: 2.11.39

charts/metrics-agent/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ uploadRegion: "us-west-2"
2626

2727
image:
2828
name: cloudability/metrics-agent
29-
tag: 2.11.38
29+
tag: 2.11.39
3030
pullPolicy: Always
3131

3232
imagePullSecrets: []

util/util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func CheckRequiredSettings(requiredArgs []string) error {
8080

8181
}
8282

83+
if strings.TrimSpace(viper.GetString("cluster_name")) == "" {
84+
return fmt.Errorf("Cluster name cannot only contain whitespace")
85+
}
86+
8387
if viper.IsSet("poll_interval") && viper.GetInt("poll_interval") < 5 {
8488
return fmt.Errorf(
8589
"Polling interval must be 5 seconds or greater")

util/util_test.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type testConfig struct {
2222
KubeStateMetricsURL string
2323
PollInterval int
2424
UseInClusterConfig bool
25+
ClusterName string
2526
}
2627

2728
func TestIsValidURL(t *testing.T) {
@@ -112,14 +113,21 @@ func TestCheckRequiredSettings(t *testing.T) {
112113
600,
113114
"Time, in seconds to poll the services infrastructure. Default: 600",
114115
)
116+
kubernetesCmd.PersistentFlags().StringVar(
117+
&config.ClusterName,
118+
"cluster_name",
119+
"default-test",
120+
"Kubernetes Cluster Name - required this must be unique to every cluster.",
121+
)
115122

116123
_ = viper.BindPFlag("api_key", kubernetesCmd.PersistentFlags().Lookup("api_key"))
117124
_ = viper.BindPFlag("poll_interval", kubernetesCmd.PersistentFlags().Lookup("poll_interval"))
125+
_ = viper.BindPFlag("cluster_name", kubernetesCmd.PersistentFlags().Lookup("cluster_name"))
118126

119127
// nolint dupl
120128
t.Run("ensure that required settings are set as cmd flags", func(t *testing.T) {
121129

122-
args := []string{"kubernetes", "--poll_interval", "5", "--api_key", "8675309-9035768"}
130+
args := []string{"kubernetes", "--poll_interval", "5", "--api_key", "8675309-9035768", "--cluster_name", "specificTest"}
123131
kubernetesCmd.SetArgs(args)
124132

125133
if err := kubernetesCmd.Execute(); err != nil {
@@ -130,7 +138,7 @@ func TestCheckRequiredSettings(t *testing.T) {
130138
// nolint dupl
131139
t.Run("ensure that missing required cmd flags is detected", func(t *testing.T) {
132140

133-
args := []string{"kubernetes", "--poll_interval", "5", "--api_key", "8675309-9035768"}
141+
args := []string{"kubernetes", "--poll_interval", "5", "--api_key", "8675309-9035768", "--cluster_name", "specificTest"}
134142
kubernetesCmd.SetArgs(args)
135143

136144
if err := kubernetesCmd.Execute(); err != nil {
@@ -145,6 +153,7 @@ func TestCheckRequiredSettings(t *testing.T) {
145153

146154
_ = os.Setenv("CLOUDABILITY_API_KEY", "8675309-9035768")
147155
_ = os.Setenv("CLOUDABILITY_POLL_INTERVAL", "5")
156+
_ = os.Setenv("CLOUDABILITY_CLUSTER_NAME", "test")
148157

149158
if err := kubernetesCmd.Execute(); err != nil {
150159
t.Errorf("required settings set via environment variables but not detected: %v", err)
@@ -162,6 +171,7 @@ func TestCheckRequiredSettings(t *testing.T) {
162171

163172
_ = os.Setenv("CLOUDABILITY_API_KEY", "8675309-9035768")
164173
_ = os.Setenv("CLOUDABILITY_POLL_INTERVAL", "5")
174+
_ = os.Setenv("CLOUDABILITY_CLUSTER_NAME", "test")
165175

166176
if err := kubernetesCmd.Execute(); err != nil {
167177
t.Errorf("incorrect settings via environment variables but condition not detected: %v", err)
@@ -178,11 +188,28 @@ func TestCheckRequiredSettings(t *testing.T) {
178188
kubernetesCmd.SetArgs(envArgs)
179189
_ = os.Setenv("CLOUDABILITY_API_KEY", "8675309-9035768")
180190
_ = os.Setenv("CLOUDABILITY_POLL_INTERVAL", "4")
191+
_ = os.Setenv("CLOUDABILITY_CLUSTER_NAME", "test")
181192

182193
if err := kubernetesCmd.Execute(); err != nil {
183194
t.Errorf("incorrect poll interval set via environment variables but not detected: %v", err)
184195
}
185196
})
197+
198+
t.Run("ensure that invalid string value is detected", func(t *testing.T) {
199+
200+
viper.SetEnvPrefix("cloudability")
201+
viper.AutomaticEnv()
202+
203+
envArgs := []string{"kubernetes"}
204+
kubernetesCmd.SetArgs(envArgs)
205+
_ = os.Setenv("CLOUDABILITY_API_KEY", "8675309-9035768")
206+
_ = os.Setenv("CLOUDABILITY_POLL_INTERVAL", "5")
207+
_ = os.Setenv("CLOUDABILITY_CLUSTER_NAME", " ")
208+
209+
if err := kubernetesCmd.Execute(); err != nil {
210+
t.Errorf("incorrect cluster name set via environment variables but condition not detected: %v", err)
211+
}
212+
})
186213
}
187214

188215
func TestCreateMetricSample(t *testing.T) {

version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package version
22

33
// VERSION is the current version of the agent
4-
var VERSION = "2.11.38"
4+
var VERSION = "2.11.39"

0 commit comments

Comments
 (0)