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
24 changes: 24 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,30 @@ resources:
webhooks:
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMAnomalyModel
path: github.com/VictoriaMetrics/operator/api/operator/v1
version: v1
webhooks:
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMAnomalyScheduler
path: github.com/VictoriaMetrics/operator/api/operator/v1
version: v1
webhooks:
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
Expand Down
15 changes: 15 additions & 0 deletions api/operator/v1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
Expand Down Expand Up @@ -89,6 +90,20 @@ func (o *OAuth2) Validate() error {
return nil
}

// Selector defines object and namespace selectors
type Selector struct {
// ObjectSelector defines object to be selected for discovery.
// +optional
ObjectSelector *metav1.LabelSelector `json:"objectSelector,omitempty"`
// NamespaceSelector defines namespaces to be selected for object discovery.
// +optional
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
}

func (s *Selector) IsUnmanaged() bool {
return s == nil || (s.ObjectSelector == nil && s.NamespaceSelector == nil)
}

// TLSConfig specifies TLS configuration parameters
// with optional references to secrets with corresponding sensitive values
type TLSConfig struct {
Expand Down
11 changes: 11 additions & 0 deletions api/operator/v1/vmanomaly_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ type VMAnomalySpec struct {
// Monitoring configures how expose anomaly metrics
// See https://docs.victoriametrics.com/anomaly-detection/components/monitoring/
Monitoring *VMAnomalyMonitoringSpec `json:"monitoring,omitempty"`
// ModelSelector defines VMAnomalyModel's object and namespace selectors.
// +optional
ModelSelector *Selector `json:"modelSelector,omitempty"`
// SchedulerSelector defines VMAnomalyScheduler's object and namespace selectors.
// +optional
SchedulerSelector *Selector `json:"schedulerSelector,omitempty"`
// License allows to configure license key to be used for enterprise features.
// Using license key is supported starting from VictoriaMetrics v1.94.0.
// See [here](https://docs.victoriametrics.com/victoriametrics/enterprise/)
Expand Down Expand Up @@ -457,6 +463,11 @@ func (cr *VMAnomalySpec) UnmarshalJSON(src []byte) error {
return nil
}

// IsUnmanaged checks if object should managed any config objects
func (cr *VMAnomaly) IsUnmanaged() bool {
return cr.Spec.ModelSelector.IsUnmanaged() && cr.Spec.SchedulerSelector.IsUnmanaged()
}

// +kubebuilder:object:root=true

// VMAnomalyList contains a list of VMAnomaly.
Expand Down
87 changes: 87 additions & 0 deletions api/operator/v1/vmanomalymodel_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
"encoding/json"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

vmv1beta1 "github.com/VictoriaMetrics/operator/api/operator/v1beta1"
)

// VMAnomalyModelSpec defines the desired state of VMAnomalyModel.
type VMAnomalyModelSpec struct {
// ParsingError contents error with context if operator was failed to parse json object from kubernetes api server
ParsingError string `json:"-" yaml:"-"`
// Class defines anomaly detection model class
Class string `json:"class" yaml:"class"`
// Params defines anomaly detection model params
Params runtime.RawExtension `json:"params,omitempty" yaml:"params,omitempty"`
}

// UnmarshalJSON implements json.Unmarshaler interface
func (cr *VMAnomalyModelSpec) UnmarshalJSON(src []byte) error {
type pcr VMAnomalyModelSpec
if err := json.Unmarshal(src, (*pcr)(cr)); err != nil {
cr.ParsingError = fmt.Sprintf("cannot parse spec: %s, err: %s", string(src), err)
return nil
}
return nil
}

// VMAnomalyModelStatus defines the observed state of VMAnomalyModel.
type VMAnomalyModelStatus struct {
vmv1beta1.StatusMetadata `json:",inline"`
}

// GetStatusMetadata returns metadata for object status
func (cr *VMAnomalyModel) GetStatusMetadata() *vmv1beta1.StatusMetadata {
return &cr.Status.StatusMetadata
}

// AsKey returns unique key for object
func (cr *VMAnomalyModel) AsKey(_ bool) string {
return cr.Namespace + "/" + cr.Name
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// VMAnomalyModel is the Schema for the vmanomalymodels API.
type VMAnomalyModel struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VMAnomalyModelSpec `json:"spec,omitempty"`
Status VMAnomalyModelStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// VMAnomalyModelList contains a list of VMAnomalyModel.
type VMAnomalyModelList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []VMAnomalyModel `json:"items"`
}

func init() {
SchemeBuilder.Register(&VMAnomalyModel{}, &VMAnomalyModelList{})
}
87 changes: 87 additions & 0 deletions api/operator/v1/vmanomalyscheduler_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
"encoding/json"
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

vmv1beta1 "github.com/VictoriaMetrics/operator/api/operator/v1beta1"
)

// VMAnomalySchedulerSpec defines the desired state of VMAnomalyScheduler.
type VMAnomalySchedulerSpec struct {
// ParsingError contents error with context if operator was failed to parse json object from kubernetes api server
ParsingError string `json:"-" yaml:"-"`
// Class defines anomaly detection scheduler class
Class string `json:"class" yaml:"class"`
// Params defines anomaly detection scheduler params
Params runtime.RawExtension `json:"params,omitempty" yaml:"params,omitempty"`
}

// VMAnomalySchedulerStatus defines the observed state of VMAnomalyScheduler.
type VMAnomalySchedulerStatus struct {
vmv1beta1.StatusMetadata `json:",inline"`
}

// GetStatusMetadata returns metadata for object status
func (cr *VMAnomalyScheduler) GetStatusMetadata() *vmv1beta1.StatusMetadata {
return &cr.Status.StatusMetadata
}

// AsKey returns unique key for object
func (cr *VMAnomalyScheduler) AsKey(_ bool) string {
return cr.Namespace + "/" + cr.Name
}

// UnmarshalJSON implements json.Unmarshaler interface
func (cr *VMAnomalySchedulerSpec) UnmarshalJSON(src []byte) error {
type pcr VMAnomalySchedulerSpec
if err := json.Unmarshal(src, (*pcr)(cr)); err != nil {
cr.ParsingError = fmt.Sprintf("cannot parse spec: %s, err: %s", string(src), err)
return nil
}
return nil
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// VMAnomalyScheduler is the Schema for the vmanomalyschedulers API.
type VMAnomalyScheduler struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VMAnomalySchedulerSpec `json:"spec,omitempty"`
Status VMAnomalySchedulerStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// VMAnomalySchedulerList contains a list of VMAnomalyScheduler.
type VMAnomalySchedulerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []VMAnomalyScheduler `json:"items"`
}

func init() {
SchemeBuilder.Register(&VMAnomalyScheduler{}, &VMAnomalySchedulerList{})
}
Loading