talos/pkg/filetree/chown.go
Andrey Smirnov a2aea97263
fix: write etcd PKI files in a controller
Instead of writing PKI "once" around the startup time, keep writing PKI
files as the certificates get updated. `etcd` is able to reload
certificates, so we should keep updating them e.g. if the hostname/IPs
change over time.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2022-07-21 18:37:45 +04:00

28 lines
691 B
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package filetree
import (
"io/fs"
"os"
"path/filepath"
"syscall"
)
// ChownRecursive changes file ownership recursively from the specified root.
func ChownRecursive(root string, uid, gid uint32) error {
return filepath.Walk(root, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
if info.Sys().(*syscall.Stat_t).Uid != uid || info.Sys().(*syscall.Stat_t).Gid != gid {
return os.Chown(path, int(uid), int(gid))
}
return nil
})
}