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
11 changes: 7 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/clarketm/json v1.14.1
github.com/containers/image/v5 v5.14.0
github.com/containers/storage v1.32.6
github.com/coreos/fcct v0.5.0
github.com/coreos/butane v0.14.0
github.com/coreos/go-semver v0.3.0
github.com/coreos/ign-converter v0.0.0-20201123214124-8dac862888aa
github.com/coreos/ignition v0.35.0
Expand All @@ -32,7 +32,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.0
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace
github.com/stretchr/testify v1.7.0
github.com/vincent-petithory/dataurl v1.0.0
golang.org/x/net v0.0.0-20210825183410-e898025ed96a
Expand All @@ -49,6 +49,11 @@ require (
sigs.k8s.io/controller-runtime v0.11.0
)

require (
github.com/coreos/go-json v0.0.0-20211020211907-c63f628265de // indirect
github.com/coreos/vcontext v0.0.0-20211021162308-f1dbbca7bef4 // indirect
)

require (
4d63.com/gochecknoglobals v0.0.0-20201008074935-acfc0b28355a // indirect
github.com/Antonboom/errname v0.1.4 // indirect
Expand Down Expand Up @@ -79,10 +84,8 @@ require (
github.com/containerd/cgroups v1.0.1 // indirect
github.com/containers/libtrust v0.0.0-20190913040956-14b96171aa3b // indirect
github.com/containers/ocicrypt v1.1.2 // indirect
github.com/coreos/go-json v0.0.0-20211020211907-c63f628265de // indirect
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/coreos/vcontext v0.0.0-20211021162308-f1dbbca7bef4 // indirect
github.com/daixiang0/gci v0.2.9 // indirect
github.com/denis-tingajkin/go-header v0.4.2 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
Expand Down
13 changes: 4 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ github.com/ashcrow/osrelease v0.0.0-20180626175927-9b292693c55c h1:icme0QhxrgZOx
github.com/ashcrow/osrelease v0.0.0-20180626175927-9b292693c55c/go.mod h1:BRljTyotlu+6N+Qlu5MhjxpdmccCnp9lDvZjNNV8qr4=
github.com/auth0/go-jwt-middleware v1.0.1/go.mod h1:YSeUX3z6+TF2H+7padiEqNJ73Zy9vXW72U//IgN0BIM=
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/aws/aws-sdk-go v1.19.11/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.23.20/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.25.37/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.30.28/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
Expand Down Expand Up @@ -334,10 +333,10 @@ github.com/containers/storage v1.32.6/go.mod h1:mdB+b89p+jU8zpzLTVXA0gWMmIo0Wrkf
github.com/coredns/caddy v1.1.0/go.mod h1:A6ntJQlAWuQfFlsd9hvigKbo2WS0VUs2l1e2F+BawD4=
github.com/coredns/corefile-migration v1.0.14/go.mod h1:XnhgULOEouimnzgn0t4WPuFDN2/PJQcTxdWKC5eXNGE=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/butane v0.14.0 h1:1xLt5y6RR8NTmeDf6yMzqP7Jqre8PvJ/1BTXQTxEMhk=
github.com/coreos/butane v0.14.0/go.mod h1:Q5DcBsHDckEZ7IgQSb1MvvkNc50dpoT1lOHdGWwCRjY=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/fcct v0.5.0 h1:f/z+MCoR2vULes+MyoPEApQ6iluy/JbXoRi6dahPItQ=
github.com/coreos/fcct v0.5.0/go.mod h1:cbE+j77YSQwFB2fozWVB3qsI2Pi3YiVEbDz/b6Yywdo=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-iptables v0.4.5/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU=
github.com/coreos/go-iptables v0.5.0/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU=
Expand All @@ -362,14 +361,12 @@ github.com/coreos/ign-converter v0.0.0-20201123214124-8dac862888aa h1:oIF6XCee+G
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.7.0/go.mod h1:3CjaRpg51hmJzPjarbzB0RvSZbLkNOczxKJobTl6nOY=
github.com/coreos/ignition/v2 v2.13.0 h1:1ouW+d0nOuPUbLjxxOCnC+dWQxynr8Mt5exqJoCD7b4=
github.com/coreos/ignition/v2 v2.13.0/go.mod h1:HO1HWYWcvAIbHu6xewoKxPGBTyZ32FLwGIuipw5d63o=
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coreos/vcontext v0.0.0-20190529201340-22b159166068/go.mod h1:E+6hug9bFSe0KZ2ZAzr8M9F5JlArJjv5D1JS7KSkPKE=
github.com/coreos/vcontext v0.0.0-20191017033345-260217907eb5/go.mod h1:E+6hug9bFSe0KZ2ZAzr8M9F5JlArJjv5D1JS7KSkPKE=
github.com/coreos/vcontext v0.0.0-20211021162308-f1dbbca7bef4 h1:pfSsrvbjUFGINaPGy0mm2QKQKTdq7IcbUa+nQwsz2UM=
github.com/coreos/vcontext v0.0.0-20211021162308-f1dbbca7bef4/go.mod h1:HckqHnP/HI41vS0bfVjJ20u6jD0biI5+68QwZm5Xb9U=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
Expand Down Expand Up @@ -1228,8 +1225,9 @@ github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzu
github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace h1:9PNP1jnUjRhfmGMlkXHjYPishpcw4jpSt/V/xYY3FMA=
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
Expand Down Expand Up @@ -1489,7 +1487,6 @@ golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190228165749-92fc7df08ae7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down Expand Up @@ -1607,7 +1604,6 @@ golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191110163157-d32e6e3b99c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -1994,7 +1990,6 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20190502103701-55513cacd4ae/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20191010095647-fc94e3f71652/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
Expand Down
2 changes: 1 addition & 1 deletion manifests/on-prem/keepalived.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ spec:
image: {{ .Images.BaremetalRuntimeCfgBootstrap }}
env:
- name: ENABLE_UNICAST
value: "{{ onPremPlatformKeepalivedEnableUnicast .ControllerConfig }}"
value: "yes"
- name: IS_BOOTSTRAP
value: "yes"
command:
Expand Down
59 changes: 34 additions & 25 deletions pkg/controller/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
"sort"

"github.com/clarketm/json"
fcctbase "github.com/coreos/fcct/base/v0_1"
bubase "github.com/coreos/butane/base/v0_3"
bucommon "github.com/coreos/butane/config/common"
fcosbutane "github.com/coreos/butane/config/fcos/v1_2"
"github.com/coreos/ign-converter/translate/v23tov30"
"github.com/coreos/ign-converter/translate/v32tov22"
"github.com/coreos/ign-converter/translate/v32tov31"
Expand Down Expand Up @@ -593,47 +595,54 @@ func removeIgnDuplicateFilesUnitsUsers(ignConfig ign2types.Config) (ign2types.Co
return ignConfig, nil
}

// TranspileCoreOSConfigToIgn transpiles Fedora CoreOS config to ignition
// internally it transpiles to Ign spec v3 config
func TranspileCoreOSConfigToIgn(files, units []string) (*ign3types.Config, error) {
// ConvertButaneFragmentsToIgnition takes as input butane fragments (fcos 1.3) and returns an Ignition v3.2 configuration.
func ConvertButaneFragmentsToIgnition(files, units []string) (*ign3types.Config, error) {
overwrite := true
outConfig := ign3types.Config{}
buCfg := fcosbutane.Config{}
// Convert data to Ignition resources
for _, contents := range files {
f := new(fcctbase.File)
f := new(bubase.File)
if err := yaml.Unmarshal([]byte(contents), f); err != nil {
return nil, fmt.Errorf("failed to unmarshal %q into struct: %v", contents, err)
}
f.Overwrite = &overwrite

// Add the file to the config
var ctCfg fcctbase.Config
ctCfg.Storage.Files = append(ctCfg.Storage.Files, *f)
ign3_0config, tSet, err := ctCfg.ToIgn3_0()
if err != nil {
return nil, fmt.Errorf("failed to transpile config to Ignition config %s\nTranslation set: %v", err, tSet)
}
ign3_2config := translate3.Translate(translate3_1.Translate(ign3_0config))
outConfig = ign3.Merge(outConfig, ign3_2config)
buCfg.Storage.Files = append(buCfg.Storage.Files, *f)
Comment on lines -609 to +610
Copy link
Member Author

Choose a reason for hiding this comment

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

While I had the patient open, I changed this to generate a single butane config, then translate it once to ignition which is way simpler than generating a tiny butane config and then continually merging ignition.

}

dropins := make(map[string]bubase.Unit)
for _, contents := range units {
u := new(fcctbase.Unit)
u := new(bubase.Unit)
if err := yaml.Unmarshal([]byte(contents), u); err != nil {
return nil, fmt.Errorf("failed to unmarshal systemd unit into struct: %v", err)
return nil, fmt.Errorf("failed to unmarshal systemd unit into struct: %w", err)
}

// Add the unit to the config
var ctCfg fcctbase.Config
ctCfg.Systemd.Units = append(ctCfg.Systemd.Units, *u)
ign3_0config, tSet, err := ctCfg.ToIgn3_0()
if err != nil {
return nil, fmt.Errorf("failed to transpile config to Ignition config %s\nTranslation set: %v", err, tSet)
// Handle drop-ins specially; a unit name with drop-ins can be repeated and they should be merged.
if len(u.Dropins) > 0 {
if current, ok := dropins[u.Name]; ok {
current.Dropins = append(current.Dropins, u.Dropins...)
} else {
dropins[u.Name] = *u
}
} else {
buCfg.Systemd.Units = append(buCfg.Systemd.Units, *u)
}
ign3_2config := translate3.Translate(translate3_1.Translate(ign3_0config))
outConfig = ign3.Merge(outConfig, ign3_2config)
}
for _, unit := range dropins {
buCfg.Systemd.Units = append(buCfg.Systemd.Units, unit)
}

// We want the output of this to be reproducible (it should not depend on the order of the filesystem)
sort.Slice(buCfg.Storage.Files, func(i, j int) bool { return buCfg.Storage.Files[i].Path < buCfg.Storage.Files[j].Path })
sort.Slice(buCfg.Systemd.Units, func(i, j int) bool { return buCfg.Systemd.Units[i].Name < buCfg.Systemd.Units[j].Name })
for _, unit := range buCfg.Systemd.Units {
sort.Slice(unit.Dropins, func(i, j int) bool { return unit.Dropins[i].Name < unit.Dropins[j].Name })
}

outConfig, rep, err := buCfg.ToIgn3_2(bucommon.TranslateOptions{})
if err != nil {
return nil, fmt.Errorf("failed to convert butane fragments: %v %w", rep, err)
}
return &outConfig, nil
}

Expand Down
41 changes: 38 additions & 3 deletions pkg/controller/common/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ import (
"github.com/openshift/machine-config-operator/test/helpers"
)

func TestTranspileCoreOSConfig(t *testing.T) {
func TestConvertButaneFragmentsToIgnition(t *testing.T) {
// Test the null case
config, err := ConvertButaneFragmentsToIgnition([]string{}, []string{})
require.NoError(t, err)
if report := validate3.ValidateWithContext(config, nil); report.IsFatal() {
t.Fatalf("invalid ignition V3 config found: %v", report)
}
require.Equal(t, len(config.Storage.Files), 0)

kubeletConfig := `
mode: 0644
path: "/etc/kubernetes/kubelet.conf"
Expand Down Expand Up @@ -57,16 +65,43 @@ dropins:
[Unit]
ConditionPathExists=/enoent
`
config, err := TranspileCoreOSConfigToIgn([]string{kubeletConfig, auditConfig}, []string{kubeletService, crioDropin, dockerDropin})
config, err = ConvertButaneFragmentsToIgnition([]string{kubeletConfig, auditConfig}, []string{kubeletService, crioDropin, dockerDropin})
require.Nil(t, err)
if report := validate3.ValidateWithContext(config, nil); report.IsFatal() {
t.Fatalf("invalid ignition V3 config found: %v", report)
}
require.Equal(t, len(config.Storage.Files), 2)
require.True(t, strings.HasPrefix(*config.Storage.Files[0].Contents.Source, "data:,kind%3A%20KubeletConfiguration%0Aapi"))
kubeconfig := config.Storage.Files[1].Contents
require.True(t, strings.HasPrefix(*kubeconfig.Source, "data:,kind%3A%20KubeletConfiguration%0Aapi"))
buf, err := DecodeIgnitionFileContents(kubeconfig.Source, kubeconfig.Compression)
require.NoError(t, err)
require.Contains(t, string(buf), "kind: KubeletConfiguration")
require.Equal(t, len(config.Systemd.Units), 3)
}

func TestDecodeIgnitionFileContents(t *testing.T) {
mode := 0644
compression := "gzip"
// echo hello world | gzip | base64
buf := "data:text/plain;base64,H4sIAEArMmIAA8tIzcnJVyjPL8pJ4QIALTsIrwwAAAA="
f := ign3types.File{
Node: ign3types.Node{
Path: "/etc/someconfig",
},
FileEmbedded1: ign3types.FileEmbedded1{
Mode: &mode,
Contents: ign3types.Resource{
Source: &buf,
Compression: &compression,
},
},
}

extractedbuf, err := DecodeIgnitionFileContents(f.Contents.Source, f.Contents.Compression)
require.NoError(t, err)
require.Equal(t, "hello world\n", string(extractedbuf))
}

func TestValidateIgnition(t *testing.T) {
// Test that an empty ignition config returns nil
testIgn2Config := ign2types.Config{}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/template/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ func generateMachineConfigForName(config *RenderConfig, role, name, templateDir,
return vs
}

ignCfg, err := ctrlcommon.TranspileCoreOSConfigToIgn(keySortVals(files), keySortVals(units))
ignCfg, err := ctrlcommon.ConvertButaneFragmentsToIgnition(keySortVals(files), keySortVals(units))
if err != nil {
return nil, fmt.Errorf("error transpiling CoreOS config to Ignition config: %v", err)
return nil, fmt.Errorf("error converting Butane fragments to Ignition config: %w", err)
}
mcfg, err := ctrlcommon.MachineConfigFromIgnConfig(role, name, ignCfg)
if err != nil {
Expand Down
9 changes: 0 additions & 9 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,6 @@ func appendFileToIgnition(conf *igntypes.Config, outPath, contents string) error
return nil
}

func getDecodedContent(inp string) (string, error) {
d, err := dataurl.DecodeString(inp)
if err != nil {
return "", err
}

return string(d.Data), nil
}

func getEncodedContent(inp string) string {
return (&url.URL{
Scheme: "data",
Expand Down
14 changes: 1 addition & 13 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ var (
testKubeConfig = fmt.Sprintf("%s/kubeconfig", testDir)
)

func TestStringDecode(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if I missed it but I don't see anything testing DecodeIgnitionFileContents. Would it make sense to move this test to helpers_test.go?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added one, though this function is definitely tested indirectly in a bunch of other unit tests.

inp := "data:,Hello%2C%20world!"
exp := "Hello, world!"
dec, err := getDecodedContent(inp)
if err != nil {
t.Errorf("expected error to be nil, received: %v", err)
}
if exp != dec {
t.Errorf("string decode failed. exp: %s, got: %s", exp, dec)
}
}

func TestStringEncode(t *testing.T) {
inp := "Hello, world!"
exp := "data:,Hello%2C%20world!"
Expand Down Expand Up @@ -315,7 +303,7 @@ func TestClusterServer(t *testing.T) {
}
foundEncapsulated = true
encapMc := new(mcfgv1.MachineConfig)
contents, err := getDecodedContent(*f.Contents.Source)
contents, err := ctrlcommon.DecodeIgnitionFileContents(f.Contents.Source, f.Contents.Compression)
assert.Nil(t, err)
err = yaml.Unmarshal([]byte(contents), encapMc)
assert.Nil(t, err)
Expand Down
1 change: 0 additions & 1 deletion templates/common/_base/files/etc-mco-proxy.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
filesystem: "root"
mode: 0644
path: "/etc/mco/proxy.env"
contents:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
filesystem: "root"
mode: 0644
path: "/etc/systemd/system.conf.d/10-default-env-godebug.conf"
contents:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
filesystem: "root"
mode: 0744
path: "/etc/NetworkManager/dispatcher.d/99-vsphere-disable-tx-udp-tnl"
contents:
Expand Down
2 changes: 1 addition & 1 deletion templates/common/on-prem/files/keepalived.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ contents:
image: {{ .Images.baremetalRuntimeCfgImage }}
env:
- name: ENABLE_UNICAST
value: "{{ onPremPlatformKeepalivedEnableUnicast . }}"
value: "yes"
- name: IS_BOOTSTRAP
value: "no"
command:
Expand Down
Loading