util

package
v0.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Copyright © 2020 The k3d Author(s)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2020 The k3d Author(s)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2020 The k3d Author(s)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2020 The k3d Author(s)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2020 The k3d Author(s)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2020 The k3d Author(s)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright © 2020 The k3d Author(s)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	EdacFolderPath = "/sys/devices/system/edac"
	MemInfoPath    = "/proc/meminfo"
)

Variables

This section is empty.

Functions

func CheckExitFile added in v0.2.3

func CheckExitFile(file string) (err error)

CheckExitFile

func CheckExitValueFile added in v0.2.3

func CheckExitValueFile(clusterName string, addonsName string) (file string, err error)

CheckExitValueFile

func CheckСredentials added in v0.5.0

func CheckСredentials(clusterName string, provider string) (ok bool, secretFile string)

CheckСredentials - проверяем естьли файл с credentials

func CreateVersionStr

func CreateVersionStr(k3sVersion, k3sChannel string) string

CreateVersionStr Create install string kubernetesVersion or k3s channel

func ExpandPath

func ExpandPath(path string) string

ExpandPath

func Find

func Find(slice []string, val string) (string, bool)

Find takes a slice and looks for an element in it. If found it will return it's key, otherwise it will return -1 and a bool of false.

func FormatIP

func FormatIP(IP string) (string, error)

FormatIP - trim spaces and format IP

IP - the provided IP

string - return "" if the input is neither valid IPv4 nor valid IPv6

return IPv4 in format like "192.168.9.1"
return IPv6 in format like "[2002:ac1f:91c5:1::bd59]"

func GenerateRandomString

func GenerateRandomString(n int) string

GenerateRandomString thanks to https://stackoverflow.com/a/31832326/6450189 GenerateRandomString is used to generate a random string that is used as a cluster token

func GetConfigDirOrCreate

func GetConfigDirOrCreate() (string, error)

GetConfigDirOrCreate will return the base path of the k3d config directory or create it if it doesn't exist yet k3d's config directory will be $HOME/.k3d (Unix)

func GetConfigFileName

func GetConfigFileName(configFile string) (configFilePath string)

GetConfigFileName load config from file seach path <clusterName>.yaml, ./variables/<clusterName>.yaml, ~/<clusterName>/cluster.yaml, ~/.k3s/<clusterName>.yaml, ~/.k3s/<clusterName>/cluster.yaml

func GetEnvDir

func GetEnvDir(clusterName string) (envPath string)

GetEnvDir

func GetEnvValue

func GetEnvValue(val string, k3sEnv []string) (res string)

func GetFakeMeminfoPathForName

func GetFakeMeminfoPathForName(nodeName string) (string, error)

GetFakeMeminfoPathForName returns a path to (existent or not) fake meminfo file for a given node/container name

func GetFreePort

func GetFreePort() (int, error)

GetFreePort tries to fetch an open port from the OS-Kernel

func GetGroupNodes

func GetGroupNodes(nodes []*k3sv1alpha1.Node) (ServerNodes, AgentNodes, error)

GetGroupNodes nodes grouping to role

func GetNodeFakerDirOrCreate

func GetNodeFakerDirOrCreate(name string) (string, error)

GetNodeFakerDirOrCreate creates or gets a hidden folder in k3d home dir to keep container(node)-specific fake files in it

func GetNodeRole

func GetNodeRole(val string) string

func ItemExists

func ItemExists(arrayType interface{}, item interface{}) bool

ItemExists - check if array element exists strArray := [5]string{"India", "Canada", "Japan", "Germany", "Italy"} fmt.Println(itemExists(strArray, "Canada"))

func ListClusterName added in v0.6.4

func ListClusterName() (clusterNames []string)

ListClusterName

func LoadTemplate added in v0.6.5

func LoadTemplate(url string) ([]byte, error)

LoadTemplate - load template from url

func MakeFakeEdac

func MakeFakeEdac(nodeName string) (string, error)

MakeFakeEdac creates an empty edac folder to force cadvisor to use meminfo even for ECC memory

func MakeFakeMeminfo

func MakeFakeMeminfo(memoryBytes int64, nodeName string) (string, error)

MakeFakeMeminfo creates a fake meminfo file to be mounted and provide a specific RAM capacity. This file is created on a per specific container/node basis, uniqueName must ensure that. Returns a path to the file

func MapSubexpNames

func MapSubexpNames(names, matches []string) map[string]string

MapSubexpNames maps regex capturing group names to corresponding matches

func PingRetry

func PingRetry(args *PingArgs) (err error)

func PingTCP

func PingTCP(host string, timeout int, counter int) (err error)

PingTCP ping tcp,http, https timeot in second, ping counter command line util https://github.com/cloverstd/tcping

func RandomToken

func RandomToken(size int) (string, error)

// RandomToken generate random token.

func ShowFilesInDirectory added in v0.6.4

func ShowFilesInDirectory(dir string, extension string) ([]string, []string, error)

ShowFilesInDirectory show files in directory filter extension

func SplitLabelKeyValue

func SplitLabelKeyValue(label string) (string, string)

SplitLabelKeyValue separates the label key from the label value (if any)

Types

type AgentNodes

type AgentNodes []*k3sv1alpha1.Node

type PingArgs

type PingArgs struct {
	Host         string
	Port         int
	Protocol     string
	ShowResponse bool
	Timeout      int
	Counter      int
	Retry        int
}

type ServerNodes

type ServerNodes []*k3sv1alpha1.Node

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL