Skip to content

Commit d04724e

Browse files
authored
Merge pull request #683 from rabbitmq/builder
Use embedded field in ResourceBuilder structs
2 parents 61e9619 + f3ba234 commit d04724e

File tree

10 files changed

+28
-77
lines changed

10 files changed

+28
-77
lines changed

internal/resource/configmap.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ import (
1919

2020
"gopkg.in/ini.v1"
2121

22-
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
2322
"github.com/rabbitmq/cluster-operator/internal/metadata"
2423
corev1 "k8s.io/api/core/v1"
2524
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26-
"k8s.io/apimachinery/pkg/runtime"
2725
)
2826

2927
const (
@@ -57,15 +55,11 @@ prometheus.ssl.port = 15691
5755
)
5856

5957
type ServerConfigMapBuilder struct {
60-
Instance *rabbitmqv1beta1.RabbitmqCluster
61-
Scheme *runtime.Scheme
58+
*RabbitmqResourceBuilder
6259
}
6360

6461
func (builder *RabbitmqResourceBuilder) ServerConfigMap() *ServerConfigMapBuilder {
65-
return &ServerConfigMapBuilder{
66-
Instance: builder.Instance,
67-
Scheme: builder.Scheme,
68-
}
62+
return &ServerConfigMapBuilder{builder}
6963
}
7064

