utils

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const HashLength = 7

HashLength is the length of the randomly generated "hash" that is used throughout claudie in different places. be CAUTIOUS when changing this value as this will break backwards compatibility and also invariants within claudie. Dynamic nodepools are assigned a randomly generated hash. Node pool names have a max constraint of 15 characters changing the hash length will invalidate this.

Variables

View Source
var ErrConnectionNotReady = errors.New("unhealthy gRPC connection")

Functions

func CloseClientConnection

func CloseClientConnection(connection *grpc.ClientConn)

CloseClientConnection is a wrapper around grpc.ClientConn Close function

func ConcurrentExec

func ConcurrentExec[K any](items []K, f func(index int, item K) error) error

func CountLbNodes added in v0.6.3

func CountLbNodes(lb *spec.LBcluster) int

func CountNodes added in v0.6.3

func CountNodes(k *spec.K8Scluster) int

func CreateDirectory

func CreateDirectory(dir string) error

func CreateHash

func CreateHash(length int) string

func CreateKeyFile

func CreateKeyFile(key string, outputPath string, keyName string) error

CreateKeyFile writes the given key to a file. The key filename is specified by its outputPath and KeyName operands.

func CreateKeysForDynamicNodePools added in v0.9.0

func CreateKeysForDynamicNodePools(nps []*spec.NodePool, outputDirectory string) error

func CreateKeysForStaticNodepools added in v0.4.1

func CreateKeysForStaticNodepools(nps []*spec.NodePool, outputDirectory string) error

CreateKeysForStaticNodepools creates private keys files for all nodes in the provided static node pools in form of <node name>.pem.

func CreateLoggerWithClusterName added in v0.3.1

func CreateLoggerWithClusterName(clusterName string) zerolog.Logger

CreateLoggerWithClusterName creates a new logger aware of the cluster-name. Returns the new logger

func CreateLoggerWithProjectAndClusterName added in v0.3.1

func CreateLoggerWithProjectAndClusterName(projectName, clusterName string) zerolog.Logger

CreateLoggerWithProjectAndClusterName creates a new logger aware of the project-name and cluster-name. Returns the new logger

func CreateLoggerWithProjectName added in v0.3.1

func CreateLoggerWithProjectName(projectName string) zerolog.Logger

CreateLoggerWithProjectName creates a new logger aware of the project-name. Returns the new logger

func CreateNpsFromCommonControlPlaneNodes added in v0.9.0

func CreateNpsFromCommonControlPlaneNodes(currControlNps map[string]*spec.NodePool, desiredNp []*spec.NodePool) []*spec.NodePool

func DirectoryExists added in v0.9.0

func DirectoryExists(dir string) bool

func ExtractTargetPorts added in v0.9.0

func ExtractTargetPorts(loadBalancers []*spec.LBcluster) []int

ExtractTargetPorts extracts target ports defined inside the role in the LoadBalancer.

func FindAPIEndpointNode added in v0.3.1

func FindAPIEndpointNode(nodepools []*spec.NodePool) (*spec.Node, error)

FindAPIEndpointNode searches the NodePools for a Node with type ApiEndpoint.

func FindControlNode added in v0.3.1

func FindControlNode(nodepools []*spec.NodePool) (*spec.Node, error)

FindControlNode search the nodepools for a node with type Master.

func FindControlNodepools added in v0.7.2

func FindControlNodepools(nodepools []*spec.NodePool) []*spec.NodePool

FindControlNodepools returns control nodepools

func FindEndpointNode added in v0.3.1

func FindEndpointNode(np *spec.NodePool) (*spec.Node, error)

FindEndpointNode searches the nodes of the nodepool for a node with type ApiEndpoint.

func FindName

func FindName(realNames []string, name string) string

FindName will return a real node name based on the user defined one example: name defined in cloud provider: gcp-control-1 -> name defined in cluster : gcp-control-1

func FindNodepoolWithApiEndpointNode added in v0.4.0

func FindNodepoolWithApiEndpointNode(nodepools []*spec.NodePool) (*spec.NodePool, *spec.Node, error)

FindNodepoolWithApiEndpointNode searches for a nodepool that has the control node representing the Api endpoint of the cluster. Returns the control node if found and its corresponding nodepool.

func GetAuthCredentials added in v0.9.0

func GetAuthCredentials(provider *spec.Provider) string

GetAuthCredentials extract the key for the provider to be used within terraform.

func GetClusterID added in v0.3.1

func GetClusterID(clusterInfo *spec.ClusterInfo) string

func GetCommonDynamicControlPlaneNodes added in v0.9.0

func GetCommonDynamicControlPlaneNodes(currentNp, desiredNp []*spec.NodePool) []*spec.NodePool

func GetCommonDynamicNodePools added in v0.4.0

func GetCommonDynamicNodePools(nps []*spec.NodePool) []*spec.NodePool

GetCommonDynamicNodePools returns slice of common node pools, where every node pool is dynamic.

func GetCommonStaticControlPlaneNodes added in v0.9.0

func GetCommonStaticControlPlaneNodes(currentNp, desiredNp []*spec.NodePool) []*spec.NodePool

func GetCommonStaticNodePools added in v0.4.0

func GetCommonStaticNodePools(nps []*spec.NodePool) []*spec.NodePool

GetCommonStaticNodePools returns slice of common node pools, where every node pool is static.

