k8s

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UseFakeClient added in v0.10.0

func UseFakeClient(k8sClient kubernetes.Interface, argoClient *argocdclient.Clientset)

UseFakeClient is used for testing, if this function is called, NewClient() will return the fake client.

Types

type AllResourceStatus added in v0.8.0

type AllResourceStatus struct {
	Deployment  []ResourceStatus
	StatefulSet []ResourceStatus
	DaemonSet   []ResourceStatus
}

func (*AllResourceStatus) ToStringInterfaceMap added in v0.10.0

func (s *AllResourceStatus) ToStringInterfaceMap() (map[string]interface{}, error)

type Client

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

func (*Client) ApplyConfigMap added in v0.9.0

func (c *Client) ApplyConfigMap(name, namespace string, data, labels map[string]string) (*v1.ConfigMap, error)

func (*Client) ApplySecret added in v0.9.0

func (c *Client) ApplySecret(name, namespace string, data map[string][]byte, labels map[string]string) (*corev1.Secret, error)

func (*Client) CreateDeployment added in v0.9.0

func (c *Client) CreateDeployment(namespace string, deployment *appsv1.Deployment) error

func (*Client) CreateNamespace

func (c *Client) CreateNamespace(namespace string) error

func (*Client) CreatePersistentVolume

func (c *Client) CreatePersistentVolume(option *PVOption) error

func (*Client) CreatePersistentVolumeClaim added in v0.8.0

func (c *Client) CreatePersistentVolumeClaim(opt *PVCOption) error

func (*Client) CreateService added in v0.9.0

func (c *Client) CreateService(namespace string, service *corev1.Service) error

func (*Client) DeleteDeployment added in v0.8.0

func (c *Client) DeleteDeployment(namespace, deployName string) error

func (*Client) DeleteNamespace

func (c *Client) DeleteNamespace(namespace string) error

func (*Client) DeletePersistentVolume added in v0.8.0

func (c *Client) DeletePersistentVolume(pvName string) error

func (*Client) DeletePersistentVolumeClaim added in v0.8.0

func (c *Client) DeletePersistentVolumeClaim(namespace, pvcName string) error

func (*Client) DeleteService added in v0.8.0

func (c *Client) DeleteService(namespace, serviceName string) error

func (*Client) DescribeArgocdApp

func (c *Client) DescribeArgocdApp(app *argocdv1alpha1.Application) map[string]interface{}

func (*Client) GetArgocdApplication

func (c *Client) GetArgocdApplication(namespace, name string) (*argocdv1alpha1.Application, error)

func (*Client) GetConfigMap added in v0.9.0

func (c *Client) GetConfigMap(name, namespace string) (*v1.ConfigMap, error)

func (*Client) GetDaemonset

func (c *Client) GetDaemonset(namespace, name string) (*appsv1.DaemonSet, error)

func (*Client) GetDeployment

func (c *Client) GetDeployment(namespace, name string) (*appsv1.Deployment, error)

func (*Client) GetNamespace

func (c *Client) GetNamespace(namespace string) (*corev1.Namespace, error)

func (*Client) GetResourceStatus added in v0.8.0

func (c *Client) GetResourceStatus(nameSpace string, anFilter, labelFilter map[string]string) (*AllResourceStatus, error)

GetResourceStatus get all resource state by input nameSpace and filtermap

func (*Client) GetSecret added in v0.9.0

func (c *Client) GetSecret(namespace, name string) (map[string]string, error)

func (*Client) GetService

func (c *Client) GetService(namespace, name string) (*corev1.Service, error)

func (*Client) GetStatefulset

func (c *Client) GetStatefulset(namespace, name string) (*appsv1.StatefulSet, error)

func (*Client) IsArgocdApplicationReady

func (c *Client) IsArgocdApplicationReady(application *argocdv1alpha1.Application) bool

func (*Client) IsDevstreamNS added in v0.8.0

func (c *Client) IsDevstreamNS(namespace string) (bool, error)

Check whether the given namespace is created by dtm If the given namespace has label "created_by=DevStream", we'll control it. 1. The specified namespace is created by dtm, then it should be deleted when errors are encountered during creation or `dtm delete`. 2. The specified namespace is controlled by user, maybe they want to deploy plugins in an existing namespace or other situations, then we should not delete this namespace.

func (*Client) IsNamespaceExists

func (c *Client) IsNamespaceExists(namespace string) (bool, error)

func (*Client) ListArgocdApplications

func (c *Client) ListArgocdApplications(namespace string) ([]argocdv1alpha1.Application, error)

func (*Client) ListDaemonsetsWithLabel added in v0.8.0

func (c *Client) ListDaemonsetsWithLabel(namespace string, labeFilter map[string]string) ([]appsv1.DaemonSet, error)

