Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(refactor): update storage interface #209

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pkg/api/cephr.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
return nil, errorpkg.Wrapf(err, "could not find cluster ephemeral report in store")
}

return val.DeepCopy(), nil
return val, nil

Check warning on line 339 in pkg/api/cephr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/cephr.go#L339

Added line #L339 was not covered by tests
}

func (c *cephrStore) listCephr() (*reportsv1.ClusterEphemeralReportList, error) {
Expand All @@ -346,7 +346,11 @@
}

reportList := &reportsv1.ClusterEphemeralReportList{
Items: valList,
Items: make([]reportsv1.ClusterEphemeralReport, 0, len(valList)),

Check warning on line 349 in pkg/api/cephr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/cephr.go#L349

Added line #L349 was not covered by tests
}

for _, v := range valList {
reportList.Items = append(reportList.Items, *v.DeepCopy())

Check warning on line 353 in pkg/api/cephr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/cephr.go#L352-L353

Added lines #L352 - L353 were not covered by tests
}

klog.Infof("value found of length:%d", len(reportList.Items))
Expand All @@ -358,12 +362,12 @@
report.UID = uuid.NewUUID()
report.CreationTimestamp = metav1.Now()

return report, c.store.ClusterEphemeralReports().Create(context.TODO(), *report)
return report, c.store.ClusterEphemeralReports().Create(context.TODO(), report)

Check warning on line 365 in pkg/api/cephr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/cephr.go#L365

Added line #L365 was not covered by tests
}

func (c *cephrStore) updateCephr(report *reportsv1.ClusterEphemeralReport, _ *reportsv1.ClusterEphemeralReport) (*reportsv1.ClusterEphemeralReport, error) {
report.ResourceVersion = c.store.UseResourceVersion()
return report, c.store.ClusterEphemeralReports().Update(context.TODO(), *report)
return report, c.store.ClusterEphemeralReports().Update(context.TODO(), report)

Check warning on line 370 in pkg/api/cephr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/cephr.go#L370

Added line #L370 was not covered by tests
}

func (c *cephrStore) deleteCephr(report *reportsv1.ClusterEphemeralReport) error {
Expand Down
12 changes: 8 additions & 4 deletions pkg/api/cpolr.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
return nil, errorpkg.Wrapf(err, "could not find cluster policy report in store")
}

return val.DeepCopy(), nil
return val, nil

Check warning on line 338 in pkg/api/cpolr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/cpolr.go#L338

Added line #L338 was not covered by tests
}

func (c *cpolrStore) listCpolr() (*v1alpha2.ClusterPolicyReportList, error) {
Expand All @@ -345,7 +345,11 @@
}

reportList := &v1alpha2.ClusterPolicyReportList{
Items: valList,
Items: make([]v1alpha2.ClusterPolicyReport, 0, len(valList)),

Check warning on line 348 in pkg/api/cpolr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/cpolr.go#L348

Added line #L348 was not covered by tests
}

for _, v := range valList {
reportList.Items = append(reportList.Items, *v.DeepCopy())

Check warning on line 352 in pkg/api/cpolr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/cpolr.go#L351-L352

Added lines #L351 - L352 were not covered by tests
}

klog.Infof("value found of length:%d", len(reportList.Items))
Expand All @@ -357,12 +361,12 @@
report.UID = uuid.NewUUID()
report.CreationTimestamp = metav1.Now()

return report, c.store.ClusterPolicyReports().Create(context.TODO(), *report)
return report, c.store.ClusterPolicyReports().Create(context.TODO(), report)

Check warning on line 364 in pkg/api/cpolr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/cpolr.go#L364

Added line #L364 was not covered by tests
}

func (c *cpolrStore) updateCpolr(report *v1alpha2.ClusterPolicyReport, _ *v1alpha2.ClusterPolicyReport) (*v1alpha2.ClusterPolicyReport, error) {
report.ResourceVersion = c.store.UseResourceVersion()
return report, c.store.ClusterPolicyReports().Update(context.TODO(), *report)
return report, c.store.ClusterPolicyReports().Update(context.TODO(), report)

Check warning on line 369 in pkg/api/cpolr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/cpolr.go#L369

Added line #L369 was not covered by tests
}

