utils

package
v0.0.0-...-5573a19 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerCACerts = "observability-server-ca-certs"
	ClientCACerts = "observability-client-ca-certs"
	ServerCerts   = "observability-server-certs"
	GrafanaCerts  = "observability-grafana-certs"
)
View Source
const (
	MCO_CR_NAME                   = "observability"
	MCO_COMPONENT_LABEL           = "observability.open-cluster-management.io/name=" + MCO_CR_NAME
	OBSERVATORIUM_COMPONENT_LABEL = "app.kubernetes.io/part-of=observatorium"
	MCO_NAMESPACE                 = "open-cluster-management-observability"
	MCO_ADDON_NAMESPACE           = "open-cluster-management-addon-observability"
	MCO_PULL_SECRET_NAME          = "multiclusterhub-operator-pull-secret"
	OBJ_SECRET_NAME               = "thanos-object-storage" // #nosec G101 -- Not a hardcoded credential.
	MCO_GROUP                     = "observability.open-cluster-management.io"
	OCM_WORK_GROUP                = "work.open-cluster-management.io"
	OCM_CLUSTER_GROUP             = "cluster.open-cluster-management.io"
	OCM_ADDON_GROUP               = "addon.open-cluster-management.io"
)
View Source
const (
	ManagedClusterAddOnDisabledMessage = "enableMetrics is set to False"
	OBMAddonEnabledMessage             = "Cluster metrics sent successfully"
	ManagedClusterAddOnEnabledMessage  = "observability-controller add-on is available"
)
View Source
const (
	RouterCertsSecretName = "router-certs-default"
)

Variables

This section is empty.

Functions

func Apply

func Apply(url string, kubeconfig string, ctx string, yamlB []byte) error

Apply a multi resources file to the cluster described by the url, kubeconfig and ctx. url of the cluster kubeconfig which contains the ctx ctx, the ctx to use yamlB, a byte array containing the resources file

func CheckAdvRetentionConfig

func CheckAdvRetentionConfig(opt TestOptions) (bool, error)

func CheckAllOBADisabled

func CheckAllOBADisabled(opt TestOptions) error

func CheckAllOBAsDeleted

func CheckAllOBAsDeleted(opt TestOptions) error

func CheckAllOBAsEnabled

func CheckAllOBAsEnabled(opt TestOptions) error

func CheckAllPodNodeSelector

func CheckAllPodNodeSelector(opt TestOptions, nodeSelector map[string]interface{}) error

func CheckAllPodsAffinity

func CheckAllPodsAffinity(opt TestOptions) error

func CheckDaemonSetsInNamespace

func CheckDaemonSetsInNamespace(client kubernetes.Interface, ns string)

func CheckDeploymentPodReady

func CheckDeploymentPodReady(opt TestOptions, deployName string) error

func CheckDeploymentsInNamespace

func CheckDeploymentsInNamespace(client kubernetes.Interface, ns string)

func CheckMCOAddonResources

func CheckMCOAddonResources(opt TestOptions) error

func CheckMCOComponents

func CheckMCOComponents(opt TestOptions) error

func CheckMCOConversion

func CheckMCOConversion(opt TestOptions, v1beta1tov1beta2GoldenPath string) error

func CheckManagedClusterAddonsStatus

func CheckManagedClusterAddonsStatus(opt TestOptions, namespace, status string) error

func CheckOBAComponents

func CheckOBAComponents(opt TestOptions) error

func CheckOBADeleted

func CheckOBADeleted(opt TestOptions, namespace string) error

func CheckOBAStatus

func CheckOBAStatus(opt TestOptions, namespace, status string) error

func CheckPodsInNamespace

func CheckPodsInNamespace(client kubernetes.Interface, ns string, forcePodNamesLog []string, podLabels map[string]string)

CheckPodsInNamespace lists pods in a namespace and logs debug info (status, events, logs) for pods not running.

func CheckStatefulSetPodReady

func CheckStatefulSetPodReady(opt TestOptions, stsName string) error

func CheckStatefulSetsInNamespace

func CheckStatefulSetsInNamespace(client kubernetes.Interface, ns string)

func CheckStorageResize

func CheckStorageResize(opt TestOptions, stsName string, expectedCapacity string) error

func CleanExportResources

func CleanExportResources(opt TestOptions) error

func ContainDashboard

func ContainDashboard(opt TestOptions, title string) (error, bool)

func CreateCRB

func CreateCRB(opt TestOptions, isHub bool,
	crb *rbacv1.ClusterRoleBinding) error

func CreateMCONamespace

func CreateMCONamespace(opt TestOptions) error

func CreateMCOTestingRBAC

func CreateMCOTestingRBAC(opt TestOptions) error

