@@ -101,7 +101,8 @@ func (a *AgentImage) Generate(dependencies asset.Parents) error {
101101 }
102102 }
103103
104- err = a .updateIgnitionImg (agentArtifacts .IgnitionByte )
104+ // Update Ignition images
105+ err = a .updateIgnitionContent (agentArtifacts )
105106 if err != nil {
106107 return err
107108 }
@@ -114,38 +115,27 @@ func (a *AgentImage) Generate(dependencies asset.Parents) error {
114115 return nil
115116}
116117
117- func (a * AgentImage ) updateIgnitionImg (ignition []byte ) error {
118- ca := NewCpioArchive ()
119- err := ca .StoreBytes ("config.ign" , ignition , 0o644 )
120- if err != nil {
121- return err
122- }
123- ignitionBuff , err := ca .SaveBuffer ()
124- if err != nil {
125- return err
126- }
127-
128- ignitionImgPath := filepath .Join (a .tmpPath , "images" , "ignition.img" )
129- fi , err := os .Stat (ignitionImgPath )
118+ // updateIgnitionContent updates the ignition data into the corresponding images in the ISO.
119+ func (a * AgentImage ) updateIgnitionContent (agentArtifacts * AgentArtifacts ) error {
120+ ignitionc := & isoeditor.IgnitionContent {}
121+ ignitionc .Config = agentArtifacts .IgnitionByte
122+ fileInfo , err := isoeditor .NewIgnitionImageReader (a .isoPath , ignitionc )
130123 if err != nil {
131124 return err
132125 }
133126
134- // Verify that the current compressed ignition archive does not exceed the
135- // embed area (usually 256 Kb)
136- if len (ignitionBuff ) > int (fi .Size ()) {
137- return fmt .Errorf ("ignition content length (%d) exceeds embed area size (%d)" , len (ignitionBuff ), fi .Size ())
138- }
139-
140- ignitionImg , err := os .OpenFile (ignitionImgPath , os .O_WRONLY , 0 )
141- if err != nil {
142- return err
143- }
144- defer ignitionImg .Close ()
127+ for _ , fileData := range fileInfo {
128+ filename := filepath .Join (a .tmpPath , fileData .Filename )
129+ file , err := os .Create (filename )
130+ if err != nil {
131+ return err
132+ }
133+ defer file .Close ()
145134
146- _ , err = ignitionImg .Write (ignitionBuff )
147- if err != nil {
148- return err
135+ _ , err = io .Copy (file , fileData .Data )
136+ if err != nil {
137+ return err
138+ }
149139 }
150140
151141 return nil
0 commit comments