|
| 1 | +package v1 |
| 2 | + |
| 3 | +import ( |
| 4 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 5 | +) |
| 6 | + |
| 7 | +const ( |
| 8 | + // BillingServiceFinalizer is the finalizer used to protect BillingService resources from deletion |
| 9 | + BillingServiceFinalizer = "billing.appcat.vshn.io/delete-protection" |
| 10 | +) |
| 11 | + |
| 12 | +// +kubebuilder:object:root=true |
| 13 | +// +kubebuilder:subresource:status |
| 14 | +// +kubebuilder:object:generate=true |
| 15 | +// +kubebuilder:resource:scope=Namespaced,categories=appcat |
| 16 | +// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status" |
| 17 | +// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status" |
| 18 | +// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" |
| 19 | + |
| 20 | +// BillingService represents a service instance for billing purposes |
| 21 | +type BillingService struct { |
| 22 | + metav1.TypeMeta `json:",inline"` |
| 23 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 24 | + |
| 25 | + // Spec defines the desired state of a BillingService |
| 26 | + Spec BillingServiceSpec `json:"spec"` |
| 27 | + |
| 28 | + // Status reflects the observed state of a BillingService |
| 29 | + Status BillingServiceStatus `json:"status,omitempty"` |
| 30 | +} |
| 31 | + |
| 32 | +// BillingServiceSpec defines the desired state of a BillingService |
| 33 | +type BillingServiceSpec struct { |
| 34 | + // KeepAfterDeletion defines how many days to keep billing records after service deletion |
| 35 | + KeepAfterDeletion int `json:"keepAfterDeletion,omitempty"` |
| 36 | + |
| 37 | + // Odoo contains Odoo-specific billing configuration |
| 38 | + Odoo OdooSpec `json:"odoo,omitempty"` |
| 39 | +} |
| 40 | + |
| 41 | +// OdooSpec defines Odoo-specific billing configuration |
| 42 | +type OdooSpec struct { |
| 43 | + // InstanceID uniquely identifies the service instance in Odoo |
| 44 | + InstanceID string `json:"instanceID"` |
| 45 | + |
| 46 | + // ProductID identifies the product in the billing system |
| 47 | + ProductID string `json:"productID"` |
| 48 | + |
| 49 | + // SalesOrderID identifies the sales order in Odoo |
| 50 | + SalesOrderID string `json:"salesOrderID,omitempty"` |
| 51 | + |
| 52 | + // UnitID defines the billing unit type in Odoo |
| 53 | + UnitID string `json:"unitID"` |
| 54 | + |
| 55 | + // Size represents the size of the service instance |
| 56 | + Size string `json:"size,omitempty"` |
| 57 | + |
| 58 | + // ItemGroupDescription describes the billing item group |
| 59 | + ItemGroupDescription string `json:"itemGroupDescription"` |
| 60 | + |
| 61 | + // ItemDescription is a human readable description of the billing item |
| 62 | + ItemDescription string `json:"itemDescription"` |
| 63 | +} |
| 64 | + |
| 65 | +// BillingServiceStatus defines the observed state of a BillingService |
| 66 | +type BillingServiceStatus struct { |
| 67 | + // Events contains the history of billing events |
| 68 | + Events []BillingEventStatus `json:"events,omitempty"` |
| 69 | + |
| 70 | + // Conditions represent the latest available observations of the billing service's state |
| 71 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 72 | +} |
| 73 | + |
| 74 | +// BillingEventStatus represents the status of a billing event |
| 75 | +type BillingEventStatus struct { |
| 76 | + // Type is the type of billing event (created, deleted, scaled) |
| 77 | + // +kubebuilder:validation:Enum="created";"deleted";"scaled" |
| 78 | + Type string `json:"type"` |
| 79 | + |
| 80 | + // ProductID identifies the product in the billing system |
| 81 | + ProductID string `json:"productId"` |
| 82 | + |
| 83 | + // Size represents the size/plan at the time of the event |
| 84 | + Size string `json:"size"` |
| 85 | + |
| 86 | + // Timestamp when the event occurred |
| 87 | + Timestamp metav1.Time `json:"timestamp"` |
| 88 | + |
| 89 | + // State represents the current state of the event (sent, pending, failed, superseded) |
| 90 | + // +kubebuilder:validation:Enum="sent";"pending";"failed";"superseded" |
| 91 | + State string `json:"state"` |
| 92 | + |
| 93 | + // RetryCount tracks the number of retry attempts for failed events |
| 94 | + // +kubebuilder:default=0 |
| 95 | + RetryCount int `json:"retryCount,omitempty"` |
| 96 | + |
| 97 | + // LastAttemptTime is when we last tried to send this event |
| 98 | + LastAttemptTime metav1.Time `json:"lastAttemptTime,omitempty"` |
| 99 | +} |
| 100 | + |
| 101 | +// +kubebuilder:object:root=true |
| 102 | +// +kubebuilder:object:generate=true |
| 103 | + |
| 104 | +// BillingServiceList contains a list of BillingService |
| 105 | +type BillingServiceList struct { |
| 106 | + metav1.TypeMeta `json:",inline"` |
| 107 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 108 | + Items []BillingService `json:"items"` |
| 109 | +} |
0 commit comments