common

package
v0.0.0-...-1a511a4 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// k8s annotations for create pod
	YUNION_CNI_NETWORK_ANNOTATION = "cni.yunion.io/network"
	YUNION_CNI_IPADDR_ANNOTATION  = "cni.yunion.io/ip"

	YUNION_LB_NETWORK_ANNOTATION = "loadbalancer.yunion.io/network"
)

Variables

This section is empty.

Functions

func AddObjectMetaDefaultLabel

func AddObjectMetaDefaultLabel(meta *metav1.ObjectMeta) *metav1.ObjectMeta

func AddObjectMetaRunLabel

func AddObjectMetaRunLabel(meta *metav1.ObjectMeta) *metav1.ObjectMeta

func CreateService

func CreateService(req *Request, svc *v1.Service) (*v1.Service, error)

func CreateServiceByOption

func CreateServiceByOption(req *Request, objMeta *metav1.ObjectMeta, opt *api.ServiceCreateOption) (*v1.Service, error)

func CreateServiceIfNotExist

func CreateServiceIfNotExist(req *Request, objMeta *metav1.ObjectMeta, opt *api.ServiceCreateOption) (*v1.Service, error)

func EqualIgnoreHash

func EqualIgnoreHash(template1, template2 v1.PodTemplateSpec) bool

EqualIgnoreHash returns true if two given podTemplateSpec are equal, ignoring the diff in value of Labels[pod-template-hash] We ignore pod-template-hash because the hash result would be different upon podTemplateSpec API changes (e.g. the addition of a new field will cause the hash code to change) Note that we assume input podTemplateSpecs contain non-empty labels

func FilterDeploymentPodsByOwnerReference

func FilterDeploymentPodsByOwnerReference(deployment *apps.Deployment, allRS []*apps.ReplicaSet,
	allPods []*v1.Pod) []*v1.Pod

FilterPodsByControllerResource returns a subset of pods controlled by given deployment.

func FilterPodsByControllerRef

func FilterPodsByControllerRef(owner metav1.Object, allPods []*v1.Pod) []*v1.Pod

FilterPodsByControllerRef returns a subset of pods controlled by given controller resource, excluding deployments.

func FilterPodsForJob

func FilterPodsForJob(job *batch.Job, pods []*v1.Pod) []*v1.Pod

func GenerateName

func GenerateName(base string) string

func GetConfigMapsForPod

func GetConfigMapsForPod(pod *v1.Pod, cfgs []*v1.ConfigMap) []*v1.ConfigMap

func GetContainerImages

func GetContainerImages(podTemplate *v1.PodSpec) []api.ContainerImage

GetContainerImages returns container image strings from the given pod spec.

func GetContainerNames

func GetContainerNames(podTemplate *v1.PodSpec) []string

GetContainerNames returns the container image name without the version number from the given pod spec.

func GetExternalEndpoints

func GetExternalEndpoints(service *v1.Service) []api.Endpoint

GetExternalEndpoints returns endpoints that are externally reachable for a service.

func GetInitContainerImages

func GetInitContainerImages(podTemplate *v1.PodSpec) []api.ContainerImage

GetInitContainerImages returns init container image strings from the given pod spec.

func GetInitContainerNames

func GetInitContainerNames(podTemplate *v1.PodSpec) []string

GetInitContainerNames returns the init container image name without the version number from the given pod spec.

func GetInternalEndpoint

func GetInternalEndpoint(serviceName, namespace string, ports []v1.ServicePort) api.Endpoint

GetInternalEndpoint returns internal endpoint name for the given service properties, e.g., "my-service.namespace 80/TCP" or "my-service 53/TCP,53/UDP".

func GetK8sObjectCreateMeta

func GetK8sObjectCreateMeta(data jsonutils.JSONObject) (*metav1.ObjectMeta, error)

func GetK8sObjectCreateMetaByRequest

func GetK8sObjectCreateMetaByRequest(req *Request) (*metav1.ObjectMeta, error)

func GetK8sObjectCreateMetaWithLabel

func GetK8sObjectCreateMetaWithLabel(req *Request) (*metav1.ObjectMeta, *metav1.LabelSelector, error)

func GetPodConfigMapVolumes

func GetPodConfigMapVolumes(pod *v1.Pod) []v1.Volume

func GetPodInfo

func GetPodInfo(current int32, desired *int32, pods []*v1.Pod) api.PodInfo

GetPodInfo returns aggregate information about a group of pods.

func GetPodSecretVolumes

