cmd/start.go (42 lines of code) (raw):

/* * Licensed to Apache Software Foundation (ASF) under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Apache Software Foundation (ASF) licenses this file to you 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 main import ( "context" "os" "os/signal" "syscall" "github.com/spf13/cobra" v1 "k8s.io/api/core/v1" _ "k8s.io/client-go/plugin/pkg/client/auth" "github.com/apache/skywalking-kubernetes-event-exporter/pkg/k8s" "github.com/apache/skywalking-kubernetes-event-exporter/pkg/pipe" ) func init() { rootCmd.AddCommand(startCmd) } var startCmd = &cobra.Command{ Use: "start", Short: "Start skywalking-kubernetes-event-exporter", RunE: func(cmd *cobra.Command, args []string) error { ctx, cancel := context.WithCancel(context.Background()) addShutDownHook(cancel) watcher, err := k8s.WatchEvents(ctx, v1.NamespaceAll) if err != nil { return err } p := pipe.Pipe{ Watcher: watcher, } if err = p.Init(ctx); err != nil { return err } return p.Start(ctx) }, } func addShutDownHook(stopFunc func()) { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) go func() { <-c stopFunc() }() }