Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions butane/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import (
openshift4_23_exp "github.com/coreos/ignition/v2/butane/config/openshift/v4_23_exp"
openshift4_8 "github.com/coreos/ignition/v2/butane/config/openshift/v4_8"
openshift4_9 "github.com/coreos/ignition/v2/butane/config/openshift/v4_9"
openshift5_0 "github.com/coreos/ignition/v2/butane/config/openshift/v5_0"
openshift5_1_exp "github.com/coreos/ignition/v2/butane/config/openshift/v5_1_exp"
r4e1_0 "github.com/coreos/ignition/v2/butane/config/r4e/v1_0"
r4e1_1 "github.com/coreos/ignition/v2/butane/config/r4e/v1_1"
r4e1_2_exp "github.com/coreos/ignition/v2/butane/config/r4e/v1_2_exp"
Expand Down Expand Up @@ -96,6 +98,8 @@ func init() {
RegisterTranslator("openshift", "4.21.0", openshift4_21.ToConfigBytes)
RegisterTranslator("openshift", "4.22.0", openshift4_22.ToConfigBytes)
RegisterTranslator("openshift", "4.23.0-experimental", openshift4_23_exp.ToConfigBytes)
RegisterTranslator("openshift", "5.0.0", openshift5_0.ToConfigBytes)
RegisterTranslator("openshift", "5.1.0-experimental", openshift5_1_exp.ToConfigBytes)
RegisterTranslator("r4e", "1.0.0", r4e1_0.ToIgn3_3Bytes)
RegisterTranslator("r4e", "1.1.0", r4e1_1.ToIgn3_4Bytes)
RegisterTranslator("r4e", "1.2.0-experimental", r4e1_2_exp.ToIgn3_7Bytes)
Expand Down
138 changes: 138 additions & 0 deletions butane/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,151 @@
package config

import (
"encoding/json"
"fmt"
"testing"

"github.com/coreos/ignition/v2/butane/config/common"
ignition "github.com/coreos/ignition/v2/config/v3_5"
ignitionExp "github.com/coreos/ignition/v2/config/v3_7_experimental"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)

func TestOpenShiftVersions(t *testing.T) {
tests := []struct {
version string
ignitionVersion string
}{
{"4.22.0", "3.5.0"},
{"4.23.0-experimental", "3.7.0-experimental"},
{"5.0.0", "3.5.0"},
{"5.1.0-experimental", "3.7.0-experimental"},
}
for _, test := range tests {
for _, raw := range []bool{false, true} {
t.Run(fmt.Sprintf("%s/raw=%v", test.version, raw), func(t *testing.T) {
input := []byte(fmt.Sprintf(`variant: openshift
version: %s
metadata:
name: version-test
labels:
machineconfiguration.openshift.io/role: worker
storage:
files:
- path: /etc/version-test
mode: 0644
contents:
inline: hello
`, test.version))
out, r, err := TranslateBytes(input, common.TranslateBytesOptions{Raw: raw})
if !assert.NoError(t, err) || !assert.Empty(t, r.Entries) {
return
}
if !raw {
var mc struct {
APIVersion string `yaml:"apiVersion"`
Kind string `yaml:"kind"`
Spec struct {
Config map[string]interface{} `yaml:"config"`
} `yaml:"spec"`
}
if !assert.NoError(t, yaml.Unmarshal(out, &mc)) {
return
}
assert.Equal(t, "machineconfiguration.openshift.io/v1", mc.APIVersion)
assert.Equal(t, "MachineConfig", mc.Kind)
out, err = json.Marshal(mc.Spec.Config)
if !assert.NoError(t, err) {
return
}
}
var cfg struct {
Ignition struct {
Version string `json:"version"`
} `json:"ignition"`
}
if !assert.NoError(t, json.Unmarshal(out, &cfg)) {
return
}
assert.Equal(t, test.ignitionVersion, cfg.Ignition.Version)
if test.ignitionVersion == "3.5.0" {
// OCP 5.0's MCO uses this parser, not the newest vendored spec.
parsed, r, err := ignition.ParseCompatibleVersion(out)
if !assert.NoError(t, err) || !assert.Empty(t, r.Entries) || !assert.Len(t, parsed.Storage.Files, 1) {
return
}
assert.Equal(t, "/etc/version-test", parsed.Storage.Files[0].Path)
} else {
parsed, r, err := ignitionExp.ParseCompatibleVersion(out)
if !assert.NoError(t, err) || !assert.Empty(t, r.Entries) || !assert.Len(t, parsed.Storage.Files, 1) {
return
}
assert.Equal(t, "/etc/version-test", parsed.Storage.Files[0].Path)
}
})
}
}
}

func TestOpenShiftUnknownVersions(t *testing.T) {
for _, version := range []string{"4.23.0", "5.0.0-experimental", "5.0.1", "5.1.0", "5.2.0-experimental"} {
t.Run(version, func(t *testing.T) {
for _, raw := range []bool{false, true} {
out, _, err := TranslateBytes([]byte("variant: openshift\nversion: "+version+"\n"), common.TranslateBytesOptions{Raw: raw})
assert.IsType(t, common.ErrUnknownVersion{}, err)
assert.Empty(t, out)
}
})
}
}

// Both development lines currently share their feature set and Ignition target.
func TestOpenShiftExperimentalParity(t *testing.T) {
tests := []struct {
name string
config string
}{
{"minimal", ""},
{"grub", `grub:
users:
- name: root
password_hash: grub.pbkdf2.sha512.10000.874A958E526409...
`},
{"openshift fields", `openshift:
kernel_arguments: [console=ttyS0]
extensions: [usbguard]
fips: false
kernel_type: realtime
`},
{"unsupported file mode", `storage:
files:
- path: /etc/test
mode: 04755
`},
}
for _, test := range tests {
for _, raw := range []bool{false, true} {
t.Run(fmt.Sprintf("%s/raw=%v", test.name, raw), func(t *testing.T) {
input := `variant: openshift
version: %s
metadata:
name: parity-test
labels:
machineconfiguration.openshift.io/role: worker
` + test.config
options := common.TranslateBytesOptions{Raw: raw}
before, beforeReport, beforeErr := TranslateBytes([]byte(fmt.Sprintf(input, "4.23.0-experimental")), options)
after, afterReport, afterErr := TranslateBytes([]byte(fmt.Sprintf(input, "5.1.0-experimental")), options)
assert.Equal(t, before, after)
assert.Equal(t, beforeReport, afterReport)
assert.Equal(t, beforeErr, afterErr)
})
}
}
}

// Ensures that large sizeMiB values are rendered as normal integers in
// the generated MachineConfig YAML, rather than being formatted with
// scientific notation (e.g. "1e+06" instead of "1000000").
Expand Down
48 changes: 48 additions & 0 deletions butane/config/openshift/v5_0/result/schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2021 Red Hat, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package result

import (
"github.com/coreos/ignition/v2/config/v3_5/types"
)

const (
MC_API_VERSION = "machineconfiguration.openshift.io/v1"
MC_KIND = "MachineConfig"
)

// We round-trip through JSON because Ignition uses `json` struct tags,
// so all struct tags need to be `json` even though we're ultimately
// writing YAML.

type MachineConfig struct {
ApiVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Metadata Metadata `json:"metadata"`
Spec Spec `json:"spec"`
}

type Metadata struct {
Name string `json:"name"`
Labels map[string]string `json:"labels,omitempty"`
}

type Spec struct {
Config types.Config `json:"config"`
KernelArguments []string `json:"kernelArguments,omitempty"`
Extensions []string `json:"extensions,omitempty"`
FIPS *bool `json:"fips,omitempty"`
KernelType *string `json:"kernelType,omitempty"`
}
39 changes: 39 additions & 0 deletions butane/config/openshift/v5_0/schema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2020 Red Hat, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v5_0

import (
fcos "github.com/coreos/ignition/v2/butane/config/fcos/v1_6"
)

const ROLE_LABEL_KEY = "machineconfiguration.openshift.io/role"

type Config struct {
fcos.Config `yaml:",inline"`
Metadata Metadata `yaml:"metadata"`
OpenShift OpenShift `yaml:"openshift"`
}

type Metadata struct {
Name string `yaml:"name"`
Labels map[string]string `yaml:"labels,omitempty"`
}

type OpenShift struct {
KernelArguments []string `yaml:"kernel_arguments"`
Extensions []string `yaml:"extensions"`
FIPS *bool `yaml:"fips"`
KernelType *string `yaml:"kernel_type"`
}
Loading
Loading