Skip to content

Commit e927044

Browse files
read tolerations from values file (#207)
* read tolerations from values file
1 parent 5256d04 commit e927044

File tree

14 files changed

+71
-81
lines changed

14 files changed

+71
-81
lines changed

venona/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.8
1+
1.5.9

venonactl/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.8
1+
1.5.9

venonactl/cmd/cmdutils.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/codefresh-io/venona/venonactl/pkg/plugins"
2121
"github.com/codefresh-io/venona/venonactl/pkg/store"
2222
"github.com/olekukonko/tablewriter"
23-
"gopkg.in/yaml.v2"
2423
k8sApi "k8s.io/api/core/v1"
2524
"k8s.io/client-go/tools/clientcmd"
2625

@@ -202,21 +201,16 @@ func loadTolerationsFromFile(filename string) string {
202201
return string(data)
203202
}
204203

205-
func parseTolerations(s string) (string, error) {
204+
func parseTolerations(s string) ([]k8sApi.Toleration, error) {
206205
if s == "" {
207-
return "", nil
206+
return nil, nil
208207
}
209208
var data []k8sApi.Toleration
210209
err := json.Unmarshal([]byte(s), &data)
211210
if err != nil {
212-
return "", fmt.Errorf("can not parse tolerations: %s", err)
211+
return nil, fmt.Errorf("can not parse tolerations: %s", err)
213212
}
214-
y, err := yaml.Marshal(&data)
215-
if err != nil {
216-
return "", fmt.Errorf("can not marshel tolerations to yaml: %s", err)
217-
}
218-
d := fmt.Sprintf("\n%s", string(y))
219-
return d, nil
213+
return data, err
220214
}
221215

222216
func fillKubernetesAPI(lgr logger.Logger, context string, namespace string, inCluster bool) {
@@ -323,4 +317,4 @@ func mergeValueMSI(valuesMap map[string]interface{}, key string, param *map[stri
323317
}
324318
val := mapX.Get(key).MSI(defaultValue...)
325319
*param = val
326-
}
320+
}

venonactl/cmd/install-agent.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/codefresh-io/venona/venonactl/pkg/store"
2626
"github.com/spf13/cobra"
2727
"github.com/spf13/viper"
28+
k8sApi "k8s.io/api/core/v1"
2829
// cliValues "helm.sh/helm/v3/pkg/cli/values"
2930
// "helm.sh/helm/v3/pkg/getter"
3031
)
@@ -72,7 +73,9 @@ var installAgentCmd = &cobra.Command{
7273
mergeValueStr(templateValuesMap, "Context", &installAgentCmdOptions.kube.context)
7374
mergeValueStr(templateValuesMap, "NodeSelector", &installAgentCmdOptions.kube.nodeSelector)
7475
tolerations := getTolerations()
75-
mergeValueStr(templateValuesMap, "Tolerations", &tolerations)
76+
if tolerations != nil {
77+
templateValuesMap["Tolerations"] = tolerations
78+
}
7679
mergeValueStr(templateValuesMap, "DockerRegistry", &installAgentCmdOptions.dockerRegistry)
7780

7881
mergeValueStr(templateValuesMap, "AgentToken", &installAgentCmdOptions.agentToken)
@@ -152,7 +155,7 @@ var installAgentCmd = &cobra.Command{
152155
},
153156
}
154157

155-
func getTolerations() string {
158+
func getTolerations() []k8sApi.Toleration {
156159

157160
if installAgentCmdOptions.tolerations != "" {
158161
var tolerationsString string
@@ -170,7 +173,7 @@ func getTolerations() string {
170173
return tolerations
171174

172175
}
173-
return ""
176+
return nil
174177
}
175178

176179
func init() {

venonactl/cmd/install-runtime.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ var installRuntimeCmd = &cobra.Command{
6969
mergeValueStr(templateValuesMap, "Context", &installRuntimeCmdOptions.kube.context)
7070
mergeValueStr(templateValuesMap, "RuntimeEnvironmentName", &installRuntimeCmdOptions.runtimeEnvironmentName)
7171
mergeValueStr(templateValuesMap, "NodeSelector", &installRuntimeCmdOptions.kube.nodeSelector)
72-
mergeValueStr(templateValuesMap, "Tolerations", &installRuntimeCmdOptions.tolerations)
72+
tolerations := getTolerations()
73+
if tolerations != nil {
74+
templateValuesMap["Tolerations"] = tolerations
75+
}
7376
//mergeValueStrArray(&installAgentCmdOptions.envVars, "envVars", nil, "More env vars to be declared \"key=value\"")
7477
mergeValueStr(templateValuesMap, "DockerRegistry", &installRuntimeCmdOptions.dockerRegistry)
7578
mergeValueStr(templateValuesMap, "StorageClass", &installRuntimeCmdOptions.storageClass)
@@ -107,22 +110,7 @@ var installRuntimeCmd = &cobra.Command{
107110
Host: cfAPIHost,
108111
}
109112

110-
if installRuntimeCmdOptions.tolerations != "" {
111-
var tolerationsString string
112-
113-
if installRuntimeCmdOptions.tolerations[0] == '@' {
114-
tolerationsString = loadTolerationsFromFile(installRuntimeCmdOptions.tolerations[1:])
115-
} else {
116-
tolerationsString = installRuntimeCmdOptions.tolerations
117-
}
118-
119-
tolerations, err := parseTolerations(tolerationsString)
120-
if err != nil {
121-
dieOnError(err)
122-
}
123-
124-
s.KubernetesAPI.Tolerations = tolerations
125-
}
113+
s.KubernetesAPI.Tolerations = tolerations
126114

127115
s.KubernetesAPI.NodeSelector = installRuntimeCmdOptions.kube.nodeSelector
128116
s.DockerRegistry = installRuntimeCmdOptions.dockerRegistry

venonactl/example/values-example.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@
259259
# requests:
260260
# cpu: 200m
261261
# memory: 500Mi
262+
# userVolumeMounts: # will be set for dind pod and will be injcted for each container - https://codefresh.io/docs/docs/administration/codefresh-runner/#custom-volume-mounts
263+
# my-test:
264+
# name: test
265+
# mountPath: /etc/ssl/cert
266+
# readOnly: true
267+
# userVolumes: # will be set for dind pod and will be injcted for each container - https://codefresh.io/docs/docs/administration/codefresh-runner/#custom-volume-mounts
268+
# test:
269+
# name: test
270+
# secret:
271+
# secretName: test-secret
262272

263273

264274
########################################################

venonactl/pkg/plugins/helper.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,15 @@ func nodeSelectorParamToYaml(ns string) string {
8989
}
9090

9191
func toYAML(v interface{}) string {
92-
data, err := yaml.Marshal(v)
93-
if err != nil {
94-
// Swallow errors inside of a template.
95-
return ""
96-
}
97-
return strings.TrimSuffix(string(data), "\n")
98-
}
99-
100-
func toYAMLMSI(v map[string]interface{}) string {
101-
if len(v) == 0 {
102-
return ""
92+
switch v.(type) {
93+
case map[string]interface{}:
94+
if len(v.(map[string]interface{})) == 0 {
95+
return ""
96+
}
97+
case []v1.Toleration:
98+
if len(v.([]v1.Toleration)) == 0 {
99+
return ""
100+
}
103101
}
104102
data, err := yaml.Marshal(v)
105103
if err != nil {
@@ -140,7 +138,6 @@ func ExecuteTemplate(tplStr string, data interface{}) (string, error) {
140138
"unescape": unescape,
141139
"nodeSelectorParamToYaml": nodeSelectorParamToYaml,
142140
"toYaml": toYAML,
143-
"toYamlMsi": toYAMLMSI,
144141
"isString": isString,
145142
}
146143
template, err := template.New("base").Funcs(sprig.FuncMap()).Funcs(funcMap).Parse(tplStr)

venonactl/pkg/store/store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/codefresh-io/go-sdk/pkg/codefresh"
77
"github.com/codefresh-io/venona/venonactl/pkg/certs"
8+
k8sApi "k8s.io/api/core/v1"
89
)
910

1011
const (
@@ -75,7 +76,7 @@ type (
7576
ContextName string
7677
InCluster bool
7778
NodeSelector string
78-
Tolerations string
79+
Tolerations []k8sApi.Toleration
7980
}
8081

8182
CodefreshAPI struct {
@@ -175,7 +176,6 @@ func (s *Values) BuildValues() map[string]interface{} {
175176
"VolumeProvisioner": map[string]interface{}{
176177
"Image": "codefresh/dind-volume-provisioner:v24",
177178
"NodeSelector": s.KubernetesAPI.NodeSelector,
178-
"Tolerations": s.KubernetesAPI.Tolerations,
179179
"Resources": s.VolumeProvisioner.Resources,
180180
"MountAzureJson": false,
181181
},

venonactl/pkg/templates/kubernetes/daemonset.dind-lv-monitor.vp.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ spec:
2828
- key: 'codefresh/dind'
2929
operator: 'Exists'
3030
effect: 'NoSchedule'
31-
{{ if ne .Tolerations "" }}
32-
{{ .Tolerations | indent 8 }}
33-
{{ end }}
31+
32+
{{ toYaml .Tolerations | indent 8}}
33+
34+
3435
containers:
3536
- image: {{ if ne .DockerRegistry ""}} {{- .DockerRegistry }}/codefresh/dind-volume-utils:v5 {{- else }}codefresh/dind-volume-utils:v5{{- end}}
3637
name: lv-cleaner
3738
resources:
38-
{{ toYamlMsi .Storage.LocalVolumeMonitor | indent 10 }}
39+
{{ toYaml .Storage.LocalVolumeMonitor | indent 10 }}
3940
imagePullPolicy: Always
4041
command:
4142
- /bin/local-volumes-agent

venonactl/pkg/templates/kubernetes/deployment.app-proxy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
image: {{ if ne .DockerRegistry ""}} {{- .DockerRegistry }}/{{ .AppProxy.Image.Name }}:{{ .AppProxy.Image.Tag }} {{- else }} {{- .AppProxy.Image.Name }}:{{ .AppProxy.Image.Tag }} {{- end}}
3333
imagePullPolicy: Always
3434
resources:
35-
{{ toYamlMsi .AppProxy.resources | indent 10 }}
35+
{{ toYaml .AppProxy.resources | indent 10 }}
3636
env:
3737
{{- if $.EnvVars }}
3838
{{- range $key, $value := $.EnvVars }}

0 commit comments

Comments
 (0)