-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from lstocchi/i124
ignition: add support for ignition config file
- Loading branch information
Showing
10 changed files
with
266 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"net" | ||
"net/http" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestStartIgnitionProvisionerServer(t *testing.T) { | ||
socketPath := "virtiovsock" | ||
defer os.Remove(socketPath) | ||
|
||
ignitionData := []byte("ignition configuration") | ||
ignitionReader := bytes.NewReader(ignitionData) | ||
|
||
// Start the server using the socket so that it can returns the ignition data | ||
go func() { | ||
err := startIgnitionProvisionerServer(ignitionReader, socketPath) | ||
require.NoError(t, err) | ||
}() | ||
|
||
// Make a request to the server | ||
client := http.Client{ | ||
Transport: &http.Transport{ | ||
Dial: func(_, _ string) (net.Conn, error) { | ||
return net.Dial("unix", socketPath) | ||
}, | ||
}, | ||
} | ||
resp, err := client.Get("http://unix://" + socketPath) | ||
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
|
||
// Verify the response from the server is actually the ignition data | ||
body, err := io.ReadAll(resp.Body) | ||
require.NoError(t, err) | ||
assert.Equal(t, ignitionData, body) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Ignition | ||
|
||
Ignition uses a JSON configuration file to define the desired changes. The format of this config is specified in detail [here](https://coreos.github.io/ignition/specs/), and its [MIME type](http://www.iana.org/assignments/media-types/application/vnd.coreos.ignition+json) is registered with IANA. | ||
|
||
`myconfig.json` file provides an example of configuration that adds a new `testuser`, creates a new file to `/etc/myapp` with the content listed in the same `files` section and add a systemd unit drop-in to modify the existing service `systemd-journald` and sets its environment variable SYSTEMD_LOG_LEVEL to debug. | ||
|
||
### Examples | ||
|
||
More examples can be found at https://coreos.github.io/ignition/examples/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"ignition": { | ||
"version": "3.0.0" | ||
}, | ||
"passwd": { | ||
"users": [ | ||
{ | ||
"name": "testuser", | ||
"sshAuthorizedKeys": [ | ||
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO43Z9aRPvvj1zMib/Hh4oWX+MuOPXdFChFMaWfishLj" | ||
] | ||
} | ||
] | ||
}, | ||
"storage": { | ||
"files": [{ | ||
"path": "/etc/someconfig", | ||
"mode": 420, | ||
"contents": { "source": "data:,example%20file%0A" } | ||
}] | ||
}, | ||
"systemd": { | ||
"units": [{ | ||
"name": "systemd-journald.service", | ||
"dropins": [{ | ||
"name": "debug.conf", | ||
"contents": "[Service]\nEnvironment=SYSTEMD_LOG_LEVEL=debug" | ||
}] | ||
}] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAddIgnitionFile_MultipleOptions(t *testing.T) { | ||
vm := &VirtualMachine{} | ||
err := vm.AddIgnitionFileFromCmdLine("file1,file2") | ||
assert.EqualError(t, err, "ignition only accept one option in command line argument") | ||
} | ||
|
||
func TestAddIgnitionFile_OneOption(t *testing.T) { | ||
vm := &VirtualMachine{} | ||
err := vm.AddIgnitionFileFromCmdLine("file1") | ||
require.NoError(t, err) | ||
assert.Len(t, vm.Devices, 1) | ||
assert.Equal(t, uint32(ignitionVsockPort), vm.Devices[0].(*VirtioVsock).Port) | ||
assert.Equal(t, "file1", vm.Ignition.ConfigPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters