Skip to content

Commit

Permalink
Fixed a few small syntax bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
yodigos committed Jun 27, 2024
1 parent 58a888b commit 67386a8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
46 changes: 31 additions & 15 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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() {
Expand Down

0 comments on commit 67386a8

Please sign in to comment.