Skip to content

Commit

Permalink
Merge pull request #11 from stoneshi-yunify/main
Browse files Browse the repository at this point in the history
expose interface
  • Loading branch information
stoneshi-yunify authored May 14, 2024
2 parents a8d574d + 5baff02 commit a5dd9a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions webhook/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,18 @@ var reviewResponse = &admissionv1.AdmissionResponse{
Result: &metav1.Status{},
}

type PVCAdmitter interface {
AdmitPVC(ar admissionv1.AdmissionReview) *admissionv1.AdmissionResponse
DecidePVC(ctx context.Context, pvc ReqInfo) *admissionv1.AdmissionResponse
}

type Admitter struct {
client client.Client
}

func NewAdmitter() (*Admitter, error) {
var _ PVCAdmitter = (*Admitter)(nil)

func newAdmitter() (*Admitter, error) {
cfg, err := config.GetConfig()
if err != nil {
return nil, err
Expand All @@ -47,7 +54,7 @@ func NewAdmitter() (*Admitter, error) {
return a, nil
}

func NewAdmitterWithClient(client client.Client) *Admitter {
func NewAdmitterWithClient(client client.Client) PVCAdmitter {
return &Admitter{
client: client,
}
Expand Down Expand Up @@ -87,10 +94,10 @@ func (a *Admitter) AdmitPVC(ar admissionv1.AdmissionReview) *admissionv1.Admissi
}

klog.Infof("request pvc: %v", reqPVC)
return a.decidePVCV1(context.Background(), reqPVC)
return a.DecidePVC(context.Background(), reqPVC)
}

func (a *Admitter) decidePVCV1(ctx context.Context, pvc ReqInfo) *admissionv1.AdmissionResponse {
func (a *Admitter) DecidePVC(ctx context.Context, pvc ReqInfo) *admissionv1.AdmissionResponse {
accessors, err := a.getAccessors(ctx, pvc.storageClassName)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion webhook/weebhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func main(cmd *cobra.Command, args []string) {
GetCertificate: cw.GetCertificate,
}

admitter, err := NewAdmitter()
admitter, err := newAdmitter()
if err != nil {
klog.Fatalf("failed to initialize new admitter: %v", err)
}
Expand Down

0 comments on commit a5dd9a9

Please sign in to comment.