resources

package
v0.0.0-...-52cd4e6 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package resources defines the command execution logic.

Index

Constants

View Source
const (
	// ApiVersion is the version of meta type
	ApiVersion = "v1"
	// XuanWuApiVersion is the version of xuanwu api
	XuanWuApiVersion = "xuanwu.huawei.io/v1"
	// KindSecret is secret kind string
	KindSecret = "Secret"
	// KindConfigMap is the configmap kind string
	KindConfigMap = "ConfigMap"
	// KindStorageBackendClaim is the storage backend claim kind string
	KindStorageBackendClaim = "StorageBackendClaim"
	// YamlSeparator defines the separator of yaml file
	YamlSeparator = "---"
)

Variables

This section is empty.

Functions

func AnalyseBackendExist

func AnalyseBackendExist(jsonStr string) (interface{}, error)

AnalyseBackendExist analyse backend,an error is returned if backends not exist

func ConfigOneBackend

func ConfigOneBackend(backendConfig *BackendConfiguration) error

ConfigOneBackend config one backend

func FetchBackendConfig

func FetchBackendConfig(namespace string, names ...string) (map[string]*BackendConfiguration, error)

FetchBackendConfig fetch backend config from configmap

func FetchConfiguredBackends

func FetchConfiguredBackends(namespace string) (map[string]*BackendConfiguration, error)

FetchConfiguredBackends to fetch backend configuration

func LoadBackendsFromConfigMap

func LoadBackendsFromConfigMap(configmap corev1.ConfigMap,
	fromLocalFile string) (map[string]*BackendConfiguration, error)

LoadBackendsFromConfigMap load backend from configmap resource. fromLocalFile should be "" if the configmap is from kubernetes.

func LoadBackendsFromJson

func LoadBackendsFromJson(filename string) (map[string]*BackendConfiguration, error)

LoadBackendsFromJson load backend from json bytes

func LoadBackendsFromYaml

func LoadBackendsFromYaml(filename string) (map[string]*BackendConfiguration, error)

LoadBackendsFromYaml load backend from yaml

func RegisterCollector

func RegisterCollector(name PodType, collector FileLogsCollect)

RegisterCollector used to register a collector into the collectorSet

func RegisterIdentifyPodTypeFunc

func RegisterIdentifyPodTypeFunc(name PodType, f func(pod *coreV1.Pod) bool)

RegisterIdentifyPodTypeFunc used to register a func into the identifyPodTypeFuncSet

Types

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

Backend is a storage backend object

func NewBackend

func NewBackend(resource *Resource) *Backend

NewBackend initialize a Backend instance

func (*Backend) Create

func (b *Backend) Create() error

Create backend resource

func (*Backend) Delete

func (b *Backend) Delete() error

Delete backend resource

func (*Backend) Get

func (b *Backend) Get() error

Get query backend resources

func (*Backend) LoadBackendFile

func (b *Backend) LoadBackendFile() (map[string]*BackendConfiguration, error)

LoadBackendFile to load backend defined file on disk, the file type can be "json" or "yaml"

func (*Backend) Update

func (b *Backend) Update() error

Update update backend

type BackendConfigShow

type BackendConfigShow struct {
	Number     string `show:"NUMBER"`
	Configured string `show:"CONFIGURED"`
	Name       string `show:"NAME"`
	Storage    string `show:"STORAGE"`
	Urls       string `show:"URLS"`
}

BackendConfigShow the content echoed by executing the oceanctl create backend

type BackendConfiguration

