Skip to content

Commit

Permalink
feat: annotation reports-created by reports-server (kyverno#154)
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Choudhary <[email protected]>
Signed-off-by: Zach Stone <[email protected]>
  • Loading branch information
vishal-chdhry authored and stone-z committed Jul 4, 2024
1 parent b52e7d7 commit 9ef0a00
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
14 changes: 14 additions & 0 deletions pkg/api/annotate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package api

const (
ServedByReportsServerAnnotation = "kyverno.reports-server.io/served-by"
ServedByReportsServerValue = "reports-server"
)

func labelReports(obj map[string]string) map[string]string {
if obj == nil {
obj = make(map[string]string)
}
obj[ServedByReportsServerAnnotation] = ServedByReportsServerValue
return obj
}
2 changes: 2 additions & 0 deletions pkg/api/cephr.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func (c *cephrStore) Create(ctx context.Context, obj runtime.Object, createValid
cephr.Name = nameGenerator.GenerateName(cephr.GenerateName)
}

cephr.Annotations = labelReports(cephr.Annotations)
klog.Infof("creating cluster ephemeral reports name=%s", cephr.Name)
if !isDryRun {
r, err := c.createCephr(cephr)
Expand Down Expand Up @@ -186,6 +187,7 @@ func (c *cephrStore) Update(ctx context.Context, name string, objInfo rest.Updat
return nil, false, errors.NewBadRequest("failed to validate cluster ephemeral report")
}

cephr.Annotations = labelReports(cephr.Annotations)
klog.Infof("updating cluster ephemeral reports name=%s", cephr.Name)
if !isDryRun {
r, err := c.updateCephr(cephr, oldObj)
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/cpolr.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func (c *cpolrStore) Create(ctx context.Context, obj runtime.Object, createValid
cpolr.Name = nameGenerator.GenerateName(cpolr.GenerateName)
}

cpolr.Annotations = labelReports(cpolr.Annotations)
klog.Infof("creating cluster policy report name=%s", cpolr.Name)
if !isDryRun {
r, err := c.createCpolr(cpolr)
Expand Down Expand Up @@ -184,7 +185,7 @@ func (c *cpolrStore) Update(ctx context.Context, name string, objInfo rest.Updat
if !ok {
return nil, false, errors.NewBadRequest("failed to validate cluster policy report")
}

cpolr.Annotations = labelReports(cpolr.Annotations)
klog.Infof("updating cluster policy report name=%s", cpolr.Name)
if !isDryRun {
r, err := c.updateCpolr(cpolr, oldObj)
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/ephr.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (p *ephrStore) Create(ctx context.Context, obj runtime.Object, createValida
ephr.Namespace = namespace
}

ephr.Annotations = labelReports(ephr.Annotations)
klog.Infof("creating ephemeral reports name=%s namespace=%s", ephr.Name, ephr.Namespace)
if !isDryRun {
r, err := p.createEphr(ephr)
Expand Down Expand Up @@ -202,6 +203,7 @@ func (p *ephrStore) Update(ctx context.Context, name string, objInfo rest.Update
ephr.Namespace = namespace
}

ephr.Annotations = labelReports(ephr.Annotations)
klog.Infof("updating ephemeral reports name=%s namespace=%s", ephr.Name, ephr.Namespace)
if !isDryRun {
r, err := p.updateEphr(ephr, oldObj)
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/polr.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (p *polrStore) Create(ctx context.Context, obj runtime.Object, createValida
polr.Name = nameGenerator.GenerateName(polr.GenerateName)
}

polr.Annotations = labelReports(polr.Annotations)
klog.Infof("creating policy reports name=%s namespace=%s", polr.Name, polr.Namespace)
if !isDryRun {
r, err := p.createPolr(polr)
Expand Down Expand Up @@ -203,6 +204,7 @@ func (p *polrStore) Update(ctx context.Context, name string, objInfo rest.Update
polr.Namespace = namespace
}

polr.Annotations = labelReports(polr.Annotations)
klog.Infof("updating policy reports name=%s namespace=%s", polr.Name, polr.Namespace)
if !isDryRun {
r, err := p.updatePolr(polr, oldObj)
Expand Down

0 comments on commit 9ef0a00

Please sign in to comment.