* 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
87 lines
2.2 KiB
Go
87 lines
2.2 KiB
Go
package text
|
|
|
|
import (
|
|
"bytes"
|
|
"math"
|
|
)
|
|
|
|
var (
|
|
nl = []byte{'\n'}
|
|
sp = []byte{' '}
|
|
)
|
|
|
|
const defaultPenalty = 1e5
|
|
|
|
// Wrap wraps s into a paragraph of lines of length lim, with minimal
|
|
// raggedness.
|
|
func Wrap(s string, lim int) string {
|
|
return string(WrapBytes([]byte(s), lim))
|
|
}
|
|
|
|
// WrapBytes wraps b into a paragraph of lines of length lim, with minimal
|
|
// raggedness.
|
|
func WrapBytes(b []byte, lim int) []byte {
|
|
words := bytes.Split(bytes.Replace(bytes.TrimSpace(b), nl, sp, -1), sp)
|
|
var lines [][]byte
|
|
for _, line := range WrapWords(words, 1, lim, defaultPenalty) {
|
|
lines = append(lines, bytes.Join(line, sp))
|
|
}
|
|
return bytes.Join(lines, nl)
|
|
}
|
|
|
|
// WrapWords is the low-level line-breaking algorithm, useful if you need more
|
|
// control over the details of the text wrapping process. For most uses, either
|
|
// Wrap or WrapBytes will be sufficient and more convenient.
|
|
//
|
|
// WrapWords splits a list of words into lines with minimal "raggedness",
|
|
// treating each byte as one unit, accounting for spc units between adjacent
|
|
// words on each line, and attempting to limit lines to lim units. Raggedness
|
|
// is the total error over all lines, where error is the square of the
|
|
// difference of the length of the line and lim. Too-long lines (which only
|
|
// happen when a single word is longer than lim units) have pen penalty units
|
|
// added to the error.
|
|
func WrapWords(words [][]byte, spc, lim, pen int) [][][]byte {
|
|
n := len(words)
|
|
|
|
length := make([][]int, n)
|
|
for i := 0; i < n; i++ {
|
|
length[i] = make([]int, n)
|
|
length[i][i] = len(words[i])
|
|
for j := i + 1; j < n; j++ {
|
|
length[i][j] = length[i][j-1] + spc + len(words[j])
|
|
}
|
|
}
|
|
|
|
nbrk := make([]int, n)
|
|
cost := make([]int, n)
|
|
for i := range cost {
|
|
cost[i] = math.MaxInt32
|
|
}
|
|
for i := n - 1; i >= 0; i-- {
|
|
if length[i][n-1] <= lim || i == n-1 {
|
|
cost[i] = 0
|
|
nbrk[i] = n
|
|
} else {
|
|
for j := i + 1; j < n; j++ {
|
|
d := lim - length[i][j-1]
|
|
c := d*d + cost[j]
|
|
if length[i][j-1] > lim {
|
|
c += pen // too-long lines get a worse penalty
|
|
}
|
|
if c < cost[i] {
|
|
cost[i] = c
|
|
nbrk[i] = j
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
var lines [][][]byte
|
|
i := 0
|
|
for i < n {
|
|
lines = append(lines, words[i:nbrk[i]])
|
|
i = nbrk[i]
|
|
}
|
|
return lines
|
|
}
|