util

package
v0.0.0-...-21a76b1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 50 Imported by: 0

Documentation

Overview

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

* Copyright 2020-2023 Alibaba Group Holding Limited.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// ForwardAddress is the address to forward to
	ForwardAddress = "127.0.0.1"

	// DeploymentLabel is the label used to select the pod under a deployment
	DeploymentLabel = "app.vineyard.io/name"
)
View Source
const (
	// PodKind is the kind of the kubernetes pod.
	PodKind = "Pod"
)

Variables

View Source
var (
	// MetaHeaders are the headers for the less metadata output
	MetaHeaders []string = []string{"ID", "TYPENAME", "LENGTH", "TRANSIENT", "TYPE", "MEMBERS", "INSTANCE ID"}

	// ClusterInfoHeaders are the headers for the cluster info output
	ClusterInfoHeaders []string = []string{"INSTANCE ID", "HOSTID", "HOSTNAME", "IPC_SOCKET", "NODENAME", "RPC_ENDPOINT", "TIMESTAMP"}

	// BufferHeaders are the headers for the buffer output
	BufferHeaders []string = []string{"ID", "BUFFER"}

	// ValidSortedKeys are the valid keys for sorting
	ValidSortedKeys []string = []string{"id", "typename", "type", "instance_id"}

	// ValidOutputFormats are the valid output formats
	ValidOutputFormats []string = []string{"table", "json"}
)
View Source
var Indentation = "  "

Functions

func ApplyManifests

func ApplyManifests(c client.Client, manifests Manifests, namespace string) error

ApplyManifests create kubernetes resources from manifests

func ApplyManifestsWithOwnerRef

func ApplyManifestsWithOwnerRef(c client.Client, objs []*unstructured.Unstructured,
	ownerKind, refKind string) error

ApplyManifestsWithOwnerRef create kubernetes resources from manifests and choose one object as the owner of the other specific objects Currently, only support to use the kind of manifest as the distinguishing conditions. As a result, the ownerKind and refKind should not to be the same. Also, the refKind could be more than one and should be separated by comma.

func AssertNoArgs

func AssertNoArgs(cmd *cobra.Command, args []string)

func AssertNoArgsOrInput

func AssertNoArgsOrInput(cmd *cobra.Command, args []string)

func BuildObjsFromEtcdManifests

func BuildObjsFromEtcdManifests(etcdConfig *k8s.EtcdConfig, name string,
	namespace string, replicas int, image string, value interface{},
	tmplFunc map[string]interface{},
) ([]*unstructured.Unstructured, []*unstructured.Unstructured, error)

BuildObjsFromEtcdManifests builds a list of objects from the etcd template files. the template files are under the dir 'k8s/pkg/templates/etcd'

func BuildObjsFromManifests

func BuildObjsFromManifests(templateName string, value interface{},
	tmplFunc map[string]interface{},
) ([]*unstructured.Unstructured, error)

BuildObjsFromManifests builds a list of objects from the the standard template files such as backup and recover

func BuildObjsFromVineyarddManifests

func BuildObjsFromVineyarddManifests(files []string, value interface{},
	tmplFunc map[string]interface{},
) ([]*unstructured.Unstructured, error)

BuildObjsFromVineyarddManifests builds a list of objects from the vineyardd template files.

func CaptureCmdOutput

func CaptureCmdOutput(cmd *cobra.Command) string

func CheckClientSocket

func CheckClientSocket(cmd *cobra.Command, args []string)

func ConnectDeployment

func ConnectDeployment(deployment, namespace string, readyChannel, stopChannel chan struct{}) (*client.RPCClient, error)

ConnectDeployment connects to the vineyardd deployment via rpc

func ConnectViaIPC

func ConnectViaIPC(ipcSocket string) (*client.IPCClient, error)

ConnectViaIPC connects to the ipc server

func ConnectViaRPC

func ConnectViaRPC(rpcSocket string) (*client.RPCClient, error)

ConnectViaRPC connects to the rpc server

func ConvertToJson

func ConvertToJson(str string) (string, error)

ConvertToJson check whether the string is json type and converts the string to json type if not

func ConvertToYaml

func ConvertToYaml(str string) (string, error)

ConvertToYaml converts the json string to yaml type

func Create

func Create[T client.Object](c client.Client, v T, until ...func(T) bool) error

func CreateIfNotExists

func CreateIfNotExists[T client.Object](c client.Client, v T, until ...func(T) bool) error

func CreateNamespaceIfNotExist

func CreateNamespaceIfNotExist(c client.Client)

CreateNamespaceIfNotExist creates namespace if it does not exist

func CreateWithContext

