Skip to content
12 changes: 12 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ resources:
webhooks:
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: victoriametrics.com
group: operator
kind: VMAnomalyConfig
path: github.com/VictoriaMetrics/operator/api/operator/v1
version: v1
webhooks:
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
Expand Down
20 changes: 20 additions & 0 deletions api/operator/v1/vmanomaly_types.go
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to run it through v1beta1 for a few releases first?

Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ type VMAnomalySpec struct {
// Server configures HTTP server for VMAnomaly
// +optional
Server *VMAnomalyServerSpec `json:"server,omitempty"`
// SelectAllByDefault changes default behavior for empty configSelector and configNamespaceSelector.
// with selectAllByDefault: true and empty object and namespace selectors
// Operator selects all existing VMAnomalyConfig objects
// with selectAllByDefault: false - selects nothing
// +optional
SelectAllByDefault bool `json:"selectAllByDefault,omitempty"`
// ConfigSelector defines VMAnomalyConfig object selector.
// +optional
ConfigSelector *metav1.LabelSelector `json:"configSelector,omitempty"`
// ConfigNamespaceSelector defines VMAnomalyConfig object namespace selector.
// +optional
ConfigNamespaceSelector *metav1.LabelSelector `json:"configNamespaceSelector,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 @@ -475,6 +487,14 @@ func (cr *VMAnomalySpec) UnmarshalJSON(src []byte) error {
return nil
}

// IsUnmanaged checks if object should manage any config objects
func (cr *VMAnomaly) IsUnmanaged() bool {
Comment thread
AndrewChubatiuk marked this conversation as resolved.
if cr == nil {
return true
}
return !cr.Spec.SelectAllByDefault && cr.Spec.ConfigSelector == nil && cr.Spec.ConfigNamespaceSelector == nil
}

// +kubebuilder:object:root=true

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


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 (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

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

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

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

// GetStatus implements reconcile.ObjectWithDeepCopyAndStatus interface
func (cr *VMAnomalyConfig) GetStatus() *VMAnomalyConfigStatus {
return &cr.Status
}

// DefaultStatusFields implements reconcile.ObjectWithDeepCopyAndStatus interface
func (cr *VMAnomalyConfig) DefaultStatusFields(vs *VMAnomalyConfigStatus) {}

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

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

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

Spec runtime.RawExtension `json:"spec"`
Status VMAnomalyConfigStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&VMAnomalyConfig{}, &VMAnomalyConfigList{})
}
88 changes: 87 additions & 1 deletion api/operator/v1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ resources:
- bases/operator.victoriametrics.com_vtclusters.yaml
- bases/operator.victoriametrics.com_vmanomalies.yaml
- bases/operator.victoriametrics.com_vmdistributed.yaml
- bases/operator.victoriametrics.com_vmanomalyconfigs.yaml
patches:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
Expand Down
Loading
Loading