Skip to content

Commit

Permalink
Merge branch 'main' into fanny/CECO-1269/update-kustomize
Browse files Browse the repository at this point in the history
  • Loading branch information
levan-m committed Sep 4, 2024
2 parents 7e605fc + 9d154ce commit 007d397
Show file tree
Hide file tree
Showing 52 changed files with 4,114 additions and 93 deletions.
13 changes: 13 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: com
layout:
- go.kubebuilder.io/v4
Expand Down Expand Up @@ -68,4 +72,13 @@ resources:
kind: DatadogPodAutoscaler
path: github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: com
group: datadoghq
kind: DatadogDashboard
path: github.com/DataDog/datadog-operator/api/datadoghq/v1alpha1
version: v1alpha1
version: "3"
5 changes: 5 additions & 0 deletions api/datadoghq/common/envvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,8 @@ const (
// version value in the Agent's install info
InstallInfoToolVersion = "DD_TOOL_VERSION"
)

// DatadogAgentProfile env var names
const (
SlowStartEnabled = "DD_DAP_SLOW_START_ENABLED"
)
34 changes: 34 additions & 0 deletions api/datadoghq/v1alpha1/datadogagentprofile_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ import (
)

type ComponentName string
type SlowStartStatus string

const (
// NodeAgentComponentName is the name of the Datadog Node Agent
NodeAgentComponentName ComponentName = "nodeAgent"

CompletedStatus SlowStartStatus = "Completed"
WaitingStatus SlowStartStatus = "Waiting"
InProgressStatus SlowStartStatus = "In Progress"
)

// DatadogAgentProfileSpec defines the desired state of DatadogAgentProfile
Expand Down Expand Up @@ -97,6 +102,35 @@ type DatadogAgentProfileStatus struct {
// Applied shows whether the DatadogAgentProfile conflicts with an existing DatadogAgentProfile.
// +optional
Applied metav1.ConditionStatus `json:"applied,omitempty"`

// SlowStart is the state of the slow start feature.
// +optional
SlowStart *SlowStart `json:"slowStart,omitempty"`
}

// SlowStart defines the observed state of the slow start feature based on the agent deployment.
// +k8s:openapi-gen=true
// +kubebuilder:object:generate=true
type SlowStart struct {
// Status shows the current state of the feature.
// +optional
Status SlowStartStatus `json:"status,omitempty"`

// NodesLabeled shows the number of nodes currently labeled.
// +optional
NodesLabeled int32 `json:"nodesLabeled"`

// PodsReady shows the number of pods in the ready state.
// +optional
PodsReady int32 `json:"podsReady"`

// MaxUnavailable shows the number of pods that can be in an unready state.
// +optional
MaxUnavailable int32 `json:"maxUnavailable"`

// LastTransition is the last time the status was updated.
// +optional
LastTransition *metav1.Time `json:"lastTransition,omitempty"`
}

// DatadogAgentProfile is the Schema for the datadogagentprofiles API
Expand Down
151 changes: 151 additions & 0 deletions api/datadoghq/v1alpha1/datadogdashboard_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// 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-present Datadog, Inc.

package v1alpha1

import (
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"

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

// DatadogDashboardSpec defines the desired state of DatadogDashboard
// +k8s:openapi-gen=true
type DatadogDashboardSpec struct {
// Description is the description of the dashboard.
// +optional
Description string `json:"description,omitempty"`
// LayoutType is the layout type of the dashboard.
LayoutType datadogV1.DashboardLayoutType `json:"layoutType,omitempty"`
// NotifyList is the list of handles of users to notify when changes are made to this dashboard.
// +listType=set
// +optional
NotifyList []string `json:"notifyList,omitempty"`
// Reflowtype is the reflow type for a 'new dashboard layout' dashboard. Set this only when layout type is 'ordered'.
// If set to 'fixed', the dashboard expects all widgets to have a layout, and if it's set to 'auto',
// widgets should not have layouts.
// +optional
ReflowType *datadogV1.DashboardReflowType `json:"reflowType,omitempty"`
// Tags is a list of team names representing ownership of a dashboard.
// +listType=set
// +optional
Tags []string `json:"tags,omitempty"`
// TemplateVariablePresets is an array of template variables saved views.
// +listType=map
// +listMapKey=name
// +optional
TemplateVariablePresets []DashboardTemplateVariablePreset `json:"templateVariablePresets,omitempty"`
// TemplateVariables is a list of template variables for this dashboard.
// +listType=map
// +listMapKey=name
// +optional
TemplateVariables []DashboardTemplateVariable `json:"templateVariables,omitempty"`
// Title is the title of the dashboard.
Title string `json:"title,omitempty"`
// Widgets is a JSON string representation of a list of Datadog API Widgets
// +optional
Widgets string `json:"widgets,omitempty"`
}

// DatadogDashboardStatus defines the observed state of DatadogDashboard
// +k8s:openapi-gen=true
type DatadogDashboardStatus struct {
// Conditions represents the latest available observations of the state of a DatadogDashboard.
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty"`
// ID is the dashboard ID generated in Datadog.
ID string `json:"id,omitempty"`
// Creator is the identity of the dashboard creator.
Creator string `json:"creator,omitempty"`
// Created is the time the dashboard was created.
Created *metav1.Time `json:"created,omitempty"`
// SyncStatus shows the health of syncing the dashboard state to Datadog.
SyncStatus DatadogDashboardSyncStatus `json:"syncStatus,omitempty"`
// CurrentHash tracks the hash of the current DatadogDashboardSpec to know
// if the Spec has changed and needs an update.
CurrentHash string `json:"currentHash,omitempty"`
// DashboardLastForceSyncTime is the last time the API dashboard was last force synced with the Datadogdashboard resource
LastForceSyncTime *metav1.Time `json:"dashboardLastForceSyncTime,omitempty"`
}

type DatadogDashboardSyncStatus string

const (
// DatadogDashboardSyncStatusOK means syncing is OK.
DatadogDashboardSyncStatusOK DatadogDashboardSyncStatus = "OK"
// DatadogDashboardSyncStatusValidateError means there is a dashboard validation error.
DatadogDashboardSyncStatusValidateError DatadogDashboardSyncStatus = "error validating dashboard"
// DatadogDashboardSyncStatusUpdateError means there is a dashboard update error.
DatadogDashboardSyncStatusUpdateError DatadogDashboardSyncStatus = "error updating dashboard"
// DatadogDashboardSyncStatusCreateError means there is an error getting the dashboard.
DatadogDashboardSyncStatusCreateError DatadogDashboardSyncStatus = "error creating dashboard"
// SyncStatusGetError means there is an error getting the monitor
DatadoggDashboardSyncStatusGetError DatadogDashboardSyncStatus = "error getting dashboard"
)

// DatadogDashboard is the Schema for the datadogdashboards API
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=datadogdashboards,scope=Namespaced,shortName=ddd
// +kubebuilder:printcolumn:name="id",type="string",JSONPath=".status.id"
// +kubebuilder:printcolumn:name="sync status",type="string",JSONPath=".status.syncStatus"
// +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp"
// +k8s:openapi-gen=true
// +genclient
type DatadogDashboard struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DatadogDashboardSpec `json:"spec,omitempty"`
Status DatadogDashboardStatus `json:"status,omitempty"`
}

