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

feat: record installation method into odigos-deployment #2184

Merged
merged 3 commits into from
Jan 11, 2025
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
6 changes: 4 additions & 2 deletions cli/cmd/resources/odigosdeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/common"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/installationmethod"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -25,8 +26,9 @@ func NewOdigosDeploymentConfigMap(ns string, odigosVersion string, odigosTier st
Namespace: ns,
},
Data: map[string]string{
k8sconsts.OdigosDeploymentConfigMapVersionKey: odigosVersion,
k8sconsts.OdigosDeploymentConfigMapTierKey: odigosTier,
k8sconsts.OdigosDeploymentConfigMapVersionKey: odigosVersion,
k8sconsts.OdigosDeploymentConfigMapTierKey: odigosTier,
k8sconsts.OdigosDeploymentConfigMapInstallationMethodKey: string(installationmethod.K8sInstallationMethodOdigosCli),
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion helm/odigos/templates/odigos-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ metadata:
namespace: {{ .Release.Namespace }}
data:
ODIGOS_VERSION: {{ .Values.image.tag | default .Chart.AppVersion }}
ODIGOS_TIER: "{{- if .Values.onPremToken }}onprem{{- else }}community{{- end }}"
ODIGOS_TIER: "{{- if .Values.onPremToken }}onprem{{- else }}community{{- end }}"
installation-method: helm
7 changes: 4 additions & 3 deletions k8sutils/pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ const (
)

const (
OdigosDeploymentConfigMapName = "odigos-deployment"
OdigosDeploymentConfigMapVersionKey = commonconsts.OdigosVersionEnvVarName
OdigosDeploymentConfigMapTierKey = commonconsts.OdigosTierEnvVarName
OdigosDeploymentConfigMapName = "odigos-deployment"
OdigosDeploymentConfigMapVersionKey = commonconsts.OdigosVersionEnvVarName
OdigosDeploymentConfigMapTierKey = commonconsts.OdigosTierEnvVarName
OdigosDeploymentConfigMapInstallationMethodKey = "installation-method"
)

const (
Expand Down
2 changes: 2 additions & 0 deletions k8sutils/pkg/describe/odigos.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func DescribeOdigosToText(analyze *odigos.OdigosAnalyze) string {
var sb strings.Builder

printProperty(&sb, 0, &analyze.OdigosVersion)
printProperty(&sb, 0, &analyze.Tier)
printProperty(&sb, 0, &analyze.InstallationMethod)
sb.WriteString("\n")
printOdigosPipeline(analyze, &sb)

Expand Down
31 changes: 27 additions & 4 deletions k8sutils/pkg/describe/odigos/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package odigos

import (
odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/describe/properties"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -36,6 +37,8 @@ type NodeCollectorAnalyze struct {

type OdigosAnalyze struct {
OdigosVersion properties.EntityProperty `json:"odigosVersion"`
Tier properties.EntityProperty `json:"tier"`
InstallationMethod properties.EntityProperty `json:"installationMethod"`
NumberOfDestinations int `json:"numberOfDestinations"`
NumberOfSources int `json:"numberOfSources"`
ClusterCollector ClusterCollectorAnalyze `json:"clusterCollector"`
Expand Down Expand Up @@ -368,13 +371,33 @@ func AnalyzeOdigos(resources *OdigosResources) *OdigosAnalyze {
clusterCollector := analyzeClusterCollector(resources)
nodeCollector := analyzeNodeCollector(resources)
isSettled, hasErrors := summarizeStatus(clusterCollector, nodeCollector)
odigosVersion := properties.EntityProperty{
Name: "Odigos Version",
Value: resources.OdigosVersion,

odigosVersion := resources.OdigosDeployment.Data[k8sconsts.OdigosDeploymentConfigMapVersionKey]
tier := resources.OdigosDeployment.Data[k8sconsts.OdigosDeploymentConfigMapTierKey]
installationMethod := resources.OdigosDeployment.Data[k8sconsts.OdigosDeploymentConfigMapInstallationMethodKey]

odigosVersionProperty := properties.EntityProperty{
Name: "Odigos Version",
Value: odigosVersion,
Explain: "the version of odigos deployment currently installed in the cluster",
}

odigosTierProperty := properties.EntityProperty{
Name: "Tier",
Value: tier,
Explain: "the tier of odigos deployment (community, enterprise, cloud)",
}

installationMethodProperty := properties.EntityProperty{
Name: "Installation Method",
Value: installationMethod,
Explain: "the method used to deploy odigos in the cluster (helm or odigos cli)",
}

return &OdigosAnalyze{
OdigosVersion: odigosVersion,
OdigosVersion: odigosVersionProperty,
Tier: odigosTierProperty,
InstallationMethod: installationMethodProperty,
NumberOfDestinations: len(resources.Destinations.Items),
NumberOfSources: len(resources.InstrumentationConfigs.Items),
ClusterCollector: clusterCollector,
Expand Down
17 changes: 8 additions & 9 deletions k8sutils/pkg/describe/odigos/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (

odigosclientset "github.com/odigos-io/odigos/api/generated/odigos/clientset/versioned/typed/odigos/v1alpha1"
odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/getters"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -27,7 +26,7 @@ type NodeCollectorResources struct {
}

type OdigosResources struct {
OdigosVersion string
OdigosDeployment *corev1.ConfigMap // guaranteed to exist
ClusterCollector ClusterCollectorResources
NodeCollector NodeCollectorResources
Destinations *odigosv1.DestinationList
Expand All @@ -38,14 +37,14 @@ func getClusterCollectorResources(ctx context.Context, kubeClient kubernetes.Int

clusterCollector := ClusterCollectorResources{}

cg, err := odigosClient.CollectorsGroups(odigosNs).Get(ctx, consts.OdigosClusterCollectorCollectorGroupName, metav1.GetOptions{})
cg, err := odigosClient.CollectorsGroups(odigosNs).Get(ctx, k8sconsts.OdigosClusterCollectorCollectorGroupName, metav1.GetOptions{})
if err == nil {
clusterCollector.CollectorsGroup = cg
} else if !apierrors.IsNotFound(err) {
return nil, err
}

dep, err := kubeClient.AppsV1().Deployments(odigosNs).Get(ctx, consts.OdigosClusterCollectorDeploymentName, metav1.GetOptions{})
dep, err := kubeClient.AppsV1().Deployments(odigosNs).Get(ctx, k8sconsts.OdigosClusterCollectorDeploymentName, metav1.GetOptions{})
if err == nil {
clusterCollector.Deployment = dep
} else if !apierrors.IsNotFound(err) {
Expand Down Expand Up @@ -96,14 +95,14 @@ func getNodeCollectorResources(ctx context.Context, kubeClient kubernetes.Interf

nodeCollector := NodeCollectorResources{}

cg, err := odigosClient.CollectorsGroups(odigosNs).Get(ctx, consts.OdigosNodeCollectorCollectorGroupName, metav1.GetOptions{})
cg, err := odigosClient.CollectorsGroups(odigosNs).Get(ctx, k8sconsts.OdigosNodeCollectorCollectorGroupName, metav1.GetOptions{})
if err == nil {
nodeCollector.CollectorsGroup = cg
} else if !apierrors.IsNotFound(err) {
return nil, err
}

ds, err := kubeClient.AppsV1().DaemonSets(odigosNs).Get(ctx, consts.OdigosNodeCollectorDaemonSetName, metav1.GetOptions{})
ds, err := kubeClient.AppsV1().DaemonSets(odigosNs).Get(ctx, k8sconsts.OdigosNodeCollectorDaemonSetName, metav1.GetOptions{})
if err == nil {
nodeCollector.DaemonSet = ds
} else if !apierrors.IsNotFound(err) {
Expand All @@ -117,11 +116,11 @@ func GetRelevantOdigosResources(ctx context.Context, kubeClient kubernetes.Inter

odigos := OdigosResources{}

odigosVersion, err := getters.GetOdigosVersionInClusterFromConfigMap(ctx, kubeClient, odigosNs)
odigosDeployment, err := kubeClient.CoreV1().ConfigMaps(odigosNs).Get(ctx, k8sconsts.OdigosDeploymentConfigMapName, metav1.GetOptions{})
if err != nil {
return nil, err
}
odigos.OdigosVersion = odigosVersion
odigos.OdigosDeployment = odigosDeployment

cc, err := getClusterCollectorResources(ctx, kubeClient, odigosClient, odigosNs)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions k8sutils/pkg/installationmethod/installationmethod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package installationmethod

type K8sInstallationMethod string

const (
K8sInstallationMethodOdigosCli K8sInstallationMethod = "odigos-cli"
K8sInstallationMethodHelm K8sInstallationMethod = "helm"
)
Loading