func (c *cpolrStore) deleteCpolr(report *v1alpha2.ClusterPolicyReport) error {
Expand Down
12 changes: 8 additions & 4 deletions pkg/api/ephr.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
return nil, errorpkg.Wrapf(err, "could not find ephemeral report in store")
}

return val.DeepCopy(), nil
return val, nil

Check warning on line 359 in pkg/api/ephr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/ephr.go#L359

Added line #L359 was not covered by tests
}

func (p *ephrStore) listEphr(namespace string) (*reportsv1.EphemeralReportList, error) {
Expand All @@ -366,7 +366,11 @@
}

reportList := &reportsv1.EphemeralReportList{
Items: valList,
Items: make([]reportsv1.EphemeralReport, 0, len(valList)),

Check warning on line 369 in pkg/api/ephr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/ephr.go#L369

Added line #L369 was not covered by tests
}

for _, v := range valList {
reportList.Items = append(reportList.Items, *v.DeepCopy())

Check warning on line 373 in pkg/api/ephr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/ephr.go#L372-L373

Added lines #L372 - L373 were not covered by tests
}

klog.Infof("value found of length:%d", len(reportList.Items))
Expand All @@ -378,12 +382,12 @@
report.UID = uuid.NewUUID()
report.CreationTimestamp = metav1.Now()

return report, p.store.EphemeralReports().Create(context.TODO(), *report)
return report, p.store.EphemeralReports().Create(context.TODO(), report)

Check warning on line 385 in pkg/api/ephr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/ephr.go#L385

Added line #L385 was not covered by tests
}

func (p *ephrStore) updateEphr(report *reportsv1.EphemeralReport, _ *reportsv1.EphemeralReport) (*reportsv1.EphemeralReport, error) {
report.ResourceVersion = p.store.UseResourceVersion()
return report, p.store.EphemeralReports().Update(context.TODO(), *report)
return report, p.store.EphemeralReports().Update(context.TODO(), report)

Check warning on line 390 in pkg/api/ephr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/ephr.go#L390

Added line #L390 was not covered by tests
}

func (p *ephrStore) deleteEphr(report *reportsv1.EphemeralReport) error {
Expand Down
12 changes: 8 additions & 4 deletions pkg/api/polr.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
return nil, errorpkg.Wrapf(err, "could not find policy report in store")
}

return val.DeepCopy(), nil
return val, nil

Check warning on line 359 in pkg/api/polr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/polr.go#L359

Added line #L359 was not covered by tests
}

func (p *polrStore) listPolr(namespace string) (*v1alpha2.PolicyReportList, error) {
Expand All @@ -366,7 +366,11 @@
}

reportList := &v1alpha2.PolicyReportList{
Items: valList,
Items: make([]v1alpha2.PolicyReport, 0, len(valList)),

Check warning on line 369 in pkg/api/polr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/polr.go#L369

Added line #L369 was not covered by tests
}

for _, v := range valList {
reportList.Items = append(reportList.Items, *v.DeepCopy())

Check warning on line 373 in pkg/api/polr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/polr.go#L372-L373

Added lines #L372 - L373 were not covered by tests
}

klog.Infof("value found of length:%d", len(reportList.Items))
Expand All @@ -378,12 +382,12 @@
report.UID = uuid.NewUUID()
report.CreationTimestamp = metav1.Now()

return report, p.store.PolicyReports().Create(context.TODO(), *report)
return report, p.store.PolicyReports().Create(context.TODO(), report)

Check warning on line 385 in pkg/api/polr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/polr.go#L385

Added line #L385 was not covered by tests
}

func (p *polrStore) updatePolr(report *v1alpha2.PolicyReport, _ *v1alpha2.PolicyReport) (*v1alpha2.PolicyReport, error) {
report.ResourceVersion = p.store.UseResourceVersion()
return report, p.store.PolicyReports().Update(context.TODO(), *report)
return report, p.store.PolicyReports().Update(context.TODO(), report)

Check warning on line 390 in pkg/api/polr.go

View check run for this annotation

Codecov / codecov/patch

pkg/api/polr.go#L390

Added line #L390 was not covered by tests
}

func (p *polrStore) deletePolr(report *v1alpha2.PolicyReport) error {
Expand Down
24 changes: 12 additions & 12 deletions pkg/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
c.Annotations = make(map[string]string)
}
c.Annotations[api.ServedByReportsServerAnnotation] = api.ServedByReportsServerValue
err := store.ClusterPolicyReports().Create(context.TODO(), c)
err := store.ClusterPolicyReports().Create(context.TODO(), &c)

