utils

package
v0.0.0-...-3566972 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PublicAzureStorageEndpointSuffix defines default Storage Endpoint Suffix
	PublicAzureStorageEndpointSuffix = "core.windows.net"
	// AzureStackCloudName references the value that will be under the key "cloud" in azure.json if the application is running on Azure Stack Cloud
	// https://kubernetes-sigs.github.io/cloud-provider-azure/install/configs/#azure-stack-configuration -- See this documentation for the well-known cloud name.
	AzureStackCloudName = "AzureStackCloud"
)

Variables

This section is empty.

Functions

func Contains

func Contains(flagsList []string, flag string) bool

func CopyFile

func CopyFile(source, destination string) error

func GetContent

func GetContent(readCloserProvider func() (io.ReadCloser, error)) (string, error)

func GetStorageEndpointSuffix

func GetStorageEndpointSuffix(knownFilePaths *KnownFilePaths) string

GetStorageEndpointSuffix returns the SES url from the JSON file as a string

func GetUrlWithRetries

func GetUrlWithRetries(url string, maxRetries int) ([]byte, error)

Tries to issue an HTTP GET request up to maxRetries times

func IsAzureStackCloud

func IsAzureStackCloud(filePaths *KnownFilePaths) bool

IsAzureStackCloud returns true if the application is running on Azure Stack Cloud

func RunCommandOnHost

func RunCommandOnHost(command string, arg ...string) (string, error)

RunCommandOnHost runs a command on host system

func ToDataValueMap

func ToDataValueMap(data map[string]string) map[string]interfaces.DataValue

Types

type Azure

type Azure struct {
	Cloud string `json:"cloud"`
}

Azure defines Azure configuration

type AzureStackCloud

type AzureStackCloud struct {
	StorageEndpointSuffix string `json:"storageEndpointSuffix"`
}

AzureStackCloud defines Azure Stack Cloud configuration

type CommandOutputStreams

type CommandOutputStreams struct {
	Stdout string
	Stderr string
}

type ConfigKey

type ConfigKey string
const (
	CollectorListKey     ConfigKey = "COLLECTOR_LIST"
	ContainerLogsListKey ConfigKey = "DIAGNOSTIC_CONTAINERLOGS_LIST"
	KubeObjectsListKey   ConfigKey = "DIAGNOSTIC_KUBEOBJECTS_LIST"
	NodeLogsLinuxKey     ConfigKey = "DIAGNOSTIC_NODELOGS_LIST_LINUX"
	NodeLogsWindowsKey   ConfigKey = "DIAGNOSTIC_NODELOGS_LIST_WINDOWS"
	RunIdKey             ConfigKey = "DIAGNOSTIC_RUN_ID"
)

type Feature

type Feature string
const (
	WindowsHpc Feature = "WINHPC"
)

type FileContentWatcher

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

FileContentWatcher allows clients to register to receive notifications via a channel when a file's content changes or there is an error reading that file. It uses polling and stores file content in memory, valuing simplicity over sophisticated approaches involving cross-platform inotify or hashing mechanisms. With that in mind, it is appropriate for watching a small number of small files.

func NewFileContentWatcher

func NewFileContentWatcher(fileSystem interfaces.FileSystemAccessor, pollInterval time.Duration) *FileContentWatcher

NewFileContentWatcher constructs a FileContentWatcher based on the specified FileSystemAccessor and polling interval. This will initially contain no handlers, and will not start polling until the Start method is called.

func (*FileContentWatcher) AddHandler

func (w *FileContentWatcher) AddHandler(filePath string, contentChan chan string, errChan chan error)

AddHandler supplies channels for receiving notifications when the specified file is read or changed, or when there is an error reading it. No files will be read or notifications sent until the Start method is called.

func (*FileContentWatcher) Start

func (w *FileContentWatcher) Start()

Start tells the FileContentWatcher to periodically read the files for which a handler has been registered, starting immediately.

type FilePathDataValue

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

func NewFilePathDataValue

func NewFilePathDataValue(fileSystem interfaces.FileSystemAccessor, filePath string, fileSize int64) *FilePathDataValue

