cluster

package
v0.5.7-rc.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingAPIVersion                   = errors.New("apiVersion is required")
	ErrMissingKind                         = errors.New("kind is required")
	ErrMissingClusterEntry                 = errors.New("at least one cluster entry is required")
	ErrMissingUserEntry                    = errors.New("at least one user entry is required")
	ErrMissingClusterName                  = errors.New("cluster name is required")
	ErrMissingClusterServer                = errors.New("cluster server is required")
	ErrBothInsecureAndCertificateAuthority = errors.New("certificate-authority-data and insecure-skip-tls-verify couldn't both be set")
	ErrMissingCertificateAuthority         = errors.New("certificate-authority-data is required")
	ErrInvalidCertificateAuthority         = errors.New("certificate-authority-data is invalid")
	ErrClusterServerConnectivity           = errors.New("cannot connect to the cluster server")
	ErrBuildClientConfig                   = errors.New(
		"failed to create client config from provided KubeConfig",
	)
	ErrCreateClientSet  = errors.New("failed to create clientset")
	ErrGetServerVersion = errors.New("failed to connect to the cluster")
)

Functions

func SanitizeUnstructuredCluster

func SanitizeUnstructuredCluster(
	ctx context.Context,
	cluster *unstructured.Unstructured,
) (*unstructured.Unstructured, error)

SanitizeUnstructuredCluster masks sensitive information within a Unstructured cluster object, such as user credentials and certificate data.

func SortUnstructuredList

func SortUnstructuredList(
	unList *unstructured.UnstructuredList,
	criteria SortCriteria,
	descending bool,
) (*unstructured.UnstructuredList, error)

SortUnstructuredList returns a sorted unstructured.UnstructuredList based on criteria

Types

type Cluster

type Cluster struct {
	Insecure                 bool   `yaml:"insecure-skip-tls-verify,omitempty"`
	Server                   string `yaml:"server"`
	CertificateAuthorityData string `yaml:"certificate-authority-data,omitempty"`
}

Cluster contains the cluster information

type ClusterEntry

type ClusterEntry struct {
	Name    string  `yaml:"name"`
	Cluster Cluster `yaml:"cluster"`
}

ClusterEntry represents each cluster entry in kubeconfig

type ClusterManager

type ClusterManager struct{}

func NewClusterManager

func NewClusterManager() *ClusterManager

NewClusterManager returns a new ClusterManager object

func (*ClusterManager) CountCluster

func (c *ClusterManager) CountCluster(
	ctx context.Context,
	client *multicluster.MultiClusterClient,
	config *rest.Config,
) (*ClusterSummary, error)

CountCluster returns the summary of clusters by their health status

func (*ClusterManager) CreateCluster

func (c *ClusterManager) CreateCluster(
	ctx context.Context,
	client *multicluster.MultiClusterClient,
	name, displayName, description, kubeconfig string,
) (*unstructured.Unstructured, error)

CreateCluster creates a new Cluster resource in the hub cluster and returns the created unstructured Cluster object

func (*ClusterManager) DeleteCluster

func (c *ClusterManager) DeleteCluster(
	ctx context.Context,
	client *multicluster.MultiClusterClient,
	name string,
) error

DeleteCluster deletes the cluster by name

func (*ClusterManager) GetCluster

GetCluster returns the unstructured Cluster object for a given cluster

func (*ClusterManager) GetNamespace

func (c *ClusterManager) GetNamespace(
	ctx context.Context,
	client *multicluster.MultiClusterClient,
	namespace string,
) (*unstructured.Unstructured, error)

GetNamespaceForCluster returns the yaml byte array for a given cluster

func (*ClusterManager) GetNamespaceYAML

func (c *ClusterManager) GetNamespaceYAML(
	ctx context.Context,
	client *multicluster.MultiClusterClient,
	namespace string,
) ([]byte, error)

GetNamespaceForCluster returns the yaml byte array for a given cluster

func (*ClusterManager) GetYAMLForCluster

func (c *ClusterManager) GetYAMLForCluster(
	ctx context.Context,
	client *multicluster.MultiClusterClient,
	name string,
) ([]byte, error)

