-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.go
120 lines (105 loc) · 2.46 KB
/
create.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
package main
func CreateReplicaSet(cmdstr string, objectName string, namespace string) ReplicaSet {
//Creates a replicaset by constructing a golang object
//of the required type signature and marshalls it
//and sends it to the kubernetes api endpoint with
//the specified namespace
rs := ReplicaSet{
Kind: "ReplicaSet",
ApiVersion: "extensions/v1beta1",
Meta: Metadata{
Name: objectName,
Namespace: namespace,
Labels: map[string]string{
"name": objectName,
},
},
Spec: ReplicaSpec{
Replicas: 3,
Selector: ReplicaSelector{
MatchLabels: map[string]string{
"name": objectName,
},
},
Template: ReplicaTemplate{
Meta: Metadata{
Labels: map[string]string{
"name": objectName,
},
},
Spec: map[string][]Container{
"containers": []Container{
Container{
Image: "extrasalt/wgettu",
Name: objectName,
Command: []string{"sh", "-c", cmdstr},
},
},
},
},
},
}
// endpoint := fmt.Sprintf("/apis/extensions/v1beta1/namespaces/%s/replicasets", namespace)
// sendToKube(rs, endpoint)
return rs
}
func CreateService(objectName string, namespace string) Service {
//Creates a service by constructing a golang object
//of the required type signature and marshalls it
//and sends it to the kubernetes api endpoint with
//the specified namespace
//Plants the upload binary objectname in different
//fields in the go object
spec := ServiceSpec{
Selector: map[string]string{
"name": objectName,
},
ServiceType: "NodePort",
Ports: []ServicePort{
ServicePort{
Port: 8000,
Protocol: "TCP",
},
},
}
serv := Service{
ApiVersion: "v1",
Kind: "Service",
Meta: ServiceMetadata{
Name: objectName,
},
Spec: spec,
}
//endpoint := fmt.Sprintf("/api/v1/namespaces/%s/services", namespace)
//kube.sendToKube(serv, endpoint)
return serv
}
func CreateNamespace(name string) Namespace {
//Creates the namespace for the given value
//and sends it to kubernetes api
//by calling the function
ns := Namespace{
Kind: "Namespace",
ApiVersion: "v1",
Meta: NamespaceMeta{
Name: name,
Labels: map[string]string{
"name": name,
},
},
}
// endpoint := "/api/v1/namespaces"
// kube.sendToKube(ns, endpoint)
return ns
}
// *Reference*
// {
// "kind": "Namespace",
// "apiVersion": "v1",
// "metadata": {
// "name": "development",
// "labels": {
// "name": "development"
// }
// }
// }