Check warning on line 121 in pkg/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config.go#L121

Added line #L121 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -150,7 +150,7 @@
cpolr.Annotations = make(map[string]string)
}
cpolr.Annotations[api.ServedByReportsServerAnnotation] = api.ServedByReportsServerValue
err := store.ClusterPolicyReports().Create(context.TODO(), *cpolr)
err := store.ClusterPolicyReports().Create(context.TODO(), cpolr)

Check warning on line 153 in pkg/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config.go#L153

Added line #L153 was not covered by tests
if err != nil {
klog.Error(err)
}
Expand All @@ -164,7 +164,7 @@
cpolr.Annotations = make(map[string]string)
}
cpolr.Annotations[api.ServedByReportsServerAnnotation] = api.ServedByReportsServerValue
err := store.ClusterPolicyReports().Update(context.TODO(), *cpolr)
err := store.ClusterPolicyReports().Update(context.TODO(), cpolr)

Check warning on line 167 in pkg/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config.go#L167

Added line #L167 was not covered by tests
if err != nil {
klog.Error(err)
}
Expand Down Expand Up @@ -199,7 +199,7 @@
c.Annotations = make(map[string]string)
}
c.Annotations[api.ServedByReportsServerAnnotation] = api.ServedByReportsServerValue
err := store.PolicyReports().Create(context.TODO(), c)
err := store.PolicyReports().Create(context.TODO(), &c)

Check warning on line 202 in pkg/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config.go#L202

Added line #L202 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -231,7 +231,7 @@
polr.Annotations = make(map[string]string)
}
polr.Annotations[api.ServedByReportsServerAnnotation] = api.ServedByReportsServerValue
err := store.PolicyReports().Create(context.TODO(), *polr)
err := store.PolicyReports().Create(context.TODO(), polr)

Check warning on line 234 in pkg/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config.go#L234

Added line #L234 was not covered by tests
if err != nil {
klog.Error(err)
}
Expand All @@ -245,7 +245,7 @@
polr.Annotations = make(map[string]string)
}
polr.Annotations[api.ServedByReportsServerAnnotation] = api.ServedByReportsServerValue
err := store.PolicyReports().Update(context.TODO(), *polr)
err := store.PolicyReports().Update(context.TODO(), polr)

Check warning on line 248 in pkg/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config.go#L248

Added line #L248 was not covered by tests
if err != nil {
klog.Error(err)
}
Expand Down Expand Up @@ -280,7 +280,7 @@
c.Annotations = make(map[string]string)
}
c.Annotations[api.ServedByReportsServerAnnotation] = api.ServedByReportsServerValue
err := store.ClusterEphemeralReports().Create(context.TODO(), c)
err := store.ClusterEphemeralReports().Create(context.TODO(), &c)

Check warning on line 283 in pkg/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config.go#L283

Added line #L283 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -311,7 +311,7 @@
cephr.Annotations = make(map[string]string)
}
cephr.Annotations[api.ServedByReportsServerAnnotation] = api.ServedByReportsServerValue
err := store.ClusterEphemeralReports().Create(context.TODO(), *cephr)
err := store.ClusterEphemeralReports().Create(context.TODO(), cephr)

Check warning on line 314 in pkg/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config.go#L314

Added line #L314 was not covered by tests
if err != nil {
klog.Error(err)
}
Expand All @@ -325,7 +325,7 @@
cephr.Annotations = make(map[string]string)
}
cephr.Annotations[api.ServedByReportsServerAnnotation] = api.ServedByReportsServerValue
err := store.ClusterEphemeralReports().Update(context.TODO(), *cephr)
err := store.ClusterEphemeralReports().Update(context.TODO(), cephr)

Check warning on line 328 in pkg/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config.go#L328

Added line #L328 was not covered by tests
if err != nil {
klog.Error(err)
}
Expand Down Expand Up @@ -359,7 +359,7 @@
c.Annotations = make(map[string]string)
}
c.Annotations[api.ServedByReportsServerAnnotation] = api.ServedByReportsServerValue
err := store.EphemeralReports().Create(context.TODO(), c)
err := store.EphemeralReports().Create(context.TODO(), &c)

Check warning on line 362 in pkg/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config.go#L362

