Documentation
¶
Index ¶
- Constants
- Variables
- func FormatContainerState(stage corev1.ContainerState) string
- func GetContainerFromPodSpec(spec v1.PodSpec, name string) *v1.Container
- func GetContainerFromPodTemplate(temp v1.PodTemplateSpec, name string) *v1.Container
- func GetPodContainerStatusByName(pod *corev1.Pod, containerName string) *corev1.ContainerStatus
- func GetPrimaryContainerName(spec v1.PodSpec) string
- func HoldContaienrCmd(d time.Duration) []string
- func InjectContainerEnvVars(c *v1.Container, envs []v1.EnvVar)
- func InjectJobAnnotations(pod *v1.Job, annotations map[string]string)
- func InjectJobLabels(pod *v1.Job, labels map[string]string)
- func InjectPodConfigMapVolume(pod *v1.PodSpec, cs ...*v1.ConfigMap)
- func InjectPodEnvVars(pod *v1.PodSpec, envs []v1.EnvVar)
- func InjectPodSecretVolume(pod *v1.PodSpec, ss ...*v1.Secret)
- func InjectPodTemplateSpecAnnotations(pod *v1.PodTemplateSpec, key, value string)
- func InjectPodTemplateSpecLabel(pod *v1.PodTemplateSpec, key, value string)
- func NewConfigMapVolume(cm *v1.ConfigMap) v1.Volume
- func NewSecretVolume(secret *v1.Secret) v1.Volume
- func NewVolumeMount(readonly bool, vs []MountVolume) []v1.VolumeMount
- func WaitForContainerRunning(containerName string, printer terminal.Logger) watchtools.ConditionFunc
- type Client
- func (c *Client) CopyPodRun(ctx context.Context, req *CopyPodRunRequest) (*v1.Pod, error)
- func (b *Client) CreateCronJob(ctx context.Context, job *v1.CronJob) (*v1.CronJob, error)
- func (c *Client) CreateDaemonSet(ctx context.Context, obj *appsv1.DaemonSet) (*appsv1.DaemonSet, error)
- func (c *Client) CreateDeployment(ctx context.Context, req *appsv1.Deployment) (*appsv1.Deployment, error)
- func (b *Client) CreateJob(ctx context.Context, job *v1.Job) (*v1.Job, error)
- func (c *Client) CreatePod(ctx context.Context, pod *v1.Pod, req *meta.CreateRequest) (*v1.Pod, error)
- func (c *Client) CreateStatefulSet(ctx context.Context, req *appsv1.StatefulSet) (*appsv1.StatefulSet, error)
- func (c *Client) DebugPod(ctx context.Context, req *DebugPodRequest) error
- func (c *Client) Delete(ctx context.Context, wl *WorkLoad) (*WorkLoad, error)
- func (b *Client) DeleteCronJob(ctx context.Context, req *meta.DeleteRequest) error
- func (c *Client) DeleteDaemonSet(ctx context.Context, req *meta.DeleteRequest) error
- func (c *Client) DeleteDeployment(ctx context.Context, req *meta.DeleteRequest) error
- func (c *Client) DeleteJob(ctx context.Context, req *meta.DeleteRequest) error
- func (c *Client) DeletePod(ctx context.Context, req *meta.DeleteRequest) error
- func (c *Client) DeleteStatefulSet(ctx context.Context, req *meta.DeleteRequest) error
- func (c *Client) Get(ctx context.Context, wl *WorkLoad, req *meta.GetRequest) error
- func (b *Client) GetCronJob(ctx context.Context, req *meta.GetRequest) (*v1.CronJob, error)
- func (c *Client) GetDaemonSet(ctx context.Context, req *meta.GetRequest) (*appsv1.DaemonSet, error)
- func (c *Client) GetDeployment(ctx context.Context, req *meta.GetRequest) (*appsv1.Deployment, error)
- func (b *Client) GetJob(ctx context.Context, req *meta.GetRequest) (*v1.Job, error)
- func (c *Client) GetPod(ctx context.Context, req *meta.GetRequest) (*v1.Pod, error)
- func (c *Client) GetStatefulSet(ctx context.Context, req *meta.GetRequest) (*appsv1.StatefulSet, error)
- func (b *Client) ListCronJob(ctx context.Context, req *meta.ListRequest) (*v1.CronJobList, error)
- func (c *Client) ListDaemonSet(ctx context.Context, req *meta.ListRequest) (*appsv1.DaemonSetList, error)
- func (c *Client) ListDeployment(ctx context.Context, req *meta.ListRequest) (*appsv1.DeploymentList, error)
- func (b *Client) ListJob(ctx context.Context, req *meta.ListRequest) (*v1.JobList, error)
- func (c *Client) ListPod(ctx context.Context, req *meta.ListRequest) (*v1.PodList, error)
- func (c *Client) ListStatefulSet(ctx context.Context, req *meta.ListRequest) (*appsv1.StatefulSetList, error)
- func (c *Client) LoginContainer(ctx context.Context, req *LoginContainerRequest) error
- func (c *Client) ReDeploy(ctx context.Context, req *meta.GetRequest) (*appsv1.Deployment, error)
- func (c *Client) Run(ctx context.Context, wl *WorkLoad) (*WorkLoad, error)
- func (c *Client) ScaleDeployment(ctx context.Context, req *meta.ScaleRequest) (*v1.Scale, error)
- func (c *Client) Update(ctx context.Context, wl *WorkLoad) (*WorkLoad, error)
- func (b *Client) UpdateCronJob(ctx context.Context, job *v1.CronJob) (*v1.CronJob, error)
- func (c *Client) UpdateDaemonSet(ctx context.Context, obj *appsv1.DaemonSet) (*appsv1.DaemonSet, error)
- func (c *Client) UpdateDeployment(ctx context.Context, req *appsv1.Deployment) (*appsv1.Deployment, error)
- func (b *Client) UpdateJob(ctx context.Context, job *v1.Job) (*v1.Job, error)
- func (c *Client) UpdateStatefulSet(ctx context.Context, req *appsv1.StatefulSet) (*appsv1.StatefulSet, error)
- func (c *Client) WaitForPodCondition(ctx context.Context, req *WaitForContainerRequest) (*corev1.Pod, error)
- func (c *Client) WatchContainerLog(ctx context.Context, req *WatchContainerLogRequest) (io.ReadCloser, error)
- func (c *Client) WatchDeployment(ctx context.Context, req *appsv1.Deployment) (watch.Interface, error)
- type ContainerTerminal
- type CopyPodRunRequest
- type DebugPodRequest
- type EnvVarSet
- type EventNotifier
- type LoginContainerRequest
- type MountVolume
- type POD_STATUS
- type SystemVaraible
- type WORKLOAD_KIND
- type WORKLOAD_STAGE
- type WaitForContainerRequest
- type WatchContainerLogRequest
- type WorkLoad
- func (w *WorkLoad) GetMainContainer() *v1.Container
- func (w *WorkLoad) GetMainContainerVersion() string
- func (w *WorkLoad) GetObjectMeta() *metav1.ObjectMeta
- func (w *WorkLoad) GetPodTemplateSpec() (podSpec *v1.PodTemplateSpec)
- func (w *WorkLoad) GetServiceContainer(serviceName string) *v1.Container
- func (w *WorkLoad) MustToYaml() string
- func (w *WorkLoad) SetAnnotations(key, value string)
- func (w *WorkLoad) SetDefaultNamespace(ns string)
- func (w *WorkLoad) SetMatchLabel(k, v string)
- func (w *WorkLoad) Status() *WorkloadStatus
- func (w *WorkLoad) SystemVaraible(serviceName string) *SystemVaraible
- type WorkloadStatus
- func GetCronJobStatus(*v1.CronJob) *WorkloadStatus
- func GetDaemonSetStatus(*appsv1.DaemonSet) *WorkloadStatus
- func GetDeploymentStatus(obj *appsv1.Deployment) *WorkloadStatus
- func GetJobStatus(*v1.Job) *WorkloadStatus
- func GetStatefulSetStatus(obj *appsv1.StatefulSet) *WorkloadStatus
- func NewWorklaodStatus() *WorkloadStatus
Constants ¶
View Source
const ( ANNOTATION_SECRET_MOUNT = "secret.mpaas.infraboard.io/mountpath" ANNOTATION_CONFIGMAP_MOUNT = "configmap.mpaas.infraboard.io/mountpath" )
Variables ¶
View Source
var ( WORKLOAD_KIND_NAME = map[int32]string{ 0: "Deployment", 1: "StatefulSet", 2: "DaemonSet", 3: "Job", 4: "CronJob", } WORKLOAD_KIND_VALUE = map[string]int32{ "Deployment": 0, "StatefulSet": 1, "DaemonSet": 2, "Job": 3, "CronJob": 4, } )
Enum value maps for WORKLOAD_KIND.
Functions ¶
func FormatContainerState ¶
func FormatContainerState(stage corev1.ContainerState) string
func GetContainerFromPodSpec ¶
func GetContainerFromPodTemplate ¶
func GetContainerFromPodTemplate(temp v1.PodTemplateSpec, name string) *v1.Container
func GetPodContainerStatusByName ¶
func GetPodContainerStatusByName(pod *corev1.Pod, containerName string) *corev1.ContainerStatus
func GetPrimaryContainerName ¶
func HoldContaienrCmd ¶
func InjectJobAnnotations ¶
注入Job注解
func InjectPodConfigMapVolume ¶
把configmap注入到Pod中 挂载成卷使用
func InjectPodSecretVolume ¶
把secret注入到Pod中 挂载成卷使用
func InjectPodTemplateSpecAnnotations ¶
func InjectPodTemplateSpecAnnotations(pod *v1.PodTemplateSpec, key, value string)
func InjectPodTemplateSpecLabel ¶
func InjectPodTemplateSpecLabel(pod *v1.PodTemplateSpec, key, value string)
func NewVolumeMount ¶
func NewVolumeMount(readonly bool, vs []MountVolume) []v1.VolumeMount
func WaitForContainerRunning ¶
func WaitForContainerRunning(containerName string, printer terminal.Logger) watchtools.ConditionFunc
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewWorkload ¶
func NewWorkload(cs *kubernetes.Clientset, restconf *rest.Config) *Client
func (*Client) CopyPodRun ¶
func (*Client) CreateCronJob ¶
func (*Client) CreateDaemonSet ¶
func (*Client) CreateDeployment ¶
func (c *Client) CreateDeployment(ctx context.Context, req *appsv1.Deployment) (*appsv1.Deployment, error)
func (*Client) CreateStatefulSet ¶
func (c *Client) CreateStatefulSet(ctx context.Context, req *appsv1.StatefulSet) (*appsv1.StatefulSet, error)
func (*Client) DebugPod ¶
func (c *Client) DebugPod(ctx context.Context, req *DebugPodRequest) error
func (*Client) DeleteCronJob ¶
func (*Client) DeleteDaemonSet ¶
func (*Client) DeleteDeployment ¶
func (*Client) DeleteStatefulSet ¶
func (*Client) GetCronJob ¶
func (*Client) GetDaemonSet ¶
func (*Client) GetDeployment ¶
func (c *Client) GetDeployment(ctx context.Context, req *meta.GetRequest) (*appsv1.Deployment, error)
func (*Client) GetStatefulSet ¶
func (c *Client) GetStatefulSet(ctx context.Context, req *meta.GetRequest) (*appsv1.StatefulSet, error)
func (*Client) ListCronJob ¶
func (b *Client) ListCronJob(ctx context.Context, req *meta.ListRequest) (*v1.CronJobList, error)
func (*Client) ListDaemonSet ¶
func (c *Client) ListDaemonSet(ctx context.Context, req *meta.ListRequest) (*appsv1.DaemonSetList, error)
func (*Client) ListDeployment ¶
func (c *Client) ListDeployment(ctx context.Context, req *meta.ListRequest) (*appsv1.DeploymentList, error)
func (*Client) ListStatefulSet ¶
func (c *Client) ListStatefulSet(ctx context.Context, req *meta.ListRequest) (*appsv1.StatefulSetList, error)
func (*Client) LoginContainer ¶
func (c *Client) LoginContainer(ctx context.Context, req *LoginContainerRequest) error
登录容器
func (*Client) ReDeploy ¶
func (c *Client) ReDeploy(ctx context.Context, req *meta.GetRequest) (*appsv1.Deployment, error)
原生并没有重新部署的功能, 通过变更注解时间来触发重新部署 dpObj.Spec.Template.Annotations["cattle.io/timestamp"] = time.Now().Format(time.RFC3339)
func (*Client) ScaleDeployment ¶
func (*Client) UpdateCronJob ¶
func (*Client) UpdateDaemonSet ¶
func (*Client) UpdateDeployment ¶
func (c *Client) UpdateDeployment(ctx context.Context, req *appsv1.Deployment) (*appsv1.Deployment, error)
func (*Client) UpdateStatefulSet ¶
func (c *Client) UpdateStatefulSet(ctx context.Context, req *appsv1.StatefulSet) (*appsv1.StatefulSet, error)
func (*Client) WaitForPodCondition ¶
func (c *Client) WaitForPodCondition(ctx context.Context, req *WaitForContainerRequest) (*corev1.Pod, error)
WaitForPodCondition watches the given pod until the container is running
func (*Client) WatchContainerLog ¶
func (c *Client) WatchContainerLog(ctx context.Context, req *WatchContainerLogRequest) (io.ReadCloser, error)
查看容器日志
func (*Client) WatchDeployment ¶
type ContainerTerminal ¶
type ContainerTerminal interface { io.Reader io.Writer remotecommand.TerminalSizeQueue }
type CopyPodRunRequest ¶
type CopyPodRunRequest struct { // 需要被Copy的容器 SourcePod *meta.GetRequest // 克隆后的目标容器运行时的其他参数 TargetPodMeta metav1.ObjectMeta // 目标创建容器的创建选项 TargetPodOpts *meta.CreateRequest // 登录目标容器的名称 ExecContainer string `json:"exec_container"` // 用于Hold主Container的命令, 默认 sleep infinity ExecHoldCmd []string `json:"exec_hold_cmd"` // 登录目标容器的命令 ExecRunCmd []string `json:"exec_run_cmd"` // 是否登录目录容器 Attach bool `json:"attach"` // 当登录终端后,退出终端是否删除Pod Remove bool `json:"remove"` // 目标容器的优雅关闭时间, 默认30秒 TerminationGracePeriodSeconds int64 // 登录终端 Terminal *terminal.WebSocketTerminal `json:"-"` }
func NewCopyPodRunRequest ¶
func NewCopyPodRunRequest() *CopyPodRunRequest
func (*CopyPodRunRequest) SetAttachTerminal ¶
func (r *CopyPodRunRequest) SetAttachTerminal(term *terminal.WebSocketTerminal)
func (*CopyPodRunRequest) SetDefaultExecContainer ¶
func (r *CopyPodRunRequest) SetDefaultExecContainer(containerName string)
type DebugPodRequest ¶
type DebugPodRequest struct { *meta.GetRequest EphemeralContainer corev1.EphemeralContainer `json:""` Excutor *terminal.WebSocketTerminal `json:"-"` }
type EventNotifier ¶
type EventNotifier func(textMsg string)
type LoginContainerRequest ¶
type LoginContainerRequest struct { Namespace string `json:"namespace" validate:"required"` PodName string `json:"pod_name" validate:"required"` ContainerName string `json:"container_name"` Command []string `json:"command"` Executor ContainerTerminal `json:"-"` }
func NewLoginContainerRequest ¶
func NewLoginContainerRequest(ce ContainerTerminal) *LoginContainerRequest
func (*LoginContainerRequest) String ¶
func (req *LoginContainerRequest) String() string
func (*LoginContainerRequest) Validate ¶
func (req *LoginContainerRequest) Validate() error
type MountVolume ¶
func NewMountVolume ¶
func NewMountVolume(v v1.Volume, path string) MountVolume
type POD_STATUS ¶
type POD_STATUS int
const ( POD_STATUS_PENDDING POD_STATUS = iota POD_STATUS_SCHEDULED POD_STATUS_INITIALIZED POD_STATUS_CONTAINER_READY POD_STATUS_POD_READY )
func GetPodStatus ¶
func GetPodStatus(p *v1.Pod) POD_STATUS
func (POD_STATUS) String ¶
func (s POD_STATUS) String() string
type SystemVaraible ¶
type SystemVaraible struct { WorkloadName string `json:"workload_name"` Image string `json:"image"` }
func NewSystemVaraible ¶
func NewSystemVaraible() *SystemVaraible
func (*SystemVaraible) ImageDetail ¶
func (v *SystemVaraible) ImageDetail() (addr, version string)
type WORKLOAD_KIND ¶
type WORKLOAD_KIND int32
const ( // Deployment无状态部署 WORKLOAD_KIND_DEPLOYMENT WORKLOAD_KIND = 0 // StatefulSet WORKLOAD_KIND_STATEFULSET WORKLOAD_KIND = 1 // DaemonSet WORKLOAD_KIND_DAEMONSET WORKLOAD_KIND = 2 // Job WORKLOAD_KIND_JOB WORKLOAD_KIND = 3 // CronJob WORKLOAD_KIND_CRONJOB WORKLOAD_KIND = 4 )
func ParseWorkloadKindFromString ¶
func ParseWorkloadKindFromString(str string) (WORKLOAD_KIND, error)
func (WORKLOAD_KIND) Equal ¶
func (t WORKLOAD_KIND) Equal(target WORKLOAD_KIND) bool
Equal type compare
func (WORKLOAD_KIND) MarshalJSON ¶
func (t WORKLOAD_KIND) MarshalJSON() ([]byte, error)
MarshalJSON todo
func (WORKLOAD_KIND) String ¶
func (t WORKLOAD_KIND) String() string
func (*WORKLOAD_KIND) UnmarshalJSON ¶
func (t *WORKLOAD_KIND) UnmarshalJSON(b []byte) error
UnmarshalJSON todo
type WORKLOAD_STAGE ¶
type WORKLOAD_STAGE int32
const ( // 未处理 WORKLOAD_STAGE_PENDDING WORKLOAD_STAGE = iota // 处理中 WORKLOAD_STAGE_PROGERESS // 正常 WORKLOAD_STAGE_ACTIVE // 异常 WORKLOAD_STAGE_ERROR )
type WaitForContainerRequest ¶
type WaitForContainerRequest struct { Namespace string `json:"namespace" validate:"required"` PodName string `json:"pod_name" validate:"required"` ContainerName string `json:"container_name"` TimoutSecond int `json:"timeout_second"` ExitCondition watchtools.ConditionFunc }
type WatchContainerLogRequest ¶
type WatchContainerLogRequest struct { Namespace string `json:"namespace" validate:"required"` PodName string `json:"pod_name" validate:"required"` *v1.PodLogOptions }
func NewWatchContainerLogRequest ¶
func NewWatchContainerLogRequest() *WatchContainerLogRequest
func (*WatchContainerLogRequest) Validate ¶
func (req *WatchContainerLogRequest) Validate() error
type WorkLoad ¶
type WorkLoad struct { WorkloadKind WORKLOAD_KIND Deployment *appsv1.Deployment StatefulSet *appsv1.StatefulSet DaemonSet *appsv1.DaemonSet CronJob *batchv1.CronJob Job *batchv1.Job }
func NewWorkLoad ¶
func NewWorkLoad() *WorkLoad
func ParseWorkloadFromYaml ¶
func (*WorkLoad) GetMainContainer ¶
约定第一个容器为主容器, 其他容器为辅助容器
func (*WorkLoad) GetMainContainerVersion ¶
获取主容器的镜像版本
func (*WorkLoad) GetObjectMeta ¶
func (w *WorkLoad) GetObjectMeta() *metav1.ObjectMeta
func (*WorkLoad) GetPodTemplateSpec ¶
func (w *WorkLoad) GetPodTemplateSpec() (podSpec *v1.PodTemplateSpec)
func (*WorkLoad) GetServiceContainer ¶
func (*WorkLoad) MustToYaml ¶
func (*WorkLoad) SetAnnotations ¶
func (*WorkLoad) SetDefaultNamespace ¶
func (*WorkLoad) SetMatchLabel ¶
func (*WorkLoad) SystemVaraible ¶
func (w *WorkLoad) SystemVaraible(serviceName string) *SystemVaraible
type WorkloadStatus ¶
type WorkloadStatus struct { Stage WORKLOAD_STAGE Reason string Message string }
func GetCronJobStatus ¶
func GetCronJobStatus(*v1.CronJob) *WorkloadStatus
func GetDaemonSetStatus ¶
func GetDaemonSetStatus(*appsv1.DaemonSet) *WorkloadStatus
func GetDeploymentStatus ¶
func GetDeploymentStatus(obj *appsv1.Deployment) *WorkloadStatus
func GetJobStatus ¶
func GetJobStatus(*v1.Job) *WorkloadStatus
func GetStatefulSetStatus ¶
func GetStatefulSetStatus(obj *appsv1.StatefulSet) *WorkloadStatus
func NewWorklaodStatus ¶
func NewWorklaodStatus() *WorkloadStatus
func (*WorkloadStatus) UpdateDeploymentStatus ¶
func (w *WorkloadStatus) UpdateDeploymentStatus(cond appsv1.DeploymentCondition)
Click to show internal directories.
Click to hide internal directories.