Skip to content

Commit 89a7990

Browse files
Refactor tolerations arguments for the install command (#82)
* feat: ignore idea files * chore: run go fmt * refactor: use k8s api for tolerations * refactor: tolerations arguments * chore: update install options in README * chore: bump version to 0.30.0
1 parent f93ccd4 commit 89a7990

File tree

15 files changed

+528
-502
lines changed

15 files changed

+528
-502
lines changed

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# VENONA
2-
[![Go Report Card](https://goreportcard.com/badge/github.com/codefresh-io/venona)](https://goreportcard.com/report/github.com/codefresh-io/venona)
2+
[![Go Report Card](https://goreportcard.com/badge/github.com/codefresh-io/venona)](https://goreportcard.com/report/github.com/codefresh-io/venona)
33
[![Codefresh build status]( https://g.codefresh.io/api/badges/pipeline/codefresh-inc/codefresh-io%2Fvenona%2Fvenona?type=cf-1)]( https://g.codefresh.io/public/accounts/codefresh-inc/pipelines/codefresh-io/venona/venona)
44

55
## Installation
@@ -16,33 +16,37 @@
1616
### Install venona
1717

1818
* Download [venona's](https://github.com/codefresh-io/venona/releases) binary
19-
* With homebrew:
19+
* With homebrew:
2020
* `brew tap codefresh-io/venona`
2121
* `brew install venona`
2222
* Create namespace where venona should run<br />
2323
> `kubectl create namespace codefresh-runtime`
2424
* Create *new* runtime-environment with Venona's agents installed <br />
2525
> `venona install --kube-namespace codefresh-runtime`
2626
* Get the status <br />
27-
> `venona status`
27+
> `venona status`
2828
> `kubectl get pods -n codefresh-runtime`
2929
3030
#### Install Options
3131

3232
| Option Argument | Type | Description |
3333
| -------------------- | -------- | --------------------------------------------------- |
34+
| --build-annotations | stringArray | The kubernetes metadata.annotations as "key=value" to be used by venona build resources (default is no node selector) |
35+
| --build-node-selector | string | The kubernetes node selector "key=value" to be used by venona build resources (default is no node selector) |
3436
| --cluster-name | string | cluster name (if not passed runtime-environment will be created cluster-less); this is a friendly name used for metadata does not need to match the literal cluster name. Limited to 20 Characters. |
3537
| --dry-run | boolean | Set to true to simulate installation |
36-
| -h, --help | | help for install |
38+
| -h, --help | boolean | help for install |
3739
| --in-cluster | boolean | Set flag if venona is been installed from inside a cluster |
3840
| --kube-context-name | string | Name of the kubernetes context on which venona should be installed (default is current-context) [$KUBE_CONTEXT] |
39-
| --kube-namespace | string | Name of the namespace on which venona should be installed [$KUBE_NAMESPACE] |
40-
| --kubernetes-runner-type | string | Set the runner type to kubernetes (alpha feature) |
41-
| --only-runtime-environment | boolean | Set to true to only configure namespace as runtime-environment for Codefresh |
41+
| --kube-namespace | string |Name of the namespace on which venona should be installed [$KUBE_NAMESPACE] |
42+
| --kube-node-selector | string | The kubernetes node selector "key=value" to be used by venona resources (default is no node selector) |
43+
| --kubernetes-runner-type | boolean | Set the runner type to kubernetes (alpha feature) |
44+
| --only-runtime-environment | boolean | Set to true to onlky configure namespace as runtime-environment for Codefresh |
4245
| --runtime-environment | string | if --skip-runtime-installation set, will try to configure venona on current runtime-environment |
4346
| --set-default | boolean | Mark the install runtime-environment as default one after installation |
4447
| --skip-runtime-installation | boolean | Set flag if you already have a configured runtime-environment, add --runtime-environment flag with name |
4548
| --storage-class | string | Set a name of your custom storage class, note: this will not install volume provisioning components |
49+
| --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 |
4650
| --venona-version | string | Version of venona to install (default is the latest) |
4751

4852
#### Install on cluster version < 1.10
@@ -84,8 +88,8 @@ List of the resources that will be created
8488
* `cluster-role-binding.dind-volume-provisioner.yaml` - Binds the ClusterRole to `service-account.dind-volume-provisioner.re.yaml`
8589

8690
### Access the cluster from executed pipeline
87-
After a successfull installation of Venona, you'll be able to run a Codefresh pipeline on the configured cluster.
88-
However, the pipeline itself dosent have any permission to connect to the hosted cluster.
91+
After a successfull installation of Venona, you'll be able to run a Codefresh pipeline on the configured cluster.
92+
However, the pipeline itself dosent have any permission to connect to the hosted cluster.
8993
To make it work you need to add the cluster to Codefresh (make sure the service acount has all the permissions you need)
9094
> codefresh create cluster --kube-context CONTEXT_NAME --namespace NAMESPACE --serviceaccount SERVICE_ACCOUNT --behind-firewall
9195

@@ -96,5 +100,5 @@ Example: `codefresh get cluster`
96100
* Install <br />
97101
Example: `venona install --cluster-name CLUSTER`
98102
* Get the status <br />
99-
Example: `venona status RUNTIME-ENVIRONMENT`
103+
Example: `venona status RUNTIME-ENVIRONMENT`
100104
Example: `kubectl get pods -n NAMESPACE`

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.29.1",
3+
"version": "0.30.0",
44
"description": "Codefresh agent to run on Codefresh's runtime environment and execute pipeline",
55
"main": "index.js",
66
"scripts": {

venonactl/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/

venonactl/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ build-local:
55
@sh ./hack/build.sh
66

77
build-linux:
8-
@sh ./hack/build-linux.sh
8+
@sh ./hack/build-linux.sh
9+
10+
fmt:
11+
go fmt ./...

venonactl/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.29.1
1+
0.30.0

venonactl/cmd/install.go

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ limitations under the License.
1717
*/
1818

1919
import (
20+
"encoding/json"
2021
"errors"
2122
"fmt"
22-
"strings"
23-
"encoding/json"
2423
"gopkg.in/yaml.v2"
2524
"io/ioutil"
25+
"strings"
2626

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

@@ -31,19 +31,14 @@ import (
3131
"github.com/codefresh-io/venona/venonactl/pkg/plugins"
3232
"github.com/spf13/cobra"
3333
"github.com/spf13/viper"
34+
k8sApi "k8s.io/api/core/v1"
3435
)
3536

3637
const (
3738
clusterNameMaxLength = 20
38-
namespaceMaxLength = 20
39+
namespaceMaxLength = 20
3940
)
4041

41-
type toleration struct {
42-
Key string `json:key`
43-
Operator string `json:operator`
44-
Effect string `json:effect`
45-
}
46-
4742
var installCmdOptions struct {
4843
dryRun bool
4944
clusterNameInCodefresh string
@@ -64,7 +59,7 @@ var installCmdOptions struct {
6459
kubernetesRunnerType bool
6560
buildNodeSelector string
6661
buildAnnotations []string
67-
tolerationJsonString string
62+
tolerations string
6863
}
6964

7065
// installCmd represents the install command
@@ -118,19 +113,22 @@ var installCmd = &cobra.Command{
118113
}
119114
s.KubernetesAPI.NodeSelector = kns.String()
120115

121-
if installCmdOptions.tolerationJsonString != "" {
122-
123-
data, err := ioutil.ReadFile(installCmdOptions.tolerationJsonString)
124-
if err != nil {
125-
dieOnError(err)
116+
if installCmdOptions.tolerations != "" {
117+
var tolerationsString string
118+
119+
if installCmdOptions.tolerations[0] == '@' {
120+
tolerationsString = loadTolerationsFromFile(installCmdOptions.tolerations[1:])
121+
} else {
122+
tolerationsString = installCmdOptions.tolerations
126123
}
127-
tolerations, err := parseToleration(string(data))
124+
125+
tolerations, err := parseTolerations(tolerationsString)
128126
if err != nil {
129127
dieOnError(err)
130128
}
129+
131130
s.KubernetesAPI.Tolerations = tolerations
132131
}
133-
134132

135133
if installCmdOptions.dryRun {
136134
s.DryRun = installCmdOptions.dryRun
@@ -224,7 +222,7 @@ func init() {
224222
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)")
225223
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)")
226224
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)")
225+
installCmd.Flags().StringVar(&installCmdOptions.tolerations, "tolerations", "", `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`)
228226

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

251-
func parseToleration(s string) (string, error) {
249+
func loadTolerationsFromFile(filename string) string {
250+
data, err := ioutil.ReadFile(filename)
251+
if err != nil {
252+
dieOnError(err)
253+
}
254+
255+
return string(data)
256+
}
257+
258+
func parseTolerations(s string) (string, error) {
252259
if s == "" {
253260
return "", nil
254261
}
255-
data := []toleration{}
256-
err := json.Unmarshal([]byte(s), &data);
257-
if (err != nil) {
258-
return "", errors.New("can not parse tolerations")
262+
var data []k8sApi.Toleration
263+
err := json.Unmarshal([]byte(s), &data)
264+
if err != nil {
265+
return "", fmt.Errorf("can not parse tolerations: %s", err)
259266
}
260267
y, err := yaml.Marshal(&data)
261-
if (err != nil) {
262-
return "", errors.New("can not marshel tolerations to yaml")
268+
if err != nil {
269+
return "", fmt.Errorf("can not marshel tolerations to yaml: %s", err)
263270
}
264271
d := fmt.Sprintf("\n%s", string(y))
265272
return d, nil
266273
}
267274

268-
func validateInstallOptions(opts* plugins.InstallOptions) (error) {
275+
func validateInstallOptions(opts *plugins.InstallOptions) error {
269276
if len(opts.ClusterName) > clusterNameMaxLength {
270277
return errors.New(fmt.Sprintf("cluster name length is limited to %d", clusterNameMaxLength))
271278
}
272279
if len(opts.ClusterNamespace) > namespaceMaxLength {
273280
return errors.New(fmt.Sprintf("cluster namespace length is limited to %d", namespaceMaxLength))
274-
}
281+
}
275282
return nil
276283
}
277284

venonactl/hack/build-linux.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
set -e
33
OUTFILE=$PWD/venonactl-linux
44
go generate ${PWD}/hack/generate.go
5+
go fmt ${PWD}/pkg/obj/kubeobj/kubeobj.go
6+
go fmt ${PWD}/pkg/templates/kubernetes/templates.go
57
GOOS=linux GOARCH=386 go build -ldflags '-X github.com/codefresh-io/venona/venonactl/cmd.localDevFlow=true' -o $OUTFILE main.go
68

7-
chmod +x $OUTFILE
9+
chmod +x $OUTFILE

venonactl/hack/build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
set -e
33
OUTFILE=/usr/local/bin/venonactl
44
go generate ${PWD}/hack/generate.go
5+
go fmt ${PWD}/pkg/obj/kubeobj/kubeobj.go
6+
go fmt ${PWD}/pkg/templates/kubernetes/templates.go
57
go build -ldflags '-X github.com/codefresh-io/venona/venonactl/cmd.localDevFlow=true' -o $OUTFILE main.go
68

7-
chmod +x $OUTFILE
9+
chmod +x $OUTFILE

0 commit comments

Comments
 (0)