utils

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const HashLength = 7

Variables

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

Functions

func ChangedDNSProvider

func ChangedDNSProvider(currentDNS, desiredDNS *pb.DNS) bool

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 *pb.LBcluster) int

func CountNodes added in v0.6.3

func CountNodes(k *pb.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 CreateKeysForStaticNodepools added in v0.4.1

func CreateKeysForStaticNodepools(nps []*pb.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 FindAPIEndpointNode added in v0.3.1

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

FindAPIEndpointNode searches the NodePools for a Node with type ApiEndpoint.

func FindControlNode added in v0.3.1

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

FindControlNode search the nodepools for a node with type Master.

func FindControlNodepools added in v0.7.2

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

FindControlNodepools returns control nodepools

func FindEndpointNode added in v0.3.1

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

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

func FindLbAPIEndpointCluster added in v0.7.2

func FindLbAPIEndpointCluster(current []*pb.LBcluster) *pb.LBcluster

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-cluster-jkshbdc-gcp-control-1 -> name defined in cluster : gcp-control-1

func FindNodepoolWithApiEndpointNode added in v0.4.0

func FindNodepoolWithApiEndpointNode(nodepools []*pb.NodePool) (*pb.NodePool, *pb.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 GetClusterByName

func GetClusterByName(clusterName string, clusters []*pb.K8Scluster) int

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

func GetClusterID added in v0.3.1

func GetClusterID(clusterInfo *pb.ClusterInfo) string

func GetCommonDynamicNodePools added in v0.4.0

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

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

func GetCommonStaticNodePools added in v0.4.0

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

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

func GetDynamicNodePools added in v0.4.0

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

GetDynamicNodePools returns slice of dynamic node pools.

func GetDynamicNodePoolsFromCI added in v0.4.0

func GetDynamicNodePoolsFromCI(ci *pb.ClusterInfo) []*pb.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 []*pb.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 GetNameAndHashFromNodepool added in v0.7.2

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

func GetNodePoolByName

func GetNodePoolByName(nodePoolName string, nodePools []*pb.NodePool) *pb.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 []*pb.DynamicNodePool) []string

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

func GroupNodepoolsByProviderNames added in v0.4.0

func GroupNodepoolsByProviderNames(clusterInfo *pb.ClusterInfo) map[ProviderNames][]*pb.NodePool

GroupNodepoolsByProviderNames groups nodepool by provider spec name into the map[Provider Names][]*pb.Nodepool

func GroupNodepoolsByProviderRegion added in v0.2.2

func GroupNodepoolsByProviderRegion(clusterInfo *pb.ClusterInfo) map[string][]*pb.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 *pb.ClusterInfo) map[string][]*pb.NodePool

GroupNodepoolsByProviderSpecName groups nodepool by provider spec name into the map[Provider Name][]*pb.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 []*pb.Role) bool

HasAPIServerRole checks if there is an API server role.

func HasLbAPIEndpoint added in v0.7.2

func HasLbAPIEndpoint(lbs []*pb.LBcluster) bool

HasLbAPIEndpoint searches for a role with ApiEndpoint among the LBcluster.

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 if type V.

func IsAutoscaled added in v0.2.2

func IsAutoscaled(cluster *pb.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 IsNodepoolOnlyTargetOfLbAPI added in v0.7.2

func IsNodepoolOnlyTargetOfLbAPI(current []*pb.LBcluster, nodepool *pb.NodePool) bool

IsNodepoolOnlyTargetOfLbAPI checks if nodepool is the only target Pool of the API LB cluster.

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 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 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 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

type ClusterView added in v0.4.1

type ClusterView struct {
	// CurrentClusters are the individual clusters defined in the kubernetes section of the config of the current state.
	CurrentClusters map[string]*pb.K8Scluster
	// DesiredClusters are the individual clusters defined in the kubernetes section of the config of the desired state.
	DesiredClusters map[string]*pb.K8Scluster

	// Loadbalancers are the loadbalancers attach to a given kubernetes cluster in the current state.
	Loadbalancers map[string][]*pb.LBcluster
	// DesiredLoadbalancers are the loadbalancers attach to a given kubernetes cluster in the desired state.
	DesiredLoadbalancers map[string][]*pb.LBcluster

	// DeletedLoadbalancers are the loadbalancers that will be deleted (present in the current state but missing in the desired state)
	DeletedLoadbalancers map[string][]*pb.LBcluster

	// ClusterWorkflows is additional information per-cluster workflow (current stage of execution, if any error occurred etc..)
	ClusterWorkflows map[string]*pb.Workflow
}

ClusterView contains the per-cluster view on a given config. No mutex is needed when processing concurrently as long as each cluster only works with related values.

func NewClusterView added in v0.4.1

func NewClusterView(config *pb.Config) *ClusterView

func (*ClusterView) AllClusters added in v0.4.1

func (view *ClusterView) AllClusters() []string

AllClusters returns a slice of cluster all cluster names, from both the current state and desired state. This is useful to be abe to distinguish which clusters were deleted and which were not.

func (*ClusterView) MergeChanges added in v0.4.1

func (view *ClusterView) MergeChanges(config *pb.Config)

MergeChanges propagates the changes made back to the config.

func (*ClusterView) RemoveCurrentState added in v0.4.2

func (view *ClusterView) RemoveCurrentState(clusterName string)

func (*ClusterView) SetWorkflowDone added in v0.4.1

func (view *ClusterView) SetWorkflowDone(clusterName string)

func (*ClusterView) SetWorkflowError added in v0.4.1

func (view *ClusterView) SetWorkflowError(clusterName string, err error)

func (*ClusterView) UpdateCurrentState added in v0.4.2

func (view *ClusterView) UpdateCurrentState(clusterName string, c *pb.K8Scluster, lbs []*pb.LBcluster)

func (*ClusterView) UpdateDesiredState added in v0.4.2

func (view *ClusterView) UpdateDesiredState(clusterName string, c *pb.K8Scluster, lbs []*pb.LBcluster)

type ProviderNames added in v0.4.0

type ProviderNames struct {
	SpecName          string
	CloudProviderName string
}

ProviderNames struct hold pair of cloud provider name and user defined name from manifest.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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