type BackendConfiguration struct {
	Name                string                   `json:"name,omitempty" yaml:"name"`
	NameSpace           string                   `json:"namespace,omitempty" yaml:"namespace"`
	Storage             string                   `json:"storage,omitempty" yaml:"storage"`
	VstoreName          string                   `json:"vstoreName,omitempty" yaml:"vstoreName"`
	AccountName         string                   `json:"accountName,omitempty" yaml:"accountName"`
	Urls                []string                 `json:"urls,omitempty" yaml:"urls"`
	Pools               []string                 `json:"pools,omitempty" yaml:"pools"`
	MetrovStorePairID   string                   `json:"metrovStorePairID,omitempty" yaml:"metrovStorePairID"`
	MetroBackend        string                   `json:"metroBackend,omitempty" yaml:"metroBackend"`
	SupportedTopologies []map[string]interface{} `json:"supportedTopologies,omitempty" yaml:"supportedTopologies"`
	MaxClientThreads    string                   `json:"maxClientThreads,omitempty" yaml:"maxClientThreads"`
	Configured          bool                     `json:"-" yaml:"configured"`
	Provisioner         string                   `json:"provisioner,omitempty" yaml:"provisioner"`
	Parameters          struct {
		Protocol   string                            `json:"protocol,omitempty" yaml:"protocol"`
		ParentName string                            `json:"parentname,omitempty" yaml:"parentname"`
		Portals    interface{}                       `json:"portals,omitempty" yaml:"portals"`
		Alua       map[string]map[string]interface{} `json:"ALUA,omitempty" yaml:"ALUA"`
	} `json:"parameters,omitempty" yaml:"parameters"`
}

BackendConfiguration backend config

func LoadMultipleBackendFromConfigmap

func LoadMultipleBackendFromConfigmap(jsonStr string) ([]*BackendConfiguration, error)

LoadMultipleBackendFromConfigmap load multiple backend

func LoadSingleBackendFromConfigmap

func LoadSingleBackendFromConfigmap(jsonStr string) ([]*BackendConfiguration, error)

LoadSingleBackendFromConfigmap load single backend

func MergeBackends

func MergeBackends(notConfigured, configured map[string]*BackendConfiguration) []*BackendConfiguration

MergeBackends to merge two backend configuration

func (*BackendConfiguration) ToConfigMapConfig

func (b *BackendConfiguration) ToConfigMapConfig() (ConfigMapConfig, error)

ToConfigMapConfig convert backend to helper.ConfigMapConfig

func (*BackendConfiguration) ToSecretConfig

func (b *BackendConfiguration) ToSecretConfig() (SecretConfig, error)

ToSecretConfig convert backend to helper.SecretConfig If start stdin failed, an error will return.

func (*BackendConfiguration) ToStorageBackendClaimConfig

func (b *BackendConfiguration) ToStorageBackendClaimConfig() StorageBackendClaimConfig

ToStorageBackendClaimConfig covert backend to StorageBackendClaimConfig

type BackendShow

type BackendShow struct {
	Namespace   string `show:"NAMESPACE"`
	Name        string `show:"NAME"`
	Protocol    string `show:"PROTOCOL"`
	StorageType string `show:"STORAGETYPE"`
	Sn          string `show:"SN"`
	Status      string `show:"STATUS"`
	Online      string `show:"ONLINE"`
	Url         string `show:"Url"`
}

BackendShow the content echoed by executing the oceanctl get backend

type BackendShowWide

type BackendShowWide struct {
	Namespace                 string `show:"NAMESPACE"`
	Name                      string `show:"NAME"`
	Protocol                  string `show:"PROTOCOL"`
	StorageType               string `show:"STORAGETYPE"`
	Sn                        string `show:"SN"`
	Status                    string `show:"STATUS"`
	Online                    string `show:"ONLINE"`
	Url                       string `show:"Url"`
	VendorName                string `show:"VENDORNAME"`
	StorageBackendContentName string `show:"STORAGEBACKENDCONTENTNAME"`
}

BackendShowWide the content echoed by executing the oceanctl get backend -o wide

func (*BackendShowWide) ShowWithClaimOption

func (b *BackendShowWide) ShowWithClaimOption(claim xuanwuv1.StorageBackendClaim) *BackendShowWide

ShowWithClaimOption set StorageBackendClaim value for BackendShowWide

func (*BackendShowWide) ShowWithConfigOption

func (b *BackendShowWide) ShowWithConfigOption(configuration BackendConfiguration) *BackendShowWide

ShowWithConfigOption set BackendConfiguration value for BackendShowWide

