Skip to content

Commit

Permalink
support new event version
Browse files Browse the repository at this point in the history
  • Loading branch information
Gentleelephant committed Aug 12, 2024
1 parent 8d3a49c commit 573ba1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func init() {
flag.StringVar(&kubeconfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
flag.StringVar(&masterURL, "master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
flag.StringVar(&configFile, "config.file", "", "Event exporter configuration file path")
flag.BoolVar(&util.NewEventType, "newEventType", false, "if true, exporter will use new event type")
flag.StringVar(&util.NewEventType, "newEventType", util.EventVersionOld, "event version, eventsv1 or corev1")
}

func main() {
Expand Down
9 changes: 5 additions & 4 deletions pkg/exporter/kube_events_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"errors"
"fmt"
"sync"

"github.com/kubesphere/kube-events/pkg/util"
v1 "k8s.io/api/events/v1"
eventsv1 "k8s.io/api/events/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sync"

"github.com/kubesphere/kube-events/pkg/config"
"github.com/kubesphere/kube-events/pkg/exporter/sinks"
Expand Down Expand Up @@ -204,8 +205,8 @@ func NewKubeEventSource(client *kubernetes.Clientset) *K8sEventSource {
}
var eventType runtime.Object
var lw *cache.ListWatch
if util.NewEventType {
eventType = &v1.Event{}
if util.NewEventType == util.EventVersionNew {
eventType = &eventsv1.Event{}
lw = cache.NewListWatchFromClient(client.EventsV1().RESTClient(),
"events", metav1.NamespaceAll, fields.Everything())
} else {
Expand Down
8 changes: 7 additions & 1 deletion pkg/util/annoutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import (
"k8s.io/klog/v2"
)

const (
EventVersionOld = "corev1"
EventVersionNew = "eventsv1"
)

var cluster string
var NewEventType bool
var NewEventType string

func SetClusterName(client *kubernetes.Clientset) {
setCluster(client)
Expand All @@ -30,6 +35,7 @@ func setCluster(client *kubernetes.Clientset) {
ns, err := client.CoreV1().Namespaces().Get(context.Background(), "kubesphere-system", metav1.GetOptions{})
if err != nil {
klog.Errorf("get namespace kubesphere-system error: %s", err)
return
}

if ns.Annotations != nil {
Expand Down

0 comments on commit 573ba1e

Please sign in to comment.