platform/conf: Support Ignition 2.1 configs
Switch to the 2.1 parser, which also parses 2.0 configs (leaving their
version number intact). ct still emits 2.0 config structures; render and
reparse these for simplicity.
@@ -24,8 +24,8 @@ import (
cci "github.com/coreos/coreos-cloudinit/config"
v1 "github.com/coreos/ignition/config/v1"
v1types "github.com/coreos/ignition/config/v1/types"
- v2 "github.com/coreos/ignition/config/v2_0"
- v2types "github.com/coreos/ignition/config/v2_0/types"
+ v2 "github.com/coreos/ignition/config/v2_1"
+ v2types "github.com/coreos/ignition/config/v2_1/types"
"github.com/coreos/ignition/config/validate/report"
"github.com/coreos/pkg/capnslog"
"golang.org/x/crypto/ssh/agent"
@@ -156,7 +156,7 @@ func (u *UserData) Render() (*Conf, error) {
ignc, report, err := v2.Parse([]byte(u.data))
if err == nil {
c.ignitionV2 = &ignc
- } else if haveEntry(report, v2types.ErrOldVersion) {
+ } else if haveEntry(report, v2types.ErrInvalidVersion) {
// version 1 config
var ignc v1types.Config
ignc, err = v1.Parse([]byte(u.data))
@@ -184,7 +184,12 @@ func (u *UserData) Render() (*Conf, error) {
plog.Warningf("rendering Container Linux config: %s", report)
}
- c.ignitionV2 = &ignc
+ // ct still returns 2.0 configs. Convert to 2.1.
+ buf, err := json.Marshal(ignc)
+ if err != nil {
+ return nil, fmt.Errorf("serializing Container Linux config: %v", err)
+ }
+ return Ignition(string(buf)).Render()
default:
panic("invalid kind")
}
@@ -227,9 +232,13 @@ func (c *Conf) copyKeysIgnitionV1(keys []*agent.Key) {
}
func (c *Conf) copyKeysIgnitionV2(keys []*agent.Key) {
- c.ignitionV2.Passwd.Users = append(c.ignitionV2.Passwd.Users, v2types.User{
+ var keyObjs []v2types.SSHAuthorizedKey
+ for _, key := range keys {
+ keyObjs = append(keyObjs, v2types.SSHAuthorizedKey(key.String()))
+ }
+ c.ignitionV2.Passwd.Users = append(c.ignitionV2.Passwd.Users, v2types.PasswdUser{
Name: "core",
- SSHAuthorizedKeys: keysToStrings(keys),
+ SSHAuthorizedKeys: keyObjs,
})
}
