Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #37 from gossion/guwe/csi
Browse files Browse the repository at this point in the history
Add function to get pv,pvc
  • Loading branch information
feiskyer authored Mar 29, 2021
2 parents b3a8c55 + 5010dbe commit d22d879
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
11 changes: 9 additions & 2 deletions internal/commands/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,15 @@ func runRootCommandWithProviderAndClient(ctx context.Context, pInit provider.Ini
secretInformer := scmInformerFactory.Core().V1().Secrets()
configMapInformer := scmInformerFactory.Core().V1().ConfigMaps()
serviceInformer := scmInformerFactory.Core().V1().Services()

rm, err := manager.NewResourceManager(podInformer.Lister(), secretInformer.Lister(), configMapInformer.Lister(), serviceInformer.Lister())
pvcInformer := scmInformerFactory.Core().V1().PersistentVolumeClaims()
pvInformer := scmInformerFactory.Core().V1().PersistentVolumes()

rm, err := manager.NewResourceManager(podInformer.Lister(),
secretInformer.Lister(),
configMapInformer.Lister(),
serviceInformer.Lister(),
pvcInformer.Lister(),
pvInformer.Lister())
if err != nil {
return errors.Wrap(err, "could not create resource manager")
}
Expand Down
21 changes: 20 additions & 1 deletion manager/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,24 @@ type ResourceManager struct {
secretLister corev1listers.SecretLister
configMapLister corev1listers.ConfigMapLister
serviceLister corev1listers.ServiceLister
pvcLister corev1listers.PersistentVolumeClaimLister
pvLister corev1listers.PersistentVolumeLister
}

// NewResourceManager returns a ResourceManager with the internal maps initialized.
func NewResourceManager(podLister corev1listers.PodLister, secretLister corev1listers.SecretLister, configMapLister corev1listers.ConfigMapLister, serviceLister corev1listers.ServiceLister) (*ResourceManager, error) {
func NewResourceManager(podLister corev1listers.PodLister,
secretLister corev1listers.SecretLister,
configMapLister corev1listers.ConfigMapLister,
serviceLister corev1listers.ServiceLister,
pvcLister corev1listers.PersistentVolumeClaimLister,
pvLister corev1listers.PersistentVolumeLister) (*ResourceManager, error) {
rm := ResourceManager{
podLister: podLister,
secretLister: secretLister,
configMapLister: configMapLister,
serviceLister: serviceLister,
pvcLister: pvcLister,
pvLister: pvLister,
}
return &rm, nil
}
Expand Down Expand Up @@ -65,3 +74,13 @@ func (rm *ResourceManager) GetSecret(name, namespace string) (*v1.Secret, error)
func (rm *ResourceManager) ListServices() ([]*v1.Service, error) {
return rm.serviceLister.List(labels.Everything())
}

// GetPersistentVolumeClaim retrieves the specified pvc from Kubernetes
func (rm *ResourceManager) GetPersistentVolumeClaim(name, namespace string) (*v1.PersistentVolumeClaim, error) {
return rm.pvcLister.PersistentVolumeClaims(namespace).Get(name)
}

// GetPersistentVolume retrieves the specified pv from Kubernetes
func (rm *ResourceManager) GetPersistentVolume(name string) (*v1.PersistentVolume, error) {
return rm.pvLister.Get(name)
}

0 comments on commit d22d879

Please sign in to comment.