-
Notifications
You must be signed in to change notification settings - Fork 132
/
list_projects_v1alpha1.go
37 lines (32 loc) · 1.15 KB
/
list_projects_v1alpha1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package api
import (
"context"
"connectrpc.com/connect"
"google.golang.org/protobuf/types/known/timestamppb"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"sigs.k8s.io/controller-runtime/pkg/client"
kargoapi "github.com/akuity/kargo/api/v1alpha1"
svcv1alpha1 "github.com/akuity/kargo/pkg/api/service/v1alpha1"
)
func (s *server) ListProjects(
ctx context.Context,
_ *connect.Request[svcv1alpha1.ListProjectsRequest],
) (*connect.Response[svcv1alpha1.ListProjectsResponse], error) {
// Only list namespaces which are labeled as Kargo projects
selector := labels.Set{kargoapi.LabelProjectKey: kargoapi.LabelTrueValue}.AsSelector()
nsList := &corev1.NamespaceList{}
if err := s.client.List(ctx, nsList, client.MatchingLabelsSelector{Selector: selector}); err != nil {
return nil, connect.NewError(connect.CodeInternal, err)
}
projects := make([]*svcv1alpha1.Project, len(nsList.Items))
for i, ns := range nsList.Items {
projects[i] = &svcv1alpha1.Project{
Name: ns.Name,
CreateTime: timestamppb.New(ns.CreationTimestamp.Time),
}
}
return connect.NewResponse(&svcv1alpha1.ListProjectsResponse{
Projects: projects,
}), nil
}