Skip to content

Commit 232e6c7

Browse files
committed
Add tests
1 parent f004a4f commit 232e6c7

File tree

7 files changed

+57
-17
lines changed

7 files changed

+57
-17
lines changed

.github/workflows/ci.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99
- uses: actions/checkout@v2
1010
- uses: actions/setup-go@v3
1111
with:
12-
go-version: "1.20"
12+
go-version: "1.21"
1313
- uses: golangci/golangci-lint-action@v3
1414
with:
15-
version: v1.52.2
15+
version: v1.55
1616
- run: make test
1717

1818
integration:
@@ -34,7 +34,7 @@ jobs:
3434
version: v3.7.0
3535
- uses: actions/setup-go@v3
3636
with:
37-
go-version: "1.20"
37+
go-version: "1.21"
3838
- uses: actions/cache@v2
3939
with:
4040
path: |
@@ -194,7 +194,7 @@ jobs:
194194
EOF
195195
- uses: actions/setup-go@v3
196196
with:
197-
go-version: "1.20"
197+
go-version: "1.21"
198198
- uses: goreleaser/goreleaser-action@v4
199199
with:
200200
version: latest

Dockerfile.api

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.20-alpine3.18 AS builder
1+
FROM golang:1.21-alpine3.18 AS builder
22
COPY . /go/src/github.com/tsuru/rpaas-operator
33
WORKDIR /go/src/github.com/tsuru/rpaas-operator
44
RUN set -x \

Dockerfile.operator

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.20-alpine3.18 AS builder
1+
FROM golang:1.21-alpine3.18 AS builder
22
COPY . /go/src/github.com/tsuru/rpaas-operator
33
WORKDIR /go/src/github.com/tsuru/rpaas-operator
44
RUN apk add --update gcc git make musl-dev && \

Dockerfile.purger

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.20-alpine3.18 AS builder
1+
FROM golang:1.21-alpine3.18 AS builder
22
COPY . /go/src/github.com/tsuru/rpaas-operator
33
WORKDIR /go/src/github.com/tsuru/rpaas-operator
44
RUN apk add --update gcc git make musl-dev && \

controllers/controller.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"errors"
1515
"fmt"
1616
"reflect"
17+
"slices"
1718
"sort"
1819
"strconv"
1920
"strings"
@@ -881,20 +882,23 @@ func (r *RpaasInstanceReconciler) getNginx(ctx context.Context, instance *v1alph
881882
return found, err
882883
}
883884

884-
func (r *RpaasInstanceReconciler) getNginxExternalAddressses(ctx context.Context, nginx *nginxv1alpha1.Nginx) (v1alpha1.RpaasInstanceExternalAddressesStatus, error) {
885+
func externalAddresssesFromNginx(nginx *nginxv1alpha1.Nginx) v1alpha1.RpaasInstanceExternalAddressesStatus {
885886
ingressesStatus := v1alpha1.RpaasInstanceExternalAddressesStatus{}
886887

887888
for _, service := range nginx.Status.Services {
888-
ingressesStatus.IPs = append(ingressesStatus.IPs, service.Hostnames...)
889+
ingressesStatus.IPs = append(ingressesStatus.IPs, service.IPs...)
889890
ingressesStatus.Hostnames = append(ingressesStatus.Hostnames, service.Hostnames...)
890891
}
891892

892893
for _, ingress := range nginx.Status.Ingresses {
893-
ingressesStatus.IPs = append(ingressesStatus.IPs, ingress.Hostnames...)
894+
ingressesStatus.IPs = append(ingressesStatus.IPs, ingress.IPs...)
894895
ingressesStatus.Hostnames = append(ingressesStatus.Hostnames, ingress.Hostnames...)
895896
}
896897

897-
return ingressesStatus, nil
898+
slices.Sort(ingressesStatus.IPs)
899+
slices.Sort(ingressesStatus.Hostnames)
900+
901+
return ingressesStatus
898902
}
899903

900904
func (r *RpaasInstanceReconciler) reconcileNginx(ctx context.Context, instance *v1alpha1.RpaasInstance, nginx *nginxv1alpha1.Nginx) error {

controllers/controller_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -2122,6 +2122,47 @@ func TestRpaasInstanceController_Reconcile_Suspended(t *testing.T) {
21222122
assert.Equal(t, "Warning RpaasInstanceSuspended no modifications will be done by RPaaS controller", <-fr.Events)
21232123
}
21242124

2125+
func TestExternalAddresssesFromNginx(t *testing.T) {
2126+
externalAddresses := externalAddresssesFromNginx(&nginxv1alpha1.Nginx{
2127+
Status: nginxv1alpha1.NginxStatus{
2128+
Ingresses: []nginxv1alpha1.IngressStatus{
2129+
{
2130+
Name: "ing1",
2131+
IPs: []string{"1.1.1.3", "1.1.1.1"},
2132+
},
2133+
{
2134+
Name: "ing2",
2135+
IPs: []string{"1.1.1.2", "1.1.1.4"},
2136+
},
2137+
{
2138+
Name: "ing3",
2139+
Hostnames: []string{"host2", "host1"},
2140+
},
2141+
},
2142+
Services: []nginxv1alpha1.ServiceStatus{
2143+
{
2144+
Name: "svc",
2145+
IPs: []string{"8.1.1.3", "8.1.1.1"},
2146+
},
2147+
{
2148+
Name: "svc2",
2149+
IPs: []string{"8.1.1.2", "8.1.1.4"},
2150+
},
2151+
{
2152+
Name: "svc3",
2153+
Hostnames: []string{"host9", "host8"},
2154+
},
2155+
},
2156+
},
2157+
})
2158+
2159+
assert.Equal(t, v1alpha1.RpaasInstanceExternalAddressesStatus{
2160+
IPs: []string{"1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4", "8.1.1.1", "8.1.1.2", "8.1.1.3", "8.1.1.4"},
2161+
Hostnames: []string{"host1", "host2", "host8", "host9"},
2162+
}, externalAddresses)
2163+
2164+
}
2165+
21252166
func newRpaasInstanceReconciler(objs ...runtime.Object) *RpaasInstanceReconciler {
21262167
return &RpaasInstanceReconciler{
21272168
Client: fake.NewClientBuilder().WithScheme(extensionsruntime.NewScheme()).WithRuntimeObjects(objs...).Build(),

controllers/rpaasinstance_controller.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,12 @@ func (r *RpaasInstanceReconciler) refreshStatus(ctx context.Context, instance *v
180180
return err
181181
}
182182

183-
externalAddresses, err := r.getNginxExternalAddressses(ctx, existingNginx)
184-
if err != nil {
185-
return err
186-
}
187-
188183
newStatus := v1alpha1.RpaasInstanceStatus{
189184
ObservedGeneration: instance.Generation,
190185
WantedNginxRevisionHash: newHash,
191186
ObservedNginxRevisionHash: existingHash,
192187
NginxUpdated: newHash == existingHash,
193-
ExternalAddresses: externalAddresses,
188+
ExternalAddresses: externalAddresssesFromNginx(existingNginx),
194189
}
195190

196191
if existingNginx != nil {

0 commit comments

Comments
 (0)