Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance: updates, removal of deprecated modules and function calls #1520

Merged
merged 11 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
branches: [ "main" ]

env:
GO_VERSION: ~1.20
GO_VERSION: ~1.21
# Taken from https://github.com/kubernetes-sigs/kind/releases/tag/v0.18.0
# The image here should be listed under 'Images built for this release' for the version of kind in go.mod
KIND_NODE_IMAGE: "kindest/node:v1.26.3@sha256:61b92f38dff6ccc29969e7aa154d34e38b89443af1a2c14e6cfbd2df6419c66f"
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prometheus-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- observability/prometheus/rules/**/*.y*ml

env:
GO_VERSION: ~1.20
GO_VERSION: ~1.21

jobs:
rules:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.20 as builder
FROM --platform=$BUILDPLATFORM golang:1.21 as builder

WORKDIR /workspace

Expand Down
20 changes: 10 additions & 10 deletions api/v1beta1/rabbitmqcluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
k8sresource "k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"golang.org/x/net/context"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -30,7 +30,7 @@ var _ = Describe("RabbitmqCluster", func() {
Context("RabbitmqClusterSpec", func() {
It("can be created with a single replica", func() {
created := generateRabbitmqClusterObject("rabbit1")
created.Spec.Replicas = pointer.Int32(1)
created.Spec.Replicas = ptr.To(int32(1))
Expect(k8sClient.Create(context.Background(), created)).To(Succeed())

fetched := &RabbitmqCluster{}
Expand All @@ -40,7 +40,7 @@ var _ = Describe("RabbitmqCluster", func() {

It("can be created with three replicas", func() {
created := generateRabbitmqClusterObject("rabbit2")
created.Spec.Replicas = pointer.Int32(3)
created.Spec.Replicas = ptr.To(int32(3))
Expect(k8sClient.Create(context.Background(), created)).To(Succeed())

fetched := &RabbitmqCluster{}
Expand All @@ -50,7 +50,7 @@ var _ = Describe("RabbitmqCluster", func() {

It("can be created with five replicas", func() {
created := generateRabbitmqClusterObject("rabbit3")
created.Spec.Replicas = pointer.Int32(5)
created.Spec.Replicas = ptr.To(int32(5))
Expect(k8sClient.Create(context.Background(), created)).To(Succeed())

fetched := &RabbitmqCluster{}
Expand Down Expand Up @@ -124,7 +124,7 @@ var _ = Describe("RabbitmqCluster", func() {
It("is validated", func() {
By("checking the replica count", func() {
invalidReplica := generateRabbitmqClusterObject("rabbit4")
invalidReplica.Spec.Replicas = pointer.Int32(-1)
invalidReplica.Spec.Replicas = ptr.To(int32(-1))
Expect(apierrors.IsInvalid(k8sClient.Create(context.Background(), invalidReplica))).To(BeTrue())
Expect(k8sClient.Create(context.Background(), invalidReplica)).To(MatchError(ContainSubstring("spec.replicas in body should be greater than or equal to 0")))
})
Expand Down Expand Up @@ -198,10 +198,10 @@ var _ = Describe("RabbitmqCluster", func() {
Namespace: "default",
},
Spec: RabbitmqClusterSpec{
Replicas: pointer.Int32(3),
Replicas: ptr.To(int32(3)),
Image: "rabbitmq-image-from-cr",
ImagePullSecrets: []corev1.LocalObjectReference{{Name: "my-super-secret"}},
TerminationGracePeriodSeconds: pointer.Int64(0),
TerminationGracePeriodSeconds: ptr.To(int64(0)),
Service: RabbitmqClusterServiceSpec{
Type: "NodePort",
Annotations: map[string]string{
Expand Down Expand Up @@ -528,9 +528,9 @@ func generateRabbitmqClusterObject(clusterName string) *RabbitmqCluster {
Namespace: "default",
},
Spec: RabbitmqClusterSpec{
Replicas: pointer.Int32(1),
TerminationGracePeriodSeconds: pointer.Int64(604800),
DelayStartSeconds: pointer.Int32(30),
Replicas: ptr.To(int32(1)),
TerminationGracePeriodSeconds: ptr.To(int64(604800)),
DelayStartSeconds: ptr.To(int32(30)),
Service: RabbitmqClusterServiceSpec{
Type: "ClusterIP",
},
Expand Down
3 changes: 2 additions & 1 deletion controllers/pod_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"bufio"
"bytes"
"context"

corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -42,7 +43,7 @@ func (p *rabbitmqPodExecutor) Exec(clientset *kubernetes.Clientset, clusterConfi
stdOut := bytes.Buffer{}
stdErr := bytes.Buffer{}

err = exec.Stream(remotecommand.StreamOptions{
err = exec.StreamWithContext(context.TODO(), remotecommand.StreamOptions{
Stdout: bufio.NewWriter(&stdOut),
Stderr: bufio.NewWriter(&stdErr),
Stdin: nil,
Expand Down
8 changes: 5 additions & 3 deletions controllers/rabbitmqcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import (
"errors"
"fmt"
"reflect"
"strings"
"time"

"github.com/go-logr/logr"
"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/rabbitmq/cluster-operator/v2/internal/resource"
"github.com/rabbitmq/cluster-operator/v2/internal/status"
Expand Down Expand Up @@ -266,16 +267,17 @@ func (r *RabbitmqClusterReconciler) logAndRecordOperationResult(logger logr.Logg
operation = "update"
}

caser := cases.Title(language.English)
if err == nil {
msg := fmt.Sprintf("%sd resource %s of Type %T", operation, resource.(metav1.Object).GetName(), resource.(metav1.Object))
logger.Info(msg)
r.Recorder.Event(rmq, corev1.EventTypeNormal, fmt.Sprintf("Successful%s", strings.Title(operation)), msg)
r.Recorder.Event(rmq, corev1.EventTypeNormal, fmt.Sprintf("Successful%s", caser.String(operation)), msg)
}

if err != nil {
msg := fmt.Sprintf("failed to %s resource %s of Type %T", operation, resource.(metav1.Object).GetName(), resource.(metav1.Object))
logger.Error(err, msg)
r.Recorder.Event(rmq, corev1.EventTypeWarning, fmt.Sprintf("Failed%s", strings.Title(operation)), msg)
r.Recorder.Event(rmq, corev1.EventTypeWarning, fmt.Sprintf("Failed%s", caser.String(operation)), msg)
}
}

Expand Down
15 changes: 7 additions & 8 deletions controllers/rabbitmqcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ package controllers_test
import (
"context"
"fmt"
"k8s.io/utils/ptr"
"time"

"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"k8s.io/apimachinery/pkg/util/intstr"

Expand Down Expand Up @@ -744,7 +743,7 @@ var _ = Describe("RabbitmqClusterController", func() {
Namespace: defaultNamespace,
},
}
cluster.Spec.Replicas = pointer.Int32(1)
cluster.Spec.Replicas = ptr.To(int32(1))
})

It("exposes ReconcileSuccess condition", func() {
Expand Down Expand Up @@ -788,7 +787,7 @@ var _ = Describe("RabbitmqClusterController", func() {
Namespace: defaultNamespace,
},
Spec: rabbitmqv1beta1.RabbitmqClusterSpec{
Replicas: pointer.Int32(10),
Replicas: ptr.To(int32(10)),
Override: rabbitmqv1beta1.RabbitmqClusterOverrideSpec{
StatefulSet: &rabbitmqv1beta1.StatefulSet{
Spec: &rabbitmqv1beta1.StatefulSetSpec{
Expand Down Expand Up @@ -1030,7 +1029,7 @@ var _ = Describe("RabbitmqClusterController", func() {

It("updates", func() {
Expect(updateWithRetry(cluster, func(r *rabbitmqv1beta1.RabbitmqCluster) {
cluster.Spec.Override.StatefulSet.Spec.Replicas = pointer.Int32(15)
cluster.Spec.Override.StatefulSet.Spec.Replicas = ptr.To(int32(15))
cluster.Spec.Override.StatefulSet.Spec.Template.Spec.Containers = []corev1.Container{
{
Name: "additional-container-2",
Expand Down Expand Up @@ -1130,21 +1129,21 @@ var _ = Describe("RabbitmqClusterController", func() {
Port: 5672,
Protocol: corev1.ProtocolTCP,
TargetPort: amqpTargetPort,
AppProtocol: pointer.String("amqp"),
AppProtocol: ptr.To("amqp"),
},
corev1.ServicePort{
Name: "management",
Port: 15672,
Protocol: corev1.ProtocolTCP,
TargetPort: managementTargetPort,
AppProtocol: pointer.String("http"),
AppProtocol: ptr.To("http"),
},
corev1.ServicePort{
Name: "prometheus",
Port: 15692,
Protocol: corev1.ProtocolTCP,
TargetPort: prometheusTargetPort,
AppProtocol: pointer.String("prometheus.io/metrics"),
AppProtocol: ptr.To("prometheus.io/metrics"),
},
corev1.ServicePort{
Protocol: corev1.ProtocolTCP,
Expand Down
8 changes: 4 additions & 4 deletions controllers/reconcile_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"time"

"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -73,7 +73,7 @@ var _ = Describe("Reconcile CLI", func() {
Namespace: defaultNamespace,
},
Spec: rabbitmqv1beta1.RabbitmqClusterSpec{
Replicas: pointer.Int32(3),
Replicas: ptr.To(int32(3)),
},
}
Expect(client.Create(ctx, cluster)).To(Succeed())
Expand Down Expand Up @@ -147,7 +147,7 @@ var _ = Describe("Reconcile CLI", func() {
Namespace: defaultNamespace,
},
Spec: rabbitmqv1beta1.RabbitmqClusterSpec{
Replicas: pointer.Int32(3),
Replicas: ptr.To(int32(3)),
SkipPostDeploySteps: true,
},
}
Expand Down Expand Up @@ -205,7 +205,7 @@ var _ = Describe("Reconcile CLI", func() {
Namespace: defaultNamespace,
},
Spec: rabbitmqv1beta1.RabbitmqClusterSpec{
Replicas: pointer.Int32(1),
Replicas: ptr.To(int32(1)),
SkipPostDeploySteps: false,
},
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/reconcile_no_persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
k8sresource "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
runtimeClient "sigs.k8s.io/controller-runtime/pkg/client"
)

Expand All @@ -32,7 +32,7 @@ var _ = Describe("Persistence", func() {
Namespace: defaultNamespace,
},
Spec: rabbitmqv1beta1.RabbitmqClusterSpec{
Replicas: pointer.Int32(5),
Replicas: ptr.To(int32(5)),
Persistence: rabbitmqv1beta1.RabbitmqClusterPersistenceSpec{
Storage: &zeroGi,
},
Expand Down
4 changes: 2 additions & 2 deletions controllers/reconcile_persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
k8sresource "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
runtimeClient "sigs.k8s.io/controller-runtime/pkg/client"
)

Expand All @@ -31,7 +31,7 @@ var _ = Describe("Persistence", func() {
Namespace: defaultNamespace,
},
Spec: rabbitmqv1beta1.RabbitmqClusterSpec{
Replicas: pointer.Int32(5),
Replicas: ptr.To(int32(5)),
},
}
Expect(client.Create(ctx, cluster)).To(Succeed())
Expand Down
6 changes: 3 additions & 3 deletions controllers/reconcile_scale_down_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
runtimeClient "sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -39,14 +39,14 @@ var _ = Describe("Cluster scale down", func() {
Namespace: defaultNamespace,
},
Spec: rabbitmqv1beta1.RabbitmqClusterSpec{
Replicas: pointer.Int32(5),
Replicas: ptr.To(int32(5)),
},
}
Expect(client.Create(ctx, cluster)).To(Succeed())
waitForClusterCreation(ctx, cluster, client)

Expect(updateWithRetry(cluster, func(r *rabbitmqv1beta1.RabbitmqCluster) {
r.Spec.Replicas = pointer.Int32(3)
r.Spec.Replicas = ptr.To(int32(3))
})).To(Succeed())
Consistently(func() int32 {
sts, err := clientSet.AppsV1().StatefulSets(defaultNamespace).Get(ctx, cluster.ChildResourceName("server"), metav1.GetOptions{})
Expand Down
6 changes: 3 additions & 3 deletions controllers/reconcile_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"
"github.com/rabbitmq/cluster-operator/v2/internal/status"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
runtimeClient "sigs.k8s.io/controller-runtime/pkg/client"

rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/v2/api/v1beta1"
Expand Down Expand Up @@ -57,11 +57,11 @@ var _ = Describe("Reconcile TLS", func() {
LocalObjectReference: corev1.LocalObjectReference{
Name: "tls-secret",
},
Optional: pointer.Bool(true),
Optional: ptr.To(true),
},
},
},
DefaultMode: pointer.Int32(400),
DefaultMode: ptr.To(int32(400)),
},
},
}))
Expand Down
4 changes: 2 additions & 2 deletions docs/api/rabbitmq.com.ref.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ The settings for the persistent storage desired for each Pod in the RabbitmqClus
|===
| Field | Description
| *`storageClassName`* __string__ | The name of the StorageClass to claim a PersistentVolume from.
| *`storage`* __Quantity__ | The requested size of the persistent volume attached to each Pod in the RabbitmqCluster. The format of this field matches that defined by kubernetes/apimachinery. See https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity for more info on the format of this field.
| *`storage`* __xref:{anchor_prefix}-k8s-io-apimachinery-pkg-api-resource-quantity[$$Quantity$$]__ | The requested size of the persistent volume attached to each Pod in the RabbitmqCluster. The format of this field matches that defined by kubernetes/apimachinery. See https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity for more info on the format of this field.
|===


Expand Down Expand Up @@ -332,7 +332,7 @@ Status presents the observed state of RabbitmqCluster
[cols="25a,75a", options="header"]
|===
| Field | Description
| *`conditions`* __xref:{anchor_prefix}-github.aaakk.us.kg-rabbitmq-cluster-operator-v2-internal-status-rabbitmqclustercondition[$$RabbitmqClusterCondition$$] array__ | Set of Conditions describing the current state of the RabbitmqCluster
| *`conditions`* __RabbitmqClusterCondition array__ | Set of Conditions describing the current state of the RabbitmqCluster
| *`defaultUser`* __xref:{anchor_prefix}-github.aaakk.us.kg-rabbitmq-cluster-operator-v2-api-v1beta1-rabbitmqclusterdefaultuser[$$RabbitmqClusterDefaultUser$$]__ | Identifying information on internal resources
| *`binding`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#localobjectreference-v1-core[$$LocalObjectReference$$]__ | Binding exposes a secret containing the binding information for this RabbitmqCluster. It implements the service binding Provisioned Service duck type. See: https://github.com/servicebinding/spec#provisioned-service
| *`observedGeneration`* __integer__ | observedGeneration is the most recent successful generation observed for this RabbitmqCluster. It corresponds to the RabbitmqCluster's generation, which is updated on mutation by the API Server.
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/rabbitmq/cluster-operator/v2

go 1.20
go 1.21

toolchain go1.21.5

require (
github.com/cloudflare/cfssl v1.6.4
Expand All @@ -9,14 +11,14 @@ require (
github.com/go-logr/logr v1.4.1
github.com/go-stomp/stomp v2.1.4+incompatible
github.com/michaelklishin/rabbit-hole/v2 v2.15.0
github.com/mikefarah/yq/v4 v4.40.5
github.com/onsi/ginkgo/v2 v2.13.2
github.com/onsi/gomega v1.30.0
github.com/rabbitmq/amqp091-go v1.9.0
github.com/rabbitmq/rabbitmq-stream-go-client v1.3.0
github.com/sclevine/yj v0.0.0-20200815061347-554173e71934
golang.org/x/mod v0.14.0
golang.org/x/net v0.19.0
golang.org/x/text v0.14.0
golang.org/x/vuln v1.0.1
gopkg.in/ini.v1 v1.67.0
k8s.io/api v0.28.4
Expand Down Expand Up @@ -117,7 +119,6 @@ require (
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
Expand Down
Loading
Loading