func CreateObjSecret

func CreateObjSecret(opt TestOptions) error

func CreatePullSecret

func CreatePullSecret(opt TestOptions, mcoNs string) error

func CreateSA

func CreateSA(opt TestOptions, isHub bool, namespace string,
	sa *v1.ServiceAccount) error

func DeleteCRB

func DeleteCRB(opt TestOptions, isHub bool, name string) error

func DeleteCertSecret

func DeleteCertSecret(opt TestOptions) error

func DeleteConfigMap

func DeleteConfigMap(opt TestOptions, isHub bool, name string, namespace string) error

func DeleteDeployment

func DeleteDeployment(opt TestOptions, isHub bool, name string, namespace string) error

func DeleteMCOInstance

func DeleteMCOInstance(opt TestOptions, name string) error

func DeleteMCOTestingRBAC

func DeleteMCOTestingRBAC(opt TestOptions) error

func DeleteSA

func DeleteSA(opt TestOptions, isHub bool, namespace string,
	name string) error

func FetchBearerToken

func FetchBearerToken(opt TestOptions) (string, error)

func GetAllMCOPods

func GetAllMCOPods(opt TestOptions) ([]corev1.Pod, error)

func GetCRB

func GetCRB(opt TestOptions, isHub bool, name string) (error, *rbacv1.ClusterRoleBinding)

func GetConfigMap

func GetConfigMap(opt TestOptions, isHub bool, name string,
	namespace string) (error, *corev1.ConfigMap)

func GetDefaultMetricList

func GetDefaultMetricList(opt TestOptions) ([]string, []string)

func GetDeployment

func GetDeployment(opt TestOptions, isHub bool, name string,
	namespace string) (*appv1.Deployment, error)

func GetDeploymentWithLabel

func GetDeploymentWithLabel(opt TestOptions, isHub bool, label string,
	namespace string) (*appv1.DeploymentList, error)

func GetGrafanaURL

func GetGrafanaURL(opt TestOptions) string

func GetKubeClientDynamic

func GetKubeClientDynamic(opt TestOptions, isHub bool) dynamic.Interface

func GetMCOAddonSpecResources

func GetMCOAddonSpecResources(opt TestOptions) (map[string]interface{}, error)

func GetManagedClusterName

func GetManagedClusterName(opt TestOptions) string

func GetNamespace

func GetNamespace(opt TestOptions, isHub bool, namespace string) (error, *v1.Namespace)

func GetPodList

func GetPodList(opt TestOptions, isHub bool, namespace string, labelSelector string) (error, *v1.PodList)

func GetPodLogs

func GetPodLogs(
	opt TestOptions,
	isHub bool,
	namespace, podName, containerName string,
	previous bool,
	tailLines int64,
) (string, error)

func GetPullSecret

func GetPullSecret(opt TestOptions) (string, error)

GetPullSecret checks the secret from MCH CR and return the secret name

func GetRouterCA

func GetRouterCA(cli kubernetes.Interface) ([]byte, error)

func GetSAWithLabel

func GetSAWithLabel(opt TestOptions, isHub bool, label string,
	namespace string) (*v1.ServiceAccountList, error)

func GetStatefulSet

func GetStatefulSet(opt TestOptions, isHub bool, name string,
	namespace string) (*appv1.StatefulSet, error)

func GetStatefulSetWithLabel

func GetStatefulSetWithLabel(opt TestOptions, isHub bool, label string,
	namespace string) (*appv1.StatefulSetList, error)

func HaveCRDs

func HaveCRDs(c Cluster, kubeconfig string, expectedCRDs []string) error

func IntegrityChecking

func IntegrityChecking(opt TestOptions) error

IntegrityChecking checks to ensure all required conditions are met when completing the specs

func ListKSManagedClusterNames

func ListKSManagedClusterNames(opt TestOptions) ([]string, error)

func ListManagedClusters

func ListManagedClusters(opt TestOptions) ([]string, error)

func ListOCPManagedClusterIDs

func ListOCPManagedClusterIDs(opt TestOptions, minVersionStr string) ([]string, error)

func LoadConfig

func LoadConfig(url, kubeconfig, ctx string) (*rest.Config, error)

func LogDeploymentStatus

func LogDeploymentStatus(deployment appsv1.Deployment)

func LogFailingTestStandardDebugInfo

func LogFailingTestStandardDebugInfo(opt TestOptions)

LogFailingTestStandardDebugInfo logs standard debug info for failing tests. It scans workloads and pods from hub and managed clusters observability namespaces. It also prints MCO and OBA objects. If a workload or pod is not running, it prints the resource spec, status, events and logs if appropriate.

func LogObjectEvents