GetYAMLForCluster returns the yaml byte array for a given cluster

func (*ClusterManager) ListCluster

func (c *ClusterManager) ListCluster(
	ctx context.Context,
	client *multicluster.MultiClusterClient,
	orderBy SortCriteria,
	descending bool,
) (*unstructured.UnstructuredList, error)

ListCluster returns the full list of clusters in a specific order

func (*ClusterManager) ListClusterName

func (c *ClusterManager) ListClusterName(ctx context.Context, client *multicluster.MultiClusterClient, orderBy SortCriteria, descending bool) ([]string, error)

ListClusterName retrieves a list of cluster names based on the specified sorting criteria and order.

func (*ClusterManager) SanitizeKubeConfigFor

func (c *ClusterManager) SanitizeKubeConfigFor(config *KubeConfig)

SanitizeKubeConfigFor masks sensitive information within a KubeConfig object, such as user credentials and certificate data.

func (*ClusterManager) SanitizeKubeConfigWithYAML

func (c *ClusterManager) SanitizeKubeConfigWithYAML(
	ctx context.Context,
	plain string,
) (sanitize string, err error)

SanitizeKubeConfigWithYAML takes a plain KubeConfig YAML string and returns a sanitized version with sensitive information masked.

func (*ClusterManager) UpdateCredential

func (c *ClusterManager) UpdateCredential(
	ctx context.Context,
	client *multicluster.MultiClusterClient,
	name, kubeconfig string,
) (*unstructured.Unstructured, error)

UpdateCredential updates cluster credential by name and a new kubeconfig

func (*ClusterManager) UpdateMetadata

func (c *ClusterManager) UpdateMetadata(
	ctx context.Context,
	client *multicluster.MultiClusterClient,
	name, displayName, description string,
) (*unstructured.Unstructured, error)

UpdateMetadata updates cluster by name with a full payload

func (*ClusterManager) ValidateKubeConfigFor

func (c *ClusterManager) ValidateKubeConfigFor(
	ctx context.Context,
	config *KubeConfig,
) (string, error)

ValidateKubeConfigFor validates the provided KubeConfig.

func (*ClusterManager) ValidateKubeConfigWithYAML

func (c *ClusterManager) ValidateKubeConfigWithYAML(
	ctx context.Context,
	plain string,
) (string, error)

ValidateKubeConfigWithYAML unmarshals YAML content into KubeConfig and validates it.

type ClusterSummary

type ClusterSummary struct {
	TotalCount        int      `json:"totalCount"`
	HealthyCount      int      `json:"healthyCount"`
	HealthyClusters   []string `json:"healthyClusters"`
	UnhealthyCount    int      `json:"unhealthyCount"`
	UnhealthyClusters []string `json:"unhealthyClusters"`
}

type Context

type Context struct {
	Cluster string `yaml:"cluster"`
	User    string `yaml:"user"`
}

Context contains the context information

type ContextEntry

type ContextEntry struct {
	Name    string  `yaml:"name"`
	Context Context `yaml:"context"`
}

ContextEntry represents each context entry in kubeconfig

type KubeConfig

type KubeConfig struct {
	APIVersion     string         `yaml:"apiVersion"`
	Kind           string         `yaml:"kind"`
	Clusters       []ClusterEntry `yaml:"clusters"`
	Contexts       []ContextEntry `yaml:"contexts"`
	CurrentContext string         `yaml:"current-context"`
	Users          []UserEntry    `yaml:"users"`
}

KubeConfig represents the structure of a kubeconfig file

type SortCriteria

type SortCriteria int
const (
	ByTimestamp SortCriteria = iota
	ByName
)

type User

type User struct {
	ClientCertificateData string `yaml:"client-certificate-data,omitempty"`
	ClientKeyData         string `yaml:"client-key-data,omitempty"`
	Token                 string `yaml:"token,omitempty"`
	Username              string `yaml:"username,omitempty"`
	Password              string `yaml:"password,omitempty"`
}

User contains the user information

type UserEntry

type UserEntry struct {
	Name string `yaml:"name"`
	User User   `yaml:"user"`
}

UserEntry represents each user entry in kubeconfig

Jump to

Keyboard shortcuts

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