k0sproject/k0sctl

Reordering apply `UploadFiles()` phase order after `RunHooks` breaks some functionality

cr1cr1 opened this issue · 4 comments

This commit changed the order of the phases, more precisely, &phase.UploadFiles{}, is now after &phase.RunHooks{Stage: "before", Action: "apply"},.

d33fa10#diff-5f7e9ac62ed6d2dc91ebd4ba12f19a0ab34b78a72d2ece10ab3dba6186e15a12R55

I assume it was not thought to be used in this way, but I really took advantage of this, by having some scripts and config files uploaded and then executed by the before hooks, prior to k0s installation. In my case, those scripts would prepare the node with some configuration I need like some software packages, LAN IPs, firewall, hostnames, ntp, etc.

This really eliminated the need to run some other tool (like one based on rig to prepare the boxes in advance, instead k0sctl would do it for me quite nicely.

Is there a benefit of moving UploadFiles after RunHooks{Stage: "before" and more importantly, can UploadFiles be left ahead of RunHooks{Stage: "before" ?

kke commented

I'm not sure why it moved. Having it after UploadFiles would make more sense because you can then do something to the files that were uploaded.

Yes, you could to something to the files (changing perms), including running them if they are scripts :)

I'm not sure why it moved. Having it after UploadFiles would make more sense because you can then do something to the files that were uploaded.

I agree. A typical use case could be to execute a script/executable that's been uploaded before. One thing I noticed that you cannot upload files to non-existent directories, which is a bit of a chicken-and-egg problem, because you'd need the RunHooks phase to create directories first.

I use the files upload feature to upload files including subdirs starting with the root in the destination:

      files: &files
        - name: os-files
          src: ../os/
          dstDir: /
          perm: 0644

This will create all the subdirectories and update the files as needed.

image

All the files in that tree are synced to the targets. Then, in the "before" hooks I execute os-debian-setup.sh that does all the prepping of the node.