Skip to content

Commit

Permalink
MEDIUM: add transformer functions to all K8s events
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hdurand0710 authored and oktalz committed Oct 7, 2024
1 parent c5f940d commit 1980ba2
Show file tree
Hide file tree
Showing 47 changed files with 1,490 additions and 164 deletions.
1 change: 1 addition & 0 deletions .aspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ allowed:
- crd
- linter
- linters
- tls
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/fasthttp/router v1.4.20
github.com/go-openapi/swag v0.23.0
github.com/go-test/deep v1.1.0
github.com/google/go-cmp v0.6.0
github.com/google/renameio v1.0.1
github.com/haproxytech/client-native/v3 v3.1.2-0.20230607075433-231591da68ed
github.com/haproxytech/client-native/v5 v5.1.11
Expand Down Expand Up @@ -51,7 +52,6 @@ require (
github.com/gogo/protobuf v1.3.2 // 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.6.0 // indirect
github.com/haproxytech/go-logger v1.1.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/haproxytech/kubernetes-ingress/pkg/controller"
"github.com/haproxytech/kubernetes-ingress/pkg/job"
"github.com/haproxytech/kubernetes-ingress/pkg/k8s"
"github.com/haproxytech/kubernetes-ingress/pkg/k8s/meta"
k8ssync "github.com/haproxytech/kubernetes-ingress/pkg/k8s/sync"
"github.com/haproxytech/kubernetes-ingress/pkg/store"
"github.com/haproxytech/kubernetes-ingress/pkg/utils"
Expand Down Expand Up @@ -140,6 +141,10 @@ func main() {
publishService,
)

if osArgs.Test {
meta.GetMetaStore().ProcessedResourceVersion.SetTestMode()
}

c := controller.NewBuilder().
WithHaproxyCfgFile(haproxyConf).
WithEventChan(eventChan).
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *HAProxyController) SyncData() {
case k8ssync.NAMESPACE:
change = c.store.EventNamespace(ns, job.Data.(*store.Namespace)) //nolint:forcetypeassert
case k8ssync.INGRESS:
change = c.store.EventIngress(ns, job.Data.(*store.Ingress)) //nolint:forcetypeassert
change = c.store.EventIngress(ns, job.Data.(*store.Ingress), job.UID, job.ResourceVersion) //nolint:forcetypeassert
case k8ssync.INGRESS_CLASS:
change = c.store.EventIngressClass(job.Data.(*store.IngressClass)) //nolint:forcetypeassert
case k8ssync.ENDPOINTS:
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (handler PrometheusEndpoint) Update(k store.K8s, h haproxy.HAProxy, a annot
}

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

instance.ReloadIf(status != store.EMPTY, "creation/modification of prometheus endpoint")
Expand Down
32 changes: 32 additions & 0 deletions pkg/k8s/informer-utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2019 HAProxy Technologies LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package k8s

import (
k8smeta "github.com/haproxytech/kubernetes-ingress/pkg/k8s/meta"
k8ssync "github.com/haproxytech/kubernetes-ingress/pkg/k8s/sync"
"k8s.io/apimachinery/pkg/types"
)

func ToSyncDataEvent(meta k8smeta.MetaInfoer, data interface{}, uid types.UID, resourceVersion string) k8ssync.SyncDataEvent {
return k8ssync.SyncDataEvent{
SyncType: meta.GetType(),
Namespace: meta.GetNamespace(),
Name: meta.GetName(),
Data: data,
UID: uid,
ResourceVersion: resourceVersion,
}
}
Loading

0 comments on commit 1980ba2

Please sign in to comment.