func LogObjectEvents(client kubernetes.Interface, ns string, kind string, name string)

func LogPodLogs

func LogPodLogs(client kubernetes.Interface, ns string, pod corev1.Pod)

func LogPodStatus

func LogPodStatus(podList corev1.Pod)

func ModifyMCOAddonSpecInterval

func ModifyMCOAddonSpecInterval(opt TestOptions, interval int64) error

func ModifyMCOAddonSpecMetrics

func ModifyMCOAddonSpecMetrics(opt TestOptions, enable bool) error

func ModifyMCOCR

func ModifyMCOCR(opt TestOptions) error

ModifyMCOCR modifies the MCO CR for reconciling. modify multiple parameter to save running time

func NewKubeClient

func NewKubeClient(url, kubeconfig, ctx string) kubernetes.Interface

func NewKubeClientAPIExtension

func NewKubeClientAPIExtension(url, kubeconfig, ctx string) apiextensionsclientset.Interface

func NewKubeClientDynamic

func NewKubeClientDynamic(url, kubeconfig, ctx string) dynamic.Interface

func NewMCOAddonGVR

func NewMCOAddonGVR() schema.GroupVersionResource

func NewMCOClusterManagementAddonsGVR

func NewMCOClusterManagementAddonsGVR() schema.GroupVersionResource

func NewMCOGVRV1BETA1

func NewMCOGVRV1BETA1() schema.GroupVersionResource

func NewMCOGVRV1BETA2

func NewMCOGVRV1BETA2() schema.GroupVersionResource

func NewMCOMObservatoriumGVR

func NewMCOMObservatoriumGVR() schema.GroupVersionResource

func NewMCOManagedClusterAddonsGVR

func NewMCOManagedClusterAddonsGVR() schema.GroupVersionResource

func NewOCMManagedClustersGVR

func NewOCMManagedClustersGVR() schema.GroupVersionResource

func NewOCMManifestworksGVR

func NewOCMManifestworksGVR() schema.GroupVersionResource

func NewOCMMultiClusterHubGVR

func NewOCMMultiClusterHubGVR() schema.GroupVersionResource

func PrintObject

func PrintObject(ctx context.Context, client dynamic.Interface, gvr schema.GroupVersionResource, ns, name string)

func RevertMCOCRModification

func RevertMCOCRModification(opt TestOptions) error

RevertMCOCRModification revert the previous changes

func StatusContainsTypeEqualTo

func StatusContainsTypeEqualTo(u *unstructured.Unstructured, typeString string) bool

StatusContainsTypeEqualTo check if u contains a condition type with value typeString

func UninstallMCO

func UninstallMCO(opt TestOptions) error

func UpdateCRB

func UpdateCRB(opt TestOptions, isHub bool, name string,
	crb *rbacv1.ClusterRoleBinding) (error, *rbacv1.ClusterRoleBinding)

func UpdateDeployment

func UpdateDeployment(
	opt TestOptions,
	isHub bool,
	name string,
	namespace string,
	dep *appv1.Deployment) (*appv1.Deployment, error)

func UpdateDeploymentReplicas

func UpdateDeploymentReplicas(
	opt TestOptions,
	deployName, crProperty string,
	desiredReplicas, expectedReplicas int32,
) error

func UpdateObservabilityFromManagedCluster

func UpdateObservabilityFromManagedCluster(opt TestOptions, enableObservability bool) error

func UpdateSA

func UpdateSA(opt TestOptions, isHub bool, namespace string,
	sa *v1.ServiceAccount) (error, *v1.ServiceAccount)

Types

type APIKeys

type APIKeys struct {
	AWS   AWSAPIKey   `yaml:"aws,omitempty"`
	GCP   GCPAPIKey   `yaml:"gcp,omitempty"`
	Azure AzureAPIKey `yaml:"azure,omitempty"`
}

type AWSAPIKey

type AWSAPIKey struct {
	AWSAccessID     string `yaml:"awsAccessKeyID"`
	AWSAccessSecret string `yaml:"awsSecretAccessKeyID"`
	BaseDnsDomain   string `yaml:"baseDnsDomain"`
	Region          string `yaml:"region"`
}

type AzureAPIKey

type AzureAPIKey struct {
	BaseDnsDomain  string `yaml:"baseDnsDomain"`
	BaseDomainRGN  string `yaml:"azureBaseDomainRGN"`
	Region         string `yaml:"region"`
	SubscriptionID string `yaml:"subscriptionID"`
	TenantID       string `yaml:"tenantID"`
	ClientID       string `yaml:"clientID"`
	ClientSecret   string `yaml:"clientSecret"`
}

type CloudConnection