func (*BackendShowWide) ShowWithContentOption

func (b *BackendShowWide) ShowWithContentOption(content xuanwuv1.StorageBackendContent) *BackendShowWide

ShowWithContentOption set StorageBackendContent value for BackendShowWide

func (*BackendShowWide) ToBackendShow

func (b *BackendShowWide) ToBackendShow() BackendShow

ToBackendShow convert BackendShowWide to BackendShow

type BaseFileLogsCollect

type BaseFileLogsCollect struct{}

BaseFileLogsCollect collect file logs.

func (*BaseFileLogsCollect) CopyToLocal

func (b *BaseFileLogsCollect) CopyToLocal(namespace, nodeName, podName, containerName string) error

CopyToLocal copy the compressed log file to the local host.

func (*BaseFileLogsCollect) GetHostInformation

func (b *BaseFileLogsCollect) GetHostInformation(namespace, containerName, nodeName, podName string) error

GetHostInformation get the host information of a specified node.

type Cert

type Cert struct {
	// contains filtered or unexported fields
}

Cert is the cert resource

func NewCert

func NewCert(resource *Resource) *Cert

NewCert initialize a Cert instance

func (*Cert) Create

func (c *Cert) Create() error

Create create Cert

func (*Cert) Delete

func (c *Cert) Delete() error

Delete cert resource

func (*Cert) Get

func (c *Cert) Get() error

Get query Cert resources

func (*Cert) LoadCertFile

func (c *Cert) LoadCertFile() (*CertConfig, error)

LoadCertFile to load cert file from disk

func (*Cert) LoadCertsFromDate

func (c *Cert) LoadCertsFromDate(Data []byte) (*CertConfig, error)

LoadCertsFromDate load cert from bytes

func (*Cert) Update

func (c *Cert) Update() error

Update update Cert

type CertConfig

type CertConfig struct {
	Name      string
	Namespace string
	Cert      []byte
}

CertConfig used to create a cert object

func (*CertConfig) ToCertSecret

func (c *CertConfig) ToCertSecret() corev1.Secret

ToCertSecret convert CertSecretConfig to Secret resource

type CertShow

type CertShow struct {
	Namespace    string `show:"NAMESPACE"`
	Name         string `show:"NAME"`
	BoundBackend string `show:"BOUNDBACKEND"`
}

CertShow the content echoed by executing the oceanctl get cert

type ConfigMapConfig

type ConfigMapConfig struct {
	Name      string
	Namespace string
	JsonData  string
}

ConfigMapConfig used to create a configmap object

func (*ConfigMapConfig) ToConfigMap

func (c *ConfigMapConfig) ToConfigMap() corev1.ConfigMap

ToConfigMap convert ConfigMapConfig to ConfigMap resource

type Display

type Display struct {
	// contains filtered or unexported fields
}

Display Collects the progress display function of all nodes to display the progress.

func NewDisplay

func NewDisplay() *Display

NewDisplay initialize a Display instance

func (*Display) Add

func (d *Display) Add(prefixDesc string, f func())

Add the progress function to be displayed.

func (*Display) Show

func (d *Display) Show(ctx context.Context)

Show all progresses

type FileLogsCollect

type FileLogsCollect interface {
	GetFileLogs(namespace, podName, nodeName, fileLogPath string) (err error)
	GetHostInformation(namespace, containerName, nodeName, podName string) error
	CopyToLocal(namespace, nodeName, podName, containerName string) error
}

FileLogsCollect is the interface to collect file logs.

func LoadSupportedCollector

func LoadSupportedCollector(name PodType) (FileLogsCollect, error)

LoadSupportedCollector used to load supported collector. Return a collector of type FileLogsCollect and nil error if a client with the specified testName exists. If not exists, return an error with not supported.

type FileLogsCollector

type FileLogsCollector struct {
	BaseFileLogsCollect
}

FileLogsCollector collect specific file logs.

func (*FileLogsCollector) GetFileLogs

func (c *FileLogsCollector) GetFileLogs(namespace, podName, containerName, fileLogPath string) (err error)

