Skip to content

Commit

Permalink
test: cloud config
Browse files Browse the repository at this point in the history
Check cluster config params.
  • Loading branch information
sergelogvinov committed May 8, 2023
1 parent c051d38 commit f8c32e1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ RUN make build-all-archs
########################################

FROM --platform=${TARGETARCH} scratch AS release
LABEL org.opencontainers.image.source https://github.com/sergelogvinov/proxmox-cloud-controller-manager
LABEL org.opencontainers.image.source https://github.com/sergelogvinov/proxmox-cloud-controller-manager \
org.opencontainers.image.licenses = "Apache-2.0" \
org.opencontainers.image.description = "Proxmox VE CCM for Kubernetes"

COPY --from=gcr.io/distroless/static-debian11:nonroot . .
ARG TARGETARCH
Expand Down
19 changes: 19 additions & 0 deletions pkg/cluster/cloud_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

yaml "gopkg.in/yaml.v3"
)
Expand All @@ -46,6 +47,24 @@ func ReadCloudConfig(config io.Reader) (ClustersConfig, error) {
}
}

for idx, c := range cfg.Clusters {
if c.TokenID == "" {
return ClustersConfig{}, fmt.Errorf("cluster #%d: token_id is required", idx+1)
}

if c.TokenSecret == "" {
return ClustersConfig{}, fmt.Errorf("cluster #%d: token_secret is required", idx+1)
}

if c.Region == "" {
return ClustersConfig{}, fmt.Errorf("cluster #%d: region is required", idx+1)
}

if c.URL == "" || !strings.HasPrefix(c.URL, "http") {
return ClustersConfig{}, fmt.Errorf("cluster #%d: url is required", idx+1)
}
}

return cfg, nil
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/cluster/cloud_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ clusters:
assert.NotNil(t, err)
assert.NotNil(t, cfg)

// Non full config
cfg, err = cluster.ReadCloudConfig(strings.NewReader(`
clusters:
- url: abcd
region: cluster-1
`))

assert.NotNil(t, err)
assert.NotNil(t, cfg)

// Valid config with one cluster
cfg, err = cluster.ReadCloudConfig(strings.NewReader(`
clusters:
Expand Down

0 comments on commit f8c32e1

Please sign in to comment.