Skip to content

Commit 4a2555e

Browse files
author
kosta709
committed
added dind-storage - draft1
1 parent dba7642 commit 4a2555e

File tree

13 files changed

+211
-17
lines changed

13 files changed

+211
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
| --skip-runtime-installation | boolean | Set flag if you already have a configured runtime-environment, add --runtime-environment flag with name |
4848
| --storage-class | string | Set a name of your custom storage class, note: this will not install volume provisioning components |
4949
| --tolerations | string | The kubernetes tolerations as JSON string to be used by venona resources (default is no tolerations). If prefixed with "@", loads from a file: @/tmp/tolerations.json |
50-
| --set-value | stringArray | Set values for templates, example: --set-value LocalVolumeDir=/mnt/disk/ssd0/codefresh-volumes |
50+
| --set-value | stringArray | Set values for templates, example: --set-value Storage.LocalVolumeParentDir=/mnt/disk/ssd0/codefresh-volumes |
5151
| --venona-version | string | Version of venona to install (default is the latest) |
5252

5353
#### Install on cluster version < 1.10

venonactl/cmd/install.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ var installCmd = &cobra.Command{
207207
dieOnError(fmt.Errorf("Cannot parse option --set-value %s", value))
208208
}
209209
}
210-
for k, v := range base {
211-
values[k] = v
212-
}
210+
211+
values = mergeMaps(values, base)
213212

214213
for _, p := range builder.Get() {
215214
values, err = p.Install(builderInstallOpt, values)
@@ -221,6 +220,25 @@ var installCmd = &cobra.Command{
221220
},
222221
}
223222

