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 (
|
const (
|
||||||
testCluster = "my-new-cluster"
|
testCluster = "my_new-cluster"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSetClusterWithCAFile(t *testing.T) {
|
func TestSetClusterWithCAFile(t *testing.T) {
|
||||||
|
@ -930,15 +930,27 @@ func (c *ClusterComplexName) validName() bool {
|
|||||||
err := ValidClusterType(c.clusterType)
|
err := ValidClusterType(c.clusterType)
|
||||||
return c.clusterName != "" && err == nil
|
return c.clusterName != "" && err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClusterComplexName) FromName(clusterName string) {
|
func (c *ClusterComplexName) FromName(clusterName string) {
|
||||||
if clusterName != "" {
|
if clusterName == "" {
|
||||||
userNameSplit := strings.Split(clusterName, AirshipClusterNameSep)
|
return
|
||||||
if len(userNameSplit) == 2 {
|
}
|
||||||
c.clusterType = userNameSplit[1]
|
|
||||||
|
userNameSplit := strings.Split(clusterName, AirshipClusterNameSep)
|
||||||
|
if len(userNameSplit) == 1 {
|
||||||
|
c.clusterName = clusterName
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
c.clusterName = userNameSplit[0]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClusterComplexName) WithType(clusterName string, clusterType string) {
|
func (c *ClusterComplexName) WithType(clusterName string, clusterType string) {
|
||||||
c.FromName(clusterName)
|
c.FromName(clusterName)
|
||||||
c.SetClusterType(clusterType)
|
c.SetClusterType(clusterType)
|
||||||
|
@ -50,20 +50,20 @@ func DummyConfig() *Config {
|
|||||||
kubeConfig: kubeconfig.NewConfig(),
|
kubeConfig: kubeconfig.NewConfig(),
|
||||||
}
|
}
|
||||||
dummyCluster := conf.Clusters["dummy_cluster"]
|
dummyCluster := conf.Clusters["dummy_cluster"]
|
||||||
conf.KubeConfig().Clusters["dummycluster_target"] = dummyCluster.ClusterTypes[Target].KubeCluster()
|
conf.KubeConfig().Clusters["dummy_cluster_target"] = dummyCluster.ClusterTypes[Target].KubeCluster()
|
||||||
conf.KubeConfig().Clusters["dummycluster_ephemeral"] = dummyCluster.ClusterTypes[Ephemeral].KubeCluster()
|
conf.KubeConfig().Clusters["dummy_cluster_ephemeral"] = dummyCluster.ClusterTypes[Ephemeral].KubeCluster()
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
||||||
// DummyContext , utility function used for tests
|
// DummyContext , utility function used for tests
|
||||||
func DummyContext() *Context {
|
func DummyContext() *Context {
|
||||||
c := NewContext()
|
c := NewContext()
|
||||||
c.NameInKubeconf = "dummy_cluster"
|
c.NameInKubeconf = "dummy_cluster_ephemeral"
|
||||||
c.Manifest = "dummy_manifest"
|
c.Manifest = "dummy_manifest"
|
||||||
context := kubeconfig.NewContext()
|
context := kubeconfig.NewContext()
|
||||||
context.Namespace = "dummy_namespace"
|
context.Namespace = "dummy_namespace"
|
||||||
context.AuthInfo = "dummy_user"
|
context.AuthInfo = "dummy_user"
|
||||||
context.Cluster = "dummycluster_ephemeral"
|
context.Cluster = "dummy_cluster_ephemeral"
|
||||||
c.SetKubeContext(context)
|
c.SetKubeContext(context)
|
||||||
|
|
||||||
return c
|
return c
|
||||||
@ -78,7 +78,7 @@ func DummyCluster() *Cluster {
|
|||||||
cluster.InsecureSkipTLSVerify = false
|
cluster.InsecureSkipTLSVerify = false
|
||||||
cluster.CertificateAuthority = "dummy_ca"
|
cluster.CertificateAuthority = "dummy_ca"
|
||||||
c.SetKubeCluster(cluster)
|
c.SetKubeCluster(cluster)
|
||||||
c.NameInKubeconf = "dummycluster_target"
|
c.NameInKubeconf = "dummy_cluster_target"
|
||||||
c.Bootstrap = "dummy_bootstrap_config"
|
c.Bootstrap = "dummy_bootstrap_config"
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ func DummyModules() *Modules {
|
|||||||
func DummyClusterPurpose() *ClusterPurpose {
|
func DummyClusterPurpose() *ClusterPurpose {
|
||||||
cp := NewClusterPurpose()
|
cp := NewClusterPurpose()
|
||||||
cp.ClusterTypes["ephemeral"] = DummyCluster()
|
cp.ClusterTypes["ephemeral"] = DummyCluster()
|
||||||
cp.ClusterTypes["ephemeral"].NameInKubeconf = "dummycluster_ephemeral"
|
cp.ClusterTypes["ephemeral"].NameInKubeconf = "dummy_cluster_ephemeral"
|
||||||
cp.ClusterTypes["target"] = DummyCluster()
|
cp.ClusterTypes["target"] = DummyCluster()
|
||||||
return cp
|
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
|
bootstrap-info: dummy_bootstrap_config
|
||||||
cluster-kubeconf: dummycluster_target
|
cluster-kubeconf: dummy_cluster_target
|
||||||
|
|
||||||
LocationOfOrigin: ""
|
LocationOfOrigin: ""
|
||||||
certificate-authority: dummy_ca
|
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:
|
cluster-type:
|
||||||
ephemeral:
|
ephemeral:
|
||||||
bootstrap-info: dummy_bootstrap_config
|
bootstrap-info: dummy_bootstrap_config
|
||||||
cluster-kubeconf: dummycluster_ephemeral
|
cluster-kubeconf: dummy_cluster_ephemeral
|
||||||
target:
|
target:
|
||||||
bootstrap-info: dummy_bootstrap_config
|
bootstrap-info: dummy_bootstrap_config
|
||||||
cluster-kubeconf: dummycluster_target
|
cluster-kubeconf: dummy_cluster_target
|
||||||
contexts:
|
contexts:
|
||||||
dummy_context:
|
dummy_context:
|
||||||
context-kubeconf: dummy_cluster
|
context-kubeconf: dummy_cluster_ephemeral
|
||||||
manifest: dummy_manifest
|
manifest: dummy_manifest
|
||||||
current-context: dummy_context
|
current-context: dummy_context
|
||||||
kind: Config
|
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
|
manifest: dummy_manifest
|
||||||
|
|
||||||
LocationOfOrigin: ""
|
LocationOfOrigin: ""
|
||||||
cluster: dummycluster_ephemeral
|
cluster: dummy_cluster_ephemeral
|
||||||
namespace: dummy_namespace
|
namespace: dummy_namespace
|
||||||
user: dummy_user
|
user: dummy_user
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
Cluster: dummycluster
|
Cluster: dummy_cluster
|
||||||
target:
|
target:
|
||||||
bootstrap-info: dummy_bootstrap_config
|
bootstrap-info: dummy_bootstrap_config
|
||||||
cluster-kubeconf: dummycluster_target
|
cluster-kubeconf: dummy_cluster_target
|
||||||
|
|
||||||
LocationOfOrigin: ""
|
LocationOfOrigin: ""
|
||||||
certificate-authority: dummy_ca
|
certificate-authority: dummy_ca
|
||||||
|
Loading…
Reference in New Issue
Block a user