func GetPodSecretVolumes(pod *v1.Pod) []v1.Volume

func GetPodTemplate

func GetPodTemplate(req *Request, wrapperKey string) (*v1.PodTemplateSpec, error)

func GetSecretsForPod

func GetSecretsForPod(pod *v1.Pod, ss []*v1.Secret) []*v1.Secret

func GetSelectorByObjectMeta

func GetSelectorByObjectMeta(meta *metav1.ObjectMeta) *metav1.LabelSelector

func GetServiceFromOption

func GetServiceFromOption(objMeta *metav1.ObjectMeta, opt *api.ServiceCreateOption) *v1.Service

func GetServicePorts

func GetServicePorts(apiPorts []v1.ServicePort) []api.ServicePort

GetServicePorts returns human readable name for the given service ports list.

func GetServicePortsByMapping

func GetServicePortsByMapping(ps []api.PortMapping) []v1.ServicePort

func JsonDecode

func JsonDecode(data jsonutils.JSONObject, obj interface{}) error

func ListResource2JSONWithKey

func ListResource2JSONWithKey(list ListResource, key string) map[string]interface{}

func NewDataSelectQuery

func NewDataSelectQuery(query jsonutils.JSONObject) *dataselect.DataSelectQuery

func ToConfigMap

func ToConfigMap(configMap *v1.ConfigMap, cluster api.ICluster) api.ConfigMap

func ToConfigMaps

func ToConfigMaps(cfgs []*v1.ConfigMap, cluster api.ICluster) []api.ConfigMap

func ToSecret

func ToSecret(secret *v1.Secret, cluster api.ICluster) *api.Secret

func ToSecrets

func ToSecrets(ss []*v1.Secret, cluster api.ICluster) []api.Secret

func ValidateK8sResourceCreateData

func ValidateK8sResourceCreateData(req *Request, kind string, inNamespace bool) error

Types

type BaseList

type BaseList struct {
	*dataselect.ListMeta
	Cluster api.ICluster
}

func NewBaseList

func NewBaseList(cluster api.ICluster) *BaseList

func (*BaseList) GetCluster

func (l *BaseList) GetCluster() api.ICluster

type ClusterRoleBindingListChannel

type ClusterRoleBindingListChannel struct {
	List  chan []*rbac.ClusterRoleBinding
	Error chan error
}

ClusterRoleBindingListChannel is a list and error channels to ClusterRoleBindings.

func GetClusterRoleBindingListChannel

func GetClusterRoleBindingListChannel(indexer *client.CacheFactory) ClusterRoleBindingListChannel

type ClusterRoleListChannel

type ClusterRoleListChannel struct {
	List  chan []*rbac.ClusterRole
	Error chan error
}

ClusterRoleListChannel is a list and error channels to ClusterRoles.

func GetClusterRoleListChannel

func GetClusterRoleListChannel(indexer *client.CacheFactory) ClusterRoleListChannel

type ConfigMapListChannel

type ConfigMapListChannel struct {
	List  chan []*v1.ConfigMap
	Error chan error
}

ConfigMapListChannel is a list and error channels to ConfigMaps.

func GetConfigMapListChannel

func GetConfigMapListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) ConfigMapListChannel

func GetConfigMapListChannelWithOptions

func GetConfigMapListChannelWithOptions(indexer *client.CacheFactory, nsQuery *NamespaceQuery, options labels.Selector) ConfigMapListChannel

type DaemonSetListChannel

type DaemonSetListChannel struct {
	//List  chan []*apps.DaemonSet
	List  chan []*apps.DaemonSet
	Error chan error
}

func GetDaemonSetListChannel

func GetDaemonSetListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) DaemonSetListChannel

type DeploymentListChannel

type DeploymentListChannel struct {
	List  chan []*apps.Deployment
	Error chan error
}

func GetDeploymentListChannel

func GetDeploymentListChannel(indexer *client.CacheFactory,
	nsQuery *NamespaceQuery) DeploymentListChannel

type EndpointListChannel

type EndpointListChannel struct {
	List  chan []*v1.Endpoints
	Error chan error
}

func GetEndpointListChannel

func GetEndpointListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) EndpointListChannel

func GetEndpointListChannelWithOptions

func GetEndpointListChannelWithOptions(indexer *client.CacheFactory,
	nsQuery *NamespaceQuery, opt labels.Selector) EndpointListChannel

type EventList

type EventList struct {
	*BaseList
	// List of events from given namespace.
	Events []api.Event `json:"events"`
}

