Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an option to do odigos version --cli/--cluster to print only th… #1298

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
```

Expand All @@ -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=<CURRENT-ODIGOS-VERSION> 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.
Expand Down Expand Up @@ -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=<CURRENT-ODIGOS-VERSION> 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.
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
69 changes: 49 additions & 20 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,65 @@ 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
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)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blumamir I changed it so you can do multiple arguments (cli + cluster).. I'm not sure there is or will be a use case for it. But, usually CLIs allow multiple arguments. So even in the future if we will want to add


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")
Expand All @@ -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")
}
Loading