7165
func (builder *ServerConfigMapBuilder) Build() (client.Object, error) {

internal/resource/default_user_secret.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ package resource
1212
import (
1313
"bytes"
1414
"fmt"
15+
1516
"sigs.k8s.io/controller-runtime/pkg/client"
1617

1718
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1819

19-
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
2020
"github.com/rabbitmq/cluster-operator/internal/metadata"
2121
"gopkg.in/ini.v1"
2222
corev1 "k8s.io/api/core/v1"
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24-
"k8s.io/apimachinery/pkg/runtime"
2524
)
2625

2726
const (
@@ -31,15 +30,11 @@ const (
3130
)
3231

3332
type DefaultUserSecretBuilder struct {
34-
Instance *rabbitmqv1beta1.RabbitmqCluster
35-
Scheme *runtime.Scheme
33+
*RabbitmqResourceBuilder
3634
}
3735

3836
func (builder *RabbitmqResourceBuilder) DefaultUserSecret() *DefaultUserSecretBuilder {
39-
return &DefaultUserSecretBuilder{
40-
Instance: builder.Instance,
41-
Scheme: builder.Scheme,
42-
}
37+
return &DefaultUserSecretBuilder{builder}
4338
}
4439

4540
func (builder *DefaultUserSecretBuilder) Build() (client.Object, error) {

internal/resource/erlang_cookie.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,25 @@ import (
1313
"crypto/rand"
1414
"encoding/base64"
1515
"fmt"
16+
1617
"sigs.k8s.io/controller-runtime/pkg/client"
1718
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1819

19-
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
2020
"github.com/rabbitmq/cluster-operator/internal/metadata"
2121
corev1 "k8s.io/api/core/v1"
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23-
"k8s.io/apimachinery/pkg/runtime"
2423
)
2524

2625
const (
2726
erlangCookieName = "erlang-cookie"
2827
)
2928

3029
type ErlangCookieBuilder struct {
31-
Instance *rabbitmqv1beta1.RabbitmqCluster
32-
Scheme *runtime.Scheme
30+
*RabbitmqResourceBuilder
3331
}
3432

3533
func (builder *RabbitmqResourceBuilder) ErlangCookie() *ErlangCookieBuilder {
36-
return &ErlangCookieBuilder{
37-
Instance: builder.Instance,
38-
Scheme: builder.Scheme,
39-
}
34+
return &ErlangCookieBuilder{builder}
4035
}
4136

4237
func (builder *ErlangCookieBuilder) Build() (client.Object, error) {

internal/resource/headless_service.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ package resource
1111

1212
import (
1313
"fmt"
14+
1415
"sigs.k8s.io/controller-runtime/pkg/client"
1516

16-
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
1717
"github.com/rabbitmq/cluster-operator/internal/metadata"
1818
corev1 "k8s.io/api/core/v1"
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20-
"k8s.io/apimachinery/pkg/runtime"
2120
"k8s.io/apimachinery/pkg/util/intstr"
2221
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2322
)
@@ -27,15 +26,11 @@ const (
2726
)
2827

2928
type HeadlessServiceBuilder struct {
30-
Instance *rabbitmqv1beta1.RabbitmqCluster
31-
Scheme *runtime.Scheme
29+
*RabbitmqResourceBuilder
3230
}
3331

3432
func (builder *RabbitmqResourceBuilder) HeadlessService() *HeadlessServiceBuilder {
35-
return &HeadlessServiceBuilder{
36-
Instance: builder.Instance,
37-
Scheme: builder.Scheme,
38-
}
33+
return &HeadlessServiceBuilder{builder}
3934
}
4035

4136
func (builder *HeadlessServiceBuilder) UpdateMayRequireStsRecreate() bool {

internal/resource/rabbitmq_plugins.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package resource
22

33
import (
44
"fmt"
5-
"sigs.k8s.io/controller-runtime/pkg/client"
65
"strings"
76

7+
"sigs.k8s.io/controller-runtime/pkg/client"
8+
89
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
910

1011
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
1112
"github.com/rabbitmq/cluster-operator/internal/metadata"
1213
corev1 "k8s.io/api/core/v1"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14-
"k8s.io/apimachinery/pkg/runtime"
1515
)
1616

1717
var requiredPlugins = []string{
@@ -23,15 +23,11 @@ var requiredPlugins = []string{
2323
const PluginsConfigName = "plugins-conf"
2424

2525
type RabbitmqPluginsConfigMapBuilder struct {
26-
Instance *rabbitmqv1beta1.RabbitmqCluster
27-
Scheme *runtime.Scheme
26+
*RabbitmqResourceBuilder
2827
}
2928

3029
func (builder *RabbitmqResourceBuilder) RabbitmqPluginsConfigMap() *RabbitmqPluginsConfigMapBuilder {
31-
return &RabbitmqPluginsConfigMapBuilder{
32-
Instance: builder.Instance,
33-
Scheme: builder.Scheme,
34-
}
30+
return &RabbitmqPluginsConfigMapBuilder{builder}
3531
}
3632

3733
func (builder *RabbitmqPluginsConfigMapBuilder) Build() (client.Object, error) {

internal/resource/role.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ package resource
1111

1212
import (
1313
"fmt"
14+
1415
"sigs.k8s.io/controller-runtime/pkg/client"
1516

16-
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
1717
"github.com/rabbitmq/cluster-operator/internal/metadata"
1818
rbacv1 "k8s.io/api/rbac/v1"
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20-
"k8s.io/apimachinery/pkg/runtime"
2120
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2221
)
2322

@@ -26,15 +25,11 @@ const (
2625
)
2726

2827
type RoleBuilder struct {
29-
Instance *rabbitmqv1beta1.RabbitmqCluster
30-
Scheme *runtime.Scheme
28+
*RabbitmqResourceBuilder
3129
}
3230

3331
func (builder *RabbitmqResourceBuilder) Role() *RoleBuilder {
34-
return &RoleBuilder{
35-
Instance: builder.Instance,
36-
Scheme: builder.Scheme,
37-
}
32+
return &RoleBuilder{builder}
3833
}
3934

4035
func (builder *RoleBuilder) Build() (client.Object, error) {

internal/resource/role_binding.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ package resource
1111

1212
import (
1313
"fmt"
14+
1415
rbacv1 "k8s.io/api/rbac/v1"
1516
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16-
"k8s.io/apimachinery/pkg/runtime"
1717
"sigs.k8s.io/controller-runtime/pkg/client"
1818
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1919

20-
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
2120
"github.com/rabbitmq/cluster-operator/internal/metadata"
2221
)
2322

@@ -26,15 +25,11 @@ const (
2625
)
2726

2827
type RoleBindingBuilder struct {
29-
Instance *rabbitmqv1beta1.RabbitmqCluster
30-
Scheme *runtime.Scheme
28+
*RabbitmqResourceBuilder
3129
}
3230

3331
func (builder *RabbitmqResourceBuilder) RoleBinding() *RoleBindingBuilder {
34-
return &RoleBindingBuilder{
35-
Instance: builder.Instance,
36-
Scheme: builder.Scheme,
37-
}
32+
return &RoleBindingBuilder{builder}
3833
}
3934

4035
func (builder *RoleBindingBuilder) UpdateMayRequireStsRecreate() bool {

internal/resource/service.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/rabbitmq/cluster-operator/internal/metadata"
2323
corev1 "k8s.io/api/core/v1"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25-
"k8s.io/apimachinery/pkg/runtime"
2625
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2726
)
2827

@@ -31,15 +30,11 @@ const (
3130
)
3231

3332
type ServiceBuilder struct {
34-
Instance *rabbitmqv1beta1.RabbitmqCluster
35-
Scheme *runtime.Scheme
33+
*RabbitmqResourceBuilder
3634
}
3735

3836
func (builder *RabbitmqResourceBuilder) Service() *ServiceBuilder {
39-
return &ServiceBuilder{
40-
Instance: builder.Instance,
41-
Scheme: builder.Scheme,
42-
}
37+
return &ServiceBuilder{builder}
4338
}
4439

4540
func (builder *ServiceBuilder) Build() (client.Object, error) {

internal/resource/service_account.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ package resource
1111

1212
import (
1313
"fmt"
14+
1415
"sigs.k8s.io/controller-runtime/pkg/client"
1516

16-
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
1717
"github.com/rabbitmq/cluster-operator/internal/metadata"
1818
corev1 "k8s.io/api/core/v1"
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20-
"k8s.io/apimachinery/pkg/runtime"
2120
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2221
)
2322

@@ -26,15 +25,11 @@ const (
2625
)
2726

2827
type ServiceAccountBuilder struct {
29-
Instance *rabbitmqv1beta1.RabbitmqCluster
30-
Scheme *runtime.Scheme
28+
*RabbitmqResourceBuilder
3129
}
3230

3331
func (builder *RabbitmqResourceBuilder) ServiceAccount() *ServiceAccountBuilder {
34-
return &ServiceAccountBuilder{
35-
Instance: builder.Instance,
36-
Scheme: builder.Scheme,
37-
}
32+
return &ServiceAccountBuilder{builder}
3833
}
3934

4035
func (builder *ServiceAccountBuilder) Build() (client.Object, error) {

internal/resource/statefulset.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,11 @@ const (
3838
)
3939

4040
type StatefulSetBuilder struct {
41-
Instance *rabbitmqv1beta1.RabbitmqCluster
42-
Scheme *runtime.Scheme
41+
*RabbitmqResourceBuilder
4342
}
4443

4544
func (builder *RabbitmqResourceBuilder) StatefulSet() *StatefulSetBuilder {
46-
return &StatefulSetBuilder{
47-
Instance: builder.Instance,
48-
Scheme: builder.Scheme,
49-
}
45+
return &StatefulSetBuilder{builder}
5046
}
5147

5248
func (builder *StatefulSetBuilder) Build() (client.Object, error) {

0 commit comments

Comments
 (0)