Skip to content

Commit e667e86

Browse files
authored
Autogenerate API Reference Documentation (#546)
This PR allows auto generation of the API Reference documentation from the api/ directory in the repo. Running make api-reference, or any other make target that requires auto generation of code, will cause the reference docs to be regenerated. They now live at docs/api/rabbitmq.com.ref.asciidoc. This format can be interpreted by GitHub and rendered as HTML. Allowing this documentation to be autogenerated will prevent API elements/descriptions being updated without the API reference docs being updated alongside. This PR also includes a GitHub Action to take the generated Asciidoc and insert it into our GitHub Wiki, so that our API reference is neatly packaged together with the source code.
1 parent d348dce commit e667e86

File tree

13 files changed

+723
-45
lines changed

13 files changed

+723
-45
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "Update API Reference Wiki page"
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
update-api-reference:
9+
name: Update API Reference Wiki
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout operator codebase
14+
uses: actions/checkout@v2
15+
with:
16+
path: cluster-operator
17+
- name: Checkout wiki codebase
18+
uses: actions/checkout@v2
19+
with:
20+
repository: ${{ github.repository }}.wiki
21+
path: wiki
22+
- name: Push to wiki
23+
run: |
24+
cd wiki
25+
git config --local user.email "[email protected]"
26+
git config --local user.name "github-actions"
27+
cp ../cluster-operator/docs/api/rabbitmq.com.ref.asciidoc ./API_Reference.asciidoc
28+
git add .
29+
git diff-index --quiet HEAD || git commit -m "Update API Reference" && git push

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ manifests: install-tools ## Generate manifests e.g. CRD, RBAC etc.
2323
./hack/add-notice-to-yaml.sh config/rbac/role.yaml
2424
./hack/add-notice-to-yaml.sh config/crd/bases/rabbitmq.com_rabbitmqclusters.yaml
2525

26+
api-reference: install-tools ## Generate API reference documentation
27+
crd-ref-docs \
28+
--source-path ./api/v1beta1 \
29+
--config ./docs/api/autogen/config.yaml \
30+
--templates-dir ./docs/api/autogen/templates \
31+
--output-path ./docs/api/rabbitmq.com.ref.asciidoc \
32+
--max-depth 30
33+
2634
# Run go fmt against code
2735
fmt:
2836
go fmt ./...
@@ -31,8 +39,8 @@ fmt:
3139
vet:
3240
go vet ./...
3341

34-
# Generate code
35-
generate: install-tools
42+
# Generate code & docs
43+
generate: install-tools api-reference
3644
controller-gen object:headerFile=./hack/NOTICE.go.txt paths=./api/...
3745
controller-gen object:headerFile=./hack/NOTICE.go.txt paths=./internal/status/...
3846

api/v1beta1/rabbitmqcluster_types.go

Lines changed: 76 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,60 @@ import (
2222

2323
// +kubebuilder:object:root=true
2424

25-
// RabbitmqCluster is the Schema for the rabbitmqclusters API
25+
// RabbitmqCluster is the Schema for the RabbitmqCluster API. Each instance of this object
26+
// corresponds to a single RabbitMQ cluster.
2627
// +kubebuilder:subresource:status
2728
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
2829
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.clusterStatus"
2930
// +kubebuilder:resource:shortName={"rmq"}
3031
type RabbitmqCluster struct {
32+
// Embedded metadata identifying a Kind and API Verison of an object.
33+
// For more info, see: https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#TypeMeta
3134
metav1.TypeMeta `json:",inline"`
3235
metav1.ObjectMeta `json:"metadata,omitempty"`
3336

34-
Spec RabbitmqClusterSpec `json:"spec,omitempty"`
37+
// Spec is the desired state of the RabbitmqCluster Custom Resource.
38+
Spec RabbitmqClusterSpec `json:"spec,omitempty"`
39+
// Status presents the observed state of RabbitmqCluster
3540
Status RabbitmqClusterStatus `json:"status,omitempty"`
3641
}
3742

3843
// Spec is the desired state of the RabbitmqCluster Custom Resource.
3944
type RabbitmqClusterSpec struct {
4045
// Replicas is the number of nodes in the RabbitMQ cluster. Each node is deployed as a Replica in a StatefulSet. Only 1, 3, 5 replicas clusters are tested.
46+
// This value should be an odd number to ensure the resultant cluster can establish exactly one quorum of nodes
47+
// in the event of a fragmenting network partition.
4148
// +optional
4249
// +kubebuilder:validation:Minimum:=0
4350
// +kubebuilder:default:=1
4451
Replicas *int32 `json:"replicas,omitempty"`
4552
// Image is the name of the RabbitMQ docker image to use for RabbitMQ nodes in the RabbitmqCluster.
53+
// Must be provided together with ImagePullSecrets in order to use an image in a private registry.
4654
// +kubebuilder:default:="rabbitmq:3.8.9-management"
4755
Image string `json:"image,omitempty"`
4856
// List of Secret resource containing access credentials to the registry for the RabbitMQ image. Required if the docker registry is private.
4957
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
58+
// The desired state of the Kubernetes Service to create for the cluster.
5059
// +kubebuilder:default:={type: "ClusterIP"}
5160
Service RabbitmqClusterServiceSpec `json:"service,omitempty"`
61+
// The desired persistent storage configuration for each Pod in the cluster.
5262
// +kubebuilder:default:={storage: "10Gi"}
5363
Persistence RabbitmqClusterPersistenceSpec `json:"persistence,omitempty"`
64+
// The desired compute resource requirements of Pods in the cluster.
5465
// +kubebuilder:default:={limits: {cpu: "2000m", memory: "2Gi"}, requests: {cpu: "1000m", memory: "2Gi"}}
5566
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
56-
Affinity *corev1.Affinity `json:"affinity,omitempty"`
67+
// Affinity scheduling rules to be applied on created Pods.
68+
Affinity *corev1.Affinity `json:"affinity,omitempty"`
5769
// Tolerations is the list of Toleration resources attached to each Pod in the RabbitmqCluster.
58-
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
59-
Rabbitmq RabbitmqClusterConfigurationSpec `json:"rabbitmq,omitempty"`
60-
TLS TLSSpec `json:"tls,omitempty"`
61-
Override RabbitmqClusterOverrideSpec `json:"override,omitempty"`
70+
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
71+
// Configuration options for RabbitMQ Pods created in the cluster.
72+
Rabbitmq RabbitmqClusterConfigurationSpec `json:"rabbitmq,omitempty"`
73+
// TLS-related configuration for the RabbitMQ cluster.
74+
TLS TLSSpec `json:"tls,omitempty"`
75+
// Provides the ability to override the generated manifest of several child resources.
76+
Override RabbitmqClusterOverrideSpec `json:"override,omitempty"`
6277
// If unset, or set to false, the cluster will run `rabbitmq-queues rebalance all` whenever the cluster is updated.
78+
// Set to true to prevent the operator rebalancing queue leaders after a cluster update.
6379
// Has no effect if the cluster only consists of one node.
6480
// For more information, see https://www.rabbitmq.com/rabbitmq-queues.8.html#rebalance
6581
SkipPostDeploySteps bool `json:"skipPostDeploySteps,omitempty"`
@@ -71,20 +87,27 @@ type RabbitmqClusterSpec struct {
7187
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
7288
}
7389

90+
// Provides the ability to override the generated manifest of several child resources.
7491
type RabbitmqClusterOverrideSpec struct {
92+
// Override configuration for the RabbitMQ StatefulSet.
7593
StatefulSet *StatefulSet `json:"statefulSet,omitempty"`
76-
Service *Service `json:"service,omitempty"`
94+
// Override configuration for the Service created to serve traffic to the cluster.
95+
Service *Service `json:"service,omitempty"`
7796
}
7897

98+
// Override configuration for the Service created to serve traffic to the cluster.
99+
// Allows for the manifest of the created Service to be overwritten with custom configuration.
79100
type Service struct {
80101
// +optional
81102
*EmbeddedLabelsAnnotations `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
82-
// Spec defines the behavior of a service.
103+
// Spec defines the behavior of a Service.
83104
// https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
84105
// +optional
85106
Spec *corev1.ServiceSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
86107
}
87108

109+
// Override configuration for the RabbitMQ StatefulSet.
110+
// Allows for the manifest of the created StatefulSet to be overwritten with custom configuration.
88111
type StatefulSet struct {
89112
// +optional
90113
*EmbeddedLabelsAnnotations `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
@@ -97,9 +120,8 @@ type StatefulSet struct {
97120
// Field RevisionHistoryLimit is omitted.
98121
// Every field is made optional.
99122
type StatefulSetSpec struct {
100-
// replicas is the desired number of replicas of the given Template.
101-
// These are replicas in the sense that they are instantiations of the
102-
// same Template, but individual replicas also have a consistent identity.
123+
// replicas corresponds to the desired number of Pods in the StatefulSet.
124+
// For more info, see https://pkg.go.dev/k8s.io/api/apps/v1#StatefulSetSpec
103125
// +optional
104126
Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"`
105127

@@ -151,7 +173,8 @@ type StatefulSetSpec struct {
151173
UpdateStrategy *appsv1.StatefulSetUpdateStrategy `json:"updateStrategy,omitempty" protobuf:"bytes,7,opt,name=updateStrategy"`
152174
}
153175

154-
// It is used in Service and StatefulSet
176+
// EmbeddedLabelsAnnotations is an embedded subset of the fields included in k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta.
177+
// Only labels and annotations are included.
155178
type EmbeddedLabelsAnnotations struct {
156179
// Map of string keys and values that can be used to organize and categorize
157180
// (scope and select) objects. May match selectors of replication controllers
@@ -168,9 +191,8 @@ type EmbeddedLabelsAnnotations struct {
168191
Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,12,rep,name=annotations"`
169192
}
170193

171-
// EmbeddedObjectMeta contains a subset of the fields included in k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta
194+
// EmbeddedObjectMeta is an embedded subset of the fields included in k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta.
172195
// Only fields which are relevant to embedded resources are included.
173-
// It is used in PersistentVolumeClaim and PodTemplate
174196
type EmbeddedObjectMeta struct {
175197
// Name must be unique within a namespace. Is required when creating resources, although
176198
// some resources may allow a client to request the generation of an appropriate name
@@ -223,6 +245,8 @@ type PodTemplateSpec struct {
223245
// It contains TypeMeta and a reduced ObjectMeta.
224246
// Field status is omitted.
225247
type PersistentVolumeClaim struct {
248+
// Embedded metadata identifying a Kind and API Verison of an object.
249+
// For more info, see: https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#TypeMeta
226250
metav1.TypeMeta `json:",inline"`
227251
// +optional
228252
EmbeddedObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
@@ -233,12 +257,15 @@ type PersistentVolumeClaim struct {
233257
Spec corev1.PersistentVolumeClaimSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
234258
}
235259

260+
// Allows for the configuration of TLS certificates to be used by RabbitMQ. Also allows for non-TLS traffic to be disabled.
236261
type TLSSpec struct {
237262
// Name of a Secret in the same Namespace as the RabbitmqCluster, containing the server's private key & public certificate for TLS.
238263
// The Secret must store these as tls.key and tls.crt, respectively.
264+
// This Secret can be created by running `kubectl create secret tls tls-secret --cert=path/to/tls.cert --key=path/to/tls.key`
239265
SecretName string `json:"secretName,omitempty"`
240266
// Name of a Secret in the same Namespace as the RabbitmqCluster, containing the Certificate Authority's public certificate for TLS.
241267
// The Secret must store this as ca.crt.
268+
// This Secret can be created by running `kubectl create secret generic ca-secret --from-file=ca.crt=path/to/ca.cert`
242269
// Used for mTLS, and TLS for rabbitmq_web_stomp and rabbitmq_web_mqtt.
243270
CaSecretName string `json:"caSecretName,omitempty"`
244271
// When set to true, the RabbitmqCluster disables non-TLS listeners for RabbitMQ, management plugin and for any enabled plugins in the following list: stomp, mqtt, web_stomp, web_mqtt.
@@ -252,33 +279,41 @@ type TLSSpec struct {
252279
// +kubebuilder:validation:MaxLength=100
253280
type Plugin string
254281

255-
// Rabbitmq related configurations
282+
// RabbitMQ-related configuration.
256283
type RabbitmqClusterConfigurationSpec struct {
257284
// List of plugins to enable in addition to essential plugins: rabbitmq_management, rabbitmq_prometheus, and rabbitmq_peer_discovery_k8s.
258285
// +kubebuilder:validation:MaxItems:=100
259286
AdditionalPlugins []Plugin `json:"additionalPlugins,omitempty"`
260-
// Modify to add to the rabbitmq.conf file in addition to default configurations set by the operator. Modifying this property on an existing RabbitmqCluster will trigger a StatefulSet rolling restart and will cause rabbitmq downtime.
287+
// Modify to add to the rabbitmq.conf file in addition to default configurations set by the operator.
288+
// Modifying this property on an existing RabbitmqCluster will trigger a StatefulSet rolling restart and will cause rabbitmq downtime.
289+
// For more information on this config, see https://www.rabbitmq.com/configure.html#config-file
261290
// +kubebuilder:validation:MaxLength:=2000
262291
AdditionalConfig string `json:"additionalConfig,omitempty"`
263-
// Specify any rabbitmq advanced.config configurations
292+
// Specify any rabbitmq advanced.config configurations to apply to the cluster.
293+
// For more information on advanced config, see https://www.rabbitmq.com/configure.html#advanced-config-file
264294
// +kubebuilder:validation:MaxLength:=100000
265295
AdvancedConfig string `json:"advancedConfig,omitempty"`
266296
// Modify to add to the rabbitmq-env.conf file. Modifying this property on an existing RabbitmqCluster will trigger a StatefulSet rolling restart and will cause rabbitmq downtime.
297+
// For more information on env config, see https://www.rabbitmq.com/man/rabbitmq-env.conf.5.html
267298
// +kubebuilder:validation:MaxLength:=100000
268299
EnvConfig string `json:"envConfig,omitempty"`
269300
}
270301

271302
// The settings for the persistent storage desired for each Pod in the RabbitmqCluster.
272303
type RabbitmqClusterPersistenceSpec struct {
273-
// StorageClassName is the name of the StorageClass to claim a PersistentVolume from.
304+
// The name of the StorageClass to claim a PersistentVolume from.
274305
StorageClassName *string `json:"storageClassName,omitempty"`
275306
// The requested size of the persistent volume attached to each Pod in the RabbitmqCluster.
307+
// The format of this field matches that defined by kubernetes/apimachinery.
308+
// See https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity for more info on the format of this field.
276309
// +kubebuilder:default:="10Gi"
277310
Storage *k8sresource.Quantity `json:"storage,omitempty"`
278311
}
279312

280313
// Settable attributes for the Service resource.
281314
type RabbitmqClusterServiceSpec struct {
315+
// Type of Service to create for the cluster. Must be one of: ClusterIP, LoadBalancer, NodePort.
316+
// For more info see https://pkg.go.dev/k8s.io/api/core/v1#ServiceType
282317
// +kubebuilder:validation:Enum=ClusterIP;LoadBalancer;NodePort
283318
// +kubebuilder:default:="ClusterIP"
284319
Type corev1.ServiceType `json:"type,omitempty"`
@@ -288,6 +323,7 @@ type RabbitmqClusterServiceSpec struct {
288323

289324
// Status presents the observed state of RabbitmqCluster
290325
type RabbitmqClusterStatus struct {
326+
// Unused.
291327
ClusterStatus string `json:"clusterStatus,omitempty"`
292328
// Set of Conditions describing the current state of the RabbitmqCluster
293329
Conditions []status.RabbitmqClusterCondition `json:"conditions"`
@@ -296,19 +332,30 @@ type RabbitmqClusterStatus struct {
296332
DefaultUser *RabbitmqClusterDefaultUser `json:"defaultUser,omitempty"`
297333
}
298334

335+
// Contains references to resources created with the RabbitmqCluster resource.
299336
type RabbitmqClusterDefaultUser struct {
300-
SecretReference *RabbitmqClusterSecretReference `json:"secretReference,omitempty"`
337+
// Reference to the Kubernetes Secret containing the credentials of the default
338+
// user.
339+
SecretReference *RabbitmqClusterSecretReference `json:"secretReference,omitempty"`
340+
// Reference to the Kubernetes Service serving the cluster.
301341
ServiceReference *RabbitmqClusterServiceReference `json:"serviceReference,omitempty"`
302342
}
303343

344+
// Reference to the Kubernetes Secret containing the credentials of the default user.
304345
type RabbitmqClusterSecretReference struct {
305-
Name string `json:"name"`
306-
Namespace string `json:"namespace"`
307-
Keys map[string]string `json:"keys"`
346+
// Name of the Secret containing the default user credentials
347+
Name string `json:"name"`
348+
// Namespace of the Secret containing the default user credentials
349+
Namespace string `json:"namespace"`
350+
// Key-value pairs in the Secret corresponding to `username` and `password`
351+
Keys map[string]string `json:"keys"`
308352
}
309353

354+
// Reference to the Kubernetes Service serving the cluster.
310355
type RabbitmqClusterServiceReference struct {
311-
Name string `json:"name"`
356+
// Name of the Service serving the cluster
357+
Name string `json:"name"`
358+
// Namespace of the Service serving the cluster
312359
Namespace string `json:"namespace"`
313360
}
314361

@@ -392,11 +439,14 @@ func (clusterStatus *RabbitmqClusterStatus) SetCondition(condType status.Rabbitm
392439

393440
// +kubebuilder:object:root=true
394441

395-
// RabbitmqClusterList contains a list of RabbitmqCluster
442+
// RabbitmqClusterList contains a list of RabbitmqClusters.
396443
type RabbitmqClusterList struct {
444+
// Embedded metadata identifying a Kind and API Verison of an object.
445+
// For more info, see: https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#TypeMeta
397446
metav1.TypeMeta `json:",inline"`
398447
metav1.ListMeta `json:"metadata,omitempty"`
399-
Items []RabbitmqCluster `json:"items"`
448+
// Array of RabbitmqCluster resources.
449+
Items []RabbitmqCluster `json:"items"`
400450
}
401451

402452
func (cluster RabbitmqCluster) ChildResourceName(name string) string {

0 commit comments

Comments
 (0)