From 89a7990d2e98ff863eefcbf0e122f200e27e8eb2 Mon Sep 17 00:00:00 2001 From: Fernando Carletti Date: Wed, 12 Feb 2020 10:23:06 -0600 Subject: [PATCH] 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 --- README.md | 24 +- package.json | 2 +- venonactl/.gitignore | 1 + venonactl/Makefile | 5 +- venonactl/VERSION | 2 +- venonactl/cmd/install.go | 61 +- venonactl/hack/build-linux.sh | 4 +- venonactl/hack/build.sh | 4 +- venonactl/pkg/obj/kubeobj/kubeobj.go | 826 +++++++++--------- venonactl/pkg/plugins/helper.go | 6 +- venonactl/pkg/plugins/venona.go | 4 +- venonactl/pkg/store/store.go | 2 +- .../daemonset.dind-lv-monitor.vp.yaml | 3 + ...deployment.dind-volume-provisioner.vp.yaml | 3 + .../pkg/templates/kubernetes/templates.go | 83 +- 15 files changed, 528 insertions(+), 502 deletions(-) create mode 100644 venonactl/.gitignore diff --git a/README.md b/README.md index cd28cd4a..c1658fab 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # VENONA -[![Go Report Card](https://goreportcard.com/badge/github.com/codefresh-io/venona)](https://goreportcard.com/report/github.com/codefresh-io/venona) +[![Go Report Card](https://goreportcard.com/badge/github.com/codefresh-io/venona)](https://goreportcard.com/report/github.com/codefresh-io/venona) [![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) ## Installation @@ -16,7 +16,7 @@ ### Install venona * Download [venona's](https://github.com/codefresh-io/venona/releases) binary - * With homebrew: + * With homebrew: * `brew tap codefresh-io/venona` * `brew install venona` * Create namespace where venona should run
@@ -24,25 +24,29 @@ * Create *new* runtime-environment with Venona's agents installed
> `venona install --kube-namespace codefresh-runtime` * Get the status
- > `venona status` + > `venona status` > `kubectl get pods -n codefresh-runtime` #### Install Options | Option Argument | Type | Description | | -------------------- | -------- | --------------------------------------------------- | +| --build-annotations | stringArray | The kubernetes metadata.annotations as "key=value" to be used by venona build resources (default is no node selector) | +| --build-node-selector | string | The kubernetes node selector "key=value" to be used by venona build resources (default is no node selector) | | --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. | | --dry-run | boolean | Set to true to simulate installation | -| -h, --help | | help for install | +| -h, --help | boolean | help for install | | --in-cluster | boolean | Set flag if venona is been installed from inside a cluster | | --kube-context-name | string | Name of the kubernetes context on which venona should be installed (default is current-context) [$KUBE_CONTEXT] | -| --kube-namespace | string | Name of the namespace on which venona should be installed [$KUBE_NAMESPACE] | -| --kubernetes-runner-type | string | Set the runner type to kubernetes (alpha feature) | -| --only-runtime-environment | boolean | Set to true to only configure namespace as runtime-environment for Codefresh | +| --kube-namespace | string |Name of the namespace on which venona should be installed [$KUBE_NAMESPACE] | +| --kube-node-selector | string | The kubernetes node selector "key=value" to be used by venona resources (default is no node selector) | +| --kubernetes-runner-type | boolean | Set the runner type to kubernetes (alpha feature) | +| --only-runtime-environment | boolean | Set to true to onlky configure namespace as runtime-environment for Codefresh | | --runtime-environment | string | if --skip-runtime-installation set, will try to configure venona on current runtime-environment | | --set-default | boolean | Mark the install runtime-environment as default one after installation | | --skip-runtime-installation | boolean | Set flag if you already have a configured runtime-environment, add --runtime-environment flag with name | | --storage-class | string | Set a name of your custom storage class, note: this will not install volume provisioning components | +| --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 | | --venona-version | string | Version of venona to install (default is the latest) | #### Install on cluster version < 1.10 @@ -84,8 +88,8 @@ List of the resources that will be created * `cluster-role-binding.dind-volume-provisioner.yaml` - Binds the ClusterRole to `service-account.dind-volume-provisioner.re.yaml` ### Access the cluster from executed pipeline -After a successfull installation of Venona, you'll be able to run a Codefresh pipeline on the configured cluster. -However, the pipeline itself dosent have any permission to connect to the hosted cluster. +After a successfull installation of Venona, you'll be able to run a Codefresh pipeline on the configured cluster. +However, the pipeline itself dosent have any permission to connect to the hosted cluster. To make it work you need to add the cluster to Codefresh (make sure the service acount has all the permissions you need) > codefresh create cluster --kube-context CONTEXT_NAME --namespace NAMESPACE --serviceaccount SERVICE_ACCOUNT --behind-firewall @@ -96,5 +100,5 @@ Example: `codefresh get cluster` * Install
Example: `venona install --cluster-name CLUSTER` * Get the status
-Example: `venona status RUNTIME-ENVIRONMENT` +Example: `venona status RUNTIME-ENVIRONMENT` Example: `kubectl get pods -n NAMESPACE` diff --git a/package.json b/package.json index f03c23d0..a96e336a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "venona", - "version": "0.29.1", + "version": "0.30.0", "description": "Codefresh agent to run on Codefresh's runtime environment and execute pipeline", "main": "index.js", "scripts": { diff --git a/venonactl/.gitignore b/venonactl/.gitignore new file mode 100644 index 00000000..9f11b755 --- /dev/null +++ b/venonactl/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/venonactl/Makefile b/venonactl/Makefile index aeacf60f..c9875dc9 100644 --- a/venonactl/Makefile +++ b/venonactl/Makefile @@ -5,4 +5,7 @@ build-local: @sh ./hack/build.sh build-linux: - @sh ./hack/build-linux.sh \ No newline at end of file + @sh ./hack/build-linux.sh + +fmt: + go fmt ./... diff --git a/venonactl/VERSION b/venonactl/VERSION index fde212bd..c25c8e5b 100644 --- a/venonactl/VERSION +++ b/venonactl/VERSION @@ -1 +1 @@ -0.29.1 \ No newline at end of file +0.30.0 diff --git a/venonactl/cmd/install.go b/venonactl/cmd/install.go index eac2fe45..0eac949c 100644 --- a/venonactl/cmd/install.go +++ b/venonactl/cmd/install.go @@ -17,12 +17,12 @@ limitations under the License. */ import ( + "encoding/json" "errors" "fmt" - "strings" - "encoding/json" "gopkg.in/yaml.v2" "io/ioutil" + "strings" "k8s.io/client-go/tools/clientcmd" @@ -31,19 +31,14 @@ import ( "github.com/codefresh-io/venona/venonactl/pkg/plugins" "github.com/spf13/cobra" "github.com/spf13/viper" + k8sApi "k8s.io/api/core/v1" ) const ( clusterNameMaxLength = 20 - namespaceMaxLength = 20 + namespaceMaxLength = 20 ) -type toleration struct { - Key string `json:key` - Operator string `json:operator` - Effect string `json:effect` -} - var installCmdOptions struct { dryRun bool clusterNameInCodefresh string @@ -64,7 +59,7 @@ var installCmdOptions struct { kubernetesRunnerType bool buildNodeSelector string buildAnnotations []string - tolerationJsonString string + tolerations string } // installCmd represents the install command @@ -118,19 +113,22 @@ var installCmd = &cobra.Command{ } s.KubernetesAPI.NodeSelector = kns.String() - if installCmdOptions.tolerationJsonString != "" { - - data, err := ioutil.ReadFile(installCmdOptions.tolerationJsonString) - if err != nil { - dieOnError(err) + if installCmdOptions.tolerations != "" { + var tolerationsString string + + if installCmdOptions.tolerations[0] == '@' { + tolerationsString = loadTolerationsFromFile(installCmdOptions.tolerations[1:]) + } else { + tolerationsString = installCmdOptions.tolerations } - tolerations, err := parseToleration(string(data)) + + tolerations, err := parseTolerations(tolerationsString) if err != nil { dieOnError(err) } + s.KubernetesAPI.Tolerations = tolerations } - if installCmdOptions.dryRun { s.DryRun = installCmdOptions.dryRun @@ -224,7 +222,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().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`) 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") @@ -248,30 +246,39 @@ func parseNodeSelector(s string) (nodeSelector, error) { return nodeSelector{v[0]: v[1]}, nil } -func parseToleration(s string) (string, error) { +func loadTolerationsFromFile(filename string) string { + data, err := ioutil.ReadFile(filename) + if err != nil { + dieOnError(err) + } + + return string(data) +} + +func parseTolerations(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") + var data []k8sApi.Toleration + err := json.Unmarshal([]byte(s), &data) + if err != nil { + return "", fmt.Errorf("can not parse tolerations: %s", err) } y, err := yaml.Marshal(&data) - if (err != nil) { - return "", errors.New("can not marshel tolerations to yaml") + if err != nil { + return "", fmt.Errorf("can not marshel tolerations to yaml: %s", err) } d := fmt.Sprintf("\n%s", string(y)) return d, nil } -func validateInstallOptions(opts* plugins.InstallOptions) (error) { +func validateInstallOptions(opts *plugins.InstallOptions) error { if len(opts.ClusterName) > clusterNameMaxLength { return errors.New(fmt.Sprintf("cluster name length is limited to %d", clusterNameMaxLength)) } if len(opts.ClusterNamespace) > namespaceMaxLength { return errors.New(fmt.Sprintf("cluster namespace length is limited to %d", namespaceMaxLength)) - } + } return nil } diff --git a/venonactl/hack/build-linux.sh b/venonactl/hack/build-linux.sh index a9483246..a6e33207 100755 --- a/venonactl/hack/build-linux.sh +++ b/venonactl/hack/build-linux.sh @@ -2,6 +2,8 @@ set -e OUTFILE=$PWD/venonactl-linux go generate ${PWD}/hack/generate.go +go fmt ${PWD}/pkg/obj/kubeobj/kubeobj.go +go fmt ${PWD}/pkg/templates/kubernetes/templates.go GOOS=linux GOARCH=386 go build -ldflags '-X github.com/codefresh-io/venona/venonactl/cmd.localDevFlow=true' -o $OUTFILE main.go -chmod +x $OUTFILE \ No newline at end of file +chmod +x $OUTFILE diff --git a/venonactl/hack/build.sh b/venonactl/hack/build.sh index 293c8276..613c92da 100755 --- a/venonactl/hack/build.sh +++ b/venonactl/hack/build.sh @@ -2,6 +2,8 @@ set -e OUTFILE=/usr/local/bin/venonactl go generate ${PWD}/hack/generate.go +go fmt ${PWD}/pkg/obj/kubeobj/kubeobj.go +go fmt ${PWD}/pkg/templates/kubernetes/templates.go go build -ldflags '-X github.com/codefresh-io/venona/venonactl/cmd.localDevFlow=true' -o $OUTFILE main.go -chmod +x $OUTFILE \ No newline at end of file +chmod +x $OUTFILE diff --git a/venonactl/pkg/obj/kubeobj/kubeobj.go b/venonactl/pkg/obj/kubeobj/kubeobj.go index 82190e09..90aa37ed 100644 --- a/venonactl/pkg/obj/kubeobj/kubeobj.go +++ b/venonactl/pkg/obj/kubeobj/kubeobj.go @@ -1,4 +1,3 @@ - // Code generated by go generate; DO NOT EDIT. package kubeobj @@ -8,505 +7,504 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/api/core/v1" - v1beta1 "k8s.io/api/extensions/v1beta1" - appsv1 "k8s.io/api/apps/v1" + appsv1 "k8s.io/api/apps/v1" + "k8s.io/api/core/v1" + v1beta1 "k8s.io/api/extensions/v1beta1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - rbacv1beta1 "k8s.io/api/rbac/v1beta1" - rbacv1 "k8s.io/api/rbac/v1" + rbacv1 "k8s.io/api/rbac/v1" + rbacv1beta1 "k8s.io/api/rbac/v1beta1" storagev1 "k8s.io/api/storage/v1" ) // CreateObject - creates kubernetes object from *runtime.Object. Returns object name, kind and creation error -func CreateObject(clientset *kubernetes.Clientset, obj runtime.Object, namespace string) (string, string, error){ - +func CreateObject(clientset *kubernetes.Clientset, obj runtime.Object, namespace string) (string, string, error) { + var name, kind string var err error switch objT := obj.(type) { - - case *appsv1.DaemonSet: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.AppsV1().DaemonSets(namespace).Create(objT) - - case *appsv1.Deployment: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.AppsV1().Deployments(namespace).Create(objT) - - case *rbacv1.ClusterRole: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1().ClusterRoles().Create(objT) - - case *rbacv1.ClusterRoleBinding: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1().ClusterRoleBindings().Create(objT) - - case *rbacv1.Role: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1().Roles(namespace).Create(objT) - - case *rbacv1.RoleBinding: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1().RoleBindings(namespace).Create(objT) - - case *rbacv1beta1.ClusterRole: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1beta1().ClusterRoles().Create(objT) - - case *rbacv1beta1.ClusterRoleBinding: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1beta1().ClusterRoleBindings().Create(objT) - - case *rbacv1beta1.Role: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1beta1().Roles(namespace).Create(objT) - - case *rbacv1beta1.RoleBinding: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1beta1().RoleBindings(namespace).Create(objT) - - case *storagev1.StorageClass: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.StorageV1().StorageClasses().Create(objT) - - case *v1.ConfigMap: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().ConfigMaps(namespace).Create(objT) - - case *v1.PersistentVolume: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().PersistentVolumes().Create(objT) - - case *v1.PersistentVolumeClaim: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().PersistentVolumeClaims(namespace).Create(objT) - - case *v1.Pod: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().Pods(namespace).Create(objT) - - case *v1.Secret: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().Secrets(namespace).Create(objT) - - case *v1.Service: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().Services(namespace).Create(objT) - - case *v1.ServiceAccount: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().ServiceAccounts(namespace).Create(objT) - - case *v1beta1.DaemonSet: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.ExtensionsV1beta1().DaemonSets(namespace).Create(objT) - - case *v1beta1.Deployment: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.ExtensionsV1beta1().Deployments(namespace).Create(objT) - - default: - return "", "", fmt.Errorf("Unknown object type %T\n ", objT) - } - return name, kind, err + + case *appsv1.DaemonSet: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.AppsV1().DaemonSets(namespace).Create(objT) + + case *appsv1.Deployment: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.AppsV1().Deployments(namespace).Create(objT) + + case *rbacv1.ClusterRole: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1().ClusterRoles().Create(objT) + + case *rbacv1.ClusterRoleBinding: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1().ClusterRoleBindings().Create(objT) + + case *rbacv1.Role: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1().Roles(namespace).Create(objT) + + case *rbacv1.RoleBinding: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1().RoleBindings(namespace).Create(objT) + + case *rbacv1beta1.ClusterRole: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1beta1().ClusterRoles().Create(objT) + + case *rbacv1beta1.ClusterRoleBinding: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1beta1().ClusterRoleBindings().Create(objT) + + case *rbacv1beta1.Role: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1beta1().Roles(namespace).Create(objT) + + case *rbacv1beta1.RoleBinding: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1beta1().RoleBindings(namespace).Create(objT) + + case *storagev1.StorageClass: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.StorageV1().StorageClasses().Create(objT) + + case *v1.ConfigMap: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().ConfigMaps(namespace).Create(objT) + + case *v1.PersistentVolume: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().PersistentVolumes().Create(objT) + + case *v1.PersistentVolumeClaim: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().PersistentVolumeClaims(namespace).Create(objT) + + case *v1.Pod: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().Pods(namespace).Create(objT) + + case *v1.Secret: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().Secrets(namespace).Create(objT) + + case *v1.Service: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().Services(namespace).Create(objT) + + case *v1.ServiceAccount: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().ServiceAccounts(namespace).Create(objT) + + case *v1beta1.DaemonSet: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.ExtensionsV1beta1().DaemonSets(namespace).Create(objT) + + case *v1beta1.Deployment: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.ExtensionsV1beta1().Deployments(namespace).Create(objT) + + default: + return "", "", fmt.Errorf("Unknown object type %T\n ", objT) + } + return name, kind, err } // CheckObject - checks kubernetes object from *runtime.Object. Returns object name, kind and creation error -func CheckObject(clientset *kubernetes.Clientset, obj runtime.Object, namespace string) (string, string, error){ - +func CheckObject(clientset *kubernetes.Clientset, obj runtime.Object, namespace string) (string, string, error) { + var name, kind string var err error switch objT := obj.(type) { - - case *appsv1.DaemonSet: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.AppsV1().DaemonSets(namespace).Get(name, metav1.GetOptions{}) - - case *appsv1.Deployment: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.AppsV1().Deployments(namespace).Get(name, metav1.GetOptions{}) - - case *rbacv1.ClusterRole: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1().ClusterRoles().Get(name, metav1.GetOptions{}) - - case *rbacv1.ClusterRoleBinding: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1().ClusterRoleBindings().Get(name, metav1.GetOptions{}) - - case *rbacv1.Role: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1().Roles(namespace).Get(name, metav1.GetOptions{}) - - case *rbacv1.RoleBinding: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1().RoleBindings(namespace).Get(name, metav1.GetOptions{}) - - case *rbacv1beta1.ClusterRole: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1beta1().ClusterRoles().Get(name, metav1.GetOptions{}) - - case *rbacv1beta1.ClusterRoleBinding: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1beta1().ClusterRoleBindings().Get(name, metav1.GetOptions{}) - - case *rbacv1beta1.Role: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1beta1().Roles(namespace).Get(name, metav1.GetOptions{}) - - case *rbacv1beta1.RoleBinding: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1beta1().RoleBindings(namespace).Get(name, metav1.GetOptions{}) - - case *storagev1.StorageClass: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.StorageV1().StorageClasses().Get(name, metav1.GetOptions{}) - - case *v1.ConfigMap: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().ConfigMaps(namespace).Get(name, metav1.GetOptions{}) - - case *v1.PersistentVolume: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().PersistentVolumes().Get(name, metav1.GetOptions{}) - - case *v1.PersistentVolumeClaim: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().PersistentVolumeClaims(namespace).Get(name, metav1.GetOptions{}) - - case *v1.Pod: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().Pods(namespace).Get(name, metav1.GetOptions{}) - - case *v1.Secret: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().Secrets(namespace).Get(name, metav1.GetOptions{}) - - case *v1.Service: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().Services(namespace).Get(name, metav1.GetOptions{}) - - case *v1.ServiceAccount: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().ServiceAccounts(namespace).Get(name, metav1.GetOptions{}) - - case *v1beta1.DaemonSet: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.ExtensionsV1beta1().DaemonSets(namespace).Get(name, metav1.GetOptions{}) - - case *v1beta1.Deployment: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.ExtensionsV1beta1().Deployments(namespace).Get(name, metav1.GetOptions{}) - - default: - return "", "", fmt.Errorf("Unknown object type %T\n ", objT) - } - return name, kind, err + + case *appsv1.DaemonSet: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.AppsV1().DaemonSets(namespace).Get(name, metav1.GetOptions{}) + + case *appsv1.Deployment: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.AppsV1().Deployments(namespace).Get(name, metav1.GetOptions{}) + + case *rbacv1.ClusterRole: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1().ClusterRoles().Get(name, metav1.GetOptions{}) + + case *rbacv1.ClusterRoleBinding: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1().ClusterRoleBindings().Get(name, metav1.GetOptions{}) + + case *rbacv1.Role: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1().Roles(namespace).Get(name, metav1.GetOptions{}) + + case *rbacv1.RoleBinding: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1().RoleBindings(namespace).Get(name, metav1.GetOptions{}) + + case *rbacv1beta1.ClusterRole: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1beta1().ClusterRoles().Get(name, metav1.GetOptions{}) + + case *rbacv1beta1.ClusterRoleBinding: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1beta1().ClusterRoleBindings().Get(name, metav1.GetOptions{}) + + case *rbacv1beta1.Role: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1beta1().Roles(namespace).Get(name, metav1.GetOptions{}) + + case *rbacv1beta1.RoleBinding: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1beta1().RoleBindings(namespace).Get(name, metav1.GetOptions{}) + + case *storagev1.StorageClass: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.StorageV1().StorageClasses().Get(name, metav1.GetOptions{}) + + case *v1.ConfigMap: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().ConfigMaps(namespace).Get(name, metav1.GetOptions{}) + + case *v1.PersistentVolume: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().PersistentVolumes().Get(name, metav1.GetOptions{}) + + case *v1.PersistentVolumeClaim: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().PersistentVolumeClaims(namespace).Get(name, metav1.GetOptions{}) + + case *v1.Pod: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().Pods(namespace).Get(name, metav1.GetOptions{}) + + case *v1.Secret: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().Secrets(namespace).Get(name, metav1.GetOptions{}) + + case *v1.Service: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().Services(namespace).Get(name, metav1.GetOptions{}) + + case *v1.ServiceAccount: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().ServiceAccounts(namespace).Get(name, metav1.GetOptions{}) + + case *v1beta1.DaemonSet: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.ExtensionsV1beta1().DaemonSets(namespace).Get(name, metav1.GetOptions{}) + + case *v1beta1.Deployment: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.ExtensionsV1beta1().Deployments(namespace).Get(name, metav1.GetOptions{}) + + default: + return "", "", fmt.Errorf("Unknown object type %T\n ", objT) + } + return name, kind, err } // DeleteObject - checks kubernetes object from *runtime.Object. Returns object name, kind and creation error -func DeleteObject(clientset *kubernetes.Clientset, obj runtime.Object, namespace string) (string, string, error){ +func DeleteObject(clientset *kubernetes.Clientset, obj runtime.Object, namespace string) (string, string, error) { var propagationPolicy metav1.DeletionPropagation = "Background" var name, kind string var err error switch objT := obj.(type) { - - case *appsv1.DaemonSet: - name = objT.ObjectMeta.Name + + case *appsv1.DaemonSet: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.AppsV1().DaemonSets(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.AppsV1().DaemonSets(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *appsv1.Deployment: - name = objT.ObjectMeta.Name + + case *appsv1.Deployment: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.AppsV1().Deployments(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.AppsV1().Deployments(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *rbacv1.ClusterRole: - name = objT.ObjectMeta.Name + + case *rbacv1.ClusterRole: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.RbacV1().ClusterRoles().Delete(name, &metav1.DeleteOptions{ + err = clientset.RbacV1().ClusterRoles().Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *rbacv1.ClusterRoleBinding: - name = objT.ObjectMeta.Name + + case *rbacv1.ClusterRoleBinding: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.RbacV1().ClusterRoleBindings().Delete(name, &metav1.DeleteOptions{ + err = clientset.RbacV1().ClusterRoleBindings().Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *rbacv1.Role: - name = objT.ObjectMeta.Name + + case *rbacv1.Role: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.RbacV1().Roles(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.RbacV1().Roles(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *rbacv1.RoleBinding: - name = objT.ObjectMeta.Name + + case *rbacv1.RoleBinding: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.RbacV1().RoleBindings(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.RbacV1().RoleBindings(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *rbacv1beta1.ClusterRole: - name = objT.ObjectMeta.Name + + case *rbacv1beta1.ClusterRole: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.RbacV1beta1().ClusterRoles().Delete(name, &metav1.DeleteOptions{ + err = clientset.RbacV1beta1().ClusterRoles().Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *rbacv1beta1.ClusterRoleBinding: - name = objT.ObjectMeta.Name + + case *rbacv1beta1.ClusterRoleBinding: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.RbacV1beta1().ClusterRoleBindings().Delete(name, &metav1.DeleteOptions{ + err = clientset.RbacV1beta1().ClusterRoleBindings().Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *rbacv1beta1.Role: - name = objT.ObjectMeta.Name + + case *rbacv1beta1.Role: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.RbacV1beta1().Roles(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.RbacV1beta1().Roles(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *rbacv1beta1.RoleBinding: - name = objT.ObjectMeta.Name + + case *rbacv1beta1.RoleBinding: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.RbacV1beta1().RoleBindings(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.RbacV1beta1().RoleBindings(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *storagev1.StorageClass: - name = objT.ObjectMeta.Name + + case *storagev1.StorageClass: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.StorageV1().StorageClasses().Delete(name, &metav1.DeleteOptions{ + err = clientset.StorageV1().StorageClasses().Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *v1.ConfigMap: - name = objT.ObjectMeta.Name + + case *v1.ConfigMap: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.CoreV1().ConfigMaps(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.CoreV1().ConfigMaps(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *v1.PersistentVolume: - name = objT.ObjectMeta.Name + + case *v1.PersistentVolume: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.CoreV1().PersistentVolumes().Delete(name, &metav1.DeleteOptions{ + err = clientset.CoreV1().PersistentVolumes().Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *v1.PersistentVolumeClaim: - name = objT.ObjectMeta.Name + + case *v1.PersistentVolumeClaim: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.CoreV1().PersistentVolumeClaims(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.CoreV1().PersistentVolumeClaims(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *v1.Pod: - name = objT.ObjectMeta.Name + + case *v1.Pod: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.CoreV1().Pods(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.CoreV1().Pods(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *v1.Secret: - name = objT.ObjectMeta.Name + + case *v1.Secret: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.CoreV1().Secrets(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.CoreV1().Secrets(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *v1.Service: - name = objT.ObjectMeta.Name + + case *v1.Service: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.CoreV1().Services(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.CoreV1().Services(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *v1.ServiceAccount: - name = objT.ObjectMeta.Name + + case *v1.ServiceAccount: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.CoreV1().ServiceAccounts(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.CoreV1().ServiceAccounts(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *v1beta1.DaemonSet: - name = objT.ObjectMeta.Name + + case *v1beta1.DaemonSet: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.ExtensionsV1beta1().DaemonSets(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.ExtensionsV1beta1().DaemonSets(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - case *v1beta1.Deployment: - name = objT.ObjectMeta.Name + + case *v1beta1.Deployment: + name = objT.ObjectMeta.Name kind = objT.TypeMeta.Kind - err = clientset.ExtensionsV1beta1().Deployments(namespace).Delete(name, &metav1.DeleteOptions{ + err = clientset.ExtensionsV1beta1().Deployments(namespace).Delete(name, &metav1.DeleteOptions{ PropagationPolicy: &propagationPolicy, }) - - default: - return "", "", fmt.Errorf("Unknown object type %T\n ", objT) - } - return name, kind, err + + default: + return "", "", fmt.Errorf("Unknown object type %T\n ", objT) + } + return name, kind, err } // ReplaceObject - replaces kubernetes object from *runtime.Object. Returns object name, kind and creation error -func ReplaceObject(clientset *kubernetes.Clientset, obj runtime.Object, namespace string) (string, string, error){ +func ReplaceObject(clientset *kubernetes.Clientset, obj runtime.Object, namespace string) (string, string, error) { var name, kind string var err error switch objT := obj.(type) { - - case *appsv1.DaemonSet: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.AppsV1().DaemonSets(namespace).Update(objT) - - case *appsv1.Deployment: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.AppsV1().Deployments(namespace).Update(objT) - - case *rbacv1.ClusterRole: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1().ClusterRoles().Update(objT) - - case *rbacv1.ClusterRoleBinding: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1().ClusterRoleBindings().Update(objT) - - case *rbacv1.Role: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1().Roles(namespace).Update(objT) - - case *rbacv1.RoleBinding: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1().RoleBindings(namespace).Update(objT) - - case *rbacv1beta1.ClusterRole: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1beta1().ClusterRoles().Update(objT) - - case *rbacv1beta1.ClusterRoleBinding: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1beta1().ClusterRoleBindings().Update(objT) - - case *rbacv1beta1.Role: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1beta1().Roles(namespace).Update(objT) - - case *rbacv1beta1.RoleBinding: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.RbacV1beta1().RoleBindings(namespace).Update(objT) - - case *storagev1.StorageClass: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.StorageV1().StorageClasses().Update(objT) - - case *v1.ConfigMap: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().ConfigMaps(namespace).Update(objT) - - case *v1.PersistentVolume: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().PersistentVolumes().Update(objT) - - case *v1.PersistentVolumeClaim: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().PersistentVolumeClaims(namespace).Update(objT) - - case *v1.Pod: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().Pods(namespace).Update(objT) - - case *v1.Secret: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().Secrets(namespace).Update(objT) - - case *v1.Service: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().Services(namespace).Update(objT) - - case *v1.ServiceAccount: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.CoreV1().ServiceAccounts(namespace).Update(objT) - - case *v1beta1.DaemonSet: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.ExtensionsV1beta1().DaemonSets(namespace).Update(objT) - - case *v1beta1.Deployment: - name = objT.ObjectMeta.Name - kind = objT.TypeMeta.Kind - _, err = clientset.ExtensionsV1beta1().Deployments(namespace).Update(objT) - - default: - return "", "", fmt.Errorf("Unknown object type %T\n ", objT) - } - return name, kind, err -} + case *appsv1.DaemonSet: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.AppsV1().DaemonSets(namespace).Update(objT) + + case *appsv1.Deployment: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.AppsV1().Deployments(namespace).Update(objT) + + case *rbacv1.ClusterRole: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1().ClusterRoles().Update(objT) + + case *rbacv1.ClusterRoleBinding: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1().ClusterRoleBindings().Update(objT) + + case *rbacv1.Role: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1().Roles(namespace).Update(objT) + + case *rbacv1.RoleBinding: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1().RoleBindings(namespace).Update(objT) + + case *rbacv1beta1.ClusterRole: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1beta1().ClusterRoles().Update(objT) + + case *rbacv1beta1.ClusterRoleBinding: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1beta1().ClusterRoleBindings().Update(objT) + + case *rbacv1beta1.Role: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1beta1().Roles(namespace).Update(objT) + + case *rbacv1beta1.RoleBinding: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.RbacV1beta1().RoleBindings(namespace).Update(objT) + + case *storagev1.StorageClass: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.StorageV1().StorageClasses().Update(objT) + + case *v1.ConfigMap: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().ConfigMaps(namespace).Update(objT) + + case *v1.PersistentVolume: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().PersistentVolumes().Update(objT) + + case *v1.PersistentVolumeClaim: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().PersistentVolumeClaims(namespace).Update(objT) + + case *v1.Pod: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().Pods(namespace).Update(objT) + + case *v1.Secret: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().Secrets(namespace).Update(objT) + + case *v1.Service: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().Services(namespace).Update(objT) + + case *v1.ServiceAccount: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.CoreV1().ServiceAccounts(namespace).Update(objT) + + case *v1beta1.DaemonSet: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.ExtensionsV1beta1().DaemonSets(namespace).Update(objT) + + case *v1beta1.Deployment: + name = objT.ObjectMeta.Name + kind = objT.TypeMeta.Kind + _, err = clientset.ExtensionsV1beta1().Deployments(namespace).Update(objT) + + default: + return "", "", fmt.Errorf("Unknown object type %T\n ", objT) + } + return name, kind, err +} diff --git a/venonactl/pkg/plugins/helper.go b/venonactl/pkg/plugins/helper.go index 164fa5bc..0b3d92b1 100644 --- a/venonactl/pkg/plugins/helper.go +++ b/venonactl/pkg/plugins/helper.go @@ -19,20 +19,18 @@ package plugins import ( "bytes" "fmt" - "regexp" "html/template" + "regexp" // import all cloud providers auth clients _ "k8s.io/client-go/plugin/pkg/client/auth" + "github.com/Masterminds/sprig" "github.com/codefresh-io/venona/venonactl/pkg/logger" templates "github.com/codefresh-io/venona/venonactl/pkg/templates/kubernetes" - "github.com/Masterminds/sprig" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes/scheme" - - ) // ExecuteTemplate - executes templates in tpl str with config as values diff --git a/venonactl/pkg/plugins/venona.go b/venonactl/pkg/plugins/venona.go index 3fc1a747..273c57e1 100644 --- a/venonactl/pkg/plugins/venona.go +++ b/venonactl/pkg/plugins/venona.go @@ -120,7 +120,7 @@ func (u *venonaPlugin) Upgrade(opt *UpgradeOptions, v Values) (Values, error) { // avoid it till patch fully implemented var skipUpgradeFor = map[string]interface{}{ "service-account.venona.yaml": nil, - "deployment.venona.yaml": nil, + "deployment.venona.yaml": nil, } var deletePriorUpgrade = map[string]interface{}{ @@ -182,7 +182,7 @@ func (u *venonaPlugin) Upgrade(opt *UpgradeOptions, v Values) (Values, error) { return nil, err } } - + if _, ok := skipUpgradeFor[fileName]; ok { u.logger.Debug(fmt.Sprintf("Skipping upgrade of %s: should be ignored", fileName)) continue diff --git a/venonactl/pkg/store/store.go b/venonactl/pkg/store/store.go index fa751cc1..f29ffa36 100644 --- a/venonactl/pkg/store/store.go +++ b/venonactl/pkg/store/store.go @@ -100,7 +100,7 @@ func (s *Values) BuildValues() map[string]interface{} { }, "Namespace": s.KubernetesAPI.Namespace, "NodeSelector": s.KubernetesAPI.NodeSelector, - "Tolerations": s.KubernetesAPI.Tolerations, + "Tolerations": s.KubernetesAPI.Tolerations, "AgentToken": "", "ServerCert": map[string]string{ "Cert": "", diff --git a/venonactl/pkg/templates/kubernetes/daemonset.dind-lv-monitor.vp.yaml b/venonactl/pkg/templates/kubernetes/daemonset.dind-lv-monitor.vp.yaml index dde16c92..3fa8b42f 100644 --- a/venonactl/pkg/templates/kubernetes/daemonset.dind-lv-monitor.vp.yaml +++ b/venonactl/pkg/templates/kubernetes/daemonset.dind-lv-monitor.vp.yaml @@ -30,6 +30,9 @@ spec: - key: 'codefresh/dind' operator: 'Exists' effect: 'NoSchedule' + {{ if ne .Tolerations "" }} + {{ .Tolerations | indent 8 }} + {{ end }} containers: - image: codefresh/dind-volume-utils:v5 name: lv-cleaner diff --git a/venonactl/pkg/templates/kubernetes/deployment.dind-volume-provisioner.vp.yaml b/venonactl/pkg/templates/kubernetes/deployment.dind-volume-provisioner.vp.yaml index a249845e..06492da6 100644 --- a/venonactl/pkg/templates/kubernetes/deployment.dind-volume-provisioner.vp.yaml +++ b/venonactl/pkg/templates/kubernetes/deployment.dind-volume-provisioner.vp.yaml @@ -26,6 +26,9 @@ spec: - effect: NoSchedule key: node-role.kubernetes.io/master operator: "Exists" + {{ if ne .Tolerations "" }} + {{ .Tolerations | indent 8 }} + {{ end }} containers: - name: dind-volume-provisioner image: {{ .VolumeProvisionerImage.Name }}:{{ .VolumeProvisionerImage.Tag }} diff --git a/venonactl/pkg/templates/kubernetes/templates.go b/venonactl/pkg/templates/kubernetes/templates.go index 7c7271bd..80f33a42 100644 --- a/venonactl/pkg/templates/kubernetes/templates.go +++ b/venonactl/pkg/templates/kubernetes/templates.go @@ -1,12 +1,11 @@ - // Code generated by go generate; DO NOT EDIT. // using data from templates/kubernetes package kubernetes func TemplatesMap() map[string]string { - templatesMap := make(map[string]string) + templatesMap := make(map[string]string) -templatesMap["cluster-role-binding.dind-volume-provisioner.vp.yaml"] = `--- + templatesMap["cluster-role-binding.dind-volume-provisioner.vp.yaml"] = `--- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: @@ -21,9 +20,9 @@ roleRef: kind: ClusterRole name: volume-provisioner-{{ .AppName }}-{{ .Namespace }} apiGroup: rbac.authorization.k8s.io -` +` -templatesMap["cluster-role-binding.engine.yaml"] = `kind: ClusterRoleBinding + templatesMap["cluster-role-binding.engine.yaml"] = `kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: {{ .AppName }}-{{ .Namespace }}-engine @@ -34,9 +33,9 @@ subjects: roleRef: kind: ClusterRole name: cluster-admin - apiGroup: rbac.authorization.k8s.io` + apiGroup: rbac.authorization.k8s.io` -templatesMap["cluster-role-binding.venona.yaml"] = `kind: ClusterRoleBinding + templatesMap["cluster-role-binding.venona.yaml"] = `kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: {{ .AppName }}-{{ .Namespace }} @@ -47,9 +46,9 @@ subjects: roleRef: kind: ClusterRole name: system:discovery - apiGroup: rbac.authorization.k8s.io` + apiGroup: rbac.authorization.k8s.io` -templatesMap["cluster-role.dind-volume-provisioner.vp.yaml"] = `kind: ClusterRole + templatesMap["cluster-role.dind-volume-provisioner.vp.yaml"] = `kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: volume-provisioner-{{ .AppName }}-{{ .Namespace }} @@ -80,9 +79,9 @@ rules: - apiGroups: [""] resources: ["endpoints"] verbs: ["get", "list", "watch", "create", "update", "delete"] -` +` -templatesMap["cluster-role.engine.yaml"] = `kind: ClusterRole + templatesMap["cluster-role.engine.yaml"] = `kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: {{ .AppName }}-{{ .Namespace }}-engine @@ -90,9 +89,9 @@ rules: - apiGroups: [""] resources: ["pods", "persistentvolumeclaims"] verbs: ["get", "create", "delete", "list"] -` +` -templatesMap["codefresh-certs-server-secret.re.yaml"] = `apiVersion: v1 + templatesMap["codefresh-certs-server-secret.re.yaml"] = `apiVersion: v1 type: Opaque kind: Secret metadata: @@ -105,9 +104,9 @@ data: server-key.pem: {{ .ServerCert.Key }} ca.pem: {{ .ServerCert.Ca }} -` +` -templatesMap["daemonset.dind-lv-monitor.vp.yaml"] = `apiVersion: apps/v1 + templatesMap["daemonset.dind-lv-monitor.vp.yaml"] = `apiVersion: apps/v1 kind: DaemonSet metadata: name: dind-lv-monitor-{{ .AppName }} @@ -139,6 +138,9 @@ spec: - key: 'codefresh/dind' operator: 'Exists' effect: 'NoSchedule' + {{ if ne .Tolerations "" }} + {{ .Tolerations | indent 8 }} + {{ end }} containers: - image: codefresh/dind-volume-utils:v5 name: lv-cleaner @@ -172,9 +174,9 @@ spec: - name: dind-volume-dir hostPath: path: /var/lib/codefresh/dind-volumes -` +` -templatesMap["deployment.dind-volume-provisioner.vp.yaml"] = `apiVersion: apps/v1 + templatesMap["deployment.dind-volume-provisioner.vp.yaml"] = `apiVersion: apps/v1 kind: Deployment metadata: name: dind-volume-provisioner-{{ .AppName }} @@ -202,6 +204,9 @@ spec: - effect: NoSchedule key: node-role.kubernetes.io/master operator: "Exists" + {{ if ne .Tolerations "" }} + {{ .Tolerations | indent 8 }} + {{ end }} containers: - name: dind-volume-provisioner image: {{ .VolumeProvisionerImage.Name }}:{{ .VolumeProvisionerImage.Tag }} @@ -220,9 +225,9 @@ spec: env: - name: PROVISIONER_NAME value: codefresh.io/dind-volume-provisioner-{{ .AppName }}-{{ .Namespace }} -` +` -templatesMap["deployment.venona.yaml"] = `apiVersion: apps/v1 + templatesMap["deployment.venona.yaml"] = `apiVersion: apps/v1 kind: Deployment metadata: labels: @@ -278,9 +283,9 @@ spec: imagePullPolicy: Always name: {{ .AppName }} restartPolicy: Always -` +` -templatesMap["dind-daemon-conf.re.yaml"] = `--- + templatesMap["dind-daemon-conf.re.yaml"] = `--- apiVersion: v1 kind: ConfigMap metadata: @@ -301,9 +306,9 @@ data: "metrics-addr" : "0.0.0.0:9323", "experimental" : true } -` +` -templatesMap["dind-headless-service.re.yaml"] = `--- + templatesMap["dind-headless-service.re.yaml"] = `--- apiVersion: v1 kind: Service metadata: @@ -323,9 +328,9 @@ spec: selector: app: dind -` +` -templatesMap["role-binding.venona.yaml"] = `kind: RoleBinding + templatesMap["role-binding.venona.yaml"] = `kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: {{ .AppName }} @@ -336,9 +341,9 @@ subjects: roleRef: kind: Role name: {{ .AppName }} - apiGroup: rbac.authorization.k8s.io` + apiGroup: rbac.authorization.k8s.io` -templatesMap["role.venona.yaml"] = `kind: Role + templatesMap["role.venona.yaml"] = `kind: Role apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: {{ .AppName }} @@ -347,18 +352,18 @@ rules: - apiGroups: [""] resources: ["pods", "persistentvolumeclaims"] verbs: ["get", "create", "delete"] -` +` -templatesMap["secret.venona.yaml"] = `apiVersion: v1 + templatesMap["secret.venona.yaml"] = `apiVersion: v1 kind: Secret type: Opaque metadata: name: {{ .AppName }} namespace: {{ .Namespace }} data: - codefresh.token: {{ .AgentToken }}` + codefresh.token: {{ .AgentToken }}` -templatesMap["service-account.dind-volume-provisioner.vp.yaml"] = `--- + templatesMap["service-account.dind-volume-provisioner.vp.yaml"] = `--- apiVersion: v1 kind: ServiceAccount metadata: @@ -366,21 +371,21 @@ metadata: namespace: {{ .Namespace }} labels: app: dind-volume-provisioner -` +` -templatesMap["service-account.engine.yaml"] = `apiVersion: v1 + templatesMap["service-account.engine.yaml"] = `apiVersion: v1 kind: ServiceAccount metadata: name: engine - namespace: {{ .Namespace }}` + namespace: {{ .Namespace }}` -templatesMap["service-account.venona.yaml"] = `apiVersion: v1 + templatesMap["service-account.venona.yaml"] = `apiVersion: v1 kind: ServiceAccount metadata: name: {{ .AppName }} - namespace: {{ .Namespace }}` + namespace: {{ .Namespace }}` -templatesMap["storageclass.dind-local-volume-provisioner.vp.yaml"] = `--- + templatesMap["storageclass.dind-local-volume-provisioner.vp.yaml"] = `--- kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: @@ -390,7 +395,7 @@ metadata: provisioner: codefresh.io/dind-volume-provisioner-{{ .AppName }}-{{ .Namespace }} parameters: volumeBackend: local -` +` - return templatesMap + return templatesMap }