Skip to content

Commit

Permalink
fix: Trim newline of the content read from Secrets or Configmaps (#1146)
Browse files Browse the repository at this point in the history
* fix: fix: Trim newline of the content read from Secrets or Configmaps

Signed-off-by: Derek Wang <[email protected]>
  • Loading branch information
whynowy committed Mar 30, 2021
1 parent 219780e commit d31cc64
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 45 deletions.
8 changes: 6 additions & 2 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ func GetSecretFromVolume(selector *v1.SecretKeySelector) (string, error) {
if err != nil {
return "", errors.Wrapf(err, "failed to get secret value of name: %s, key: %s", selector.Name, selector.Key)
}
return string(data), nil
// Secrets edied by tools like "vim" always have an extra invisible "\n" in the end,
// and it's often negleted, but it makes differences for some of the applications.
return strings.TrimSuffix(string(data), "\n"), nil
}

// GetSecretVolumePath returns the path of the mounted secret
Expand All @@ -176,7 +178,9 @@ func GetConfigMapFromVolume(selector *v1.ConfigMapKeySelector) (string, error) {
if err != nil {
return "", errors.Wrapf(err, "failed to get configMap value of name: %s, key: %s", selector.Name, selector.Key)
}
return string(data), nil
// Contents edied by tools like "vim" always have an extra invisible "\n" in the end,
// and it's often negleted, but it makes differences for some of the applications.
return strings.TrimSuffix(string(data), "\n"), nil
}

// GetConfigMapVolumePath returns the path of the mounted configmap
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
github.com/fsnotify/fsnotify v1.4.9
github.com/gavv/httpexpect/v2 v2.2.0
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-git/go-git/v5 v5.3.0
github.com/go-openapi/inflect v0.19.0
github.com/go-openapi/spec v0.20.2
github.com/go-redis/redis v6.15.8+incompatible
Expand All @@ -41,7 +42,7 @@ require (
github.com/gorilla/mux v1.7.3
github.com/grpc-ecosystem/grpc-gateway v1.9.5
github.com/hokaccha/go-prettyjson v0.0.0-20190818114111-108c894c2c0e // indirect
github.com/imdario/mergo v0.3.11
github.com/imdario/mergo v0.3.12
github.com/joncalhoun/qson v0.0.0-20200422171543-84433dcd3da0
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/minio/minio-go v1.0.1-0.20190523192347-c6c2912aa552
Expand All @@ -60,7 +61,6 @@ require (
github.com/radovskyb/watcher v1.0.7
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/robfig/cron v1.2.0
github.com/sergi/go-diff v1.1.0 // indirect
github.com/slack-go/slack v0.7.4
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3 // indirect
github.com/smartystreets/goconvey v1.6.4
Expand All @@ -73,14 +73,13 @@ require (
github.com/tidwall/sjson v1.1.1
github.com/xanzy/go-gitlab v0.33.0
go.uber.org/zap v1.15.0
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
google.golang.org/api v0.15.1
google.golang.org/grpc v1.28.1
gopkg.in/jcmturner/goidentity.v2 v2.0.0 // indirect
gopkg.in/jcmturner/gokrb5.v5 v5.3.0
gopkg.in/jcmturner/rpc.v0 v0.0.2 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1
honnef.co/go/tools v0.0.1-2020.1.3 // indirect
k8s.io/api v0.19.6
k8s.io/apimachinery v0.19.6
Expand Down
Loading

0 comments on commit d31cc64

Please sign in to comment.