Skip to content

Commit db718e0

Browse files
committed
Switch from deprecated corev1.Endpoints to discoveryv1.EndpointSlice.
1 parent 18b4a44 commit db718e0

File tree

11 files changed

+85
-118
lines changed

11 files changed

+85
-118
lines changed

api/v1beta1/rabbitmqcluster_status_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/rabbitmq/cluster-operator/v2/internal/status"
77
appsv1 "k8s.io/api/apps/v1"
88
corev1 "k8s.io/api/core/v1"
9+
discoveryv1 "k8s.io/api/discovery/v1"
910
"k8s.io/apimachinery/pkg/api/resource"
1011
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1112
"k8s.io/apimachinery/pkg/runtime"
@@ -40,19 +41,17 @@ var _ = Describe("RabbitmqClusterStatus", func() {
4041
Conditions: nil,
4142
}
4243

43-
endPoints := &corev1.Endpoints{
44-
Subsets: []corev1.EndpointSubset{
44+
endPointSlice := &discoveryv1.EndpointSlice{
45+
Endpoints: []discoveryv1.Endpoint{
4546
{
46-
Addresses: []corev1.EndpointAddress{
47-
{
48-
IP: "127.0.0.1",
49-
},
47+
Addresses: []string{
48+
"127.0.0.1",
5049
},
5150
},
5251
},
5352
}
5453

55-
rabbitmqClusterStatus.SetConditions([]runtime.Object{sts, endPoints})
54+
rabbitmqClusterStatus.SetConditions([]runtime.Object{sts, endPointSlice})
5655

5756
Expect(rabbitmqClusterStatus.Conditions).To(HaveLen(4))
5857
Expect(rabbitmqClusterStatus.Conditions[0].Type).To(Equal(status.AllReplicasReady))

api/v1beta1/rabbitmqcluster_types_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/rabbitmq/cluster-operator/v2/internal/status"
1515
appsv1 "k8s.io/api/apps/v1"
1616
corev1 "k8s.io/api/core/v1"
17+
discoveryv1 "k8s.io/api/discovery/v1"
1718
k8sresource "k8s.io/apimachinery/pkg/api/resource"
1819
"k8s.io/apimachinery/pkg/runtime"
1920
"k8s.io/utils/ptr"
@@ -484,19 +485,17 @@ var _ = Describe("RabbitmqCluster", func() {
484485
Conditions: nil,
485486
}
486487

487-
endPoints := &corev1.Endpoints{
488-
Subsets: []corev1.EndpointSubset{
488+
endPointSlice := &discoveryv1.EndpointSlice{
489+
Endpoints: []discoveryv1.Endpoint{
489490
{
490-
Addresses: []corev1.EndpointAddress{
491-
{
492-
IP: "127.0.0.1",
493-
},
491+
Addresses: []string{
492+
"127.0.0.1",
494493
},
495494
},
496495
},
497496
}
498497

499-
rabbitmqClusterStatus.SetConditions([]runtime.Object{statefulset, endPoints})
498+
rabbitmqClusterStatus.SetConditions([]runtime.Object{statefulset, endPointSlice})
500499

501500
Expect(rabbitmqClusterStatus.Conditions).To(HaveLen(4))
502501
Expect(rabbitmqClusterStatus.Conditions[0].Type).To(Equal(status.AllReplicasReady))

config/rbac/role.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ rules:
2626
- list
2727
- update
2828
- watch
29-
- apiGroups:
30-
- ""
31-
resources:
32-
- endpoints
33-
verbs:
34-
- get
35-
- list
36-
- watch
3729
- apiGroups:
3830
- ""
3931
resources:
@@ -68,6 +60,13 @@ rules:
6860
- list
6961
- update
7062
- watch
63+
- apiGroups:
64+
- discovery.k8s.io
65+
resources:
66+
- endpointslices
67+
verbs:
68+
- get
69+
- list
7170
- apiGroups:
7271
- rabbitmq.com
7372
resources:

controllers/rabbitmqcluster_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/v2/api/v1beta1"
4444
appsv1 "k8s.io/api/apps/v1"
4545
corev1 "k8s.io/api/core/v1"
46+
discoveryv1 "k8s.io/api/discovery/v1"
4647
rbacv1 "k8s.io/api/rbac/v1"
4748
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4849
)
@@ -77,7 +78,6 @@ type RabbitmqClusterReconciler struct {
7778
// +kubebuilder:rbac:groups="",resources=pods/exec,verbs=create
7879
// +kubebuilder:rbac:groups="",resources=pods,verbs=update;get;list;watch
7980
// +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update
80-
// +kubebuilder:rbac:groups="",resources=endpoints,verbs=get;watch;list
8181
// +kubebuilder:rbac:groups=apps,resources=statefulsets,verbs=get;list;watch;create;update;delete
8282
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch;create;update
8383
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update
@@ -88,6 +88,7 @@ type RabbitmqClusterReconciler struct {
8888
// +kubebuilder:rbac:groups="",resources=serviceaccounts,verbs=get;list;watch;create;update
8989
// +kubebuilder:rbac:groups="",resources=persistentvolumeclaims,verbs=get;list;watch;create;update
9090
// +kubebuilder:rbac:groups="rbac.authorization.k8s.io",resources=roles,verbs=get;list;watch;create;update
91+
// +kubebuilder:rbac:groups="discovery.k8s.io",resources=endpointslices,verbs=get;list
9192
// +kubebuilder:rbac:groups="rbac.authorization.k8s.io",resources=rolebindings,verbs=get;list;watch;create;update
9293

9394
func (r *RabbitmqClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
@@ -342,7 +343,7 @@ func (r *RabbitmqClusterReconciler) updateStatusConditions(ctx context.Context,
342343

343344
func (r *RabbitmqClusterReconciler) getChildResources(ctx context.Context, rmq *rabbitmqv1beta1.RabbitmqCluster) ([]runtime.Object, error) {
344345
sts := &appsv1.StatefulSet{}
345-
endPoints := &corev1.Endpoints{}
346+
endPoints := &discoveryv1.EndpointSlice{}
346347

347348
if err := r.Get(ctx,
348349
types.NamespacedName{Name: rmq.ChildResourceName("server"), Namespace: rmq.Namespace},

internal/resource/role.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func (builder *RoleBuilder) Update(object client.Object) error {
5151
role.Annotations = metadata.ReconcileAndFilterAnnotations(role.GetAnnotations(), builder.Instance.Annotations)
5252
role.Rules = []rbacv1.PolicyRule{
5353
{
54-
APIGroups: []string{""},
55-
Resources: []string{"endpoints"},
54+
APIGroups: []string{"discovery.k8s.io"},
55+
Resources: []string{"endpointslices"},
5656
Verbs: []string{"get"},
5757
},
5858
{

internal/resource/role_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ var _ = Describe("Role", func() {
130130
It("overwrites the modified rules", func() {
131131
expectedRules := []rbacv1.PolicyRule{
132132
{
133-
APIGroups: []string{""},
134-
Resources: []string{"endpoints"},
133+
APIGroups: []string{"discovery.k8s.io"},
134+
Resources: []string{"endpointslices"},
135135
Verbs: []string{"get"},
136136
},
137137
{

internal/status/all_replicas_ready_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
rabbitmqstatus "github.com/rabbitmq/cluster-operator/v2/internal/status"
1818
appsv1 "k8s.io/api/apps/v1"
1919
corev1 "k8s.io/api/core/v1"
20+
discoveryv1 "k8s.io/api/discovery/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
"k8s.io/apimachinery/pkg/runtime"
2223
)
@@ -44,7 +45,7 @@ var _ = Describe("AllReplicasReady", func() {
4445
})
4546

4647
It("returns the expected condition", func() {
47-
condition := rabbitmqstatus.AllReplicasReadyCondition([]runtime.Object{&corev1.Endpoints{}, sts}, oldCondition)
48+
condition := rabbitmqstatus.AllReplicasReadyCondition([]runtime.Object{&discoveryv1.EndpointSlice{}, sts}, oldCondition)
4849

4950
By("having status true and reason message", func() {
5051
Expect(condition.Status).To(Equal(corev1.ConditionTrue))
@@ -112,7 +113,7 @@ var _ = Describe("AllReplicasReady", func() {
112113
})
113114

114115
It("updates the transition time", func() {
115-
condition := rabbitmqstatus.AllReplicasReadyCondition([]runtime.Object{&corev1.Endpoints{}, sts}, oldCondition)
116+
condition := rabbitmqstatus.AllReplicasReadyCondition([]runtime.Object{&discoveryv1.EndpointSlice{}, sts}, oldCondition)
116117
Expect(condition.LastTransitionTime).ToNot(Equal(emptyTime))
117118
})
118119
})

internal/status/cluster_available.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import (
1313
"time"
1414

1515
corev1 "k8s.io/api/core/v1"
16+
discoveryv1 "k8s.io/api/discovery/v1"
1617
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1718
"k8s.io/apimachinery/pkg/runtime"
1819
)
1920

2021
type ClusterAvailableConditionManager struct {
21-
condition RabbitmqClusterCondition
22-
endpoints *corev1.Endpoints
22+
condition RabbitmqClusterCondition
23+
endpointslice *discoveryv1.EndpointSlice
2324
}
2425

2526
func ClusterAvailableCondition(resources []runtime.Object,
@@ -32,16 +33,16 @@ func ClusterAvailableCondition(resources []runtime.Object,
3233

3334
for _, res := range resources {
3435
switch resource := res.(type) {
35-
case *corev1.Endpoints:
36+
case *discoveryv1.EndpointSlice:
3637
if resource == nil {
3738
condition.Status = corev1.ConditionUnknown
3839
condition.Reason = "CouldNotRetrieveEndpoints"
3940
condition.Message = "Could not verify available service endpoints"
4041
goto assignLastTransitionTime
4142
}
4243

43-
for _, subset := range resource.Subsets {
44-
if len(subset.Addresses) > 0 {
44+
for _, endpoint := range resource.Endpoints {
45+
if len(endpoint.Addresses) > 0 {
4546
condition.Status = corev1.ConditionTrue
4647
condition.Reason = "AtLeastOneEndpointAvailable"
4748
goto assignLastTransitionTime

0 commit comments

Comments
 (0)