-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathkargo.go
96 lines (84 loc) · 2.72 KB
/
kargo.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
// Copyright 2017 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package kargo
import (
"flag"
"fmt"
"io"
)
var (
apiHost string
cpuLimit string
cpuRequest string
memoryLimit string
memoryRequest string
namespace string
replicas int
EnableKubernetes bool
)
func init() {
flag.StringVar(&apiHost, "api-host", "127.0.0.1:8001", "Kubernetes API server")
flag.StringVar(&cpuLimit, "cpu-limit", "100m", "Max CPU in milicores")
flag.StringVar(&cpuRequest, "cpu-request", "100m", "Min CPU in milicores")
flag.StringVar(&memoryLimit, "memory-limit", "64M", "Max memory in MB")
flag.StringVar(&memoryRequest, "memory-request", "64M", "Min memory in MB")
flag.StringVar(&namespace, "namespace", "default", "The Kubernetes namespace.")
flag.IntVar(&replicas, "replicas", 1, "Number of replicas")
flag.BoolVar(&EnableKubernetes, "kubernetes", false, "Deploy to Kubernetes.")
}
type DeploymentConfig struct {
Annotations map[string]string
Args []string
Env map[string]string
BinaryURL string
cpuRequest string
cpuLimit string
memoryRequest string
memoryLimit string
Name string
Namespace string
Replicas int
Labels map[string]string
}
type DeploymentManager struct {
apiHost string
config DeploymentConfig
}
func New() *DeploymentManager {
return &DeploymentManager{apiHost: apiHost}
}
func (dm *DeploymentManager) Create(config DeploymentConfig) error {
config.cpuRequest = cpuRequest
config.cpuLimit = cpuLimit
config.memoryRequest = memoryRequest
config.memoryLimit = memoryLimit
config.Replicas = replicas
config.Namespace = namespace
if config.Env == nil {
config.Env = make(map[string]string)
}
if config.Annotations == nil {
config.Annotations = make(map[string]string)
}
if config.Labels == nil {
config.Labels = make(map[string]string)
}
dm.config = config
fmt.Printf("Creating %s ReplicaSet...\n", config.Name)
return createReplicaSet(dm.config)
}
func (dm *DeploymentManager) Delete() error {
fmt.Printf("Deleting %s ReplicaSet...\n", dm.config.Name)
return deleteReplicaSet(dm.config)
}
func (dm *DeploymentManager) Logs(w io.Writer) error {
return getLogs(dm.config, w)
}