| /* |
| * 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 ( |
| "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 { |
| watcher, err := k8s.WatchEvents(v1.NamespaceAll) |
| if err != nil { |
| return err |
| } |
| |
| p := pipe.Pipe{ |
| Watcher: watcher, |
| } |
| |
| if err = p.Init(); err != nil { |
| return err |
| } |
| |
| addShutDownHook(p.Stop) |
| |
| return p.Start() |
| }, |
| } |
| |
| func addShutDownHook(stopFunc func()) { |
| c := make(chan os.Signal) |
| signal.Notify(c, os.Interrupt, syscall.SIGTERM) |
| go func() { |
| <-c |
| stopFunc() |
| }() |
| } |