forked from jaegertracing/jaeger-operator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the Jaeger Operator version at build time
Signed-off-by: Juraci Paixão Kröhling <[email protected]>
- Loading branch information
1 parent
15645fc
commit 764e981
Showing
12 changed files
with
215 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
homedir "github.com/mitchellh/go-homedir" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/jaegertracing/jaeger-operator/pkg/cmd/start" | ||
"github.com/jaegertracing/jaeger-operator/pkg/cmd/version" | ||
) | ||
|
||
var cfgFile string | ||
|
||
// RootCmd represents the base command when called without any subcommands | ||
var RootCmd = &cobra.Command{ | ||
Use: "jaeger-operator", | ||
Short: "The Kubernetes operator for Jaeger", | ||
Long: `The Kubernetes operator for Jaeger`, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
if err := RootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
|
||
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.jaeger-operator.yaml)") | ||
|
||
RootCmd.AddCommand(start.NewStartCommand()) | ||
RootCmd.AddCommand(version.NewVersionCommand()) | ||
} | ||
|
||
// initConfig reads in config file and ENV variables if set. | ||
func initConfig() { | ||
if cfgFile != "" { | ||
// Use config file from the flag. | ||
viper.SetConfigFile(cfgFile) | ||
} else { | ||
// Find home directory. | ||
home, err := homedir.Dir() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
// Search config in home directory with name ".jaeger-operator" (without extension). | ||
viper.AddConfigPath(home) | ||
viper.SetConfigName(".jaeger-operator") | ||
} | ||
|
||
viper.AutomaticEnv() // read in environment variables that match | ||
|
||
// If a config file is found, read it in. | ||
if err := viper.ReadInConfig(); err == nil { | ||
fmt.Println("Using config file:", viper.ConfigFileUsed()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "github.com/jaegertracing/jaeger-operator/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package start | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
sdk "github.com/operator-framework/operator-sdk/pkg/sdk" | ||
k8sutil "github.com/operator-framework/operator-sdk/pkg/util/k8sutil" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // this | ||
|
||
stub "github.com/jaegertracing/jaeger-operator/pkg/stub" | ||
) | ||
|
||
// NewStartCommand starts the Jaeger Operator | ||
func NewStartCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "start", | ||
Short: "Starts a new Jaeger Operator", | ||
Long: "Starts a new Jaeger Operator", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
start(cmd, args) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func start(cmd *cobra.Command, args []string) { | ||
var ch = make(chan os.Signal, 0) | ||
signal.Notify(ch, os.Interrupt, syscall.SIGTERM) | ||
|
||
ctx := context.Background() | ||
|
||
sdk.ExposeMetricsPort() | ||
|
||
resource := "io.jaegertracing/v1alpha1" | ||
kind := "Jaeger" | ||
namespace, err := k8sutil.GetWatchNamespace() | ||
if err != nil { | ||
logrus.Fatalf("failed to get watch namespace: %v", err) | ||
} | ||
resyncPeriod := 5 | ||
logrus.Infof("Watching %s, %s, %s, %d", resource, kind, namespace, resyncPeriod) | ||
sdk.Watch(resource, kind, namespace, resyncPeriod) | ||
sdk.Handle(stub.NewHandler()) | ||
go sdk.Run(ctx) | ||
|
||
select { | ||
case <-ch: | ||
ctx.Done() | ||
logrus.Info("Jaeger Operator finished") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package version | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"runtime" | ||
|
||
sdkVersion "github.com/operator-framework/operator-sdk/version" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
gitCommit string | ||
buildDate string | ||
) | ||
|
||
// Info holds build information | ||
type Info struct { | ||
GoVersion string `json:"go-version"` | ||
OperatorSdkVersion string `json:"operator-sdk-version"` | ||
GitCommit string `json:"commit"` | ||
BuildDate string `json:"date"` | ||
} | ||
|
||
// Get creates and initialized Info object | ||
func Get() Info { | ||
return Info{ | ||
GitCommit: gitCommit, | ||
BuildDate: buildDate, | ||
GoVersion: runtime.Version(), | ||
OperatorSdkVersion: sdkVersion.Version, | ||
} | ||
} | ||
|
||
// NewVersionCommand creates the command that exposes the version | ||
func NewVersionCommand() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version", | ||
Long: `Print the version and build information`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
info := Get() | ||
json, err := json.Marshal(info) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(string(json)) | ||
|
||
return nil | ||
}, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.