Skip to content

translate: convert deprecated networkd to files#6

Merged
tormath1 merged 3 commits intomainfrom
tormath1/networkd
May 20, 2022
Merged

translate: convert deprecated networkd to files#6
tormath1 merged 3 commits intomainfrom
tormath1/networkd

Conversation

@tormath1
Copy link
Copy Markdown
Collaborator

@tormath1 tormath1 commented May 19, 2022

In this PR, we convert this config:

{
  "ignition": {
    "version": "2.3.0"
  },
  "networkd": {
    "units": [
      {
        "name": "00-eth.network",
        "dropins": [
          {
            "name": "my-conf.conf",
            "contents": "[Match]\nName=eth*\n\n[Network]\nBond=bond0"
          }
        ],
        "contents": "[NetDev]\nName=bond0\nKind=bond"
      }
    ]
  }
}

to this config:

{
  "ignition": {
    "version": "3.1.0"
  },
  "storage": {
    "files": [
      {
        "overwrite": true,
        "path": "/etc/systemd/network/00-eth.network",
        "contents": {
          "source": "data:,%5BNetDev%5D%0AName%3Dbond0%0AKind%3Dbond"
        },
        "mode": 420
      },
      {
        "overwrite": true,
        "path": "/etc/systemd/network/00-eth.network.d/my-conf.conf",
        "contents": {
          "source": "data:,%5BMatch%5D%0AName%3Deth%2A%0A%0A%5BNetwork%5D%0ABond%3Dbond0"
        },
        "mode": 420
      }
    ]
  }
}

How to use

Locally:

go build ./internal/main.go
./main < config.json | jq

Testing done

About to add some network ignition tests and to kick-off a CI.

Note for reviewers

@tormath1 tormath1 force-pushed the tormath1/networkd branch from 136c276 to 7127448 Compare May 19, 2022 11:03
@tormath1 tormath1 requested a review from a team May 19, 2022 11:20
@tormath1 tormath1 self-assigned this May 19, 2022
},
}

file.Node.Path = path.Join(m["root"], filepath.Join("/etc/systemd/network", string(u.Name)+".d", d.Name))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the reason for mixing path.Join and filepath.Join? Maybe it could be also:

Suggested change
file.Node.Path = path.Join(m["root"], filepath.Join("/etc/systemd/network", string(u.Name)+".d", d.Name))
file.Node.Path = filepath.Join(m["root"], "/etc/systemd/network", string(u.Name)+".d", d.Name)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

aha - it seems I was not really awake this morning. Thanks for the heads-up.

}
// path /etc/systemd/network is hardcoded in Ignition2.x codebase.
// TODO: customize this path at compilation time.
file.Node.Path = path.Join(m["root"], filepath.Join("/etc/systemd/network", u.Name))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here too - mixing of path.Join and filepath.Join.

}
// path /etc/systemd/network is hardcoded in Ignition2.x codebase.
// TODO: customize this path at compilation time.
file.Node.Path = path.Join(m["root"], filepath.Join("/etc/systemd/network", u.Name))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same. Also, lovely copy-pasta. But I see that there is no package for common functionality.

},
}

file.Node.Path = path.Join(m["root"], filepath.Join("/etc/systemd/network", string(u.Name)+".d", d.Name))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same.

tormath1 added 3 commits May 20, 2022 10:14
with Ignition3, `networkd` section does not exist anymore. As best
effort, we try to convert `networkd` section to `files` section.

Files will be located in `/etc/systemd/network` as it was currently done
with Ignition2.

Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Signed-off-by: Mathieu Tortuyaux <mtortuyaux@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants