Skip to content

Commit a64360d

Browse files
authored
Merge pull request #1027 from rabbitmq/examples-namespace
Document `examples` namespace in examples and small refactors
2 parents 9b84a28 + 8b3b56e commit a64360d

File tree

7 files changed

+30
-13
lines changed

7 files changed

+30
-13
lines changed

controllers/reconcile_persistence.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (r *RabbitmqClusterReconciler) reconcilePVC(ctx context.Context, rmq *rabbi
1818
err := scaling.NewPersistenceScaler(r.Clientset).Scale(ctx, *rmq, desiredCapacity)
1919
if err != nil {
2020
msg := fmt.Sprintf("Failed to scale PVCs: %s", err.Error())
21-
logger.Error(fmt.Errorf("Hit an error while scaling PVC capacity: %w", err), msg)
21+
logger.Error(fmt.Errorf("hit an error while scaling PVC capacity: %w", err), msg)
2222
r.Recorder.Event(rmq, corev1.EventTypeWarning, "FailedReconcilePersistence", msg)
2323
}
2424
return err

docs/examples/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ The test and setup scripts can assume that [Cert Manager](https://cert-manager.i
3737
There is also a cluster issuer to produce self-signed certificates, named `selfsigned-issuer`. It is also
3838
acceptable to create local `Issuer`s when needed.
3939

40+
### Namespace
41+
42+
Some examples in this folder default to namespace `examples`, which can be created by:
43+
44+
```shell
45+
kubectl create ns examples
46+
```
47+
48+
You can also replace the namespace with any existing namespace in your environment.

docs/examples/vault-default-user/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ This example requires:
2626
4. The RabbitMQ admin credentials were already written to Vault to path `spec.secretBackend.vault.defaultUserPath` with keys `username` and `password` (by some cluster-operator external mechanism. The cluster-operator will never write admin credentials to Vault).
2727
5. Role `spec.secretBackend.vault.role` is configured in Vault with a policy to read from `defaultUserPath`.
2828

29-
Run script [setup.sh](./setup.sh) to get started with a Vault server in [dev mode](https://www.vaultproject.io/docs/concepts/dev-server) fullfilling above requirements. (This script is not production-ready. It is only meant to get you started experiencing end-to-end how RabbitMQ integrates with Vault.)
29+
Run script [setup.sh](./setup.sh) to get started with a Vault server in [dev mode](https://www.vaultproject.io/docs/concepts/dev-server) fulfilling above requirements.
30+
[setup.sh](./setup.sh) assumes you are using namespace `examples`, which can be created by:
31+
32+
```shell
33+
kubectl create ns examples
34+
```
35+
36+
If you want to deploy this example in a different existing namespace, you can set environment variable `RABBITMQ_NAMESPACE` when you run the script.
37+
(This script is not production-ready. It is only meant to get you started experiencing end-to-end how RabbitMQ integrates with Vault.)
3038

3139
You can deploy this example like this:
3240

internal/metadata/annotation_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package metadata_test
33
import (
44
. "github.com/onsi/ginkgo/v2"
55
. "github.com/onsi/gomega"
6-
internal_metadata "github.com/rabbitmq/cluster-operator/internal/metadata"
6+
internalmetadata "github.com/rabbitmq/cluster-operator/internal/metadata"
77
)
88

99
var _ = Describe("Annotation", func() {
@@ -16,7 +16,7 @@ var _ = Describe("Annotation", func() {
1616

1717
DescribeTable("Reconcile annotations",
1818
func(expectedAnnotations map[string]string, existingAnnotations map[string]string, defaultAnnotations ...map[string]string) {
19-
reconciledAnnotations := internal_metadata.ReconcileAnnotations(existingAnnotations, defaultAnnotations...)
19+
reconciledAnnotations := internalmetadata.ReconcileAnnotations(existingAnnotations, defaultAnnotations...)
2020
Expect(reconciledAnnotations).To(Equal(expectedAnnotations))
2121
},
2222

@@ -55,7 +55,7 @@ var _ = Describe("Annotation", func() {
5555

5656
DescribeTable("Reconcile and filter annotations",
5757
func(expectedAnnotations map[string]string, existingAnnotations map[string]string, defaultAnnotations ...map[string]string) {
58-
reconciledAnnotations := internal_metadata.ReconcileAndFilterAnnotations(existingAnnotations, defaultAnnotations...)
58+
reconciledAnnotations := internalmetadata.ReconcileAndFilterAnnotations(existingAnnotations, defaultAnnotations...)
5959
Expect(reconciledAnnotations).To(Equal(expectedAnnotations))
6060
},
6161

internal/scaling/scaling.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (p PersistenceScaler) Scale(ctx context.Context, rmq rabbitmqv1beta1.Rabbit
3434

3535
existingCapacity, err := p.existingCapacity(ctx, rmq)
3636
if client.IgnoreNotFound(err) != nil {
37-
logErr := fmt.Errorf("Failed to determine existing STS capactiy: %w", err)
37+
logErr := fmt.Errorf("failed to determine existing STS capactiy: %w", err)
3838
logger.Error(logErr, "Could not read sts")
3939
return logErr
4040
}
@@ -65,7 +65,7 @@ func (p PersistenceScaler) Scale(ctx context.Context, rmq rabbitmqv1beta1.Rabbit
6565
logger.Info("Scaling up PVCs", "RabbitmqCluster", rmq.Name, "pvcsToBeScaled", pvcsToBeScaled)
6666

6767
if err := p.deleteSts(ctx, rmq); err != nil {
68-
logErr := fmt.Errorf("Failed to delete Statefulset from Kubernetes API: %w", err)
68+
logErr := fmt.Errorf("failed to delete Statefulset from Kubernetes API: %w", err)
6969
logger.Error(logErr, "Could not delete existing sts")
7070
return logErr
7171
}
@@ -82,7 +82,7 @@ func (p PersistenceScaler) getClusterPVCs(ctx context.Context, rmq rabbitmqv1bet
8282
for i = 0; i < pointer.Int32Deref(rmq.Spec.Replicas, 1); i++ {
8383
pvc, err := p.Client.CoreV1().PersistentVolumeClaims(rmq.Namespace).Get(ctx, rmq.PVCName(int(i)), metav1.GetOptions{})
8484
if client.IgnoreNotFound(err) != nil {
85-
logErr := fmt.Errorf("Failed to get PVC from Kubernetes API: %w", err)
85+
logErr := fmt.Errorf("failed to get PVC from Kubernetes API: %w", err)
8686
logger.Error(logErr, "Could not read existing PVC")
8787
return nil, logErr
8888
}
@@ -137,7 +137,7 @@ func (p PersistenceScaler) deleteSts(ctx context.Context, rmq rabbitmqv1beta1.Ra
137137

138138
sts, err := p.getSts(ctx, rmq)
139139
if client.IgnoreNotFound(err) != nil {
140-
logErr := fmt.Errorf("Failed to get statefulset from Kubernetes API: %w", err)
140+
logErr := fmt.Errorf("failed to get statefulset from Kubernetes API: %w", err)
141141
logger.Error(logErr, "Could not read existing statefulset")
142142
return logErr
143143
}
@@ -174,7 +174,7 @@ func (p PersistenceScaler) scaleUpPVCs(ctx context.Context, rmq rabbitmqv1beta1.
174174
// To minimise any timing windows, retrieve the latest version of this PVC before updating
175175
pvc, err := p.Client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(ctx, pvc.Name, metav1.GetOptions{})
176176
if err != nil {
177-
logErr := fmt.Errorf("Failed to get PVC from Kubernetes API: %w", err)
177+
logErr := fmt.Errorf("failed to get PVC from Kubernetes API: %w", err)
178178
logger.Error(logErr, "Could not read existing PVC")
179179
return logErr
180180
}

internal/scaling/scaling_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var (
4141
ephemeralStorage = k8sresource.MustParse("0")
4242
)
4343

44-
func generatePVCTemplate(rmq rabbitmqv1beta1.RabbitmqCluster, size k8sresource.Quantity) corev1.PersistentVolumeClaim {
44+
func generatePVCTemplate(size k8sresource.Quantity) corev1.PersistentVolumeClaim {
4545
return corev1.PersistentVolumeClaim{
4646
ObjectMeta: metav1.ObjectMeta{
4747
Name: "persistence",
@@ -201,7 +201,7 @@ func (matcher *UpdateActionMatcher) Match(actual interface{}) (bool, error) {
201201
updatedObject := reflect.ValueOf(action.GetObject()).Elem()
202202
objMeta, ok := updatedObject.FieldByName("ObjectMeta").Interface().(metav1.ObjectMeta)
203203
if !ok {
204-
return false, fmt.Errorf("Object of action was not an object with ObjectMeta")
204+
return false, fmt.Errorf("object of action was not an object with ObjectMeta")
205205
}
206206

207207
// Check the object's Name, Namespace, resource type and the verb of the action first. If this fails, there's

internal/scaling/scaling_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var _ = Describe("Scaling", func() {
3030
Namespace: namespace,
3131
},
3232
Spec: appsv1.StatefulSetSpec{
33-
VolumeClaimTemplates: []corev1.PersistentVolumeClaim{generatePVCTemplate(rmq, tenG)},
33+
VolumeClaimTemplates: []corev1.PersistentVolumeClaim{generatePVCTemplate(tenG)},
3434
},
3535
}
3636
})

0 commit comments

Comments
 (0)