Skip to content

Commit 2102ece

Browse files
add operator_bad_objects_count metric for vmauth and vmagent, additionally unified it
1 parent b3218a6 commit 2102ece

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+878
-1092
lines changed

api/operator/v1beta1/vmalertmanagerconfig_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,8 @@ func (hc *HTTPConfig) validate() error {
12561256
return nil
12571257
}
12581258

1259-
func (r *VMAlertmanagerConfig) AsKey() string {
1259+
// AsKey returns unique key for object
1260+
func (r *VMAlertmanagerConfig) AsKey(_ bool) string {
12601261
return fmt.Sprintf("%s/%s", r.Namespace, r.Name)
12611262
}
12621263

api/operator/v1beta1/vmnodescrape_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ func (cr *VMNodeScrape) GetStatusMetadata() *StatusMetadata {
8787
return &cr.Status.StatusMetadata
8888
}
8989

90+
// AsKey returns unique key for object
91+
func (cr *VMNodeScrape) AsKey(_ bool) string {
92+
return cr.Namespace + "/" + cr.Name
93+
}
94+
9095
func init() {
9196
SchemeBuilder.Register(&VMNodeScrape{}, &VMNodeScrapeList{})
9297
}

api/operator/v1beta1/vmpodscrape_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ func (cr *VMPodScrape) Validate() error {
142142
return nil
143143
}
144144

145+
// AsKey returns unique key for object
146+
func (cr *VMPodScrape) AsKey(_ bool) string {
147+
return cr.Namespace + "/" + cr.Name
148+
}
149+
145150
// GetStatusMetadata implements reconcile.objectWithStatus interface
146151
func (cr *VMPodScrape) GetStatusMetadata() *StatusMetadata {
147152
return &cr.Status.StatusMetadata

api/operator/v1beta1/vmprobe_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ func (cr *VMProbe) GetStatusMetadata() *StatusMetadata {
141141
return &cr.Status.StatusMetadata
142142
}
143143

144+
// AsKey returns unique key for object
145+
func (cr *VMProbe) AsKey(_ bool) string {
146+
return cr.Namespace + "/" + cr.Name
147+
}
148+
144149
// Validate returns error if CR is invalid
145150
func (cr *VMProbe) Validate() error {
146151
if MustSkipCRValidation(cr) {

api/operator/v1beta1/vmrule_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ func (cr *VMRule) GetStatusMetadata() *StatusMetadata {
144144
return &cr.Status.StatusMetadata
145145
}
146146

147+
// AsKey returns unique key for object
148+
func (cr *VMRule) AsKey(_ bool) string {
149+
return fmt.Sprintf("%s-%s.yaml", cr.Namespace, cr.Name)
150+
}
151+
147152
// Validate performs semantic validation of object
148153
func (cr *VMRule) Validate() error {
149154
if MustSkipCRValidation(cr) {

api/operator/v1beta1/vmscrapeconfig_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,11 @@ func (cr *VMScrapeConfig) Validate() error {
530530
return cr.Spec.validate()
531531
}
532532

533+
// AsKey returns unique key for object
534+
func (cr *VMScrapeConfig) AsKey(_ bool) string {
535+
return cr.Namespace + "/" + cr.Name
536+
}
537+
533538
// GetStatusMetadata implements reconcile.objectWithStatus interface
534539
func (cr *VMScrapeConfig) GetStatusMetadata() *StatusMetadata {
535540
return &cr.Status.StatusMetadata

api/operator/v1beta1/vmservicescrape_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ func (cr *VMServiceScrape) Validate() error {
164164
return nil
165165
}
166166

167+
// AsKey returns unique key for object
168+
func (cr *VMServiceScrape) AsKey(_ bool) string {
169+
return cr.Namespace + "/" + cr.Name
170+
}
171+
167172
// GetStatusMetadata implements reconcile.objectWithStatus interface
168173
func (cr *VMServiceScrape) GetStatusMetadata() *StatusMetadata {
169174
return &cr.Status.StatusMetadata

api/operator/v1beta1/vmstaticscrape_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ func (cr *VMStaticScrape) GetStatusMetadata() *StatusMetadata {
9393
return &cr.Status.StatusMetadata
9494
}
9595

96+
// AsKey returns unique key for object
97+
func (cr *VMStaticScrape) AsKey(_ bool) string {
98+
return cr.Namespace + "/" + cr.Name
99+
}
100+
96101
func init() {
97102
SchemeBuilder.Register(&VMStaticScrape{}, &VMStaticScrapeList{})
98103
}

api/operator/v1beta1/vmuser_types.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1beta1
22

33
import (
44
"fmt"
5+
"strings"
56

67
corev1 "k8s.io/api/core/v1"
78
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -15,10 +16,10 @@ type VMUserSpec struct {
1516
// Name of the VMUser object.
1617
// +optional
1718
Name *string `json:"name,omitempty"`
18-
// UserName basic auth user name for accessing protected endpoint,
19+
// Username basic auth user name for accessing protected endpoint,
1920
// will be replaced with metadata.name of VMUser if omitted.
2021
// +optional
21-
UserName *string `json:"username,omitempty"`
22+
Username *string `json:"username,omitempty"`
2223
// Password basic auth password for accessing protected endpoint.
2324
// +optional
2425
Password *string `json:"password,omitempty"`
@@ -119,6 +120,7 @@ func (cr *CRDRef) AddRefToObj(obj client.Object) client.Object {
119120
return obj
120121
}
121122

123+
// AsKey returns unique key for object
122124
func (cr *CRDRef) AsKey() string {
123125
return fmt.Sprintf("%s/%s/%s", cr.Kind, cr.Namespace, cr.Name)
124126
}
@@ -232,11 +234,37 @@ func (cr *VMUser) GetStatusMetadata() *StatusMetadata {
232234
return &cr.Status.StatusMetadata
233235
}
234236

237+
func (cr *VMUser) AsKey(hide bool) string {
238+
var id string
239+
if cr.Spec.Username != nil {
240+
v := *cr.Spec.Username
241+
if hide {
242+
v = strings.Repeat("*", 5)
243+
}
244+
id = "basicAuth:" + v
245+
}
246+
if cr.Spec.Password != nil {
247+
v := *cr.Spec.Password
248+
if hide {
249+
v = strings.Repeat("*", 5)
250+
}
251+
return id + ":" + v
252+
}
253+
if cr.Spec.BearerToken != nil {
254+
v := *cr.Spec.BearerToken
255+
if hide {
256+
v = strings.Repeat("*", 5)
257+
}
258+
return "bearerToken:" + v
259+
}
260+
return id
261+
}
262+
235263
func (cr *VMUser) Validate() error {
236264
if MustSkipCRValidation(cr) {
237265
return nil
238266
}
239-
if cr.Spec.UserName != nil && cr.Spec.BearerToken != nil {
267+
if cr.Spec.Username != nil && cr.Spec.BearerToken != nil {
240268
return fmt.Errorf("one of spec.username and spec.bearerToken must be defined for user, got both")
241269
}
242270
if cr.Spec.PasswordRef != nil && cr.Spec.Password != nil {

api/operator/v1beta1/vmuser_types_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ func TestVMUser_Validate(t *testing.T) {
1818
// invalid auths
1919
f(&VMUser{
2020
Spec: VMUserSpec{
21-
UserName: ptr.To("user"),
21+
Username: ptr.To("user"),
2222
BearerToken: ptr.To("bearer"),
2323
},
2424
}, true)
2525

2626
// invalid ref
2727
f(&VMUser{
2828
Spec: VMUserSpec{
29-
UserName: ptr.To("some-user"),
29+
Username: ptr.To("some-user"),
3030
TargetRefs: []TargetRef{
3131
{
3232
CRD: &CRDRef{Name: "sm"},
@@ -39,7 +39,7 @@ func TestVMUser_Validate(t *testing.T) {
3939
// invalid ref wo targets
4040
f(&VMUser{
4141
Spec: VMUserSpec{
42-
UserName: ptr.To("some-user"),
42+
Username: ptr.To("some-user"),
4343
TargetRefs: []TargetRef{
4444
{
4545
Paths: []string{"/some-path"},
@@ -51,7 +51,7 @@ func TestVMUser_Validate(t *testing.T) {
5151
// invalid ref crd, bad empty ns
5252
f(&VMUser{
5353
Spec: VMUserSpec{
54-
UserName: ptr.To("some-user"),
54+
Username: ptr.To("some-user"),
5555
TargetRefs: []TargetRef{
5656
{
5757
CRD: &CRDRef{
@@ -68,7 +68,7 @@ func TestVMUser_Validate(t *testing.T) {
6868
// incorrect password
6969
f(&VMUser{
7070
Spec: VMUserSpec{
71-
UserName: ptr.To("some-user"),
71+
Username: ptr.To("some-user"),
7272
Password: ptr.To("some-password"),
7373
PasswordRef: &corev1.SecretKeySelector{
7474
Key: "some-key",

0 commit comments

Comments
 (0)