Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions api/operator/v1beta1/common_scrapeparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (

// AttachMetadata configures metadata attachment
type AttachMetadata struct {
// Node instructs vmagent to add node specific metadata from service discovery
// Node instructs vmagent or vmsingle to add node specific metadata from service discovery
// Valid for roles: pod, endpoints, endpointslice.
// +optional
Node *bool `json:"node,omitempty"`

// Namespace instructs vmagent to add namespace specific metadata from service discovery
// Namespace instructs vmagent or vmsingle to add namespace specific metadata from service discovery
// Valid for roles: pod, service, endpoints, endpointslice, ingress.
Namespace *bool `json:"namespace,omitempty"`
}
Expand Down Expand Up @@ -52,7 +52,7 @@ type VMScrapeParams struct {
// must be in of semicolon separated header with it's value
// eg:
// headerName: headerValue
// vmagent supports since 1.79.0 version
// vmagent and vmsingle support since 1.79.0 version
// +optional
Headers []string `json:"headers,omitempty"`
}
Expand Down Expand Up @@ -283,7 +283,7 @@ type EndpointScrapeParams struct {
// HonorLabels chooses the metric's labels on collisions with target labels.
// +optional
HonorLabels bool `json:"honorLabels,omitempty"`
// HonorTimestamps controls whether vmagent respects the timestamps present in scraped data.
// HonorTimestamps controls whether vmagent or vmsingle respects the timestamps present in scraped data.
// +optional
HonorTimestamps *bool `json:"honorTimestamps,omitempty"`
// MaxScrapeSize defines a maximum size of scraped data for a job
Expand Down Expand Up @@ -360,7 +360,7 @@ type CommonScrapeSecurityEnforcements struct {
EnforcedNamespaceLabel string `json:"enforcedNamespaceLabel,omitempty"`
// ArbitraryFSAccessThroughSMs configures whether configuration
// based on EndpointAuth can access arbitrary files on the file system
// of the VMAgent container e.g. bearer token files, basic auth, tls certs
// of the VMAgent or VMSingle container e.g. bearer token files, basic auth, tls certs
// +optional
ArbitraryFSAccessThroughSMs ArbitraryFSAccessThroughSMsConfig `json:"arbitraryFSAccessThroughSMs,omitempty"`
}
Expand Down Expand Up @@ -391,70 +391,70 @@ type CommonScrapeParams struct {
SelectAllByDefault bool `json:"selectAllByDefault,omitempty"`
// ServiceScrapeSelector defines ServiceScrapes to be selected for target discovery.
// Works in combination with NamespaceSelector.
// NamespaceSelector nil - only objects at VMAgent namespace.
// NamespaceSelector nil - only objects at VMAgent or VMSingle namespace.
// Selector nil - only objects at NamespaceSelector namespaces.
// If both nil - behaviour controlled by selectAllByDefault
// +optional
ServiceScrapeSelector *metav1.LabelSelector `json:"serviceScrapeSelector,omitempty"`
// ServiceScrapeNamespaceSelector Namespaces to be selected for VMServiceScrape discovery.
// Works in combination with Selector.
// NamespaceSelector nil - only objects at VMAgent namespace.
// NamespaceSelector nil - only objects at VMAgent or VMSingle namespace.
// Selector nil - only objects at NamespaceSelector namespaces.
// If both nil - behaviour controlled by selectAllByDefault
// +optional
ServiceScrapeNamespaceSelector *metav1.LabelSelector `json:"serviceScrapeNamespaceSelector,omitempty"`
// PodScrapeSelector defines PodScrapes to be selected for target discovery.
// Works in combination with NamespaceSelector.
// NamespaceSelector nil - only objects at VMAgent namespace.
// NamespaceSelector nil - only objects at VMAgent or VMSingle namespace.
// Selector nil - only objects at NamespaceSelector namespaces.
// If both nil - behaviour controlled by selectAllByDefault
// +optional
PodScrapeSelector *metav1.LabelSelector `json:"podScrapeSelector,omitempty"`
// PodScrapeNamespaceSelector defines Namespaces to be selected for VMPodScrape discovery.
// Works in combination with Selector.
// NamespaceSelector nil - only objects at VMAgent namespace.
// NamespaceSelector nil - only objects at VMAgent or VMSingle namespace.
// Selector nil - only objects at NamespaceSelector namespaces.
// If both nil - behaviour controlled by selectAllByDefault
// +optional
PodScrapeNamespaceSelector *metav1.LabelSelector `json:"podScrapeNamespaceSelector,omitempty"`
// ProbeSelector defines VMProbe to be selected for target probing.
// Works in combination with NamespaceSelector.
// NamespaceSelector nil - only objects at VMAgent namespace.
// NamespaceSelector nil - only objects at VMAgent or VMSingle namespace.
// Selector nil - only objects at NamespaceSelector namespaces.
// If both nil - behaviour controlled by selectAllByDefault
// +optional
ProbeSelector *metav1.LabelSelector `json:"probeSelector,omitempty"`
// ProbeNamespaceSelector defines Namespaces to be selected for VMProbe discovery.
// Works in combination with Selector.
// NamespaceSelector nil - only objects at VMAgent namespace.
// NamespaceSelector nil - only objects at VMAgent or VMSingle namespace.
// Selector nil - only objects at NamespaceSelector namespaces.
// If both nil - behaviour controlled by selectAllByDefault
// +optional
ProbeNamespaceSelector *metav1.LabelSelector `json:"probeNamespaceSelector,omitempty"`
// NodeScrapeSelector defines VMNodeScrape to be selected for scraping.
// Works in combination with NamespaceSelector.
// NamespaceSelector nil - only objects at VMAgent namespace.
// NamespaceSelector nil - only objects at VMAgent or VMSingle namespace.
// Selector nil - only objects at NamespaceSelector namespaces.
// If both nil - behaviour controlled by selectAllByDefault
// +optional
NodeScrapeSelector *metav1.LabelSelector `json:"nodeScrapeSelector,omitempty"`
// NodeScrapeNamespaceSelector defines Namespaces to be selected for VMNodeScrape discovery.
// Works in combination with Selector.
// NamespaceSelector nil - only objects at VMAgent namespace.
// NamespaceSelector nil - only objects at VMAgent or VMSingle namespace.
// Selector nil - only objects at NamespaceSelector namespaces.
// If both nil - behaviour controlled by selectAllByDefault
// +optional
NodeScrapeNamespaceSelector *metav1.LabelSelector `json:"nodeScrapeNamespaceSelector,omitempty"`
// StaticScrapeSelector defines VMStaticScrape to be selected for target discovery.
// Works in combination with NamespaceSelector.
// If both nil - match everything.
// NamespaceSelector nil - only objects at VMAgent namespace.
// NamespaceSelector nil - only objects at VMAgent or VMSingle namespace.
// Selector nil - only objects at NamespaceSelector namespaces.
// +optional
StaticScrapeSelector *metav1.LabelSelector `json:"staticScrapeSelector,omitempty"`
// StaticScrapeNamespaceSelector defines Namespaces to be selected for VMStaticScrape discovery.
// Works in combination with NamespaceSelector.
// NamespaceSelector nil - only objects at VMAgent namespace.
// NamespaceSelector nil - only objects at VMAgent or VMSingle namespace.
// Selector nil - only objects at NamespaceSelector namespaces.
// If both nil - behaviour controlled by selectAllByDefault
// +optional
Expand All @@ -465,16 +465,16 @@ type CommonScrapeParams struct {
ScrapeConfigSelector *metav1.LabelSelector `json:"scrapeConfigSelector,omitempty"`
// ScrapeConfigNamespaceSelector defines Namespaces to be selected for VMScrapeConfig discovery.
// Works in combination with Selector.
// NamespaceSelector nil - only objects at VMAgent namespace.
// NamespaceSelector nil - only objects at VMAgent or VMSingle namespace.
// Selector nil - only objects at NamespaceSelector namespaces.
// If both nil - behaviour controlled by selectAllByDefault
// +optional
ScrapeConfigNamespaceSelector *metav1.LabelSelector `json:"scrapeConfigNamespaceSelector,omitempty"`
// InlineScrapeConfig As scrape configs are appended, the user is responsible to make sure it
// is valid. Note that using this feature may expose the possibility to
// break upgrades of VMAgent. It is advised to review VMAgent release
// break upgrades of VMAgent or VMSingle. It is advised to review VMAgent or VMSingle release
// notes to ensure that no incompatible scrape configs are going to break
// VMAgent after the upgrade.
// VMAgent or VMSingle after the upgrade.
// it should be defined as single yaml file.
// inlineScrapeConfig: |
// - job_name: "prometheus"
Expand All @@ -484,9 +484,9 @@ type CommonScrapeParams struct {
InlineScrapeConfig string `json:"inlineScrapeConfig,omitempty"`
// AdditionalScrapeConfigs As scrape configs are appended, the user is responsible to make sure it
// is valid. Note that using this feature may expose the possibility to
// break upgrades of VMAgent. It is advised to review VMAgent release
// break upgrades of VMAgent or VMSingle. It is advised to review VMAgent or VMSingle release
// notes to ensure that no incompatible scrape configs are going to break
// VMAgent after the upgrade.
// VMAgent or VMSingle after the upgrade.
// +optional
AdditionalScrapeConfigs *corev1.SecretKeySelector `json:"additionalScrapeConfigs,omitempty"`
// ServiceScrapeRelabelTemplate defines relabel config, that will be added to each VMServiceScrape.
Expand Down Expand Up @@ -536,16 +536,16 @@ type CommonScrapeParams struct {
// _not_ be added when value is set to empty string (`""`).
// +optional
ExternalLabelName *string `json:"externalLabelName,omitempty"`
// ExternalLabels The labels to add to any time series scraped by vmagent.
// ExternalLabels The labels to add to any time series scraped by vmagent or vmsingle.
// it doesn't affect metrics ingested directly by push API's
// +optional
ExternalLabels map[string]string `json:"externalLabels,omitempty"`
// IngestOnlyMode switches vmagent into unmanaged mode
// IngestOnlyMode switches vmagent or vmsingle into unmanaged mode
// it disables any config generation for scraping
// Currently it prevents vmagent from managing tls and auth options for remote write
// Currently it prevents vmagent or vmsingle from managing tls and auth options for remote write
// +optional
IngestOnlyMode *bool `json:"ingestOnlyMode,omitempty"`
// EnableKubernetesAPISelectors instructs vmagent to use CRD scrape objects spec.selectors for
// EnableKubernetesAPISelectors instructs vmagent or vmsingle to use CRD scrape objects spec.selectors for
// Kubernetes API list and watch requests.
// https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#list-and-watch-filtering
// It could be useful to reduce Kubernetes API server resource usage for serving less than 100 CRD scrape objects in total.
Expand Down
4 changes: 4 additions & 0 deletions api/operator/v1beta1/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ type CRDName int
const (
VMAgentCRD CRDName = iota
VLAgentCRD
VMSingleCRD
)

func (c CRDName) String() string {
return []string{
"vmagents.operator.victoriametrics.com",
"vlagents.operator.victoriametrics.com",
"vmsingles.operator.victoriametrics.com",
}[c]
}

Expand All @@ -46,6 +48,8 @@ func Init(ctx context.Context, rclient client.Client) error {
n = VMAgentCRD
case "vlagents.operator.victoriametrics.com":
n = VLAgentCRD
case "vmsingles.operator.victoriametrics.com":
n = VMSingleCRD
default:
continue
}
Expand Down
4 changes: 2 additions & 2 deletions api/operator/v1beta1/vmagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ type VMAgentRemoteWriteSpec struct {
// +optional
BearerTokenSecret *corev1.SecretKeySelector `json:"bearerTokenSecret,omitempty"`

// ConfigMap with relabeling config which is applied to metrics before sending them to the corresponding -remoteWrite.url
// ConfigMap with relabeling config which is applied to metrics before sending them to the corresponding -remoteWrite.url.
// +optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Key at Configmap with relabelConfig for remoteWrite",xDescriptors="urn:alm:descriptor:io.kubernetes:ConfigMapKeySelector"
UrlRelabelConfig *corev1.ConfigMapKeySelector `json:"urlRelabelConfig,omitempty"`
Expand Down Expand Up @@ -569,7 +569,7 @@ func (cr *VMAgent) IsOwnsServiceAccount() bool {
return cr.Spec.ServiceAccountName == ""
}

func (cr *VMAgent) GetClusterRoleName() string {
func (cr *VMAgent) GetRBACName() string {
return fmt.Sprintf("monitoring:%s:%s", cr.Namespace, cr.PrefixedName())
}

Expand Down
1 change: 1 addition & 0 deletions api/operator/v1beta1/vmextra_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const (
LastAppliedSpecAnnotation = "operator.victoriametrics/last-applied-spec"
VMAuthLBServiceProxyTargetLabel = "operator.victoriametrics.com/vmauthlb-proxy-name"
VMAuthLBServiceProxyJobNameLabel = "operator.victoriametrics.com/vmauthlb-proxy-job-name"
KubeNodeEnvName = "KUBE_NODE_NAME"
)

const (
Expand Down
83 changes: 83 additions & 0 deletions api/operator/v1beta1/vmsingle_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,21 @@ type VMSingleSpec struct {
*EmbeddedProbes `json:",inline"`
// StreamAggrConfig defines stream aggregation configuration for VMSingle
StreamAggrConfig *StreamAggrConfig `json:"streamAggrConfig,omitempty"`
// APIServerConfig allows specifying a host and auth methods to access apiserver.
// If left empty, VMSingle is assumed to run inside of the cluster
// and will discover API servers automatically and use the pod's CA certificate
// and bearer token file at /var/run/secrets/kubernetes.io/serviceaccount/.
// +optional
APIServerConfig *APIServerConfig `json:"apiServerConfig,omitempty"`

// ServiceAccountName is the name of the ServiceAccount to use to run the pods
// +optional
ServiceAccountName string `json:"serviceAccountName,omitempty"`

CommonRelabelParams `json:",inline,omitempty"`
CommonScrapeParams `json:",inline,omitempty"`
CommonDefaultableParams `json:",inline"`
CommonConfigReloaderParams `json:",inline,omitempty"`
CommonApplicationDeploymentParams `json:",inline"`
}

Expand All @@ -93,11 +102,76 @@ func (cr *VMSingle) HasAnyStreamAggrRule() bool {
return cr.Spec.StreamAggrConfig.HasAnyRule()
}

// HasAnyRelabellingConfigs checks if vmagent has any defined relabeling rules
func (cr *VMSingle) HasAnyRelabellingConfigs() bool {
return cr.Spec.HasAnyRelabellingConfigs()
}

// SetLastSpec implements objectWithLastAppliedState interface
func (cr *VMSingle) SetLastSpec(prevSpec VMSingleSpec) {
cr.ParsedLastAppliedSpec = &prevSpec
}

// ScrapeSelectors gets object and namespace sepectors
func (cr *VMSingle) ScrapeSelectors(scrape client.Object) (*metav1.LabelSelector, *metav1.LabelSelector) {
return cr.Spec.ScrapeSelectors(scrape)
}

// IsUnmanaged checks if object should managed any config objects
func (cr *VMSingle) IsUnmanaged(scrape client.Object) bool {
if !cr.DeletionTimestamp.IsZero() || cr.Spec.ParsingError != "" {
return true
}
if scrape == nil {
return cr.Spec.isUnmanaged()
}
switch s := scrape.(type) {
case *VMNodeScrape:
return cr.Spec.isNodeScrapeUnmanaged()
case *VMServiceScrape:
return cr.Spec.isServiceScrapeUnmanaged()
case *VMPodScrape:
return cr.Spec.isPodScrapeUnmanaged()
case *VMProbe:
return cr.Spec.isProbeUnmanaged()
case *VMStaticScrape:
return cr.Spec.isStaticScrapeUnmanaged()
case *VMScrapeConfig:
return cr.Spec.isScrapeConfigUnmanaged()
default:
panic(fmt.Sprintf("BUG: scrape kind %T is not supported", s))
}

}

// ExternalLabels returns external labels for scraping
func (cr *VMSingle) ExternalLabels() map[string]string {
return cr.Spec.externalLabels(fmt.Sprintf("%s/%s", cr.Namespace, cr.Name))
}

// GetReloadURL implements reloadable interface
func (cr *VMSingle) GetReloadURL(host string) string {
return BuildLocalURL(reloadAuthKeyFlag, host, cr.Spec.Port, reloadPath, cr.Spec.ExtraArgs)
}

// GetReloaderParams implements reloadable interface
func (cr *VMSingle) GetReloaderParams() *CommonConfigReloaderParams {
return &cr.Spec.CommonConfigReloaderParams
}

// UseProxyProtocol implements reloadable interface
func (cr *VMSingle) UseProxyProtocol() bool {
if v, ok := cr.Spec.ExtraArgs["httpListenAddr.useProxyProtocol"]; ok && v == "true" {
return true
}
return false
}

// AutomountServiceAccountToken implements reloadable interface
func (cr *VMSingle) AutomountServiceAccountToken() bool {
return !cr.Spec.DisableAutomountServiceAccountToken
}

// UnmarshalJSON implements json.Unmarshaler interface
func (cr *VMSingle) UnmarshalJSON(src []byte) error {
type pcr VMSingle
Expand Down Expand Up @@ -151,6 +225,11 @@ type VMSingle struct {
Status VMSingleStatus `json:"status,omitempty"`
}

// AsCRDOwner implements interface
func (*VMSingle) AsCRDOwner() *metav1.OwnerReference {
return GetCRDAsOwner(VMSingleCRD)
}

// GetStatus implements reconcile.ObjectWithDeepCopyAndStatus interface
func (cr *VMSingle) GetStatus() *VMSingleStatus {
return &cr.Status
Expand Down Expand Up @@ -280,6 +359,10 @@ func (cr *VMSingle) IsOwnsServiceAccount() bool {
return cr.Spec.ServiceAccountName == ""
}

func (cr *VMSingle) GetRBACName() string {
return fmt.Sprintf("monitoring:%s:%s", cr.Namespace, cr.PrefixedName())
}

func (cr *VMSingle) AsURL() string {
port := cr.Spec.Port
if port == "" {
Expand Down
8 changes: 8 additions & 0 deletions api/operator/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading