Skip to content

Commit

Permalink
platform/conf: support 3.2-experimental configs
Browse files Browse the repository at this point in the history
Vendor the 3.2-experimental Ignition spec containing LUKS and then add
support in `platform.Conf` for 3.2-experimental specs.
  • Loading branch information
jlebon committed Jul 13, 2020
1 parent e5faa21 commit 1adbcfd
Show file tree
Hide file tree
Showing 396 changed files with 84,075 additions and 34,520 deletions.
15 changes: 7 additions & 8 deletions mantle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190929091402-5711055976b5
github.com/aliyun/aliyun-oss-go-sdk v2.0.3+incompatible
github.com/aws/aws-sdk-go v1.25.14
github.com/aws/aws-sdk-go v1.30.28
github.com/coreos/container-linux-config-transpiler v0.8.0
github.com/coreos/go-semver v0.3.0
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e
github.com/coreos/go-systemd/v22 v22.0.0
github.com/coreos/ign-converter v0.0.0-20200228175238-237c8512310a
github.com/coreos/ignition v0.35.0
github.com/coreos/ignition/v2 v2.3.0
github.com/coreos/ignition/v2 v2.3.1-0.20200710194004-ff94f8727d85
github.com/coreos/ioprogress v0.0.0-20151023204047-4637e494fd9b
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f
github.com/coreos/vcontext v0.0.0-20191017033345-260217907eb5 // indirect
github.com/digitalocean/godo v1.33.0
github.com/dimchansky/utfbom v1.1.0 // indirect
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7 // indirect
github.com/golang/protobuf v1.3.5
github.com/golang/protobuf v1.4.2
github.com/gophercloud/gophercloud v0.0.0-20180817041643-185230dfbd12
github.com/idubinskiy/schematyper v0.0.0-20190118213059-f71b40dac30d
github.com/kballard/go-shellquote v0.0.0-20150810074751-d8ec1a69a250
Expand All @@ -35,7 +35,7 @@ require (
github.com/packethost/packngo v0.0.0-20180426081943-80f62d78849d
github.com/pborman/uuid v1.2.0
github.com/pin/tftp v2.1.0+incompatible
github.com/pkg/errors v0.8.1
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v0.0.6
github.com/spf13/pflag v1.0.3
github.com/ulikunitz/xz v0.5.4
Expand All @@ -45,13 +45,12 @@ require (
github.com/vmware/govmomi v0.15.0
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a // indirect
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d
golang.org/x/sys v0.0.0-20200610111108-226ff32320da
golang.org/x/text v0.3.2
golang.org/x/tools v0.0.0-20200508184754-b8469989bc69 // indirect
google.golang.org/api v0.23.0
google.golang.org/api v0.26.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)

Expand Down
88 changes: 88 additions & 0 deletions mantle/go.sum

Large diffs are not rendered by default.

127 changes: 126 additions & 1 deletion mantle/platform/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import (
ign3err "github.com/coreos/ignition/v2/config/shared/errors"
v3 "github.com/coreos/ignition/v2/config/v3_0"
v3types "github.com/coreos/ignition/v2/config/v3_0/types"
v32exp "github.com/coreos/ignition/v2/config/v3_2_experimental"
v32exptypes "github.com/coreos/ignition/v2/config/v3_2_experimental/types"
ign3validate "github.com/coreos/ignition/v2/config/validate"
"github.com/coreos/pkg/capnslog"
"github.com/vincent-petithory/dataurl"
Expand Down Expand Up @@ -82,6 +84,8 @@ type Conf struct {
ignitionV23 *v23types.Config
ignitionV24 *v24types.Config
ignitionV3 *v3types.Config

ignitionV32exp *v32exptypes.Config
}

func Empty() *UserData {
Expand Down Expand Up @@ -233,6 +237,18 @@ func (u *UserData) Render(ctPlatform string, ignv2 bool) (*Conf, error) {
return err
}

ignc32exp, report3, err := v32exp.Parse([]byte(u.data))
if err == nil {
c.ignitionV32exp = &ignc32exp
if ignv2 {
return fmt.Errorf("cannot convert Ignition from v3.2-experimental to v2")
}
return nil
} else if err != ign3err.ErrUnknownVersion {
plog.Errorf("invalid userdata: %v", report3)
return err
}

// give up
return err
}
Expand Down Expand Up @@ -293,6 +309,9 @@ func (c *Conf) String() string {
} else if c.ignitionV3 != nil {
buf, _ := json.Marshal(c.ignitionV3)
return string(buf)
} else if c.ignitionV32exp != nil {
buf, _ := json.Marshal(c.ignitionV32exp)
return string(buf)
}

return ""
Expand All @@ -315,6 +334,12 @@ func (c *Conf) MergeV3(newConfig v3types.Config) {
c.ignitionV3 = &mergeConfig
}

// MergeV32exp merges a config with the ignitionV32exp config via Ignition's merging function.
func (c *Conf) MergeV32exp(newConfig v32exptypes.Config) {
mergeConfig := v32exp.Merge(*c.ignitionV32exp, newConfig)
c.ignitionV32exp = &mergeConfig
}

func (c *Conf) ValidConfig() bool {
if !c.IsIgnition() {
return false
Expand All @@ -323,6 +348,9 @@ func (c *Conf) ValidConfig() bool {
if c.ignitionV3 != nil {
rpt := ign3validate.ValidateWithContext(c.ignitionV3, nil)
return !rpt.IsFatal()
} else if c.ignitionV32exp != nil {
rpt := ign3validate.ValidateWithContext(c.ignitionV32exp, nil)
return !rpt.IsFatal()
} else {
rpt := ignvalidate.ValidateWithoutSource(val)
return !rpt.IsFatal()
Expand All @@ -342,6 +370,8 @@ func (c *Conf) getIgnitionValidateValue() reflect.Value {
return reflect.ValueOf(c.ignitionV24)
} else if c.ignitionV3 != nil {
return reflect.ValueOf(c.ignitionV3)
} else if c.ignitionV32exp != nil {
return reflect.ValueOf(c.ignitionV32exp)
}
return reflect.ValueOf(nil)
}
Expand Down Expand Up @@ -457,9 +487,36 @@ func (c *Conf) addFileV3(path, filesystem, contents string, mode int) {
c.MergeV3(newConfig)
}

func (c *Conf) addFileV32exp(path, filesystem, contents string, mode int) {
source := dataurl.EncodeBytes([]byte(contents))
newConfig := v32exptypes.Config{
Ignition: v32exptypes.Ignition{
Version: "3.2.0-experimental",
},
Storage: v32exptypes.Storage{
Files: []v32exptypes.File{
{
Node: v32exptypes.Node{
Path: path,
},
FileEmbedded1: v32exptypes.FileEmbedded1{
Contents: v32exptypes.Resource{
Source: &source,
},
Mode: &mode,
},
},
},
},
}
c.MergeV32exp(newConfig)
}

func (c *Conf) AddFile(path, filesystem, contents string, mode int) {
if c.ignitionV3 != nil {
c.addFileV3(path, filesystem, contents, mode)
} else if c.ignitionV3 != nil {
c.addFileV32exp(path, filesystem, contents, mode)
} else if c.ignitionV2 != nil {
c.addFileV2(path, filesystem, contents, mode)
} else if c.ignitionV21 != nil {
Expand Down Expand Up @@ -537,6 +594,25 @@ func (c *Conf) addSystemdUnitV3(name, contents string, enable, mask bool) {
c.MergeV3(newConfig)
}

func (c *Conf) addSystemdUnitV32exp(name, contents string, enable, mask bool) {
newConfig := v32exptypes.Config{
Ignition: v32exptypes.Ignition{
Version: "3.2.0-experimental",
},
Systemd: v32exptypes.Systemd{
Units: []v32exptypes.Unit{
{
Name: name,
Contents: &contents,
Enabled: &enable,
Mask: &mask,
},
},
},
}
c.MergeV32exp(newConfig)
}

func (c *Conf) AddSystemdUnit(name, contents string, state systemdUnitState) {
enable, mask := false, false
switch state {
Expand All @@ -557,6 +633,8 @@ func (c *Conf) AddSystemdUnit(name, contents string, state systemdUnitState) {
c.addSystemdUnitV24(name, contents, enable, mask)
} else if c.ignitionV3 != nil {
c.addSystemdUnitV3(name, contents, enable, mask)
} else if c.ignitionV32exp != nil {
c.addSystemdUnitV32exp(name, contents, enable, mask)
}
}

Expand Down Expand Up @@ -692,6 +770,28 @@ func (c *Conf) addSystemdDropinV3(service, name, contents string) {
c.MergeV3(newConfig)
}

func (c *Conf) addSystemdDropinV32exp(service, name, contents string) {
newConfig := v32exptypes.Config{
Ignition: v32exptypes.Ignition{
Version: "3.2.0-experimental",
},
Systemd: v32exptypes.Systemd{
Units: []v32exptypes.Unit{
{
Name: service,
Dropins: []v32exptypes.Dropin{
{
Name: name,
Contents: &contents,
},
},
},
},
},
}
c.MergeV32exp(newConfig)
}

func (c *Conf) AddSystemdUnitDropin(service, name, contents string) {
if c.ignitionV2 != nil {
c.addSystemdDropinV2(service, name, contents)
Expand All @@ -705,6 +805,8 @@ func (c *Conf) AddSystemdUnitDropin(service, name, contents string) {
c.addSystemdDropinV24(service, name, contents)
} else if c.ignitionV3 != nil {
c.addSystemdDropinV3(service, name, contents)
} else if c.ignitionV32exp != nil {
c.addSystemdDropinV32exp(service, name, contents)
}
}

Expand Down Expand Up @@ -816,6 +918,27 @@ func (c *Conf) copyKeysIgnitionV3(keys []*agent.Key) {
c.MergeV3(newConfig)
}

func (c *Conf) copyKeysIgnitionV32exp(keys []*agent.Key) {
var keyObjs []v32exptypes.SSHAuthorizedKey
for _, key := range keys {
keyObjs = append(keyObjs, v32exptypes.SSHAuthorizedKey(key.String()))
}
newConfig := v32exptypes.Config{
Ignition: v32exptypes.Ignition{
Version: "3.2.0-experimental",
},
Passwd: v32exptypes.Passwd{
Users: []v32exptypes.PasswdUser{
{
Name: "core",
SSHAuthorizedKeys: keyObjs,
},
},
},
}
c.MergeV32exp(newConfig)
}

// CopyKeys copies public keys from agent ag into the configuration to the
// appropriate configuration section for the core user.
func (c *Conf) CopyKeys(keys []*agent.Key) {
Expand All @@ -831,6 +954,8 @@ func (c *Conf) CopyKeys(keys []*agent.Key) {
c.copyKeysIgnitionV24(keys)
} else if c.ignitionV3 != nil {
c.copyKeysIgnitionV3(keys)
} else if c.ignitionV32exp != nil {
c.copyKeysIgnitionV32exp(keys)
}
}

Expand All @@ -844,7 +969,7 @@ func keysToStrings(keys []*agent.Key) (keyStrs []string) {
// IsIgnition returns true if the config is for Ignition.
// Returns false in the case of empty configs
func (c *Conf) IsIgnition() bool {
return c.ignitionV2 != nil || c.ignitionV21 != nil || c.ignitionV22 != nil || c.ignitionV23 != nil || c.ignitionV24 != nil || c.ignitionV3 != nil
return c.ignitionV2 != nil || c.ignitionV21 != nil || c.ignitionV22 != nil || c.ignitionV23 != nil || c.ignitionV24 != nil || c.ignitionV3 != nil || c.ignitionV32exp != nil
}

func (c *Conf) IsEmpty() bool {
Expand Down
93 changes: 93 additions & 0 deletions mantle/vendor/github.com/aws/aws-sdk-go/aws/arn/arn.go

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

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

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

Loading

0 comments on commit 1adbcfd

Please sign in to comment.