Skip to content

Commit dc11070

Browse files
authored
Add support for in-cluster config in the k8s provider (#645)
* Add support in-cluster config for k8s provider Signed-off-by: Aditya Menon <amenon@canarytechnologies.com> * fix ci issues Signed-off-by: Aditya Menon <amenon@canarytechnologies.com> * update .golangci-lint config file and apply fixes suggested Signed-off-by: Aditya Menon <amenon@canarytechnologies.com> --------- Signed-off-by: Aditya Menon <amenon@canarytechnologies.com>
1 parent 813fa0c commit dc11070

File tree

22 files changed

+230
-153
lines changed

22 files changed

+230
-153
lines changed

.golangci.yaml

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@ run:
1919
# build-tags:
2020
# - mytag
2121

22-
# which dirs to skip: issues from them won't be reported;
23-
# can use regexp here: generated.*, regexp is applied on full path;
24-
# default value is empty list, but default dirs are skipped independently
25-
# from this option's value (see skip-dirs-use-default).
26-
# skip-dirs:
27-
# - src/external_libs
28-
# - autogenerated_by_my_lib
29-
30-
# default is true. Enables skipping of directories:
31-
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
32-
skip-dirs-use-default: true
33-
3422
# which files to skip: they will be analyzed, but issues from them
3523
# won't be reported. Default value is empty list, but there is
3624
# no need to include all autogenerated files, we confidently recognize
@@ -51,8 +39,35 @@ run:
5139

5240
# output configuration options
5341
output:
54-
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
55-
format: line-number
42+
# The formats used to render issues.
43+
# Formats:
44+
# - `colored-line-number`
45+
# - `line-number`
46+
# - `json`
47+
# - `colored-tab`
48+
# - `tab`
49+
# - `html`
50+
# - `checkstyle`
51+
# - `code-climate`
52+
# - `junit-xml`
53+
# - `junit-xml-extended`
54+
# - `github-actions`
55+
# - `teamcity`
56+
# - `sarif`
57+
# Output path can be either `stdout`, `stderr` or path to the file to write to.
58+
#
59+
# For the CLI flag (`--out-format`), multiple formats can be specified by separating them by comma.
60+
# The output can be specified for each of them by separating format name and path by colon symbol.
61+
# Example: "--out-format=checkstyle:report.xml,json:stdout,colored-line-number"
62+
# The CLI flag (`--out-format`) override the configuration file.
63+
#
64+
# Default:
65+
# formats:
66+
# - format: colored-line-number
67+
# path: stdout
68+
formats:
69+
- format: line-number
70+
path: stdout
5671

5772
# print lines of code with issue, default is true
5873
print-issued-lines: true
@@ -88,13 +103,15 @@ linters-settings:
88103

89104
# Disable error checking, as errorcheck detects more errors and is more configurable.
90105
gosec:
91-
exclude:
92-
- "G104"
106+
excludes:
107+
- "G104"
93108

94109
govet:
95110
# report about shadowed variables
96-
check-shadowing: false
97-
111+
enable:
112+
- fieldalignment
113+
disable:
114+
- shadow
98115
# settings per analyzer
99116
settings:
100117
printf: # analyzer name, run `go tool vet help` to see all analyzers
@@ -111,13 +128,15 @@ linters-settings:
111128
# disable:
112129
# - shadow
113130
# disable-all: false
114-
golint:
131+
revive:
115132
# minimal confidence for issues, default is 0.8
116-
min-confidence: 0.8
133+
confidence: 0.8
134+
ignore-generated-header: true
135+
severity: warning
117136
gofmt:
118137
# simplify code: gofmt with `-s` option, true by default
119138
simplify: true
120-
goimports:
139+
# goimports:
121140
# put imports beginning with prefix after 3rd-party packages;
122141
# it's a comma-separated list of prefixes
123142
# local-prefixes: github.com/org/project
@@ -127,9 +146,6 @@ linters-settings:
127146
gocognit:
128147
# minimal code complexity to report, 30 by default (but we recommend 10-20)
129148
min-complexity: 100
130-
maligned:
131-
# print struct with more effective memory layout or not, false by default
132-
suggest-new: true
133149
dupl:
134150
# tokens count to trigger issue, 150 by default
135151
threshold: 100
@@ -139,13 +155,12 @@ linters-settings:
139155
# minimal occurrences count to trigger, 3 by default
140156
min-occurrences: 8
141157
depguard:
142-
list-type: blacklist
143-
include-go-root: false
144-
packages:
145-
- github.com/sirupsen/logrus
146-
packages-with-error-messages:
147-
# specify an error message to output when a blacklisted package is used
148-
github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
158+
rules:
159+
main:
160+
deny:
161+
- pkg: github.com/sirupsen/logrus
162+
desc: "logging is allowed only by logutils.Log"
163+
list-mode: lax
149164
misspell:
150165
# Correct spellings using locale preferences for US or UK.
151166
# Default is to use a neutral variety of English.
@@ -159,12 +174,6 @@ linters-settings:
159174
line-length: 120
160175
# tab width in spaces. Default to 1.
161176
tab-width: 1
162-
unused:
163-
# treat code as a program (not a library) and report unused exported identifiers; default is false.
164-
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
165-
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
166-
# with golangci-lint call it on a directory with the changed file.
167-
check-exported: false
168177
unparam:
169178
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
170179
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
@@ -237,9 +246,6 @@ linters-settings:
237246
allow-trailing-comment: false
238247
# Force newlines in end of case at this limit (0 = never).
239248
force-case-trailing-whitespace: 0
240-
revive:
241-
ignore-generated-header: true
242-
severity: warning
243249
funlen:
244250
# Checks the number of lines in a function.
245251
# If lower than 0, disable the check.
@@ -270,7 +276,7 @@ linters:
270276
- ineffassign
271277
- misspell
272278
- nakedret
273-
- exportloopref
279+
- copyloopvar
274280
- staticcheck
275281
- typecheck
276282
- unconvert
@@ -338,6 +344,11 @@ issues:
338344
# Default value for this option is true.
339345
exclude-use-default: false
340346

347+
# Enables exclude of directories:
348+
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
349+
# Default: true
350+
exclude-dirs-use-default: true
351+
341352
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
342353
max-issues-per-linter: 0
343354

@@ -357,4 +368,4 @@ issues:
357368
# new-from-rev: REV
358369

359370
# Show only new issues created in git patch with set file path.
360-
# new-from-patch: path/to/patch/file
371+
# new-from-patch: path/to/patch/file

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ lint:
1616
test:
1717
go test -v ${PKGS} -coverprofile cover.out -race -p=1
1818
go tool cover -func cover.out
19-
.PHONY: test
19+
.PHONY: test

README.md

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -207,31 +207,53 @@ Please see the [relevant unit test cases](https://github.com/helmfile/vals/blob/
207207

208208
## Supported Backends
209209

210-
- [Vault](#vault)
211-
- [AWS SSM Parameter Store](#aws-ssm-parameter-store)
212-
- [AWS Secrets Manager](#aws-secrets-manager)
213-
- [AWS S3](#aws-s3)
214-
- [GCP Secrets Manager](#gcp-secrets-manager)
215-
- [GCP KMS](#gcp-kms)
216-
- [Google Sheets](#google-sheets)
217-
- [Google GCS](#google-gcs)
218-
- [SOPS](#sops) powered by [sops](https://github.com/getsops/sops)
219-
- [Terraform (tfstate)](#terraform-tfstate) powered by [tfstate-lookup](https://github.com/fujiwara/tfstate-lookup)
220-
- [Keychain](#keychain)
221-
- [Echo](#echo)
222-
- [File](#file)
223-
- [Azure Key Vault](#azure-key-vault)
224-
- [EnvSubst](#envsubst)
225-
- [GitLab](#gitlab)
226-
- [1Password](#1password)
227-
- [1Password Connect](#1password-connect)
228-
- [Doppler](#doppler)
229-
- [Pulumi State](#pulumi-state)
230-
- [Kubernetes](#kubernetes)
231-
- [Conjur](#conjur)
232-
- [HCP Vault Secrets](#hcp-vault-secrets)
233-
- [HTTP JSON](#http-json)
234-
- [Bitwarden](#bitwarden)
210+
- [vals](#vals)
211+
- [Usage](#usage)
212+
- [CLI](#cli)
213+
- [Helm](#helm)
214+
- [Go](#go)
215+
- [Expression Syntax](#expression-syntax)
216+
- [Supported Backends](#supported-backends)
217+
- [Vault](#vault)
218+
- [Authentication](#authentication)
219+
- [AWS](#aws)
220+
- [AWS SSM Parameter Store](#aws-ssm-parameter-store)
221+
- [AWS Secrets Manager](#aws-secrets-manager)
222+
- [AWS S3](#aws-s3)
223+
- [AWS KMS](#aws-kms)
224+
- [Google GCS](#google-gcs)
225+
- [GCP Secrets Manager](#gcp-secrets-manager)
226+
- [GCP KMS](#gcp-kms)
227+
- [Google Sheets](#google-sheets)
228+
- [Terraform (tfstate)](#terraform-tfstate)
229+
- [Terraform in GCS bucket (tfstategs)](#terraform-in-gcs-bucket-tfstategs)
230+
- [Terraform in S3 bucket (tfstates3)](#terraform-in-s3-bucket-tfstates3)
231+
- [Terraform in AzureRM Blob storage (tfstateazurerm)](#terraform-in-azurerm-blob-storage-tfstateazurerm)
232+
- [Terraform in Terraform Cloud / Terraform Enterprise (tfstateremote)](#terraform-in-terraform-cloud--terraform-enterprise-tfstateremote)
233+
- [SOPS](#sops)
234+
- [Keychain](#keychain)
235+
- [Echo](#echo)
236+
- [File](#file)
237+
- [Azure Key Vault](#azure-key-vault)
238+
- [Authentication](#authentication-1)
239+
- [EnvSubst](#envsubst)
240+
- [GitLab Secrets](#gitlab-secrets)
241+
- [1Password](#1password)
242+
- [1Password Connect](#1password-connect)
243+
- [Doppler](#doppler)
244+
- [Pulumi State](#pulumi-state)
245+
- [Kubernetes](#kubernetes)
246+
- [Conjur](#conjur)
247+
- [HCP Vault Secrets](#hcp-vault-secrets)
248+
- [Bitwarden](#bitwarden)
249+
- [HTTP JSON](#http-json)
250+
- [Fetch string value](#fetch-string-value)
251+
- [Fetch integer value](#fetch-integer-value)
252+
- [Advanced Usages](#advanced-usages)
253+
- [Discriminating config and secrets](#discriminating-config-and-secrets)
254+
- [Non-Goals](#non-goals)
255+
- [Complex String-Interpolation / Template Functions](#complex-string-interpolation--template-functions)
256+
- [Merge](#merge)
235257

236258
Please see [pkg/providers](https://github.com/helmfile/vals/tree/master/pkg/providers) for the implementations of all the providers. The package names corresponds to the URI schemes.
237259

@@ -779,11 +801,12 @@ Examples:
779801
780802
Fetch value from Kubernetes:
781803
782-
- `ref+k8s://API_VERSION/KIND/NAMESPACE/NAME/KEY[?kubeConfigPath=<path_to_kubeconfig>&kubeContext=<kubernetes context name>]`
804+
- `ref+k8s://API_VERSION/KIND/NAMESPACE/NAME/KEY[?kubeConfigPath=<path_to_kubeconfig>&kubeContext=<kubernetes context name>&inCluster]`
783805
784-
Authentication to the Kubernetes cluster is done by referencing the local kubeconfig file.
806+
Authentication to the Kubernetes cluster is done by referencing the local kubeconfig file or in-cluster config.
785807
The path to the kubeconfig can be specified as a URI parameter, read from the `KUBECONFIG` environment variable or the provider will attempt to read `$HOME/.kube/config`.
786808
The Kubernetes context can be specified as a URI parameteter.
809+
If `?inCluster` is passed in the URI, ensure the pod running the `vals`command has the appropriate RBAC permissions to access the ConfigMap/Secret.
787810
788811
Environment variables:
789812
@@ -794,6 +817,7 @@ Examples:
794817
- `ref+k8s://v1/Secret/mynamespace/mysecret/foo`
795818
- `ref+k8s://v1/ConfigMap/mynamespace/myconfigmap/foo`
796819
- `ref+k8s://v1/Secret/mynamespace/mysecret/bar?kubeConfigPath=/home/user/kubeconfig`
820+
- `ref+k8s://v1/Secret/mynamespace/mysecret/foo?inCluster`
797821
- `secretref+k8s://v1/Secret/mynamespace/mysecret/baz`
798822
- `secretref+k8s://v1/Secret/mynamespace/mysecret/baz?kubeContext=minikube`
799823
@@ -849,7 +873,7 @@ Example:
849873
850874
851875
### Bitwarden
852-
This provider retrieves the secrets stored in Bitwarden. It uses the [Bitwarden Vault-Management API](https://bitwarden.com/help/vault-management-api/) that is included in the [Bitwarden CLI](https://github.com/bitwarden/clients) by executing `bw serve`.
876+
This provider retrieves the secrets stored in Bitwarden. It uses the [Bitwarden Vault-Management API](https://bitwarden.com/help/vault-management-api/) that is included in the [Bitwarden CLI](https://github.com/bitwarden/clients) by executing `bw serve`.
853877
854878
Environment variables:
855879
@@ -872,7 +896,7 @@ Examples:
872896
873897
This provider retrieves values stored in JSON hosted by a HTTP frontend.
874898
875-
This provider is built on top of [jsonquery](https://pkg.go.dev/github.com/antchfx/jsonquery@v1.3.3) and [xpath](https://pkg.go.dev/github.com/antchfx/xpath@v1.2.3) packages.
899+
This provider is built on top of [jsonquery](https://pkg.go.dev/github.com/antchfx/jsonquery@v1.3.3) and [xpath](https://pkg.go.dev/github.com/antchfx/xpath@v1.2.3) packages.
876900
877901
Given the diverse array of JSON structures that can be encountered, utilizing jsonquery with XPath presents a more effective approach for handling this variability in data structures.
878902
@@ -896,7 +920,7 @@ Let's say you want to fetch the below JSON object from https://api.github.com/us
896920
"name": "go-yaml"
897921
}
898922
]
899-
```
923+
```
900924
```
901925
# To get name="chartify" using https protocol you would use:
902926
ref+httpjson://api.github.com/users/helmfile/repos#///*[1]/name
@@ -919,7 +943,7 @@ Let's say you want to fetch the below JSON object from https://api.github.com/us
919943
"id": 251296379
920944
}
921945
]
922-
```
946+
```
923947
```
924948
# Running the following will return: 2.51296379e+08
925949
ref+httpjson://api.github.com/users/helmfile/repos#///*[1]/id

pkg/expansion/expand_match_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99

1010
func TestExpandRegexpMatchInString(t *testing.T) {
1111
testcases := []struct {
12-
name string
1312
regex *regexp.Regexp
14-
only []string
13+
name string
1514
input string
1615
expected string
16+
only []string
1717
}{
1818
{
1919
name: "ref",
@@ -174,10 +174,10 @@ func TestExpandRegexpMatchInString(t *testing.T) {
174174

175175
func TestExpandRegexpMatchInMap(t *testing.T) {
176176
testcases := []struct {
177-
name string
178177
regex *regexp.Regexp
179178
input map[string]interface{}
180179
expected map[string]interface{}
180+
name string
181181
}{
182182
{
183183
name: "string",

pkg/providers/bitwarden/bitwarden.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ type bwData struct {
2020
}
2121

2222
type bwResponse struct {
23-
Success bool `json:"success"`
24-
Message string `json:"message"`
2523
Data bwData `json:"data"`
24+
Message string `json:"message"`
25+
Success bool `json:"success"`
2626
}
2727

2828
type provider struct {

pkg/providers/conjur/conjur_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212

1313
func Test_New(t *testing.T) {
1414
testsConfig := []struct {
15-
name string
1615
options map[string]interface{}
1716
envVars map[string]string
1817
want *provider
18+
name string
1919
}{
2020
{
2121
name: "onlyConf",

pkg/providers/doppler/doppler.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ import (
1414
)
1515

1616
type provider struct {
17-
log *log.Logger
18-
Proto string
19-
Host string
20-
Address string
21-
VerifyTLS bool
22-
17+
log *log.Logger
18+
Proto string
19+
Host string
20+
Address string
2321
Token string
2422
Project string
2523
Config string
24+
VerifyTLS bool
2625
IncludeDopplerDefaults bool
2726
}
2827

0 commit comments

Comments
 (0)