accounts

package
v0.0.0-1607021651 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2020 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultAccountantFactory = func(cmd Command) (Accountant, error) {
	var opener PostgresOpener
	if cmd.WebK8sNamespace != "" && cmd.WebK8sPod != "" {
		restConfig, err := RESTConfig()
		if err != nil {
			return nil, err
		}
		k8sClient := &k8sClient{
			RESTConfig: restConfig,
			Namespace:  cmd.WebK8sNamespace,
		}
		pod, err := k8sClient.GetPod(cmd.WebK8sPod)
		if err != nil {
			return nil, err
		}
		opener = &WebNodeInferredPostgresOpener{
			WebNode:     &K8sWebPod{Pod: pod, Client: k8sClient},
			FileTracker: &TmpfsTracker{},
		}
	} else {
		opener = &StaticPostgresOpener{cmd.Postgres}
	}
	return &DBAccountant{Opener: opener}, nil
}
View Source
var DefaultValidator = func(cmd Command) error {
	err := validateFileFlag(cmd.Postgres.CACert.Path())
	if err != nil {
		return err
	}
	err = validateFileFlag(cmd.Postgres.ClientCert.Path())
	if err != nil {
		return err
	}
	err = validateFileFlag(cmd.Postgres.ClientKey.Path())
	if err != nil {
		return err
	}
	return nil
}

Functions

func Execute

func Execute(
	workerFactory WorkerFactory,
	accountantFactory AccountantFactory,
	validator func(Command) error,
	args []string,
	stdout io.Writer,
) int

func RESTConfig

func RESTConfig() (*rest.Config, error)

Types

type Accountant

type Accountant interface {
	Account([]Container) ([]Sample, error)
}

type AccountantFactory

type AccountantFactory func(Command) (Accountant, error)

type BuildWorkload

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

func (BuildWorkload) ToString

func (bw BuildWorkload) ToString() string

type Command

type Command struct {
	Postgres        flag.PostgresConfig
	K8sNamespace    string
	K8sPod          string
	WebK8sNamespace string
	WebK8sPod       string
}

type Container

type Container struct {
	Handle string
	Stats  Stats
}

type DBAccountant

type DBAccountant struct {
	Opener PostgresOpener
}

func (*DBAccountant) Account

func (da *DBAccountant) Account(containers []Container) ([]Sample, error)

type FileTracker

type FileTracker interface {
	Write(string) (string, error)
	Clear()
}

type GardenConnection

type GardenConnection struct {
	Dialer GardenDialer
}

func (GardenConnection) AllMetrics

func (gc GardenConnection) AllMetrics() (map[string]garden.ContainerMetricsEntry, error)

type GardenDialer

type GardenDialer interface {
	Dial() (net.Conn, error)
}

type GardenWorker

type GardenWorker struct {
	Dialer GardenDialer
}

func (*GardenWorker) Containers

func (gw *GardenWorker) Containers(opts ...StatsOption) ([]Container, error)

type K8sClient

type K8sClient interface {
	GetPod(string) (*corev1.Pod, error)
	GetSecret(string, string) (string, error)
}

func NewK8sClient

func NewK8sClient(restConfig *rest.Config, namespace string) K8sClient

type K8sGardenDialer

type K8sGardenDialer struct {
	RESTConfig *rest.Config
	Namespace  string
	PodName    string
}

func (*K8sGardenDialer) Dial

func (kgd *K8sGardenDialer) Dial() (net.Conn, error)

type K8sWebPod

type K8sWebPod struct {
	Pod    *corev1.Pod
	Client K8sClient
}

func (*K8sWebPod) FileContentsFromEnvVar

func (wp *K8sWebPod) FileContentsFromEnvVar(paramName string) (string, error)

func (*K8sWebPod) PostgresParamNames

func (wp *K8sWebPod) PostgresParamNames() ([]string, error)

func (*K8sWebPod) ValueFromEnvVar

