Skip to content

Commit

Permalink
fetch-offline: add recognition for ClevisCustom's NeedsNetwork field
Browse files Browse the repository at this point in the history
Resolves #1473, add a check for attributes that trigger networking
to be inclusive of `ClevisCustom`'s `NeedNetwork` field.
  • Loading branch information
prestist committed Dec 7, 2022
1 parent c26304c commit ddc873f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/release-notes.md
Expand Up @@ -29,6 +29,7 @@ nav_order: 9
- Clarify spec docs for `files`/`directories`/`links` `group` fields
- Document that `user`/`group` fields aren't applied to hard links
- Fix version string in ignition-validate release container
- Request network when custom Clevis config has `needsNetwork` set


## Ignition 2.14.0 (12-May-2022)
Expand Down
6 changes: 6 additions & 0 deletions internal/exec/stages/fetch_offline/fetch-offline.go
Expand Up @@ -84,13 +84,19 @@ func configNeedsNet(cfg *types.Config) (bool, error) {
func configNeedsNetRecurse(v reflect.Value) (bool, error) {
t := v.Type()
k := t.Kind()

switch {
case cfgutil.IsPrimitive(k):
return false, nil
case t == reflect.TypeOf(types.Resource{}):
return sourceNeedsNet(v.Interface().(types.Resource))
case t == reflect.TypeOf(types.Tang{}):
return true, nil
case t == reflect.TypeOf(types.ClevisCustom{}):
cc := v.Interface().(types.ClevisCustom)
if cc.NeedsNetwork != nil {
return *cc.NeedsNetwork, nil
}
case k == reflect.Struct:
for i := 0; i < v.NumField(); i += 1 {
if needsNet, err := configNeedsNetRecurse(v.Field(i)); err != nil {
Expand Down
32 changes: 32 additions & 0 deletions internal/exec/stages/fetch_offline/fetch_offline_test.go
Expand Up @@ -31,6 +31,22 @@ func checkNeedsNet(t *testing.T, cfg *types.Config) bool {

func TestConfigNotNeedsNet(t *testing.T) {
tests := []types.Config{
// Test ClevisCustom NeedsNetwork set to false
{
Storage: types.Storage{
Luks: []types.Luks{
{
Name: "foobar",
Device: util.StrToPtr("foo"),
Clevis: types.Clevis{
Custom: types.ClevisCustom{
NeedsNetwork: util.BoolToPtr(false),
},
},
},
},
},
},
// Source with no URL
{
Ignition: types.Ignition{
Expand Down Expand Up @@ -94,6 +110,22 @@ func TestConfigNeedsNet(t *testing.T) {
},
},
},
// CustomClevis with NeedsNetwork set to true
{
Storage: types.Storage{
Luks: []types.Luks{
{
Name: "foobar",
Device: util.StrToPtr("foo"),
Clevis: types.Clevis{
Custom: types.ClevisCustom{
NeedsNetwork: util.BoolToPtr(true),
},
},
},
},
},
},
}

for i, test := range tests {
Expand Down

0 comments on commit ddc873f

Please sign in to comment.