Skip to content

Commit

Permalink
Added Destination CRDS
Browse files Browse the repository at this point in the history
  • Loading branch information
yodigos committed Nov 4, 2024
1 parent a0116ad commit 7041424
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
9 changes: 9 additions & 0 deletions cli/cmd/diagnose.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ func startDiagnose(ctx context.Context, client *kube.Client) error {
}
}()

// Fetch Odigos Destinations
wg.Add(1)
go func() {
defer wg.Done()
if err = diagnose_util.FetchDestinationsCRDs(ctx, client, filepath.Join(mainTempDir, CRDsDir)); err != nil {
fmt.Printf("Error fetching Odigos CRDs: %v\n", err)
}
}()

wg.Wait()

// Package the results into a tar.gz file
Expand Down
32 changes: 29 additions & 3 deletions cli/cmd/diagnose_util/crd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package diagnose_util
import (
"context"
"fmt"
"github.com/odigos-io/odigos/cli/cmd/resources"
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/k8sutils/pkg/client"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -106,7 +107,7 @@ func fetchSingleResource(ctx context.Context, kubeClient *kube.Client, crdDataDi

err := client.ListWithPages(client.DefaultPageSize, kubeClient.Dynamic.Resource(gvr).List, ctx, metav1.ListOptions{}, func(crds *unstructured.UnstructuredList) error {
for _, crd := range crds.Items {
if err := saveCrdToFile(crd, crdDataDirPath); err != nil {
if err := saveCrdToFile(crd, crdDataDirPath, crd.GetName()); err != nil {
fmt.Printf("Fetching Resource %s Failed because: %s\n", resourceData[CRDName], err)
}
}
Expand All @@ -121,8 +122,8 @@ func fetchSingleResource(ctx context.Context, kubeClient *kube.Client, crdDataDi
return nil
}

func saveCrdToFile(crd unstructured.Unstructured, crdDataDirPath string) error {
crdDirPath := filepath.Join(crdDataDirPath, crd.GetName()+".yaml.gz")
func saveCrdToFile(crd interface{}, crdDataDirPath string, crdName string) error {
crdDirPath := filepath.Join(crdDataDirPath, crdName+".yaml")
crdFile, err := os.OpenFile(crdDirPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
return err
Expand All @@ -144,3 +145,28 @@ func saveCrdToFile(crd unstructured.Unstructured, crdDataDirPath string) error {

return nil
}

func FetchDestinationsCRDs(ctx context.Context, client *kube.Client, CRDsDir string) error {
odigosNamespace, err := resources.GetOdigosNamespace(client, ctx)
if err != nil {
return err
}

destinations, err := client.OdigosClient.Destinations(odigosNamespace).List(ctx, metav1.ListOptions{})
if err != nil {
return err
}

crdDestinationPath := filepath.Join(CRDsDir, "destinations")
err = os.Mkdir(crdDestinationPath, os.ModePerm)

for _, destination := range destinations.Items {
//crdDataDirPath := filepath.Join(crdDestinationPath, destination.Name)
if err := saveCrdToFile(destination, crdDestinationPath, destination.Name); err != nil {
fmt.Printf("Fetching Resource %s Failed because: %s\n", destination.Name, err)
}

}

return nil
}

0 comments on commit 7041424

Please sign in to comment.