func (*Client) ListDeploymentsWithLabel added in v0.8.0

func (c *Client) ListDeploymentsWithLabel(namespace string, labelFilter map[string]string) ([]appsv1.Deployment, error)

func (*Client) ListStatefulsetsWithLabel added in v0.8.0

func (c *Client) ListStatefulsetsWithLabel(namespace string, labelFilter map[string]string) ([]appsv1.StatefulSet, error)

func (*Client) UpsertNameSpace added in v0.9.0

func (c *Client) UpsertNameSpace(nameSpace string) error

func (*Client) WaitForDeploymentReady added in v0.8.0

func (c *Client) WaitForDeploymentReady(retry int, namespace, deployName string) error

Wait for deployment to be ready after creating

type K8sAPI added in v0.10.0

type K8sAPI interface {
	// secret API
	GetSecret(namespace, name string) (map[string]string, error)
	ApplySecret(name, namespace string, data map[string][]byte, labels map[string]string) (*corev1.Secret, error)
	// service API
	CreateService(namespace string, service *corev1.Service) error
	DeleteService(namespace, serviceName string) error
	GetService(namespace, name string) (*corev1.Service, error)
	// storage API
	CreatePersistentVolume(option *PVOption) error
	DeletePersistentVolume(pvName string) error
	CreatePersistentVolumeClaim(opt *PVCOption) error
	DeletePersistentVolumeClaim(namespace, pvcName string) error
	// resource API
	GetResourceStatus(nameSpace string, anFilter, labelFilter map[string]string) (*AllResourceStatus, error)
	ListDeploymentsWithLabel(namespace string, labelFilter map[string]string) ([]appsv1.Deployment, error)
	GetDeployment(namespace, name string) (*appsv1.Deployment, error)
	CreateDeployment(namespace string, deployment *appsv1.Deployment) error
	WaitForDeploymentReady(retry int, namespace, deployName string) error
	DeleteDeployment(namespace, deployName string) error
	ListDaemonsetsWithLabel(namespace string, labeFilter map[string]string) ([]appsv1.DaemonSet, error)
	GetStatefulset(namespace, name string) (*appsv1.StatefulSet, error)
	// namespace API
	UpsertNameSpace(nameSpace string) error
	GetNamespace(namespace string) (*corev1.Namespace, error)
	IsDevstreamNS(namespace string) (bool, error)
	CreateNamespace(namespace string) error
	DeleteNamespace(namespace string) error
	IsNamespaceExists(namespace string) (bool, error)
	// configmap API
	ApplyConfigMap(name, namespace string, data, labels map[string]string) (*corev1.ConfigMap, error)
	GetConfigMap(name, namespace string) (*corev1.ConfigMap, error)
	// argocd API
	ListArgocdApplications(namespace string) ([]argocdv1alpha1.Application, error)
	GetArgocdApplication(namespace, name string) (*argocdv1alpha1.Application, error)
	IsArgocdApplicationReady(application *argocdv1alpha1.Application) bool
	DescribeArgocdApp(app *argocdv1alpha1.Application) map[string]interface{}
}

func NewClient

func NewClient() (K8sAPI, error)

type MockClient added in v0.10.0

type MockClient struct {
	GetSecretError error
	GetSecretValue map[string]string
}

func (*MockClient) ApplyConfigMap added in v0.10.0

func (m *MockClient) ApplyConfigMap(name, namespace string, data, labels map[string]string) (*corev1.ConfigMap, error)

func (*MockClient) ApplySecret added in v0.10.0

func (m *MockClient) ApplySecret(name, namespace string, data map[string][]byte, labels map[string]string) (*corev1.Secret, error)

func (*MockClient) CreateDeployment added in v0.10.0

func (m *MockClient) CreateDeployment(namespace string, deployment *appsv1.Deployment) error

func (*MockClient) CreateNamespace added in v0.10.0

func (m *MockClient) CreateNamespace(namespace string) error

func (*MockClient) CreatePersistentVolume added in v0.10.0

func (m *MockClient) CreatePersistentVolume(option *PVOption) error

func (*MockClient) CreatePersistentVolumeClaim added in v0.10.0

func (m *MockClient) CreatePersistentVolumeClaim(opt *PVCOption) error

func (*MockClient) CreateService added in v0.10.0

func (m *MockClient) CreateService(namespace string, service *corev1.Service) error

func (*MockClient) DeleteDeployment added in v0.10.0

func (m *MockClient) DeleteDeployment(namespace, deployName string) error

func (*MockClient) DeleteNamespace added in v0.10.0

func (m *MockClient) DeleteNamespace(namespace string) error

func (*MockClient) DeletePersistentVolume added in v0.10.0

func (m *MockClient) DeletePersistentVolume(pvName string) error

func (*MockClient) DeletePersistentVolumeClaim added in v0.10.0

