Skip to content

Commit

Permalink
api: adds status and lastSyncError to scrape objects
Browse files Browse the repository at this point in the history
* adds `status` and `lastSyncError` to `VMServiceScrape`, `VMPodScrape`,
  `VMNodeScrape`, `VMStaticScrape`, `VMProbeScrape` and
`VMScrapeConfig`.  It provides better obersvability for API users.
* adds generic functions for scrape objects secrets fetching. It reduces
  boilerplat and simplifies code.
* adds status track for scrape objects
* unifies tlsAssetLoad and secretValue fetch into single function for
  vmagent config builder. It should improve readibilty.

Signed-off-by: f41gh7 <[email protected]>
  • Loading branch information
f41gh7 committed Aug 15, 2024
1 parent b90472f commit 70dac2a
Show file tree
Hide file tree
Showing 17 changed files with 861 additions and 908 deletions.
10 changes: 10 additions & 0 deletions api/operator/v1beta1/vmextra_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,3 +984,13 @@ type TLSClientConfig struct {
// Certs defines cert, CA and key for TLS auth
Certs `json:",inline"`
}

// ScrapeObjectStatus defines the observed state of ScrapeObjects
type ScrapeObjectStatus struct {
// Status defines update status of resource
Status UpdateStatus `json:"status,omitempty"`
// LastSyncError contains error message for unsuccessful config generation
LastSyncError string `json:"lastSyncError,omitempty"`
// CurrentSyncError holds an error occured during reconcile loop
CurrentSyncError string `json:"-"`
}
13 changes: 9 additions & 4 deletions api/operator/v1beta1/vmnodescrape_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ type VMNodeScrapeSpec struct {
Selector metav1.LabelSelector `json:"selector,omitempty"`
}

// VMNodeScrapeStatus defines the observed state of VMNodeScrape
type VMNodeScrapeStatus struct{}

// VMNodeScrape defines discovery for targets placed on kubernetes nodes,
// usually its node-exporters and other host services.
// InternalIP is used as __address__ for scraping.
// +kubebuilder:object:root=true
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.status"
// +kubebuilder:printcolumn:name="Sync Error",type="string",JSONPath=".status.lastSyncError"
// +genclient
type VMNodeScrape struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VMNodeScrapeSpec `json:"spec,omitempty"`
Status VMNodeScrapeStatus `json:"status,omitempty"`
Status ScrapeObjectStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
Expand All @@ -66,6 +66,11 @@ func (cr VMNodeScrape) AsMapKey() string {
return fmt.Sprintf("nodeScrape/%s/%s", cr.Namespace, cr.Name)
}

// GetStatus returns scrape object status
func (cr *VMNodeScrape) GetStatus() *ScrapeObjectStatus {
return &cr.Status
}

func init() {
SchemeBuilder.Register(&VMNodeScrape{}, &VMNodeScrapeList{})
}
16 changes: 10 additions & 6 deletions api/operator/v1beta1/vmpodscrape_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ type VMPodScrapeSpec struct {
AttachMetadata AttachMetadata `json:"attach_metadata,omitempty"`
}

// VMPodScrapeStatus defines the observed state of VMPodScrape
type VMPodScrapeStatus struct{}

// VMPodScrape is scrape configuration for pods,
// it generates vmagent's config for scraping pod targets
// based on selectors.
Expand All @@ -49,15 +46,17 @@ type VMPodScrapeStatus struct{}
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=vmpodscrapes,scope=Namespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.status"
// +kubebuilder:printcolumn:name="Sync Error",type="string",JSONPath=".status.lastSyncError"
// +genclient
type VMPodScrape struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VMPodScrapeSpec `json:"spec,omitempty"`
// +optional
Status VMPodScrapeStatus `json:"status"`
Spec VMPodScrapeSpec `json:"spec,omitempty"`
Status ScrapeObjectStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -114,6 +113,11 @@ func (cr *VMPodScrape) AsMapKey(i int) string {
return fmt.Sprintf("podScrape/%s/%s/%d", cr.Namespace, cr.Name, i)
}

// GetStatus returns scrape object status
func (cr *VMPodScrape) GetStatus() *ScrapeObjectStatus {
return &cr.Status
}

func init() {
SchemeBuilder.Register(&VMPodScrape{}, &VMPodScrapeList{})
}
15 changes: 10 additions & 5 deletions api/operator/v1beta1/vmprobe_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ type VMProberSpec struct {
Path string `json:"path,omitempty"`
}

// VMProbeStatus defines the observed state of VMProbe
type VMProbeStatus struct{}