func GetDynamicNodePools added in v0.4.0

func GetDynamicNodePools(nps []*spec.NodePool) []*spec.DynamicNodePool

GetDynamicNodePools returns slice of dynamic node pools.

func GetDynamicNodePoolsFromCI added in v0.4.0

func GetDynamicNodePoolsFromCI(ci *spec.ClusterInfo) []*spec.DynamicNodePool

GetDynamicNodePoolsFromCI returns slice of dynamic node pools used in specified cluster info.

func GetEnvDefault added in v0.4.0

func GetEnvDefault(envKey string, defaultVal string) string

GetEnvDefault take a string representing environment variable as an argument, and a default value If the environment variable is not defined, it returns the provided default value.

func GetLBClusterByName added in v0.4.0

func GetLBClusterByName(name string, clusters []*spec.LBcluster) int

GetLBClusterByName will return index of Cluster that will have same name as specified in parameters If no name is found, return -1

func GetNodePoolByName

func GetNodePoolByName(nodePoolName string, nodePools []*spec.NodePool) *spec.NodePool

GetNodePoolByName will return first Nodepool that will have same name as specified in parameters If no name is found, return nil

func GetRegions

func GetRegions(nodepools []*spec.DynamicNodePool) []string

GetRegions will return a list of all regions used in list of nodepools

func GetWatchNamespaceList added in v0.8.0

func GetWatchNamespaceList(input string) []string

watchNamespaceList takes a string input of the form "namespace1,namespace-2,namespace3" and splits it into a slice of strings based on the comma separator. It returns the slice containing individual namespace strings.

func GroupNodepoolsByProviderRegion added in v0.2.2

func GroupNodepoolsByProviderRegion(clusterInfo *spec.ClusterInfo) map[string][]*spec.NodePool

GroupNodepoolsByProviderRegion groups nodepool by cloud provider instance name and region into the map[<provider-instance-name>-<region>][]*pb.Nodepool

func GroupNodepoolsByProviderSpecName

func GroupNodepoolsByProviderSpecName(clusterInfo *spec.ClusterInfo) map[string][]*spec.NodePool

GroupNodepoolsByProviderSpecName groups nodepool by provider spec name into the map[Provider Name][]*spec.Nodepool

func GrpcDialWithRetryAndBackoff added in v0.4.1

func GrpcDialWithRetryAndBackoff(serviceName, serviceURL string) (*grpc.ClientConn, error)

GrpcDialWithRetryAndBackoff creates an insecure gRPC connection to serviceURL After successfully connected, any RPC calls made from this connection also have a retry policy of ~10 minutes after which an error is returned that it couldn't connect to the service.

func HasAPIServerRole added in v0.3.1

func HasAPIServerRole(roles []*spec.Role) bool

HasAPIServerRole checks if there is an API server role.

func InitLog

func InitLog(moduleName string)

Initialize the logging framework. Inputs are the golang module name used as a logging prefix and the env variable with the logging level

func Into added in v0.4.2

func Into[K, V any](k []K, f func(k K) *V) []*V

Into traverse the elements in k and calls the supplied function f to convert them into elements of type V.

func IsAutoscaled added in v0.2.2

func IsAutoscaled(cluster *spec.K8Scluster) bool

IsAutoscaled returns true, if cluster has at least one nodepool with autoscaler config.

func IsConnectionReady added in v0.4.2

func IsConnectionReady(c *grpc.ClientConn) error

func IterateInOrder added in v0.7.3

func IterateInOrder[M ~map[K]V, K inorder, V any](m M, f func(k K, v V) error) error

func MatchNameAndHashWithTemplate added in v0.9.0

func MatchNameAndHashWithTemplate(template, nodepoolName string) (name, hash string)

func MergeMaps added in v0.4.1

func MergeMaps[M ~map[K]V, K comparable, V any](maps ...M) M

MergeMaps merges two or more maps together, into single map.

func MustExtractNameAndHash added in v0.9.0

func MustExtractNameAndHash(pool string) (name, hash string)

func NewGRPCServer added in v0.4.1

func NewGRPCServer(opts ...grpc.ServerOption) *grpc.Server

func PeerInfoInterceptor added in v0.7.5

func PeerInfoInterceptor(logger *zerolog.Logger) grpc.UnaryServerInterceptor

func PointerValEqual added in v0.9.0

func PointerValEqual[K comparable](left, right *K) bool

func RemoveDuplicates added in v0.6.6

func RemoveDuplicates[K comparable](slice []K) []K

func SanitiseKubeconfig

func SanitiseKubeconfig(s string) string

SanitiseKubeconfig replaces the entire kubeconfig found after the '--kubeconfig' flag with '*****'. This has been decided to be the superior option when compared to matching sensitive fields and obscuring just those.

func SanitiseString added in v0.4.1

func SanitiseString(s string) string

sanitiseString replaces all white spaces and ":" in the string to "-", and converts everything to lower case.

func SanitiseURI

func SanitiseURI(s string) string

SanitiseURI replaces passwords with '*****' in connection strings that are in the form of <scheme>://<username>:<password>@<domain>.<tld> or <scheme>://<username>:<password>@<pqdn>.

func Sum added in v0.6.3

func Sum[M ~map[K]V, K comparable, V constraints.Integer | constraints.Float](m M) int

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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