-
Notifications
You must be signed in to change notification settings - Fork 1
/
cluster_profiles.go
81 lines (75 loc) · 1.71 KB
/
cluster_profiles.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
package main
import (
"encoding/json"
"fmt"
"log"
"github.com/nikhilsbhat/gocd-sdk-go"
)
func main() {
auth := gocd.Auth{
UserName: "admin",
Password: "admin",
}
client := gocd.NewClient("http://localhost:8153/go", auth, "info", nil)
clusterProfileConfig := gocd.CommonConfig{
ID: "sample-cluster-profile",
PluginID: "cd.go.contrib.elasticagent.kubernetes",
Properties: []gocd.PluginConfiguration{
{
Key: "go_server_url",
Value: "https://gocd.sample.com/go",
},
{
Key: "auto_register_timeout",
Value: "15",
},
{
Key: "pending_pods_count",
Value: "2",
},
{
Key: "kubernetes_cluster_url",
Value: "https://0.0.0.0:64527",
},
{
Key: "namespace",
Value: "default",
},
{
Key: "security_token",
Value: "dGVoZHhuZGhueGl3dWRoZnhua2R3aGZuaXdkdWZobnh3",
},
{
Key: "kubernetes_cluster_ca_cert",
Value: "dGVoZHhuZGhueGl3dWRoZnhua2R3aGZuaXdkdWZobnh3",
},
},
ETAG: "",
}
createClusterProfiles(client, clusterProfileConfig)
jsonOut, err := json.MarshalIndent(getClusterProfiles(client, clusterProfileConfig.ID), " ", " ")
if err != nil {
log.Fatal(err)
} else {
fmt.Println(string(jsonOut))
}
}
func getClusterProfiles(client gocd.GoCd, id string) gocd.CommonConfig {
clusterProfile, err := client.GetClusterProfile(id)
if err != nil {
log.Fatal(err)
}
return clusterProfile
}
func createClusterProfiles(client gocd.GoCd, config gocd.CommonConfig) gocd.CommonConfig {
out, err := json.MarshalIndent(config, " ", " ")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(out))
clusterProfile, err := client.CreateClusterProfile(config)
if err != nil {
log.Fatal(err)
}
return clusterProfile
}