func CreateWithContext[T client.Object](
	c client.Client,
	ctx context.Context,
	v T,
	ignoreExists bool,
	until ...func(T) bool,
) error

func Delete

func DeleteManifests

func DeleteManifests(c client.Client, manifests Manifests, namespace string) error

DeleteManifests delete kubernetes resources from manifests

func DeleteWithContext

func DeleteWithContext(
	c client.Client,
	ctx context.Context,
	key types.NamespacedName,
	v client.Object,
) error

func Deserializer

func Deserializer() runtime.Decoder

func Examples

func Examples(examples string) string

func GetAnnotations

func GetAnnotations(obj *unstructured.Unstructured) (map[string]string, error)

GetAnnotations returns the annotations of the given unstructured kubernetes object.

func GetContainer

func GetContainer(obj *unstructured.Unstructured) ([]interface{}, error)

GetContainer returns the container interface with the given unstructured kubernetes object.

func GetContainersAndVolumes

func GetContainersAndVolumes(obj *unstructured.Unstructured) ([]interface{}, []interface{}, error)

GetContainersAndVolumes returns the containers and volumes of the given unstructured kubernetes object.

func GetKubernetesConfig

func GetKubernetesConfig() *rest.Config

func GetLabels

func GetLabels(obj *unstructured.Unstructured) (map[string]string, error)

GetLabels returns the labels of the given unstructured kubernetes object.

func GetName

func GetName(obj *unstructured.Unstructured) (string, error)

GetName returns the name of the given unstructured kubernetes object.

func GetNamespace

func GetNamespace(obj *unstructured.Unstructured) (string, error)

GetNamespace returns the namespace of the given unstructured kubernetes object.

func GetPVAndPVC

GetPVAndPVC parse the pVAndPVC string to corev1.PersistentVolumeSpec and corev1.PersistentVolumeClaimSpec, then return the relevant fields.

func GetRequiredPodAffinity

func GetRequiredPodAffinity(obj *unstructured.Unstructured) ([]interface{}, error)

GetRequiredPodAffinity returns the required pod affinity of the given unstructured kubernetes object.

func GetStatus

func GetStatus(obj *unstructured.Unstructured) (map[string]interface{}, error)

GetStatus returns the status of the given unstructured kubernetes object.

func GetValidForwardPort

func GetValidForwardPort(forwardPort int) (int, error)

func GetVolume

func GetVolume(obj *unstructured.Unstructured) ([]interface{}, error)

GetVolume returns the volume interface with the given unstructured kubernetes object.

func KubernetesClient

func KubernetesClient() client.Client

KubernetesClient return the kubernetes client

func KubernetesClientset

func KubernetesClientset() *kubernetes.Clientset

KubernetesClientset return the kubernetes clientset

func LongDesc

func LongDesc(long string) string

func ParseEnvs

func ParseEnvs(envArray []string) ([]corev1.EnvVar, error)

ParseEnvs parse the string to container's environment variables

func ParseManifestToObject

func ParseManifestToObject(manifest string) (*unstructured.Unstructured, error)

ParseManifestToObject parse a kubernetes manifest to an object

func ParseOwnerRef

func ParseOwnerRef(of string) ([]metav1.OwnerReference, error)

ParseOwnerRef parse the string to metav1.OwnerReference

func ParsePVCSpec

func ParsePVCSpec(pvcspec string) (*corev1.PersistentVolumeClaimSpec, error)

ParsePVCSpec parse the json string to corev1.PersistentVolumeClaimSpec

func ParsePVSpec

func ParsePVSpec(pvspec string) (*corev1.PersistentVolumeSpec, error)

ParsePVSpec parse the json string to corev1.PersistentVolumeSpec

func ParsePVandPVCSpec

func ParsePVandPVCSpec(
	PvAndPvcJSON string,
) (*corev1.PersistentVolumeSpec, *corev1.PersistentVolumeClaimSpec, error)

ParsePVandPVCSpec parse the json string to corev1.PersistentVolumeSpec and corev1.PersistentVolumeClaimSpec

func ParseVineyardClusters

func ParseVineyardClusters(clusters []string) (*[]v1alpha1.VineyardClusters, error)
ParseVineyardClusters parse the []string to nested []{
	"namespace": "vineyard-cluster-namespace",
    "name": "vineyard-cluster-name",
}

func PortForwardDeployment

func PortForwardDeployment(deploymentName, namespace string, forwardPort, port int, readyChannel, stopChannel chan struct{})

func ReadFromFile

func ReadFromFile(path string) (string, error)

ReadFromFile reads the file and returns the content as a string.

func ReadFromStdin

func ReadFromStdin(args []string) (string, error)

ReadFromStdin read the stdin to string

func ReadJsonFromStdin

func ReadJsonFromStdin(args []string) (string, error)

