Skip to content

Commit c09c70d

Browse files
authored
Merge pull request #14 from SimonKienzler/switch-to-stackit-sdk
deps(refactor) Switch from `stackit-dns-api-client-go` to `stackit-sdk-go`
2 parents 68e6032 + 9c345be commit c09c70d

File tree

16 files changed

+406
-432
lines changed

16 files changed

+406
-432
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ demonstrates the deployment as a
3131
[sidecar container](https://kubernetes.io/docs/concepts/workloads/pods/#workload-resources-for-managing-pods)
3232
within the ExternalDNS pod.
3333

34-
```shell
34+
```shell
35+
# We create a Secret from an auth token. Alternatively, you can also
36+
# use keys to authenticate the webhook - see "Authentication" below.
3537
kubectl create secret generic external-dns-stackit-webhook --from-literal=auth-token='<Your-Token>'
3638
```
3739

@@ -217,7 +219,8 @@ The configuration of the STACKIT webhook can be accomplished through command lin
217219
Below are the options that are available.
218220

219221
- `--project-id`/`PROJECT_ID` (required): Specifies the project id of the STACKIT project.
220-
- `--auth-token`/`AUTH_TOKEN` (required): Defines the authentication token for the STACKIT API.
222+
- `--auth-token`/`AUTH_TOKEN` (required if `auth-key-path` is not set): Defines the authentication token for the STACKIT API. Mutually exclusive with 'auth-key-path'.
223+
- `--auth-key-path`/`AUTH_KEY_PATH` (required if `auth-token` is not set): Defines the file path of the service account key for the STACKIT API. Mutually exclusive with 'auth-token'.
221224
- `--worker`/`WORKER` (optional): Specifies the number of workers to employ for querying the API. Given that we
222225
need to iterate over all zones and records, it can be parallelized. However, it is important to avoid
223226
setting this number excessively high to prevent receiving 429 rate limiting from the API (default 10).

cmd/webhook/cmd/root.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ package cmd
33
import (
44
"fmt"
55
"log"
6-
"net/http"
76
"strings"
8-
"time"
97

108
"github.com/spf13/cobra"
119
"github.com/spf13/pflag"
1210
"github.com/spf13/viper"
1311
"github.com/stackitcloud/external-dns-stackit-webhook/internal/stackitprovider"
1412
"github.com/stackitcloud/external-dns-stackit-webhook/pkg/api"
1513
"github.com/stackitcloud/external-dns-stackit-webhook/pkg/metrics"
14+
"github.com/stackitcloud/external-dns-stackit-webhook/pkg/stackit"
1615
"go.uber.org/zap"
1716
"go.uber.org/zap/zapcore"
1817
"sigs.k8s.io/external-dns/endpoint"
@@ -21,6 +20,7 @@ import (
2120
var (
2221
apiPort string
2322
authBearerToken string
23+
authKeyPath string
2424
baseUrl string
2525
projectID string
2626
worker int
@@ -34,10 +34,6 @@ var rootCmd = &cobra.Command{
3434
Short: "provider webhook for the STACKIT DNS service",
3535
Long: "provider webhook for the STACKIT DNS service",
3636
Run: func(cmd *cobra.Command, args []string) {
37-
if len(authBearerToken) == 0 {
38-
panic("auth-token is required")
39-
}
40-
4137
logger := getLogger()
4238
defer func(logger *zap.Logger) {
4339
err := logger.Sync()
@@ -48,16 +44,23 @@ var rootCmd = &cobra.Command{
4844

4945
endpointDomainFilter := endpoint.DomainFilter{Filters: domainFilter}
5046

51-
stackitProvider, err := stackitprovider.NewStackitDNSProvider(stackitprovider.Config{
52-
BasePath: baseUrl,
53-
Token: authBearerToken,
54-
ProjectId: projectID,
55-
DomainFilter: endpointDomainFilter,
56-
DryRun: dryRun,
57-
Workers: worker,
58-
}, logger.With(zap.String("component", "stackitprovider")), &http.Client{
59-
Timeout: 10 * time.Second,
60-
})
47+
stackitConfigOptions, err := stackit.SetConfigOptions(baseUrl, authBearerToken, authKeyPath)
48+
if err != nil {
49+
panic(err)
50+
}
51+
52+
stackitProvider, err := stackitprovider.NewStackitDNSProvider(
53+
logger.With(zap.String("component", "stackitprovider")),
54+
// ExternalDNS provider config
55+
stackitprovider.Config{
56+
ProjectId: projectID,
57+
DomainFilter: endpointDomainFilter,
58+
DryRun: dryRun,
59+
Workers: worker,
60+
},
61+
// STACKIT client SDK config
62+
stackitConfigOptions...,
63+
)
6164
if err != nil {
6265
panic(err)
6366
}
@@ -110,7 +113,8 @@ func init() {
110113
cobra.OnInitialize(initConfig)
111114

112115
rootCmd.PersistentFlags().StringVar(&apiPort, "api-port", "8888", "Specifies the port to listen on.")
113-
rootCmd.PersistentFlags().StringVar(&authBearerToken, "auth-token", "", "Defines the authentication token for the STACKIT API.")
116+
rootCmd.PersistentFlags().StringVar(&authBearerToken, "auth-token", "", "Defines the authentication token for the STACKIT API. Mutually exclusive with 'auth-key-path'.")
117+
rootCmd.PersistentFlags().StringVar(&authKeyPath, "auth-key-path", "", "Defines the file path of the service account key for the STACKIT API. Mutually exclusive with 'auth-token'.")
114118
rootCmd.PersistentFlags().StringVar(&baseUrl, "base-url", "https://dns.api.stackit.cloud", " Identifies the Base URL for utilizing the API.")
115119
rootCmd.PersistentFlags().StringVar(&projectID, "project-id", "", "Specifies the project id of the STACKIT project.")
116120
rootCmd.PersistentFlags().IntVar(&worker, "worker", 10, "Specifies the number "+

go.mod

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ module github.com/stackitcloud/external-dns-stackit-webhook
33
go 1.20
44

55
require (
6-
github.com/antihax/optional v1.0.0
76
github.com/goccy/go-json v0.10.2
87
github.com/gofiber/adaptor/v2 v2.2.1
98
github.com/gofiber/fiber/v2 v2.50.0
109
github.com/prometheus/client_golang v1.17.0
1110
github.com/spf13/cobra v1.7.0
1211
github.com/spf13/pflag v1.0.5
1312
github.com/spf13/viper v1.17.0
14-
github.com/stackitcloud/stackit-dns-api-client-go v0.0.0-20230228185514-6838d6d6f051
13+
github.com/stackitcloud/stackit-sdk-go/core v0.10.0
14+
github.com/stackitcloud/stackit-sdk-go/services/dns v0.8.4
1515
github.com/stretchr/testify v1.8.4
1616
go.uber.org/mock v0.3.0
1717
go.uber.org/zap v1.26.0
@@ -27,10 +27,11 @@ require (
2727
github.com/fsnotify/fsnotify v1.6.0 // indirect
2828
github.com/go-logr/logr v1.2.4 // indirect
2929
github.com/gogo/protobuf v1.3.2 // indirect
30+
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect
3031
github.com/golang/protobuf v1.5.3 // indirect
3132
github.com/google/go-cmp v0.6.0 // indirect
3233
github.com/google/gofuzz v1.2.0 // indirect
33-
github.com/google/uuid v1.3.1 // indirect
34+
github.com/google/uuid v1.6.0 // indirect
3435
github.com/hashicorp/hcl v1.0.0 // indirect
3536
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3637
github.com/jmespath/go-jmespath v0.4.0 // indirect
@@ -57,18 +58,15 @@ require (
5758
github.com/sourcegraph/conc v0.3.0 // indirect
5859
github.com/spf13/afero v1.10.0 // indirect
5960
github.com/spf13/cast v1.5.1 // indirect
60-
github.com/spf13/jwalterweatherman v1.1.0 // indirect
6161
github.com/subosito/gotenv v1.6.0 // indirect
6262
github.com/valyala/bytebufferpool v1.0.0 // indirect
6363
github.com/valyala/fasthttp v1.50.0 // indirect
6464
github.com/valyala/tcplisten v1.0.0 // indirect
6565
go.uber.org/multierr v1.11.0 // indirect
6666
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
6767
golang.org/x/net v0.17.0 // indirect
68-
golang.org/x/oauth2 v0.13.0 // indirect
6968
golang.org/x/sys v0.13.0 // indirect
7069
golang.org/x/text v0.13.0 // indirect
71-
google.golang.org/appengine v1.6.8 // indirect
7270
google.golang.org/protobuf v1.31.0 // indirect
7371
gopkg.in/inf.v0 v0.9.1 // indirect
7472
gopkg.in/ini.v1 v1.67.0 // indirect

0 commit comments

Comments
 (0)