volm

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 16 Imported by: 0

README

volm

WIP: PVC management API

Run

From source:

PVC_NAMESPACE=volm-test PVC_SELECTOR=pvci.txn2.com/service=pvci go run ./cmd/volm.go

Endpoints

Get list of PVCs:

curl --location --request GET 'http://localhost:8070/vol/' | jq

Get a PVC:

curl --location --request GET 'http://localhost:8070/vol/volm-test-pvc-1' | jq

Delete a PVC:

curl --location --request DELETE 'http://localhost:8070/vol/volm-test-pvc-1' | jq

Development

Create test environment with manifests from ./k8s/.

Build and Deploy

Release
goreleaser --skip-publish --rm-dist --skip-validate
GITHUB_TOKEN=$GITHUB_TOKEN goreleaser --rm-dist

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsNotFound added in v0.1.1

func IsNotFound(err error) bool

IsNotFound returns true if the error is a errors.StatusError matching metaV1.StatusReasonNotFound this function allows us to log more critical errors and pass status information such at 404s and 500s through the REST API.

Types

type API

type API struct {
	*Config
	LogErrors      prometheus.Counter
	PVCSelectorMap map[string]string
	PodStore       *PodStore
	PVCStore       *PVCStore
}

API is primary object implementing the core API methods and HTTP handlers

func NewApi

func NewApi(cfg *Config) (*API, error)

NewApi constructs an API object and populates it with configuration along with setting defaults where required.

func (*API) DeletePVC

func (a *API) DeletePVC(name string) error

func (*API) DeletePVCHandler

func (a *API) DeletePVCHandler() gin.HandlerFunc

func (*API) GetPVC

func (a *API) GetPVC(name string) (VolumeInfo, error)

func (*API) GetPVCHandler

func (a *API) GetPVCHandler() gin.HandlerFunc

func (*API) GetPVCList

func (a *API) GetPVCList() ([]VolumeInfo, error)

func (*API) GetPodsInfoByPVC

func (a *API) GetPodsInfoByPVC(pods []v1.Pod, pvcName string) ([]PodInfo, error)

func (*API) ListPVCHandler

func (a *API) ListPVCHandler() gin.HandlerFunc

func (*API) OkHandler

func (a *API) OkHandler(version string, mode string, service string) gin.HandlerFunc

OkHandler is provided for created a default slash route for the HTTP API and returns basic version, node and service name.

type Config

type Config struct {
	Service      string
	Version      string
	Log          *zap.Logger
	Cs           *kubernetes.Clientset
	PVCNamespace string
	PVCSelector  string
}

Config configures the API

type PVCStore added in v0.1.1

type PVCStore struct {
	*PVCStoreConfig
	Stopper chan struct{}

	sync.Mutex
	// contains filtered or unexported fields
}

func NewPVCStore added in v0.1.1

func NewPVCStore(cfg *PVCStoreConfig) (*PVCStore, error)

func (*PVCStore) AddPVC added in v0.1.1

func (pvcs *PVCStore) AddPVC(pvc v1.PersistentVolumeClaim)

func (*PVCStore) DeletePVC added in v0.1.1

func (pvcs *PVCStore) DeletePVC(podName string)

func (*PVCStore) GetPVC added in v0.1.1

func (pvcs *PVCStore) GetPVC(pvcName string) *v1.PersistentVolumeClaim

func (*PVCStore) GetPVCs added in v0.1.1

func (pvcs *PVCStore) GetPVCs() []v1.PersistentVolumeClaim

func (*PVCStore) PVCWatch added in v0.1.1

func (pvcs *PVCStore) PVCWatch()

type PVCStoreConfig added in v0.1.1

type PVCStoreConfig struct {
	Namespace string
	Log       *zap.Logger
	Cs        *kubernetes.Clientset
}

type PodInfo

type PodInfo struct {
	Name             string            `json:"name"`
	Labels           map[string]string `json:"labels,omitempty"`
	Annotations      map[string]string `json:"annotations,omitempty"`
	Phase            v1.PodPhase       `json:"phase"`
	StartTime        *metaV1.Time      `json:"startTime"`
	Terminating      bool              `json:"terminating"`
	TerminatingSince *metaV1.Time      `json:"terminatingSince,omitempty"`
}

type PodStore added in v0.1.1

type PodStore struct {
	*PodStoreConfig
	Stopper chan struct{}

	sync.Mutex
	// contains filtered or unexported fields
}

func NewPodStore added in v0.1.1

func NewPodStore(cfg *PodStoreConfig) (*PodStore, error)

func (*PodStore) AddPod added in v0.1.1

func (ps *PodStore) AddPod(pod v1.Pod)

func (*PodStore) DeletePod added in v0.1.1

func (ps *PodStore) DeletePod(podName string)

func (*PodStore) GetPod added in v0.1.1

func (ps *PodStore) GetPod(podName string) *v1.Pod

func (*PodStore) GetPods added in v0.1.1

func (ps *PodStore) GetPods() []v1.Pod

func (*PodStore) PodWatch added in v0.1.1

func (ps *PodStore) PodWatch()

type PodStoreConfig added in v0.1.1

type PodStoreConfig struct {
	Namespace string
	Log       *zap.Logger
	Cs        *kubernetes.Clientset
}

type VolumeInfo

type VolumeInfo struct {
	Name             string                         `json:"name"`
	Labels           map[string]string              `json:"labels,omitempty"`
	Annotations      map[string]string              `json:"annotations,omitempty"`
	Status           v1.PersistentVolumeClaimStatus `json:"status"`
	Spec             v1.PersistentVolumeClaimSpec   `json:"spec"`
	Terminating      bool                           `json:"terminating"`
	TerminatingSince *metaV1.Time                   `json:"terminatingSince,omitempty"`
	UsedBy           []PodInfo                      `json:"usedBy"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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