func (*FilePathDataValue) GetLength

func (v *FilePathDataValue) GetLength() int64

func (*FilePathDataValue) GetReader

func (v *FilePathDataValue) GetReader() (io.ReadCloser, error)

type FileSystem

type FileSystem struct{}

func NewFileSystem

func NewFileSystem() *FileSystem

func (*FileSystem) FileExists

func (fs *FileSystem) FileExists(filePath string) (bool, error)

func (*FileSystem) GetFileReader

func (fs *FileSystem) GetFileReader(filePath string) (io.ReadCloser, error)

func (*FileSystem) GetFileSize

func (fs *FileSystem) GetFileSize(filePath string) (int64, error)

func (*FileSystem) ListFiles

func (fs *FileSystem) ListFiles(directoryPath string) ([]string, error)

type KnownFilePaths

type KnownFilePaths struct {
	AzureJson               string
	AzureStackCloudJson     string
	WindowsLogsOutput       string
	ResolvConfHost          string
	ResolvConfContainer     string
	AzureStackCertHost      string
	AzureStackCertContainer string
	NodeLogsList            string
	Config                  string
	Secret                  string
}

func GetKnownFilePaths

func GetKnownFilePaths(osIdentifier OSIdentifier) (*KnownFilePaths, error)

GetKnownFilePaths get known file paths

func (*KnownFilePaths) GetConfigPath

func (p *KnownFilePaths) GetConfigPath(key ConfigKey) string

func (*KnownFilePaths) GetFeaturePath

func (p *KnownFilePaths) GetFeaturePath(feature Feature) string

func (*KnownFilePaths) GetSecretPath

func (p *KnownFilePaths) GetSecretPath(key SecretKey) string

type KubeCommandRunner

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

KubeCommandRunner replicates some of the functionality provided by the kubectl binary. This uses the `Unstructured` package (https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured) to work with API resources. That decision means we sacrifice strong typing to get more straightforward serialization, fewer package dependencies, and better ability to handle resource version changes over time.

func NewKubeCommandRunner

func NewKubeCommandRunner(config *rest.Config) *KubeCommandRunner

func (*KubeCommandRunner) GetCRDUnstructuredList

func (runner *KubeCommandRunner) GetCRDUnstructuredList() (*unstructured.UnstructuredList, error)

GetCRDUnstructuredList reads all the CRDs in the cluster and returns the result as an UnstructuredList.

func (*KubeCommandRunner) GetGVRForCRD

func (runner *KubeCommandRunner) GetGVRForCRD(crdName string) (*schema.GroupVersionResource, error)

GetGVRForCRD gets the GroupVersionResource for the specified CRD (where Version is the 'storage' version for the resources).

func (*KubeCommandRunner) GetGVRFromCRD

GetGVRFromCRD takes a CRD in Unstructured form and returns the GroupVersionResource for its resources.

func (*KubeCommandRunner) GetJsonListOutput

func (runner *KubeCommandRunner) GetJsonListOutput(gvr *schema.GroupVersionResource, namespace string, listOptions *metav1.ListOptions) (string, error)

GetJsonListOutput replicates 'kubectl get [kind] -o json'.

func (*KubeCommandRunner) GetJsonObjectOutput

func (runner *KubeCommandRunner) GetJsonObjectOutput(gvr *schema.GroupVersionResource, namespace, name string) (string, error)

GetJsonObjectOutput replicates 'kubectl get [kind] [name] -o json'.

func (*KubeCommandRunner) GetTableOutput

func (runner *KubeCommandRunner) GetTableOutput(gvr *schema.GroupVersionResource, namespace string, listOptions *metav1.ListOptions, printOptions *printers.PrintOptions) (string, error)

GetTableOutput replicates 'kubectl get [kind] -o [table|wide]'.

func (*KubeCommandRunner) GetUnstructuredItem

func (runner *KubeCommandRunner) GetUnstructuredItem(gvr *schema.GroupVersionResource, namespace string, name string) (*unstructured.Unstructured, error)

GetUnstructuredItem gets the API response to a Get request in Unstructured form.