GetFileLogs get the file log of a specified node.

type Logs

type Logs struct {
	// contains filtered or unexported fields
}

Logs Records specified conditions and provides a method for collecting logs.

func NewLogs

func NewLogs(resource *Resource) *Logs

NewLogs initialize a Logs instance

func (*Logs) Collect

func (lg *Logs) Collect() error

Collect logs based on specified conditions

type NodeLogCollector

type NodeLogCollector struct {
	// contains filtered or unexported fields
}

NodeLogCollector Collecting Node Logs

func NewNodeLogsCollector

func NewNodeLogsCollector(podList []coreV1.Pod, transmitter *helper.TaskHandler, display *Display) *NodeLogCollector

NewNodeLogsCollector initialize a NodeLogsCollector instance

func (*NodeLogCollector) Collect

func (n *NodeLogCollector) Collect()

Collect collects container logs of specified conditions on the node.

type PodType

type PodType byte

PodType defines the type of pod.

const (
	// CSI is the pod type of CSI.
	CSI PodType = 0
	// CSM is the pod type of CSM.
	CSM PodType = 1
	// Xuanwu is the pod type of Xuanwu.
	Xuanwu PodType = 2
	// UnKnow is the unknown pod type.
	UnKnow PodType = 3
)

type Resource

type Resource struct {
	*ResourceBuilder
}

Resource is a resource for Kubernetes

type ResourceBuilder

type ResourceBuilder struct {
	// contains filtered or unexported fields
}

ResourceBuilder is used to build a resource object

func NewResourceBuilder

func NewResourceBuilder() *ResourceBuilder

NewResourceBuilder initialize a ResourceBuilder instance

func (*ResourceBuilder) AllNamespaces

func (b *ResourceBuilder) AllNamespaces(allNamespace bool) *ResourceBuilder

AllNamespaces instructs the builder to metav1.NamespaceAll as a namespace to request resources across all the namespace. This overrides the namespace set by NamespaceParam().

func (*ResourceBuilder) AllNodes

func (b *ResourceBuilder) AllNodes(isAllNodes bool) *ResourceBuilder

AllNodes instructs the builder to request isAllNodes options.

func (*ResourceBuilder) BoundBackend

func (b *ResourceBuilder) BoundBackend(backend string) *ResourceBuilder

BoundBackend instructs the builder to request backend name.

func (*ResourceBuilder) Build

func (b *ResourceBuilder) Build() *Resource

Build convert ResourceBuilder to Resource

func (*ResourceBuilder) DefaultNamespace

func (b *ResourceBuilder) DefaultNamespace() *ResourceBuilder

DefaultNamespace instructs the builder to set the namespace value for any object found to NamespaceParam() if empty.

func (*ResourceBuilder) FileName

func (b *ResourceBuilder) FileName(fileName string) *ResourceBuilder

FileName instructs the builder to request file name.

func (*ResourceBuilder) FileType

func (b *ResourceBuilder) FileType(fileType string) *ResourceBuilder

FileType instructs the builder to request file type.

func (*ResourceBuilder) MaxNodeThreads

func (b *ResourceBuilder) MaxNodeThreads(maxNodeThreads int) *ResourceBuilder

MaxNodeThreads instructs the builder to request maxNodeThreads.

func (*ResourceBuilder) Names

func (b *ResourceBuilder) Names(names ...string) *ResourceBuilder

Names instructs the builder to request resources names

func (*ResourceBuilder) NamespaceParam

func (b *ResourceBuilder) NamespaceParam(namespace string) *ResourceBuilder

NamespaceParam accepts the namespace that these resources should be considered under from - used by DefaultNamespace()

func (*ResourceBuilder) NodeName

func (b *ResourceBuilder) NodeName(nodeName string) *ResourceBuilder

NodeName instructs the builder to request node name.

func (*ResourceBuilder) Output

func (b *ResourceBuilder) Output(output string) *ResourceBuilder

Output instructs the builder to request output type

func (*ResourceBuilder) ResourceNames

