Skip to content

Commit

Permalink
*: drop networkd section
Browse files Browse the repository at this point in the history
Drop the networkd section from spec 3.0. networkd is not as widespread
as systemd and everything done in this section can be accomplished in
the files section.

Fixes coreos#638
  • Loading branch information
arithx committed Jan 11, 2019
1 parent 5a28cac commit e7e7aa2
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 606 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ignition

Ignition is the utility used by CoreOS Container Linux to manipulate disks during the initramfs. This includes partitioning disks, formatting partitions, writing files (regular files, systemd units, networkd units, etc.), and configuring users. On first boot, Ignition reads its configuration from a source of truth (remote URL, network metadata service, hypervisor bridge, etc.) and applies the configuration.
Ignition is the utility used by CoreOS Container Linux to manipulate disks during the initramfs. This includes partitioning disks, formatting partitions, writing files (regular files, systemd units, etc.), and configuring users. On first boot, Ignition reads its configuration from a source of truth (remote URL, network metadata service, hypervisor bridge, etc.) and applies the configuration.

Ignition has two main development branches: master and spec2x. This is the master branch which is for Ignition included in Red Hat CoreOS and Fedora CoreOS. For Ignition development for Container Linux see the [spec2x](https://github.com/coreos/ignition/tree/spec2x) branch.

Expand Down
8 changes: 3 additions & 5 deletions config/shared/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ var (
ErrPasswdCreateAndSystem = errors.New("cannot use both the create object and the user-level system field")
ErrPasswdCreateAndUID = errors.New("cannot use both the create object and the user-level uid field")

// Systemd and Networkd section errors
ErrInvalidSystemdExt = errors.New("invalid systemd unit extension")
ErrInvalidSystemdDropinExt = errors.New("invalid systemd drop-in extension")
ErrInvalidNetworkdExt = errors.New("invalid networkd unit extension")
ErrInvalidNetworkdDropinExt = errors.New("invalid networkd drop-in extension")
// Systemd section errors
ErrInvalidSystemdExt = errors.New("invalid systemd unit extension")
ErrInvalidSystemdDropinExt = errors.New("invalid systemd drop-in extension")

// Misc errors
ErrInvalidScheme = errors.New("invalid url scheme")
Expand Down
40 changes: 12 additions & 28 deletions config/v3_0_experimental/types/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type CaReference struct {

type Config struct {
Ignition Ignition `json:"ignition"`
Networkd Networkd `json:"networkd,omitempty"`
Passwd Passwd `json:"passwd,omitempty"`
Storage Storage `json:"storage,omitempty"`
Systemd Systemd `json:"systemd,omitempty"`
Expand Down Expand Up @@ -44,6 +43,11 @@ type Disk struct {
WipeTable bool `json:"wipeTable,omitempty"`
}

type Dropin struct {
Contents string `json:"contents,omitempty"`
Name string `json:"name"`
}

type File struct {
Node
FileEmbedded1
Expand Down Expand Up @@ -103,21 +107,6 @@ type Mount struct {

type MountOption string

type Networkd struct {
Units []Networkdunit `json:"units,omitempty"`
}

type NetworkdDropin struct {
Contents string `json:"contents,omitempty"`
Name string `json:"name"`
}

type Networkdunit struct {
Contents string `json:"contents,omitempty"`
Dropins []NetworkdDropin `json:"dropins,omitempty"`
Name string `json:"name"`
}

type Node struct {
Filesystem string `json:"filesystem"`
Group *NodeGroup `json:"group,omitempty"`
Expand Down Expand Up @@ -191,7 +180,7 @@ type RaidOption string
type SSHAuthorizedKey string

type Security struct {
TLS `json:"tls,omitempty"`
TLS TLS `json:"tls,omitempty"`
}

type Storage struct {
Expand All @@ -207,11 +196,6 @@ type Systemd struct {
Units []Unit `json:"units,omitempty"`
}

type SystemdDropin struct {
Contents string `json:"contents,omitempty"`
Name string `json:"name"`
}

type TLS struct {
CertificateAuthorities []CaReference `json:"certificateAuthorities,omitempty"`
}
Expand All @@ -222,12 +206,12 @@ type Timeouts struct {
}

type Unit struct {
Contents string `json:"contents,omitempty"`
Dropins []SystemdDropin `json:"dropins,omitempty"`
Enable bool `json:"enable,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Mask bool `json:"mask,omitempty"`
Name string `json:"name"`
Contents string `json:"contents,omitempty"`
Dropins []Dropin `json:"dropins,omitempty"`
Enable bool `json:"enable,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Mask bool `json:"mask,omitempty"`
Name string `json:"name"`
}

type Usercreate struct {
Expand Down
46 changes: 1 addition & 45 deletions config/v3_0_experimental/types/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (u Unit) ValidateName() report.Report {
return r
}

func (d SystemdDropin) Validate() report.Report {
func (d Dropin) Validate() report.Report {
r := report.Report{}

if _, err := validateUnitContent(d.Contents); err != nil {
Expand All @@ -77,50 +77,6 @@ func (d SystemdDropin) Validate() report.Report {
return r
}

func (u Networkdunit) Validate() report.Report {
r := report.Report{}

if _, err := validateUnitContent(u.Contents); err != nil {
r.Add(report.Entry{
Message: err.Error(),
Kind: report.EntryError,
})
}

switch path.Ext(u.Name) {
case ".link", ".netdev", ".network":
default:
r.Add(report.Entry{
Message: errors.ErrInvalidNetworkdExt.Error(),
Kind: report.EntryError,
})
}

return r
}

func (d NetworkdDropin) Validate() report.Report {
r := report.Report{}

if _, err := validateUnitContent(d.Contents); err != nil {
r.Add(report.Entry{
Message: err.Error(),
Kind: report.EntryError,
})
}

switch path.Ext(d.Name) {
case ".conf":
default:
r.Add(report.Entry{
Message: errors.ErrInvalidNetworkdDropinExt.Error(),
Kind: report.EntryError,
})
}

return r
}

func validateUnitContent(content string) ([]*unit.UnitOption, error) {
c := strings.NewReader(content)
opts, err := unit.Deserialize(c)
Expand Down
106 changes: 4 additions & 102 deletions config/v3_0_experimental/types/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestSystemdUnitValidateContents(t *testing.T) {
out: out{err: fmt.Errorf("invalid unit content: unable to find end of section")},
},
{
in: in{unit: Unit{Name: "test.service", Contents: "", Dropins: []SystemdDropin{{}}}},
in: in{unit: Unit{Name: "test.service", Contents: "", Dropins: []Dropin{{}}}},
out: out{err: nil},
},
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestSystemdUnitValidateName(t *testing.T) {

func TestSystemdUnitDropInValidate(t *testing.T) {
type in struct {
unit SystemdDropin
unit Dropin
}
type out struct {
err error
Expand All @@ -104,109 +104,11 @@ func TestSystemdUnitDropInValidate(t *testing.T) {
out out
}{
{
in: in{unit: SystemdDropin{Name: "test.conf", Contents: "[Foo]\nQux=Bar"}},
in: in{unit: Dropin{Name: "test.conf", Contents: "[Foo]\nQux=Bar"}},
out: out{err: nil},
},
{
in: in{unit: SystemdDropin{Name: "test.conf", Contents: "[Foo"}},
out: out{err: fmt.Errorf("invalid unit content: unable to find end of section")},
},
}

for i, test := range tests {
err := test.in.unit.Validate()
if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), err) {
t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
}
}
}

func TestNetworkdUnitNameValidate(t *testing.T) {
type in struct {
unit string
}
type out struct {
err error
}

tests := []struct {
in in
out out
}{
{
in: in{unit: "test.network"},
out: out{err: nil},
},
{
in: in{unit: "test.link"},
out: out{err: nil},
},
{
in: in{unit: "test.netdev"},
out: out{err: nil},
},
{
in: in{unit: "test.blah"},
out: out{err: errors.ErrInvalidNetworkdExt},
},
}

for i, test := range tests {
err := Networkdunit{Name: test.in.unit, Contents: "[Foo]\nQux=Bar"}.Validate()
if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), err) {
t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
}
}
}

func TestNetworkdUnitValidate(t *testing.T) {
type in struct {
unit Networkdunit
}
type out struct {
err error
}

tests := []struct {
in in
out out
}{
{
in: in{unit: Networkdunit{Name: "test.network", Contents: "[Foo]\nQux=Bar"}},
out: out{err: nil},
},
{
in: in{unit: Networkdunit{Name: "test.network", Contents: "[Foo"}},
out: out{err: fmt.Errorf("invalid unit content: unable to find end of section")},
},
}

for i, test := range tests {
err := test.in.unit.Validate()
if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), err) {
t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
}
}
}

func TestNetworkdUnitDropInValidate(t *testing.T) {
type in struct {
unit NetworkdDropin
}
type out struct {
err error
}

tests := []struct {
in in
out out
}{
{
in: in{unit: NetworkdDropin{Name: "test.conf", Contents: "[Foo]\nQux=Bar"}},
out: out{err: nil},
},
{
in: in{unit: NetworkdDropin{Name: "test.conf", Contents: "[Foo"}},
in: in{unit: Dropin{Name: "test.conf", Contents: "[Foo"}},
out: out{err: fmt.Errorf("invalid unit content: unable to find end of section")},
},
}
Expand Down
7 changes: 0 additions & 7 deletions doc/configuration-v3_0-experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ The Ignition configuration is a JSON document conforming to the following specif
* **_dropins_** (list of objects): the list of drop-ins for the unit.
* **name** (string): the name of the drop-in. This must be suffixed with ".conf".
* **_contents_** (string): the contents of the drop-in.
* **_networkd_** (object): describes the desired state of the networkd files.
* **_units_** (list of objects): the list of networkd files.
* **name** (string): the name of the file. This must be suffixed with a valid unit type (e.g. "00-eth0.network").
* **_contents_** (string): the contents of the networkd file.
* **_dropins_** (list of objects): the list of drop-ins for the unit.
* **name** (string): the name of the drop-in. This must be suffixed with ".conf".
* **_contents_** (string): the contents of the drop-in.
* **_passwd_** (object): describes the desired additions to the passwd database.
* **_users_** (list of objects): the list of accounts that shall exist.
* **name** (string): the username for the account.
Expand Down
6 changes: 3 additions & 3 deletions doc/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ WantedBy=multi-user.target

### Modify Services

This config will add a [systemd unit drop-in](https://coreos.com/os/docs/latest/using-systemd-drop-in-units.html) to modify the existing service `systemd-networkd` and sets its environment variable `SYSTEMD_LOG_LEVEL` to `debug`.
This config will add a [systemd unit drop-in](https://coreos.com/os/docs/latest/using-systemd-drop-in-units.html) to modify the existing service `systemd-journald` and sets its environment variable `SYSTEMD_LOG_LEVEL` to `debug`.

```json ignition
{
"ignition": { "version": "2.2.0" },
"systemd": {
"units": [{
"name": "systemd-networkd.service",
"name": "systemd-journald.service",
"dropins": [{
"name": "debug.conf",
"contents": "[Service]\nEnvironment=SYSTEMD_LOG_LEVEL=debug"
Expand All @@ -51,7 +51,7 @@ This config will add a [systemd unit drop-in](https://coreos.com/os/docs/latest/
}
```

#### systemd-networkd.service.d/debug.conf
#### systemd-journald.service.d/debug.conf

```INI
[Service]
Expand Down
32 changes: 4 additions & 28 deletions internal/config/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,6 @@ func Translate(old from.Config) types.Config {
}
return res
}
translateNetworkdDropinSlice := func(old []from.NetworkdDropin) []types.NetworkdDropin {
var res []types.NetworkdDropin
for _, x := range old {
res = append(res, types.NetworkdDropin{
Contents: x.Contents,
Name: x.Name,
})
}
return res
}
translateNetworkdUnitSlice := func(old []from.Networkdunit) []types.Networkdunit {
var res []types.Networkdunit
for _, u := range old {
res = append(res, types.Networkdunit{
Contents: u.Contents,
Name: u.Name,
Dropins: translateNetworkdDropinSlice(u.Dropins),
})
}
return res
}
translatePasswdGroupSlice := func(old []from.PasswdGroup) []types.PasswdGroup {
var res []types.PasswdGroup
for _, g := range old {
Expand Down Expand Up @@ -334,10 +313,10 @@ func Translate(old from.Config) types.Config {
}
return res
}
translateSystemdDropinSlice := func(old []from.SystemdDropin) []types.SystemdDropin {
var res []types.SystemdDropin
translateDropinSlice := func(old []from.Dropin) []types.Dropin {
var res []types.Dropin
for _, x := range old {
res = append(res, types.SystemdDropin{
res = append(res, types.Dropin{
Contents: x.Contents,
Name: x.Name,
})
Expand All @@ -349,7 +328,7 @@ func Translate(old from.Config) types.Config {
for _, x := range old {
res = append(res, types.Unit{
Contents: x.Contents,
Dropins: translateSystemdDropinSlice(x.Dropins),
Dropins: translateDropinSlice(x.Dropins),
Enable: x.Enable,
Enabled: x.Enabled,
Mask: x.Mask,
Expand All @@ -375,9 +354,6 @@ func Translate(old from.Config) types.Config {
},
},
},
Networkd: types.Networkd{
Units: translateNetworkdUnitSlice(old.Networkd.Units),
},
Passwd: types.Passwd{
Groups: translatePasswdGroupSlice(old.Passwd.Groups),
Users: translatePasswdUserSlice(old.Passwd.Users),
Expand Down
Loading

0 comments on commit e7e7aa2

Please sign in to comment.