func (m *MockClient) DeletePersistentVolumeClaim(namespace, pvcName string) error

func (*MockClient) DeleteService added in v0.10.0

func (m *MockClient) DeleteService(namespace, serviceName string) error

func (*MockClient) DescribeArgocdApp added in v0.10.0

func (m *MockClient) DescribeArgocdApp(app *argocdv1alpha1.Application) map[string]interface{}

func (*MockClient) GetArgocdApplication added in v0.10.0

func (m *MockClient) GetArgocdApplication(namespace, name string) (*argocdv1alpha1.Application, error)

func (*MockClient) GetConfigMap added in v0.10.0

func (m *MockClient) GetConfigMap(name, namespace string) (*corev1.ConfigMap, error)

func (*MockClient) GetDeployment added in v0.10.0

func (m *MockClient) GetDeployment(namespace, name string) (*appsv1.Deployment, error)

func (*MockClient) GetNamespace added in v0.10.0

func (m *MockClient) GetNamespace(namespace string) (*corev1.Namespace, error)

func (*MockClient) GetResourceStatus added in v0.10.0

func (m *MockClient) GetResourceStatus(nameSpace string, anFilter, labelFilter map[string]string) (*AllResourceStatus, error)

func (*MockClient) GetSecret added in v0.10.0

func (m *MockClient) GetSecret(namespace, name string) (map[string]string, error)

func (*MockClient) GetService added in v0.10.0

func (m *MockClient) GetService(namespace, name string) (*corev1.Service, error)

func (*MockClient) GetStatefulset added in v0.10.0

func (m *MockClient) GetStatefulset(namespace, name string) (*appsv1.StatefulSet, error)

func (*MockClient) IsArgocdApplicationReady added in v0.10.0

func (m *MockClient) IsArgocdApplicationReady(application *argocdv1alpha1.Application) bool

func (*MockClient) IsDevstreamNS added in v0.10.0

func (m *MockClient) IsDevstreamNS(namespace string) (bool, error)

func (*MockClient) IsNamespaceExists added in v0.10.0

func (m *MockClient) IsNamespaceExists(namespace string) (bool, error)

func (*MockClient) ListArgocdApplications added in v0.10.0

func (m *MockClient) ListArgocdApplications(namespace string) ([]argocdv1alpha1.Application, error)

func (*MockClient) ListDaemonsetsWithLabel added in v0.10.0

func (m *MockClient) ListDaemonsetsWithLabel(namespace string, labeFilter map[string]string) ([]appsv1.DaemonSet, error)

func (*MockClient) ListDeploymentsWithLabel added in v0.10.0

func (m *MockClient) ListDeploymentsWithLabel(namespace string, labelFilter map[string]string) ([]appsv1.Deployment, error)

func (*MockClient) UpsertNameSpace added in v0.10.0

func (m *MockClient) UpsertNameSpace(nameSpace string) error

func (*MockClient) WaitForDeploymentReady added in v0.10.0

func (m *MockClient) WaitForDeploymentReady(retry int, namespace, deployName string) error

type PVCOption added in v0.8.0

type PVCOption struct {
	Name             string
	NameSpace        string
	StorageClassName string

	AccessMode []corev1.PersistentVolumeAccessMode

	Requirement corev1.ResourceRequirements
}

type PVOption

type PVOption struct {
	Name             string
	StorageClassName string

	// ReadWriteOnce PersistentVolumeAccessMode = "ReadWriteOnce"
	// ReadOnlyMany PersistentVolumeAccessMode = "ReadOnlyMany"
	// ReadWriteMany PersistentVolumeAccessMode = "ReadWriteMany"
	// ReadWriteOncePod PersistentVolumeAccessMode = "ReadWriteOncePod"
	AccessMode []corev1.PersistentVolumeAccessMode

	// <binarySI>        ::= Ki | Mi | Gi | Ti | Pi | Ei
	//   (International System of units; See: https://physics.nist.gov/cuu/Units/binary.html)
	// <decimalSI>       ::= m | "" | k | M | G | T | P | E
	//   (Note that 1024 = 1Ki but 1000 = 1k; I didn't choose the capitalization.)
	// eg: 10Gi 200Mi
	Capacity string

	//PersistentVolumeReclaimRecycle PersistentVolumeReclaimPolicy = "Recycle"
	//PersistentVolumeReclaimDelete PersistentVolumeReclaimPolicy = "Delete"
	//PersistentVolumeReclaimRetain PersistentVolumeReclaimPolicy = "Retain"
	PersistentVolumeReclaimPolicy corev1.PersistentVolumeReclaimPolicy
	HostPath                      string
}

type ResourceStatus added in v0.8.0

type ResourceStatus struct {
	Name  string
	Ready bool
}

Jump to

Keyboard shortcuts

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