func (*KubeCommandRunner) GetUnstructuredList

func (runner *KubeCommandRunner) GetUnstructuredList(gvr *schema.GroupVersionResource, namespace string, options *metav1.ListOptions) (*unstructured.UnstructuredList, error)

GetUnstructuredList gets the API response to a List request in Unstructured form.

func (*KubeCommandRunner) GetUnstructuredTable

func (runner *KubeCommandRunner) GetUnstructuredTable(gvr *schema.GroupVersionResource, namespace string, options *metav1.ListOptions) (*unstructured.Unstructured, error)

GetUnstructuredTable gets the API response to a List request for a server-generated table, in Unstructured form.

func (*KubeCommandRunner) GetYamlListOutput

func (runner *KubeCommandRunner) GetYamlListOutput(gvr *schema.GroupVersionResource, namespace string, listOptions *metav1.ListOptions) (string, error)

GetYamlListOutput replicates 'kubectl get [kind] -o yaml'.

func (*KubeCommandRunner) GetYamlObjectOutput

func (runner *KubeCommandRunner) GetYamlObjectOutput(gvr *schema.GroupVersionResource, namespace, name string) (string, error)

GetYamlObjectOutput replicates 'kubectl get [kind] [name] -o yaml'.

func (*KubeCommandRunner) PrintAsJson

func (runner *KubeCommandRunner) PrintAsJson(obj runtime.Unstructured) (string, error)

PrintAsJson takes the Unstructured representation or one or more resources and serializes them as formatted JSON. If the input is a List type, it replaces the Kind/APIVersion with a generic 'List' Kind (as kubectl does).

func (*KubeCommandRunner) PrintAsTable

func (runner *KubeCommandRunner) PrintAsTable(obj runtime.Unstructured, printOptions *printers.PrintOptions) (string, error)

PrintAsTable takes the Unstructured representation of a table (as returned from the API), and outputs it as a human-readable table.

func (*KubeCommandRunner) PrintAsYaml

func (runner *KubeCommandRunner) PrintAsYaml(obj runtime.Unstructured) (string, error)

PrintAsYaml takes the Unstructured representation or one or more resources and serializes them as formatted YAML. If the input is a List type, it replaces the Kind/APIVersion with a generic 'List' Kind (as kubectl does).

type OSIdentifier

type OSIdentifier string
const (
	Linux   OSIdentifier = "linux"
	Windows OSIdentifier = "windows"
)

func StringToOSIdentifier

func StringToOSIdentifier(identifier string) (OSIdentifier, error)

type RuntimeInfo

type RuntimeInfo struct {
	RunId                   string
	HostNodeName            string
	CollectorList           []string
	KubernetesObjects       []string
	NodeLogs                []string
	ContainerLogsNamespaces []string
	StorageAccountName      string
	StorageSasKey           string
	StorageContainerName    string
	StorageSasKeyType       string
	Features                map[Feature]bool
}

func GetRuntimeInfo

func GetRuntimeInfo(fs interfaces.FileSystemAccessor, filePaths *KnownFilePaths) (*RuntimeInfo, error)

GetRuntimeInfo gets runtime info

func (*RuntimeInfo) HasFeature

func (runtimeInfo *RuntimeInfo) HasFeature(feature Feature) bool

type SecretKey

type SecretKey string
const (
	AccountNameKey   SecretKey = "AZURE_BLOB_ACCOUNT_NAME"
	SasTokenKey      SecretKey = "AZURE_BLOB_SAS_KEY"
	ContainerNameKey SecretKey = "AZURE_BLOB_CONTAINER_NAME"
	SasTokenTypeKey  SecretKey = "AZURE_STORAGE_SAS_KEY_TYPE"
)

type StringDataValue

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

func NewStringDataValue

func NewStringDataValue(value string) *StringDataValue

func (*StringDataValue) GetLength

func (v *StringDataValue) GetLength() int64

func (*StringDataValue) GetReader

func (v *StringDataValue) GetReader() (io.ReadCloser, error)

Jump to

Keyboard shortcuts

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