Skip to content

Commit

Permalink
Adapt DatadogMetric CRD following RFC
Browse files Browse the repository at this point in the history
  • Loading branch information
vboulineau authored and clamoriniere committed May 20, 2020
1 parent 0c1d408 commit 607e3ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 69 deletions.
55 changes: 10 additions & 45 deletions deploy/crds/datadoghq.com_datadogmetrics_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ spec:
- JSONPath: .status.conditions[?(@.type=='Active')].status
name: active
type: string
- JSONPath: .status.currentMetrics[*].external.currentValue..
- JSONPath: .status.conditions[?(@.type=='Valid')].status
name: valid
type: string
- JSONPath: .status.currentValue
name: value
type: string
- JSONPath: .metadata.creationTimestamp
name: age
- JSONPath: .status.conditions[?(@.type=='Updated')].lastUpdateTime
name: update time
type: date
group: datadoghq.com
names:
Expand Down Expand Up @@ -41,48 +44,11 @@ spec:
spec:
description: DatadogMetricSpec defines the desired state of DatadogMetric
properties:
name:
description: Name use to provide a Name to the metrics, if not provided,
the "DatadogMetric.name"."DatadogMetric.name" will be used.
externalMetricName:
description: ExternalMetricName is reversed for internal use
type: string
objectReference:
description: ObjectReference
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: 'If referring to a piece of an object instead of an
entire object, this string should contain a valid JSON/Go field
access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container within
a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]"
(container with index 2 in this pod). This syntax is chosen only
to have some well-defined way of referencing a part of an object.
TODO: this design is not final and this field is subject to change
in the future.'
type: string
kind:
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
resourceVersion:
description: 'Specific resourceVersion to which this reference is
made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
type: string
uid:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
query:
description: Query the raw datadog query
description: Query is the raw datadog query
type: string
type: object
status:
Expand Down Expand Up @@ -123,8 +89,7 @@ spec:
type: object
type: array
currentValue:
description: CurrentValue is the current value of the metric (as a quantity)
type: string
description: Value is the latest value of the metric
required:
- currentValue
type: object
Expand Down
26 changes: 9 additions & 17 deletions pkg/apis/datadoghq/v1alpha1/datadogmetric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,24 @@ package v1alpha1

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

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// DatadogMetricSpec defines the desired state of DatadogMetric
type DatadogMetricSpec struct {
// Name use to provide a Name to the metrics, if not provided, the "DatadogMetric.name"."DatadogMetric.name"
// will be used.
// +optional
Name string `json:"name,omitempty"`
// Query the raw datadog query
// Query is the raw datadog query
Query string `json:"query,omitempty"`
// ObjectReference
ObjectReference *v1.ObjectReference `json:"objectReference,omitempty"`
// ExternalMetricName is reversed for internal use
ExternalMetricName string `json:"externalMetricName,omitempty"`
}

// DatadogMetricStatus defines the observed state of DatadogMetric
type DatadogMetricStatus struct {
// Conditions Represents the latest available observations of a DatadogMetric's current state.
// +listType=set
Conditions []DatadogMetricCondition `json:"conditions,omitempty"`
// CurrentValue is the current value of the metric (as a quantity)
CurrentValue resource.Quantity `json:"currentValue"`
// Value is the latest value of the metric
Value float64 `json:"currentValue"`
}

// DatadogMetricCondition describes the state of a DatadogMetric at a certain point.
Expand Down Expand Up @@ -61,7 +52,7 @@ type DatadogMetricCondition struct {
type DatadogMetricConditionType string

const (
// DatadogMetricConditionTypeActive DatadogMetric is active
// DatadogMetricConditionTypeActive DatadogMetric is active (referenced by an HPA), Datadog will only be queried for active metrics
DatadogMetricConditionTypeActive DatadogMetricConditionType = "Active"
// DatadogMetricConditionTypeUpdated DatadogMetric is updated
DatadogMetricConditionTypeUpdated DatadogMetricConditionType = "Updated"
Expand All @@ -79,8 +70,9 @@ const (
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=datadogmetrics,scope=Namespaced
// +kubebuilder:printcolumn:name="active",type="string",JSONPath=".status.conditions[?(@.type=='Active')].status"
// +kubebuilder:printcolumn:name="value",type="string",JSONPath=".status.currentMetrics[*].external.currentValue.."
// +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="valid",type="string",JSONPath=".status.conditions[?(@.type=='Valid')].status"
// +kubebuilder:printcolumn:name="value",type="string",JSONPath=".status.currentValue"
// +kubebuilder:printcolumn:name="update time",type="date",JSONPath=".status.conditions[?(@.type=='Updated')].lastUpdateTime"
type DatadogMetric struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
8 changes: 1 addition & 7 deletions pkg/apis/datadoghq/v1alpha1/zz_generated.deepcopy.go

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

0 comments on commit 607e3ce

Please sign in to comment.