Skip to content

Commit

Permalink
chore: move profiles manifest files to profiles module (#2193)
Browse files Browse the repository at this point in the history
profiles manifests are currently hosted in cli module.

this PR moves them to the `profiles` module, so they can later be
consumed and apply as a reconciliation in sschedualer.

It will also help maintainability to have all profiles definitions in
one place instead of having the profile info in one module and manifests
in another
  • Loading branch information
blumamir authored Jan 12, 2025
1 parent a5c8e94 commit 1ef26a8
Show file tree
Hide file tree
Showing 14 changed files with 16 additions and 680 deletions.
10 changes: 5 additions & 5 deletions cli/cmd/resources/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import (
"context"
"fmt"

cliprofiles "github.com/odigos-io/odigos/cli/cmd/resources/profiles"
"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/profiles"
"github.com/odigos-io/odigos/profiles/manifests"
"github.com/odigos-io/odigos/profiles/profile"
)

func GetResourcesForProfileName(profileName common.ProfileName, tier common.OdigosTier) ([]kube.Object, error) {
func GetResourcesForProfileName(profileName common.ProfileName, tier common.OdigosTier) ([]profile.K8sObject, error) {
allAvailableProfiles := GetAvailableProfilesForTier(tier)
for _, p := range allAvailableProfiles {
if p.ProfileName == common.ProfileName(profileName) {
if p.KubeObject != nil {
filename := fmt.Sprintf("%s.yaml", profileName)
return cliprofiles.GetEmbeddedYAMLFileAsObjects(filename, p.KubeObject)
return manifests.GetEmbeddedResourceManifestsAsObjects(filename, p.KubeObject)
}
if len(p.Dependencies) > 0 {
allResources := []kube.Object{}
allResources := []profile.K8sObject{}
for _, dep := range p.Dependencies {
resources, err := GetResourcesForProfileName(dep, tier)
if err != nil {
Expand Down Expand Up @@ -71,8 +71,8 @@ func (a *profilesResourceManager) InstallFromScratch(ctx context.Context) error
}
for _, r := range profileResources {
r.SetNamespace(a.ns)
allResources = append(allResources, r)
}
allResources = append(allResources, profileResources...)
}
return a.client.ApplyResources(ctx, a.config.ConfigVersion, allResources)
}
650 changes: 0 additions & 650 deletions cli/cmd/resources/profiles/category-attributes-deprecated.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions cli/cmd/resources/profiles/semconv-deprecated.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion profiles/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/odigos-io/odigos/api v0.0.0
github.com/odigos-io/odigos/common v0.0.0
k8s.io/apimachinery v0.32.0
sigs.k8s.io/yaml v1.4.0
)

require (
Expand Down Expand Up @@ -57,7 +58,6 @@ require (
sigs.k8s.io/controller-runtime v0.19.0 // indirect
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package profiles
package manifests

import (
"embed"
"fmt"
"reflect"

"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/profiles/profile"
"sigs.k8s.io/yaml"
)

//go:embed *.yaml
var embeddedFiles embed.FS

// GetEmbeddedYAMLFileAsObjects is a generic function to read embedded YAML files and convert them into runtime.Object
func GetEmbeddedYAMLFileAsObjects(filename string, obj kube.Object) ([]kube.Object, error) {
// GetEmbeddedResourceManifestsAsObjects is a generic function to read embedded YAML files and convert them into runtime.Object
func GetEmbeddedResourceManifestsAsObjects(filename string, obj profile.K8sObject) ([]profile.K8sObject, error) {

// Read the embedded YAML file content
yamlBytes, err := embeddedFiles.ReadFile(filename)
Expand All @@ -31,6 +31,11 @@ func GetEmbeddedYAMLFileAsObjects(filename string, obj kube.Object) ([]kube.Obje
return nil, fmt.Errorf("failed to unmarshal YAML: %v", err)
}

k8sObj, ok := newObj.(profile.K8sObject)
if !ok {
return nil, fmt.Errorf("unmarshaled object is not a k8s object")
}

// Return the object wrapped in a slice
return []kube.Object{newObj.(kube.Object)}, nil
return []profile.K8sObject{k8sObj}, nil
}
File renamed without changes.
File renamed without changes.

0 comments on commit 1ef26a8

Please sign in to comment.