@@ -10,29 +10,35 @@ import (
1010 storagev1alpha1 "github.com/ironcore-dev/ironcore/api/storage/v1alpha1"
1111 "github.com/ironcore-dev/ironcore/broker/common"
1212 volumebrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/volumebroker/api/v1alpha1"
13- "github.com/ironcore-dev/ironcore/broker/volumebroker/apiutils"
1413 iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1"
1514 "google.golang.org/grpc/codes"
1615 "google.golang.org/grpc/status"
1716 corev1 "k8s.io/api/core/v1"
1817 apierrors "k8s.io/apimachinery/pkg/api/errors"
19- "k8s.io/apimachinery/pkg/labels"
2018 "sigs.k8s.io/controller-runtime/pkg/client"
2119)
2220
23- func (s * Server ) listManagedAndCreated (ctx context.Context , list client.ObjectList ) error {
24- return s .client .List (ctx , list ,
21+ func (s * Server ) listManagedAndCreated (ctx context.Context , ironcoreVolumeList * storagev1alpha1.VolumeList , filter * iri.VolumeFilter ) error {
22+ matchingLabels := client.MatchingLabels {
23+ volumebrokerv1alpha1 .ManagerLabel : volumebrokerv1alpha1 .VolumeBrokerManager ,
24+ volumebrokerv1alpha1 .CreatedLabel : "true" ,
25+ }
26+
27+ if filter != nil && filter .LabelSelector != nil {
28+ for k := range filter .LabelSelector {
29+ matchingLabels [k ] = filter .LabelSelector [k ]
30+ }
31+ }
32+
33+ return s .client .List (ctx , ironcoreVolumeList ,
2534 client .InNamespace (s .namespace ),
26- client.MatchingLabels {
27- volumebrokerv1alpha1 .ManagerLabel : volumebrokerv1alpha1 .VolumeBrokerManager ,
28- volumebrokerv1alpha1 .CreatedLabel : "true" ,
29- },
35+ matchingLabels ,
3036 )
3137}
3238
33- func (s * Server ) listAggregateIronCoreVolumes (ctx context.Context ) ([]AggregateIronCoreVolume , error ) {
39+ func (s * Server ) listAggregateIronCoreVolumes (ctx context.Context , filter * iri. VolumeFilter ) ([]AggregateIronCoreVolume , error ) {
3440 ironcoreVolumeList := & storagev1alpha1.VolumeList {}
35- if err := s .listManagedAndCreated (ctx , ironcoreVolumeList ); err != nil {
41+ if err := s .listManagedAndCreated (ctx , ironcoreVolumeList , filter ); err != nil {
3642 return nil , fmt .Errorf ("error listing ironcore volumes: %w" , err )
3743 }
3844
@@ -132,21 +138,6 @@ func (s *Server) aggregateIronCoreVolume(
132138 }, nil
133139}
134140
135- func (s * Server ) getIronCoreVolume (ctx context.Context , id string ) (* storagev1alpha1.Volume , error ) {
136- ironcoreVolume := & storagev1alpha1.Volume {}
137- ironcoreVolumeKey := client.ObjectKey {Namespace : s .namespace , Name : id }
138- if err := s .client .Get (ctx , ironcoreVolumeKey , ironcoreVolume ); err != nil {
139- if ! apierrors .IsNotFound (err ) {
140- return nil , fmt .Errorf ("error getting ironcore volume %s: %w" , id , err )
141- }
142- return nil , status .Errorf (codes .NotFound , "volume %s not found" , id )
143- }
144- if ! apiutils .IsManagedBy (ironcoreVolume , volumebrokerv1alpha1 .VolumeBrokerManager ) || ! apiutils .IsCreated (ironcoreVolume ) {
145- return nil , status .Errorf (codes .NotFound , "volume %s not found" , id )
146- }
147- return ironcoreVolume , nil
148- }
149-
150141func (s * Server ) getAggregateIronCoreVolume (ctx context.Context , id string ) (* AggregateIronCoreVolume , error ) {
151142 ironcoreVolume := & storagev1alpha1.Volume {}
152143 if err := s .getManagedAndCreated (ctx , id , ironcoreVolume ); err != nil {
@@ -159,8 +150,8 @@ func (s *Server) getAggregateIronCoreVolume(ctx context.Context, id string) (*Ag
159150 return s .aggregateIronCoreVolume (ironcoreVolume , s .clientGetSecretFunc (ctx ))
160151}
161152
162- func (s * Server ) listVolumes (ctx context.Context ) ([]* iri.Volume , error ) {
163- ironcoreVolumes , err := s .listAggregateIronCoreVolumes (ctx )
153+ func (s * Server ) listVolumes (ctx context.Context , filter * iri. VolumeFilter ) ([]* iri.Volume , error ) {
154+ ironcoreVolumes , err := s .listAggregateIronCoreVolumes (ctx , filter )
164155 if err != nil {
165156 return nil , fmt .Errorf ("error listing volumes: %w" , err )
166157 }
@@ -177,25 +168,6 @@ func (s *Server) listVolumes(ctx context.Context) ([]*iri.Volume, error) {
177168 return res , nil
178169}
179170
180- func (s * Server ) filterVolumes (volumes []* iri.Volume , filter * iri.VolumeFilter ) []* iri.Volume {
181- if filter == nil {
182- return volumes
183- }
184-
185- var (
186- res []* iri.Volume
187- sel = labels .SelectorFromSet (filter .LabelSelector )
188- )
189- for _ , iriVolume := range volumes {
190- if ! sel .Matches (labels .Set (iriVolume .Metadata .Labels )) {
191- continue
192- }
193-
194- res = append (res , iriVolume )
195- }
196- return res
197- }
198-
199171func (s * Server ) getVolume (ctx context.Context , id string ) (* iri.Volume , error ) {
200172 ironcoreVolume , err := s .getAggregateIronCoreVolume (ctx , id )
201173 if err != nil {
@@ -222,13 +194,11 @@ func (s *Server) ListVolumes(ctx context.Context, req *iri.ListVolumesRequest) (
222194 }, nil
223195 }
224196
225- volumes , err := s .listVolumes (ctx )
197+ volumes , err := s .listVolumes (ctx , req . Filter )
226198 if err != nil {
227199 return nil , err
228200 }
229201
230- volumes = s .filterVolumes (volumes , req .Filter )
231-
232202 return & iri.ListVolumesResponse {
233203 Volumes : volumes ,
234204 }, nil
0 commit comments