Skip to content

Commit

Permalink
chore: move common strings for "odigos-deployment" cm to consts and u…
Browse files Browse the repository at this point in the history
…se them (#2183)

Cleanup, in prepration for adding more keys to the `odigos-deployment`
configmap
  • Loading branch information
blumamir authored Jan 11, 2025
1 parent 4b07451 commit 7eb0e40
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 28 deletions.
21 changes: 11 additions & 10 deletions autoscaler/controllers/gateway/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"errors"

"github.com/odigos-io/odigos/autoscaler/utils"
"github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/common/consts"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/autoscaler/controllers/common"
Expand Down Expand Up @@ -105,7 +106,7 @@ func getDesiredDeployment(dests *odigosv1.DestinationList, configDataHash string

desiredDeployment := &appsv1.Deployment{
ObjectMeta: v1.ObjectMeta{
Name: consts.OdigosClusterCollectorDeploymentName,
Name: k8sconsts.OdigosClusterCollectorDeploymentName,
Namespace: gateway.Namespace,
Labels: ClusterCollectorGateway,
},
Expand All @@ -124,16 +125,16 @@ func getDesiredDeployment(dests *odigosv1.DestinationList, configDataHash string
Spec: corev1.PodSpec{
Volumes: []corev1.Volume{
{
Name: consts.OdigosClusterCollectorConfigMapKey,
Name: k8sconsts.OdigosClusterCollectorConfigMapKey,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: gateway.Name,
},
Items: []corev1.KeyToPath{
{
Key: consts.OdigosClusterCollectorConfigMapKey,
Path: fmt.Sprintf("%s.yaml", consts.OdigosClusterCollectorConfigMapKey),
Key: k8sconsts.OdigosClusterCollectorConfigMapKey,
Path: fmt.Sprintf("%s.yaml", k8sconsts.OdigosClusterCollectorConfigMapKey),
},
},
},
Expand All @@ -144,18 +145,18 @@ func getDesiredDeployment(dests *odigosv1.DestinationList, configDataHash string
{
Name: containerName,
Image: utils.GetCollectorContainerImage(containerImage, odigosVersion),
Command: []string{containerCommand, fmt.Sprintf("--config=%s/%s.yaml", confDir, consts.OdigosClusterCollectorConfigMapKey)},
Command: []string{containerCommand, fmt.Sprintf("--config=%s/%s.yaml", confDir, k8sconsts.OdigosClusterCollectorConfigMapKey)},
EnvFrom: getSecretsFromDests(dests),
// Add the ODIGOS_VERSION environment variable from the ConfigMap
Env: []corev1.EnvVar{
{
Name: "ODIGOS_VERSION",
Name: consts.OdigosVersionEnvVarName,
ValueFrom: &corev1.EnvVarSource{
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "odigos-deployment",
Name: k8sconsts.OdigosDeploymentConfigMapName,
},
Key: "ODIGOS_VERSION",
Key: k8sconsts.OdigosDeploymentConfigMapVersionKey,
},
},
},
Expand Down Expand Up @@ -190,7 +191,7 @@ func getDesiredDeployment(dests *odigosv1.DestinationList, configDataHash string
},
VolumeMounts: []corev1.VolumeMount{
{
Name: consts.OdigosClusterCollectorConfigMapKey,
Name: k8sconsts.OdigosClusterCollectorConfigMapKey,
MountPath: confDir,
},
},
Expand Down
3 changes: 2 additions & 1 deletion autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"strings"

"github.com/odigos-io/odigos/common/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
odigosver "github.com/odigos-io/odigos/k8sutils/pkg/version"

Expand Down Expand Up @@ -93,7 +94,7 @@ func main() {
"The image pull secrets to use for the collectors created by autoscaler")
flag.StringVar(&nameutils.ImagePrefix, "image-prefix", "", "The image prefix to use for the collectors created by autoscaler")

odigosVersion := os.Getenv("ODIGOS_VERSION")
odigosVersion := os.Getenv(consts.OdigosVersionEnvVarName)
if odigosVersion == "" {
flag.StringVar(&odigosVersion, "version", "", "for development purposes only")
}
Expand Down
9 changes: 5 additions & 4 deletions cli/cmd/resources/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"github.com/odigos-io/odigos/cli/pkg/containers"
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/common/consts"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -291,13 +292,13 @@ func NewAutoscalerDeployment(ns string, version string, imagePrefix string, imag
},
},
{
Name: "ODIGOS_VERSION",
Name: consts.OdigosVersionEnvVarName,
ValueFrom: &corev1.EnvVarSource{
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: consts.OdigosDeploymentConfigMapName,
Name: k8sconsts.OdigosDeploymentConfigMapName,
},
Key: "ODIGOS_VERSION",
Key: k8sconsts.OdigosDeploymentConfigMapVersionKey,
},
},
},
Expand Down
5 changes: 3 additions & 2 deletions cli/cmd/resources/instrumentor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/consts"

k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
k8sutilsconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -401,13 +402,13 @@ func NewInstrumentorDeployment(ns string, version string, telemetryEnabled bool,
},
},
{
Name: "ODIGOS_TIER",
Name: consts.OdigosTierEnvVarName,
ValueFrom: &corev1.EnvVarSource{
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: k8sutilsconsts.OdigosDeploymentConfigMapName,
},
Key: "ODIGOS_TIER",
Key: k8sconsts.OdigosDeploymentConfigMapTierKey,
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions cli/cmd/resources/odigosdeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/odigos-io/odigos/cli/cmd/resources/resourcemanager"
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/k8sutils/pkg/consts"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -21,12 +21,12 @@ func NewOdigosDeploymentConfigMap(ns string, odigosVersion string, odigosTier st
APIVersion: "v1",
},
ObjectMeta: v1.ObjectMeta{
Name: consts.OdigosDeploymentConfigMapName,
Name: k8sconsts.OdigosDeploymentConfigMapName,
Namespace: ns,
},
Data: map[string]string{
"ODIGOS_VERSION": odigosVersion,
"ODIGOS_TIER": odigosTier,
k8sconsts.OdigosDeploymentConfigMapVersionKey: odigosVersion,
k8sconsts.OdigosDeploymentConfigMapTierKey: odigosTier,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ and apply any required migrations and adaptations.`,
os.Exit(1)
}

currOdigosVersion := cm.Data["ODIGOS_VERSION"]
currOdigosVersion := cm.Data[k8sconsts.OdigosDeploymentConfigMapVersionKey]
if currOdigosVersion == "" {
fmt.Println("Odigos upgrade failed - unable to read the current Odigos version for migration")
os.Exit(1)
Expand Down
2 changes: 2 additions & 0 deletions common/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

const (
CurrentNamespaceEnvVar = "CURRENT_NS"
OdigosVersionEnvVarName = "ODIGOS_VERSION"
OdigosTierEnvVarName = "ODIGOS_TIER"
DefaultOdigosNamespace = "odigos-system"
OdigosConfigurationName = "odigos-config"
OdigosEffectiveConfigName = "effective-config"
Expand Down
9 changes: 7 additions & 2 deletions k8sutils/pkg/consts/consts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package consts

import "k8s.io/apimachinery/pkg/util/version"
import (
commonconsts "github.com/odigos-io/odigos/common/consts"
"k8s.io/apimachinery/pkg/util/version"
)

var (
DefaultIgnoredNamespaces = []string{"kube-system", "local-path-storage", "istio-system", "linkerd", "kube-node-lease"}
Expand All @@ -22,7 +25,9 @@ const (
)

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

const (
Expand Down
2 changes: 1 addition & 1 deletion k8sutils/pkg/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func GetSyncDaemonSetDelay() int {
}

func GetOdigosTierFromEnv() common.OdigosTier {
odigosTierStr := os.Getenv("ODIGOS_TIER")
odigosTierStr := os.Getenv(consts.OdigosTierEnvVarName)

switch odigosTierStr {
case string(common.CommunityOdigosTier):
Expand Down
6 changes: 3 additions & 3 deletions k8sutils/pkg/getters/odigosversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"

"github.com/odigos-io/odigos/k8sutils/pkg/consts"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
Expand All @@ -17,12 +17,12 @@ var (
// Return the Odigos version installed in the cluster.
// The function assumes odigos is installed, and will return an error if it is not or if the version cannot be detected (not expected in normal operation).
func GetOdigosVersionInClusterFromConfigMap(ctx context.Context, client kubernetes.Interface, ns string) (string, error) {
cm, err := client.CoreV1().ConfigMaps(ns).Get(ctx, consts.OdigosDeploymentConfigMapName, metav1.GetOptions{})
cm, err := client.CoreV1().ConfigMaps(ns).Get(ctx, k8sconsts.OdigosDeploymentConfigMapName, metav1.GetOptions{})
if err != nil {
return "", ErrNoOdigosDeploymentConfigMap
}

odigosVersion, ok := cm.Data["ODIGOS_VERSION"]
odigosVersion, ok := cm.Data[k8sconsts.OdigosDeploymentConfigMapVersionKey]
if !ok || odigosVersion == "" {
return "", ErrMissingVersionInConfigMap
}
Expand Down

0 comments on commit 7eb0e40

Please sign in to comment.