Skip to content

Commit ca59986

Browse files
Merge pull request openshift#8679 from mresvanis/add-image-based-installation-iso
MGMT-17226: Add image-based installer create installation ISO
2 parents 54e81ef + 04d2b91 commit ca59986

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+10903
-26
lines changed

cmd/openshift-install/imagebased.go

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55

66
"github.com/sirupsen/logrus"
77
"github.com/spf13/cobra"
8+
9+
"github.com/openshift/installer/pkg/asset"
10+
"github.com/openshift/installer/pkg/asset/imagebased/image"
811
)
912

1013
func newImageBasedCmd(ctx context.Context) *cobra.Command {
@@ -20,6 +23,37 @@ func newImageBasedCmd(ctx context.Context) *cobra.Command {
2023
return imagebasedCmd
2124
}
2225

26+
var (
27+
imageBasedInstallationConfigTemplateTarget = target{
28+
name: "Image-based Installation ISO Configuration template",
29+
command: &cobra.Command{
30+
Use: "image-config-template",
31+
Short: "Generates a template of the Image-based Installation ISO config manifest used by the Image-based installer",
32+
Args: cobra.ExactArgs(0),
33+
},
34+
assets: []asset.WritableAsset{
35+
&image.ImageBasedInstallationConfig{},
36+
},
37+
}
38+
39+
imageBasedInstallationImageTarget = target{
40+
name: "Image-based Installation ISO Image",
41+
command: &cobra.Command{
42+
Use: "image",
43+
Short: "Generates a bootable ISO image containing all the information needed to deploy a cluster",
44+
Args: cobra.ExactArgs(0),
45+
},
46+
assets: []asset.WritableAsset{
47+
&image.Image{},
48+
},
49+
}
50+
51+
imageBasedTargets = []target{
52+
imageBasedInstallationConfigTemplateTarget,
53+
imageBasedInstallationImageTarget,
54+
}
55+
)
56+
2357
func newImageBasedCreateCmd(ctx context.Context) *cobra.Command {
2458
cmd := &cobra.Command{
2559
Use: "create",
@@ -29,36 +63,18 @@ func newImageBasedCreateCmd(ctx context.Context) *cobra.Command {
2963
},
3064
}
3165

32-
cmd.AddCommand(createImageConfigTemplateCmd())
33-
cmd.AddCommand(createImageCmd())
66+
for _, t := range imageBasedTargets {
67+
t.command.Args = cobra.ExactArgs(0)
68+
t.command.Run = runTargetCmd(ctx, t.assets...)
69+
cmd.AddCommand(t.command)
70+
}
71+
3472
cmd.AddCommand(createConfigTemplateCmd())
3573
cmd.AddCommand(createConfigImageCmd())
3674

3775
return cmd
3876
}
3977

40-
func createImageConfigTemplateCmd() *cobra.Command {
41-
return &cobra.Command{
42-
Use: "image-config-template",
43-
Short: "Generates a template of the Image-based Installation ISO config manifest used by the Image-based installer",
44-
Args: cobra.ExactArgs(0),
45-
Run: func(_ *cobra.Command, _ []string) {
46-
logrus.Info("Create image config template command")
47-
},
48-
}
49-
}
50-
51-
func createImageCmd() *cobra.Command {
52-
return &cobra.Command{
53-
Use: "image",
54-
Short: "Generates a bootable ISO image containing all the information needed to deploy a cluster",
55-
Args: cobra.ExactArgs(0),
56-
Run: func(_ *cobra.Command, _ []string) {
57-
logrus.Info("Create image command")
58-
},
59-
}
60-
}
61-
6278
func createConfigTemplateCmd() *cobra.Command {
6379
return &cobra.Command{
6480
Use: "config-template",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e # Halt on error
4+
5+
seed_image=${1:-$SEED_IMAGE}
6+
authfile=${PULL_SECRET_FILE:-"/var/tmp/pull-secret.json"}
7+
ibi_config=${IBI_CONFIGURATION_FILE:-"/var/tmp/ibi-configuration.json"}
8+
9+
# Copy the lca-cli binary to the host, pulling the seed image can sometimes fail
10+
until podman create --authfile "${authfile}" --name lca-cli "${seed_image}" lca-cli ; do
11+
sleep 10
12+
done
13+
podman cp lca-cli:lca-cli /usr/local/bin/lca-cli
14+
podman rm lca-cli
15+
16+
/usr/local/bin/lca-cli ibi -f "${ibi_config}"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{.IBIConfiguration}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{.NetworkConfig}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{.PullSecret}}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[Unit]
2+
Wants=network-online.target
3+
After=network-online.target
4+
Description=SNO Image-based Installation
5+
6+
[Service]
7+
Environment=SEED_IMAGE={{.SeedImage}}
8+
Environment=IBI_CONFIGURATION_FILE=/var/tmp/ibi-configuration.json
9+
Environment=PULL_SECRET_FILE=/var/tmp/pull-secret.json
10+
{{if .Proxy -}}
11+
{{if .Proxy.HTTPProxy -}}
12+
Environment=HTTP_PROXY="{{.Proxy.HTTPProxy}}"
13+
Environment=http_proxy="{{.Proxy.HTTPProxy}}"
14+
{{end -}}
15+
{{if .Proxy.HTTPSProxy -}}
16+
Environment=HTTPS_PROXY="{{.Proxy.HTTPSProxy}}"
17+
Environment=https_proxy="{{.Proxy.HTTPSProxy}}"
18+
{{end -}}
19+
{{if .Proxy.NoProxy -}}
20+
Environment=NO_PROXY="{{.Proxy.NoProxy}}"
21+
Environment=no_proxy="{{.Proxy.NoProxy}}"
22+
{{end -}}
23+
{{end -}}
24+
25+
Type=oneshot
26+
RemainAfterExit=yes
27+
ExecStartPre=/usr/bin/chcon -t install_exec_t /usr/local/bin/install-rhcos-and-restore-seed.sh
28+
ExecStart=/usr/local/bin/install-rhcos-and-restore-seed.sh
29+
30+
[Install]
31+
WantedBy=multi-user.target
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=Pre Network Manager Config
3+
After=NetworkManager.service
4+
Before=install-rhcos-and-restore-seed.service
5+
6+
[Service]
7+
Type=oneshot
8+
RemainAfterExit=yes
9+
TimeoutSec=60
10+
ExecStart=bash -c "until /usr/bin/nmstatectl apply /var/tmp/network-config.yaml; do sleep 1; done"
11+
12+
[Install]
13+
WantedBy=multi-user.target

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ require (
157157
github.com/chai2010/gettext-go v1.0.2 // indirect
158158
github.com/cjlapao/common-go v0.0.39 // indirect
159159
github.com/containers/storage v1.54.0 // indirect
160+
github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb // indirect
160161
github.com/coreos/go-semver v0.3.1 // indirect
161162
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
162163
github.com/coreos/vcontext v0.0.0-20230201181013-d72178a18687 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,8 @@ github.com/containers/image/v5 v5.31.0 h1:eDFVlz5XaYICxe9dXpf23htEKvyosgkl62mJlI
13581358
github.com/containers/image/v5 v5.31.0/go.mod h1:5QfOqSackPkSbF7Qxc1DnVNnPJKQ+KWLkfEfDpK590Q=
13591359
github.com/containers/storage v1.54.0 h1:xwYAlf6n9OnIlURQLLg3FYHbO74fQ/2W2N6EtQEUM4I=
13601360
github.com/containers/storage v1.54.0/go.mod h1:PlMOoinRrBSnhYODLxt4EXl0nmJt+X0kjG0Xdt9fMTw=
1361+
github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb h1:rmqyI19j3Z/74bIRhuC59RB442rXUazKNueVpfJPxg4=
1362+
github.com/coreos/go-json v0.0.0-20230131223807-18775e0fb4fb/go.mod h1:rcFZM3uxVvdyNmsAV2jopgPD1cs5SPWJWU5dOz2LUnw=
13611363
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
13621364
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
13631365
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=

pkg/asset/agent/manifests/staticnetworkconfig/generator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type StaticNetworkConfig interface {
3737
GenerateStaticNetworkConfigData(ctx context.Context, hostsYAMLS string) ([]StaticNetworkConfigData, error)
3838
FormatStaticNetworkConfigForDB(staticNetworkConfig []*models.HostStaticNetworkConfig) (string, error)
3939
ValidateStaticConfigParams(ctx context.Context, staticNetworkConfig []*models.HostStaticNetworkConfig) error
40+
ValidateNMStateYaml(ctx context.Context, networkYaml string) error
4041
}
4142

4243
type staticNetworkConfigGenerator struct {
@@ -219,7 +220,7 @@ func (s *staticNetworkConfigGenerator) ValidateStaticConfigParams(ctx context.Co
219220
var err *multierror.Error
220221
for i, hostConfig := range staticNetworkConfig {
221222
err = multierror.Append(err, s.validateMacInterfaceName(i, hostConfig.MacInterfaceMap))
222-
if validateErr := s.validateNMStateYaml(ctx, hostConfig.NetworkYaml); validateErr != nil {
223+
if validateErr := s.ValidateNMStateYaml(ctx, hostConfig.NetworkYaml); validateErr != nil {
223224
err = multierror.Append(err, fmt.Errorf("failed to validate network yaml for host %d, %w", i, validateErr))
224225
}
225226
}
@@ -239,7 +240,7 @@ func (s *staticNetworkConfigGenerator) validateMacInterfaceName(hostIdx int, mac
239240
return nil
240241
}
241242

242-
func (s *staticNetworkConfigGenerator) validateNMStateYaml(ctx context.Context, networkYaml string) error {
243+
func (s *staticNetworkConfigGenerator) ValidateNMStateYaml(ctx context.Context, networkYaml string) error {
243244
result, err := s.executeNMStatectl(ctx, networkYaml)
244245
if err != nil {
245246
return err

0 commit comments

Comments
 (0)