type CloudConnection struct {
	PullSecret    string  `yaml:"pullSecret"`
	SSHPrivateKey string  `yaml:"sshPrivatekey"`
	SSHPublicKey  string  `yaml:"sshPublickey"`
	Keys          APIKeys `yaml:"apiKeys,omitempty"`
	OCPRelease    string  `yaml:"ocpRelease,omitempty"`
}

CloudConnection struct for bits having to do with Connections

type Cluster

type Cluster struct {
	Name             string          `yaml:"name,omitempty"`
	Namespace        string          `yaml:"namespace,omitempty"`
	Tags             map[string]bool `yaml:"tags,omitempty"`
	BaseDomain       string          `yaml:"baseDomain"`
	User             string          `yaml:"user,omitempty"`
	Password         string          `yaml:"password,omitempty"`
	KubeContext      string          `yaml:"kubecontext,omitempty"`
	ClusterServerURL string          `yaml:"clusterServerURL,omitempty"`
	GrafanaURL       string          `yaml:"grafanaURL,omitempty"`
	GrafanaHost      string          `yaml:"grafanaHost,omitempty"`
	KubeConfig       string          `yaml:"kubeconfig,omitempty"`
}

Define the shape of clusters that may be added under management

type CollectRule

type CollectRule struct {
	Collect     string            `yaml:"collect"`
	Annotations map[string]string `yaml:"annotations"`
	Expr        string            `yaml:"expr"`
	For         string            `yaml:"for"`
	Metrics     DynamicMetrics    `yaml:"dynamic_metrics"`
}

type CollectRuleGroup

type CollectRuleGroup struct {
	Name            string              `yaml:"group"`
	Annotations     map[string]string   `yaml:"annotations"`
	Selector        CollectRuleSelector `yaml:"selector"`
	CollectRuleList []CollectRule       `yaml:"rules"`
}

CollectRuleGroup structure contains information of a group of collect rules used for dnamically collecting metrics.

type CollectRuleSelector

type CollectRuleSelector struct {
	MatchExpression []metav1.LabelSelectorRequirement `yaml:"matchExpressions"`
}

type DynamicMetrics

type DynamicMetrics struct {
	NameList  []string `yaml:"names"`
	MatchList []string `yaml:"matches"`
}

type GCPAPIKey

type GCPAPIKey struct {
	ProjectID             string `yaml:"gcpProjectID"`
	ServiceAccountJsonKey string `yaml:"gcpServiceAccountJsonKey"`
	BaseDnsDomain         string `yaml:"baseDnsDomain"`
	Region                string `yaml:"region"`
}

type GrafanaResponse

type GrafanaResponse struct {
	Status string `json:"status"`
	Data   struct {
		ResultType string `json:"resultType"`
		Result     []struct {
			Metric map[string]string `json:"metric"`
			Value  []interface{}     `json:"value"` // Use interface{} because value can be mixed types
		} `json:"result"`
	} `json:"data"`
}

func QueryGrafana

func QueryGrafana(opt TestOptions, query string) (*GrafanaResponse, error)

func (GrafanaResponse) ContainsLabelsSet

func (r GrafanaResponse) ContainsLabelsSet(labels map[string]string) bool

func (GrafanaResponse) String

func (r GrafanaResponse) String() string

type MetricsAllowlist

type MetricsAllowlist struct {
	NameList             []string           `yaml:"names"`
	MatchList            []string           `yaml:"matches"`
	RenameMap            map[string]string  `yaml:"renames"`
	RuleList             []RecordingRule    `yaml:"rules"` //deprecated
	RecordingRuleList    []RecordingRule    `yaml:"recording_rules"`
	CollectRuleGroupList []CollectRuleGroup `yaml:"collect_rules"`
}

type RecordingRule

type RecordingRule struct {
	Record string `yaml:"record"`
	Expr   string `yaml:"expr"`
}

type Registry

type Registry struct {
	// example: quay.io/stolostron
	Server   string `yaml:"server"`
	User     string `yaml:"user"`
	Password string `yaml:"password"`
}

Define the image registry

type TestOptions

type TestOptions struct {
	HubCluster      Cluster         `yaml:"hub"`
	ManagedClusters []Cluster       `yaml:"clusters"`
	ImageRegistry   Registry        `yaml:"imageRegistry,omitempty"`
	KubeConfig      string          `yaml:"kubeconfig,omitempty"`
	Connection      CloudConnection `yaml:"cloudConnection,omitempty"`
	Headless        string          `yaml:"headless,omitempty"`
	OwnerPrefix     string          `yaml:"ownerPrefix,omitempty"`
}

Define options available for Tests to consume

type TestOptionsContainer

type TestOptionsContainer struct {
	Options TestOptions `yaml:"options"`
}

Jump to

Keyboard shortcuts

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