Skip to content

Cluster id annotation #11

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

Merged
merged 4 commits into from
Nov 5, 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/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
go-version: "1.22"
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Setup Docker Buildx
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.21.x]
go-version: [1.22.x]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand Down
49 changes: 25 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
module github.com/serverscom/serverscom-ingress-controller

go 1.21.4
go 1.22.0

require (
github.com/joho/godotenv v1.5.1
github.com/jonboulle/clockwork v0.4.0
github.com/onsi/gomega v1.29.0
github.com/serverscom/serverscom-go-client v1.0.2
github.com/onsi/gomega v1.33.1
github.com/serverscom/serverscom-go-client v1.0.7
github.com/spf13/pflag v1.0.5
go.uber.org/mock v0.4.0
golang.org/x/net v0.19.0
k8s.io/api v0.29.1
k8s.io/apimachinery v0.29.1
k8s.io/client-go v0.29.1
k8s.io/component-base v0.29.1
k8s.io/klog/v2 v2.110.1
golang.org/x/net v0.26.0
k8s.io/api v0.31.1
k8s.io/apimachinery v0.31.1
k8s.io/client-go v0.31.1
k8s.io/component-base v0.31.1
k8s.io/klog/v2 v2.130.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -40,19 +40,20 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/oauth2 v0.10.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
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
128 changes: 64 additions & 64 deletions go.sum

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions internal/service/annotations/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
LBGeoIPEnabled = "servers.com/load-balancer-geo-ip-enabled"
LBRealIPTrustedNetworks = "servers.com/load-balancer-real-ip-trusted-networks" // TODO not implemented yet
LBMinTLSVersion = "servers.com/load-balancer-min-tls-version"
LBClusterID = "servers.com/cluster-id"
)

// FillLBWithIngressAnnotations prepares the LB input based on annotations.
Expand Down Expand Up @@ -40,5 +41,10 @@ func FillLBWithIngressAnnotations(lbInput *serverscom.L7LoadBalancerCreateInput,
}
}

// LBClusterID annotation
if id, ok := annotations[LBClusterID]; ok && id != "" {
lbInput.ClusterID = &id
}

return lbInput, nil
}
2 changes: 2 additions & 0 deletions internal/service/annotations/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestFillLBWithIngressAnnotations(t *testing.T) {
LBStoreLogsRegionCode: "US01",
LBGeoIPEnabled: "true",
LBMinTLSVersion: "TLSv1.3",
LBClusterID: "123",
}

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

g.Expect(*result.StoreLogsRegionID).To(Equal(1))
g.Expect(*result.Geoip).To(BeTrue())
g.Expect(*result.ClusterID).To(Equal("123"))
for _, uz := range result.UpstreamZones {
g.Expect(*uz.TLSPreset).To(Equal("TLSv1.3"))
}
Expand Down
7 changes: 6 additions & 1 deletion internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func (s *Service) SyncToPortal(key string) error {
ctx, cancel := context.WithTimeout(context.Background(), LBPollTimeout)
defer cancel()
activeLB, err := s.syncManager.SyncStatus(ctx, lb)
if err != nil {
s.recorder.Eventf(ing, v1.EventTypeWarning, "SyncStatus", err.Error())
return
}

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

s.recorder.Eventf(ing, v1.EventTypeNormal, "Synced", "Successfully synced")
Expand Down
1 change: 0 additions & 1 deletion internal/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ func TestSyncToPortal(t *testing.T) {
}
}
g.Expect(events).To(ContainElements(
"Normal Synced Successfully synced",
`Warning UpdateStatus ingresses.networking.k8s.io "test-ingress" not found`,
))
})
Expand Down
5 changes: 5 additions & 0 deletions internal/service/sync/lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func (s *SyncManager) SyncL7LB(lb *serverscom.L7LoadBalancerCreateInput) (*serve
Geoip: lb.Geoip,
VHostZones: lb.VHostZones,
UpstreamZones: lb.UpstreamZones,
ClusterID: lb.ClusterID,
}
if lbUpdateInput.ClusterID == nil {
lbUpdateInput.SharedCluster = new(bool)
*lbUpdateInput.SharedCluster = true
}
result, err, _ := s.lbMgr.UpdateLoadBalancer(lbUpdateInput)
return result, err
Expand Down
Loading