forked from openshift/oc
-
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.
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 which is generated by `openshift-install`. Since the idea is `openshift-install` should in theory be disposable after a cluster is provisioned, let's add this to `oc` which admins will need anyways. Vendor and use 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
226 changed files
with
23,220 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package ignition | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/coreos/ign-converter/translate/v24tov31" | ||
ignv2 "github.com/coreos/ignition/config/v2_4" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
kcmdutil "k8s.io/kubectl/pkg/cmd/util" | ||
"k8s.io/kubectl/pkg/util/templates" | ||
) | ||
|
||
const convert3CommandName = "convert3" | ||
|
||
type convert3Options struct { | ||
// Source file | ||
Source string | ||
// Destination file | ||
Destination string | ||
|
||
SourceReader io.Reader | ||
DestWriter io.Writer | ||
} | ||
|
||
var convert3Example = templates.Examples(` | ||
# Convert an Ignition Spec 2 pointer configuration to Spec 3 | ||
oc ignition convert3 < worker.ign > worker.ign3 | ||
`) | ||
|
||
// NewCommandConvert3 creates the command | ||
func NewCommandConvert3(streams genericclioptions.IOStreams) *cobra.Command { | ||
o := convert3Options{ | ||
SourceReader: streams.In, | ||
DestWriter: streams.Out, | ||
} | ||
cmd := &cobra.Command{ | ||
Use: convert3CommandName, | ||
Short: "Convert Ignition Spec 2 to Spec 3", | ||
Example: convert3Example, | ||
Args: cobra.ExactArgs(0), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
kcmdutil.CheckErr(o.validate(args)) | ||
kcmdutil.CheckErr(o.run()) | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&o.Source, "in", o.Source, "File containing input Ignition to convert. Read from stdin if omitted.") | ||
cmd.Flags().StringVar(&o.Destination, "out", o.Destination, "Path to file for converted Ignition. Written to stdout if omitted.") | ||
// autocompletion hints | ||
cmd.MarkFlagFilename("in") | ||
cmd.MarkFlagFilename("out") | ||
|
||
return cmd | ||
} | ||
|
||
func (o *convert3Options) validate(args []string) error { | ||
if len(o.Source) == 0 && o.SourceReader == nil { | ||
return errors.New("an input file, or reader is required") | ||
} | ||
|
||
if len(o.Destination) == 0 && o.DestWriter == nil { | ||
return errors.New("an output file or writer is required") | ||
} | ||
return nil | ||
} | ||
|
||
func (o *convert3Options) run() error { | ||
var data []byte | ||
switch { | ||
case len(o.Source) > 0: | ||
d, err := ioutil.ReadFile(o.Source) | ||
if err != nil { | ||
return err | ||
} | ||
data = d | ||
case o.SourceReader != nil: | ||
d, err := ioutil.ReadAll(o.SourceReader) | ||
if err != nil { | ||
return err | ||
} | ||
data = d | ||
} | ||
|
||
cfg, rpt, err := ignv2.Parse(data) | ||
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.Wrap(err, "translation failed") | ||
} | ||
dataOut, err := json.Marshal(newCfg) | ||
if err != nil { | ||
return errors.Wrap(err, "failed to marshal JSON") | ||
} | ||
|
||
// Write data | ||
if len(o.Destination) > 0 { | ||
return ioutil.WriteFile(o.Destination, dataOut, 0644) | ||
} else if o.DestWriter != nil { | ||
_, err := o.DestWriter.Write(dataOut) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
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,28 @@ | ||
package ignition | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
cmdutil "k8s.io/kubectl/pkg/cmd/util" | ||
) | ||
|
||
// NewCmdIgnition generates the command | ||
func NewCmdIgnition(streams genericclioptions.IOStreams) *cobra.Command { | ||
// Parent command to which all subcommands are added. | ||
cmds := &cobra.Command{ | ||
Use: "ignition", | ||
Long: "Manage Ignition configuration", | ||
Short: "", | ||
Run: cmdutil.DefaultSubCommandRun(streams.ErrOut), | ||
} | ||
|
||
subCommands := []*cobra.Command{ | ||
NewCommandConvert3(streams), | ||
} | ||
for _, cmd := range subCommands { | ||
cmds.AddCommand(cmd) | ||
} | ||
|
||
return cmds | ||
} |
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.