// VMProbe defines a probe for targets, that will be executed with prober,
// like blackbox exporter.
// It helps to monitor reachability of target with various checks.
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.status"
// +kubebuilder:printcolumn:name="Sync Error",type="string",JSONPath=".status.lastSyncError"
// +genclient
// +k8s:openapi-gen=true
type VMProbe struct {
Expand All @@ -106,8 +106,8 @@ type VMProbe struct {
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VMProbeSpec `json:"spec"`
Status VMProbeStatus `json:"status,omitempty"`
Spec VMProbeSpec `json:"spec"`
Status ScrapeObjectStatus `json:"status,omitempty"`
}

// VMProbeList contains a list of VMProbe
Expand All @@ -127,6 +127,11 @@ func (cr VMProbe) AsMapKey() string {
return fmt.Sprintf("probeScrape/%s/%s", cr.Namespace, cr.Name)
}

// GetStatus returns scrape object status
func (cr *VMProbe) GetStatus() *ScrapeObjectStatus {
return &cr.Status
}

func init() {
SchemeBuilder.Register(&VMProbe{}, &VMProbeList{})
}
16 changes: 10 additions & 6 deletions api/operator/v1beta1/vmscrapeconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ import (
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=vmscrapeconfigs,scope=Namespaced
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.status"
// +kubebuilder:printcolumn:name="Sync Error",type="string",JSONPath=".status.lastSyncError"
// +genclient
type VMScrapeConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VMScrapeConfigSpec `json:"spec,omitempty"`
// +optional
Status VMScrapeConfigStatus `json:"status"`
Spec VMScrapeConfigSpec `json:"spec,omitempty"`
Status ScrapeObjectStatus `json:"status,omitempty"`
}

// VMScrapeConfigSpec defines the desired state of VMScrapeConfig
Expand Down Expand Up @@ -488,9 +490,6 @@ type DigitalOceanSDConfig struct {
Port *int `json:"port,omitempty"`
}

// VMScrapeConfigStatus defines the observed state of VMScrapeConfig
type VMScrapeConfigStatus struct{}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// VMScrapeConfigList contains a list of VMScrapeConfig
Expand All @@ -510,6 +509,11 @@ func (cr VMScrapeConfig) AsMapKey(prefix string, i int) string {
return fmt.Sprintf("scrapeConfig/%s/%s/%s/%d", cr.Namespace, cr.Name, prefix, i)
}

// GetStatus returns scrape object status
func (cr *VMScrapeConfig) GetStatus() *ScrapeObjectStatus {
return &cr.Status
}

func init() {
SchemeBuilder.Register(&VMScrapeConfig{}, &VMScrapeConfigList{})
}
15 changes: 10 additions & 5 deletions api/operator/v1beta1/vmservicescrape_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ type VMServiceScrapeSpec struct {
AttachMetadata AttachMetadata `json:"attach_metadata,omitempty"`
}

// VMServiceScrapeStatus defines the observed state of VMServiceScrape
type VMServiceScrapeStatus struct{}

// VMServiceScrape is scrape configuration for endpoints associated with
// kubernetes service,
// it generates scrape configuration for vmagent based on selectors.
Expand All @@ -61,13 +58,16 @@ type VMServiceScrapeStatus struct{}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=vmservicescrapes,scope=Namespaced
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.status"
// +kubebuilder:printcolumn:name="Sync Error",type="string",JSONPath=".status.lastSyncError"
// +genclient
type VMServiceScrape struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VMServiceScrapeSpec `json:"spec"`
Status VMServiceScrapeStatus `json:"status,omitempty"`
Spec VMServiceScrapeSpec `json:"spec"`
Status ScrapeObjectStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -140,6 +140,11 @@ func (cr VMServiceScrape) AsMapKey(i int) string {
return fmt.Sprintf("serviceScrape/%s/%s/%d", cr.Namespace, cr.Name, i)
}

// GetStatus returns scrape object status
func (cr *VMServiceScrape) GetStatus() *ScrapeObjectStatus {
return &cr.Status
}

func init() {
SchemeBuilder.Register(&VMServiceScrape{}, &VMServiceScrapeList{})
}
16 changes: 10 additions & 6 deletions api/operator/v1beta1/vmstaticscrape_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,22 @@ type TargetEndpoint struct {
EndpointScrapeParams `json:",inline"`
}

// VMStaticScrapeStatus defines the observed state of VMStaticScrape
type VMStaticScrapeStatus struct{}

// VMStaticScrape defines static targets configuration for scraping.
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.status"
// +kubebuilder:printcolumn:name="Sync Error",type="string",JSONPath=".status.lastSyncError"
// +genclient
type VMStaticScrape struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VMStaticScrapeSpec `json:"spec,omitempty"`
Status VMStaticScrapeStatus `json:"status,omitempty"`
Spec VMStaticScrapeSpec `json:"spec,omitempty"`
Status ScrapeObjectStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// VMStaticScrapeList contains a list of VMStaticScrape
type VMStaticScrapeList struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -68,6 +67,11 @@ func (cr VMStaticScrape) AsMapKey(i int) string {
return fmt.Sprintf("staticScrape/%s/%s/%d", cr.Namespace, cr.Name, i)
}

// GetStatus returns scrape object status
func (cr *VMStaticScrape) GetStatus() *ScrapeObjectStatus {
return &cr.Status
}

func init() {
SchemeBuilder.Register(&VMStaticScrape{}, &VMStaticScrapeList{})
}
Loading

0 comments on commit 70dac2a

Please sign in to comment.