utils

package
v1.0.0-2021-09-29-07-0... Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: Apache-2.0 Imports: 35 Imported by: 10

Documentation

Index

Constants

View Source
const (
	ApiserverConfigName      = "cluster"
	OpenshiftConfigNamespace = "openshift-config"
	ServiceAccountNamespace  = "kube-system"
	ServiceAccountName       = "default"

	ConfigmapNamespace   = "kube-public"
	CrtConfigmapName     = "kube-root-ca.crt"
	ClusterinfoConfigmap = "cluster-info"
)

Variables

This section is empty.

Functions

func APIGroupMatches

func APIGroupMatches(rule *rbacv1.PolicyRule, requestedGroup string) bool

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 AppendErrors

func AppendErrors(errsList ...[]error) []error

appendErrors append errs, return appended result

func ApplyClusterRole

func ApplyClusterRole(kubeClient kubernetes.Interface, requiredClusterrole *rbacv1.ClusterRole) error

apply cluster role

func ApplyClusterRoleBinding

func ApplyClusterRoleBinding(ctx context.Context, kubeClient kubernetes.Interface, required *rbacv1.ClusterRoleBinding) error

ApplyClusterRoleBinding merges objectmeta, requires subjects and role refs

func ApplyRoleBinding

func ApplyRoleBinding(ctx context.Context, kubeClient kubernetes.Interface, required *rbacv1.RoleBinding) error

ApplyRoleBinding merges objectmeta, requires subjects and role refs

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 ClusterIsOffLine

func ClusterIsOffLine(conditions []metav1.Condition) bool

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 GenerateClusterRoleName

func GenerateClusterRoleName(clusterName, role string) string

managedcluster admin role

func GenerateClustersetClusterRoleBindingName

func GenerateClustersetClusterRoleBindingName(clusterName, role string) string

clusterset clusterrolebinding

func GenerateClustersetClusterroleName

func GenerateClustersetClusterroleName(clustersetName, role string) string

func GenerateClustersetResourceRoleBindingName

func GenerateClustersetResourceRoleBindingName(role string) string

clusterset resource rolebinding name

func GeneratePemFile

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

GeneratePemFile generate a pem file that include key and cert

func GetAdminResourceFromClusterRole

func GetAdminResourceFromClusterRole(clusterRole *rbacv1.ClusterRole, group, resource string) (sets.String, bool)

GetViewResourceFromClusterRole match the "update" permission of resource, which means this role has admin permission to this resource

func GetCAFromApiserver

func GetCAFromApiserver(ctx context.Context, ocpClient openshiftclientset.Interface, kubeClient kubernetes.Interface, kubeAPIServer string) ([]byte, error)

func GetCAFromConfigMap

func GetCAFromConfigMap(ctx context.Context, kubeClient kubernetes.Interface) ([]byte, error)

GetCACert returns the CA cert. It searches in the kube-root-ca.crt configmap in kube-public ns.

func GetCAFromServiceAccount

func GetCAFromServiceAccount(ctx context.Context, kubeClient kubernetes.Interface) ([]byte, error)

func GetCPUAndMemoryAllocation

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

func GetCPUAndMemoryCapacity

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

func GetComponentNamespace

func GetComponentNamespace() (string, error)

func GetKubeAPIServerAddress

func GetKubeAPIServerAddress(ctx context.Context, openshiftClient openshiftclientset.Interface) (string, error)

func GetStorageCapacityAndAllocation

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

func GetViewResourceFromClusterRole

func GetViewResourceFromClusterRole(clusterRole *rbacv1.ClusterRole, group, resource string) (sets.String, bool)

GetViewResourceFromClusterRole match the "get" permission of resource, which means this role has view permission to this resource

func IsManagedClusterClusterrolebinding

func IsManagedClusterClusterrolebinding(clusterrolebindingName, role string) bool

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 ResourceMatches

func ResourceMatches(rule *rbacv1.PolicyRule, combinedRequestedResource, requestedSubresource string) bool

func ResourceNamespacedName

func ResourceNamespacedName(resourceType, namespace, name string) string

func StringToMap

func StringToMap(str string) map[string]string

string to map

func SyncMapField

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

SyncMapField sync the "syncFiledKey" label filed of required map.

func VerbMatches

func VerbMatches(rule *rbacv1.PolicyRule, requestedVerb string) bool

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