/
template.go
54 lines (44 loc) · 1.35 KB
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package solution
import (
"fmt"
"strings"
"github.com/containerum/chkit/pkg/util/text"
kubeModels "github.com/containerum/kube-client/pkg/model"
)
type SolutionTemplate kubeModels.AvailableSolution
func SolutionTemplateFromKube(kubeSolution kubeModels.AvailableSolution) SolutionTemplate {
return SolutionTemplate(kubeSolution.Copy())
}
func (solution SolutionTemplate) ToKube() kubeModels.AvailableSolution {
return kubeModels.AvailableSolution(solution).Copy()
}
func (solution SolutionTemplate) Copy() SolutionTemplate {
return SolutionTemplateFromKube(kubeModels.AvailableSolution(solution))
}
func (solution SolutionTemplate) String() string {
return fmt.Sprintf(`%s <%s> [%s]`,
solution.Name, solution.URL, solution.ImagePreview())
}
func (solution SolutionTemplate) ImagePreview() string {
view := strings.Join(solution.Images, ", ")
width := text.Width(view)
const max = 32
if width > max {
view = string([]rune(view)[:max]) + "..."
}
return view
}
func (solution SolutionTemplate) Resources() string {
return fmt.Sprintf("CPU : %v mCPU\n"+
"MEMORY : %v Mb",
solution.Limits.CPU, solution.Limits.RAM)
}
func (solution SolutionTemplate) Describe() string {
imgs := "Images:"
return fmt.Sprintf("Name: %s"+
"URL : %s"+
imgs+"\n%s",
solution.Name,
solution.URL,
text.Indent(strings.Join(solution.Images, "\n"), uint(len(imgs))))
}