Skip to content

Commit 1abb6b3

Browse files
authored
Merge pull request #11 from serverscom/cluster-id-annotation
Cluster id annotation
2 parents ea370fa + d20de1e commit 1abb6b3

File tree

9 files changed

+110
-92
lines changed

9 files changed

+110
-92
lines changed

.github/workflows/goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Go
1616
uses: actions/setup-go@v4
1717
with:
18-
go-version: "1.21"
18+
go-version: "1.22"
1919
- name: Set up QEMU
2020
uses: docker/setup-qemu-action@v2
2121
- name: Setup Docker Buildx

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jobs:
44
test:
55
strategy:
66
matrix:
7-
go-version: [1.21.x]
7+
go-version: [1.22.x]
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Install Go

go.mod

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
module github.com/serverscom/serverscom-ingress-controller
22

3-
go 1.21.4
3+
go 1.22.0
44

55
require (
66
github.com/joho/godotenv v1.5.1
77
github.com/jonboulle/clockwork v0.4.0
8-
github.com/onsi/gomega v1.29.0
9-
github.com/serverscom/serverscom-go-client v1.0.2
8+
github.com/onsi/gomega v1.33.1
9+
github.com/serverscom/serverscom-go-client v1.0.7
1010
github.com/spf13/pflag v1.0.5
1111
go.uber.org/mock v0.4.0
12-
golang.org/x/net v0.19.0
13-
k8s.io/api v0.29.1
14-
k8s.io/apimachinery v0.29.1
15-
k8s.io/client-go v0.29.1
16-
k8s.io/component-base v0.29.1
17-
k8s.io/klog/v2 v2.110.1
12+
golang.org/x/net v0.26.0
13+
k8s.io/api v0.31.1
14+
k8s.io/apimachinery v0.31.1
15+
k8s.io/client-go v0.31.1
16+
k8s.io/component-base v0.31.1
17+
k8s.io/klog/v2 v2.130.1
1818
)
1919

2020
require (
21-
github.com/davecgh/go-spew v1.1.1 // indirect
21+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2222
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
23-
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
24-
github.com/go-logr/logr v1.3.0 // indirect
23+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
24+
github.com/go-logr/logr v1.4.2 // indirect
2525
github.com/go-openapi/jsonpointer v0.19.6 // indirect
2626
github.com/go-openapi/jsonreference v0.20.2 // indirect
27-
github.com/go-openapi/swag v0.22.3 // indirect
27+
github.com/go-openapi/swag v0.22.4 // indirect
2828
github.com/gogo/protobuf v1.3.2 // indirect
2929
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
30-
github.com/golang/protobuf v1.5.3 // indirect
30+
github.com/golang/protobuf v1.5.4 // indirect
3131
github.com/google/gnostic-models v0.6.8 // indirect
3232
github.com/google/go-cmp v0.6.0 // indirect
3333
github.com/google/gofuzz v1.2.0 // indirect
34-
github.com/google/uuid v1.3.0 // indirect
34+
github.com/google/uuid v1.6.0 // indirect
3535
github.com/imdario/mergo v0.3.7 // indirect
3636
github.com/josharian/intern v1.0.0 // indirect
3737
github.com/json-iterator/go v1.1.12 // indirect
@@ -40,19 +40,20 @@ require (
4040
github.com/modern-go/reflect2 v1.0.2 // indirect
4141
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
4242
github.com/pkg/errors v0.9.1 // indirect
43-
golang.org/x/oauth2 v0.10.0 // indirect
44-
golang.org/x/sys v0.15.0 // indirect
45-
golang.org/x/term v0.15.0 // indirect
46-
golang.org/x/text v0.14.0 // indirect
43+
github.com/x448/float16 v0.8.4 // indirect
44+
golang.org/x/oauth2 v0.21.0 // indirect
45+
golang.org/x/sys v0.21.0 // indirect
46+
golang.org/x/term v0.21.0 // indirect
47+
golang.org/x/text v0.16.0 // indirect
4748
golang.org/x/time v0.3.0 // indirect
48-
google.golang.org/appengine v1.6.7 // indirect
49-
google.golang.org/protobuf v1.33.0 // indirect
49+
google.golang.org/protobuf v1.34.2 // indirect
50+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
5051
gopkg.in/inf.v0 v0.9.1 // indirect
5152
gopkg.in/yaml.v2 v2.4.0 // indirect
5253
gopkg.in/yaml.v3 v3.0.1 // indirect
53-
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
54-
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
54+
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
55+
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
5556
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
5657
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
57-
sigs.k8s.io/yaml v1.3.0 // indirect
58+
sigs.k8s.io/yaml v1.4.0 // indirect
5859
)

go.sum

Lines changed: 64 additions & 64 deletions
Large diffs are not rendered by default.

internal/service/annotations/ingress.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
LBGeoIPEnabled = "servers.com/load-balancer-geo-ip-enabled"
1212
LBRealIPTrustedNetworks = "servers.com/load-balancer-real-ip-trusted-networks" // TODO not implemented yet
1313
LBMinTLSVersion = "servers.com/load-balancer-min-tls-version"
14+
LBClusterID = "servers.com/cluster-id"
1415
)
1516

