Skip to content

Commit

Permalink
Add openshift-install ignition convert
Browse files Browse the repository at this point in the history
The transition to Ignition Spec 3 with 4.6 creates a
discontinuity.  Some users want to update their bootimages,
e.g. for a cluster originally provisioned as 4.4 but upgraded
in place to 4.6, it should be possible to directly use RHCOS 4.6
bootimages for new workers.

In some cases in fact, this could be *required* for things like
adding a node with newer hardware.

The main stumbling block here is the pointer ignition config.
Since `openshift-install` already includes Ignition bits, let's
add translation capability here using
https://github.com/coreos/ign-converter
the same as the MCO uses.

xref openshift/enhancements#492 (comment)
xref https://bugzilla.redhat.com/show_bug.cgi?id=1884750
  • Loading branch information
cgwalters committed Oct 23, 2020
1 parent de62b01 commit 662547a
Show file tree
Hide file tree
Showing 176 changed files with 18,438 additions and 0 deletions.
74 changes: 74 additions & 0 deletions cmd/openshift-install/ignition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"
ignv2 "github.com/coreos/ignition/config/v2_4"
"github.com/coreos/ign-converter/translate/v24tov31"
)

func newIgnitionCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "ignition",
Short: "Operations on Ignition configs",
Long: `Operations on Ignition configs
See sub-operations for details.`,
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
cmd.AddCommand(newIgnitionConvertCmd())
return cmd
}

var (
ignitionConvertOpts struct {
source string
dest string
}
)

func newIgnitionConvertCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "convert",
Short: "Convert a Spec2 config to Spec 3",
Long: `Convert a Spec2 config to Spec 3
OpenShift versions 4.6 and above use Ignition Spec 3. This
command can be used to translate the "pointer config" generated
by a prior version of openshift-install to Spec 3, so that
it can be used with newer bootimages.
`,
Args: cobra.ExactArgs(2),

RunE: func(cmd *cobra.Command, args []string) error {
dataIn, err := ioutil.ReadFile(args[0])
if err != nil {
return errors.Wrapf(err, "failed to read %s", args[0])
}
dest := args[1]
cfg, rpt, err := ignv2.Parse(dataIn)
fmt.Fprintf(os.Stderr, "%s", rpt.String())
if err != nil || rpt.IsFatal() {
return errors.Errorf("Error parsing spec v2 config: %v\n%v", err, rpt)
}

newCfg, err := v24tov31.Translate(cfg, nil)
if err != nil {
return errors.Wrapf(err, "translation failed", err)
}
dataOut, err := json.Marshal(newCfg)
if err != nil {
return errors.Wrapf(err, "failed to marshal JSON")
}
return ioutil.WriteFile(dest, dataOut, 0666)
},
}
return cmd
}
1 change: 1 addition & 0 deletions cmd/openshift-install/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func installerMain() {
newCompletionCmd(),
newMigrateCmd(),
newExplainCmd(),
newIgnitionCmd(),
} {
rootCmd.AddCommand(subCmd)
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ require (
github.com/c4milo/gotoolkit v0.0.0-20190525173301-67483a18c17a // indirect
github.com/clarketm/json v1.14.1
github.com/containers/image v3.0.2+incompatible
github.com/coreos/ign-converter v0.0.0-20200918193805-44d462f1c700
github.com/coreos/ignition v0.35.0
github.com/coreos/ignition/v2 v2.3.0
github.com/dmacvicar/terraform-provider-libvirt v0.6.2
github.com/frankban/quicktest v1.7.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7
github.com/coreos/go-systemd/v22 v22.0.0 h1:XJIw/+VlJ+87J+doOxznsAWIdmWuViOVhkQamW5YV28=
github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
github.com/coreos/ign-converter v0.0.0-20200629171308-e40a44f244c5/go.mod h1:LNu0WTt8iVH/WJH15R/SjZw7AdyY2qAyf9ILZTCBvho=
github.com/coreos/ign-converter v0.0.0-20200918193805-44d462f1c700 h1:Un1+sTzUeZGSr0gFIpHMUEZnwfBJeswD1ZJS05W8m/Y=
github.com/coreos/ign-converter v0.0.0-20200918193805-44d462f1c700/go.mod h1:LNu0WTt8iVH/WJH15R/SjZw7AdyY2qAyf9ILZTCBvho=
github.com/coreos/ignition v0.33.0/go.mod h1:WJQapxzEn9DE0ryxsGvm8QnBajm/XsS/PkrDqSpz+bA=
github.com/coreos/ignition v0.34.0/go.mod h1:WJQapxzEn9DE0ryxsGvm8QnBajm/XsS/PkrDqSpz+bA=
github.com/coreos/ignition v0.35.0 h1:UFodoYq1mOPrbEjtxIsZbThcDyQwAI1owczRDqWmKkQ=
Expand Down
10 changes: 10 additions & 0 deletions vendor/github.com/ajeddeloh/go-json/README

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 662547a

Please sign in to comment.