44 "fmt"
55 "os"
66 "path/filepath"
7- "strings"
87
98 "github.com/pkg/errors"
109 "k8s.io/apimachinery/pkg/util/validation/field"
@@ -13,7 +12,6 @@ import (
1312 "github.com/openshift/installer/pkg/asset"
1413 "github.com/openshift/installer/pkg/types/agent"
1514 "github.com/openshift/installer/pkg/types/agent/conversion"
16- "github.com/openshift/installer/pkg/types/baremetal/validation"
1715 "github.com/openshift/installer/pkg/validate"
1816)
1917
@@ -43,7 +41,6 @@ func (*AgentConfig) Dependencies() []asset.Asset {
4341
4442// Generate generates the Agent Config manifest.
4543func (a * AgentConfig ) Generate (dependencies asset.Parents ) error {
46-
4744 // TODO: We are temporarily generating a template of the agent-config.yaml
4845 // Change this when its interactive survey is implemented.
4946 agentConfigTemplate := `#
@@ -103,7 +100,7 @@ hosts:
103100 return nil
104101}
105102
106- // PersistToFile writes the agent-config.yaml file to the assets folder
103+ // PersistToFile writes the agent-config.yaml file to the assets folder.
107104func (a * AgentConfig ) PersistToFile (directory string ) error {
108105 templatePath := filepath .Join (directory , agentConfigFilename )
109106 templateByte := []byte (a .Template )
@@ -126,7 +123,6 @@ func (a *AgentConfig) Files() []*asset.File {
126123
127124// Load returns agent config asset from the disk.
128125func (a * AgentConfig ) Load (f asset.FileFetcher ) (bool , error ) {
129-
130126 file , err := f .FetchByName (agentConfigFilename )
131127 if err != nil {
132128 if os .IsNotExist (err ) {
@@ -146,6 +142,7 @@ func (a *AgentConfig) Load(f asset.FileFetcher) (bool, error) {
146142 }
147143
148144 a .File , a .Config = file , config
145+
149146 if err = a .finish (); err != nil {
150147 return false , err
151148 }
@@ -168,18 +165,10 @@ func (a *AgentConfig) validateAgent() field.ErrorList {
168165 allErrs = append (allErrs , err ... )
169166 }
170167
171- if err := a .validateHosts (); err != nil {
172- allErrs = append (allErrs , err ... )
173- }
174-
175168 if err := a .validateAdditionalNTPSources (field .NewPath ("AdditionalNTPSources" ), a .Config .AdditionalNTPSources ); err != nil {
176169 allErrs = append (allErrs , err ... )
177170 }
178171
179- if err := a .validateRendezvousIPNotWorker (a .Config .RendezvousIP , a .Config .Hosts ); err != nil {
180- allErrs = append (allErrs , err ... )
181- }
182-
183172 if err := a .validateBootArtifactsBaseURL (); err != nil {
184173 allErrs = append (allErrs , err ... )
185174 }
@@ -192,7 +181,7 @@ func (a *AgentConfig) validateRendezvousIP() field.ErrorList {
192181
193182 rendezvousIPPath := field .NewPath ("rendezvousIP" )
194183
195- //empty rendezvous ip is fine
184+ // empty rendezvous ip is fine
196185 if a .Config .RendezvousIP == "" {
197186 return nil
198187 }
@@ -204,86 +193,6 @@ func (a *AgentConfig) validateRendezvousIP() field.ErrorList {
204193 return allErrs
205194}
206195
207- func (a * AgentConfig ) validateHosts () field.ErrorList {
208- var allErrs field.ErrorList
209-
210- macs := make (map [string ]bool )
211- for i , host := range a .Config .Hosts {
212-
213- hostPath := field .NewPath ("Hosts" ).Index (i )
214-
215- if err := a .validateHostInterfaces (hostPath , host , macs ); err != nil {
216- allErrs = append (allErrs , err ... )
217- }
218-
219- if err := a .validateHostRootDeviceHints (hostPath , host ); err != nil {
220- allErrs = append (allErrs , err ... )
221- }
222-
223- if err := a .validateRoles (hostPath , host ); err != nil {
224- allErrs = append (allErrs , err ... )
225- }
226- }
227-
228- return allErrs
229- }
230-
231- func (a * AgentConfig ) validateHostInterfaces (hostPath * field.Path , host agent.Host , macs map [string ]bool ) field.ErrorList {
232- var allErrs field.ErrorList
233-
234- interfacePath := hostPath .Child ("Interfaces" )
235- if len (host .Interfaces ) == 0 {
236- allErrs = append (allErrs , field .Required (interfacePath , "at least one interface must be defined for each node" ))
237- }
238-
239- for j := range host .Interfaces {
240- mac := host .Interfaces [j ].MacAddress
241- macAddressPath := interfacePath .Index (j ).Child ("macAddress" )
242-
243- if mac == "" {
244- allErrs = append (allErrs , field .Required (macAddressPath , "each interface must have a MAC address defined" ))
245- continue
246- }
247-
248- if err := validate .MAC (mac ); err != nil {
249- allErrs = append (allErrs , field .Invalid (macAddressPath , mac , err .Error ()))
250- }
251-
252- if _ , ok := macs [mac ]; ok {
253- allErrs = append (allErrs , field .Invalid (macAddressPath , mac , "duplicate MAC address found" ))
254- }
255- macs [mac ] = true
256- }
257-
258- return allErrs
259- }
260-
261- func (a * AgentConfig ) validateHostRootDeviceHints (hostPath * field.Path , host agent.Host ) field.ErrorList {
262- rdhPath := hostPath .Child ("rootDeviceHints" )
263- allErrs := validation .ValidateHostRootDeviceHints (& host .RootDeviceHints , rdhPath )
264-
265- if host .RootDeviceHints .WWNWithExtension != "" {
266- allErrs = append (allErrs , field .Forbidden (
267- rdhPath .Child ("wwnWithExtension" ), "WWN extensions are not supported in root device hints" ))
268- }
269-
270- if host .RootDeviceHints .WWNVendorExtension != "" {
271- allErrs = append (allErrs , field .Forbidden (rdhPath .Child ("wwnVendorExtension" ), "WWN vendor extensions are not supported in root device hints" ))
272- }
273-
274- return allErrs
275- }
276-
277- func (a * AgentConfig ) validateRoles (hostPath * field.Path , host agent.Host ) field.ErrorList {
278- var allErrs field.ErrorList
279-
280- if len (host .Role ) > 0 && host .Role != "master" && host .Role != "worker" {
281- allErrs = append (allErrs , field .Forbidden (hostPath .Child ("Host" ), "host role has incorrect value. Role must either be 'master' or 'worker'" ))
282- }
283-
284- return allErrs
285- }
286-
287196func (a * AgentConfig ) validateAdditionalNTPSources (additionalNTPSourcesPath * field.Path , sources []string ) field.ErrorList {
288197 var allErrs field.ErrorList
289198
@@ -300,21 +209,6 @@ func (a *AgentConfig) validateAdditionalNTPSources(additionalNTPSourcesPath *fie
300209 return allErrs
301210}
302211
303- func (a * AgentConfig ) validateRendezvousIPNotWorker (rendezvousIP string , hosts []agent.Host ) field.ErrorList {
304- var allErrs field.ErrorList
305-
306- if rendezvousIP != "" {
307- for i , host := range hosts {
308- hostPath := field .NewPath ("Hosts" ).Index (i )
309- if strings .Contains (string (host .NetworkConfig .Raw ), rendezvousIP ) && host .Role == "worker" {
310- errMsg := "Host " + host .Hostname + " has role 'worker' and has the rendezvousIP assigned to it. The rendezvousIP must be assigned to a control plane host."
311- allErrs = append (allErrs , field .Forbidden (hostPath .Child ("Host" ), errMsg ))
312- }
313- }
314- }
315- return allErrs
316- }
317-
318212func (a * AgentConfig ) validateBootArtifactsBaseURL () field.ErrorList {
319213 var allErrs field.ErrorList
320214
@@ -332,48 +226,6 @@ func (a *AgentConfig) validateBootArtifactsBaseURL() field.ErrorList {
332226 return allErrs
333227}
334228
335- // HostConfigFileMap is a map from a filepath ("<host>/<file>") to file content
336- // for hostconfig files.
337- type HostConfigFileMap map [string ][]byte
338-
339- // HostConfigFiles returns a map from filename to contents of the files used for
340- // host-specific configuration by the agent installer client
341- func (a * AgentConfig ) HostConfigFiles () (HostConfigFileMap , error ) {
342- if a == nil || a .Config == nil {
343- return nil , nil
344- }
345-
346- files := HostConfigFileMap {}
347- for i , host := range a .Config .Hosts {
348- name := fmt .Sprintf ("host-%d" , i )
349- if host .Hostname != "" {
350- name = host .Hostname
351- }
352-
353- macs := []string {}
354- for _ , iface := range host .Interfaces {
355- macs = append (macs , strings .ToLower (iface .MacAddress )+ "\n " )
356- }
357-
358- if len (macs ) > 0 {
359- files [filepath .Join (name , "mac_addresses" )] = []byte (strings .Join (macs , "" ))
360- }
361-
362- rdh , err := yaml .Marshal (host .RootDeviceHints )
363- if err != nil {
364- return nil , err
365- }
366- if len (rdh ) > 0 && string (rdh ) != "{}\n " {
367- files [filepath .Join (name , "root-device-hints.yaml" )] = rdh
368- }
369-
370- if len (host .Role ) > 0 {
371- files [filepath .Join (name , "role" )] = []byte (host .Role )
372- }
373- }
374- return files , nil
375- }
376-
377229func unmarshalJSON (b []byte ) []byte {
378230 output , _ := yaml .JSONToYAML (b )
379231 return output
0 commit comments