From 50b74b51dcc53d7cbf9842115eb4d19f64307c79 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Sat, 3 Jun 2023 01:57:41 +0300 Subject: [PATCH] Add multipart mime as a config type Signed-off-by: Gabriel Adrian Samfira --- kola/tests/misc/cloudinit.go | 2 +- platform/conf/conf.go | 39 +++++++++++++------ .../ignition/config/shared/errors/errors.go | 1 + .../flatcar/ignition/config/v2_2/cloudinit.go | 14 +++++++ .../flatcar/ignition/config/v2_2/config.go | 2 + 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/kola/tests/misc/cloudinit.go b/kola/tests/misc/cloudinit.go index d0ae37de7..6d6338b2d 100644 --- a/kola/tests/misc/cloudinit.go +++ b/kola/tests/misc/cloudinit.go @@ -179,7 +179,7 @@ chmod 600 ~core/.ssh/authorized_keys`), Run: CloudInitMultipartMime, ClusterSize: 1, Name: "cl.cloudinit.multipart-mime", - UserData: conf.CloudConfig(multipartMimeUserdata), + UserData: conf.MultipartMimeConfig(multipartMimeUserdata), Distros: []string{"cl"}, Platforms: []string{"qemu", "qemu-unpriv"}, }) diff --git a/platform/conf/conf.go b/platform/conf/conf.go index 33da2a10e..b1111fda5 100644 --- a/platform/conf/conf.go +++ b/platform/conf/conf.go @@ -63,6 +63,7 @@ const ( kindContainerLinuxConfig kindScript kindButane + kindMultipartMime ) var plog = capnslog.NewPackageLogger("github.com/flatcar/mantle", "platform/conf") @@ -80,18 +81,19 @@ type UserData struct { // Conf is a configuration for a Container Linux machine. It may be either a // coreos-cloudconfig or an ignition configuration. type Conf struct { - ignitionV1 *v1types.Config - ignitionV2 *v2types.Config - ignitionV21 *v21types.Config - ignitionV22 *v22types.Config - ignitionV23 *v23types.Config - ignitionV3 *v3types.Config - ignitionV31 *v31types.Config - ignitionV32 *v32types.Config - ignitionV33 *v33types.Config - cloudconfig *cci.CloudConfig - script string - user string + ignitionV1 *v1types.Config + ignitionV2 *v2types.Config + ignitionV21 *v21types.Config + ignitionV22 *v22types.Config + ignitionV23 *v23types.Config + ignitionV3 *v3types.Config + ignitionV31 *v31types.Config + ignitionV32 *v32types.Config + ignitionV33 *v33types.Config + cloudconfig *cci.CloudConfig + script string + multipartMime string + user string } func Empty() *UserData { @@ -100,6 +102,13 @@ func Empty() *UserData { } } +func MultipartMimeConfig(data string) *UserData { + return &UserData{ + kind: kindMultipartMime, + data: data, + } +} + func ContainerLinuxConfig(data string) *UserData { return &UserData{ kind: kindContainerLinuxConfig, @@ -148,6 +157,8 @@ func Unknown(data string) *UserData { u.kind = kindCloudConfig case ignerr.ErrScript: u.kind = kindScript + case ignerr.ErrMultipartMime: + u.kind = kindMultipartMime default: // Guess whether this is an Ignition config or a CLC. // This treats an invalid Ignition config as a CLC, and a @@ -291,6 +302,8 @@ func (u *UserData) Render(ctPlatform string) (*Conf, error) { case kindScript: // pass through scripts unmodified, you are on your own. c.script = u.data + case kindMultipartMime: + c.multipartMime = u.data case kindIgnition: err := renderIgnition() if err != nil { @@ -388,6 +401,8 @@ func (c *Conf) String() string { return c.cloudconfig.String() } else if c.script != "" { return c.script + } else if c.multipartMime != "" { + return c.multipartMime } return "" diff --git a/vendor/github.com/flatcar/ignition/config/shared/errors/errors.go b/vendor/github.com/flatcar/ignition/config/shared/errors/errors.go index f2b47cf90..2b87f3516 100644 --- a/vendor/github.com/flatcar/ignition/config/shared/errors/errors.go +++ b/vendor/github.com/flatcar/ignition/config/shared/errors/errors.go @@ -29,6 +29,7 @@ var ( ErrScript = errors.New("not a config (found coreos-cloudinit script)") ErrDeprecated = errors.New("config format deprecated") ErrCompressionInvalid = errors.New("invalid compression method") + ErrMultipartMime = errors.New("not a config (found multipart mime)") // Ignition section errors ErrOldVersion = errors.New("incorrect config version (too old)") diff --git a/vendor/github.com/flatcar/ignition/config/v2_2/cloudinit.go b/vendor/github.com/flatcar/ignition/config/v2_2/cloudinit.go index 36a543932..7308da435 100644 --- a/vendor/github.com/flatcar/ignition/config/v2_2/cloudinit.go +++ b/vendor/github.com/flatcar/ignition/config/v2_2/cloudinit.go @@ -17,13 +17,27 @@ package v2_2 import ( + "bufio" "bytes" "compress/gzip" "io/ioutil" + "net/textproto" "strings" "unicode" ) +func isMultipartMime(userdata []byte) bool { + userdata = decompressIfGzipped(userdata) + mimeReader := textproto.NewReader(bufio.NewReader(bytes.NewReader(userdata))) + header, err := mimeReader.ReadMIMEHeader() + if err != nil { + return false + } + contentType := header.Get("Content-Type") + + return strings.Contains(contentType, "multipart/mixed") +} + func isCloudConfig(userdata []byte) bool { header := strings.SplitN(string(decompressIfGzipped(userdata)), "\n", 2)[0] diff --git a/vendor/github.com/flatcar/ignition/config/v2_2/config.go b/vendor/github.com/flatcar/ignition/config/v2_2/config.go index 7df845016..cb0d9b013 100644 --- a/vendor/github.com/flatcar/ignition/config/v2_2/config.go +++ b/vendor/github.com/flatcar/ignition/config/v2_2/config.go @@ -35,6 +35,8 @@ func Parse(rawConfig []byte) (types.Config, report.Report, error) { return types.Config{}, report.Report{}, errors.ErrCloudConfig } else if isScript(rawConfig) { return types.Config{}, report.Report{}, errors.ErrScript + } else if isMultipartMime(rawConfig) { + return types.Config{}, report.Report{}, errors.ErrMultipartMime } var err error