func (wp *K8sWebPod) ValueFromEnvVar(paramName string) (string, error)

type LANGardenDialer

type LANGardenDialer struct{}

func (*LANGardenDialer) Dial

func (lgd *LANGardenDialer) Dial() (net.Conn, error)

type Labels

type Labels struct {
	Type      db.ContainerType
	Workloads []Workload
}

type PostgresOpener

type PostgresOpener interface {
	Open() (*sql.DB, error)
}

type ResourceWorkload

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

func (ResourceWorkload) ToString

func (rw ResourceWorkload) ToString() string

type Sample

type Sample struct {
	Container Container
	Labels    Labels
}

type StaticPostgresOpener

type StaticPostgresOpener struct {
	flag.PostgresConfig
}

func (*StaticPostgresOpener) Open

func (spo *StaticPostgresOpener) Open() (*sql.DB, error)

type Stats

type Stats struct {
	Memory uint64
	Age    time.Duration
}

type StatsOption

type StatsOption func()

type StreamAddr

type StreamAddr struct {
}

func (*StreamAddr) Network

func (sa *StreamAddr) Network() string

func (*StreamAddr) String

func (sa *StreamAddr) String() string

type StreamConn

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

func (*StreamConn) Close

func (sc *StreamConn) Close() error

func (*StreamConn) LocalAddr

func (sc *StreamConn) LocalAddr() net.Addr

func (*StreamConn) Read

func (sc *StreamConn) Read(p []byte) (n int, err error)

func (*StreamConn) RemoteAddr

func (sc *StreamConn) RemoteAddr() net.Addr

func (*StreamConn) SetDeadline

func (sc *StreamConn) SetDeadline(t time.Time) error

func (*StreamConn) SetReadDeadline

func (sc *StreamConn) SetReadDeadline(t time.Time) error

func (*StreamConn) SetWriteDeadline

func (sc *StreamConn) SetWriteDeadline(t time.Time) error

func (*StreamConn) Write

func (sc *StreamConn) Write(p []byte) (n int, err error)

type TmpfsTracker

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

func (*TmpfsTracker) Clear

func (tt *TmpfsTracker) Clear()

func (*TmpfsTracker) Count

func (tt *TmpfsTracker) Count() int

func (*TmpfsTracker) Write

func (tt *TmpfsTracker) Write(contents string) (string, error)

type WebNode

type WebNode interface {
	PostgresParamNames() ([]string, error)
	ValueFromEnvVar(string) (string, error)
	FileContentsFromEnvVar(string) (string, error)
}

type WebNodeInferredPostgresOpener

type WebNodeInferredPostgresOpener struct {
	WebNode     WebNode
	FileTracker FileTracker
}

func (*WebNodeInferredPostgresOpener) Open

func (wnipo *WebNodeInferredPostgresOpener) Open() (*sql.DB, error)

func (*WebNodeInferredPostgresOpener) PostgresConfig

func (wnipo *WebNodeInferredPostgresOpener) PostgresConfig() (flag.PostgresConfig, error)

type Worker

type Worker interface {
	Containers(...StatsOption) ([]Container, error)
}

type WorkerFactory

type WorkerFactory func(Command) (Worker, error)
var DefaultWorkerFactory WorkerFactory = func(cmd Command) (Worker, error) {
	var dialer GardenDialer
	if cmd.K8sNamespace != "" && cmd.K8sPod != "" {
		restConfig, err := RESTConfig()
		if err != nil {
			return nil, err
		}
		dialer = &K8sGardenDialer{
			RESTConfig: restConfig,
			Namespace:  cmd.K8sNamespace,
			PodName:    cmd.K8sPod,
		}
	} else {
		dialer = &LANGardenDialer{}
	}
	return &GardenWorker{
		Dialer: dialer,
	}, nil
}

type Workload

type Workload interface {
	ToString() string
}

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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