Added line #L362 was not covered by tests
if err != nil {
return err
}
Expand Down Expand Up @@ -390,7 +390,7 @@
ephr.Annotations = make(map[string]string)
}
ephr.Annotations[api.ServedByReportsServerAnnotation] = api.ServedByReportsServerValue
err := store.EphemeralReports().Create(context.TODO(), *ephr)
err := store.EphemeralReports().Create(context.TODO(), ephr)

Check warning on line 393 in pkg/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config.go#L393

Added line #L393 was not covered by tests
if err != nil {
klog.Error(err)
}
Expand All @@ -404,7 +404,7 @@
ephr.Annotations = make(map[string]string)
}
ephr.Annotations[api.ServedByReportsServerAnnotation] = api.ServedByReportsServerValue
err := store.EphemeralReports().Update(context.TODO(), *ephr)
err := store.EphemeralReports().Update(context.TODO(), ephr)

Check warning on line 407 in pkg/server/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/config.go#L407

Added line #L407 was not covered by tests
if err != nil {
klog.Error(err)
}
Expand Down
32 changes: 16 additions & 16 deletions pkg/storage/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ type Storage interface {
}

type PolicyReportsInterface interface {
Get(ctx context.Context, name, namespace string) (v1alpha2.PolicyReport, error)
List(ctx context.Context, namespace string) ([]v1alpha2.PolicyReport, error)
Create(ctx context.Context, polr v1alpha2.PolicyReport) error
Update(ctx context.Context, polr v1alpha2.PolicyReport) error
Get(ctx context.Context, name, namespace string) (*v1alpha2.PolicyReport, error)
List(ctx context.Context, namespace string) ([]*v1alpha2.PolicyReport, error)
Create(ctx context.Context, polr *v1alpha2.PolicyReport) error
Update(ctx context.Context, polr *v1alpha2.PolicyReport) error
Delete(ctx context.Context, name, namespace string) error
}

type ClusterPolicyReportsInterface interface {
Get(ctx context.Context, name string) (v1alpha2.ClusterPolicyReport, error)
List(ctx context.Context) ([]v1alpha2.ClusterPolicyReport, error)
Create(ctx context.Context, cpolr v1alpha2.ClusterPolicyReport) error
Update(ctx context.Context, cpolr v1alpha2.ClusterPolicyReport) error
Get(ctx context.Context, name string) (*v1alpha2.ClusterPolicyReport, error)
List(ctx context.Context) ([]*v1alpha2.ClusterPolicyReport, error)
Create(ctx context.Context, cpolr *v1alpha2.ClusterPolicyReport) error
Update(ctx context.Context, cpolr *v1alpha2.ClusterPolicyReport) error
Delete(ctx context.Context, name string) error
}

type EphemeralReportsInterface interface {
Get(ctx context.Context, name, namespace string) (reportsv1.EphemeralReport, error)
List(ctx context.Context, namespace string) ([]reportsv1.EphemeralReport, error)
Create(ctx context.Context, polr reportsv1.EphemeralReport) error
Update(ctx context.Context, polr reportsv1.EphemeralReport) error
Get(ctx context.Context, name, namespace string) (*reportsv1.EphemeralReport, error)
List(ctx context.Context, namespace string) ([]*reportsv1.EphemeralReport, error)
Create(ctx context.Context, polr *reportsv1.EphemeralReport) error
Update(ctx context.Context, polr *reportsv1.EphemeralReport) error
Delete(ctx context.Context, name, namespace string) error
}

type ClusterEphemeralReportsInterface interface {
Get(ctx context.Context, name string) (reportsv1.ClusterEphemeralReport, error)
List(ctx context.Context) ([]reportsv1.ClusterEphemeralReport, error)
Create(ctx context.Context, cephr reportsv1.ClusterEphemeralReport) error
Update(ctx context.Context, cephr reportsv1.ClusterEphemeralReport) error
Get(ctx context.Context, name string) (*reportsv1.ClusterEphemeralReport, error)
List(ctx context.Context) ([]*reportsv1.ClusterEphemeralReport, error)
Create(ctx context.Context, cephr *reportsv1.ClusterEphemeralReport) error
Update(ctx context.Context, cephr *reportsv1.ClusterEphemeralReport) error
Delete(ctx context.Context, name string) error
}

Expand Down
Loading
Loading