Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

Commit

Permalink
Accomodate 'host.cfdev.sh' route in non OSS' for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Emengo committed Apr 3, 2019
1 parent 6237176 commit 691a55a
Showing 1 changed file with 74 additions and 21 deletions.
95 changes: 74 additions & 21 deletions provision/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ const (

func (c *Controller) DeployBosh() error {
var (
credsPath = filepath.Join(c.Config.StateBosh, "creds.yml")
directorPath = filepath.Join(c.Config.StateBosh, "director.yml")
cloudConfigPath = filepath.Join(c.Config.StateBosh, "cloud-config.yml")
dnsConfigPath = filepath.Join(c.Config.StateBosh, "dns.yml")
stateJSONPath = filepath.Join(c.Config.StateBosh, "state.json")
boshRunner = runner.NewBosh(c.Config)
credhubIsDeployed = func() bool {
credsPath = filepath.Join(c.Config.StateBosh, "creds.yml")
directorPath = filepath.Join(c.Config.StateBosh, "director.yml")
cloudConfigPath = filepath.Join(c.Config.StateBosh, "cloud-config.yml")
dnsConfigPath = filepath.Join(c.Config.StateBosh, "dns.yml")
opsManDnsConfigPath = filepath.Join(c.Config.StateBosh, "ops-manager-dns-runtime.yml")
stateJSONPath = filepath.Join(c.Config.StateBosh, "state.json")
boshRunner = runner.NewBosh(c.Config)
credhubIsDeployed = func() bool {
// For now we determine if we have a BOSH Director with credhub deployed
// by looking to see if a creds.yml is present or not
// This is definitely not the most expressive solution
Expand Down Expand Up @@ -95,34 +96,86 @@ func (c *Controller) DeployBosh() error {
}

if runtime.GOOS == "linux" {
cloudConfigContents, err := ioutil.ReadFile(cloudConfigPath)
err = c.updateCloudConfig(boshRunner, cloudConfigPath)
if err != nil {
return err
}

cloudConfigContents = bytes.Replace(cloudConfigContents, []byte(vpnkitNameserverIP), []byte(kvmNameserverIP), -1)

err = ioutil.WriteFile(cloudConfigPath, cloudConfigContents, 0600)
err = c.updateDNSRuntime(boshRunner, dnsConfigPath)
if err != nil {
return err
}

boshRunner.Output("-n", "update-cloud-config", cloudConfigPath)

dnsConfigContents, err := ioutil.ReadFile(dnsConfigPath)
err = c.updateOpsManDNSRuntime(boshRunner, opsManDnsConfigPath)
if err != nil {
return err
}
}

dnsConfigContents = bytes.Replace(dnsConfigContents, []byte(vpnkitHostIP), []byte(kvmNameserverIP), -1)
return nil
}

err = ioutil.WriteFile(dnsConfigPath, dnsConfigContents, 0600)
if err != nil {
return err
}
func (c *Controller) updateCloudConfig(boshRunner *runner.Bosh, path string) error {
cloudConfigContents, err := ioutil.ReadFile(path)
if err != nil {
return err
}

boshRunner.Output("-n", "update-runtime-config", dnsConfigPath)
cloudConfigContents = bytes.Replace(cloudConfigContents, []byte(vpnkitNameserverIP), []byte(kvmNameserverIP), -1)

err = ioutil.WriteFile(path, cloudConfigContents, 0600)
if err != nil {
return err
}

return nil
_, err = boshRunner.Output("-n", "update-cloud-config", path)
return err
}

func (c *Controller) updateDNSRuntime(boshRunner *runner.Bosh, path string) error {
_, err := os.Stat(path)
if os.IsNotExist(err) {
// dns.yml does not exist
// skipping in favor of next DNS runtime method updater
return nil
}

dnsConfigContents, err := ioutil.ReadFile(path)
if err != nil {
return err
}

dnsConfigContents = bytes.Replace(dnsConfigContents, []byte(vpnkitHostIP), []byte(kvmNameserverIP), -1)

err = ioutil.WriteFile(path, dnsConfigContents, 0600)
if err != nil {
return err
}

_, err = boshRunner.Output("-n", "update-runtime-config", path)
return err
}

func (c *Controller) updateOpsManDNSRuntime(boshRunner *runner.Bosh, path string) error {
_, err := os.Stat(path)
if os.IsNotExist(err) {
// dns.yml does not exist
// skipping in favor of next DNS runtime method updater
return nil
}

dnsConfigContents, err := ioutil.ReadFile(path)
if err != nil {
return err
}

dnsConfigContents = bytes.Replace(dnsConfigContents, []byte(vpnkitHostIP), []byte(kvmNameserverIP), -1)

err = ioutil.WriteFile(path, dnsConfigContents, 0600)
if err != nil {
return err
}

_, err = boshRunner.Output("-n", "update-config", "--name", "ops_manager_dns_runtime", "--type", "runtime", path)
return err
}

0 comments on commit 691a55a

Please sign in to comment.