forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
openshift-install ignition convert
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
Showing
176 changed files
with
18,438 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.