Skip to content

Commit

Permalink
Generate prom metrics periodically; Handle scanner-opa removal
Browse files Browse the repository at this point in the history
Signed-off-by: Arnob kumar saha <[email protected]>
  • Loading branch information
ArnobKumarSaha committed Oct 2, 2023
1 parent b647e24 commit 35b891f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/graph/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func PollNewResourceTypes(cfg *restclient.Config, pqr *projectquotacontroller.Pr
klog.ErrorS(err, "failed to list server preferred resources")
return false, nil
}
klog.Infof("*********************************************************")
// As we are generating metrics based on these variables, we need to update them timely.
opaInstalled = false
scannerInstalled = false
for _, rsList := range rsLists {
for _, rs := range rsList.APIResources {
// skip sub resource
Expand Down Expand Up @@ -85,6 +89,7 @@ func PollNewResourceTypes(cfg *restclient.Config, pqr *projectquotacontroller.Pr
Kind: rs.Kind,
Scope: scope,
}
updateVarsForMetricsGeneration(rid)
if _, found := resourceTracker[gvk]; !found {
resourceTracker[gvk] = rid
resourceChannel <- rid
Expand Down Expand Up @@ -113,6 +118,16 @@ var (
func OPAInstalled() bool { return opaInstalled }
func ScannerInstalled() bool { return scannerInstalled }

func updateVarsForMetricsGeneration(rid kmapi.ResourceID) {
if rid.Group == "templates.gatekeeper.sh" && rid.Kind == "ConstraintTemplate" {
opaInstalled = true
}
if rid.Group == scannerapi.SchemeGroupVersion.Group && rid.Kind == scannerapi.ResourceKindImageScanRequest {
klog.Infof("*************** set true **********************")
scannerInstalled = true
}
}

func SetupGraphReconciler(mgr manager.Manager) func(ctx context.Context) error {
return func(ctx context.Context) error {
for rid := range resourceChannel {
Expand All @@ -124,13 +139,8 @@ func SetupGraphReconciler(mgr manager.Manager) func(ctx context.Context) error {
return err
}

if rid.Group == "templates.gatekeeper.sh" && rid.Kind == "ConstraintTemplate" {
opaInstalled = true
}

if rid.Group == scannerapi.SchemeGroupVersion.Group &&
rid.Kind == scannerapi.ResourceKindImageScanRequest {
scannerInstalled = true
if err := (&scannercontrollers.WorkloadReconciler{
Client: mgr.GetClient(),
}).SetupWithManager(mgr); err != nil {
Expand Down

0 comments on commit 35b891f

Please sign in to comment.