mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-03-03 18:20:19 +00:00
Compare commits
1 Commits
renovate/g
...
issues/451
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86f28a0202 |
@@ -121,7 +121,7 @@ func (r *Manager) ownerRoleBinding(tenant *capsulev1beta1.Tenant) error {
|
|||||||
newLabels := map[string]string{tl: tenant.Name}
|
newLabels := map[string]string{tl: tenant.Name}
|
||||||
|
|
||||||
for _, owner := range tenant.Spec.Owners {
|
for _, owner := range tenant.Spec.Owners {
|
||||||
if owner.Kind == "ServiceAccount" {
|
if owner.Kind == rbacv1.ServiceAccountKind {
|
||||||
splitName := strings.Split(owner.Name, ":")
|
splitName := strings.Split(owner.Name, ":")
|
||||||
subjects = append(subjects, rbacv1.Subject{
|
subjects = append(subjects, rbacv1.Subject{
|
||||||
Kind: owner.Kind.String(),
|
Kind: owner.Kind.String(),
|
||||||
|
|||||||
42
pkg/indexer/tenant/status.go
Normal file
42
pkg/indexer/tenant/status.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
// Copyright 2020-2021 Clastix Labs
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package tenant
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
|
capsulev1beta1 "github.com/clastix/capsule/api/v1beta1"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ListByStatus(ctx context.Context, clt client.Client, state string) (tenantList *capsulev1beta1.TenantList, err error) {
|
||||||
|
tenantList = &capsulev1beta1.TenantList{}
|
||||||
|
|
||||||
|
if err = clt.List(ctx, tenantList, client.MatchingFieldsSelector{
|
||||||
|
Selector: fields.OneTermEqualSelector(".status.state", state),
|
||||||
|
}); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type State struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o State) Object() client.Object {
|
||||||
|
return &capsulev1beta1.Tenant{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o State) Field() string {
|
||||||
|
return ".status.state"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o State) Func() client.IndexerFunc {
|
||||||
|
return func(object client.Object) []string {
|
||||||
|
return []string{string(object.(*capsulev1beta1.Tenant).Status.State)}
|
||||||
|
}
|
||||||
|
}
|
||||||
43
pkg/metrics/tenant_status.go
Normal file
43
pkg/metrics/tenant_status.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package metrics
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
|
"github.com/clastix/capsule/api/v1beta1"
|
||||||
|
"github.com/clastix/capsule/pkg/indexer/tenant"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewActiveTenantCollector(ctx context.Context, clt client.Client) prometheus.Collector {
|
||||||
|
return prometheus.NewCounterFunc(prometheus.CounterOpts{
|
||||||
|
Namespace: "capsule",
|
||||||
|
Subsystem: "tenant",
|
||||||
|
Name: "active",
|
||||||
|
Help: "sum of active Tenant resources in Active state",
|
||||||
|
}, func() float64 {
|
||||||
|
list, err := tenant.ListByStatus(ctx, clt, string(v1beta1.TenantStateActive))
|
||||||
|
if err != nil {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
return float64(len(list.Items))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCordonedTenantCollector(ctx context.Context, clt client.Client) prometheus.Collector {
|
||||||
|
return prometheus.NewCounterFunc(prometheus.CounterOpts{
|
||||||
|
Namespace: "capsule",
|
||||||
|
Subsystem: "tenant",
|
||||||
|
Name: "cordoned",
|
||||||
|
Help: "sum of Tenant resources in Cordoned state",
|
||||||
|
}, func() float64 {
|
||||||
|
list, err := tenant.ListByStatus(ctx, clt, string(v1beta1.TenantStateCordoned))
|
||||||
|
if err != nil {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
return float64(len(list.Items))
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user