utils

package
v2.3.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLabel

func AddLabel(labels map[string]string, labelKey, labelValue string) map[string]string

AddLabel returns a map with the given key and value added to the given map.

func AddOwnersLabel

func AddOwnersLabel(owners, resource, name, namespace string) string

func ApplyClusterRole

func ApplyClusterRole(kubeClient kubernetes.Interface, clusterRoleName string, rules []rbacv1.PolicyRule) error

apply cluster role

func ApplyClusterRoleBinding

func ApplyClusterRoleBinding(ctx context.Context, client client.Client, required *rbacv1.ClusterRoleBinding) error

ApplyClusterRoleBinding merges objectmeta, requires subjects and role refs

func BuildClusterRoleName

func BuildClusterRoleName(objName, rule string) string

func BuildKubeClient

func BuildKubeClient(kubeConfigPath string) (*kubernetes.Clientset, error)

func CloneAndAddLabel

func CloneAndAddLabel(labels map[string]string, labelKey, labelValue string) map[string]string

CloneAndAddLabel the given map and returns a new map with the given key and value added. Returns the given map, if labelKey is empty.

func ContainsString

func ContainsString(slice []string, s string) bool

ContainsString to check string from a slice of strings.

func ConvertLabels

func ConvertLabels(labelSelector *metav1.LabelSelector) (labels.Selector, error)

ConvertLabels returns label

func DeleteClusterRole

func DeleteClusterRole(kubeClient kubernetes.Interface, clusterRoleName string) error

Delete cluster role

func EncodeCertPEM

func EncodeCertPEM(cert *x509.Certificate) []byte

EncodeCertPEM returns PEM-endcoded certificate data

func EncodePrivateKeyPEM

func EncodePrivateKeyPEM(key *rsa.PrivateKey) []byte

EncodePrivateKeyPEM returns PEM-encoded private key data

func EqualSubjects

func EqualSubjects(subjects1, subjects2 []rbacv1.Subject) bool

func FormatQuatityToGi

func FormatQuatityToGi(q resource.Quantity) resource.Quantity

func FormatQuatityToMi

func FormatQuatityToMi(q resource.Quantity) resource.Quantity

func GenerateClusterRoleBindingName

func GenerateClusterRoleBindingName(clusterName string) string

clusterset clusterrolebinding

func GenerateClusterRoleName

func GenerateClusterRoleName(clusterName, role string) string

managedcluster admin role

func GenerateClustersetClusterroleName

func GenerateClustersetClusterroleName(clustersetName, role string) string

func GeneratePemFile

func GeneratePemFile(dir, certFile, keyFile string) (string, error)

GeneratePemFile generate a pem file that include key and cert

func GetCPUAndMemoryAllocation

func GetCPUAndMemoryAllocation(pods []*corev1.Pod) (cpuAllocation, memoryAllocation resource.Quantity)

func GetCPUAndMemoryCapacity

func GetCPUAndMemoryCapacity(nodes []*corev1.Node) (cpuCapacity, memoryCapacity resource.Quantity)

func GetClustersetInRules

func GetClustersetInRules(rules []rbacv1.PolicyRule) sets.String

func GetComponentNamespace

func GetComponentNamespace() (string, error)

func GetStorageCapacityAndAllocation

func GetStorageCapacityAndAllocation(pvs []*corev1.PersistentVolume) (storageCapacity, storageAllocation resource.Quantity)

func MatchLabelForLabelSelector

func MatchLabelForLabelSelector(targetLabels map[string]string, labelSelector *metav1.LabelSelector) bool

MatchLabelForLabelSelector match labels for labelselector, if labelSelecor is nil, select everything

func MergeMap

func MergeMap(modified *bool, existing map[string]string, required map[string]string)

func Mergesubjects

func Mergesubjects(subjects []rbacv1.Subject, cursubjects []rbacv1.Subject) []rbacv1.Subject

func NewMultiLineAggregate

func NewMultiLineAggregate(errList []error) error

NewMultiLineAggregate returns an aggregate error with multi-line output

func NewPrivateKey

func NewPrivateKey() (*rsa.PrivateKey, error)

NewPrivateKey creates an RSA private key

func NewSignedCert

func NewSignedCert(cfg cert.Config, key crypto.Signer, caCert *x509.Certificate, caKey crypto.Signer) (*x509.Certificate, error)

NewSignedCert creates a signed certificate using the given CA certificate and key

func PodRequestsAndLimits

func PodRequestsAndLimits(
	pod *corev1.Pod) (reqs map[corev1.ResourceName]resource.Quantity, limits map[corev1.ResourceName]resource.Quantity)

PodRequestsAndLimits returns a dictionary of all defined resources summed up for all containers of the pod.

func RemoveString

func RemoveString(slice []string, s string) (result []string)

ContainsString to remove string from a slice of strings.

func StringToMap

func StringToMap(str string) map[string]string

string to map

func WriteKeyCertToFile

func WriteKeyCertToFile(certDir string, key, cert []byte) (string, error)

WriteKeyCertToFile write key/cert to a certain cert path

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