diff --git a/controllers/rabbitmqcluster_controller.go b/controllers/rabbitmqcluster_controller.go index 9b74901d4..731ba0373 100644 --- a/controllers/rabbitmqcluster_controller.go +++ b/controllers/rabbitmqcluster_controller.go @@ -305,7 +305,7 @@ func (r *RabbitmqClusterReconciler) getRabbitmqCluster(ctx context.Context, name } func (r *RabbitmqClusterReconciler) SetupWithManager(mgr ctrl.Manager) error { - for _, resource := range []runtime.Object{&appsv1.StatefulSet{}, &corev1.ConfigMap{}, &corev1.Service{}} { + for _, resource := range []client.Object{&appsv1.StatefulSet{}, &corev1.ConfigMap{}, &corev1.Service{}} { if err := mgr.GetFieldIndexer().IndexField(context.Background(), resource, ownerKey, addResourceToIndex); err != nil { return err } @@ -323,7 +323,7 @@ func (r *RabbitmqClusterReconciler) SetupWithManager(mgr ctrl.Manager) error { Complete(r) } -func addResourceToIndex(rawObj runtime.Object) []string { +func addResourceToIndex(rawObj client.Object) []string { switch resourceObject := rawObj.(type) { case *appsv1.StatefulSet: owner := metav1.GetControllerOf(resourceObject) diff --git a/controllers/reconcile_rabbitmq_configurations.go b/controllers/reconcile_rabbitmq_configurations.go index 7070d8e85..b695fe113 100644 --- a/controllers/reconcile_rabbitmq_configurations.go +++ b/controllers/reconcile_rabbitmq_configurations.go @@ -10,7 +10,6 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" clientretry "k8s.io/client-go/util/retry" "sigs.k8s.io/controller-runtime/pkg/client" @@ -28,7 +27,7 @@ const ( // These annotations are temporary markers used in later reconcile loops to perform some action (such as restarting the StatefulSet or executing RabbitMQ CLI commands) func (r *RabbitmqClusterReconciler) annotateIfNeeded(ctx context.Context, builder resource.ResourceBuilder, operationResult controllerutil.OperationResult, rmq *rabbitmqv1beta1.RabbitmqCluster) error { var ( - obj runtime.Object + obj client.Object objName string annotationKey string ) diff --git a/controllers/reconcile_tls_test.go b/controllers/reconcile_tls_test.go index 09dab6c88..f76e043a4 100644 --- a/controllers/reconcile_tls_test.go +++ b/controllers/reconcile_tls_test.go @@ -44,7 +44,7 @@ var _ = Describe("Reconcile TLS", func() { sts, err := clientSet.AppsV1().StatefulSets(cluster.Namespace).Get(ctx, cluster.ChildResourceName("server"), metav1.GetOptions{}) Expect(err).NotTo(HaveOccurred()) - + Expect(sts.Spec.Template.Spec.Volumes).To(ContainElement(corev1.Volume{ Name: "rabbitmq-tls", VolumeSource: corev1.VolumeSource{ diff --git a/controllers/utils.go b/controllers/utils.go index 180d0f6d9..cd7c9d5dc 100644 --- a/controllers/utils.go +++ b/controllers/utils.go @@ -2,13 +2,13 @@ package controllers import ( "context" + "sigs.k8s.io/controller-runtime/pkg/client" rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" - "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/util/retry" ) @@ -17,7 +17,7 @@ func (r *RabbitmqClusterReconciler) exec(namespace, podName, containerName strin return r.PodExecutor.Exec(r.Clientset, r.ClusterConfig, namespace, podName, containerName, command...) } -func (r *RabbitmqClusterReconciler) deleteAnnotation(ctx context.Context, obj runtime.Object, annotation string) error { +func (r *RabbitmqClusterReconciler) deleteAnnotation(ctx context.Context, obj client.Object, annotation string) error { accessor, err := meta.Accessor(obj) if err != nil { return err @@ -31,7 +31,7 @@ func (r *RabbitmqClusterReconciler) deleteAnnotation(ctx context.Context, obj ru return r.Update(ctx, obj) } -func (r *RabbitmqClusterReconciler) updateAnnotation(ctx context.Context, obj runtime.Object, namespace, objName, key, value string) error { +func (r *RabbitmqClusterReconciler) updateAnnotation(ctx context.Context, obj client.Object, namespace, objName, key, value string) error { return retry.OnError( retry.DefaultRetry, errorIsConflictOrNotFound, // StatefulSet needs time to be found after it got created diff --git a/internal/resource/configmap.go b/internal/resource/configmap.go index 0031d3aae..57203072f 100644 --- a/internal/resource/configmap.go +++ b/internal/resource/configmap.go @@ -12,6 +12,7 @@ package resource import ( "bytes" "fmt" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -64,7 +65,7 @@ func (builder *RabbitmqResourceBuilder) ServerConfigMap() *ServerConfigMapBuilde } } -func (builder *ServerConfigMapBuilder) Build() (runtime.Object, error) { +func (builder *ServerConfigMapBuilder) Build() (client.Object, error) { return &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: builder.Instance.ChildResourceName(ServerConfigMapName), @@ -75,7 +76,7 @@ func (builder *ServerConfigMapBuilder) Build() (runtime.Object, error) { }, nil } -func (builder *ServerConfigMapBuilder) Update(object runtime.Object) error { +func (builder *ServerConfigMapBuilder) Update(object client.Object) error { configMap := object.(*corev1.ConfigMap) ini.PrettySection = false // Remove trailing new line because rabbitmq.conf has only a default section. diff --git a/internal/resource/default_user_secret.go b/internal/resource/default_user_secret.go index 43723bce5..eeb0b2ad7 100644 --- a/internal/resource/default_user_secret.go +++ b/internal/resource/default_user_secret.go @@ -12,6 +12,7 @@ package resource import ( "bytes" "fmt" + "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -39,7 +40,7 @@ func (builder *RabbitmqResourceBuilder) DefaultUserSecret() *DefaultUserSecretBu } } -func (builder *DefaultUserSecretBuilder) Build() (runtime.Object, error) { +func (builder *DefaultUserSecretBuilder) Build() (client.Object, error) { username, err := randomEncodedString(24) if err != nil { return nil, err @@ -69,7 +70,7 @@ func (builder *DefaultUserSecretBuilder) Build() (runtime.Object, error) { }, nil } -func (builder *DefaultUserSecretBuilder) Update(object runtime.Object) error { +func (builder *DefaultUserSecretBuilder) Update(object client.Object) error { secret := object.(*corev1.Secret) secret.Labels = metadata.GetLabels(builder.Instance.Name, builder.Instance.Labels) secret.Annotations = metadata.ReconcileAndFilterAnnotations(secret.GetAnnotations(), builder.Instance.Annotations) diff --git a/internal/resource/erlang_cookie.go b/internal/resource/erlang_cookie.go index 421eab6c7..509c8c39a 100644 --- a/internal/resource/erlang_cookie.go +++ b/internal/resource/erlang_cookie.go @@ -13,6 +13,7 @@ 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" @@ -38,7 +39,7 @@ func (builder *RabbitmqResourceBuilder) ErlangCookie() *ErlangCookieBuilder { } } -func (builder *ErlangCookieBuilder) Build() (runtime.Object, error) { +func (builder *ErlangCookieBuilder) Build() (client.Object, error) { cookie, err := randomEncodedString(24) if err != nil { return nil, err @@ -56,7 +57,7 @@ func (builder *ErlangCookieBuilder) Build() (runtime.Object, error) { }, nil } -func (builder *ErlangCookieBuilder) Update(object runtime.Object) error { +func (builder *ErlangCookieBuilder) Update(object client.Object) error { secret := object.(*corev1.Secret) secret.Labels = metadata.GetLabels(builder.Instance.Name, builder.Instance.Labels) secret.Annotations = metadata.ReconcileAndFilterAnnotations(secret.GetAnnotations(), builder.Instance.Annotations) diff --git a/internal/resource/headless_service.go b/internal/resource/headless_service.go index c5e133f9e..13fc8c8ae 100644 --- a/internal/resource/headless_service.go +++ b/internal/resource/headless_service.go @@ -11,6 +11,7 @@ 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" @@ -37,7 +38,7 @@ func (builder *RabbitmqResourceBuilder) HeadlessService() *HeadlessServiceBuilde } } -func (builder *HeadlessServiceBuilder) Build() (runtime.Object, error) { +func (builder *HeadlessServiceBuilder) Build() (client.Object, error) { return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: builder.Instance.ChildResourceName(headlessServiceSuffix), @@ -46,7 +47,7 @@ func (builder *HeadlessServiceBuilder) Build() (runtime.Object, error) { }, nil } -func (builder *HeadlessServiceBuilder) Update(object runtime.Object) error { +func (builder *HeadlessServiceBuilder) Update(object client.Object) error { service := object.(*corev1.Service) service.Labels = metadata.GetLabels(builder.Instance.Name, builder.Instance.Labels) service.Annotations = metadata.ReconcileAndFilterAnnotations(service.GetAnnotations(), builder.Instance.Annotations) diff --git a/internal/resource/rabbitmq_plugins.go b/internal/resource/rabbitmq_plugins.go index 3d3ac38be..326db7ab8 100644 --- a/internal/resource/rabbitmq_plugins.go +++ b/internal/resource/rabbitmq_plugins.go @@ -2,6 +2,7 @@ package resource import ( "fmt" + "sigs.k8s.io/controller-runtime/pkg/client" "strings" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -33,7 +34,7 @@ func (builder *RabbitmqResourceBuilder) RabbitmqPluginsConfigMap() *RabbitmqPlug } } -func (builder *RabbitmqPluginsConfigMapBuilder) Build() (runtime.Object, error) { +func (builder *RabbitmqPluginsConfigMapBuilder) Build() (client.Object, error) { return &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: builder.Instance.ChildResourceName(PluginsConfigName), @@ -47,7 +48,7 @@ func (builder *RabbitmqPluginsConfigMapBuilder) Build() (runtime.Object, error) }, nil } -func (builder *RabbitmqPluginsConfigMapBuilder) Update(object runtime.Object) error { +func (builder *RabbitmqPluginsConfigMapBuilder) Update(object client.Object) error { configMap := object.(*corev1.ConfigMap) if configMap.Data == nil { diff --git a/internal/resource/rabbitmq_resource_builder.go b/internal/resource/rabbitmq_resource_builder.go index 39f5d4932..43550d6fd 100644 --- a/internal/resource/rabbitmq_resource_builder.go +++ b/internal/resource/rabbitmq_resource_builder.go @@ -12,6 +12,7 @@ package resource import ( rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1" "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/controller-runtime/pkg/client" ) type RabbitmqResourceBuilder struct { @@ -20,8 +21,8 @@ type RabbitmqResourceBuilder struct { } type ResourceBuilder interface { - Build() (runtime.Object, error) - Update(runtime.Object) error + Build() (client.Object, error) + Update(client.Object) error } func (builder *RabbitmqResourceBuilder) ResourceBuilders() ([]ResourceBuilder, error) { diff --git a/internal/resource/role.go b/internal/resource/role.go index 689628ea6..d5a4da38a 100644 --- a/internal/resource/role.go +++ b/internal/resource/role.go @@ -11,6 +11,7 @@ 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" @@ -36,7 +37,7 @@ func (builder *RabbitmqResourceBuilder) Role() *RoleBuilder { } } -func (builder *RoleBuilder) Build() (runtime.Object, error) { +func (builder *RoleBuilder) Build() (client.Object, error) { return &rbacv1.Role{ ObjectMeta: metav1.ObjectMeta{ Namespace: builder.Instance.Namespace, @@ -45,7 +46,7 @@ func (builder *RoleBuilder) Build() (runtime.Object, error) { }, nil } -func (builder *RoleBuilder) Update(object runtime.Object) error { +func (builder *RoleBuilder) Update(object client.Object) error { role := object.(*rbacv1.Role) role.Labels = metadata.GetLabels(builder.Instance.Name, builder.Instance.Labels) role.Annotations = metadata.ReconcileAndFilterAnnotations(role.GetAnnotations(), builder.Instance.Annotations) diff --git a/internal/resource/role_binding.go b/internal/resource/role_binding.go index 6865c1fa7..dc9de17dd 100644 --- a/internal/resource/role_binding.go +++ b/internal/resource/role_binding.go @@ -14,6 +14,7 @@ import ( 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" @@ -36,7 +37,7 @@ func (builder *RabbitmqResourceBuilder) RoleBinding() *RoleBindingBuilder { } } -func (builder *RoleBindingBuilder) Update(object runtime.Object) error { +func (builder *RoleBindingBuilder) Update(object client.Object) error { roleBinding := object.(*rbacv1.RoleBinding) roleBinding.Labels = metadata.GetLabels(builder.Instance.Name, builder.Instance.Labels) roleBinding.Annotations = metadata.ReconcileAndFilterAnnotations(roleBinding.GetAnnotations(), builder.Instance.Annotations) @@ -58,7 +59,7 @@ func (builder *RoleBindingBuilder) Update(object runtime.Object) error { return nil } -func (builder *RoleBindingBuilder) Build() (runtime.Object, error) { +func (builder *RoleBindingBuilder) Build() (client.Object, error) { return &rbacv1.RoleBinding{ ObjectMeta: metav1.ObjectMeta{ Namespace: builder.Instance.Namespace, diff --git a/internal/resource/service.go b/internal/resource/service.go index 055550be9..419601dc5 100644 --- a/internal/resource/service.go +++ b/internal/resource/service.go @@ -12,6 +12,7 @@ package resource import ( "encoding/json" "fmt" + "sigs.k8s.io/controller-runtime/pkg/client" "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/strategicpatch" @@ -40,7 +41,7 @@ func (builder *RabbitmqResourceBuilder) Service() *ServiceBuilder { } } -func (builder *ServiceBuilder) Build() (runtime.Object, error) { +func (builder *ServiceBuilder) Build() (client.Object, error) { return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: builder.Instance.ChildResourceName(ServiceSuffix), @@ -49,7 +50,7 @@ func (builder *ServiceBuilder) Build() (runtime.Object, error) { }, nil } -func (builder *ServiceBuilder) Update(object runtime.Object) error { +func (builder *ServiceBuilder) Update(object client.Object) error { service := object.(*corev1.Service) builder.setAnnotations(service) service.Labels = metadata.GetLabels(builder.Instance.Name, builder.Instance.Labels) diff --git a/internal/resource/service_account.go b/internal/resource/service_account.go index 449993ac0..b19fdaad7 100644 --- a/internal/resource/service_account.go +++ b/internal/resource/service_account.go @@ -11,6 +11,7 @@ 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" @@ -36,7 +37,7 @@ func (builder *RabbitmqResourceBuilder) ServiceAccount() *ServiceAccountBuilder } } -func (builder *ServiceAccountBuilder) Build() (runtime.Object, error) { +func (builder *ServiceAccountBuilder) Build() (client.Object, error) { return &corev1.ServiceAccount{ ObjectMeta: metav1.ObjectMeta{ Namespace: builder.Instance.Namespace, @@ -45,7 +46,7 @@ func (builder *ServiceAccountBuilder) Build() (runtime.Object, error) { }, nil } -func (builder *ServiceAccountBuilder) Update(object runtime.Object) error { +func (builder *ServiceAccountBuilder) Update(object client.Object) error { serviceAccount := object.(*corev1.ServiceAccount) serviceAccount.Labels = metadata.GetLabels(builder.Instance.Name, builder.Instance.Labels) serviceAccount.Annotations = metadata.ReconcileAndFilterAnnotations(serviceAccount.GetAnnotations(), builder.Instance.Annotations) diff --git a/internal/resource/statefulset.go b/internal/resource/statefulset.go index d3c43e933..6b84ed66a 100644 --- a/internal/resource/statefulset.go +++ b/internal/resource/statefulset.go @@ -12,6 +12,7 @@ package resource import ( "encoding/json" "fmt" + "sigs.k8s.io/controller-runtime/pkg/client" "k8s.io/apimachinery/pkg/util/intstr" @@ -46,7 +47,7 @@ func (builder *RabbitmqResourceBuilder) StatefulSet() *StatefulSetBuilder { } } -func (builder *StatefulSetBuilder) Build() (runtime.Object, error) { +func (builder *StatefulSetBuilder) Build() (client.Object, error) { // PVC, ServiceName & Selector: can't be updated without deleting the statefulset pvc, err := persistentVolumeClaim(builder.Instance, builder.Scheme) if err != nil { @@ -98,7 +99,7 @@ func (builder *StatefulSetBuilder) Build() (runtime.Object, error) { return sts, nil } -func (builder *StatefulSetBuilder) Update(object runtime.Object) error { +func (builder *StatefulSetBuilder) Update(object client.Object) error { sts := object.(*appsv1.StatefulSet) //Replicas diff --git a/system_tests/system_tests.go b/system_tests/system_tests.go index 76d6888d6..4216e2633 100644 --- a/system_tests/system_tests.go +++ b/system_tests/system_tests.go @@ -380,7 +380,6 @@ CONSOLE_LOG=new` return actualCert }, 180, 10).ShouldNot(Equal(oldServerCert)) - Eventually(func() []byte { newServerCertificate := inspectServerCertificate(username, password, hostname, amqpsNodePort, caFilePath) return newServerCertificate