podbridge

package module
v0.0.0-...-7a1098e Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: Apache-2.0 Imports: 28 Imported by: 1

README

podbridge

Go Reference Build Status CodeFactor

package main

import (
	"context"
	"fmt"

	pbr "github.com/seoyhaein/podbridge"
)

func main() {
	ctx, err := pbr.NewConnectionLinux(context.Background())
	if err != nil {
		panic(err)
	}
	// spec 만들기
	conSpec := pbr.NewSpec()
	conSpec.SetImage("docker.io/library/test07")

	f := func(spec pbr.SpecGen) pbr.SpecGen {
		spec.Name = "container-tester01"
		spec.Terminal = true
		return spec
	}
	conSpec.SetOther(f)
	// 해당 이미지에 해당 shell script 가 있다.
	conSpec.SetHealthChecker("CMD-SHELL /app/healthcheck/healthcheck.sh", "2s", 1, "30s", "1s")

	// container 만들기
	r := pbr.CreateContainer(ctx, conSpec)
	fmt.Println("container Id is :", r.ID)
	result := r.RunT(ctx, "1s")

	v := int(result)
	fmt.Println(v)
}

Documentation

Index

Constants

View Source
const (
	Min int = 1
	Max int = 100
)

channel buffer size

Variables

View Source
var Log = logrus.New()

Functions

func CreateBaseImage

func CreateBaseImage(healthCheckerPath string) string

CreateBaseImage healthcheck 를 넣는다.

func CreateCustomImage

func CreateCustomImage(imageName, baseImage, filename, cmd string) *string

CreateCustomImage alpine 으로 만들어주고 명령어를 넣어줘서 image 를 만들어 주는 function. 테스트는 별도의 프로젝트 열어서 해야함. 1. bash, nano 와 업데이트를 해줌. 2. /app 폴더를 WorkDir 로 만들어줌. 3. /app/healthcheck 폴더를 만들어줌. 4. /app/healthcheck 여기에 executor.sh 를 집어 넣어줌. TODO 데이터 넣는 것도 구현되어야 함. BaseImage 를 만들자.

func CreateNamedVolume

func CreateNamedVolume(ctx context.Context, conf ...*VolumeConfig) ([]*specgen.NamedVolume, error)

func LimitResources

func LimitResources(cores float64, mems float64) (*specs.LinuxCPU, *specs.LinuxResources)

func NewConnection

func NewConnection(ctx context.Context, ipcName string) (context.Context, error)

func NewConnectionLinux

func NewConnectionLinux(ctx context.Context) (context.Context, error)

func Reset

func Reset() error

Reset truncate podbridge.yaml ListCreated 를 리셋하는 것은 생각해볼 것

func Save

func Save() error

func SetCpuSet

func SetCpuSet() *specs.LinuxResources

func SetHealthChecker

func SetHealthChecker(inCmd, interval string, retries uint, timeout, startPeriod string) (*manifest.Schema2HealthConfig, error)

Types

type ContainerSpec

type ContainerSpec struct {
	Spec *specgen.SpecGenerator
}

func NewSpec

func NewSpec() *ContainerSpec

NewSpec ContainerSpec 을 생성한다.

func (*ContainerSpec) SetHealthChecker

func (c *ContainerSpec) SetHealthChecker(inCmd, interval string, retries uint, timeout, startPeriod string) *ContainerSpec

SetHealthChecker HealthChecker 를 등록한다.

func (*ContainerSpec) SetImage

func (c *ContainerSpec) SetImage(imgName string) *ContainerSpec

SetImage 해당 이미지를 spec 에 등록한다.

func (*ContainerSpec) SetOther

func (c *ContainerSpec) SetOther(f func(spec SpecGen) SpecGen) *ContainerSpec

SetOther Spec 옵션을 적용하도록 돕는다.

type ContainerStatus

type ContainerStatus int
const (
	Created   ContainerStatus = iota //0
	Running                          // 1
	Exited                           // 2
	ExitedErr                        // 3
	Healthy                          // 4
	Unhealthy                        // 5
	Dead                             // 6
	Paused                           // 7
	UnKnown                          // 8
	None                             // 9
)

type CreateContainerResult

type CreateContainerResult struct {
	Name     string
	ID       string
	Warnings []string
	Status   ContainerStatus
	// contains filtered or unexported fields
}

func CreateContainer

func CreateContainer(ctx context.Context, conSpec *ContainerSpec) *CreateContainerResult

CreateContainer

func (*CreateContainerResult) HealthCheck

func (Res *CreateContainerResult) HealthCheck(ctx context.Context, interval string)

HealthCheck 테스트 필요

