Skip to content

Commit

Permalink
Merge pull request #78 from codefresh-io/SAAS-4945
Browse files Browse the repository at this point in the history
support toleration to venona pod
  • Loading branch information
oren-codefresh authored Jan 13, 2020
2 parents 65dbab2 + f2a38c3 commit b5d7d4a
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "venona",
"version": "0.28.5",
"version": "0.29.0",
"description": "Codefresh agent to run on Codefresh's runtime environment and execute pipeline",
"main": "index.js",
"scripts": {
Expand Down
42 changes: 42 additions & 0 deletions venonactl/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"errors"
"fmt"
"strings"
"encoding/json"
"gopkg.in/yaml.v2"
"io/ioutil"

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

Expand All @@ -35,6 +38,12 @@ const (
namespaceMaxLength = 20
)

type toleration struct {
Key string `json:key`
Operator string `json:operator`
Effect string `json:effect`
}

var installCmdOptions struct {
dryRun bool
clusterNameInCodefresh string
Expand All @@ -55,6 +64,7 @@ var installCmdOptions struct {
kubernetesRunnerType bool
buildNodeSelector string
buildAnnotations []string
tolerationJsonString string
}

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

if installCmdOptions.tolerationJsonString != "" {

data, err := ioutil.ReadFile(installCmdOptions.tolerationJsonString)
if err != nil {
dieOnError(err)
}
tolerations, err := parseToleration(string(data))
if err != nil {
dieOnError(err)
}
s.KubernetesAPI.Tolerations = tolerations
}


if installCmdOptions.dryRun {
s.DryRun = installCmdOptions.dryRun
lgr.Info("Running in dry-run mode")
Expand Down Expand Up @@ -200,6 +224,7 @@ func init() {
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)")
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)")
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)")
installCmd.Flags().StringVar(&installCmdOptions.tolerationJsonString, "tolerations", "", "The kubernetes tolerations as JSON string to be used by venona resources (default is no tolerations)")

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")
installCmd.Flags().BoolVar(&installCmdOptions.kube.inCluster, "in-cluster", false, "Set flag if venona is been installed from inside a cluster")
Expand All @@ -223,6 +248,23 @@ func parseNodeSelector(s string) (nodeSelector, error) {
return nodeSelector{v[0]: v[1]}, nil
}

func parseToleration(s string) (string, error) {
if s == "" {
return "", nil
}
data := []toleration{}
err := json.Unmarshal([]byte(s), &data);
if (err != nil) {
return "", errors.New("can not parse tolerations")
}
y, err := yaml.Marshal(&data)
if (err != nil) {
return "", errors.New("can not marshel tolerations to yaml")
}
d := fmt.Sprintf("\n%s", string(y))
return d, nil
}

func validateInstallOptions(opts* plugins.InstallOptions) (error) {
if len(opts.ClusterName) > clusterNameMaxLength {
return errors.New(fmt.Sprintf("cluster name length is limited to %d", clusterNameMaxLength))
Expand Down
19 changes: 9 additions & 10 deletions venonactl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,35 @@ module github.com/codefresh-io/venona/venonactl
require (
contrib.go.opencensus.io/exporter/ocagent v0.4.3 // indirect
github.com/Azure/go-autorest v11.4.0+incompatible // indirect
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/codefresh-io/go-sdk v0.17.0
github.com/dustin/go-humanize v1.0.0
github.com/google/go-github/v21 v21.0.0
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367 // indirect
github.com/google/uuid v1.1.1 // indirect
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d // indirect
github.com/gophercloud/gophercloud v0.0.0-20190206021053-df38e1611dbe // indirect
github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7 // indirect
github.com/hashicorp/go-version v1.1.0
github.com/huandu/xstrings v1.3.0 // indirect
github.com/imdario/mergo v0.3.5 // indirect
github.com/inconshreveable/log15 v0.0.0-20180818164646-67afb5ed74ec
github.com/json-iterator/go v0.0.0-20180701071628-ab8a2e0c74be // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mattn/go-colorable v0.1.0 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/olekukonko/tablewriter v0.0.1
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/olekukonko/tablewriter v0.0.4
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.4.0
github.com/spf13/viper v1.6.1
go.opencensus.io v0.19.0 // indirect
golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed // indirect
golang.org/x/text v0.3.2 // indirect
google.golang.org/appengine v1.4.0 // indirect
gopkg.in/inf.v0 v0.9.0 // indirect
gopkg.in/yaml.v2 v2.2.3 // indirect
gopkg.in/yaml.v2 v2.2.7
k8s.io/api v0.0.0-20181221193117-173ce66c1e39
k8s.io/apimachinery v0.0.0-20181127025237-2b1284ed4c93
k8s.io/client-go v10.0.0+incompatible
Expand Down
Loading

0 comments on commit b5d7d4a

Please sign in to comment.