@@ -20,13 +20,14 @@ const (
20
20
21
21
func (c * Controller ) DeployBosh () error {
22
22
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 {
30
31
// For now we determine if we have a BOSH Director with credhub deployed
31
32
// by looking to see if a creds.yml is present or not
32
33
// This is definitely not the most expressive solution
@@ -95,34 +96,86 @@ func (c *Controller) DeployBosh() error {
95
96
}
96
97
97
98
if runtime .GOOS == "linux" {
98
- cloudConfigContents , err := ioutil . ReadFile ( cloudConfigPath )
99
+ err = c . updateCloudConfig ( boshRunner , cloudConfigPath )
99
100
if err != nil {
100
101
return err
101
102
}
102
103
103
- cloudConfigContents = bytes .Replace (cloudConfigContents , []byte (vpnkitNameserverIP ), []byte (kvmNameserverIP ), - 1 )
104
-
105
- err = ioutil .WriteFile (cloudConfigPath , cloudConfigContents , 0600 )
104
+ err = c .updateDNSRuntime (boshRunner , dnsConfigPath )
106
105
if err != nil {
107
106
return err
108
107
}
109
108
110
- boshRunner .Output ("-n" , "update-cloud-config" , cloudConfigPath )
111
-
112
- dnsConfigContents , err := ioutil .ReadFile (dnsConfigPath )
109
+ err = c .updateOpsManDNSRuntime (boshRunner , opsManDnsConfigPath )
113
110
if err != nil {
114
111
return err
115
112
}
113
+ }
116
114
117
- dnsConfigContents = bytes .Replace (dnsConfigContents , []byte (vpnkitHostIP ), []byte (kvmNameserverIP ), - 1 )
115
+ return nil
116
+ }
118
117
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
+ }
123
123
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
125
129
}
126
130
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
128
181
}
0 commit comments