// DashboardTemplateVariablePresetValue Template variables saved views.
// +k8s:openapi-gen=true
type DashboardTemplateVariablePresetValue struct {
// The name of the variable.
Name *string `json:"name"`
// One or many template variable values within the saved view, which will be unioned together using `OR` if more than one is specified. Cannot be used in conjunction with `value`.
// +listType=set
Values []string `json:"values,omitempty"`
}

// DashboardTemplateVariablePreset Template variables saved views.
// +k8s:openapi-gen=true
type DashboardTemplateVariablePreset struct {
// The name of the variable.
Name *string `json:"name"`
// List of variables.
// +listType=map
// +listMapKey=name
TemplateVariables []DashboardTemplateVariablePresetValue `json:"templateVariables,omitempty"`
}

// DashboardTemplateVariable Template variable.
// +k8s:openapi-gen=true
type DashboardTemplateVariable struct {
// The list of values that the template variable drop-down is limited to.
AvailableValues *[]string `json:"availableValues,omitempty"`
// One or many default values for template variables on load. If more than one default is specified, they will be unioned together with `OR`. Cannot be used in conjunction with `default`.
// +listType=set
Defaults []string `json:"defaults,omitempty"`
// The name of the variable.
Name string `json:"name"`
// The tag prefix associated with the variable. Only tags with this prefix appear in the variable drop-down.
Prefix *string `json:"prefix,omitempty"`
}

// DatadogDashboardList contains a list of DatadogDashboard
// +kubebuilder:object:root=true
type DatadogDashboardList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DatadogDashboard `json:"items"`
}

func init() {
SchemeBuilder.Register(&DatadogDashboard{}, &DatadogDashboardList{})
}
27 changes: 27 additions & 0 deletions api/datadoghq/v1alpha1/datadogdashboard_validation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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-present Datadog, Inc.

package v1alpha1

import (
"fmt"

utilserrors "k8s.io/apimachinery/pkg/util/errors"
)

// IsValidDatadogDashboard use to check if a DatadogDashboardSpec is valid by checking
// that the required fields are defined
func IsValidDatadogDashboard(spec *DatadogDashboardSpec) error {
var errs []error
if spec.Title == "" {
errs = append(errs, fmt.Errorf("spec.Title must be defined"))
}

if spec.LayoutType == "" {
errs = append(errs, fmt.Errorf("spec.LayoutType must be defined"))
}

return utilserrors.NewAggregate(errs)
}
59 changes: 59 additions & 0 deletions api/datadoghq/v1alpha1/datadogdashboard_validation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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-present Datadog, Inc.

package v1alpha1

import (
"testing"

"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
"github.com/stretchr/testify/assert"
)

func TestIsValidDatadogDashboard(t *testing.T) {
// Test cases are missing each of the required parameters
minimumValid := &DatadogDashboardSpec{
LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
Title: "test",
}
missingTitle := &DatadogDashboardSpec{
LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
}
missingLayoutType := &DatadogDashboardSpec{
Title: "test",
}

testCases := []struct {
name string
spec *DatadogDashboardSpec
wantErr string
}{
{
name: "minimum valid dashboard",
spec: minimumValid,
},
{
name: "dashboard missing title",
spec: missingTitle,
wantErr: "spec.Title must be defined",
},
{
name: "dashboard missing layout type",
spec: missingLayoutType,
wantErr: "spec.LayoutType must be defined",
},
}
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
result := IsValidDatadogDashboard(test.spec)
if test.wantErr != "" {
assert.Error(t, result)
assert.EqualError(t, result, test.wantErr)
} else {
assert.NoError(t, result)
}
})
}
}
Loading

0 comments on commit 007d397

Please sign in to comment.