1617
// FillLBWithIngressAnnotations prepares the LB input based on annotations.
@@ -40,5 +41,10 @@ func FillLBWithIngressAnnotations(lbInput *serverscom.L7LoadBalancerCreateInput,
4041
}
4142
}
4243

44+
// LBClusterID annotation
45+
if id, ok := annotations[LBClusterID]; ok && id != "" {
46+
lbInput.ClusterID = &id
47+
}
48+
4349
return lbInput, nil
4450
}

internal/service/annotations/ingress_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestFillLBWithIngressAnnotations(t *testing.T) {
4141
LBStoreLogsRegionCode: "US01",
4242
LBGeoIPEnabled: "true",
4343
LBMinTLSVersion: "TLSv1.3",
44+
LBClusterID: "123",
4445
}
4546

4647
result, err := FillLBWithIngressAnnotations(lbInput, annotations)
@@ -49,6 +50,7 @@ func TestFillLBWithIngressAnnotations(t *testing.T) {
4950

5051
g.Expect(*result.StoreLogsRegionID).To(Equal(1))
5152
g.Expect(*result.Geoip).To(BeTrue())
53+
g.Expect(*result.ClusterID).To(Equal("123"))
5254
for _, uz := range result.UpstreamZones {
5355
g.Expect(*uz.TLSPreset).To(Equal("TLSv1.3"))
5456
}

internal/service/service.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ func (s *Service) SyncToPortal(key string) error {
122122
ctx, cancel := context.WithTimeout(context.Background(), LBPollTimeout)
123123
defer cancel()
124124
activeLB, err := s.syncManager.SyncStatus(ctx, lb)
125+
if err != nil {
126+
s.recorder.Eventf(ing, v1.EventTypeWarning, "SyncStatus", err.Error())
127+
return
128+
}
125129

126130
var ingress []networkv1.IngressLoadBalancerIngress
127131
for _, ip := range activeLB.ExternalAddresses {
@@ -134,9 +138,10 @@ func (s *Service) SyncToPortal(key string) error {
134138
},
135139
}
136140
ingClient := s.KubeClient.NetworkingV1().Ingresses(ing.Namespace)
137-
_, err = ingClient.UpdateStatus(context.Background(), ing, metav1.UpdateOptions{})
141+
_, err = ingClient.UpdateStatus(ctx, ing, metav1.UpdateOptions{})
138142
if err != nil {
139143
s.recorder.Eventf(ing, v1.EventTypeWarning, "UpdateStatus", err.Error())
144+
return
140145
}
141146

142147
s.recorder.Eventf(ing, v1.EventTypeNormal, "Synced", "Successfully synced")

internal/service/service_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ func TestSyncToPortal(t *testing.T) {
179179
}
180180
}
181181
g.Expect(events).To(ContainElements(
182-
"Normal Synced Successfully synced",
183182
`Warning UpdateStatus ingresses.networking.k8s.io "test-ingress" not found`,
184183
))
185184
})

internal/service/sync/lb.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ func (s *SyncManager) SyncL7LB(lb *serverscom.L7LoadBalancerCreateInput) (*serve
2525
Geoip: lb.Geoip,
2626
VHostZones: lb.VHostZones,
2727
UpstreamZones: lb.UpstreamZones,
28+
ClusterID: lb.ClusterID,
29+
}
30+
if lbUpdateInput.ClusterID == nil {
31+
lbUpdateInput.SharedCluster = new(bool)
32+
*lbUpdateInput.SharedCluster = true
2833
}
2934
result, err, _ := s.lbMgr.UpdateLoadBalancer(lbUpdateInput)
3035
return result, err

0 commit comments

Comments
 (0)