-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
57 lines (50 loc) · 1.17 KB
/
service.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
55
56
57
package validators
import (
"fmt"
"github.com/btoll/validator/lib"
"k8s.io/apimachinery/pkg/util/intstr"
)
type ServiceManifest struct {
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Metadata `json:"metadata"`
Spec ServiceSpec `json:"spec"`
}
type ServiceSpec struct {
Ports []ServicePort
Selector Data
Type string
}
type ServicePort struct {
Port int
TargetPort intstr.IntOrString
Protocol string
}
func (m ServiceManifest) Write() {
dir := fmt.Sprintf("build/%s/service", m.Name)
err := lib.CreateBuildDir(dir)
if err != nil {
fmt.Println("err", err)
}
localFile := fmt.Sprintf("%s/local", dir)
WriteTemplate(localFile, "service.tpl", m)
service, err := GetServiceClient(m.Name)
if err != nil {
fmt.Println("err", err)
}
// This values are empty in the returned struct.
service.APIVersion = "v1"
service.Kind = "Service"
remoteFile := fmt.Sprintf("%s/remote", dir)
WriteTemplate(remoteFile, "service.tpl", service)
b, err := Validate(localFile, remoteFile)
if err != nil {
fmt.Println("err", err)
}
if b {
err = RemoveDir(dir, fmt.Sprintf("build/%s", m.Name))
if err != nil {
fmt.Println(err)
}
}
}