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

Bug 1862481: Correctly count non-default Marketplace CRs #322

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 3 additions & 8 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,7 @@ func GetRoundTripper() http.RoundTripper {
return roundTripper
}

// RegisterCustomResource increases the count of the custom_resource_total metric
func RegisterCustomResource(resourceType string) {
customResourceGaugeVec.With(prometheus.Labels{ResourceTypeLabel: resourceType}).Inc()
}

// DeregisterCustomResource decreases the count of the custom_resource_total metric
func DeregisterCustomResource(resourceType string) {
customResourceGaugeVec.With(prometheus.Labels{ResourceTypeLabel: resourceType}).Dec()
// RegisterCustomResource sets the count of the custom_resource_total metric to the provided value.
func RegisterCustomResource(resourceType string, count float64) {
customResourceGaugeVec.With(prometheus.Labels{ResourceTypeLabel: resourceType}).Set(count)
}
4 changes: 0 additions & 4 deletions pkg/operatorsource/deleted.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

"github.com/operator-framework/operator-marketplace/pkg/grpccatalog"
"github.com/operator-framework/operator-marketplace/pkg/metrics"

"github.com/operator-framework/operator-marketplace/pkg/apis/operators/shared"
"github.com/operator-framework/operator-marketplace/pkg/apis/operators/v1"
Expand Down Expand Up @@ -65,9 +64,6 @@ func (r *deletedReconciler) Reconcile(ctx context.Context, in *v1.OperatorSource
// Otherwise this phase has been requeued because the garbage collector hasn't
// finished its work yet.
if in.HasFinalizer() {
if !defaults.IsDefaultSource(in.Name) {
metrics.DeregisterCustomResource(metrics.ResourceTypeOpsrc)
}
// Delete the operator source manifests.
r.datastore.RemoveOperatorSource(out.UID)
grpcCatalog := grpccatalog.New(r.logger, nil, r.client)
Expand Down
5 changes: 0 additions & 5 deletions pkg/operatorsource/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"github.com/operator-framework/operator-marketplace/pkg/apis/operators/shared"
"github.com/operator-framework/operator-marketplace/pkg/apis/operators/v1"
"github.com/operator-framework/operator-marketplace/pkg/datastore"
"github.com/operator-framework/operator-marketplace/pkg/defaults"
"github.com/operator-framework/operator-marketplace/pkg/metrics"
"github.com/operator-framework/operator-marketplace/pkg/phase"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -47,9 +45,6 @@ func (r *initialReconciler) Reconcile(ctx context.Context, in *v1.OperatorSource
err = phase.ErrWrongReconcilerInvoked
return
}
if !defaults.IsDefaultSource(in.Name) {
metrics.RegisterCustomResource(metrics.ResourceTypeOpsrc)
}
out = in.DeepCopy()

// When an opsrc is created, make sure the opsrc finalizer is included
Expand Down
15 changes: 9 additions & 6 deletions pkg/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
mktconfig "github.com/operator-framework/operator-marketplace/pkg/apis/config/v1"
v1 "github.com/operator-framework/operator-marketplace/pkg/apis/operators/v1"
"github.com/operator-framework/operator-marketplace/pkg/defaults"
"github.com/operator-framework/operator-marketplace/pkg/metrics"
"github.com/operator-framework/operator-marketplace/pkg/operatorhub"
log "github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -439,25 +440,27 @@ func (NoOpReporter) StartReporting() <-chan struct{} {
// of any non default Opsrc in the cluster to indicate that the cluster is not upgradable
// to future versions.
func CheckOperatorUpgradeablity(kubeClient client.Client) (bool, error) {
clusterHasOpsrc, err := isNonDefaultOpsrcPresent(kubeClient)
count, err := nonDefaultMarketplaceCRCount(kubeClient)
if err != nil {
return false, err
}
if clusterHasOpsrc {
metrics.RegisterCustomResource(metrics.ResourceTypeOpsrc, float64(count))
if count > 0 {
return false, nil
}
return true, nil
}

func isNonDefaultOpsrcPresent(kubeClient client.Client) (bool, error) {
func nonDefaultMarketplaceCRCount(kubeClient client.Client) (int, error) {
opsrcs := &v1.OperatorSourceList{}
nonDefaultOpsrcCount := 0
if err := kubeClient.List(context.TODO(), &client.ListOptions{}, opsrcs); err != nil {
return false, err
return nonDefaultOpsrcCount, err
}
for _, opsrc := range opsrcs.Items {
if !defaults.IsDefaultSource(opsrc.Name) {
return true, nil
nonDefaultOpsrcCount++
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to keep a count at all? Why can't we just have knowledge of if they exist on the cluster?

Copy link
Member Author

@awgreene awgreene Aug 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have a strong preference, but we lose information regarding how many Marketplace CRs exist on cluster by going binary. If you can explain potential benefits, I'll be happy to make the change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think it's beneficial to have a count coz it enhances the UX for an admin.

If it is binary:

  • Sees the alert
  • Deletes an opsrc
  • Sees the alert still exists (but I already deleted a custom resource)

If it is a count:

  • Sees the alert
  • Deletes a CR and sees the count go down
  • Alert tells the admin there's more CRs to be deleted.

}
}
return false, nil
return nonDefaultOpsrcCount, nil
}