Skip to content

Commit f057d92

Browse files
committed
[cozystack-api] fix type for ApplicationList
Signed-off-by: Andrei Kvapil <[email protected]>
1 parent 9617071 commit f057d92

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

  • pkg/registry/apps/application

‎pkg/registry/apps/application/rest.go‎

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ func (r *REST) List(ctx context.Context, options *metainternalversion.ListOption
271271
klog.Errorf("Invalid field selector: %v", err)
272272
return nil, fmt.Errorf("invalid field selector: %v", err)
273273
}
274-
275274
// Check if selector is for metadata.name
276275
if name, exists := fs.RequiresExactMatch("metadata.name"); exists {
277276
// Convert Application name to HelmRelease name
@@ -321,17 +320,8 @@ func (r *REST) List(ctx context.Context, options *metainternalversion.ListOption
321320
return nil, err
322321
}
323322

324-
// Initialize empty Application list
325-
appList := &appsv1alpha1.ApplicationList{
326-
TypeMeta: metav1.TypeMeta{
327-
APIVersion: "apps.cozystack.io/v1alpha1",
328-
Kind: "ApplicationList",
329-
},
330-
ListMeta: metav1.ListMeta{
331-
ResourceVersion: hrList.GetResourceVersion(),
332-
},
333-
Items: []appsv1alpha1.Application{},
334-
}
323+
// Initialize unstructured items array
324+
items := make([]unstructured.Unstructured, 0)
335325

336326
// Iterate over HelmReleases and convert to Applications
337327
for _, hr := range hrList.Items {
@@ -369,7 +359,6 @@ func (r *REST) List(ctx context.Context, options *metainternalversion.ListOption
369359
klog.Errorf("Invalid field selector: %v", err)
370360
continue
371361
}
372-
373362
fieldsSet := fields.Set{
374363
"metadata.name": app.Name,
375364
"metadata.namespace": app.Namespace,
@@ -379,10 +368,23 @@ func (r *REST) List(ctx context.Context, options *metainternalversion.ListOption
379368
}
380369
}
381370

382-
appList.Items = append(appList.Items, app)
371+
// Convert Application to unstructured
372+
unstructuredApp, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&app)
373+
if err != nil {
374+
klog.Errorf("Error converting Application %s to unstructured: %v", app.Name, err)
375+
continue
376+
}
377+
items = append(items, unstructured.Unstructured{Object: unstructuredApp})
383378
}
384379

385-
klog.V(6).Infof("Successfully listed %d Application resources in namespace %s", len(appList.Items), namespace)
380+
// Explicitly set apiVersion and kind in unstructured object
381+
appList := &unstructured.UnstructuredList{}
382+
appList.SetAPIVersion("apps.cozystack.io/v1alpha1")
383+
appList.SetKind(r.kindName + "List")
384+
appList.SetResourceVersion(hrList.GetResourceVersion())
385+
appList.Items = items
386+
387+
klog.V(6).Infof("Successfully listed %d Application resources in namespace %s", len(items), namespace)
386388
return appList, nil
387389
}
388390

@@ -1036,6 +1038,19 @@ func (r *REST) ConvertToTable(ctx context.Context, object runtime.Object, tableO
10361038
case *appsv1alpha1.Application:
10371039
table = r.buildTableFromApplication(*obj)
10381040
table.ListMeta.ResourceVersion = obj.GetResourceVersion()
1041+
case *unstructured.UnstructuredList:
1042+
apps := make([]appsv1alpha1.Application, 0, len(obj.Items))
1043+
for _, u := range obj.Items {
1044+
var a appsv1alpha1.Application
1045+
err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &a)
1046+
if err != nil {
1047+
klog.Errorf("Failed to convert Unstructured to Application: %v", err)
1048+
continue
1049+
}
1050+
apps = append(apps, a)
1051+
}
1052+
table = r.buildTableFromApplications(apps)
1053+
table.ListMeta.ResourceVersion = obj.GetResourceVersion()
10391054
case *unstructured.Unstructured:
10401055
var app appsv1alpha1.Application
10411056
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), &app)
@@ -1067,7 +1082,6 @@ func (r *REST) ConvertToTable(ctx context.Context, object runtime.Object, tableO
10671082
}
10681083

10691084
klog.V(6).Infof("ConvertToTable: returning table with %d rows", len(table.Rows))
1070-
10711085
return &table, nil
10721086
}
10731087

0 commit comments

Comments
 (0)