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

[WIP] * : Ignition v2 to v3 transition #583

Closed
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
373 changes: 35 additions & 338 deletions Gopkg.lock

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,9 @@ required = [
name = "github.com/blang/semver"
version = "v3.5.0"

[[constraint]]
name = "github.com/coreos/container-linux-config-transpiler"
version = "v0.9.0"

[[constraint]]
name = "github.com/coreos/ignition"
version = "0.26.0"
branch = "master"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can now use 2.0.0-alpha tag iirc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok i was following your installer pr


[[constraint]]
name = "github.com/ghodss/yaml"
Expand Down
2 changes: 1 addition & 1 deletion docs/MachineConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type MachineConfigSpec struct {
// fetch the OS. This must be in the canonical $name@$digest format.
OSImageURL string `json:"osImageURL"`
// Config is a Ignition Config object.
Config ignv2_2.Config `json:"config"`
Config igntypes.Config `json:"config"`
}
```

Expand Down
45 changes: 24 additions & 21 deletions lib/resourceapply/machineconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

ignv2_2types "github.com/coreos/ignition/config/v2_2/types"
igntypes "github.com/coreos/ignition/config/v3_0/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 All @@ -16,6 +16,9 @@ import (
)

func TestApplyMachineConfig(t *testing.T) {
homeDir0 := "/home/dummy-prev"
homeDir1 := "/home/dummy"

tests := []struct {
existing []runtime.Object
input *mcfgv1.MachineConfig
Expand Down Expand Up @@ -175,10 +178,10 @@ func TestApplyMachineConfig(t *testing.T) {
input: &mcfgv1.MachineConfig{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: mcfgv1.MachineConfigSpec{
Config: ignv2_2types.Config{
Passwd: ignv2_2types.Passwd{
Users: []ignv2_2types.PasswdUser{{
HomeDir: "/home/dummy",
Config: igntypes.Config{
Passwd: igntypes.Passwd{
Users: []igntypes.PasswdUser{{
HomeDir: &homeDir1,
}},
},
},
Expand All @@ -199,10 +202,10 @@ func TestApplyMachineConfig(t *testing.T) {
expected := &mcfgv1.MachineConfig{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Labels: map[string]string{"extra": "leave-alone"}},
Spec: mcfgv1.MachineConfigSpec{
Config: ignv2_2types.Config{
Passwd: ignv2_2types.Passwd{
Users: []ignv2_2types.PasswdUser{{
HomeDir: "/home/dummy",
Config: igntypes.Config{
Passwd: igntypes.Passwd{
Users: []igntypes.PasswdUser{{
HomeDir: &homeDir1,
}},
},
},
Expand All @@ -218,10 +221,10 @@ func TestApplyMachineConfig(t *testing.T) {
&mcfgv1.MachineConfig{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Labels: map[string]string{"extra": "leave-alone"}},
Spec: mcfgv1.MachineConfigSpec{
Config: ignv2_2types.Config{
Passwd: ignv2_2types.Passwd{
Users: []ignv2_2types.PasswdUser{{
HomeDir: "/home/dummy-prev",
Config: igntypes.Config{
Passwd: igntypes.Passwd{
Users: []igntypes.PasswdUser{{
HomeDir: &homeDir0,
}},
},
},
Expand All @@ -231,10 +234,10 @@ func TestApplyMachineConfig(t *testing.T) {
input: &mcfgv1.MachineConfig{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Spec: mcfgv1.MachineConfigSpec{
Config: ignv2_2types.Config{
Passwd: ignv2_2types.Passwd{
Users: []ignv2_2types.PasswdUser{{
HomeDir: "/home/dummy",
Config: igntypes.Config{
Passwd: igntypes.Passwd{
Users: []igntypes.PasswdUser{{
HomeDir: &homeDir1,
}},
},
},
Expand All @@ -255,10 +258,10 @@ func TestApplyMachineConfig(t *testing.T) {
expected := &mcfgv1.MachineConfig{
ObjectMeta: metav1.ObjectMeta{Name: "foo", Labels: map[string]string{"extra": "leave-alone"}},
Spec: mcfgv1.MachineConfigSpec{
Config: ignv2_2types.Config{
Passwd: ignv2_2types.Passwd{
Users: []ignv2_2types.PasswdUser{{
HomeDir: "/home/dummy",
Config: igntypes.Config{
Passwd: igntypes.Passwd{
Users: []igntypes.PasswdUser{{
HomeDir: &homeDir1,
}},
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/machineconfiguration.openshift.io/v1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"sort"

ignv2_2 "github.com/coreos/ignition/config/v2_2"
ign "github.com/coreos/ignition/config/v3_0"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -21,7 +21,7 @@ func MergeMachineConfigs(configs []*MachineConfig, osImageURL string) *MachineCo

outIgn := configs[0].Spec.Config
for idx := 1; idx < len(configs); idx++ {
outIgn = ignv2_2.Append(outIgn, configs[idx].Spec.Config)
outIgn = ign.Merge(outIgn, configs[idx].Spec.Config)
}

ajeddeloh marked this conversation as resolved.
Show resolved Hide resolved
return &MachineConfig{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package v1

import (
ignv2_2 "github.com/coreos/ignition/config/v2_2"
ignv2_2types "github.com/coreos/ignition/config/v2_2/types"
ign "github.com/coreos/ignition/config/v3_0"
igntypes "github.com/coreos/ignition/config/v3_0/types"
runtime "k8s.io/apimachinery/pkg/runtime"
)

Expand Down Expand Up @@ -37,13 +37,12 @@ func (in *MachineConfigSpec) DeepCopyInto(out *MachineConfigSpec) {
return
}

func deepCopyIgnConfig(in ignv2_2types.Config) ignv2_2types.Config {
var out ignv2_2types.Config
func deepCopyIgnConfig(in igntypes.Config) igntypes.Config {
var out igntypes.Config

// https://github.com/coreos/ignition/blob/d19b2021cf397de7c31774c13805bbc3aa655646/config/v2_2/append.go#L41
out.Ignition.Version = in.Ignition.Version

return ignv2_2.Append(out, in)
return ign.Merge(out, in)
}

// DeepCopy copying the receiver, creating a new MachineConfigSpec.
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/machineconfiguration.openshift.io/v1/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v1

import (
ignv2_2types "github.com/coreos/ignition/config/v2_2/types"
igntypes "github.com/coreos/ignition/config/v3_0/types"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -227,7 +227,7 @@ type MachineConfigSpec struct {
// fetch the OS.
OSImageURL string `json:"osImageURL"`
// Config is a Ignition Config object.
Config ignv2_2types.Config `json:"config"`
Config igntypes.Config `json:"config"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
21 changes: 15 additions & 6 deletions pkg/controller/common/helpers.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package common

import (
ignv2_2types "github.com/coreos/ignition/config/v2_2/types"
igntypes "github.com/coreos/ignition/config/v3_0/types"
)

// NewIgnConfig returns an empty ignition config with version set as 2.2.0
func NewIgnConfig() ignv2_2types.Config {
return ignv2_2types.Config{
Ignition: ignv2_2types.Ignition{
Version: "2.2.0",
// NewIgnConfig returns an empty ignition config with version set as
// igntypes.MaxVersion.String() currently: 3.0.0
func NewIgnConfig() igntypes.Config {
return igntypes.Config{
Ignition: igntypes.Ignition{
Version: igntypes.MaxVersion.String(),
},
}
}

// StrFromStrPtr returns string value from string pointer or empty string if nil
func StrFromStrPtr(strptr *string) string {
if strptr == nil {
return ""
}
return *strptr
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"reflect"
"time"

ignv2_2types "github.com/coreos/ignition/config/v2_2/types"
igntypes "github.com/coreos/ignition/config/v3_0/types"
"github.com/golang/glog"
"github.com/vincent-petithory/dataurl"
"k8s.io/api/core/v1"
Expand Down Expand Up @@ -334,7 +334,7 @@ func (ctrl *Controller) handleImgErr(err error, key interface{}) {
}

// generateOriginalContainerRuntimeConfigs returns rendered default storage, and crio config files
func (ctrl *Controller) generateOriginalContainerRuntimeConfigs(role string) (*ignv2_2types.File, *ignv2_2types.File, *ignv2_2types.File, error) {
func (ctrl *Controller) generateOriginalContainerRuntimeConfigs(role string) (*igntypes.File, *igntypes.File, *igntypes.File, error) {
cc, err := ctrl.ccLister.Get(ctrlcommon.ControllerConfigName)
if err != nil {
return nil, nil, nil, fmt.Errorf("could not get ControllerConfig %v", err)
Expand All @@ -348,7 +348,7 @@ func (ctrl *Controller) generateOriginalContainerRuntimeConfigs(role string) (*i
}
// Find generated storage.config, and crio.config
var (
config, gmcStorageConfig, gmcCRIOConfig, gmcRegistriesConfig *ignv2_2types.File
config, gmcStorageConfig, gmcCRIOConfig, gmcRegistriesConfig *igntypes.File
errStorage, errCRIO, errRegistries error
)
// Find storage config
Expand Down Expand Up @@ -493,7 +493,8 @@ func (ctrl *Controller) syncContainerRuntimeConfig(key string) error {
}
}
if isNotFound {
mc = mtmpl.MachineConfigFromIgnConfig(role, managedKey, &ignv2_2types.Config{})
igncfg := ctrlcommon.NewIgnConfig()
mc = mtmpl.MachineConfigFromIgnConfig(role, managedKey, &igncfg)
}
mc.Spec.Config = createNewCtrRuntimeConfigIgnition(storageTOML, crioTOML)
mc.ObjectMeta.Annotations = map[string]string{
Expand Down Expand Up @@ -530,8 +531,12 @@ func (ctrl *Controller) syncContainerRuntimeConfig(key string) error {

// mergeConfigChanges retrieves the original/default config data from the templates, decodes it and merges in the changes given by the Custom Resource.
// It then encodes the new data and returns it.
func (ctrl *Controller) mergeConfigChanges(origFile *ignv2_2types.File, cfg *mcfgv1.ContainerRuntimeConfig, mc *mcfgv1.MachineConfig, role, managedKey string, isNotFound bool, update updateConfig) ([]byte, error) {
dataURL, err := dataurl.DecodeString(origFile.Contents.Source)
func (ctrl *Controller) mergeConfigChanges(origFile *igntypes.File, cfg *mcfgv1.ContainerRuntimeConfig, mc *mcfgv1.MachineConfig, role, managedKey string, isNotFound bool, update updateConfig) ([]byte, error) {
sourceData := ctrlcommon.StrFromStrPtr(origFile.Contents.Source)
if len(sourceData) == 0 {
sourceData = "data:,"
}
dataURL, err := dataurl.DecodeString(sourceData)
if err != nil {
return nil, ctrl.syncStatusOnly(cfg, err, "could not decode original Container Runtime config: %v", err)
}
Expand Down Expand Up @@ -600,7 +605,11 @@ func (ctrl *Controller) syncImageConfig(key string) error {

var registriesTOML []byte
if insecureRegs != nil || blockedRegs != nil {
dataURL, err := dataurl.DecodeString(originalRegistriesIgn.Contents.Source)
sourceData := ctrlcommon.StrFromStrPtr(originalRegistriesIgn.Contents.Source)
if len(sourceData) == 0 {
sourceData = "data:,"
}
dataURL, err := dataurl.DecodeString(sourceData)
if err != nil {
return fmt.Errorf("could not decode original registries config: %v", err)
}
Expand All @@ -625,7 +634,8 @@ func (ctrl *Controller) syncImageConfig(key string) error {
}
}
if isNotFound {
mc = mtmpl.MachineConfigFromIgnConfig(role, managedKey, &ignv2_2types.Config{})
igncfg := ctrlcommon.NewIgnConfig()
mc = mtmpl.MachineConfigFromIgnConfig(role, managedKey, &igncfg)
}
mc.Spec.Config = registriesIgn
mc.ObjectMeta.Annotations = map[string]string{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"

ignv2_2types "github.com/coreos/ignition/config/v2_2/types"
igntypes "github.com/coreos/ignition/config/v3_0/types"
apicfgv1 "github.com/openshift/api/config/v1"
fakeconfigv1client "github.com/openshift/client-go/config/clientset/versioned/fake"
configv1informer "github.com/openshift/client-go/config/informers/externalversions"
mcfgv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/fake"
"github.com/openshift/machine-config-operator/pkg/controller/common"
"github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/fake"
informers "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions"
)

Expand Down Expand Up @@ -86,7 +86,7 @@ func (f *fixture) validateActions() {
}
}

func newMachineConfig(name string, labels map[string]string, osurl string, files []ignv2_2types.File) *mcfgv1.MachineConfig {
func newMachineConfig(name string, labels map[string]string, osurl string, files []igntypes.File) *mcfgv1.MachineConfig {
if labels == nil {
labels = map[string]string{}
}
Expand All @@ -95,7 +95,7 @@ func newMachineConfig(name string, labels map[string]string, osurl string, files
ObjectMeta: metav1.ObjectMeta{Name: name, Labels: labels, UID: types.UID(utilrand.String(5))},
Spec: mcfgv1.MachineConfigSpec{
OSImageURL: osurl,
Config: ignv2_2types.Config{Storage: ignv2_2types.Storage{Files: files}},
Config: igntypes.Config{Storage: igntypes.Storage{Files: files}},
},
}
}
Expand Down Expand Up @@ -336,7 +336,7 @@ func TestContainerRuntimeConfigCreate(t *testing.T) {
mcp := newMachineConfigPool("master", map[string]string{"custom-crio": "my-config"}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "node-role", "master"), "v0")
mcp2 := newMachineConfigPool("worker", map[string]string{"custom-crio": "storage-config"}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "node-role", "worker"), "v0")
ctrcfg1 := newContainerRuntimeConfig("set-log-level", &mcfgv1.ContainerRuntimeConfiguration{LogLevel: "debug", LogSizeMax: resource.MustParse("9k"), OverlaySize: resource.MustParse("3G")}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "custom-crio", "my-config"))
mcs1 := newMachineConfig(getManagedKeyCtrCfg(mcp, ctrcfg1), map[string]string{"node-role": "master"}, "dummy://", []ignv2_2types.File{{}})
mcs1 := newMachineConfig(getManagedKeyCtrCfg(mcp, ctrcfg1), map[string]string{"node-role": "master"}, "dummy://", []igntypes.File{{}})

f.ccLister = append(f.ccLister, cc)
f.mcpLister = append(f.mcpLister, mcp)
Expand Down Expand Up @@ -367,7 +367,7 @@ func TestContainerRuntimeConfigUpdate(t *testing.T) {
mcp := newMachineConfigPool("master", map[string]string{"custom-crio": "my-config"}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "node-role", "master"), "v0")
mcp2 := newMachineConfigPool("worker", map[string]string{"custom-crio": "storage-config"}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "node-role", "worker"), "v0")
ctrcfg1 := newContainerRuntimeConfig("set-log-level", &mcfgv1.ContainerRuntimeConfiguration{LogLevel: "debug", LogSizeMax: resource.MustParse("9k"), OverlaySize: resource.MustParse("3G")}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "custom-crio", "my-config"))
mcs := newMachineConfig(getManagedKeyCtrCfg(mcp, ctrcfg1), map[string]string{"node-role": "master"}, "dummy://", []ignv2_2types.File{{}})
mcs := newMachineConfig(getManagedKeyCtrCfg(mcp, ctrcfg1), map[string]string{"node-role": "master"}, "dummy://", []igntypes.File{{}})

f.ccLister = append(f.ccLister, cc)
f.mcpLister = append(f.mcpLister, mcp)
Expand Down Expand Up @@ -443,8 +443,8 @@ func TestImageConfigCreate(t *testing.T) {
mcp2 := newMachineConfigPool("worker", map[string]string{"custom-crio": "storage-config"}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "node-role", "worker"), "v0")
imgcfg1 := newImageConfig("cluster", &apicfgv1.RegistrySources{InsecureRegistries: []string{"blah.io"}})
cvcfg1 := newClusterVersionConfig("version", "test.io/myuser/myimage:test")
mcs1 := newMachineConfig(getManagedKeyReg(mcp, imgcfg1), map[string]string{"node-role": "master"}, "dummy://", []ignv2_2types.File{{}})
mcs2 := newMachineConfig(getManagedKeyReg(mcp2, imgcfg1), map[string]string{"node-role": "worker"}, "dummy://", []ignv2_2types.File{{}})
mcs1 := newMachineConfig(getManagedKeyReg(mcp, imgcfg1), map[string]string{"node-role": "master"}, "dummy://", []igntypes.File{{}})
mcs2 := newMachineConfig(getManagedKeyReg(mcp2, imgcfg1), map[string]string{"node-role": "worker"}, "dummy://", []igntypes.File{{}})

f.ccLister = append(f.ccLister, cc)
f.mcpLister = append(f.mcpLister, mcp)
Expand Down Expand Up @@ -475,8 +475,8 @@ func TestImageConfigUpdate(t *testing.T) {
mcp2 := newMachineConfigPool("worker", map[string]string{"custom-crio": "storage-config"}, metav1.AddLabelToSelector(&metav1.LabelSelector{}, "node-role", "worker"), "v0")
imgcfg1 := newImageConfig("cluster", &apicfgv1.RegistrySources{InsecureRegistries: []string{"blah.io"}})
cvcfg1 := newClusterVersionConfig("version", "test.io/myuser/myimage:test")
mcs1 := newMachineConfig(getManagedKeyReg(mcp, imgcfg1), map[string]string{"node-role": "master"}, "dummy://", []ignv2_2types.File{{}})
mcs2 := newMachineConfig(getManagedKeyReg(mcp2, imgcfg1), map[string]string{"node-role": "worker"}, "dummy://", []ignv2_2types.File{{}})
mcs1 := newMachineConfig(getManagedKeyReg(mcp, imgcfg1), map[string]string{"node-role": "master"}, "dummy://", []igntypes.File{{}})
mcs2 := newMachineConfig(getManagedKeyReg(mcp2, imgcfg1), map[string]string{"node-role": "worker"}, "dummy://", []igntypes.File{{}})

f.ccLister = append(f.ccLister, cc)
f.mcpLister = append(f.mcpLister, mcp)
Expand Down
Loading