|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed |
| 2 | +// under the Apache License Version 2.0. |
| 3 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 4 | +// Copyright 2016-present Datadog, Inc. |
| 5 | + |
| 6 | +package v1alpha1 |
| 7 | + |
| 8 | +import ( |
| 9 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 10 | +) |
| 11 | + |
| 12 | +type SupportedResourcesType string |
| 13 | + |
| 14 | +// When adding a new type, make sure to update the kubebuilder validation enum marker |
| 15 | +const ( |
| 16 | + Notebook SupportedResourcesType = "notebook" |
| 17 | + SyntheticsAPITest SupportedResourcesType = "synthetics_api_test" |
| 18 | + SyntheticsBrowserTest SupportedResourcesType = "synthetics_browser_test" |
| 19 | +) |
| 20 | + |
| 21 | +// DatadogGenericResourceSpec defines the desired state of DatadogGenericResource |
| 22 | +// +k8s:openapi-gen=true |
| 23 | +type DatadogGenericResourceSpec struct { |
| 24 | + // Type is the type of the API object |
| 25 | + // +kubebuilder:validation:Enum=notebook;synthetics_api_test;synthetics_browser_test |
| 26 | + Type SupportedResourcesType `json:"type"` |
| 27 | + // JsonSpec is the specification of the API object |
| 28 | + JsonSpec string `json:"jsonSpec"` |
| 29 | +} |
| 30 | + |
| 31 | +// DatadogGenericResourceStatus defines the observed state of DatadogGenericResource |
| 32 | +// +k8s:openapi-gen=true |
| 33 | +type DatadogGenericResourceStatus struct { |
| 34 | + // Conditions represents the latest available observations of the state of a DatadogGenericResource. |
| 35 | + // +listType=map |
| 36 | + // +listMapKey=type |
| 37 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 38 | + // Id is the object unique identifier generated in Datadog. |
| 39 | + Id string `json:"id,omitempty"` |
| 40 | + // Creator is the identity of the creator. |
| 41 | + Creator string `json:"creator,omitempty"` |
| 42 | + // Created is the time the object was created. |
| 43 | + Created *metav1.Time `json:"created,omitempty"` |
| 44 | + // SyncStatus shows the health of syncing the object state to Datadog. |
| 45 | + SyncStatus DatadogSyncStatus `json:"syncStatus,omitempty"` |
| 46 | + // CurrentHash tracks the hash of the current DatadogGenericResourceSpec to know |
| 47 | + // if the JsonSpec has changed and needs an update. |
| 48 | + CurrentHash string `json:"currentHash,omitempty"` |
| 49 | + // LastForceSyncTime is the last time the API object was last force synced with the custom resource |
| 50 | + LastForceSyncTime *metav1.Time `json:"lastForceSyncTime,omitempty"` |
| 51 | +} |
| 52 | + |
| 53 | +type DatadogSyncStatus string |
| 54 | + |
| 55 | +const ( |
| 56 | + // DatadogSyncStatusOK means syncing is OK. |
| 57 | + DatadogSyncStatusOK DatadogSyncStatus = "OK" |
| 58 | + // DatadogSyncStatusValidateError means there is an object validation error. |
| 59 | + DatadogSyncStatusValidateError DatadogSyncStatus = "error validating object" |
| 60 | + // DatadogSyncStatusUpdateError means there is an object update error. |
| 61 | + DatadogSyncStatusUpdateError DatadogSyncStatus = "error updating object" |
| 62 | + // DatadogSyncStatusCreateError means there is an error getting the object. |
| 63 | + DatadogSyncStatusCreateError DatadogSyncStatus = "error creating object" |
| 64 | + // DatadogSyncStatusGetError means there is an error getting the object. |
| 65 | + DatadogSyncStatusGetError DatadogSyncStatus = "error getting object" |
| 66 | +) |
| 67 | + |
| 68 | +// DatadogGenericResource is the Schema for the DatadogGenericResources API |
| 69 | +// +kubebuilder:object:root=true |
| 70 | +// +kubebuilder:subresource:status |
| 71 | +// +kubebuilder:resource:path=datadoggenericresources,scope=Namespaced,shortName=ddgr |
| 72 | +// +kubebuilder:printcolumn:name="id",type="string",JSONPath=".status.id" |
| 73 | +// +kubebuilder:printcolumn:name="sync status",type="string",JSONPath=".status.syncStatus" |
| 74 | +// +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" |
| 75 | +// +k8s:openapi-gen=true |
| 76 | +// +genclient |
| 77 | +type DatadogGenericResource struct { |
| 78 | + metav1.TypeMeta `json:",inline"` |
| 79 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 80 | + |
| 81 | + Spec DatadogGenericResourceSpec `json:"spec,omitempty"` |
| 82 | + Status DatadogGenericResourceStatus `json:"status,omitempty"` |
| 83 | +} |
| 84 | + |
| 85 | +// DatadogGenericResourceList contains a list of DatadogGenericResource |
| 86 | +// +kubebuilder:object:root=true |
| 87 | +type DatadogGenericResourceList struct { |
| 88 | + metav1.TypeMeta `json:",inline"` |
| 89 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 90 | + Items []DatadogGenericResource `json:"items"` |
| 91 | +} |
| 92 | + |
| 93 | +func init() { |
| 94 | + SchemeBuilder.Register(&DatadogGenericResource{}, &DatadogGenericResourceList{}) |
| 95 | +} |
0 commit comments