* Add Virtual Kubelet provider for VIC Initial virtual kubelet provider for VMware VIC. This provider currently handles creating and starting of a pod VM via the VIC portlayer and persona server. Image store handling via the VIC persona server. This provider currently requires the feature/wolfpack branch of VIC. * Added pod stop and delete. Also added node capacity. Added the ability to stop and delete pod VMs via VIC. Also retrieve node capacity information from the VCH. * Cleanup and readme file Some file clean up and added a Readme.md markdown file for the VIC provider. * Cleaned up errors, added function comments, moved operation code 1. Cleaned up error handling. Set standard for creating errors. 2. Added method prototype comments for all interface functions. 3. Moved PodCreator, PodStarter, PodStopper, and PodDeleter to a new folder. * Add mocking code and unit tests for podcache, podcreator, and podstarter Used the unit test framework used in VIC to handle assertions in the provider's unit test. Mocking code generated using OSS project mockery, which is compatible with the testify assertion framework. * Vendored packages for the VIC provider Requires feature/wolfpack branch of VIC and a few specific commit sha of projects used within VIC. * Implementation of POD Stopper and Deleter unit tests (#4) * Updated files for initial PR
148 lines
3.2 KiB
Go
148 lines
3.2 KiB
Go
// Package colwriter provides a write filter that formats
|
|
// input lines in multiple columns.
|
|
//
|
|
// The package is a straightforward translation from
|
|
// /src/cmd/draw/mc.c in Plan 9 from User Space.
|
|
package colwriter
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
const (
|
|
tab = 4
|
|
)
|
|
|
|
const (
|
|
// Print each input line ending in a colon ':' separately.
|
|
BreakOnColon uint = 1 << iota
|
|
)
|
|
|
|
// A Writer is a filter that arranges input lines in as many columns as will
|
|
// fit in its width. Tab '\t' chars in the input are translated to sequences
|
|
// of spaces ending at multiples of 4 positions.
|
|
//
|
|
// If BreakOnColon is set, each input line ending in a colon ':' is written
|
|
// separately.
|
|
//
|
|
// The Writer assumes that all Unicode code points have the same width; this
|
|
// may not be true in some fonts.
|
|
type Writer struct {
|
|
w io.Writer
|
|
buf []byte
|
|
width int
|
|
flag uint
|
|
}
|
|
|
|
// NewWriter allocates and initializes a new Writer writing to w.
|
|
// Parameter width controls the total number of characters on each line
|
|
// across all columns.
|
|
func NewWriter(w io.Writer, width int, flag uint) *Writer {
|
|
return &Writer{
|
|
w: w,
|
|
width: width,
|
|
flag: flag,
|
|
}
|
|
}
|
|
|
|
// Write writes p to the writer w. The only errors returned are ones
|
|
// encountered while writing to the underlying output stream.
|
|
func (w *Writer) Write(p []byte) (n int, err error) {
|
|
var linelen int
|
|
var lastWasColon bool
|
|
for i, c := range p {
|
|
w.buf = append(w.buf, c)
|
|
linelen++
|
|
if c == '\t' {
|
|
w.buf[len(w.buf)-1] = ' '
|
|
for linelen%tab != 0 {
|
|
w.buf = append(w.buf, ' ')
|
|
linelen++
|
|
}
|
|
}
|
|
if w.flag&BreakOnColon != 0 && c == ':' {
|
|
lastWasColon = true
|
|
} else if lastWasColon {
|
|
if c == '\n' {
|
|
pos := bytes.LastIndex(w.buf[:len(w.buf)-1], []byte{'\n'})
|
|
if pos < 0 {
|
|
pos = 0
|
|
}
|
|
line := w.buf[pos:]
|
|
w.buf = w.buf[:pos]
|
|
if err = w.columnate(); err != nil {
|
|
if len(line) < i {
|
|
return i - len(line), err
|
|
}
|
|
return 0, err
|
|
}
|
|
if n, err := w.w.Write(line); err != nil {
|
|
if r := len(line) - n; r < i {
|
|
return i - r, err
|
|
}
|
|
return 0, err
|
|
}
|
|
}
|
|
lastWasColon = false
|
|
}
|
|
if c == '\n' {
|
|
linelen = 0
|
|
}
|
|
}
|
|
return len(p), nil
|
|
}
|
|
|
|
// Flush should be called after the last call to Write to ensure that any data
|
|
// buffered in the Writer is written to output.
|
|
func (w *Writer) Flush() error {
|
|
return w.columnate()
|
|
}
|
|
|
|
func (w *Writer) columnate() error {
|
|
words := bytes.Split(w.buf, []byte{'\n'})
|
|
w.buf = nil
|
|
if len(words[len(words)-1]) == 0 {
|
|
words = words[:len(words)-1]
|
|
}
|
|
maxwidth := 0
|
|
for _, wd := range words {
|
|
if n := utf8.RuneCount(wd); n > maxwidth {
|
|
maxwidth = n
|
|
}
|
|
}
|
|
maxwidth++ // space char
|
|
wordsPerLine := w.width / maxwidth
|
|
if wordsPerLine <= 0 {
|
|
wordsPerLine = 1
|
|
}
|
|
nlines := (len(words) + wordsPerLine - 1) / wordsPerLine
|
|
for i := 0; i < nlines; i++ {
|
|
col := 0
|
|
endcol := 0
|
|
for j := i; j < len(words); j += nlines {
|
|
endcol += maxwidth
|
|
_, err := w.w.Write(words[j])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
col += utf8.RuneCount(words[j])
|
|
if j+nlines < len(words) {
|
|
for col < endcol {
|
|
_, err := w.w.Write([]byte{' '})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
col++
|
|
}
|
|
}
|
|
}
|
|
_, err := w.w.Write([]byte{'\n'})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|