Documentation ¶
Index ¶
- func AppendToken(token string, tokensFile string, chownGroup string) error
- func FileExists(path string) bool
- func GenerateCSRConf(extraSANs []string) ([]byte, error)
- func GetRemoteHost(lookupIP func(string) ([]net.IP, error), hostname string, remoteAddress string) string
- func IsValidToken(token string, tokensFile string) (isValidToken, hasTTL bool)
- func NewRandomString(letters RandomCharacters, length int) string
- func ParseArgumentLine(line string) (key string, value string)
- func ReadFile(path string) (string, error)
- func RemoveToken(token string, tokensFile string, chownGroup string) error
- func RunCommand(ctx context.Context, command ...string) error
- func SetupPermissions(path string, chownGroup string)
- type RandomCharacters
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendToken ¶
AppendToken appends a token to a file. Token files contain a single token in each line.
func FileExists ¶
FileExists returns true if the specified path exists.
func GenerateCSRConf ¶
GenerateCSRConf generates a csr.conf.template file for the MicroK8s node. extraSANs are a list of extra Subject Alternate Names to be added to the certificates.
func GetRemoteHost ¶
func GetRemoteHost(lookupIP func(string) ([]net.IP, error), hostname string, remoteAddress string) string
GetRemoteHost returns the hostname that should be used for communicating with the joining node. The endpoint is either the hostname (if it can be resolved), or the remote IP address, as read from the HTTP request. lookupIP is net.LookupIP. If the hostname resolves to a different IP than remoteAddress, then the IP from remoteAddress is returned.
func IsValidToken ¶
IsValidToken checks tokensFile to see if token is valid. A token is valid when it appears in the tokensFile. A token may optionally have a TTL, which is appended at the end of the token. For example, the tokens file may look like this:
token1 token2|35616531876
In the file above, token1 is a valid token. token2 is valid until the unix timestamp 35616531876.
func NewRandomString ¶
func NewRandomString(letters RandomCharacters, length int) string
NewRandomString creates a new cryptographically safe random string from a source of characters.
func ParseArgumentLine ¶
ParseArgumentLine parses a command-line argument from a single line. The returned key includes any dash prefixes.
func RemoveToken ¶
RemoveToken removes a token from a tokens file, if it exists. RemoveToken will not return an error if the token does not exist. RemoveToken will only the first occurence of the token, if it exists multiple times in the tokens file. RemoveToken will return an error if it fails to read or write the tokens file.
func RunCommand ¶
RunCommand executes a command with a given context. RunCommand returns nil if the command completes successfully and the exit code is 0.
func SetupPermissions ¶
SetupPermissions attempts to set file permissions to 0660 and group to `microk8s` for a given file. SetupPermissions will knowingly ignore any errors, as failing to update permissions will only occur in extraordinary situations, and will never break the MicroK8s cluster.
Types ¶
type RandomCharacters ¶
type RandomCharacters string
RandomCharacters is used as a source for NewRandomString.
const ( // Alpha is lower-case and upper-case ASCII characters, as well as digits 0-9. Alpha RandomCharacters = "abcdefghijklmnopqrstuvqxyzABCDEFGHIJKLMONPQRSTUVWXYZ1234567890" // Digits is digits 0-9. Digits RandomCharacters = "0123456789" )