mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-04 15:25:00 -04:00
join: make Azure instance names k8s compliant (#807)
join: make Azure instance names k8s compliant
This commit is contained in:
parent
edd51cb137
commit
d1195d1d5f
4 changed files with 133 additions and 23 deletions
|
@ -10,7 +10,6 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
|
@ -465,22 +464,32 @@ func TestJoinCluster(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestK8sCompliantHostname(t *testing.T) {
|
||||
compliantHostname := regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`)
|
||||
testCases := map[string]struct {
|
||||
hostname string
|
||||
wantHostname string
|
||||
input string
|
||||
expected string
|
||||
wantErr bool
|
||||
}{
|
||||
"azure scale set names work": {
|
||||
hostname: "constellation-scale-set-bootstrappers-name_0",
|
||||
wantHostname: "constellation-scale-set-bootstrappers-name-0",
|
||||
"no change": {
|
||||
input: "test",
|
||||
expected: "test",
|
||||
},
|
||||
"compliant hostname is not modified": {
|
||||
hostname: "abcd-123",
|
||||
wantHostname: "abcd-123",
|
||||
"uppercase": {
|
||||
input: "TEST",
|
||||
expected: "test",
|
||||
},
|
||||
"uppercase hostnames are lowercased": {
|
||||
hostname: "ABCD",
|
||||
wantHostname: "abcd",
|
||||
"underscore": {
|
||||
input: "test_node",
|
||||
expected: "test-node",
|
||||
},
|
||||
"empty": {
|
||||
input: "",
|
||||
expected: "",
|
||||
wantErr: true,
|
||||
},
|
||||
"error": {
|
||||
input: "test_node_",
|
||||
expected: "",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -488,10 +497,13 @@ func TestK8sCompliantHostname(t *testing.T) {
|
|||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
hostname := k8sCompliantHostname(tc.hostname)
|
||||
|
||||
assert.Equal(tc.wantHostname, hostname)
|
||||
assert.Regexp(compliantHostname, hostname)
|
||||
actual, err := k8sCompliantHostname(tc.input)
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
assert.NoError(err)
|
||||
assert.Equal(tc.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue