Skip to content

Commit

Permalink
Use correc json field names for inv structs
Browse files Browse the repository at this point in the history
  • Loading branch information
foot committed Oct 19, 2023
1 parent abe3975 commit dad5ebe
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions core/server/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ func (cs *coreServer) GetInventory(ctx context.Context, msg *pb.GetInventoryRequ
var inventoryRefs []*unstructured.Unstructured

switch msg.Kind {
case kustomizev1.KustomizationKind:
inventoryRefs, err = cs.getKustomizationInventory(ctx, client, msg.Name, msg.Namespace)
if err != nil {
return nil, fmt.Errorf("failed getting kustomization inventory: %w", err)
}
case helmv2.HelmReleaseKind:
inventoryRefs, err = cs.getHelmReleaseInventory(ctx, client, msg.Name, msg.Namespace)
if err != nil {
return nil, fmt.Errorf("failed getting helm Release inventory: %w", err)
}
// case kustomizev1.KustomizationKind:
// inventoryRefs, err = cs.getKustomizationInventory(ctx, client, msg.Name, msg.Namespace)
// if err != nil {
// return nil, fmt.Errorf("failed getting kustomization inventory: %w", err)
// }
default:
gvk, err := cs.primaryKinds.Lookup(msg.Kind)
if err != nil {
return nil, err
}
inventoryRefs, err = cs.getUnknownInventory(ctx, client, msg.Name, msg.Namespace, *gvk)
inventoryRefs, err = cs.getUnstructedInventory(ctx, client, msg.Name, msg.Namespace, *gvk)
if err != nil {
return nil, fmt.Errorf("failed getting %s inventory: %w", msg.Kind, err)
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func (cs *coreServer) getKustomizationInventory(ctx context.Context, k8sClient c
return objects, nil
}

func (cs *coreServer) getUnknownInventory(ctx context.Context, k8sClient client.Client, name, namespace string, gvk schema.GroupVersionKind) ([]*unstructured.Unstructured, error) {
func (cs *coreServer) getUnstructedInventory(ctx context.Context, k8sClient client.Client, name, namespace string, gvk schema.GroupVersionKind) ([]*unstructured.Unstructured, error) {
// Create an unstructured object with the desired GVK (GroupVersionKind)
obj := &unstructured.Unstructured{}
obj.SetGroupVersionKind(gvk)
Expand Down Expand Up @@ -152,8 +152,8 @@ func (cs *coreServer) getUnknownInventory(ctx context.Context, k8sClient client.
continue
}

id, _, _ := unstructured.NestedString(entry, "ID")
version, _, _ := unstructured.NestedString(entry, "Version")
id, _, _ := unstructured.NestedString(entry, "id")
version, _, _ := unstructured.NestedString(entry, "v")
obj, err := ResourceRefToUnstructured(id, version)
if err != nil {
cs.logger.Error(err, "failed converting inventory entry", "entry", entry)
Expand Down

0 comments on commit dad5ebe

Please sign in to comment.