Skip to content

Commit

Permalink
fix: Store custome resources in JSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
banjoh committed Oct 9, 2023
1 parent 32b0e1a commit 19aed1c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pkg/collect/cluster_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
"github.com/replicatedhq/troubleshoot/pkg/constants"
"github.com/replicatedhq/troubleshoot/pkg/k8sutil"
"gopkg.in/yaml.v2"
authorizationv1 "k8s.io/api/authorization/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
Expand Down Expand Up @@ -1319,12 +1318,12 @@ func crsV1(ctx context.Context, client dynamic.Interface, config *rest.Config, n
for _, item := range customResourceList.Items {
objects = append(objects, item.Object)
}
b, err := yaml.Marshal(objects)
b, err := json.Marshal(objects)
if err != nil {
errorList[crd.Name] = err.Error()
continue
}
customResources[fmt.Sprintf("%s.yaml", crd.Name)] = b
customResources[fmt.Sprintf("%s.json", crd.Name)] = b
} else {
// Group fetched resources by the namespace
perNamespace := map[string][]map[string]interface{}{}
Expand Down Expand Up @@ -1353,13 +1352,13 @@ func crsV1(ctx context.Context, client dynamic.Interface, config *rest.Config, n
}

namespacedName := fmt.Sprintf("%s/%s", crd.Name, ns)
b, err := yaml.Marshal(perNamespace[ns])
b, err := json.Marshal(perNamespace[ns])
if err != nil {
errorList[namespacedName] = err.Error()
continue
}

customResources[fmt.Sprintf("%s.yaml", namespacedName)] = b
customResources[fmt.Sprintf("%s.json", namespacedName)] = b
}
}
}
Expand Down Expand Up @@ -1430,12 +1429,13 @@ func crsV1beta(ctx context.Context, client dynamic.Interface, config *rest.Confi
for _, item := range customResourceList.Items {
objects = append(objects, item.Object)
}
b, err := yaml.Marshal(customResourceList.Items)
b, err := json.Marshal(objects) // TODO: Check if this is the correct way to do this
// b, err := json.Marshal(customResourceList.Items)
if err != nil {
errorList[crd.Name] = err.Error()
continue
}
customResources[fmt.Sprintf("%s.yaml", crd.Name)] = b
customResources[fmt.Sprintf("%s.json", crd.Name)] = b
} else {
// Group fetched resources by the namespace
perNamespace := map[string][]map[string]interface{}{}
Expand Down Expand Up @@ -1464,13 +1464,14 @@ func crsV1beta(ctx context.Context, client dynamic.Interface, config *rest.Confi
}

namespacedName := fmt.Sprintf("%s/%s", crd.Name, ns)
b, err := yaml.Marshal(perNamespace[ns])
b, err := json.Marshal(perNamespace[ns])
if err != nil {
errorList[namespacedName] = err.Error()
continue
}

customResources[fmt.Sprintf("%s.yaml", namespacedName)] = b
// TODO: Store in YAML format to preserve (perhaps broken) backwards compatibility
customResources[fmt.Sprintf("%s.json", namespacedName)] = b
}
}
}
Expand Down

0 comments on commit 19aed1c

Please sign in to comment.