Skip to content

WIP: Support externally defined machine files.#425

Open
mrueg wants to merge 1 commit intobudimanjojo:masterfrom
mrueg:read-from-file
Open

WIP: Support externally defined machine files.#425
mrueg wants to merge 1 commit intobudimanjojo:masterfrom
mrueg:read-from-file

Conversation

@mrueg
Copy link

@mrueg mrueg commented Apr 21, 2024

This is a first attempt to support externally defined machine files as well.

What the code does is:

  • reads machineFiles key from config into machineFileConfigs
    for all items in this slice:
  • figures out if this is a proper machineFile type (a map) or a pointer to an external file (string starts with "@")
  • if it's a map, read it and add it to the actual machineFiles key in the struct
  • if it's a string, find the file, and add them to a list of additionalMachineFiles that still need to be read.

for all items in the list of additionalMachineFiles

  • check if it's a machineFile type (a map), read it and add it to the actual machineFiles key

Things that need to be checked:

  • Tests are failing
  • Figure out what the difference between LoadAndValidateFromFile and NewFromByte/NewFromFile is and why LoadAndValidateFromFile is not used in the tests/elsewhere.

@budimanjojo
Copy link
Owner

Thanks for the PR! ❤️

To answer the question in the checkbox, LoadAndValidateFromFile is calling NewFromByte, then substitute the all the ${} with the environment variables, then validate all the keys defined before returning the TalhelperConfig.

I'll have a look into your branch when I have time.

@budimanjojo
Copy link
Owner

Looking at the code, I think it's better to have custom UnmarshalYAML method for MachineFile like so: https://github.com/siderolabs/talos/blob/ccdb4c8b10450aa7fb6c32b0559bda73746a03ed/pkg/machinery/config/types/v1alpha1/v1alpha1_types.go#L840

I'm thinking about something like this in the ./pkg/config/config.go:

type NodeConfigs struct {
    MachineFiles   []MachineFileWrapper  `yaml:"machineFiles,omitempty"
    ....
}

type MachineFileWrapper struct  {
    MachineFile *v1alpha1.MachineFile
}

func (mfw *MachineFileWrapper) UnmarshalYAML(unmarshal func(any) error) error {
    // do stuffs here that returns mfw.MachineFile with type v1alpha1.MachineFile
}

So everything in the code can just be changed from MachineFiles to MachineFiles.MachineFileWrapper, but don't know how to do this 🤣

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