func (b *ResourceBuilder) ResourceNames(resource string, names ...string) *ResourceBuilder

ResourceNames accepts a default type and one or more names, and creates tuples of resources

func (*ResourceBuilder) ResourceTypes

func (b *ResourceBuilder) ResourceTypes(types ...string) *ResourceBuilder

ResourceTypes is a list of types of resources to operate on, when listing objects on the server or retrieving objects that match a selector.

func (*ResourceBuilder) SelectAll

func (b *ResourceBuilder) SelectAll(selectAll bool) *ResourceBuilder

SelectAll accepts a bool value and will filter the resulting list by that object.

func (*ResourceBuilder) Selector

func (b *ResourceBuilder) Selector(selector string) *ResourceBuilder

Selector accepts a selector directly and will filter the resulting list by that object.

type SecretConfig

type SecretConfig struct {
	Name      string
	Namespace string
	User      string
	Pwd       string
}

SecretConfig used to create a secret object

func (*SecretConfig) ToSecret

func (c *SecretConfig) ToSecret() corev1.Secret

ToSecret convert SecretConfig to Secret resource

type Status

type Status struct {
	// contains filtered or unexported fields
}

Status Collection status display

func (*Status) Display

func (n *Status) Display()

Display displays the pod log collection status of the current node.

type StorageBackendClaimConfig

type StorageBackendClaimConfig struct {
	Name             string
	Namespace        string
	ConfigmapMeta    string
	SecretMeta       string
	MaxClientThreads string
	Provisioner      string
}

StorageBackendClaimConfig used to create a storageBackendClaim object

func (*StorageBackendClaimConfig) ToStorageBackendClaim

func (c *StorageBackendClaimConfig) ToStorageBackendClaim() xuanwuv1.StorageBackendClaim

ToStorageBackendClaim convert StorageBackendClaimConfig to Secret StorageBackendClaim

type TransmitTask

type TransmitTask struct {
	FileLogsCollect
	// contains filtered or unexported fields
}

TransmitTask Configuring a Pod Log File Transfer Task

func (*TransmitTask) Do

func (t *TransmitTask) Do()

Do copy the compressed log file to the local host.

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator is used to validate a Resource object

func (*Validator) Validate

func (v *Validator) Validate() error

Validate used to validate whether the command params are legal

type ValidatorBuilder

type ValidatorBuilder struct {
	*Validator
}

ValidatorBuilder is used to build a Validator object

func NewValidatorBuilder

func NewValidatorBuilder(resource *Resource) *ValidatorBuilder

NewValidatorBuilder initialize a ValidatorBuilder instance

func (*ValidatorBuilder) Build

func (b *ValidatorBuilder) Build() *Validator

Build used to convert ValidatorBuilder to Validator

func (*ValidatorBuilder) ValidateBackend

func (b *ValidatorBuilder) ValidateBackend() *ValidatorBuilder

ValidateBackend used to validate backend

func (*ValidatorBuilder) ValidateNameIsExist

func (b *ValidatorBuilder) ValidateNameIsExist() *ValidatorBuilder

ValidateNameIsExist used to validate resource names is exists. For example, the following operations are illegal oceanctl update backend

func (*ValidatorBuilder) ValidateNameIsSingle

func (b *ValidatorBuilder) ValidateNameIsSingle() *ValidatorBuilder

ValidateNameIsSingle used to validate resource names is single. For example, the following operations are illegal oceanctl update backend <name-1> <name-2>

func (*ValidatorBuilder) ValidateOutputFormat

func (b *ValidatorBuilder) ValidateOutputFormat() *ValidatorBuilder

ValidateOutputFormat used to validate resource names is single.For example, the following operations are illegal oceanctl get backend <name-1> -o xml

func (*ValidatorBuilder) ValidateSelector

func (b *ValidatorBuilder) ValidateSelector() *ValidatorBuilder

ValidateSelector used to validate selector. For example, the following operations are illegal oceanctl delete backend oceanctl delete backend <name> --all

Jump to

Keyboard shortcuts

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