Merge "Fix cluster reconciliation logic"

This commit is contained in:
Zuul 2020-05-19 23:42:58 +00:00 committed by Gerrit Code Review
commit 6b86b120ab
2 changed files with 17 additions and 8 deletions

View File

@ -175,21 +175,26 @@ func (c *Config) reconcileClusters() (map[string]string, bool) {
// Probable should just add a number _<COUNTER to it
}
// Update the airship config file
// The cluster in the kubeconfig is not present in the airship config. Create it.
if c.Clusters[clusterComplexName.Name] == nil {
c.Clusters[clusterComplexName.Name] = NewClusterPurpose()
}
// NOTE(drewwalters96): This is a user error because a cluster is defined in name but incomplete. We
// need to fail sooner than this function; add up-front validation for this later.
if c.Clusters[clusterComplexName.Name].ClusterTypes == nil {
c.Clusters[clusterComplexName.Name].ClusterTypes = make(map[string]*Cluster)
}
// The cluster is defined, but the type is not. Define the type.
if c.Clusters[clusterComplexName.Name].ClusterTypes[clusterComplexName.Type] == nil {
// We have to make sure that ClusterTypes map is initialized properly before assignment
if c.Clusters[clusterComplexName.Name].ClusterTypes == nil {
c.Clusters[clusterComplexName.Name].ClusterTypes = make(map[string]*Cluster)
}
c.Clusters[clusterComplexName.Name].ClusterTypes[clusterComplexName.Type] = NewCluster()
}
// Point cluster at kubeconfig
configCluster := c.Clusters[clusterComplexName.Name].ClusterTypes[clusterComplexName.Type]
configCluster.NameInKubeconf = clusterComplexName.String()
configCluster.Bootstrap = AirshipDefaultBootstrapInfo
configCluster.ManagementConfiguration = AirshipDefaultManagementConfiguration
// Store the reference to the KubeConfig Cluster in the Airship Config
configCluster.SetKubeCluster(cluster)
}

View File

@ -91,7 +91,11 @@ func NewContext() *Context {
// NewCluster is a convenience function that returns a new Cluster
func NewCluster() *Cluster {
return &Cluster{}
return &Cluster{
NameInKubeconf: "",
Bootstrap: AirshipDefaultBootstrapInfo,
ManagementConfiguration: AirshipDefaultManagementConfiguration,
}
}
// NewManifest is a convenience function that returns a new Manifest