Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: switch to v3.2.0 Ignition configs instead of v3.1.0 #2248

Merged
merged 2 commits into from Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/HACKING.md
Expand Up @@ -344,7 +344,7 @@ sh-4.2# chroot /host
sh-4.4# /sbin/iptables -D OPENSHIFT-BLOCK-OUTPUT 1
sh-4.4# curl -k https://<api-server-url>:22623/config/worker
...
sh-4.4# curl -H "Accept: application/vnd.coreos.ignition+json; version=3.1.0" -k https://<api-server-url>/config/worker
sh-4.4# curl -H "Accept: application/vnd.coreos.ignition+json; version=3.2.0" -k https://<api-server-url>/config/worker
...
```

Expand Down
6 changes: 3 additions & 3 deletions docs/MachineConfiguration.md
Expand Up @@ -57,7 +57,7 @@ type MachineConfigSpec struct {
}
```

The actual custom resource manifest then could look like this if you are applying it to cluster on version >= 4.6:
The actual custom resource manifest then could look like this if you are applying it to cluster on version >= 4.7:

```
apiVersion: machineconfiguration.openshift.io/v1
Expand All @@ -67,7 +67,7 @@ metadata:
spec:
config:
ignition:
version: 3.1.0
version: 3.2.0
storage:
files:
- contents:
Expand Down Expand Up @@ -216,7 +216,7 @@ metadata:
spec:
config:
ignition:
version: 3.1.0
version: 3.2.0
extensions:
- usbguard
```
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -18,7 +18,7 @@ require (
github.com/coreos/fcct v0.5.0
github.com/coreos/go-semver v0.3.0
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect
github.com/coreos/ign-converter v0.0.0-20200629171308-e40a44f244c5
github.com/coreos/ign-converter v0.0.0-20201123214124-8dac862888aa
github.com/coreos/ignition v0.35.0
github.com/coreos/ignition/v2 v2.7.0
github.com/davecgh/go-spew v1.1.1
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Expand Up @@ -168,13 +168,11 @@ github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.0.0 h1:XJIw/+VlJ+87J+doOxznsAWIdmWuViOVhkQamW5YV28=
github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
github.com/coreos/ign-converter v0.0.0-20200629171308-e40a44f244c5 h1:rBga8xIJ7MzGbTfruI8Kfxu1X3FlIquMRuW9yLsW5Mc=
github.com/coreos/ign-converter v0.0.0-20200629171308-e40a44f244c5/go.mod h1:LNu0WTt8iVH/WJH15R/SjZw7AdyY2qAyf9ILZTCBvho=
github.com/coreos/ign-converter v0.0.0-20201123214124-8dac862888aa h1:oIF6XCee+GoGNTykmC2pvx3A3d5ES/CHAB2H0beGji0=
github.com/coreos/ign-converter v0.0.0-20201123214124-8dac862888aa/go.mod h1:pqAsDWa5YDi10Va/aqQI0bwOs9hXqoE2xwb5vnFys5s=
github.com/coreos/ignition v0.35.0 h1:UFodoYq1mOPrbEjtxIsZbThcDyQwAI1owczRDqWmKkQ=
github.com/coreos/ignition v0.35.0/go.mod h1:WJQapxzEn9DE0ryxsGvm8QnBajm/XsS/PkrDqSpz+bA=
github.com/coreos/ignition/v2 v2.1.1/go.mod h1:RqmqU64zxarUJa3l4cHtbhcSwfQLpUhv0WVziZwoXvE=
github.com/coreos/ignition/v2 v2.3.0 h1:TK+STbzVe6KZp4tQ2IaNSRMiWX4/diNngep1F7tP7Zk=
github.com/coreos/ignition/v2 v2.3.0/go.mod h1:85dmM/CERMZXNrJsXqtNLIxR/dn8G9qlL1CmEjCugp0=
github.com/coreos/ignition/v2 v2.7.0 h1:JCKxJllVtnk1lQY1uisxrtFSHG5L2NI1LRzc8wBEk84=
github.com/coreos/ignition/v2 v2.7.0/go.mod h1:3CjaRpg51hmJzPjarbzB0RvSZbLkNOczxKJobTl6nOY=
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
Expand Down
2 changes: 1 addition & 1 deletion lib/resourceapply/machineconfig_test.go
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

ign3types "github.com/coreos/ignition/v2/config/v3_1/types"
ign3types "github.com/coreos/ignition/v2/config/v3_2/types"
"github.com/davecgh/go-spew/spew"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/fake"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/bootstrap/bootstrap_test.go
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"testing"

ign3types "github.com/coreos/ignition/v2/config/v3_1/types"
ign3types "github.com/coreos/ignition/v2/config/v3_2/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/vincent-petithory/dataurl"
Expand Down
Expand Up @@ -13,7 +13,7 @@ spec:
security:
tls: {}
timeouts: {}
version: 3.1.0
version: 3.2.0
passwd:
users:
- name: core
Expand Down
Expand Up @@ -13,7 +13,7 @@ spec:
security:
tls: {}
timeouts: {}
version: 3.1.0
version: 3.2.0
passwd:
users:
- name: core
Expand Down
145 changes: 101 additions & 44 deletions pkg/controller/common/helpers.go
Expand Up @@ -10,17 +10,21 @@ import (
"github.com/clarketm/json"
fcctbase "github.com/coreos/fcct/base/v0_1"
"github.com/coreos/ign-converter/translate/v23tov30"
"github.com/coreos/ign-converter/translate/v31tov22"
"github.com/coreos/ign-converter/translate/v32tov22"
"github.com/coreos/ign-converter/translate/v32tov31"
ign2error "github.com/coreos/ignition/config/shared/errors"
ign2 "github.com/coreos/ignition/config/v2_2"
ign2types "github.com/coreos/ignition/config/v2_2/types"
ign2_3 "github.com/coreos/ignition/config/v2_3"
validate2 "github.com/coreos/ignition/config/validate"
ign3error "github.com/coreos/ignition/v2/config/shared/errors"
ign3_0 "github.com/coreos/ignition/v2/config/v3_0"
ign3 "github.com/coreos/ignition/v2/config/v3_1"
translate3 "github.com/coreos/ignition/v2/config/v3_1/translate"
ign3types "github.com/coreos/ignition/v2/config/v3_1/types"
ign3_1 "github.com/coreos/ignition/v2/config/v3_1"
translate3_1 "github.com/coreos/ignition/v2/config/v3_1/translate"
ign3_1types "github.com/coreos/ignition/v2/config/v3_1/types"
ign3 "github.com/coreos/ignition/v2/config/v3_2"
translate3 "github.com/coreos/ignition/v2/config/v3_2/translate"
ign3types "github.com/coreos/ignition/v2/config/v3_2/types"
validate3 "github.com/coreos/ignition/v2/config/validate"
"github.com/ghodss/yaml"
"github.com/golang/glog"
Expand Down Expand Up @@ -144,22 +148,28 @@ func WriteTerminationError(err error) {
}

// ConvertRawExtIgnitionToV3 ensures that the Ignition config in
// the RawExtension is spec v3.1, or translates to it.
// the RawExtension is spec v3.2, or translates to it.
func ConvertRawExtIgnitionToV3(inRawExtIgn *runtime.RawExtension) (runtime.RawExtension, error) {
// This function is only used by the MCServer so we don't need to consider v3.0
_, rptV3, errV3 := ign3.Parse(inRawExtIgn.Raw)
if errV3 == nil && !rptV3.IsFatal() {
// The rawExt is already on V3.1, no need to translate
// The rawExt is already on V3.2, no need to translate
return *inRawExtIgn, nil
}

ignCfg, rpt, err := ign2.Parse(inRawExtIgn.Raw)
if err != nil || rpt.IsFatal() {
return runtime.RawExtension{}, errors.Errorf("parsing Ignition config spec v2.2 failed with error: %v\nReport: %v", err, rpt)
}
converted3, err := convertIgnition2to3(ignCfg)
if err != nil {
return runtime.RawExtension{}, errors.Errorf("failed to convert config from spec v2.2 to v3.1: %v", err)
var converted3 ign3types.Config
ignCfgV3_1, rptV3_1, errV3_1 := ign3_1.Parse(inRawExtIgn.Raw)
if errV3_1 == nil && !rptV3_1.IsFatal() {
converted3 = translate3.Translate(ignCfgV3_1)
} else {
ignCfg, rpt, err := ign2.Parse(inRawExtIgn.Raw)
if err != nil || rpt.IsFatal() {
return runtime.RawExtension{}, errors.Errorf("parsing Ignition config spec v2.2 failed with error: %v\nReport: %v", err, rpt)
}
converted3, err = convertIgnition2to3(ignCfg)
if err != nil {
return runtime.RawExtension{}, errors.Errorf("failed to convert config from spec v2.2 to v3.2: %v", err)
}
}

outIgnV3, err := json.Marshal(converted3)
Expand All @@ -173,17 +183,46 @@ func ConvertRawExtIgnitionToV3(inRawExtIgn *runtime.RawExtension) (runtime.RawEx
return outRawExt, nil
}

// ConvertRawExtIgnitionToV3_1 ensures that the Ignition config in
// the RawExtension is spec v3.1, or translates to it.
func ConvertRawExtIgnitionToV3_1(inRawExtIgn *runtime.RawExtension) (runtime.RawExtension, error) {
rawExt, err := ConvertRawExtIgnitionToV3(inRawExtIgn)
if err != nil {
return runtime.RawExtension{}, err
}

ignCfgV3, rptV3, errV3 := ign3.Parse(rawExt.Raw)
if errV3 != nil || rptV3.IsFatal() {
return runtime.RawExtension{}, errors.Errorf("parsing Ignition config failed with error: %v\nReport: %v", errV3, rptV3)
}

ignCfgV31, err := convertIgnition32to31(ignCfgV3)
if err != nil {
return runtime.RawExtension{}, err
}

outIgnV31, err := json.Marshal(ignCfgV31)
if err != nil {
return runtime.RawExtension{}, errors.Errorf("failed to marshal converted config: %v", err)
}

outRawExt := runtime.RawExtension{}
outRawExt.Raw = outIgnV31

return outRawExt, nil
}

// ConvertRawExtIgnitionToV2 ensures that the Ignition config in
// the RawExtension is spec v2.2, or translates to it.
func ConvertRawExtIgnitionToV2(inRawExtIgn *runtime.RawExtension) (runtime.RawExtension, error) {
ignCfg, rpt, err := ign3.Parse(inRawExtIgn.Raw)
if err != nil || rpt.IsFatal() {
return runtime.RawExtension{}, errors.Errorf("parsing Ignition config spec v3.1 failed with error: %v\nReport: %v", err, rpt)
return runtime.RawExtension{}, errors.Errorf("parsing Ignition config spec v3.2 failed with error: %v\nReport: %v", err, rpt)
}

converted2, err := convertIgnition3to2(ignCfg)
if err != nil {
return runtime.RawExtension{}, errors.Errorf("failed to convert config from spec v3.1 to v2.2: %v", err)
return runtime.RawExtension{}, errors.Errorf("failed to convert config from spec v3.2 to v2.2: %v", err)
}

outIgnV2, err := json.Marshal(converted2)
Expand All @@ -197,7 +236,7 @@ func ConvertRawExtIgnitionToV2(inRawExtIgn *runtime.RawExtension) (runtime.RawEx
return outRawExt, nil
}

// convertIgnition2to3 takes an ignition spec v2.2 config and returns a v3.1 config
// convertIgnition2to3 takes an ignition spec v2.2 config and returns a v3.2 config
func convertIgnition2to3(ign2config ign2types.Config) (ign3types.Config, error) {
// only support writing to root file system
fsMap := map[string]string{
Expand All @@ -210,16 +249,16 @@ func convertIgnition2to3(ign2config ign2types.Config) (ign3types.Config, error)
if err != nil {
return ign3types.Config{}, errors.Errorf("unable to convert Ignition spec v2 config to v3: %v", err)
}
// Workaround to get a v3.1 config as output
converted3 := translate3.Translate(ign3_0config)
// Workaround to get a v3.2 config as output
converted3 := translate3.Translate(translate3_1.Translate(ign3_0config))
bgilbert marked this conversation as resolved.
Show resolved Hide resolved

glog.V(4).Infof("Successfully translated Ignition spec v2 config to Ignition spec v3 config: %v", converted3)
return converted3, nil
}

// convertIgnition3to2 takes an ignition spec v3.1 config and returns a v2.2 config
// convertIgnition3to2 takes an ignition spec v3.2 config and returns a v2.2 config
func convertIgnition3to2(ign3config ign3types.Config) (ign2types.Config, error) {
converted2, err := v31tov22.Translate(ign3config)
converted2, err := v32tov22.Translate(ign3config)
if err != nil {
return ign2types.Config{}, errors.Errorf("unable to convert Ignition spec v3 config to v2: %v", err)
}
Expand All @@ -228,6 +267,17 @@ func convertIgnition3to2(ign3config ign3types.Config) (ign2types.Config, error)
return converted2, nil
}

// convertIgnition32to31 takes an ignition spec v3.2 config and returns a v3.1 config
func convertIgnition32to31(ign3config ign3types.Config) (ign3_1types.Config, error) {
converted31, err := v32tov31.Translate(ign3config)
if err != nil {
return ign3_1types.Config{}, errors.Errorf("unable to convert Ignition spec v3_2 config to v3_1: %v", err)
}
glog.V(4).Infof("Successfully translated Ignition spec v3_2 config to Ignition spec v3_1 config: %v", converted31)

return converted31, nil
}

// ValidateIgnition wraps the underlying Ignition V2/V3 validation, but explicitly supports
// a completely empty Ignition config as valid. This is because we
// want to allow MachineConfig objects which just have e.g. KernelArguments
Expand Down Expand Up @@ -287,32 +337,39 @@ func ValidateMachineConfig(cfg mcfgv1.MachineConfigSpec) error {
// IgnParseWrapper parses rawIgn for both V2 and V3 ignition configs and returns
// a V2 or V3 Config or an error. This wrapper is necessary since V2 and V3 use different parsers.
func IgnParseWrapper(rawIgn []byte) (interface{}, error) {
ignCfgV3_1, rptV3_1, errV3_1 := ign3.Parse(rawIgn)
if errV3_1 == nil && !rptV3_1.IsFatal() {
return ignCfgV3_1, nil
}
// unlike spec v2 parsers, v3 parsers aren't chained by default so we need to try parsing as spec v3.0 as well
if errV3_1.Error() == ign3error.ErrUnknownVersion.Error() {
ignCfgV3_0, rptV3_0, errV3_0 := ign3_0.Parse(rawIgn)
if errV3_0 == nil && !rptV3_0.IsFatal() {
return translate3.Translate(ignCfgV3_0), nil
ignCfgV3_2, rptV3_2, errV3_2 := ign3.Parse(rawIgn)
if errV3_2 == nil && !rptV3_2.IsFatal() {
return ignCfgV3_2, nil
}
if errV3_2.Error() == ign3error.ErrUnknownVersion.Error() {
ignCfgV3_1, rptV3_1, errV3_1 := ign3_1.Parse(rawIgn)
if errV3_1 == nil && !rptV3_1.IsFatal() {
return translate3.Translate(ignCfgV3_1), nil
}

if errV3_0.Error() == ign3error.ErrUnknownVersion.Error() {
ignCfgV2, rptV2, errV2 := ign2.Parse(rawIgn)
if errV2 == nil && !rptV2.IsFatal() {
return ignCfgV2, nil
// unlike spec v2 parsers, v3 parsers aren't chained by default so we need to try parsing as spec v3.0 as well
if errV3_1.Error() == ign3error.ErrUnknownVersion.Error() {
ignCfgV3_0, rptV3_0, errV3_0 := ign3_0.Parse(rawIgn)
if errV3_0 == nil && !rptV3_0.IsFatal() {
return translate3.Translate(translate3_1.Translate(ignCfgV3_0)), nil
}

// If the error is still UnknownVersion it's not a 3.1/3.0 or 2.x config, thus unsupported
if errV2.Error() == ign2error.ErrUnknownVersion.Error() {
return ign3types.Config{}, errors.Errorf("parsing Ignition config failed: unknown version. Supported spec versions: 2.2, 3.0, 3.1")
if errV3_0.Error() == ign3error.ErrUnknownVersion.Error() {
ignCfgV2, rptV2, errV2 := ign2.Parse(rawIgn)
if errV2 == nil && !rptV2.IsFatal() {
return ignCfgV2, nil
}

// If the error is still UnknownVersion it's not a 3.2/3.1/3.0 or 2.x config, thus unsupported
if errV2.Error() == ign2error.ErrUnknownVersion.Error() {
return ign3types.Config{}, errors.Errorf("parsing Ignition config failed: unknown version. Supported spec versions: 2.2, 3.0, 3.1, 3.2")
}
return ign3types.Config{}, errors.Errorf("parsing Ignition spec v2 failed with error: %v\nReport: %v", errV2, rptV2)
}
return ign3types.Config{}, errors.Errorf("parsing Ignition spec v2 failed with error: %v\nReport: %v", errV2, rptV2)
return ign3types.Config{}, errors.Errorf("parsing Ignition config spec v3.0 failed with error: %v\nReport: %v", errV3_0, rptV3_0)
}
return ign3types.Config{}, errors.Errorf("parsing Ignition config spec v3.0 failed with error: %v\nReport: %v", errV3_0, rptV3_0)
return ign3types.Config{}, errors.Errorf("parsing Ignition config spec v3.1 failed with error: %v\nReport: %v", errV3_1, rptV3_1)
}
return ign3types.Config{}, errors.Errorf("parsing Ignition config spec v3.1 failed with error: %v\nReport: %v", errV3_1, rptV3_1)
return ign3types.Config{}, errors.Errorf("parsing Ignition config spec v3.2 failed with error: %v\nReport: %v", errV3_2, rptV3_2)
}

// ParseAndConvertConfig parses rawIgn for both V2 and V3 ignition configs and returns
Expand Down Expand Up @@ -452,8 +509,8 @@ func TranspileCoreOSConfigToIgn(files, units []string) (*ign3types.Config, error
if err != nil {
return nil, fmt.Errorf("failed to transpile config to Ignition config %s\nTranslation set: %v", err, tSet)
}
ign3_1config := translate3.Translate(ign3_0config)
outConfig = ign3.Merge(outConfig, ign3_1config)
ign3_2config := translate3.Translate(translate3_1.Translate(ign3_0config))
outConfig = ign3.Merge(outConfig, ign3_2config)
}

for _, d := range units {
Expand All @@ -469,8 +526,8 @@ func TranspileCoreOSConfigToIgn(files, units []string) (*ign3types.Config, error
if err != nil {
return nil, fmt.Errorf("failed to transpile config to Ignition config %s\nTranslation set: %v", err, tSet)
}
ign3_1config := translate3.Translate(ign3_0config)
outConfig = ign3.Merge(outConfig, ign3_1config)
ign3_2config := translate3.Translate(translate3_1.Translate(ign3_0config))
outConfig = ign3.Merge(outConfig, ign3_2config)
}

return &outConfig, nil
Expand Down