Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add openshift-install ignition convert #4300

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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