EventList is an events response structure.

func (*EventList) Append

func (l *EventList) Append(obj interface{})

type EventListChannel

type EventListChannel struct {
	List  chan []*v1.Event
	Error chan error
}

func GetEventListChannel

func GetEventListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) EventListChannel

func GetEventListChannelWithOptions

func GetEventListChannelWithOptions(indexer *client.CacheFactory,
	nsQuery *NamespaceQuery, options labels.Selector) EventListChannel

type HorizontalPodAutoscalerListChannel

type HorizontalPodAutoscalerListChannel struct {
	List  chan []*autoscaling.HorizontalPodAutoscaler
	Error chan error
}

HorizontalPodAutoscalerListChannel is a list and error channels.

func GetHorizontalPodAutoscalerListChannel

func GetHorizontalPodAutoscalerListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) HorizontalPodAutoscalerListChannel

type JobListChannel

type JobListChannel struct {
	List  chan []*batch.Job
	Error chan error
}

func GetJobListChannel

func GetJobListChannel(indexer *client.CacheFactory,
	nsQuery *NamespaceQuery) JobListChannel

type LimitRangeListChannel

type LimitRangeListChannel struct {
	List  chan []*v1.LimitRange
	Error chan error
}

func GetLimitRangeListChannel

func GetLimitRangeListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) LimitRangeListChannel

type ListResource

type ListResource interface {
	api.IListMeta

	GetResponseData() interface{}
}

type NamespaceListChannel

type NamespaceListChannel struct {
	List  chan []*v1.Namespace
	Error chan error
}

func GetNamespaceListChannel

func GetNamespaceListChannel(indexer *client.CacheFactory) NamespaceListChannel

type NamespaceQuery

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

func NewNamespaceQuery

func NewNamespaceQuery(namespaces ...string) *NamespaceQuery

func NewSameNamespaceQuery

func NewSameNamespaceQuery(namespace string) *NamespaceQuery

NewSameNamespaceQuery creates new namespace query that queries single namespace.

func (*NamespaceQuery) Matches

func (n *NamespaceQuery) Matches(namespace string) bool

func (*NamespaceQuery) ToRequestParam

func (n *NamespaceQuery) ToRequestParam() string

type NetworkConfig

type NetworkConfig struct {
	Network string `json:"network"`
	Address string `json:"address"`
}

func (NetworkConfig) ToPodAnnotation

func (n NetworkConfig) ToPodAnnotation() map[string]string

type NodeListChannel

type NodeListChannel struct {
	List  chan []*v1.Node
	Error chan error
}

func GetNodeListChannel

func GetNodeListChannel(indexer *client.CacheFactory) NodeListChannel

type PersistentVolumeClaimListChannel

type PersistentVolumeClaimListChannel struct {
	List  chan []*v1.PersistentVolumeClaim
	Error chan error
}

PersistentVolumeClaimListChannel is a list and error channels to PersistentVolumeClaims.

func GetPersistentVolumeClaimListChannel

func GetPersistentVolumeClaimListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) PersistentVolumeClaimListChannel

type PersistentVolumeListChannel

type PersistentVolumeListChannel struct {
	List  chan []*v1.PersistentVolume
	Error chan error
}

PersistentVolumeListChannel is a list and error channels to PersistentVolumes.

func GetPersistentVolumeListChannel

func GetPersistentVolumeListChannel(indexer *client.CacheFactory) PersistentVolumeListChannel

type PodListChannel

type PodListChannel struct {
	List  chan []*v1.Pod
	Error chan error
}

PodListChannel is a list and error channels to Nodes

func GetPodListChannel

func GetPodListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) PodListChannel

func GetPodListChannelWithOptions

func GetPodListChannelWithOptions(indexer *client.CacheFactory, nsQuery *NamespaceQuery, options labels.Selector) PodListChannel

type ReplicaSetListChannel

type ReplicaSetListChannel struct {
	List  chan []*apps.ReplicaSet
	Error chan error
}

func GetReplicaSetListChannel

func GetReplicaSetListChannel(indexer *client.CacheFactory,
	nsQuery *NamespaceQuery) ReplicaSetListChannel

func GetReplicaSetListChannelWithOptions

func GetReplicaSetListChannelWithOptions(indexer *client.CacheFactory, nsQuery *NamespaceQuery,
	options labels.Selector) ReplicaSetListChannel

type ReplicationControllerListChannel