ReadJsonFromStdin read the stdin to json string

func RenderManifestAsObj

func RenderManifestAsObj(path string, value interface{},
	tmplFunc map[string]interface{},
) (*unstructured.Unstructured, error)

RenderManifestAsObj renders the manifest as an object

func Scheme

func Scheme() *runtime.Scheme

func SetAnnotations

func SetAnnotations(obj *unstructured.Unstructured, annotations map[string]string) error

SetAnnotations sets the annotations of the given unstructured kubernetes object.

func SetContainer

func SetContainer(obj *unstructured.Unstructured, containers []interface{}) error

SetContainer sets the container with the given unstructured kubernetes object.

func SetLabels

func SetLabels(obj *unstructured.Unstructured, labels map[string]string) error

SetLabels sets the labels of the given unstructured kubernetes object.

func SetNodename

func SetNodename(obj *unstructured.Unstructured, nodename string) error

SetNodename sets the nodename of the given unstructured kubernetes object.

func SetRequiredPodAffinity

func SetRequiredPodAffinity(obj *unstructured.Unstructured, required []interface{}) error

SetRequiredPodAffinity sets the required pod affinity of the given unstructured kubernetes object.

func SetVolume

func SetVolume(obj *unstructured.Unstructured, volumes []interface{}) error

SetVolume sets the volume with the given unstructured kubernetes object.

func Wait

func Wait(condition wait.ConditionFunc) error

func WriteToFile

func WriteToFile(path string, content string) error

WriteToFile writes the content to the file.

Types

type Client

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

func NewClient

func NewClient() (Client, chan struct{})

NewClient returns a new client connected to the vineyardd server

func (*Client) GetBlob

func (c *Client) GetBlob(id string, unsafe bool) (blob map[types.ObjectID]client.Blob, err error)

GetBlob

func (*Client) GetClusterInfo

func (c *Client) GetClusterInfo() (map[string]any, error)

GetClusterInfo returns the cluster info

func (*Client) GetMetaData

func (c *Client) GetMetaData(id string, syncRemote bool) (meta *client.ObjectMeta, err error)

GetMetadata

func (*Client) ListBlobs

func (c *Client) ListBlobs(limit int) (map[types.ObjectID]client.Blob, error)

ListBlobs lists all vineyard blobs

func (*Client) ListMetadatas

func (c *Client) ListMetadatas(pattern string, regex bool, limits int) (map[string]map[string]any, error)

ListMetadatas lists all vineyard metadata

func (*Client) PutBlob

func (c *Client) PutBlob(address []byte, size uint64) (types.ObjectID, error)

PutBlob

type KeyValue

type KeyValue struct {
	ObjectID string
	Value    string
}

type Manifests

type Manifests []*unstructured.Unstructured

func BuildKustomizeInEmbedDir

func BuildKustomizeInEmbedDir() (Manifests, error)

func GetCertManager

func GetCertManager() (Manifests, error)

GetCertManager get the cert-manager manifests

func ParseManifestsToObjects

func ParseManifestsToObjects(manifests []byte) (Manifests, error)

ParseManifestsToObjects parse kubernetes manifests to objects

type Objects

type Objects interface {
	ListMetadatas(string, bool, int) (map[string]map[string]any, error)
	ListBlobs() (map[types.ObjectID]client.Blob, error)
	GetClusterInfo() (map[string]map[string]string, error)
	GetBlob(id string, unsafe bool) (blob map[types.ObjectID]client.Blob, err error)
	GetMetaData(id string, syncRemote bool) (meta *client.ObjectMeta, err error)
}

Objects are the operate interface for all objects

type Options

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

Options are the options for the output

type Output

type Output struct {
	Options
	// contains filtered or unexported fields
}

Output is the output of the metadata and buffers

func NewOutput

func NewOutput(metadatas *map[string]map[string]any,
	buffers *map[types.ObjectID]client.Blob,
	clusterInfo *map[string]any) *Output

func (*Output) Filter

func (o *Output) Filter() *Output

Filter will filter the signature object

func (*Output) Format

func (o *Output) Format()

func (*Output) Print

func (o *Output) Print()

func (*Output) SetFormat

func (o *Output) SetFormat(format string) *Output

func (*Output) SortBy

func (o *Output) SortBy() *Output

Sort will sort the output by the specified field

func (*Output) SortedKey

func (o *Output) SortedKey(key string) *Output

func (*Output) WithFilter

func (o *Output) WithFilter(filter bool) *Output

Directories

Path Synopsis
* Copyright 2020-2023 Alibaba Group Holding Limited.
* Copyright 2020-2023 Alibaba Group Holding Limited.

Jump to

Keyboard shortcuts

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