Fix cluster name parsing
For cluster names that contain underscore ('_') symbol config module removed some part of the name due to hardcoded indexes after name split Change-Id: Ibd1e9b3ef2fce7e43cbdf41f4b1852933a253868
This commit is contained in:
parent
9a47c9b423
commit
a125dc5d8a
@ -40,7 +40,7 @@ type setClusterTest struct {
|
||||
}
|
||||
|
||||
const (
|
||||
testCluster = "my-new-cluster"
|
||||
testCluster = "my_new-cluster"
|
||||
)
|
||||
|
||||
func TestSetClusterWithCAFile(t *testing.T) {
|
||||
|
@ -930,15 +930,27 @@ func (c *ClusterComplexName) validName() bool {
|
||||
err := ValidClusterType(c.clusterType)
|
||||
return c.clusterName != "" && err == nil
|
||||
}
|
||||
|
||||
func (c *ClusterComplexName) FromName(clusterName string) {
|
||||
if clusterName != "" {
|
||||
if clusterName == "" {
|
||||
return
|
||||
}
|
||||
|
||||
userNameSplit := strings.Split(clusterName, AirshipClusterNameSep)
|
||||
if len(userNameSplit) == 2 {
|
||||
c.clusterType = userNameSplit[1]
|
||||
if len(userNameSplit) == 1 {
|
||||
c.clusterName = clusterName
|
||||
return
|
||||
}
|
||||
c.clusterName = userNameSplit[0]
|
||||
|
||||
for _, cType := range AllClusterTypes {
|
||||
if userNameSplit[len(userNameSplit)-1] == cType {
|
||||
c.clusterType = userNameSplit[len(userNameSplit)-1]
|
||||
c.clusterName = strings.Join(userNameSplit[:len(userNameSplit)-1], AirshipClusterNameSep)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ClusterComplexName) WithType(clusterName string, clusterType string) {
|
||||
c.FromName(clusterName)
|
||||
c.SetClusterType(clusterType)
|
||||
|
@ -50,20 +50,20 @@ func DummyConfig() *Config {
|
||||
kubeConfig: kubeconfig.NewConfig(),
|
||||
}
|
||||
dummyCluster := conf.Clusters["dummy_cluster"]
|
||||
conf.KubeConfig().Clusters["dummycluster_target"] = dummyCluster.ClusterTypes[Target].KubeCluster()
|
||||
conf.KubeConfig().Clusters["dummycluster_ephemeral"] = dummyCluster.ClusterTypes[Ephemeral].KubeCluster()
|
||||
conf.KubeConfig().Clusters["dummy_cluster_target"] = dummyCluster.ClusterTypes[Target].KubeCluster()
|
||||
conf.KubeConfig().Clusters["dummy_cluster_ephemeral"] = dummyCluster.ClusterTypes[Ephemeral].KubeCluster()
|
||||
return conf
|
||||
}
|
||||
|
||||
// DummyContext , utility function used for tests
|
||||
func DummyContext() *Context {
|
||||
c := NewContext()
|
||||
c.NameInKubeconf = "dummy_cluster"
|
||||
c.NameInKubeconf = "dummy_cluster_ephemeral"
|
||||
c.Manifest = "dummy_manifest"
|
||||
context := kubeconfig.NewContext()
|
||||
context.Namespace = "dummy_namespace"
|
||||
context.AuthInfo = "dummy_user"
|
||||
context.Cluster = "dummycluster_ephemeral"
|
||||
context.Cluster = "dummy_cluster_ephemeral"
|
||||
c.SetKubeContext(context)
|
||||
|
||||
return c
|
||||
@ -78,7 +78,7 @@ func DummyCluster() *Cluster {
|
||||
cluster.InsecureSkipTLSVerify = false
|
||||
cluster.CertificateAuthority = "dummy_ca"
|
||||
c.SetKubeCluster(cluster)
|
||||
c.NameInKubeconf = "dummycluster_target"
|
||||
c.NameInKubeconf = "dummy_cluster_target"
|
||||
c.Bootstrap = "dummy_bootstrap_config"
|
||||
return c
|
||||
}
|
||||
@ -125,7 +125,7 @@ func DummyModules() *Modules {
|
||||
func DummyClusterPurpose() *ClusterPurpose {
|
||||
cp := NewClusterPurpose()
|
||||
cp.ClusterTypes["ephemeral"] = DummyCluster()
|
||||
cp.ClusterTypes["ephemeral"].NameInKubeconf = "dummycluster_ephemeral"
|
||||
cp.ClusterTypes["ephemeral"].NameInKubeconf = "dummy_cluster_ephemeral"
|
||||
cp.ClusterTypes["target"] = DummyCluster()
|
||||
return cp
|
||||
}
|
||||
|
2
pkg/config/testdata/cluster-string.yaml
vendored
2
pkg/config/testdata/cluster-string.yaml
vendored
@ -1,5 +1,5 @@
|
||||
bootstrap-info: dummy_bootstrap_config
|
||||
cluster-kubeconf: dummycluster_target
|
||||
cluster-kubeconf: dummy_cluster_target
|
||||
|
||||
LocationOfOrigin: ""
|
||||
certificate-authority: dummy_ca
|
||||
|
6
pkg/config/testdata/config-string.yaml
vendored
6
pkg/config/testdata/config-string.yaml
vendored
@ -4,13 +4,13 @@ clusters:
|
||||
cluster-type:
|
||||
ephemeral:
|
||||
bootstrap-info: dummy_bootstrap_config
|
||||
cluster-kubeconf: dummycluster_ephemeral
|
||||
cluster-kubeconf: dummy_cluster_ephemeral
|
||||
target:
|
||||
bootstrap-info: dummy_bootstrap_config
|
||||
cluster-kubeconf: dummycluster_target
|
||||
cluster-kubeconf: dummy_cluster_target
|
||||
contexts:
|
||||
dummy_context:
|
||||
context-kubeconf: dummy_cluster
|
||||
context-kubeconf: dummy_cluster_ephemeral
|
||||
manifest: dummy_manifest
|
||||
current-context: dummy_context
|
||||
kind: Config
|
||||
|
4
pkg/config/testdata/context-string.yaml
vendored
4
pkg/config/testdata/context-string.yaml
vendored
@ -1,7 +1,7 @@
|
||||
context-kubeconf: dummy_cluster
|
||||
context-kubeconf: dummy_cluster_ephemeral
|
||||
manifest: dummy_manifest
|
||||
|
||||
LocationOfOrigin: ""
|
||||
cluster: dummycluster_ephemeral
|
||||
cluster: dummy_cluster_ephemeral
|
||||
namespace: dummy_namespace
|
||||
user: dummy_user
|
||||
|
@ -1,7 +1,7 @@
|
||||
Cluster: dummycluster
|
||||
Cluster: dummy_cluster
|
||||
target:
|
||||
bootstrap-info: dummy_bootstrap_config
|
||||
cluster-kubeconf: dummycluster_target
|
||||
cluster-kubeconf: dummy_cluster_target
|
||||
|
||||
LocationOfOrigin: ""
|
||||
certificate-authority: dummy_ca
|
||||
|
Loading…
Reference in New Issue
Block a user