Skip to content

Commit bcbd09d

Browse files
committed
Install yip config files in before-install step
This change allows to use after-install hooks as part of a machine registration. Fixes a regression introduced by df1961d Signed-off-by: David Cassany <[email protected]> (cherry picked from commit d784315)
1 parent 6450533 commit bcbd09d

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

pkg/install/_testdata/after-hook-config-install.yaml renamed to pkg/install/_testdata/before-hook-config-install.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Elemental Finalize System
22
stages:
3-
after-install:
3+
before-install:
44
- files:
55
- path: /run/elemental/oem/elemental-registration.yaml
66
permissions: 384

pkg/install/_testdata/after-hook-config-reset.yaml renamed to pkg/install/_testdata/before-hook-config-reset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Elemental Finalize System
22
stages:
3-
after-reset:
3+
before-reset:
44
- files:
55
- path: /oem/elemental-registration.yaml
66
permissions: 384

pkg/install/install.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ const (
5151
)
5252

5353
const (
54-
afterInstallStage = "after-install"
55-
afterResetStage = "after-reset"
56-
// Used in after-{install|reset} stages
57-
elementalAfterHook = "elemental-after-hook.yaml"
54+
beforeInstallStage = "before-install"
55+
beforeResetStage = "before-reset"
56+
// Used in before-{install|reset} stages
57+
elementalBeforeHook = "elemental-before-hook.yaml"
5858

5959
// Deterministic Elemental yip paths
6060
registrationConfigPath = "elemental-registration.yaml"
@@ -109,8 +109,8 @@ func (i *installer) InstallElemental(config elementalv1.Config, state register.S
109109
log.Warningf("Both device and device-selector set, using device-field '%s'", config.Elemental.Install.Device)
110110
}
111111

112-
if err := i.writeAfterHookConfigurator(afterInstallStage, installOEMMount, config, state, networkConfig); err != nil {
113-
return fmt.Errorf("writing %s configurator: %w", afterInstallStage, err)
112+
if err := i.writeHookConfigurator(beforeInstallStage, installOEMMount, config, state, networkConfig); err != nil {
113+
return fmt.Errorf("writing %s configurator: %w", beforeInstallStage, err)
114114
}
115115

116116
if err := i.runner.Install(config.Elemental.Install); err != nil {
@@ -126,8 +126,8 @@ func (i *installer) ResetElemental(config elementalv1.Config, state register.Sta
126126
config.Elemental.Reset.ConfigURLs = []string{}
127127
}
128128

129-
if err := i.writeAfterHookConfigurator(afterResetStage, resetOEMMount, config, state, networkConfig); err != nil {
130-
return fmt.Errorf("writing %s configurator: %w", afterResetStage, err)
129+
if err := i.writeHookConfigurator(beforeResetStage, resetOEMMount, config, state, networkConfig); err != nil {
130+
return fmt.Errorf("writing %s configurator: %w", beforeResetStage, err)
131131
}
132132

133133
if err := i.runner.Reset(config.Elemental.Reset); err != nil {
@@ -242,7 +242,7 @@ func matchesGt(disk *block.Disk, req elementalv1.DeviceSelectorRequirement) (boo
242242
return diskSize.Cmp(keySize) == 1, nil
243243
}
244244

245-
func (i *installer) writeAfterHookConfigurator(stage string, oemMount string, config elementalv1.Config, state register.State, networkConfig elementalv1.NetworkConfig) error {
245+
func (i *installer) writeHookConfigurator(stage string, oemMount string, config elementalv1.Config, state register.State, networkConfig elementalv1.NetworkConfig) error {
246246
afterHookConfigurator := schema.YipConfig{}
247247
afterHookConfigurator.Name = "Elemental Finalize System"
248248
afterHookConfigurator.Stages = map[string][]schema.Stage{
@@ -254,31 +254,31 @@ func (i *installer) writeAfterHookConfigurator(stage string, oemMount string, co
254254
if err != nil {
255255
return fmt.Errorf("getting registration config yip: %w", err)
256256
}
257-
registrationYip := yipAfterHookWrap(string(registrationYipBytes), filepath.Join(oemMount, registrationConfigPath), "Registration Config")
257+
registrationYip := yipHookWrap(string(registrationYipBytes), filepath.Join(oemMount, registrationConfigPath), "Registration Config")
258258
afterHookConfigurator.Stages[stage] = append(afterHookConfigurator.Stages[stage], registrationYip)
259259

260260
// State
261261
stateYipBytes, err := i.registrationStateYip(state)
262262
if err != nil {
263263
return fmt.Errorf("getting registration state config yip: %w", err)
264264
}
265-
stateYip := yipAfterHookWrap(string(stateYipBytes), filepath.Join(oemMount, stateConfigPath), "Registration State Config")
265+
stateYip := yipHookWrap(string(stateYipBytes), filepath.Join(oemMount, stateConfigPath), "Registration State Config")
266266
afterHookConfigurator.Stages[stage] = append(afterHookConfigurator.Stages[stage], stateYip)
267267

268268
// Cloud Init
269269
cloudInitYipBytes, err := i.cloudInitYip(config.CloudConfig)
270270
if err != nil {
271271
return fmt.Errorf("getting cloud-init config yip: %w", err)
272272
}
273-
cloudInitYip := yipAfterHookWrap(string(cloudInitYipBytes), filepath.Join(oemMount, cloudInitConfigPath), "Cloud Init Config")
273+
cloudInitYip := yipHookWrap(string(cloudInitYipBytes), filepath.Join(oemMount, cloudInitConfigPath), "Cloud Init Config")
274274
afterHookConfigurator.Stages[stage] = append(afterHookConfigurator.Stages[stage], cloudInitYip)
275275

276276
// Elemental System Agent
277277
systemAgentYipBytes, err := i.elementalSystemAgentYip(config.Elemental)
278278
if err != nil {
279279
return fmt.Errorf("getting elemental system agent config yip: %w", err)
280280
}
281-
systemAgentYip := yipAfterHookWrap(string(systemAgentYipBytes), filepath.Join(oemMount, systemAgentConfigPath), "Elemental System Agent Config")
281+
systemAgentYip := yipHookWrap(string(systemAgentYipBytes), filepath.Join(oemMount, systemAgentConfigPath), "Elemental System Agent Config")
282282
afterHookConfigurator.Stages[stage] = append(afterHookConfigurator.Stages[stage], systemAgentYip)
283283

284284
// Network Config
@@ -287,7 +287,7 @@ func (i *installer) writeAfterHookConfigurator(stage string, oemMount string, co
287287
return fmt.Errorf("getting network config yip: %w", err)
288288
}
289289
if !errors.Is(err, network.ErrEmptyConfig) {
290-
networkConfigYip := yipAfterHookWrap(string(networkConfigYipBytes), filepath.Join(oemMount, networkConfigPath), "Network Config")
290+
networkConfigYip := yipHookWrap(string(networkConfigYipBytes), filepath.Join(oemMount, networkConfigPath), "Network Config")
291291
afterHookConfigurator.Stages[stage] = append(afterHookConfigurator.Stages[stage], networkConfigYip)
292292
}
293293

@@ -296,9 +296,9 @@ func (i *installer) writeAfterHookConfigurator(stage string, oemMount string, co
296296
return fmt.Errorf("creating directory '%s': %w", elementalcli.TempCloudInitDir, err)
297297
}
298298
// Create the after hook configurator yip
299-
f, err := i.fs.Create(filepath.Join(elementalcli.TempCloudInitDir, elementalAfterHook))
299+
f, err := i.fs.Create(filepath.Join(elementalcli.TempCloudInitDir, elementalBeforeHook))
300300
if err != nil {
301-
return fmt.Errorf("creating file '%s': %w", filepath.Join(elementalcli.TempCloudInitDir, elementalAfterHook), err)
301+
return fmt.Errorf("creating file '%s': %w", filepath.Join(elementalcli.TempCloudInitDir, elementalBeforeHook), err)
302302
}
303303
defer f.Close()
304304

@@ -309,7 +309,7 @@ func (i *installer) writeAfterHookConfigurator(stage string, oemMount string, co
309309
return nil
310310
}
311311

312-
func yipAfterHookWrap(content string, path string, name string) schema.Stage {
312+
func yipHookWrap(content string, path string, name string) schema.Stage {
313313
config := schema.Stage{Name: name}
314314
config.Files = []schema.File{
315315
{

pkg/install/install_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ var _ = Describe("installer install elemental", Label("installer", "install"), f
146146
cliRunner.EXPECT().Install(configFixture.Elemental.Install).Return(nil)
147147
networkConfigurator.EXPECT().GetNetworkConfigApplicator(networkConfigFixture).Return(networkConfigApplicatorFixture, nil)
148148
Expect(install.InstallElemental(configFixture, stateFixture, networkConfigFixture)).ToNot(HaveOccurred())
149-
compareFiles(fs, filepath.Join(elementalcli.TempCloudInitDir, elementalAfterHook), "_testdata/after-hook-config-install.yaml")
149+
compareFiles(fs, filepath.Join(elementalcli.TempCloudInitDir, elementalBeforeHook), "_testdata/before-hook-config-install.yaml")
150150
})
151151
})
152152

@@ -297,7 +297,7 @@ var _ = Describe("installer reset elemental", Label("installer", "reset"), func(
297297
cliRunner.EXPECT().Reset(configFixture.Elemental.Reset).Return(nil)
298298
networkConfigurator.EXPECT().GetNetworkConfigApplicator(networkConfigFixture).Return(networkConfigApplicatorFixture, nil)
299299
Expect(install.ResetElemental(configFixture, stateFixture, networkConfigFixture)).ToNot(HaveOccurred())
300-
compareFiles(fs, filepath.Join(elementalcli.TempCloudInitDir, elementalAfterHook), "_testdata/after-hook-config-reset.yaml")
300+
compareFiles(fs, filepath.Join(elementalcli.TempCloudInitDir, elementalBeforeHook), "_testdata/before-hook-config-reset.yaml")
301301
})
302302
It("should remove reset plan", func() {
303303
Expect(fs.WriteFile(controllers.LocalResetPlanPath, []byte("{}\n"), os.FileMode(0600))).ToNot(HaveOccurred())

0 commit comments

Comments
 (0)