Skip to content

Commit 1c7a104

Browse files
authored
Merge pull request #4002 from bakhtin/scw-profile-support
Update Scaleway provider to support config files
2 parents 6abbef1 + 783e699 commit 1c7a104

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

docs/tutorials/scaleway.md

+37
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ In this example we will use `example.com` as an example.
1919
To use ExternalDNS with Scaleway DNS, you need to create an API token (composed of the Access Key and the Secret Key).
2020
You can either use existing ones or you can create a new token, as explained in [How to generate an API token](https://www.scaleway.com/en/docs/generate-an-api-token/) or directly by going to the [credentials page](https://console.scaleway.com/account/organization/credentials).
2121

22+
Scaleway provider supports configuring credentials using profiles or supplying it directly with environment variables.
2223

24+
### Configuration using a config file
25+
You can supply the credentials through a config file:
26+
1. Create the config file. Check out [Scaleway docs](https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md#scaleway-config) for instructions
27+
2. Mount it as a Secret into the Pod
28+
3. Configure environment variable `SCW_PROFILE` to match the profile name in the config file
29+
4. Configure environment variable `SCW_CONFIG_PATH` to match the location of the mounted config file
30+
31+
### Configuration using environment variables
2332
Two environment variables are needed to run ExternalDNS with Scaleway DNS:
2433
- `SCW_ACCESS_KEY` which is the Access Key.
2534
- `SCW_SECRET_KEY` which is the Secret Key.
@@ -61,6 +70,20 @@ spec:
6170
value: "<your access key>"
6271
- name: SCW_SECRET_KEY
6372
value: "<your secret key>"
73+
### Set if configuring using a config file. Make sure to create the Secret first.
74+
# - name: SCW_PROFILE
75+
# value: "<profile name>"
76+
# - name: SCW_CONFIG_PATH
77+
# value: /etc/scw/config.yaml
78+
# volumeMounts:
79+
# - name: scw-config
80+
# mountPath: /etc/scw/config.yaml
81+
# readOnly: true
82+
# volumes:
83+
# - name: scw-config
84+
# secret:
85+
# secretName: scw-config
86+
###
6487
```
6588

6689
### Manifest (for clusters with RBAC enabled)
@@ -127,6 +150,20 @@ spec:
127150
value: "<your access key>"
128151
- name: SCW_SECRET_KEY
129152
value: "<your secret key>"
153+
### Set if configuring using a config file. Make sure to create the Secret first.
154+
# - name: SCW_PROFILE
155+
# value: "<profile name>"
156+
# - name: SCW_CONFIG_PATH
157+
# value: /etc/scw/config.yaml
158+
# volumeMounts:
159+
# - name: scw-config
160+
# mountPath: /etc/scw/config.yaml
161+
# readOnly: true
162+
# volumes:
163+
# - name: scw-config
164+
# secret:
165+
# secretName: scw-config
166+
###
130167
```
131168

132169

provider/scaleway/scaleway.go

+2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ func NewScalewayProvider(ctx context.Context, domainFilter endpoint.DomainFilter
6565
defaultPageSize = 1000
6666
}
6767
}
68+
p, _ := scw.MustLoadConfig().GetActiveProfile()
6869
scwClient, err := scw.NewClient(
70+
scw.WithProfile(p),
6971
scw.WithEnv(),
7072
scw.WithUserAgent("ExternalDNS/"+externaldns.Version),
7173
scw.WithDefaultPageSize(uint32(defaultPageSize)),

provider/scaleway/scaleway_test.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,26 @@ func (m *mockScalewayDomain) UpdateDNSZoneRecords(req *domain.UpdateDNSZoneRecor
111111
}
112112

113113
func TestScalewayProvider_NewScalewayProvider(t *testing.T) {
114+
profile := `profiles:
115+
foo:
116+
access_key: SCWXXXXXXXXXXXXXXXXX
117+
secret_key: 11111111-1111-1111-1111-111111111111
118+
`
119+
tmpDir := t.TempDir()
120+
err := os.WriteFile(tmpDir+"/config.yaml", []byte(profile), 0600)
121+
if err != nil {
122+
t.Errorf("failed : %s", err)
123+
}
124+
_ = os.Setenv(scw.ScwActiveProfileEnv, "foo")
125+
_ = os.Setenv(scw.ScwConfigPathEnv, tmpDir+"/config.yaml")
126+
_, err = NewScalewayProvider(context.TODO(), endpoint.NewDomainFilter([]string{"example.com"}), true)
127+
if err != nil {
128+
t.Errorf("failed : %s", err)
129+
}
130+
114131
_ = os.Setenv(scw.ScwAccessKeyEnv, "SCWXXXXXXXXXXXXXXXXX")
115132
_ = os.Setenv(scw.ScwSecretKeyEnv, "11111111-1111-1111-1111-111111111111")
116-
_, err := NewScalewayProvider(context.TODO(), endpoint.NewDomainFilter([]string{"example.com"}), true)
133+
_, err = NewScalewayProvider(context.TODO(), endpoint.NewDomainFilter([]string{"example.com"}), true)
117134
if err != nil {
118135
t.Errorf("failed : %s", err)
119136
}

0 commit comments

Comments
 (0)