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
19 changes: 16 additions & 3 deletions api/operator/v1/vmanomaly_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ type VMAnomalyMonitoringSpec struct {
}

// VMAnomalyMonitoringPullSpec defines pull monitoring configuration
// which is enabled by default and served at POD_IP:8490/metrics
// which is enabled by default and served at POD_IP:8080/metrics
type VMAnomalyMonitoringPullSpec struct {
// Port defines a port for metrics scrape
Port string `json:"port"`
Expand Down Expand Up @@ -397,7 +397,10 @@ func (cr *VMAnomaly) GetServiceScrape() *vmv1beta1.VMServiceScrapeSpec {

// Port returns port for accessing anomaly UI
func (cr *VMAnomaly) Port() string {
return cr.Spec.Port
if cr == nil || cr.Spec.Server == nil || len(cr.Spec.Server.Port) == 0 {
return "8490"
}
return cr.Spec.Server.Port
}

// GetVolumeName returns volume name for persistent storage
Expand Down Expand Up @@ -428,14 +431,24 @@ func (cr *VMAnomaly) ProbeScheme() string {

// ProbePort implements build.probeCRD interface
func (cr *VMAnomaly) ProbePort() string {
return cr.Port()
if cr == nil || cr.Spec.Monitoring == nil || cr.Spec.Monitoring.Pull == nil || len(cr.Spec.Monitoring.Pull.Port) == 0 {
return "8080"
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
}
return cr.Spec.Monitoring.Pull.Port
}

// ProbeNeedLiveness implements build.probeCRD interface
func (*VMAnomaly) ProbeNeedLiveness() bool {
return true
}

// AsURL returns url for http access to the first replica.
// Returns empty string if spec.server.port is not configured.
func (cr *VMAnomaly) AsURL() string {
port := cr.Port()
return fmt.Sprintf("http://%s.%s.svc:%s", cr.PrefixedName(), cr.Namespace, port)
}

// Validate performs semantic validation for component
func (cr *VMAnomaly) Validate() error {
if vmv1beta1.MustSkipCRValidation(cr) {
Expand Down
4 changes: 2 additions & 2 deletions api/operator/v1beta1/vmuser_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ type NamespacedName struct {
// CRDRef describe CRD target reference.
type CRDRef struct {
// Kind one of:
// VMAgent,VMAlert, VMSingle, VMCluster/vmselect, VMCluster/vmstorage,VMCluster/vminsert,VMAlertManager, VLSingle, VLCluster/vlinsert, VLCluster/vlselect, VLCluster/vlstorage, VTSingle, VTCluster/vtinsert, VTCluster/vtselect, VTCluster/vtstorage and VLAgent
// +kubebuilder:validation:Enum=VMAgent;VMAlert;VMSingle;VLogs;VMAlertManager;VMAlertmanager;VMCluster/vmselect;VMCluster/vmstorage;VMCluster/vminsert;VLSingle;VLCluster/vlinsert;VLCluster/vlselect;VLCluster/vlstorage;VLAgent;VTCluster/vtinsert;VTCluster/vtselect;VTCluster/vtstorage;VTSingle
// VMAgent,VMAlert, VMSingle, VMCluster/vmselect, VMCluster/vmstorage,VMCluster/vminsert,VMAlertManager, VLSingle, VLCluster/vlinsert, VLCluster/vlselect, VLCluster/vlstorage, VTSingle, VTCluster/vtinsert, VTCluster/vtselect, VTCluster/vtstorage VMAnomaly and VLAgent
// +kubebuilder:validation:Enum=VMAgent;VMAlert;VMSingle;VLogs;VMAlertManager;VMAlertmanager;VMCluster/vmselect;VMCluster/vmstorage;VMCluster/vminsert;VLSingle;VLCluster/vlinsert;VLCluster/vlselect;VLCluster/vlstorage;VLAgent;VTCluster/vtinsert;VTCluster/vtselect;VTCluster/vtstorage;VTSingle;VMAnomaly
Kind string `json:"kind"`
NamespacedName `json:",inline"`
// Objects defines list of name/namespace pairs that define existing k8s object
Expand Down
5 changes: 5 additions & 0 deletions config/crd/overlay/crd.descriptionless.yaml

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

17 changes: 11 additions & 6 deletions config/crd/overlay/crd.yaml

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

1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ aliases:

* Dependency: [vmoperator](https://docs.victoriametrics.com/operator/): Updated default versions for VM apps to [v1.142.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.142.0) version
* FEATURE: [vmauth](https://docs.victoriametrics.com/operator/resources/vmauth): previously VMAuth could read configuration only from predefined locations; now VMAuth supports arbitrary filesystem access configuration, allowing users to reference required files directly and reducing configuration workarounds. See [#899](https://github.com/VictoriaMetrics/operator/issues/899).
* FEATURE: [vmuser](https://docs.victoriametrics.com/operator/resources/vmuser/): support VMAnomaly CRD in VMUser targetRefs. See [#2141](https://github.com/VictoriaMetrics/operator/issues/2141).

* BUGFIX: [converter](https://docs.victoriametrics.com/operator/integrations/prometheus/#objects-conversion): disable all prometheus controllers if CRD group was not found. See [#2838](https://github.com/VictoriaMetrics/helm-charts/issues/2838).
* BUGFIX: [vmdistributed](https://docs.victoriametrics.com/operator/resources/vmdistributed/): change default load balancing policy for write requests from `first_available` to `least_loaded`. This should allow to evenly distribute write load across all VMAgents.
Expand Down
4 changes: 2 additions & 2 deletions docs/api.md

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

18 changes: 13 additions & 5 deletions internal/controller/operator/factory/build/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,19 @@ func addVMAnomalyDefaults(objI any) {
}
addDefaultsToCommonParams(&cr.Spec.CommonAppsParams, &cp, &cv)
if cr.Spec.Monitoring == nil {
cr.Spec.Monitoring = &vmv1.VMAnomalyMonitoringSpec{
Pull: &vmv1.VMAnomalyMonitoringPullSpec{
Port: "8080",
},
}
cr.Spec.Monitoring = &vmv1.VMAnomalyMonitoringSpec{}
}
if cr.Spec.Monitoring.Pull == nil {
cr.Spec.Monitoring.Pull = &vmv1.VMAnomalyMonitoringPullSpec{}
}
if len(cr.Spec.Monitoring.Pull.Port) == 0 {
cr.Spec.Monitoring.Pull.Port = "8080"
}
if cr.Spec.Server == nil {
cr.Spec.Server = &vmv1.VMAnomalyServerSpec{}
}
if len(cr.Spec.Server.Port) == 0 {
cr.Spec.Server.Port = cv.Port
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func OnVMAnomalyDelete(ctx context.Context, rclient client.Client, cr *vmv1.VMAn
}
objsToRemove := []client.Object{
&appsv1.StatefulSet{ObjectMeta: objMeta},
&corev1.Service{ObjectMeta: objMeta},
&corev1.ServiceAccount{ObjectMeta: metav1.ObjectMeta{
Name: cr.GetServiceAccountName(),
Namespace: ns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ monitoring:
label1: value1
settings:
restore_state: true
server:
port: "8490"
`,
})

Expand Down Expand Up @@ -388,6 +390,8 @@ settings:
retention:
ttl: 24h
check_interval: 30m
server:
port: "8490"
`,
})

Expand Down Expand Up @@ -543,6 +547,8 @@ writer:
monitoring:
pull:
port: "8080"
server:
port: "8490"
`,
})

Expand Down Expand Up @@ -617,6 +623,8 @@ writer:
monitoring:
pull:
port: "8080"
server:
port: "8490"
`,
})

Expand Down Expand Up @@ -838,6 +846,8 @@ monitoring:
port: "8080"
settings:
restore_state: true
server:
port: "8490"
`,
})
}
17 changes: 17 additions & 0 deletions internal/controller/operator/factory/vmanomaly/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ import (
"github.com/VictoriaMetrics/operator/internal/controller/operator/factory/reconcile"
)

func buildService(cr *vmv1.VMAnomaly) *corev1.Service {
return build.Service(cr, cr.Spec.Server.Port, func(svc *corev1.Service) {
svc.Spec.ClusterIP = "None"
svc.Spec.PublishNotReadyAddresses = true
})
}

func buildScrape(cr *vmv1.VMAnomaly) *vmv1beta1.VMPodScrape {
if cr == nil || ptr.Deref(cr.Spec.DisableSelfServiceScrape, false) {
return nil
Expand Down Expand Up @@ -54,6 +61,15 @@ func CreateOrUpdate(ctx context.Context, cr *vmv1.VMAnomaly, rclient client.Clie
}
}

svc := buildService(cr)
var prevSvc *corev1.Service
if prevCR != nil {
prevSvc = buildService(prevCR)
}
if err := reconcile.Service(ctx, rclient, svc, prevSvc, &owner); err != nil {
return fmt.Errorf("cannot reconcile headless service for vmanomaly: %w", err)
}

if !ptr.Deref(cr.Spec.DisableSelfServiceScrape, false) {
svs := buildScrape(cr)
prevSvs := buildScrape(prevCR)
Expand Down Expand Up @@ -125,6 +141,7 @@ func newK8sApp(cr *vmv1.VMAnomaly, ac *build.AssetsCache) (*appsv1.StatefulSet,
OwnerReferences: []metav1.OwnerReference{cr.AsOwner()},
},
Spec: appsv1.StatefulSetSpec{
ServiceName: cr.PrefixedName(),
Selector: &metav1.LabelSelector{
MatchLabels: build.ShardSelectorLabels(cr),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ schedulers:
actions: []k8stools.ClientAction{
{Verb: "Get", Kind: "ServiceAccount", Resource: vmanomalyName},
{Verb: "Create", Kind: "ServiceAccount", Resource: vmanomalyName},
{Verb: "Get", Kind: "Service", Resource: vmanomalyName},
{Verb: "Create", Kind: "Service", Resource: vmanomalyName},
{Verb: "Get", Kind: "VMPodScrape", Resource: vmanomalyName},
{Verb: "Create", Kind: "VMPodScrape", Resource: vmanomalyName},
// Secrets
Expand Down Expand Up @@ -195,6 +197,7 @@ schedulers:
want{
actions: []k8stools.ClientAction{
{Verb: "Get", Kind: "ServiceAccount", Resource: vmanomalyName},
{Verb: "Get", Kind: "Service", Resource: vmanomalyName},
{Verb: "Get", Kind: "VMPodScrape", Resource: vmanomalyName},
// Secrets
{Verb: "Get", Kind: "Secret", Resource: tlsAssetName},
Expand Down Expand Up @@ -245,6 +248,7 @@ schedulers:
want{
actions: []k8stools.ClientAction{
{Verb: "Get", Kind: "ServiceAccount", Resource: vmanomalyName},
{Verb: "Get", Kind: "Service", Resource: vmanomalyName},
{Verb: "Get", Kind: "VMPodScrape", Resource: vmanomalyName},
// Secrets
{Verb: "Get", Kind: "Secret", Resource: tlsAssetName},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ var crdNameToObject = map[string]objectWithURL{
"VMCluster/vmselect": newClusterWithURL("vmselect"),
"VMCluster/vminsert": newClusterWithURL("vminsert"),
"VMCluster/vmstorage": newClusterWithURL("vmstorage"),
"VMAnomaly": &vmv1.VMAnomaly{},
"VLSingle": &vmv1.VLSingle{},
"VLCluster/vlselect": newClusterWithURL("vlselect"),
"VLCluster/vlinsert": newClusterWithURL("vlinsert"),
Expand Down
Loading
Loading