223+
func mergeMaps(a, b map[string]interface{}) map[string]interface{} {
224+
out := make(map[string]interface{}, len(a))
225+
for k, v := range a {
226+
out[k] = v
227+
}
228+
for k, v := range b {
229+
if v, ok := v.(map[string]interface{}); ok {
230+
if bv, ok := out[k]; ok {
231+
if bv, ok := bv.(map[string]interface{}); ok {
232+
out[k] = mergeMaps(bv, v)
233+
continue
234+
}
235+
}
236+
}
237+
out[k] = v
238+
}
239+
return out
240+
}
241+
224242
func init() {
225243
rootCmd.AddCommand(installCmd)
226244

venonactl/go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,10 @@ gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
647647
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
648648
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
649649
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
650+
helm.sh/helm v2.16.3+incompatible h1:a7P7FSGTBdK6ZsAcWWZZQXPIdzkgybD8CWd/Dy+jwf4=
650651
helm.sh/helm/v3 v3.1.1 h1:aykwPMVyQyncZ8iLNVMXgJ1l3c6W0+LSOPmqp8JdCjs=
651652
helm.sh/helm/v3 v3.1.1/go.mod h1:WYsFJuMASa/4XUqLyv54s0U/f3mlAaRErGmyy4z921g=
653+
helm.sh/helm/v3 v3.1.2 h1:VpNzaNv2DX4aRnOCcV7v5Of+XT2SZrJ8iOQ25AGKOos=
652654
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
653655
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
654656
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
@@ -659,6 +661,7 @@ k8s.io/apiextensions-apiserver v0.17.2/go.mod h1:4KdMpjkEjjDI2pPfBA15OscyNldHWdB
659661
k8s.io/apimachinery v0.17.2/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
660662
k8s.io/apimachinery v0.17.3 h1:f+uZV6rm4/tHE7xXgLyToprg6xWairaClGVkm2t8omg=
661663
k8s.io/apimachinery v0.17.3/go.mod h1:gxLnyZcGNdZTCLnq3fgzyg2A5BVCHTNDFrw8AmuJ+0g=
664+
k8s.io/apimachinery v0.17.4 h1:UzM+38cPUJnzqSQ+E1PY4YxMHIzQyCg29LOoGfo79Zw=
662665
k8s.io/apiserver v0.17.2/go.mod h1:lBmw/TtQdtxvrTk0e2cgtOxHizXI+d0mmGQURIHQZlo=
663666
k8s.io/cli-runtime v0.17.2/go.mod h1:aa8t9ziyQdbkuizkNLAw3qe3srSyWh9zlSB7zTqRNPI=
664667
k8s.io/client-go v0.17.2/go.mod h1:QAzRgsa0C2xl4/eVpeVAZMvikCn8Nm81yqVx3Kk9XYI=

venonactl/pkg/obj/kubeobj/kubeobj.go

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

venonactl/pkg/obj/kubeobj_generator.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ var functionsMap map[string]string = map[string]string{
5959
"rbacv1.RoleBinding": "RbacV1().RoleBindings(namespace)",
6060

6161
"storagev1.StorageClass": "StorageV1().StorageClasses()",
62+
63+
"batchv1.Job": "BatchV1().Jobs(namespace)",
64+
"batchv1beta1.CronJob": "BatchV1beta1().CronJobs(namespace)",
6265
}
6366

6467
var packageTemplate = template.Must(template.New("").Parse(
@@ -81,6 +84,9 @@ import (
8184
rbacv1 "k8s.io/api/rbac/v1"
8285
8386
storagev1 "k8s.io/api/storage/v1"
87+
88+
batchv1 "k8s.io/api/batch/v1"
89+
batchv1beta1 "k8s.io/api/batch/v1beta1"
8490
)
8591
8692
// CreateObject - creates kubernetes object from *runtime.Object. Returns object name, kind and creation error

venonactl/pkg/plugins/helper.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func ExecuteTemplate(tplStr string, data interface{}) (string, error) {
5353
// ParseTemplates - parses and exexute templates and return map of strings with obj data
5454
func ParseTemplates(templatesMap map[string]string, data interface{}, pattern string, logger logger.Logger) (map[string]string, error) {
5555
parsedTemplates := make(map[string]string)
56+
nonEmptyParsedTemplateFunc := regexp.MustCompile(`[a-zA-Z0-9]`).MatchString
5657
for n, tpl := range templatesMap {
5758
match, _ := regexp.MatchString(pattern, n)
5859
if match != true {
@@ -65,7 +66,12 @@ func ParseTemplates(templatesMap map[string]string, data interface{}, pattern st
6566
logger.Error("Failed to parse and execute template", "Name", n)
6667
return nil, err
6768
}
68-
parsedTemplates[n] = tplEx
69+
70+
// we add only non-empty parsedTemplates
71+
if nonEmptyParsedTemplateFunc(tplEx) {
72+
parsedTemplates[n] = tplEx
73+
}
74+
6975
}
7076
return parsedTemplates, nil
7177
}

venonactl/pkg/plugins/runtime-environment.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ func (u *runtimeEnvironmentPlugin) Install(opt *InstallOptions, v Values) (Value
5656
Annotations: opt.Annotations,
5757
}
5858

59+
// Set storage Class by backend
60+
if cfOpt.IsDefaultStorageClass {
61+
if storageBackend, storageBackendParamsSet := v["Storage"].(map[string]interface{})["Backend"]; storageBackendParamsSet {
62+
63+
switch storageBackend {
64+
case "local":
65+
cfOpt.StorageClass = fmt.Sprintf("dind-local-volumes-%s-%s", v["AppName"], v["Namespace"])
66+
case "gcedisk":
67+
cfOpt.StorageClass = fmt.Sprintf("dind-gcedisk-%s-%s-%s", v["AvailabilityZone"], v["AppName"], v["Namespace"])
68+
case "ebs":
69+
cfOpt.StorageClass = fmt.Sprintf("dind-ebs-%s-%s-%s", v["AvailabilityZone"], v["AppName"], v["Namespace"])
70+
}
71+
}
72+
}
73+
5974
cf := codefresh.NewCodefreshAPI(cfOpt)
6075
cert, err := cf.Sign()
6176
if err != nil {

venonactl/pkg/store/store.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,16 @@ func (s *Values) BuildValues() map[string]interface{} {
108108
"Key": "",
109109
"Ca": "",
110110
},
111+
"Storage": map[string]interface{}{
112+
"Backend": "local",
113+
"LocalVolumeParentDir": "/var/lib/codefresh/dind-volumes",
114+
"AvailabilityZone": "",
115+
"GoogleServiceAccount": "",
116+
"VolumeProvisioner": map[string]interface{}{
117+
"Image": "codefresh/dind-volume-provisioner:v20",
118+
"NodeSelector": s.KubernetesAPI.NodeSelector,
119+
"Tolerations": s.KubernetesAPI.Tolerations,
120+
},
121+
},
111122
}
112123
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{{- if not (eq .Storage.Backend "local") }}
2+
apiVersion: batch/v1beta1
3+
kind: CronJob
4+
metadata:
5+
name: dind-volume-cleanup-{{ .AppName }}
6+
namespace: {{ .Namespace }}
7+
labels:
8+
app: dind-volume-cleanup
9+
spec:
10+
schedule: "0,10,20,30,40,50 * * * *"
11+
concurrencyPolicy: Forbid
12+
jobTemplate:
13+
spec:
14+
template:
15+
spec:
16+
serviceAccountName: volume-provisioner-{{ .AppName }}
17+
restartPolicy: Never
18+
containers:
19+
- name: dind-volume-cleanup
20+
image: codefresh/dind-volume-cleanup
21+
{{- end }}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{{- if eq .Storage.Backend "local" -}}
2+
{{- $localVolumeParentDir := ( .Storage.LocalVolumeParentDir | default "/var/lib/codefresh/dind-volumes" ) }}
13
apiVersion: apps/v1
24
kind: DaemonSet
35
metadata:
@@ -45,7 +47,7 @@ spec:
4547
fieldRef:
4648
fieldPath: spec.nodeName
4749
- name: VOLUME_PARENT_DIR
48-
value: {{ .LocalVolumeDir | default "/var/lib/codefresh/dind-volumes" }}
50+
value: {{ $localVolumeParentDir }}
4951
# Debug:
5052
# - name: DRY_RUN
5153
# value: "1"
@@ -59,10 +61,11 @@ spec:
5961
# value: "20"
6062

6163
volumeMounts:
62-
- mountPath: /var/lib/codefresh/dind-volumes
64+
- mountPath: {{ $localVolumeParentDir }}
6365
readOnly: false
6466
name: dind-volume-dir
6567
volumes:
6668
- name: dind-volume-dir
6769
hostPath:
68-
path: /var/lib/codefresh/dind-volumes
70+
path: {{ $localVolumeParentDir }}
71+
{{- end -}}

0 commit comments

Comments
 (0)