Skip to content

Commit

Permalink
Merge pull request #683 from rabbitmq/builder
Browse files Browse the repository at this point in the history
Use embedded field in ResourceBuilder structs
  • Loading branch information
ansd authored May 10, 2021
2 parents 61e9619 + f3ba234 commit d04724e
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 77 deletions.
10 changes: 2 additions & 8 deletions internal/resource/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import (

"gopkg.in/ini.v1"

rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
"github.com/rabbitmq/cluster-operator/internal/metadata"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

const (
Expand Down Expand Up @@ -57,15 +55,11 @@ prometheus.ssl.port = 15691
)

type ServerConfigMapBuilder struct {
Instance *rabbitmqv1beta1.RabbitmqCluster
Scheme *runtime.Scheme
*RabbitmqResourceBuilder
}

func (builder *RabbitmqResourceBuilder) ServerConfigMap() *ServerConfigMapBuilder {
return &ServerConfigMapBuilder{
Instance: builder.Instance,
Scheme: builder.Scheme,
}
return &ServerConfigMapBuilder{builder}
}

func (builder *ServerConfigMapBuilder) Build() (client.Object, error) {
Expand Down
11 changes: 3 additions & 8 deletions internal/resource/default_user_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ package resource
import (
"bytes"
"fmt"

"sigs.k8s.io/controller-runtime/pkg/client"

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

rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
"github.com/rabbitmq/cluster-operator/internal/metadata"
"gopkg.in/ini.v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

const (
Expand All @@ -31,15 +30,11 @@ const (
)

type DefaultUserSecretBuilder struct {
Instance *rabbitmqv1beta1.RabbitmqCluster
Scheme *runtime.Scheme
*RabbitmqResourceBuilder
}

func (builder *RabbitmqResourceBuilder) DefaultUserSecret() *DefaultUserSecretBuilder {
return &DefaultUserSecretBuilder{
Instance: builder.Instance,
Scheme: builder.Scheme,
}
return &DefaultUserSecretBuilder{builder}
}

func (builder *DefaultUserSecretBuilder) Build() (client.Object, error) {
Expand Down
11 changes: 3 additions & 8 deletions internal/resource/erlang_cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,25 @@ import (
"crypto/rand"
"encoding/base64"
"fmt"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
"github.com/rabbitmq/cluster-operator/internal/metadata"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

const (
erlangCookieName = "erlang-cookie"
)

type ErlangCookieBuilder struct {
Instance *rabbitmqv1beta1.RabbitmqCluster
Scheme *runtime.Scheme
*RabbitmqResourceBuilder
}

func (builder *RabbitmqResourceBuilder) ErlangCookie() *ErlangCookieBuilder {
return &ErlangCookieBuilder{
Instance: builder.Instance,
Scheme: builder.Scheme,
}
return &ErlangCookieBuilder{builder}
}

func (builder *ErlangCookieBuilder) Build() (client.Object, error) {
Expand Down
11 changes: 3 additions & 8 deletions internal/resource/headless_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ package resource

import (
"fmt"

"sigs.k8s.io/controller-runtime/pkg/client"

rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
"github.com/rabbitmq/cluster-operator/internal/metadata"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)
Expand All @@ -27,15 +26,11 @@ const (
)

type HeadlessServiceBuilder struct {
Instance *rabbitmqv1beta1.RabbitmqCluster
Scheme *runtime.Scheme
*RabbitmqResourceBuilder
}

func (builder *RabbitmqResourceBuilder) HeadlessService() *HeadlessServiceBuilder {
return &HeadlessServiceBuilder{
Instance: builder.Instance,
Scheme: builder.Scheme,
}
return &HeadlessServiceBuilder{builder}
}

func (builder *HeadlessServiceBuilder) UpdateMayRequireStsRecreate() bool {
Expand Down
12 changes: 4 additions & 8 deletions internal/resource/rabbitmq_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package resource

import (
"fmt"
"sigs.k8s.io/controller-runtime/pkg/client"
"strings"

"sigs.k8s.io/controller-runtime/pkg/client"

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

rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
"github.com/rabbitmq/cluster-operator/internal/metadata"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

var requiredPlugins = []string{
Expand All @@ -23,15 +23,11 @@ var requiredPlugins = []string{
const PluginsConfigName = "plugins-conf"

type RabbitmqPluginsConfigMapBuilder struct {
Instance *rabbitmqv1beta1.RabbitmqCluster
Scheme *runtime.Scheme
*RabbitmqResourceBuilder
}

func (builder *RabbitmqResourceBuilder) RabbitmqPluginsConfigMap() *RabbitmqPluginsConfigMapBuilder {
return &RabbitmqPluginsConfigMapBuilder{
Instance: builder.Instance,
Scheme: builder.Scheme,
}
return &RabbitmqPluginsConfigMapBuilder{builder}
}

func (builder *RabbitmqPluginsConfigMapBuilder) Build() (client.Object, error) {
Expand Down
11 changes: 3 additions & 8 deletions internal/resource/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ package resource

import (
"fmt"

"sigs.k8s.io/controller-runtime/pkg/client"

rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
"github.com/rabbitmq/cluster-operator/internal/metadata"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

Expand All @@ -26,15 +25,11 @@ const (
)

type RoleBuilder struct {
Instance *rabbitmqv1beta1.RabbitmqCluster
Scheme *runtime.Scheme
*RabbitmqResourceBuilder
}

func (builder *RabbitmqResourceBuilder) Role() *RoleBuilder {
return &RoleBuilder{
Instance: builder.Instance,
Scheme: builder.Scheme,
}
return &RoleBuilder{builder}
}

func (builder *RoleBuilder) Build() (client.Object, error) {
Expand Down
11 changes: 3 additions & 8 deletions internal/resource/role_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ package resource

import (
"fmt"

rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
"github.com/rabbitmq/cluster-operator/internal/metadata"
)

Expand All @@ -26,15 +25,11 @@ const (
)

type RoleBindingBuilder struct {
Instance *rabbitmqv1beta1.RabbitmqCluster
Scheme *runtime.Scheme
*RabbitmqResourceBuilder
}

func (builder *RabbitmqResourceBuilder) RoleBinding() *RoleBindingBuilder {
return &RoleBindingBuilder{
Instance: builder.Instance,
Scheme: builder.Scheme,
}
return &RoleBindingBuilder{builder}
}

func (builder *RoleBindingBuilder) UpdateMayRequireStsRecreate() bool {
Expand Down
9 changes: 2 additions & 7 deletions internal/resource/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/rabbitmq/cluster-operator/internal/metadata"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

Expand All @@ -31,15 +30,11 @@ const (
)

type ServiceBuilder struct {
Instance *rabbitmqv1beta1.RabbitmqCluster
Scheme *runtime.Scheme
*RabbitmqResourceBuilder
}

func (builder *RabbitmqResourceBuilder) Service() *ServiceBuilder {
return &ServiceBuilder{
Instance: builder.Instance,
Scheme: builder.Scheme,
}
return &ServiceBuilder{builder}
}

func (builder *ServiceBuilder) Build() (client.Object, error) {
Expand Down
11 changes: 3 additions & 8 deletions internal/resource/service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ package resource

import (
"fmt"

"sigs.k8s.io/controller-runtime/pkg/client"

rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
"github.com/rabbitmq/cluster-operator/internal/metadata"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

Expand All @@ -26,15 +25,11 @@ const (
)

type ServiceAccountBuilder struct {
Instance *rabbitmqv1beta1.RabbitmqCluster
Scheme *runtime.Scheme
*RabbitmqResourceBuilder
}

func (builder *RabbitmqResourceBuilder) ServiceAccount() *ServiceAccountBuilder {
return &ServiceAccountBuilder{
Instance: builder.Instance,
Scheme: builder.Scheme,
}
return &ServiceAccountBuilder{builder}
}

func (builder *ServiceAccountBuilder) Build() (client.Object, error) {
Expand Down
8 changes: 2 additions & 6 deletions internal/resource/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,11 @@ const (
)

type StatefulSetBuilder struct {
Instance *rabbitmqv1beta1.RabbitmqCluster
Scheme *runtime.Scheme
*RabbitmqResourceBuilder
}

func (builder *RabbitmqResourceBuilder) StatefulSet() *StatefulSetBuilder {
return &StatefulSetBuilder{
Instance: builder.Instance,
Scheme: builder.Scheme,
}
return &StatefulSetBuilder{builder}
}

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

0 comments on commit d04724e

Please sign in to comment.