Skip to content

Commit

Permalink
Simplify handling of datadog secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-harris committed Oct 9, 2020
1 parent 2fc5e26 commit 6f2c557
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
7 changes: 3 additions & 4 deletions docs/features/analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,7 @@ metadata:
name: datadog
type: Opaque
data:
default:
address: https://api.datadoghq.com
api-key: <datadog-api-key>
app-key: <datadog-app-key>
address: https://api.datadoghq.com
api-key: <datadog-api-key>
app-key: <datadog-app-key>
```
17 changes: 11 additions & 6 deletions metricproviders/datadog/datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/argoproj/argo-rollouts/utils/evaluate"
metricutil "github.com/argoproj/argo-rollouts/utils/metric"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
Expand Down Expand Up @@ -173,16 +172,22 @@ func NewDatadogProvider(logCtx log.Entry, kubeclientset kubernetes.Interface) (*
if err != nil {
return nil, err
}
config := datadogConfig{}

if e := yaml.Unmarshal(secret.Data["default"], &config); e != nil {
return nil, e
apiKey := string(secret.Data["api-key"])
appKey := string(secret.Data["app-key"])
address := ""
if _, hasAddress := secret.Data["address"]; hasAddress {
address = string(secret.Data["address"])
}

if config.ApiKey != "" && config.AppKey != "" {
if apiKey != "" && appKey != "" {
return &Provider{
logCtx: logCtx,
config: config,
config: datadogConfig{
Address: address,
ApiKey: apiKey,
AppKey: appKey,
},
}, nil
} else {
return nil, errors.New("API or App token not found")
Expand Down
5 changes: 3 additions & 2 deletions metricproviders/datadog/datadog_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package datadog

import (
"fmt"
"io"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -200,7 +199,9 @@ func TestRunSuite(t *testing.T) {
Name: DatadogTokensSecretName,
},
Data: map[string][]byte{
"default": []byte(fmt.Sprintf("address: %s\napp-key: %s\napi-key: %s", server.URL, expectedAppKey, expectedApiKey)),
"address": []byte(server.URL),
"api-key": []byte(expectedApiKey),
"app-key": []byte(expectedAppKey),
},
}

Expand Down

0 comments on commit 6f2c557

Please sign in to comment.