Skip to content

Commit

Permalink
create DatadogMetric CRD
Browse files Browse the repository at this point in the history
Signed-off-by: cedric lamoriniere <cedric.lamoriniere@datadoghq.com>
  • Loading branch information
clamoriniere committed May 20, 2020
1 parent ed073f2 commit 0c1d408
Show file tree
Hide file tree
Showing 17 changed files with 976 additions and 2 deletions.
136 changes: 136 additions & 0 deletions deploy/crds/datadoghq.com_datadogmetrics_crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: datadogmetrics.datadoghq.com
spec:
additionalPrinterColumns:
- JSONPath: .status.conditions[?(@.type=='Active')].status
name: active
type: string
- JSONPath: .status.currentMetrics[*].external.currentValue..
name: value
type: string
- JSONPath: .metadata.creationTimestamp
name: age
type: date
group: datadoghq.com
names:
kind: DatadogMetric
listKind: DatadogMetricList
plural: datadogmetrics
singular: datadogmetric
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
description: DatadogMetric is the Schema for the datadogmetrics API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
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.
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
type: string
type: object
status:
description: DatadogMetricStatus defines the observed state of DatadogMetric
properties:
conditions:
description: Conditions Represents the latest available observations
of a DatadogMetric's current state.
items:
description: DatadogMetricCondition describes the state of a DatadogMetric
at a certain point.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another.
format: date-time
type: string
lastUpdateTime:
description: Last time the condition was updated.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition.
type: string
reason:
description: The reason for the condition's last transition.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of DatadogMetric condition.
type: string
required:
- status
- type
type: object
type: array
currentValue:
description: CurrentValue is the current value of the metric (as a quantity)
type: string
required:
- currentValue
type: object
type: object
version: v1alpha1
versions:
- name: v1alpha1
served: true
storage: true
2 changes: 2 additions & 0 deletions deploy/role.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
creationTimestamp: null
name: datadog-operator
rules:
- apiGroups:
Expand Down Expand Up @@ -52,5 +53,6 @@ rules:
- 'datadogagents/status'
- 'datadogagents/finalizers'
- 'extendeddaemonsets'
- 'datadogmetrics'
verbs:
- '*'
2 changes: 0 additions & 2 deletions pkg/apis/addtoscheme_datadoghq_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ package apis

import (
"github.com/DataDog/datadog-operator/pkg/apis/datadoghq/v1alpha1"
edsdatadoghqv1alpha1 "github.com/datadog/extendeddaemonset/pkg/apis/datadoghq/v1alpha1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme)
AddToSchemes = append(AddToSchemes, edsdatadoghqv1alpha1.SchemeBuilder.AddToScheme)
}
11 changes: 11 additions & 0 deletions pkg/apis/datadoghq/group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2019 Datadog, Inc.

// Package datadoghq contains datadoghq API versions.
//
// This file ensures Go source parsers acknowledge the datadoghq package
// and any child packages. It can be removed if any other Go source files are
// added to this package.
package datadoghq
103 changes: 103 additions & 0 deletions pkg/apis/datadoghq/v1alpha1/datadogmetric_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2019 Datadog, Inc.

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 string `json:"query,omitempty"`
// ObjectReference
ObjectReference *v1.ObjectReference `json:"objectReference,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"`
}

// DatadogMetricCondition describes the state of a DatadogMetric at a certain point.
// +k8s:openapi-gen=true
type DatadogMetricCondition struct {
// Type of DatadogMetric condition.
Type DatadogMetricConditionType `json:"type"`
// Status of the condition, one of True, False, Unknown.
Status corev1.ConditionStatus `json:"status"`
// Last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// Last time the condition was updated.
// +optional
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
// The reason for the condition's last transition.
// +optional
Reason string `json:"reason,omitempty"`
// A human readable message indicating details about the transition.
// +optional
Message string `json:"message,omitempty"`
}

// DatadogMetricConditionType type use to represent a DatadogMetric condition
type DatadogMetricConditionType string

const (
// DatadogMetricConditionTypeActive DatadogMetric is active
DatadogMetricConditionTypeActive DatadogMetricConditionType = "Active"
// DatadogMetricConditionTypeUpdated DatadogMetric is updated
DatadogMetricConditionTypeUpdated DatadogMetricConditionType = "Updated"
// DatadogMetricConditionTypeValid DatadogMetric.spec.query is invalid
DatadogMetricConditionTypeValid DatadogMetricConditionType = "Valid"
// DatadogMetricConditionTypeError the controller wasn't able to handle this DatadogMetric
DatadogMetricConditionTypeError DatadogMetricConditionType = "Error"
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// DatadogMetric is the Schema for the datadogmetrics API
// +k8s:openapi-gen=true
// +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"
type DatadogMetric struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DatadogMetricSpec `json:"spec,omitempty"`
Status DatadogMetricStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

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

func init() {
SchemeBuilder.Register(&DatadogMetric{}, &DatadogMetricList{})
}
Loading

0 comments on commit 0c1d408

Please sign in to comment.