@@ -20,13 +20,14 @@ const (
2020
2121func (c * Controller ) DeployBosh () error {
2222 var (
23- credsPath = filepath .Join (c .Config .StateBosh , "creds.yml" )
24- directorPath = filepath .Join (c .Config .StateBosh , "director.yml" )
25- cloudConfigPath = filepath .Join (c .Config .StateBosh , "cloud-config.yml" )
26- dnsConfigPath = filepath .Join (c .Config .StateBosh , "dns.yml" )
27- stateJSONPath = filepath .Join (c .Config .StateBosh , "state.json" )
28- boshRunner = runner .NewBosh (c .Config )
29- credhubIsDeployed = func () bool {
23+ credsPath = filepath .Join (c .Config .StateBosh , "creds.yml" )
24+ directorPath = filepath .Join (c .Config .StateBosh , "director.yml" )
25+ cloudConfigPath = filepath .Join (c .Config .StateBosh , "cloud-config.yml" )
26+ dnsConfigPath = filepath .Join (c .Config .StateBosh , "dns.yml" )
27+ opsManDnsConfigPath = filepath .Join (c .Config .StateBosh , "ops-manager-dns-runtime.yml" )
28+ stateJSONPath = filepath .Join (c .Config .StateBosh , "state.json" )
29+ boshRunner = runner .NewBosh (c .Config )
30+ credhubIsDeployed = func () bool {
3031 // For now we determine if we have a BOSH Director with credhub deployed
3132 // by looking to see if a creds.yml is present or not
3233 // This is definitely not the most expressive solution
@@ -95,34 +96,86 @@ func (c *Controller) DeployBosh() error {
9596 }
9697
9798 if runtime .GOOS == "linux" {
98- cloudConfigContents , err := ioutil . ReadFile ( cloudConfigPath )
99+ err = c . updateCloudConfig ( boshRunner , cloudConfigPath )
99100 if err != nil {
100101 return err
101102 }
102103
103- cloudConfigContents = bytes .Replace (cloudConfigContents , []byte (vpnkitNameserverIP ), []byte (kvmNameserverIP ), - 1 )
104-
105- err = ioutil .WriteFile (cloudConfigPath , cloudConfigContents , 0600 )
104+ err = c .updateDNSRuntime (boshRunner , dnsConfigPath )
106105 if err != nil {
107106 return err
108107 }
109108
110- boshRunner .Output ("-n" , "update-cloud-config" , cloudConfigPath )
111-
112- dnsConfigContents , err := ioutil .ReadFile (dnsConfigPath )
109+ err = c .updateOpsManDNSRuntime (boshRunner , opsManDnsConfigPath )
113110 if err != nil {
114111 return err
115112 }
113+ }
116114
117- dnsConfigContents = bytes .Replace (dnsConfigContents , []byte (vpnkitHostIP ), []byte (kvmNameserverIP ), - 1 )
115+ return nil
116+ }
118117
119- err = ioutil .WriteFile (dnsConfigPath , dnsConfigContents , 0600 )
120- if err != nil {
121- return err
122- }
118+ func (c * Controller ) updateCloudConfig (boshRunner * runner.Bosh , path string ) error {
119+ cloudConfigContents , err := ioutil .ReadFile (path )
120+ if err != nil {
121+ return err
122+ }
123123
124- boshRunner .Output ("-n" , "update-runtime-config" , dnsConfigPath )
124+ cloudConfigContents = bytes .Replace (cloudConfigContents , []byte (vpnkitNameserverIP ), []byte (kvmNameserverIP ), - 1 )
125+
126+ err = ioutil .WriteFile (path , cloudConfigContents , 0600 )
127+ if err != nil {
128+ return err
125129 }
126130
127- return nil
131+ _ , err = boshRunner .Output ("-n" , "update-cloud-config" , path )
132+ return err
133+ }
134+
135+ func (c * Controller ) updateDNSRuntime (boshRunner * runner.Bosh , path string ) error {
136+ _ , err := os .Stat (path )
137+ if os .IsNotExist (err ) {
138+ // dns.yml does not exist
139+ // skipping in favor of next DNS runtime method updater
140+ return nil
141+ }
142+
143+ dnsConfigContents , err := ioutil .ReadFile (path )
144+ if err != nil {
145+ return err
146+ }
147+
148+ dnsConfigContents = bytes .Replace (dnsConfigContents , []byte (vpnkitHostIP ), []byte (kvmNameserverIP ), - 1 )
149+
150+ err = ioutil .WriteFile (path , dnsConfigContents , 0600 )
151+ if err != nil {
152+ return err
153+ }
154+
155+ _ , err = boshRunner .Output ("-n" , "update-runtime-config" , path )
156+ return err
157+ }
158+
159+ func (c * Controller ) updateOpsManDNSRuntime (boshRunner * runner.Bosh , path string ) error {
160+ _ , err := os .Stat (path )
161+ if os .IsNotExist (err ) {
162+ // dns.yml does not exist
163+ // skipping in favor of next DNS runtime method updater
164+ return nil
165+ }
166+
167+ dnsConfigContents , err := ioutil .ReadFile (path )
168+ if err != nil {
169+ return err
170+ }
171+
172+ dnsConfigContents = bytes .Replace (dnsConfigContents , []byte (vpnkitHostIP ), []byte (kvmNameserverIP ), - 1 )
173+
174+ err = ioutil .WriteFile (path , dnsConfigContents , 0600 )
175+ if err != nil {
176+ return err
177+ }
178+
179+ _ , err = boshRunner .Output ("-n" , "update-config" , "--name" , "ops_manager_dns_runtime" , "--type" , "runtime" , path )
180+ return err
128181}
0 commit comments