Skip to content

Commit b5d7d4a

Browse files
Merge pull request #78 from codefresh-io/SAAS-4945
support toleration to venona pod
2 parents 65dbab2 + f2a38c3 commit b5d7d4a

File tree

8 files changed

+110
-13
lines changed

8 files changed

+110
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "venona",
3-
"version": "0.28.5",
3+
"version": "0.29.0",
44
"description": "Codefresh agent to run on Codefresh's runtime environment and execute pipeline",
55
"main": "index.js",
66
"scripts": {

venonactl/cmd/install.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020
"errors"
2121
"fmt"
2222
"strings"
23+
"encoding/json"
24+
"gopkg.in/yaml.v2"
25+
"io/ioutil"
2326

2427
"k8s.io/client-go/tools/clientcmd"
2528

@@ -35,6 +38,12 @@ const (
3538
namespaceMaxLength = 20
3639
)
3740

41+
type toleration struct {
42+
Key string `json:key`
43+
Operator string `json:operator`
44+
Effect string `json:effect`
45+
}
46+
3847
var installCmdOptions struct {
3948
dryRun bool
4049
clusterNameInCodefresh string
@@ -55,6 +64,7 @@ var installCmdOptions struct {
5564
kubernetesRunnerType bool
5665
buildNodeSelector string
5766
buildAnnotations []string
67+
tolerationJsonString string
5868
}
5969

6070
// installCmd represents the install command
@@ -108,6 +118,20 @@ var installCmd = &cobra.Command{
108118
}
109119
s.KubernetesAPI.NodeSelector = kns.String()
110120

121+
if installCmdOptions.tolerationJsonString != "" {
122+
123+
data, err := ioutil.ReadFile(installCmdOptions.tolerationJsonString)
124+
if err != nil {
125+
dieOnError(err)
126+
}
127+
tolerations, err := parseToleration(string(data))
128+
if err != nil {
129+
dieOnError(err)
130+
}
131+
s.KubernetesAPI.Tolerations = tolerations
132+
}
133+
134+
111135
if installCmdOptions.dryRun {
112136
s.DryRun = installCmdOptions.dryRun
113137
lgr.Info("Running in dry-run mode")
@@ -200,6 +224,7 @@ func init() {
200224
installCmd.Flags().StringVar(&installCmdOptions.kube.nodeSelector, "kube-node-selector", "", "The kubernetes node selector \"key=value\" to be used by venona resources (default is no node selector)")
201225
installCmd.Flags().StringVar(&installCmdOptions.buildNodeSelector, "build-node-selector", "", "The kubernetes node selector \"key=value\" to be used by venona build resources (default is no node selector)")
202226
installCmd.Flags().StringArrayVar(&installCmdOptions.buildAnnotations, "build-annotations", []string{}, "The kubernetes metadata.annotations as \"key=value\" to be used by venona build resources (default is no node selector)")
227+
installCmd.Flags().StringVar(&installCmdOptions.tolerationJsonString, "tolerations", "", "The kubernetes tolerations as JSON string to be used by venona resources (default is no tolerations)")
203228

204229
installCmd.Flags().BoolVar(&installCmdOptions.skipRuntimeInstallation, "skip-runtime-installation", false, "Set flag if you already have a configured runtime-environment, add --runtime-environment flag with name")
205230
installCmd.Flags().BoolVar(&installCmdOptions.kube.inCluster, "in-cluster", false, "Set flag if venona is been installed from inside a cluster")
@@ -223,6 +248,23 @@ func parseNodeSelector(s string) (nodeSelector, error) {
223248
return nodeSelector{v[0]: v[1]}, nil
224249
}
225250

251+
func parseToleration(s string) (string, error) {
252+
if s == "" {
253+
return "", nil
254+
}
255+
data := []toleration{}
256+
err := json.Unmarshal([]byte(s), &data);
257+
if (err != nil) {
258+
return "", errors.New("can not parse tolerations")
259+
}
260+
y, err := yaml.Marshal(&data)
261+
if (err != nil) {
262+
return "", errors.New("can not marshel tolerations to yaml")
263+
}
264+
d := fmt.Sprintf("\n%s", string(y))
265+
return d, nil
266+
}
267+
226268
func validateInstallOptions(opts* plugins.InstallOptions) (error) {
227269
if len(opts.ClusterName) > clusterNameMaxLength {
228270
return errors.New(fmt.Sprintf("cluster name length is limited to %d", clusterNameMaxLength))

venonactl/go.mod

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,35 @@ module github.com/codefresh-io/venona/venonactl
33
require (
44
contrib.go.opencensus.io/exporter/ocagent v0.4.3 // indirect
55
github.com/Azure/go-autorest v11.4.0+incompatible // indirect
6+
github.com/Masterminds/goutils v1.1.0 // indirect
7+
github.com/Masterminds/semver v1.5.0 // indirect
8+
github.com/Masterminds/sprig v2.22.0+incompatible
69
github.com/codefresh-io/go-sdk v0.17.0
710
github.com/dustin/go-humanize v1.0.0
811
github.com/google/go-github/v21 v21.0.0
912
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367 // indirect
13+
github.com/google/uuid v1.1.1 // indirect
1014
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d // indirect
1115
github.com/gophercloud/gophercloud v0.0.0-20190206021053-df38e1611dbe // indirect
1216
github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7 // indirect
1317
github.com/hashicorp/go-version v1.1.0
18+
github.com/huandu/xstrings v1.3.0 // indirect
1419
github.com/imdario/mergo v0.3.5 // indirect
1520
github.com/inconshreveable/log15 v0.0.0-20180818164646-67afb5ed74ec
1621
github.com/json-iterator/go v0.0.0-20180701071628-ab8a2e0c74be // indirect
17-
github.com/magiconair/properties v1.8.1 // indirect
1822
github.com/mattn/go-colorable v0.1.0 // indirect
1923
github.com/mattn/go-isatty v0.0.4 // indirect
24+
github.com/mitchellh/copystructure v1.0.0 // indirect
2025
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
2126
github.com/modern-go/reflect2 v1.0.1 // indirect
22-
github.com/olekukonko/tablewriter v0.0.1
23-
github.com/pelletier/go-toml v1.4.0 // indirect
27+
github.com/olekukonko/tablewriter v0.0.4
2428
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
25-
github.com/spf13/afero v1.2.2 // indirect
2629
github.com/spf13/cobra v0.0.5
27-
github.com/spf13/jwalterweatherman v1.1.0 // indirect
28-
github.com/spf13/pflag v1.0.5 // indirect
29-
github.com/spf13/viper v1.4.0
30+
github.com/spf13/viper v1.6.1
3031
go.opencensus.io v0.19.0 // indirect
31-
golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed // indirect
32-
golang.org/x/text v0.3.2 // indirect
3332
google.golang.org/appengine v1.4.0 // indirect
3433
gopkg.in/inf.v0 v0.9.0 // indirect
35-
gopkg.in/yaml.v2 v2.2.3 // indirect
34+
gopkg.in/yaml.v2 v2.2.7
3635
k8s.io/api v0.0.0-20181221193117-173ce66c1e39
3736
k8s.io/apimachinery v0.0.0-20181127025237-2b1284ed4c93
3837
k8s.io/client-go v10.0.0+incompatible

0 commit comments

Comments
 (0)