func (*CreateContainerResult) Kill

func (Res *CreateContainerResult) Kill(ctx context.Context, options ...any) error

Kill

func (*CreateContainerResult) ReStart

func (Res *CreateContainerResult) ReStart(ctx context.Context) error

ReStart 중복되는 것 같긴하다. TODO 수정해줘야 한다. ReStart

func (*CreateContainerResult) Run

Run container 의 Start 와 함께 HealthCheck 도 함께 하도록 한다.

func (*CreateContainerResult) Start

func (Res *CreateContainerResult) Start(ctx context.Context) error

Start startOptions 는 default 값을 사용한다. https://docs.podman.io/en/latest/_static/api.html?version=v4.1#operation/ContainerStartLibpod

func (*CreateContainerResult) Stop

func (Res *CreateContainerResult) Stop(ctx context.Context, options ...any) error

Stop https://docs.podman.io/en/latest/_static/api.html?version=v4.1#operation/ContainerStopLibpod default 값은 timeout 은 10 으로 세팅되어 있고, ignore 는 false 이다. ignore 는 만약 stop 된 컨테이너를 stop 되어 있을 때 stop 하는 경우 true 하면 에러 무시, false 로 하면 에러 리턴 timeout 은 몇 후에 컨테어너를 kill 할지 정한다.

type CreatePodResult

type CreatePodResult struct {
	ErrorMessage error

	Name     string
	Hostname string
	ID       string

	Success bool
}

func CreatePod

func CreatePod(ctx context.Context, spec *entities.PodSpec) *CreatePodResult

CreatePod Pod 를 생성한다. 기존 Pod 가 존재하고 있으면 실패를 리턴한다.

func (*CreatePodResult) GetPodId

func (podRes *CreatePodResult) GetPodId() string

type HealthCheck

type HealthCheck struct {
	InCmd       string
	Interval    string
	Retries     uint
	Timeout     string
	StartPeriod string
}

func CreateHealthCheck

func CreateHealthCheck(inCmd, interval string, retries uint, timeout, startPeriod string) *HealthCheck

func (*HealthCheck) SetHealthChecker

func (h *HealthCheck) SetHealthChecker() (*manifest.Schema2HealthConfig, error)

type ListCreated

type ListCreated struct {
	ImageIds     []string   `yaml:"Images,flow"`
	ContainerIds []string   `yaml:"Containers,flow"`
	Pods         []*PodInfo `yaml:"Pods,flow"`
	VolumeNames  []string   `yaml:"Volumes,flow"`
	// contains filtered or unexported fields
}
var (
	Basket *ListCreated
)

func MustFirstCall

func MustFirstCall() (*ListCreated, error)

func (*ListCreated) AddContainerId

func (lc *ListCreated) AddContainerId(containerId string) *ListCreated

func (*ListCreated) AddContainerInPod

func (lc *ListCreated) AddContainerInPod(podId string, containerIds ...string) *ListCreated

func (*ListCreated) AddImagesId

func (lc *ListCreated) AddImagesId(imgId string) *ListCreated

func (*ListCreated) AddPodId

func (lc *ListCreated) AddPodId(podId string) *ListCreated

func (*ListCreated) AddVolumeName

func (lc *ListCreated) AddVolumeName(volumeName string) *ListCreated

func (*ListCreated) RemoveContainerId

func (lc *ListCreated) RemoveContainerId(containerId string)

RemoveContainerId 테스트 해보자.

func (*ListCreated) Save

func (lc *ListCreated) Save()

Save 호출 없이 사용할 수 있도록 추후 수정하자. 종료시 호출하도록 하면 될듯하다. 결국 안지구오 app 을 닫는 경우 데이터를 보호할 목적임으로

type PodInfo

type PodInfo struct {
	Id           string   `yaml:"podId"`
	ContainerIds []string `yaml:"containers,flow"`
}

type PodSpec

type PodSpec struct {
	Spec *specgen.PodSpecGenerator
}

func NewPod

func NewPod() *PodSpec

NewPod PodSpec 을 생성한다.

func (*PodSpec) SetName

func (c *PodSpec) SetName(name string) *PodSpec

SetName Pod 의 이름을 등록한다.

func (*PodSpec) SetOther

func (c *PodSpec) SetOther(f func(spec PodSpecGen) PodSpecGen) *PodSpec

SetOther Spec 옵션을 적용하도록 돕는다.

type PodSpecGen

type PodSpecGen *specgen.PodSpecGenerator

type SpecGen

type SpecGen *specgen.SpecGenerator

type VolumeConfig

type VolumeConfig struct {
	entities.VolumeCreateOptions
	Dest string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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