test: cloud config

Check cluster config params.
This commit is contained in:
Serge Logvinov
2023-05-08 14:52:21 +03:00
parent c051d386d0
commit f8c32e1e8e
3 changed files with 32 additions and 1 deletions

View File

@@ -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

View File

@@ -21,6 +21,7 @@ import (
"io"
"os"
"path/filepath"
"strings"
yaml "gopkg.in/yaml.v3"
)
@@ -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
}

View File

@@ -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: