Skip to content

Commit

Permalink
feat: remove OdigosConfig CRD (#1405)
Browse files Browse the repository at this point in the history
This will remove usage of `odigosconfigurations.odigos.io` CRD and
replace it with a plain ConfigMap to remove race conditions when
installing named CRD and CR at the same time during the install process.
New ConfigMap will look as following:

```
[...]
data:
  config.yaml: { ... serialized JSON of odigosconfiguration.spec ... }
[...]
```

With the exception of removal of `SupportedSDKs`(as per @blumamir
request to remove it from CM) the contents of `config.yaml` value and
the `Spec` field are identical and serialize from the same string and
parse to the same object.

Installs now just install ConfigMap instead of the CR of
OdigosConfiguration, Helm upgrades are unchanged, as they used to just
overwrite the CR anyway. CLI parses the old config unless there's
already a ConfigMap and creates it as a ConfigMap.

The old CRD is left there unused for now to be able to keep on using the
API for it(for migration) - can be removed when we feel we are ready to
remove the migration path.
  • Loading branch information
rauno56 authored Aug 16, 2024
1 parent 9f342e8 commit 59b25a1
Show file tree
Hide file tree
Showing 51 changed files with 568 additions and 562 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ changelog:
- "^docs:"
- "^test:"
brews:
- tap:
- repository:
owner: keyval-dev
name: homebrew-odigos-cli
token: "{{ .Env.HOMEBREW_GITHUB_API_TOKEN }}"
Expand Down
13 changes: 11 additions & 2 deletions api/config/crd/bases/odigos.io_odigosconfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ spec:
- name: v1alpha1
schema:
openAPIV3Schema:
description: OdigosConfiguration is the Schema for the odigos configuration
description: |-
OdigosConfiguration is the Schema for the odigos configuration
Deprecated: Use common.OdigosConfiguration instead
properties:
apiVersion:
description: |-
Expand All @@ -37,11 +41,16 @@ spec:
metadata:
type: object
spec:
description: OdigosConfigurationSpec defines the desired state of OdigosConfiguration
description: |-
OdigosConfigurationSpec defines the desired state of OdigosConfiguration
Deprecated: Use common.OdigosConfiguration instead
properties:
autoscalerImage:
type: string
collectorGateway:
description: 'Deprecated: Use common.OdigosConfiguration instead'
properties:
goMemLimitMiB:
description: |-
Expand Down
33 changes: 33 additions & 0 deletions api/odigos/v1alpha1/odigosconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Deprecated: Use common.OdigosConfiguration instead
type CollectorGatewayConfiguration struct {
// RequestMemoryMiB is the memory request for the cluster gateway collector deployment.
// it will be embedded in the deployment as a resource request of the form "memory: <value>Mi"
Expand All @@ -30,6 +31,8 @@ type CollectorGatewayConfiguration struct {
}

// OdigosConfigurationSpec defines the desired state of OdigosConfiguration
//
// Deprecated: Use common.OdigosConfiguration instead
type OdigosConfigurationSpec struct {
OdigosVersion string `json:"odigosVersion"`
ConfigVersion int `json:"configVersion"`
Expand All @@ -55,6 +58,8 @@ type OdigosConfigurationSpec struct {
//+kubebuilder:object:root=true

// OdigosConfiguration is the Schema for the odigos configuration
//
// Deprecated: Use common.OdigosConfiguration instead
type OdigosConfiguration struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -74,3 +79,31 @@ type OdigosConfigurationList struct {
func init() {
SchemeBuilder.Register(&OdigosConfiguration{}, &OdigosConfigurationList{})
}

func (odigosConfig *OdigosConfiguration) ToCommonConfig() *common.OdigosConfiguration {
var collectorGateway common.CollectorGatewayConfiguration
if odigosConfig.Spec.CollectorGateway != nil {
collectorGateway = common.CollectorGatewayConfiguration{
RequestMemoryMiB: odigosConfig.Spec.CollectorGateway.RequestMemoryMiB,
MemoryLimiterLimitMiB: odigosConfig.Spec.CollectorGateway.MemoryLimiterLimitMiB,
MemoryLimiterSpikeLimitMiB: odigosConfig.Spec.CollectorGateway.MemoryLimiterSpikeLimitMiB,
GoMemLimitMib: odigosConfig.Spec.CollectorGateway.GoMemLimitMib,
}
}
return &common.OdigosConfiguration{
OdigosVersion: odigosConfig.Spec.OdigosVersion,
ConfigVersion: odigosConfig.Spec.ConfigVersion,
TelemetryEnabled: odigosConfig.Spec.TelemetryEnabled,
OpenshiftEnabled: odigosConfig.Spec.OpenshiftEnabled,
IgnoredNamespaces: odigosConfig.Spec.IgnoredNamespaces,
IgnoredContainers: odigosConfig.Spec.IgnoredContainers,
Psp: odigosConfig.Spec.Psp,
ImagePrefix: odigosConfig.Spec.ImagePrefix,
OdigletImage: odigosConfig.Spec.OdigletImage,
InstrumentorImage: odigosConfig.Spec.InstrumentorImage,
AutoscalerImage: odigosConfig.Spec.AutoscalerImage,
DefaultSDKs: odigosConfig.Spec.DefaultSDKs,
CollectorGateway: &collectorGateway,
GoAutoIncludeCodeAttributes: odigosConfig.Spec.GoAutoIncludeCodeAttributes,
}
}
23 changes: 12 additions & 11 deletions autoscaler/controllers/gateway/memory.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gateway

import odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
import (
"github.com/odigos-io/odigos/common"
)

const (
defaultRequestMemoryMiB = 500
Expand All @@ -25,27 +27,26 @@ type memoryConfigurations struct {
gomemlimitMiB int
}

func getMemoryConfigurations(odigosConfig *odigosv1.OdigosConfiguration) *memoryConfigurations {

func getMemoryConfigurations(odigosConfig *common.OdigosConfiguration) *memoryConfigurations {
memoryRequestMiB := defaultRequestMemoryMiB
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.RequestMemoryMiB > 0 {
memoryRequestMiB = odigosConfig.Spec.CollectorGateway.RequestMemoryMiB
if odigosConfig.CollectorGateway != nil && odigosConfig.CollectorGateway.RequestMemoryMiB > 0 {
memoryRequestMiB = odigosConfig.CollectorGateway.RequestMemoryMiB
}

// the memory limiter hard limit is set as 50 MiB less than the memory request
memoryLimiterLimitMiB := memoryRequestMiB - defaultMemoryLimiterLimitDiffMib
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.MemoryLimiterLimitMiB > 0 {
memoryLimiterLimitMiB = odigosConfig.Spec.CollectorGateway.MemoryLimiterLimitMiB
if odigosConfig.CollectorGateway != nil && odigosConfig.CollectorGateway.MemoryLimiterLimitMiB > 0 {
memoryLimiterLimitMiB = odigosConfig.CollectorGateway.MemoryLimiterLimitMiB
}

memoryLimiterSpikeLimitMiB := memoryLimiterLimitMiB * defaultMemoryLimiterSpikePercentage / 100.0
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.MemoryLimiterSpikeLimitMiB > 0 {
memoryLimiterSpikeLimitMiB = odigosConfig.Spec.CollectorGateway.MemoryLimiterSpikeLimitMiB
if odigosConfig.CollectorGateway != nil && odigosConfig.CollectorGateway.MemoryLimiterSpikeLimitMiB > 0 {
memoryLimiterSpikeLimitMiB = odigosConfig.CollectorGateway.MemoryLimiterSpikeLimitMiB
}

gomemlimitMiB := int(memoryLimiterLimitMiB * defaultGoMemLimitPercentage / 100.0)
if odigosConfig.Spec.CollectorGateway != nil && odigosConfig.Spec.CollectorGateway.GoMemLimitMib != 0 {
gomemlimitMiB = odigosConfig.Spec.CollectorGateway.GoMemLimitMib
if odigosConfig.CollectorGateway != nil && odigosConfig.CollectorGateway.GoMemLimitMib != 0 {
gomemlimitMiB = odigosConfig.CollectorGateway.GoMemLimitMib
}

return &memoryConfigurations{
Expand Down
16 changes: 8 additions & 8 deletions autoscaler/controllers/gateway/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
appsv1 "k8s.io/api/apps/v1"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/autoscaler/controllers/common"
"github.com/odigos-io/odigos/common/consts"
commonconf "github.com/odigos-io/odigos/autoscaler/controllers/common"
"github.com/odigos-io/odigos/common"
k8sconsts "github.com/odigos-io/odigos/k8sutils/pkg/consts"
"github.com/odigos-io/odigos/k8sutils/pkg/env"
"github.com/odigos-io/odigos/k8sutils/pkg/utils"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -44,11 +45,10 @@ func Sync(ctx context.Context, k8sClient client.Client, scheme *runtime.Scheme,
return err
}
// Add the generic batch processor to the list of processors
processors.Items = append(processors.Items, common.GetGenericBatchProcessor())
processors.Items = append(processors.Items, commonconf.GetGenericBatchProcessor())

odigosSystemNamespaceName := env.GetCurrentNamespace()
var odigosConfig odigosv1.OdigosConfiguration
if err := k8sClient.Get(ctx, types.NamespacedName{Namespace: odigosSystemNamespaceName, Name: consts.OdigosConfigurationName}, &odigosConfig); err != nil {
odigosConfig, err := utils.GetCurrentConfig(ctx, k8sClient)
if err != nil {
logger.Error(err, "failed to get odigos config")
return err
}
Expand All @@ -58,7 +58,7 @@ func Sync(ctx context.Context, k8sClient client.Client, scheme *runtime.Scheme,

func syncGateway(dests *odigosv1.DestinationList, processors *odigosv1.ProcessorList,
gateway *odigosv1.CollectorsGroup, ctx context.Context,
c client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string, odigosConfig *odigosv1.OdigosConfiguration) error {
c client.Client, scheme *runtime.Scheme, imagePullSecrets []string, odigosVersion string, odigosConfig *common.OdigosConfiguration) error {
logger := log.FromContext(ctx)
logger.V(0).Info("Syncing gateway")

Expand Down Expand Up @@ -88,7 +88,7 @@ func syncGateway(dests *odigosv1.DestinationList, processors *odigosv1.Processor
return err
}

err = common.UpdateCollectorGroupReceiverSignals(ctx, c, gateway, signals)
err = commonconf.UpdateCollectorGroupReceiverSignals(ctx, c, gateway, signals)
if err != nil {
logger.Error(err, "Failed to update cluster collectors group received signals")
return err
Expand Down
6 changes: 3 additions & 3 deletions autoscaler/controllers/odigosconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package controllers
import (
"context"

v1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/autoscaler/controllers/gateway"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -19,7 +19,6 @@ type OdigosConfigReconciler struct {
}

func (r *OdigosConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {

logger := log.FromContext(ctx)
logger.V(0).Info("Reconciling Odigos Configuration")

Expand All @@ -33,7 +32,8 @@ func (r *OdigosConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request

// SetupWithManager sets up the controller with the Manager.
func (r *OdigosConfigReconciler) SetupWithManager(mgr ctrl.Manager) error {
// TODO: Clean up noise from too broad of a definition here
return ctrl.NewControllerManagedBy(mgr).
For(&v1.OdigosConfiguration{}).
For(&v1.ConfigMap{}).
Complete(r)
}
8 changes: 3 additions & 5 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

apierrors "k8s.io/apimachinery/pkg/api/errors"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/consts"
"github.com/odigos-io/odigos/common/utils"
Expand Down Expand Up @@ -83,7 +82,7 @@ This command will install k8s components that will auto-instrument your applicat
odigosProToken = odigosOnPremToken
}

config := createOdigosConfigSpec()
config := createOdigosConfig()

fmt.Printf("Installing Odigos version %s in namespace %s ...\n", versionFlag, ns)

Expand Down Expand Up @@ -178,12 +177,11 @@ func createNamespace(ctx context.Context, cmd *cobra.Command, client *kube.Clien
return nil
}

func createOdigosConfigSpec() odigosv1.OdigosConfigurationSpec {

func createOdigosConfig() common.OdigosConfiguration {
fullIgnoredNamespaces := utils.MergeDefaultIgnoreWithUserInput(userInputIgnoredNamespaces, consts.SystemNamespaces)
fullIgnoredContainers := utils.MergeDefaultIgnoreWithUserInput(userInputIgnoredContainers, consts.IgnoredContainers)

return odigosv1.OdigosConfigurationSpec{
return common.OdigosConfiguration{
OdigosVersion: versionFlag,
ConfigVersion: 1, // config version starts at 1 and incremented on every config change
TelemetryEnabled: telemetryEnabled,
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func updateApiKey(cmd *cobra.Command, args []string) {
fmt.Println("Odigos cloud login failed - unable to read the current Odigos configuration.")
os.Exit(1)
}
config.Spec.ConfigVersion += 1
config.ConfigVersion += 1

if odigosCloudApiKeyFlag == "" {
fmt.Println("Enter your odigos cloud api-key. You can find it here: https://app.odigos.io/settings")
Expand All @@ -92,7 +92,7 @@ func updateApiKey(cmd *cobra.Command, args []string) {
}
isPrevOdigosCloud := currentTier == common.CloudOdigosTier

resourceManagers := resources.CreateResourceManagers(client, ns, common.CloudOdigosTier, &odigosCloudApiKeyFlag, &config.Spec)
resourceManagers := resources.CreateResourceManagers(client, ns, common.CloudOdigosTier, &odigosCloudApiKeyFlag, config)
err = resources.ApplyResourceManagers(ctx, client, resourceManagers, "Updating")
if err != nil {
fmt.Println("Odigos cloud login failed - unable to apply Odigos resources.")
Expand All @@ -106,7 +106,7 @@ func updateApiKey(cmd *cobra.Command, args []string) {

if isPrevOdigosCloud {
l := log.Print("Restarting relevant pods ...")
err := restartPodsAfterCloudLogin(ctx, client, ns, config.Spec.ConfigVersion)
err := restartPodsAfterCloudLogin(ctx, client, ns, config.ConfigVersion)
if err != nil {
l.Error(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var logoutCmd = &cobra.Command{
Use: "logout",
Short: "Logout from Odigos cloud",
Long: `Disconnect this Odigos installation from your odigos cloud account.
After running this command, you will no longer be able to control and monitor this Odigos installation from Odigos cloud.
You can run 'odigos ui' to manage your Odigos installation locally.
`,
Expand Down Expand Up @@ -65,10 +65,10 @@ var logoutCmd = &cobra.Command{
fmt.Println("Odigos cloud logout failed - unable to read the current Odigos configuration.")
os.Exit(1)
}
config.Spec.ConfigVersion += 1
config.ConfigVersion += 1

emptyApiKey := ""
resourceManagers := resources.CreateResourceManagers(client, ns, common.CommunityOdigosTier, &emptyApiKey, &config.Spec)
resourceManagers := resources.CreateResourceManagers(client, ns, common.CommunityOdigosTier, &emptyApiKey, config)
err = resources.ApplyResourceManagers(ctx, client, resourceManagers, "Updating")
if err != nil {
fmt.Println("Odigos cloud logout failed - unable to apply Odigos resources.")
Expand Down
23 changes: 19 additions & 4 deletions cli/cmd/resources/applyresources.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/odigos-io/odigos/cli/cmd/resources/resourcemanager"
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/cli/pkg/log"
"github.com/odigos-io/odigos/common"
"github.com/odigos-io/odigos/common/consts"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
)

func ApplyResourceManagers(ctx context.Context, client *kube.Client, resourceManagers []resourcemanager.ResourceManager, prefixForLogging string) error {
Expand All @@ -26,11 +28,11 @@ func ApplyResourceManagers(ctx context.Context, client *kube.Client, resourceMan
return nil
}

func DeleteOldOdigosSystemObjects(ctx context.Context, client *kube.Client, ns string, config *v1alpha1.OdigosConfiguration) error {
func DeleteOldOdigosSystemObjects(ctx context.Context, client *kube.Client, ns string, config *common.OdigosConfiguration) error {
resources := kube.GetManagedResources(ns)
for _, resource := range resources {
l := log.Print(fmt.Sprintf("Syncing %s", resource.Resource.Resource))
err := client.DeleteOldOdigosSystemObjects(ctx, resource, config.Spec.ConfigVersion)
err := client.DeleteOldOdigosSystemObjects(ctx, resource, config.ConfigVersion)
if err != nil {
l.Error(err)
os.Exit(1)
Expand All @@ -41,6 +43,19 @@ func DeleteOldOdigosSystemObjects(ctx context.Context, client *kube.Client, ns s
return nil
}

func GetCurrentConfig(ctx context.Context, client *kube.Client, ns string) (*v1alpha1.OdigosConfiguration, error) {
return client.OdigosClient.OdigosConfigurations(ns).Get(ctx, consts.OdigosConfigurationName, metav1.GetOptions{})
func GetCurrentConfig(ctx context.Context, client *kube.Client, ns string) (*common.OdigosConfiguration, error) {
configMap, err := client.CoreV1().ConfigMaps(ns).Get(ctx, consts.OdigosConfigurationName, metav1.GetOptions{})
if err != nil {
return nil, err
}
var odigosConfig common.OdigosConfiguration
if err := yaml.Unmarshal([]byte(configMap.Data[consts.OdigosConfigurationFileName]), &odigosConfig); err != nil {
return nil, err
}
return &odigosConfig, nil
}

func GetDeprecatedConfig(ctx context.Context, client *kube.Client, ns string) (*v1alpha1.OdigosConfiguration, error) {
return client.OdigosClient.OdigosConfigurations(ns).Get(ctx, consts.OdigosConfigurationName, metav1.GetOptions{})
}

6 changes: 3 additions & 3 deletions cli/cmd/resources/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package resources
import (
"context"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/cli/cmd/resources/resourcemanager"
"github.com/odigos-io/odigos/cli/pkg/containers"
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/common"
"sigs.k8s.io/controller-runtime/pkg/client"

appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -516,10 +516,10 @@ func NewAutoscalerDeployment(ns string, version string, imagePrefix string, imag
type autoScalerResourceManager struct {
client *kube.Client
ns string
config *odigosv1.OdigosConfigurationSpec
config *common.OdigosConfiguration
}

func NewAutoScalerResourceManager(client *kube.Client, ns string, config *odigosv1.OdigosConfigurationSpec) resourcemanager.ResourceManager {
func NewAutoScalerResourceManager(client *kube.Client, ns string, config *common.OdigosConfiguration) resourcemanager.ResourceManager {
return &autoScalerResourceManager{client: client, ns: ns, config: config}
}

Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/resources/datacollection.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package resources
import (
"context"

odigosv1 "github.com/odigos-io/odigos/api/odigos/v1alpha1"
"github.com/odigos-io/odigos/cli/cmd/resources/resourcemanager"
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/common"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -113,10 +113,10 @@ func NewDataCollectionClusterRoleBinding(ns string) *rbacv1.ClusterRoleBinding {
type dataCollectionResourceManager struct {
client *kube.Client
ns string
config *odigosv1.OdigosConfigurationSpec
config *common.OdigosConfiguration
}

func NewDataCollectionResourceManager(client *kube.Client, ns string, config *odigosv1.OdigosConfigurationSpec) resourcemanager.ResourceManager {
func NewDataCollectionResourceManager(client *kube.Client, ns string, config *common.OdigosConfiguration) resourcemanager.ResourceManager {
return &dataCollectionResourceManager{client: client, ns: ns, config: config}
}

Expand Down
Loading

0 comments on commit 59b25a1

Please sign in to comment.