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 10, 2019
1 parent 5a28cac commit 7ef277c
Show file tree
Hide file tree
Showing 20 changed files with 48 additions and 627 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
21 changes: 0 additions & 21 deletions doc/migrating-configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,27 +170,6 @@ The `ignition` section has gained a new section named `security`, which can be u
}
```

### networkd dropins

With the release of systemd v232, networkd dropins are now supported as a means of configuring existing networkd units. The `networkd` section has gained a `dropins` field to reflect this.

```json ignition
{
"ignition": {
"version": "2.2.0-experimental"
},
"networkd": {
"units": [{
"name": "zz-default.network",
"dropins": [{
"name": "disable-dhcp.conf",
"contents": "data:,%5BNetwork%5D%0ADHCP%3Dno"
}]
}]
}
}
```

## From Version 2.0.0 to 2.1.0

There are not any breaking changes between versions 2.0.0 and versions 2.1.0 of the configuration specification. Any valid 2.0.0 configuration can be updated to a 2.1.0 configuration by simply changing the version string in the config.
Expand Down
Loading

0 comments on commit 7ef277c

Please sign in to comment.