-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathkubernetes_engine_engine.go
123 lines (108 loc) · 4.25 KB
/
kubernetes_engine_engine.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package gobizfly
import (
"context"
"encoding/json"
"io"
"net/http"
)
type ClusterJoinEverywhereRequest struct {
PoolID string `json:"pool_id" yaml:"pool_id"`
PublicIP string `json:"public_ip" yaml:"public_ip"`
Hostname string `json:"hostname" yaml:"hostname"`
HasWanInterface bool `json:"has_wan_interface" yaml:"has_wan_interface"`
IPAddresses []string `json:"ip_addresses" yaml:"ip_addresses"`
Capacity EverywhereNodeCapacity `json:"capacity" yaml:"capacity"`
Annotation *EverywhereAnnotation `json:"annotation,omitempty" yaml:"annotation"`
}
type EverywhereAnnotation struct {
ForceEndpoint string `json:"kilo.squat.ai/force-endpoint" yaml:"kilo.squat.ai/force-endpoint"`
}
type EverywhereNodeCapacity struct {
Cores int `json:"cores" yaml:"cores"`
MemoryKB int `json:"memory_kb" yaml:"memory_kb"`
}
type ClusterCertificate struct {
CaCert string `json:"ca.pem" yaml:"ca.pem"`
ClientKey string `json:"client-key.pem" yaml:"client-key.pem"`
ClientCert string `json:"client.pem" yaml:"client.pem"`
}
type ClusterReserved struct {
SystemReserved ClusterSystemReserved `json:"system_reserved" yaml:"system_reserved"`
KubeReserved ClusterKubeReserved `json:"kube_reserved" yaml:"kube_reserved"`
}
type ClusterSystemReserved struct {
CPU string `json:"cpu" yaml:"cpu"`
Memory string `json:"memory" yaml:"memory"`
}
type ClusterKubeReserved struct {
CPU string `json:"cpu" yaml:"cpu"`
Memory string `json:"memory" yaml:"memory"`
}
type ClusterJoinEverywhereResponse struct {
APIServer string `json:"apiserver" yaml:"apiserver"`
ClusterDNS string `json:"cluster_dns" yaml:"cluster_dns"`
ClusterCIDR string `json:"cluster_cidr" yaml:"cluster_cidr"`
CloudProvider string `json:"cloud_provider" yaml:"cloud_provider"`
Certificate ClusterCertificate `json:"certificate" yaml:"certificate"`
UUID string `json:"uuid" yaml:"uuid"`
MaxPods int `json:"max_pods" yaml:"max_pods"`
Reserved ClusterReserved `json:"reserved" yaml:"reserved"`
}
func (c *kubernetesEngineService) AddClusterEverywhere(ctx context.Context, id string, cjer *ClusterJoinEverywhereRequest) (*ClusterJoinEverywhereResponse, error) {
var joinEverywhereResponse ClusterJoinEverywhereResponse
req, err := c.client.NewRequest(ctx, http.MethodPost, kubernetesServiceName, clusterJoinEverywhere+"/"+id, &cjer)
if err != nil {
return nil, err
}
resp, err := c.client.Do(ctx, req)
if err != nil {
return nil, err
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
defer resp.Body.Close()
err = json.Unmarshal(body, &joinEverywhereResponse)
if err != nil {
return nil, err
}
return &joinEverywhereResponse, nil
}
type WorkerConfig struct {
ID string `json:"id" yaml:"id"`
Version string `json:"version" yaml:"version"`
Everywhere bool `json:"everywhere" yaml:"everywhere"`
Nvidiadevice bool `json:"nvidiadevice" yaml:"nvidiadevice"`
CniVersion string `json:"CNI_VERSION" yaml:"CNI_VERSION"`
RuncVersion string `json:"RUNC_VERSION" yaml:"RUNC_VERSION"`
ContainerdVersion string `json:"CONTAINERD_VERSION" yaml:"CONTAINERD_VERSION"`
KubeVersion string `json:"KUBE_VERSION" yaml:"KUBE_VERSION"`
}
type ClusterInfoResponse struct {
WorkerConfig WorkerConfig `json:"worker_config" yaml:"worker_configs"`
K8sVersion string `json:"k8s_version" yaml:"k8s_version"`
ShootUid string `json:"shoot_uid" yaml:"shoot_uid"`
PoolName string `json:"pool_name" yaml:"pool_name"`
}
func (c *kubernetesEngineService) GetClusterInfo(ctx context.Context, pool_id string) (*ClusterInfoResponse, error) {
var clusterInfoResponse ClusterInfoResponse
req, err := c.client.NewRequest(ctx, http.MethodGet, kubernetesServiceName, clusterInfo+"/"+pool_id, nil)
if err != nil {
return nil, err
}
resp, err := c.client.Do(ctx, req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
err = json.Unmarshal(body, &clusterInfoResponse)
if err != nil {
return nil, err
}
return &clusterInfoResponse, nil
}