|
| 1 | +/* |
| 2 | +Copyright 2025. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v4 |
| 18 | + |
| 19 | +import ( |
| 20 | + corev1 "k8s.io/api/core/v1" |
| 21 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 22 | + "k8s.io/apimachinery/pkg/runtime" |
| 23 | +) |
| 24 | + |
| 25 | +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! |
| 26 | +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. |
| 27 | + |
| 28 | +const ( |
| 29 | + // BusConfigurationPausedAnnotation is the annotation that pauses the reconciliation (triggers |
| 30 | + // an immediate requeue) |
| 31 | + BusConfigurationPausedAnnotation = "busconfiguration.enterprise.splunk.com/paused" |
| 32 | +) |
| 33 | + |
| 34 | +// BusConfigurationSpec defines the desired state of BusConfiguration |
| 35 | +type BusConfigurationSpec struct { |
| 36 | + Type string `json:"type"` |
| 37 | + |
| 38 | + SQS SQSSpec `json:"sqs"` |
| 39 | +} |
| 40 | + |
| 41 | +type SQSSpec struct { |
| 42 | + QueueName string `json:"queueName"` |
| 43 | + |
| 44 | + AuthRegion string `json:"authRegion"` |
| 45 | + |
| 46 | + Endpoint string `json:"endpoint"` |
| 47 | + |
| 48 | + LargeMessageStoreEndpoint string `json:"largeMessageStoreEndpoint"` |
| 49 | + |
| 50 | + LargeMessageStorePath string `json:"largeMessageStorePath"` |
| 51 | + |
| 52 | + DeadLetterQueueName string `json:"deadLetterQueueName"` |
| 53 | +} |
| 54 | + |
| 55 | +// BusConfigurationStatus defines the observed state of BusConfiguration. |
| 56 | +type BusConfigurationStatus struct { |
| 57 | + // Phase of the bus configuration |
| 58 | + Phase Phase `json:"phase"` |
| 59 | + |
| 60 | + // Resource revision tracker |
| 61 | + ResourceRevMap map[string]string `json:"resourceRevMap"` |
| 62 | + |
| 63 | + // Auxillary message describing CR status |
| 64 | + Message string `json:"message"` |
| 65 | +} |
| 66 | + |
| 67 | +// +kubebuilder:object:root=true |
| 68 | +// +kubebuilder:subresource:status |
| 69 | + |
| 70 | +// BusConfiguration is the Schema for a Splunk Enterprise bus configuration |
| 71 | +// +k8s:openapi-gen=true |
| 72 | +// +kubebuilder:subresource:status |
| 73 | +// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector |
| 74 | +// +kubebuilder:resource:path=busconfigurations,scope=Namespaced,shortName=bus |
| 75 | +// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="Status of bus configuration" |
| 76 | +// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age of bus configuration resource" |
| 77 | +// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.message",description="Auxillary message describing CR status" |
| 78 | +// +kubebuilder:storageversion |
| 79 | + |
| 80 | +// BusConfiguration is the Schema for the busconfigurations API |
| 81 | +type BusConfiguration struct { |
| 82 | + metav1.TypeMeta `json:",inline"` |
| 83 | + metav1.ObjectMeta `json:"metadata,omitempty,omitzero"` |
| 84 | + |
| 85 | + Spec BusConfigurationSpec `json:"spec"` |
| 86 | + Status BusConfigurationStatus `json:"status,omitempty,omitzero"` |
| 87 | +} |
| 88 | + |
| 89 | +// DeepCopyObject implements runtime.Object |
| 90 | +func (in *BusConfiguration) DeepCopyObject() runtime.Object { |
| 91 | + if c := in.DeepCopy(); c != nil { |
| 92 | + return c |
| 93 | + } |
| 94 | + return nil |
| 95 | +} |
| 96 | + |
| 97 | +// +kubebuilder:object:root=true |
| 98 | + |
| 99 | +// BusConfigurationList contains a list of BusConfiguration |
| 100 | +type BusConfigurationList struct { |
| 101 | + metav1.TypeMeta `json:",inline"` |
| 102 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 103 | + Items []BusConfiguration `json:"items"` |
| 104 | +} |
| 105 | + |
| 106 | +func init() { |
| 107 | + SchemeBuilder.Register(&BusConfiguration{}, &BusConfigurationList{}) |
| 108 | +} |
| 109 | + |
| 110 | +// NewEvent creates a new event associated with the object and ready |
| 111 | +// to be published to Kubernetes API |
| 112 | +func (bc *BusConfiguration) NewEvent(eventType, reason, message string) corev1.Event { |
| 113 | + t := metav1.Now() |
| 114 | + return corev1.Event{ |
| 115 | + ObjectMeta: metav1.ObjectMeta{ |
| 116 | + GenerateName: reason + "-", |
| 117 | + Namespace: bc.ObjectMeta.Namespace, |
| 118 | + }, |
| 119 | + InvolvedObject: corev1.ObjectReference{ |
| 120 | + Kind: "BusConfiguration", |
| 121 | + Namespace: bc.Namespace, |
| 122 | + Name: bc.Name, |
| 123 | + UID: bc.UID, |
| 124 | + APIVersion: GroupVersion.String(), |
| 125 | + }, |
| 126 | + Reason: reason, |
| 127 | + Message: message, |
| 128 | + Source: corev1.EventSource{ |
| 129 | + Component: "splunk-busconfiguration-controller", |
| 130 | + }, |
| 131 | + FirstTimestamp: t, |
| 132 | + LastTimestamp: t, |
| 133 | + Count: 1, |
| 134 | + Type: eventType, |
| 135 | + ReportingController: "enterprise.splunk.com/busconfiguration-controller", |
| 136 | + } |
| 137 | +} |
0 commit comments