Skip to content

Commit 1980ba2

Browse files
hdurand0710oktalz
authored andcommitted
MEDIUM: add transformer functions to all K8s events
For Ingress: remove duplicates in tls and rules For all objects: remove metadata.ManagedFields For Ingress: in informers, discard events if the resourceVersion has already been processed This will also allow to have all k8s events in Elastic.
1 parent c5f940d commit 1980ba2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1490
-164
lines changed

.aspell.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ allowed:
2626
- crd
2727
- linter
2828
- linters
29+
- tls

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/fasthttp/router v1.4.20
88
github.com/go-openapi/swag v0.23.0
99
github.com/go-test/deep v1.1.0
10+
github.com/google/go-cmp v0.6.0
1011
github.com/google/renameio v1.0.1
1112
github.com/haproxytech/client-native/v3 v3.1.2-0.20230607075433-231591da68ed
1213
github.com/haproxytech/client-native/v5 v5.1.11
@@ -51,7 +52,6 @@ require (
5152
github.com/gogo/protobuf v1.3.2 // indirect
5253
github.com/golang/protobuf v1.5.4 // indirect
5354
github.com/google/gnostic-models v0.6.8 // indirect
54-
github.com/google/go-cmp v0.6.0 // indirect
5555
github.com/google/gofuzz v1.2.0 // indirect
5656
github.com/google/uuid v1.6.0 // indirect
5757
github.com/haproxytech/go-logger v1.1.0 // indirect

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/haproxytech/kubernetes-ingress/pkg/controller"
3737
"github.com/haproxytech/kubernetes-ingress/pkg/job"
3838
"github.com/haproxytech/kubernetes-ingress/pkg/k8s"
39+
"github.com/haproxytech/kubernetes-ingress/pkg/k8s/meta"
3940
k8ssync "github.com/haproxytech/kubernetes-ingress/pkg/k8s/sync"
4041
"github.com/haproxytech/kubernetes-ingress/pkg/store"
4142
"github.com/haproxytech/kubernetes-ingress/pkg/utils"
@@ -140,6 +141,10 @@ func main() {
140141
publishService,
141142
)
142143

144+
if osArgs.Test {
145+
meta.GetMetaStore().ProcessedResourceVersion.SetTestMode()
146+
}
147+
143148
c := controller.NewBuilder().
144149
WithHaproxyCfgFile(haproxyConf).
145150
WithEventChan(eventChan).

pkg/controller/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (c *HAProxyController) SyncData() {
6060
case k8ssync.NAMESPACE:
6161
change = c.store.EventNamespace(ns, job.Data.(*store.Namespace)) //nolint:forcetypeassert
6262
case k8ssync.INGRESS:
63-
change = c.store.EventIngress(ns, job.Data.(*store.Ingress)) //nolint:forcetypeassert
63+
change = c.store.EventIngress(ns, job.Data.(*store.Ingress), job.UID, job.ResourceVersion) //nolint:forcetypeassert
6464
case k8ssync.INGRESS_CLASS:
6565
change = c.store.EventIngressClass(job.Data.(*store.IngressClass)) //nolint:forcetypeassert
6666
case k8ssync.ENDPOINTS:

pkg/handler/prometheus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (handler PrometheusEndpoint) Update(k store.K8s, h haproxy.HAProxy, a annot
123123
}
124124

125125
if userListChanged || status != store.EMPTY || secretExists && secret.Status != store.EMPTY {
126-
k.EventIngress(k.GetNamespace(ing.Namespace), ing)
126+
k.EventIngress(k.GetNamespace(ing.Namespace), ing, "fakeUID", "fakeResourceVersion")
127127
}
128128

129129
instance.ReloadIf(status != store.EMPTY, "creation/modification of prometheus endpoint")

pkg/k8s/informer-utils.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2019 HAProxy Technologies LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package k8s
16+
17+
import (
18+
k8smeta "github.com/haproxytech/kubernetes-ingress/pkg/k8s/meta"
19+
k8ssync "github.com/haproxytech/kubernetes-ingress/pkg/k8s/sync"
20+
"k8s.io/apimachinery/pkg/types"
21+
)
22+
23+
func ToSyncDataEvent(meta k8smeta.MetaInfoer, data interface{}, uid types.UID, resourceVersion string) k8ssync.SyncDataEvent {
24+
return k8ssync.SyncDataEvent{
25+
SyncType: meta.GetType(),
26+
Namespace: meta.GetNamespace(),
27+
Name: meta.GetName(),
28+
Data: data,
29+
UID: uid,
30+
ResourceVersion: resourceVersion,
31+
}
32+
}

0 commit comments

Comments
 (0)