Skip to content

Commit

Permalink
ensure HostCloudRegion is written to local cloud cache; added helper …
Browse files Browse the repository at this point in the history
…funcs to build/split HostCloudRegion
  • Loading branch information
ycliuhw committed Apr 17, 2019
1 parent 66433ee commit 4fd1859
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
22 changes: 18 additions & 4 deletions cloud/clouds.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ type Cloud struct {
CACertificates []string
}

// SplitHostCloudRegion splits host cloud region to cloudType and region.
func SplitHostCloudRegion(hostCloudRegion string) []string {
return strings.Split(hostCloudRegion, "/")
}

// BuildHostCloudRegion combines cloudType with region to host cloud region.
func BuildHostCloudRegion(cloudType, region string) string {
return cloudType + "/" + region
}

// Region is a cloud region.
type Region struct {
// Name is the name of the region.
Expand Down Expand Up @@ -197,6 +207,7 @@ type cloudSet struct {
type cloud struct {
Name string `yaml:"name,omitempty"`
Type string `yaml:"type"`
HostCloudRegion string `yaml:"host-cloud-region,omitempty"`
Description string `yaml:"description,omitempty"`
AuthTypes []AuthType `yaml:"auth-types,omitempty,flow"`
Endpoint string `yaml:"endpoint,omitempty"`
Expand Down Expand Up @@ -430,10 +441,11 @@ func cloudToInternal(in Cloud, withName bool) *cloud {
var regions regions
for _, r := range in.Regions {
regions.Slice = append(regions.Slice, yaml.MapItem{
r.Name, region{
r.Endpoint,
r.IdentityEndpoint,
r.StorageEndpoint,
Key: r.Name,
Value: region{
Endpoint: r.Endpoint,
IdentityEndpoint: r.IdentityEndpoint,
StorageEndpoint: r.StorageEndpoint,
},
})
}
Expand All @@ -444,6 +456,7 @@ func cloudToInternal(in Cloud, withName bool) *cloud {
return &cloud{
Name: name,
Type: in.Type,
HostCloudRegion: in.HostCloudRegion,
AuthTypes: in.AuthTypes,
Endpoint: in.Endpoint,
IdentityEndpoint: in.IdentityEndpoint,
Expand Down Expand Up @@ -478,6 +491,7 @@ func cloudFromInternal(in *cloud) Cloud {
meta := Cloud{
Name: in.Name,
Type: in.Type,
HostCloudRegion: in.HostCloudRegion,
AuthTypes: in.AuthTypes,
Endpoint: in.Endpoint,
IdentityEndpoint: in.IdentityEndpoint,
Expand Down
12 changes: 3 additions & 9 deletions cloudconfig/podcfg/podcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ type ControllerPodConfig struct {
// for a new juju caas pod. This is only relevant for the bootstrap pod.
type BootstrapConfig struct {
instancecfg.BootstrapConfig

// ControllerServiceType is the service type to use for a k8s controller.
ControllerServiceType string
}

// ControllerConfig represents controller-specific initialization information
Expand Down Expand Up @@ -264,9 +261,9 @@ func (cfg *ControllerPodConfig) verifyBootstrapConfig() (err error) {
if cfg.APIInfo.Tag != nil || cfg.Controller.MongoInfo.Tag != nil {
return errors.New("entity tag must be nil when bootstrapping")
}
if cfg.Bootstrap.ControllerServiceType == "" {
if cfg.Bootstrap.ControllerCloud.HostCloudRegion == "" {
return errors.New(`
controller service type is missing.
host cloud region is missing.
The k8s cloud definition might be stale, please try to re-import the k8s cloud using
juju add-k8s <cloud-name> --cluster-name <cluster-name> --local
Expand Down Expand Up @@ -382,9 +379,7 @@ func NewControllerPodConfig(
func NewBootstrapControllerPodConfig(
config controller.Config,
controllerName,
series,
controllerServiceType string,

series string,
) (*ControllerPodConfig, error) {
// For a bootstrap pod, the caller must provide the state.Info
// and the api.Info. The machine id must *always* be "0".
Expand Down Expand Up @@ -418,7 +413,6 @@ func NewBootstrapControllerPodConfig(
BootstrapMachineConstraints: constraints.Value{Mem: &mem},
},
},
ControllerServiceType: controllerServiceType,
}

pcfg.Jobs = []multiwatcher.MachineJob{
Expand Down

0 comments on commit 4fd1859

Please sign in to comment.