From 9f55dc982c6e8c63a9dda362d4d8eb00919dcf4a Mon Sep 17 00:00:00 2001 From: yodigos Date: Wed, 26 Jun 2024 09:54:37 +0300 Subject: [PATCH 1/6] Added an option to do odigos version --cli/--cluster to print only the version. Removed the need of adding the TAG in the building commands. Added an option not to use TAG in the locally deploy --- CONTRIBUTING.md | 24 +++++++++++++++++------- Makefile | 7 +++++++ cli/cmd/version.go | 45 +++++++++++++++++++++++++++++---------------- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 884c1ff29..d233d08cb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -80,16 +80,16 @@ After you have a working odigos setup, you can start making changes to the code ### Run Odigos Cli from code The code for the odigos cli tool is found in the `cli` directory [here](https://github.com/odigos-io/odigos/tree/main/cli). -Test your cli code changes by running `go run -tags=embed_manifests .` from the `cli` directory: +Test your cli code running the following: ```bash -go run cli/main.go +go run -tags=embed_manifests ./cli ``` To run `odigos install` cli command from a local source, you will need to supply a version flag to tell odigos which image tags to install: ```bash -go run cli/main.go install --version v0.1.81 +go run -tags=embed_manifests ./cli install --version v0.1.81 # Installing Odigos version v0.1.81 in namespace odigos-system ... ``` @@ -100,19 +100,29 @@ If you test changes to the `install` command, you will need to `go run cli/main. The main steps involved when debugging Odigos locally are: - Use a Kind kubernetes cluster +- 2 Options: +1. Update all pods in the odigos-system namespace: - Build custom images of Odigos and load them into Kind via: - ```bash -TAG= make build-images load-to-kind +make build-images load-to-kind ``` -- Ensure the TAG matches the Odigos version output from: `odigos version` - Restart all pods in the `odigos-system` namespace: ```bash kubectl delete pods --all -n odigos-system ``` +2.Update a specific service: +- For your convinience we created for each service a speceific script that rebuilds + load to kind + restart the pod. +- So you just need to run one of the following commands according to your service and then you can test your changes: +```bash +make deploy-odiglet +make deploy-autoscaler +make deploy-collector +make deploy-instrumentor +``` + See the [Odigos docs](https://docs.odigos.io/intro) for the full steps on debugging Odigos locally. ### How to Build and run Odigos Frontend Locally @@ -149,7 +159,7 @@ First, you will have to find which version of Odigos you are running. You can do Then, run the following command to build Odiglet in debug mode and restart the Odiglet pod: ```bash -TAG= make debug-odiglet +make debug-odiglet ``` Then, you can attach a debugger to the Odiglet pod. For example, if you are using Goland, you can follow the instructions [here](https://www.jetbrains.com/help/go/attach-to-running-go-processes-with-debugger.html#step-3-create-the-remote-run-debug-configuration-on-the-client-computer) to attach to a remote process. diff --git a/Makefile b/Makefile index e164b3262..dc0351842 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,12 @@ +NAMESPACE := odigos-system +CONFIGMAP_NAME := odigos-deployment + TAG ?= $(shell odigos version --short) ORG := keyval + +# Cluster Version +TAG := $(shell kubectl get configmap $(CONFIGMAP_NAME) -n $(NAMESPACE) -o jsonpath='{.data.ODIGOS_VERSION}') + .PHONY: build-odiglet build-odiglet: docker build -t $(ORG)/odigos-odiglet:$(TAG) . -f odiglet/Dockerfile diff --git a/cli/cmd/version.go b/cli/cmd/version.go index f6550453a..b35985dd4 100644 --- a/cli/cmd/version.go +++ b/cli/cmd/version.go @@ -13,10 +13,16 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +const ( + cliFlag = "cli" + clusterFlag = "cluster" +) + var ( - OdigosVersion string - OdigosCommit string - OdigosDate string + OdigosVersion string + OdigosClusterVersion string + OdigosCommit string + OdigosDate string ) // versionCmd represents the version command @@ -24,15 +30,27 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Print odigos version.", Run: func(cmd *cobra.Command, args []string) { - short_flag, _ := cmd.Flags().GetBool("short") + short_flag, _ := cmd.Flags().GetBool(cliFlag) if short_flag { fmt.Printf("%s\n", OdigosVersion) return } + client, ns, err := getOdigosKubeClientAndNamespace(cmd) + if err == nil { + OdigosClusterVersion, _ = GetOdigosVersionInCluster(cmd.Context(), client, ns) + } + + cluster_flag, _ := cmd.Flags().GetBool(clusterFlag) + + if cluster_flag { + fmt.Printf("%s\n", OdigosClusterVersion) + return + } + fmt.Printf("Odigos Cli Version: version.Info{Version:'%s', GitCommit:'%s', BuildDate:'%s'}\n", OdigosVersion, OdigosCommit, OdigosDate) - printOdigosClusterVersion(cmd) + fmt.Printf("Odigos Version (in cluster): version.Info{Version:'%s'}\n", OdigosClusterVersion) }, } @@ -50,10 +68,10 @@ func GetOdigosVersionInCluster(ctx context.Context, client *kube.Client, ns stri return odigosVersion, nil } -func printOdigosClusterVersion(cmd *cobra.Command) { +func getOdigosKubeClientAndNamespace(cmd *cobra.Command) (*kube.Client, string, error) { client, err := kube.CreateClient(cmd) if err != nil { - return + return nil, "", err } ctx := cmd.Context() @@ -64,20 +82,15 @@ func printOdigosClusterVersion(cmd *cobra.Command) { } else { fmt.Println("Error detecting Odigos version in the current cluster") } - return - } - - clusterVersion, err := GetOdigosVersionInCluster(ctx, client, ns) - if err != nil { - fmt.Println("Error detecting Odigos version in the current cluster") - return + return nil, "", err } - fmt.Printf("Odigos Version (in cluster): version.Info{Version:'%s'}\n", clusterVersion) + return client, ns, nil } func init() { rootCmd.AddCommand(versionCmd) - versionCmd.Flags().Bool("short", false, "prints only the CLI version") + versionCmd.Flags().Bool(cliFlag, false, "prints only the CLI version") + versionCmd.Flags().Bool(clusterFlag, false, "prints only the Cluster version") } From e94cfe421c57117f9fe717cbfb852317e26ed7ac Mon Sep 17 00:00:00 2001 From: yodigos Date: Wed, 26 Jun 2024 15:04:01 +0300 Subject: [PATCH 2/6] Fixed a few small syntax bugs --- CONTRIBUTING.md | 28 +++++++++------------------- Makefile | 6 +++++- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d233d08cb..246d438bc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -98,29 +98,19 @@ If you test changes to the `install` command, you will need to `go run cli/main. ### How to Develop Odigos Locally The main steps involved when debugging Odigos locally are: - -- Use a Kind kubernetes cluster -- 2 Options: -1. Update all pods in the odigos-system namespace: -- Build custom images of Odigos and load them into Kind via: -```bash -make build-images load-to-kind -``` - -- Restart all pods in the `odigos-system` namespace: - +1. Use a Kind kubernetes cluster. +2. Choose one of the following options for deploy: +- Deploy all pods in the odigos-system namespace: ```bash -kubectl delete pods --all -n odigos-system + make deploy ``` -2.Update a specific service: -- For your convinience we created for each service a speceific script that rebuilds + load to kind + restart the pod. -- So you just need to run one of the following commands according to your service and then you can test your changes: +- Deploy a specific service by running one of the following commands: ```bash -make deploy-odiglet -make deploy-autoscaler -make deploy-collector -make deploy-instrumentor + make deploy-odiglet + make deploy-autoscaler + make deploy-collector + make deploy-instrumentor ``` See the [Odigos docs](https://docs.odigos.io/intro) for the full steps on debugging Odigos locally. diff --git a/Makefile b/Makefile index dc0351842..da1b5d56c 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ TAG ?= $(shell odigos version --short) ORG := keyval # Cluster Version -TAG := $(shell kubectl get configmap $(CONFIGMAP_NAME) -n $(NAMESPACE) -o jsonpath='{.data.ODIGOS_VERSION}') +TAG ?= $(shell kubectl get configmap $(CONFIGMAP_NAME) -n $(NAMESPACE) -o jsonpath='{.data.ODIGOS_VERSION}') .PHONY: build-odiglet build-odiglet: @@ -147,6 +147,10 @@ debug-odiglet: kubectl wait --for=condition=ready pod -n odigos-system -l app.kubernetes.io/name=odiglet --timeout=180s kubectl port-forward -n odigos-system daemonset/odiglet 2345:2345 +.PHONY: deploy +deploy: + make deploy-odiglet && make deploy-autoscaler && make deploy-collector && make deploy-instrumentor + ,PHONY: e2e-test e2e-test: ./e2e-test.sh From 58a888be25e93022fd7ac6ef50fddd5b12754be2 Mon Sep 17 00:00:00 2001 From: yodigos Date: Wed, 26 Jun 2024 15:27:17 +0300 Subject: [PATCH 3/6] Fixed a few small syntax bugs --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index da1b5d56c..2b0a81e1e 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ NAMESPACE := odigos-system CONFIGMAP_NAME := odigos-deployment -TAG ?= $(shell odigos version --short) +TAG ?= $(shell odigos version --cluster) ORG := keyval # Cluster Version -TAG ?= $(shell kubectl get configmap $(CONFIGMAP_NAME) -n $(NAMESPACE) -o jsonpath='{.data.ODIGOS_VERSION}') +#TAG ?= $(shell kubectl get configmap $(CONFIGMAP_NAME) -n $(NAMESPACE) -o jsonpath='{.data.ODIGOS_VERSION}') .PHONY: build-odiglet build-odiglet: From 67386a8797c082676d6738c7d4ca627bc852eb82 Mon Sep 17 00:00:00 2001 From: yodigos Date: Thu, 27 Jun 2024 09:07:36 +0300 Subject: [PATCH 4/6] Fixed a few small syntax bugs --- Makefile | 6 ------ cli/cmd/version.go | 46 +++++++++++++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 2b0a81e1e..7165c0241 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,6 @@ -NAMESPACE := odigos-system -CONFIGMAP_NAME := odigos-deployment - TAG ?= $(shell odigos version --cluster) ORG := keyval -# Cluster Version -#TAG ?= $(shell kubectl get configmap $(CONFIGMAP_NAME) -n $(NAMESPACE) -o jsonpath='{.data.ODIGOS_VERSION}') - .PHONY: build-odiglet build-odiglet: docker build -t $(ORG)/odigos-odiglet:$(TAG) . -f odiglet/Dockerfile diff --git a/cli/cmd/version.go b/cli/cmd/version.go index b35985dd4..b518ccd7e 100644 --- a/cli/cmd/version.go +++ b/cli/cmd/version.go @@ -30,31 +30,48 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Print odigos version.", Run: func(cmd *cobra.Command, args []string) { - short_flag, _ := cmd.Flags().GetBool(cliFlag) + cliFlag, _ := cmd.Flags().GetBool(cliFlag) + clusterFlag, _ := cmd.Flags().GetBool(clusterFlag) - if short_flag { + if cliFlag { fmt.Printf("%s\n", OdigosVersion) - return - } - - client, ns, err := getOdigosKubeClientAndNamespace(cmd) - if err == nil { - OdigosClusterVersion, _ = GetOdigosVersionInCluster(cmd.Context(), client, ns) } - cluster_flag, _ := cmd.Flags().GetBool(clusterFlag) + OdigosClusterVersion, err := getOdigosVersionInCluster(cmd, clusterFlag) - if cluster_flag { + if clusterFlag && err == nil { fmt.Printf("%s\n", OdigosClusterVersion) + } + + if cliFlag || clusterFlag { return } + if err != nil { + fmt.Printf("%s\n", err) + } + fmt.Printf("Odigos Cli Version: version.Info{Version:'%s', GitCommit:'%s', BuildDate:'%s'}\n", OdigosVersion, OdigosCommit, OdigosDate) fmt.Printf("Odigos Version (in cluster): version.Info{Version:'%s'}\n", OdigosClusterVersion) + }, } -func GetOdigosVersionInCluster(ctx context.Context, client *kube.Client, ns string) (string, error) { +func getOdigosVersionInCluster(cmd *cobra.Command, flag bool) (string, error) { + client, ns, err := getOdigosKubeClientAndNamespace(cmd) + if err != nil { + return "", err + } + + OdigosClusterVersion, err = getOdigosVersionInClusterFromConfigMap(cmd.Context(), client, ns) + if err != nil { + return "", err + } + + return OdigosClusterVersion, nil +} + +func getOdigosVersionInClusterFromConfigMap(ctx context.Context, client *kube.Client, ns string) (string, error) { cm, err := client.CoreV1().ConfigMaps(ns).Get(ctx, resources.OdigosDeploymentConfigMapName, metav1.GetOptions{}) if err != nil { return "", fmt.Errorf("error detecting Odigos version in the current cluster") @@ -78,14 +95,13 @@ func getOdigosKubeClientAndNamespace(cmd *cobra.Command) (*kube.Client, string, ns, err := resources.GetOdigosNamespace(client, ctx) if err != nil { if resources.IsErrNoOdigosNamespaceFound(err) { - fmt.Println("Odigos is NOT yet installed in the current cluster") + err = fmt.Errorf("Odigos is NOT yet installed in the current cluster") } else { - fmt.Println("Error detecting Odigos version in the current cluster") + err = fmt.Errorf("Error detecting Odigos namespace in the current cluster") } - return nil, "", err } - return client, ns, nil + return client, ns, err } func init() { From fb10ed1174cc2536c278caf50a3b689be2d3946e Mon Sep 17 00:00:00 2001 From: yodigos Date: Thu, 27 Jun 2024 09:22:44 +0300 Subject: [PATCH 5/6] Fixed a few small syntax bugs --- CONTRIBUTING.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 246d438bc..ea2abff29 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -80,8 +80,7 @@ After you have a working odigos setup, you can start making changes to the code ### Run Odigos Cli from code The code for the odigos cli tool is found in the `cli` directory [here](https://github.com/odigos-io/odigos/tree/main/cli). -Test your cli code running the following: - +Test your cli code changes by running the following: ```bash go run -tags=embed_manifests ./cli ``` From 644fd22a737788b71827ea559bb4499ddd16d9b6 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Thu, 27 Jun 2024 11:58:54 +0300 Subject: [PATCH 6/6] Update Makefile Co-authored-by: Ron Federman <73110295+RonFed@users.noreply.github.com> --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7165c0241..fffe4b0d0 100644 --- a/Makefile +++ b/Makefile @@ -142,8 +142,7 @@ debug-odiglet: kubectl port-forward -n odigos-system daemonset/odiglet 2345:2345 .PHONY: deploy -deploy: - make deploy-odiglet && make deploy-autoscaler && make deploy-collector && make deploy-instrumentor +deploy: deploy-odiglet deploy-autoscaler deploy-collector deploy-instrumentor ,PHONY: e2e-test e2e-test: