Skip to content

Commit

Permalink
fix: vertical view for secrets and filter credentials by label (#3392)
Browse files Browse the repository at this point in the history
Signed-off-by: Mayursinh Sarvaiya <marvinduff97@gmail.com>
  • Loading branch information
Marvin9 authored Jan 30, 2025
1 parent 68fa8e2 commit 0a0f08a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
23 changes: 22 additions & 1 deletion internal/api/list_credentials_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"connectrpc.com/connect"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"sigs.k8s.io/controller-runtime/pkg/client"

kargoapi "github.com/akuity/kargo/api/v1alpha1"
Expand All @@ -32,12 +34,31 @@ func (s *server) ListCredentials(
return nil, err
}

credsLabelSelector := labels.NewSelector()

credsLabelSelectorRequirement, err := labels.NewRequirement(
kargoapi.CredentialTypeLabelKey,
selection.In,
[]string{
kargoapi.CredentialTypeLabelValueGit,
kargoapi.CredentialTypeLabelValueHelm,
kargoapi.CredentialTypeLabelValueImage,
})

if err != nil {
return nil, err
}

credsLabelSelector = credsLabelSelector.Add(*credsLabelSelectorRequirement)

var secretsList corev1.SecretList
if err := s.client.List(
ctx,
&secretsList,
client.InNamespace(req.Msg.GetProject()),
client.HasLabels{kargoapi.CredentialTypeLabelKey},
&client.ListOptions{
LabelSelector: credsLabelSelector,
},
); err != nil {
return nil, fmt.Errorf("list secrets: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions ui/src/features/project/credentials/credentials-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const CredentialsList = () => {

return (
<div className='p-4'>
<Flex gap={16}>
<Flex gap={16} vertical>
<Card
title={
<Flex align='center'>
Expand All @@ -73,14 +73,14 @@ export const CredentialsList = () => {
</Button>
</Flex>
}
className='w-1/2'
>
<Table
scroll={{ x: 'max-content' }}
key={specificCredentials.length}
dataSource={specificCredentials}
rowKey={(record: Secret) => record?.metadata?.name || ''}
loading={listCredentialsQuery.isLoading}
pagination={{ defaultPageSize: 5 }}
columns={[
{
title: 'Name',
Expand Down Expand Up @@ -208,7 +208,6 @@ export const CredentialsList = () => {
</Button>
</Flex>
}
className='w-1/2'
>
<Table
scroll={{ x: 'max-content' }}
Expand Down

0 comments on commit 0a0f08a

Please sign in to comment.