type ReplicationControllerListChannel struct {
	List  chan []*v1.ReplicationController
	Error chan error
}

func GetReplicationControllerListChannel

func GetReplicationControllerListChannel(indexer *client.CacheFactory,
	nsQuery *NamespaceQuery) ReplicationControllerListChannel

type Request

type Request struct {
	Cluster         *models.SCluster
	ClusterManager  *yclient.ClusterManager
	K8sClient       client.Interface
	K8sAdminClient  client.Interface
	K8sConfig       *rest.Config
	K8sAdminConfig  *rest.Config
	UserCred        mcclient.TokenCredential
	Query           *jsonutils.JSONDict
	Data            *jsonutils.JSONDict
	Context         context.Context
	KubeAdminConfig string
}

func (*Request) AllowListItems

func (r *Request) AllowListItems() bool

func (*Request) DataUnmarshal

func (r *Request) DataUnmarshal(input interface{}) error

func (*Request) GetCluster

func (r *Request) GetCluster() *models.SCluster

func (*Request) GetDefaultNamespace

func (r *Request) GetDefaultNamespace() string

func (*Request) GetHandler

func (r *Request) GetHandler() yclient.ResourceHandler

GetHandler return generic kubenretes CRUD resource handler

func (*Request) GetHelmClient

func (r *Request) GetHelmClient(namespace string) (*helm.Client, error)

func (*Request) GetIndexer

func (r *Request) GetIndexer() *yclient.CacheFactory

func (*Request) GetK8sAdminClient

func (r *Request) GetK8sAdminClient() client.Interface

func (*Request) GetK8sAdminRestConfig

func (r *Request) GetK8sAdminRestConfig() *rest.Config

func (*Request) GetK8sClient

func (r *Request) GetK8sClient() client.Interface

func (*Request) GetK8sManager

func (r *Request) GetK8sManager() *yclient.ClusterManager

func (*Request) GetK8sRestConfig

func (r *Request) GetK8sRestConfig() *rest.Config

func (*Request) GetNamespaceByData

func (r *Request) GetNamespaceByData() (string, error)

func (*Request) GetNamespaceByQuery

func (r *Request) GetNamespaceByQuery() (string, error)
func (r *Request) GetGenericClient() (*k8sclient.GenericClient, error) {
	return k8sclient.NewGeneric(r.KubeAdminConfig)
}

func (*Request) GetNamespaceQuery

func (r *Request) GetNamespaceQuery() *NamespaceQuery

func (*Request) GetParams

func (r *Request) GetParams() map[string]string

func (*Request) GetVerberClient

func (r *Request) GetVerberClient() yclient.ResourceHandler

func (*Request) IsClusterOwner

func (r *Request) IsClusterOwner() bool

func (*Request) IsK8sResourceExists

func (r *Request) IsK8sResourceExists(kind string, namespace string, id string) (bool, error)

func (*Request) ShowAllNamespace

func (r *Request) ShowAllNamespace() bool

func (*Request) ToQuery

func (r *Request) ToQuery() *dataselect.DataSelectQuery

type ResourceChannels

type ResourceChannels struct {
	// List and error channels to Replication Controllers.
	ReplicationControllerList ReplicationControllerListChannel

	// List and error channels to Replica Sets
	ReplicaSetList ReplicaSetListChannel

	// List and error channels to Deployments
	DeploymentList DeploymentListChannel

	// List and error channels to Daemon Sets
	DaemonSetList DaemonSetListChannel

	// List and error channels to Jobs.
	JobList JobListChannel

	// List and error channels to Services
	ServiceList ServiceListChannel

	// List and error channels to Endpoints.
	EndpointList EndpointListChannel

	// List and error channels to Pods
	PodList PodListChannel

	// List and error channels to Events.
	EventList EventListChannel

	// List and error channels to LimitRanges.
	LimitRangeList LimitRangeListChannel

	// List and error channels to Nodes.
	NodeList NodeListChannel

	// List and error channels to Namespaces.
	NamespaceList NamespaceListChannel

	// List and error channels to StatefulSets.
	StatefulSetList StatefulSetListChannel

	// List and error channels to ConfigMaps.
	ConfigMapList ConfigMapListChannel

	// List and error channels to Secrets.
	SecretList SecretListChannel

	// List and error channels to PersistentVolumes
	PersistentVolumeList PersistentVolumeListChannel

	// List and error channels to PersistentVolumeClaims
	PersistentVolumeClaimList PersistentVolumeClaimListChannel

	// List and error channels to ResourceQuotas
	ResourceQuotaList ResourceQuotaListChannel

	// List and error channels to HorizontalPodAutoscalers
	HorizontalPodAutoscalerList HorizontalPodAutoscalerListChannel

	// List and error channels to StorageClasses
	StorageClassList StorageClassListChannel

	// List and error channels to Roles
	RoleList RoleListChannel

	// List and error channels to ClusterRoles
	ClusterRoleList ClusterRoleListChannel

	// List and error channels to RoleBindings
	RoleBindingList RoleBindingListChannel

	// List and error channels to ClusterRoleBindings
	ClusterRoleBindingList ClusterRoleBindingListChannel
}

