Skip to content

Commit 345d1cc

Browse files
authored
add configuration validation for webhook (#15)
meanwhile, the webhook's error message is now clearer and more precise.
1 parent f847011 commit 345d1cc

8 files changed

Lines changed: 22 additions & 20 deletions

File tree

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ indent_style = tab
1515

1616
[{*.yaml,*.yml,*.json}]
1717
indent_size = 2
18+
19+
[VERSION]
20+
insert_final_newline = false

.github/workflows/go.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ on:
88
push:
99
branches:
1010
- main
11-
tags:
12-
- 'v*'
1311

1412
jobs:
1513
test:
@@ -19,7 +17,7 @@ jobs:
1917
- name: Checkout
2018
uses: actions/checkout@v4
2119

22-
- name: Setup Go ${{ matrix.go-version }}
20+
- name: Setup Go
2321
uses: actions/setup-go@v5
2422
with:
2523
go-version-file: go.mod

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ The following table lists the correspondences between alidns-webhook and k8s ver
138138

139139
| Alidns-Webhook version | k8s supported version | Helm Chart Version |
140140
|------------------------|------------------------|--------------------|
141+
| **v1.0.0** | 1.29, 1.28, 1.27, 1.26 | 1.0.* |
141142
| **v0.1.0** | 1.29, 1.28, 1.27, 1.26 | 0.1.* |
142143

143144

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.0
1+
1.0.0

alidns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (s *AliSolver) loadAliDNS(challenge *acme.ChallengeRequest) (*AliDNS, error
118118
return nil, err
119119
}
120120

121-
accessKeySecret, err := s.loadSecretData(cfg.SecretAccessKeyRef, challenge.ResourceNamespace)
121+
accessKeySecret, err := s.loadSecretData(cfg.AccessKeySecretRef, challenge.ResourceNamespace)
122122
if err != nil {
123123
return nil, err
124124
}

charts/alidns-webhook/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type: application
1818
# This is the chart version. This version number should be incremented each time you make changes
1919
# to the chart and its templates, including the app version.
2020
# Versions are expected to follow Semantic Versioning (https://semver.org/)
21-
version: 0.1.0
21+
version: 1.0.0
2222

2323
# This is the version number of the application being deployed. This version number should be
2424
# incremented each time you make changes to the application. Versions are not expected to

config.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@ import (
2626
// be used by your provider here, you should reference a Kubernetes Secret
2727
// resource and fetch these credentials using a Kubernetes clientset.
2828
type Config struct {
29-
Region string `json:"region"` // optional
30-
AccessKeyIdRef cmmeta.SecretKeySelector `json:"accessKeyIdRef"`
31-
// AccessKeySecretRef will serve as the alias name for SecretAccessKeyRef
29+
Region string `json:"region"` // optional
30+
AccessKeyIdRef cmmeta.SecretKeySelector `json:"accessKeyIdRef"`
3231
AccessKeySecretRef cmmeta.SecretKeySelector `json:"accessKeySecretRef"`
32+
// SecretAccessKeyRef will serve as the alias name for AccessKeySecretRef
3333
SecretAccessKeyRef cmmeta.SecretKeySelector `json:"secretAccessKeyRef"`
3434
}
3535

3636
// Validate checks if the config of the webhook is valid.
3737
func (cfg *Config) Validate() error {
3838
if len(cfg.AccessKeyIdRef.Name) == 0 {
39-
return errors.New("testAccessKeyIdRef may not be empty")
39+
return errors.New("accessKeyIdRef may not be empty")
4040
}
4141

42-
if len(cfg.SecretAccessKeyRef.Name) == 0 {
43-
cfg.AccessKeySecretRef.DeepCopyInto(&cfg.SecretAccessKeyRef)
42+
if len(cfg.AccessKeySecretRef.Name) == 0 {
43+
cfg.SecretAccessKeyRef.DeepCopyInto(&cfg.AccessKeySecretRef)
4444
}
45-
if len(cfg.SecretAccessKeyRef.Name) == 0 {
46-
return errors.New("AccessKeySecretRef may not be empty")
45+
if len(cfg.AccessKeySecretRef.Name) == 0 {
46+
return errors.New("accessKeySecretRef may not be empty")
4747
}
4848

4949
return nil

config_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ var (
1919
},
2020
Key: "access-key-id",
2121
}
22-
testSecretAccessKeyRef = cmmeta.SecretKeySelector{
22+
testAccessKeySecretRef = cmmeta.SecretKeySelector{
2323
LocalObjectReference: cmmeta.LocalObjectReference{
2424
Name: "alidns-secret",
2525
},
26-
Key: "secret-access-key",
26+
Key: "access-key-secret",
2727
}
2828
)
2929

3030
func TestConfig_Validate(t *testing.T) {
3131
t.Run("happy", func(t *testing.T) {
3232
correct := &Config{
3333
AccessKeyIdRef: testAccessKeyIdRef,
34-
SecretAccessKeyRef: testSecretAccessKeyRef,
34+
AccessKeySecretRef: testAccessKeySecretRef,
3535
}
3636

3737
loaded, err := loadConfig(&extapi.JSON{Raw: mustMarshal(correct)})
@@ -43,7 +43,7 @@ func TestConfig_Validate(t *testing.T) {
4343
t.Run("compatible", func(t *testing.T) {
4444
correct := &Config{
4545
AccessKeyIdRef: testAccessKeyIdRef,
46-
AccessKeySecretRef: testSecretAccessKeyRef,
46+
SecretAccessKeyRef: testAccessKeySecretRef,
4747
}
4848

4949
loaded, err := loadConfig(&extapi.JSON{Raw: mustMarshal(correct)})
@@ -59,14 +59,14 @@ func TestConfig_Validate(t *testing.T) {
5959

6060
t.Run("no accessKeyId", func(t *testing.T) {
6161
bad := &Config{
62-
SecretAccessKeyRef: testSecretAccessKeyRef,
62+
SecretAccessKeyRef: testAccessKeySecretRef,
6363
}
6464

6565
_, err := loadConfig(&extapi.JSON{Raw: mustMarshal(bad)})
6666
assert.Error(t, err)
6767
})
6868

69-
t.Run("no secretAccessKey", func(t *testing.T) {
69+
t.Run("no accessKeySecret", func(t *testing.T) {
7070
bad := &Config{
7171
AccessKeyIdRef: testAccessKeyIdRef,
7272
}

0 commit comments

Comments
 (0)