-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.go
48 lines (42 loc) · 1.17 KB
/
parse.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
package v1alpha1
import (
"fmt"
"os"
api "github.com/edgefarm/edgefarm/apis/config/v1alpha1"
"github.com/edgefarm/edgefarm/pkg/shared"
"gopkg.in/yaml.v2"
)
func Load(path string) (*api.Cluster, error) {
path, err := shared.Expand(path)
if err != nil {
return nil, err
}
str, err := os.ReadFile(path)
if err != nil {
return nil, err
}
cluster := api.Cluster{}
err = yaml.Unmarshal(str, &cluster)
if err != nil {
return nil, err
}
return &cluster, err
}
func Parse(c *api.Cluster) error {
shared.ClusterConfig = c
shared.ClusterType = c.Spec.Type
if c.Spec.Type == Local.String() {
shared.ClusterName = c.Metadata.Name
shared.Ports.HostApiServerPort = c.Spec.Local.ApiServerPort
shared.Ports.HostNatsPort = c.Spec.Local.NatsPort
shared.Ports.HostHttpPort = c.Spec.Local.HttpPort
shared.Ports.HostHttpsPort = c.Spec.Local.HttpsPort
shared.EdgeNodesNum = c.Spec.Local.VirtualEdgeNodes
} else if c.Spec.Type == Hetzner.String() {
shared.ClusterName = fmt.Sprintf("%s-bootstrap", c.Metadata.Name)
shared.CloudClusterName = c.Metadata.Name
}
shared.KubeConfig = c.Spec.General.KubeConfigPath
shared.StatePath = c.Spec.General.StatePath
return nil
}