ResourceChannels struct holds channels to resource lists. Each list channel is paired with an error channel which *must* be read sequentially: first read the list channel and then the error channel.

type ResourceQuotaListChannel

type ResourceQuotaListChannel struct {
	List  chan []*v1.ResourceQuota
	Error chan error
}

ResourceQuotaListChannel is a list and error channels to ResourceQuotas.

func GetResourceQuotaListChannel

func GetResourceQuotaListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) ResourceQuotaListChannel

type ResourceStatus

type ResourceStatus struct {
	// Number of resources that are currently in running state.
	Running int `json:"running"`

	// Number of resources that are currently in pending state.
	Pending int `json:"pending"`

	// Number of resources that are in failed state.
	Failed int `json:"failed"`

	// Number of resources that are in succeeded state.
	Succeeded int `json:"succeeded"`
}

ResourceStatus provides basic information about resources status on the list.

type RoleBindingListChannel

type RoleBindingListChannel struct {
	List  chan []*rbac.RoleBinding
	Error chan error
}

RoleBindingListChannel is a list and error channels to RoleBindings.

func GetRoleBindingListChannel

func GetRoleBindingListChannel(indexer *client.CacheFactory) RoleBindingListChannel

type RoleListChannel

type RoleListChannel struct {
	List  chan []*rbac.Role
	Error chan error
}

RoleListChannel is a list and error channels to Roles.

func GetRoleListChannel

func GetRoleListChannel(indexer *client.CacheFactory) RoleListChannel

type SecretListChannel

type SecretListChannel struct {
	List  chan []*v1.Secret
	Error chan error
}

SecretListChannel is a list and error channels to Secrets.

func GetSecretListChannel

func GetSecretListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) SecretListChannel

type ServiceListChannel

type ServiceListChannel struct {
	List  chan []*v1.Service
	Error chan error
}

// IngressListChannel is a list and error channels to Ingresss.

type IngressListChannel struct {
	List  chan []*extensions.Ingress
	Error chan error
}

func GetIngressListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) IngressListChannel {
	return GetIngressListChannelWithOptions(indexer, nsQuery, api.ListEverything)
}

func GetIngressListChannelWithOptions(indexer *client.CacheFactory, nsQuery *NamespaceQuery, options metaV1.ListOptions) IngressListChannel {
	channel := IngressListChannel{
		List:  make(chan []*extensions.Ingress),
		Error: make(chan error),
	}
	go func() {
		list, err := indexer.IngressLister().Ingresses(nsQuery.ToRequestParam()).List(labels.Everything())
		channel.List <- list
		channel.Error <- err
	}()

	return channel
}

func GetServiceListChannel

func GetServiceListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) ServiceListChannel

func GetServiceListChannelWithOptions

func GetServiceListChannelWithOptions(indexer *client.CacheFactory, nsQuery *NamespaceQuery, options labels.Selector) ServiceListChannel

type StatefulSetListChannel

type StatefulSetListChannel struct {
	List  chan []*apps.StatefulSet
	Error chan error
}

StatefulSetListChannel is a list and error channels to Nodes.

func GetStatefulSetListChannel

func GetStatefulSetListChannel(indexer *client.CacheFactory, nsQuery *NamespaceQuery) StatefulSetListChannel

func GetStatefulSetListChannelWithOptions

func GetStatefulSetListChannelWithOptions(indexer *client.CacheFactory, nsQuery *NamespaceQuery, options labels.Selector) StatefulSetListChannel

type StorageClassListChannel

type StorageClassListChannel struct {
	List  chan []*storage.StorageClass
	Error chan error
}

StorageClassListChannel is a list and error channels to storage classes.

func GetStorageClassListChannel

func GetStorageClassListChannel(indexer *client.CacheFactory) StorageClassListChannel

Jump to

Keyboard shortcuts

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