diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 884c1ff29..ea2abff29 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -80,16 +80,15 @@ 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 changes by 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 ... ``` @@ -98,19 +97,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 -- Build custom images of Odigos and load them into Kind via: - +1. Use a Kind kubernetes cluster. +2. Choose one of the following options for deploy: +- Deploy all pods in the odigos-system namespace: ```bash -TAG= make build-images load-to-kind + make deploy ``` -- Ensure the TAG matches the Odigos version output from: `odigos version` -- Restart all pods in the `odigos-system` namespace: - +- Deploy a specific service by running one of the following commands: ```bash -kubectl delete pods --all -n odigos-system + 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. @@ -149,7 +148,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..fffe4b0d0 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ -TAG ?= $(shell odigos version --short) +TAG ?= $(shell odigos version --cluster) ORG := keyval + .PHONY: build-odiglet build-odiglet: docker build -t $(ORG)/odigos-odiglet:$(TAG) . -f odiglet/Dockerfile @@ -140,6 +141,9 @@ 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: deploy-odiglet deploy-autoscaler deploy-collector deploy-instrumentor + ,PHONY: e2e-test e2e-test: ./e2e-test.sh diff --git a/cli/cmd/version.go b/cli/cmd/version.go index f6550453a..b518ccd7e 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,19 +30,48 @@ var versionCmd = &cobra.Command{ Use: "version", Short: "Print odigos version.", Run: func(cmd *cobra.Command, args []string) { - short_flag, _ := cmd.Flags().GetBool("short") + cliFlag, _ := cmd.Flags().GetBool(cliFlag) + clusterFlag, _ := cmd.Flags().GetBool(clusterFlag) - if short_flag { + if cliFlag { fmt.Printf("%s\n", OdigosVersion) + } + + OdigosClusterVersion, err := getOdigosVersionInCluster(cmd, clusterFlag) + + 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) - printOdigosClusterVersion(cmd) + 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") @@ -50,34 +85,28 @@ 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() 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 - } - - clusterVersion, err := GetOdigosVersionInCluster(ctx, client, ns) - if err != nil { - fmt.Println("Error detecting Odigos version in the current cluster") - return } - fmt.Printf("Odigos Version (in cluster): version.Info{Version:'%s'}\n", clusterVersion) + return client, ns, err } 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") }