Skip to content

Commit

Permalink
Replace deprecated sets usages with generic version
Browse files Browse the repository at this point in the history
  • Loading branch information
ReToCode committed Jan 9, 2024
1 parent 8f4ce7f commit 9a1c89f
Show file tree
Hide file tree
Showing 50 changed files with 309 additions and 305 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,5 @@ require (

// TODO: https://github.com/knative/serving/issues/14597
replace github.com/gorilla/websocket => github.com/gorilla/websocket v1.5.0

replace knative.dev/networking => github.com/ReToCode/networking v0.0.0-20240109073627-bc010699726a
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBp
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/ReToCode/networking v0.0.0-20240109073627-bc010699726a h1:tNqizB6R53cc8/k0GmYQNh3qAvG7JGZXuUpD0Qc8cOQ=
github.com/ReToCode/networking v0.0.0-20240109073627-bc010699726a/go.mod h1:KL3tdfTQ58qOdE66WagSuFtppfMCNp+ZlDL3Oc6Bxno=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/ahmetb/gen-crd-api-reference-docs v0.3.1-0.20210609063737-0067dc6dcea2 h1:t/ces1/q8tuApSb+T5ajsu3wqkofUT43U1gpDYTPYME=
Expand Down Expand Up @@ -969,8 +971,6 @@ knative.dev/caching v0.0.0-20240108135517-d66e24d0d616 h1:VXAmfO+t6ssnZ1K6/UmKgm
knative.dev/caching v0.0.0-20240108135517-d66e24d0d616/go.mod h1:lISrLTfhtKvPKPMCqJJkCE8V+M6l2gNZyb/b73QiR4o=
knative.dev/hack v0.0.0-20240108153050-3ea694d6dad7 h1:mICurlRke2mlKP3LmyWYQYl6KZe80rYP5+ag9w2HQLA=
knative.dev/hack v0.0.0-20240108153050-3ea694d6dad7/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
knative.dev/networking v0.0.0-20240108134621-7cca4b010b25 h1:2H/mvXGSgfBcpNFUMWC3XCWL5zOrGGvas4RBbclEJ1M=
knative.dev/networking v0.0.0-20240108134621-7cca4b010b25/go.mod h1:ynNh7EoqxkST4jWPw6ZVyI9jwuF68WJNrX65yoAQ7FE=
knative.dev/pkg v0.0.0-20240108152118-de3e9cc204c9 h1:4nsTvrgApGtLTt6Gpo7ulJS03pBI+wSJ8+EOwVamDx0=
knative.dev/pkg v0.0.0-20240108152118-de3e9cc204c9/go.mod h1:YzKN/kzcJPhL+Z4fwuzbaiEnRLIbYvOiZUuCWFJ7PRA=
pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
Expand Down
10 changes: 5 additions & 5 deletions pkg/activator/net/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

// healthyAddresses takes an endpoints object and a port name and return the set
// of addresses that implement this port.
func healthyAddresses(endpoints *corev1.Endpoints, portName string) sets.String {
func healthyAddresses(endpoints *corev1.Endpoints, portName string) sets.Set[string] {
var addresses int
for _, es := range endpoints.Subsets {
for _, port := range es.Ports {
Expand All @@ -39,7 +39,7 @@ func healthyAddresses(endpoints *corev1.Endpoints, portName string) sets.String
}
}

ready := make(sets.String, addresses)
ready := make(sets.Set[string], addresses)

for _, es := range endpoints.Subsets {
for _, port := range es.Ports {
Expand All @@ -57,7 +57,7 @@ func healthyAddresses(endpoints *corev1.Endpoints, portName string) sets.String

// endpointsToDests takes an endpoints object and a port name and returns two sets of
// ready and non-ready l4 dests in the endpoints object which have that port.
func endpointsToDests(endpoints *corev1.Endpoints, portName string) (ready, notReady sets.String) {
func endpointsToDests(endpoints *corev1.Endpoints, portName string) (ready, notReady sets.Set[string]) {
var readyAddresses, nonReadyAddresses int
for _, es := range endpoints.Subsets {
for _, port := range es.Ports {
Expand All @@ -69,8 +69,8 @@ func endpointsToDests(endpoints *corev1.Endpoints, portName string) (ready, notR
}
}

ready = make(sets.String, readyAddresses)
notReady = make(sets.String, nonReadyAddresses)
ready = make(sets.Set[string], readyAddresses)
notReady = make(sets.Set[string], nonReadyAddresses)

for _, es := range endpoints.Subsets {
for _, port := range es.Ports {
Expand Down
18 changes: 9 additions & 9 deletions pkg/activator/net/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func TestEndpointsToDests(t *testing.T) {
name string
endpoints corev1.Endpoints
protocol networking.ProtocolType
expectReady sets.String
expectNotReady sets.String
expectReady sets.Set[string]
expectNotReady sets.Set[string]
}{{
name: "no endpoints",
endpoints: corev1.Endpoints{},
expectReady: sets.NewString(),
expectReady: sets.New[string](),
}, {
name: "single endpoint single address",
endpoints: corev1.Endpoints{
Expand All @@ -50,7 +50,7 @@ func TestEndpointsToDests(t *testing.T) {
}},
}},
},
expectReady: sets.NewString("128.0.0.1:1234"),
expectReady: sets.New("128.0.0.1:1234"),
}, {
name: "single endpoint multiple address",
endpoints: corev1.Endpoints{
Expand All @@ -66,7 +66,7 @@ func TestEndpointsToDests(t *testing.T) {
}},
}},
},
expectReady: sets.NewString("128.0.0.1:1234", "128.0.0.2:1234"),
expectReady: sets.New("128.0.0.1:1234", "128.0.0.2:1234"),
}, {
name: "single endpoint multiple addresses, including no ready addresses",
endpoints: corev1.Endpoints{
Expand All @@ -85,8 +85,8 @@ func TestEndpointsToDests(t *testing.T) {
}},
}},
},
expectReady: sets.NewString("128.0.0.1:1234", "128.0.0.2:1234"),
expectNotReady: sets.NewString("128.0.0.3:1234"),
expectReady: sets.New("128.0.0.1:1234", "128.0.0.2:1234"),
expectNotReady: sets.New("128.0.0.3:1234"),
}, {
name: "multiple endpoint filter port",
endpoints: corev1.Endpoints{
Expand All @@ -108,7 +108,7 @@ func TestEndpointsToDests(t *testing.T) {
}},
}},
},
expectReady: sets.NewString("128.0.0.1:1234"),
expectReady: sets.New("128.0.0.1:1234"),
}, {
name: "multiple endpoint, different protocol",
protocol: networking.ProtocolH2C,
Expand All @@ -135,7 +135,7 @@ func TestEndpointsToDests(t *testing.T) {
}},
}},
},
expectReady: sets.NewString("128.0.0.3:5678", "128.0.0.4:5678"),
expectReady: sets.New("128.0.0.3:5678", "128.0.0.4:5678"),
}} {
t.Run(tc.name, func(t *testing.T) {
if tc.protocol == "" {
Expand Down
14 changes: 7 additions & 7 deletions pkg/activator/net/revision_backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ import (
type revisionDestsUpdate struct {
Rev types.NamespacedName
ClusterIPDest string
Dests sets.String
Dests sets.Set[string]
}

type dests struct {
ready sets.String
notReady sets.String
ready sets.Set[string]
notReady sets.Set[string]
}

func (d dests) becameNonReady(prev dests) sets.String {
func (d dests) becameNonReady(prev dests) sets.Set[string] {
return prev.ready.Intersection(d.notReady)
}

Expand Down Expand Up @@ -102,7 +102,7 @@ type revisionWatcher struct {
done chan struct{}

// Stores the list of pods that have been successfully probed.
healthyPods sets.String
healthyPods sets.Set[string]
// Stores whether the service ClusterIP has been seen as healthy.
clusterIPHealthy bool

Expand Down Expand Up @@ -227,7 +227,7 @@ func (rw *revisionWatcher) probeClusterIP(dest string) (bool, error) {
// the ones that are successfully probed, whether the update was a no-op, or an error.
// If probing fails but not all errors were compatible with being caused by
// mesh being enabled, being enabled, notMesh will be true.
func (rw *revisionWatcher) probePodIPs(ready, notReady sets.String) (succeeded sets.String, noop bool, notMesh bool, err error) {
func (rw *revisionWatcher) probePodIPs(ready, notReady sets.Set[string]) (succeeded sets.Set[string], noop bool, notMesh bool, err error) {
dests := ready.Union(notReady)

// Short circuit case where all the current pods are already known to be healthy.
Expand Down Expand Up @@ -296,7 +296,7 @@ func (rw *revisionWatcher) probePodIPs(ready, notReady sets.String) (succeeded s
return healthy, unchanged, sawNotMesh.Load(), err
}

func (rw *revisionWatcher) sendUpdate(clusterIP string, dests sets.String) {
func (rw *revisionWatcher) sendUpdate(clusterIP string, dests sets.Set[string]) {
select {
case <-rw.stopCh:
return
Expand Down
Loading

0 comments on commit 9a1c89f

Please sign in to comment.