diff --git a/cmd/fluxd/checkpoint.go b/checkpoint/checkpoint.go similarity index 72% rename from cmd/fluxd/checkpoint.go rename to checkpoint/checkpoint.go index a597ab6b9..b4b04dc26 100644 --- a/cmd/fluxd/checkpoint.go +++ b/checkpoint/checkpoint.go @@ -1,4 +1,4 @@ -package main +package checkpoint import ( "time" @@ -11,7 +11,7 @@ const ( versionCheckPeriod = 6 * time.Hour ) -func checkForUpdates(clusterString string, gitString string, logger log.Logger) *checkpoint.Checker { +func CheckForUpdates(product, version string, extra map[string]string, logger log.Logger) *checkpoint.Checker { handleResponse := func(r *checkpoint.CheckResponse, err error) { if err != nil { logger.Log("err", err) @@ -25,12 +25,14 @@ func checkForUpdates(clusterString string, gitString string, logger log.Logger) } flags := map[string]string{ - "kernel-version": getKernelVersion(), - "cluster-version": clusterString, - "git-configured": gitString, + "kernel-version": getKernelVersion(), } + for k, v := range extra { + flags[k] = v + } + params := checkpoint.CheckParams{ - Product: "weave-flux", + Product: product, Version: version, SignatureFile: "", Flags: flags, diff --git a/cmd/fluxd/checkpoint_darwin.go b/checkpoint/checkpoint_darwin.go similarity index 89% rename from cmd/fluxd/checkpoint_darwin.go rename to checkpoint/checkpoint_darwin.go index c3311f7e1..726f522da 100644 --- a/cmd/fluxd/checkpoint_darwin.go +++ b/checkpoint/checkpoint_darwin.go @@ -1,4 +1,4 @@ -package main +package checkpoint import ( "syscall" diff --git a/cmd/fluxd/checkpoint_linux.go b/checkpoint/checkpoint_linux.go similarity index 94% rename from cmd/fluxd/checkpoint_linux.go rename to checkpoint/checkpoint_linux.go index 994e8176e..29a6cc1d3 100644 --- a/cmd/fluxd/checkpoint_linux.go +++ b/checkpoint/checkpoint_linux.go @@ -1,4 +1,4 @@ -package main +package checkpoint import ( "syscall" diff --git a/cmd/fluxd/main.go b/cmd/fluxd/main.go index 88e9f39dd..5044e4252 100644 --- a/cmd/fluxd/main.go +++ b/cmd/fluxd/main.go @@ -21,6 +21,7 @@ import ( k8sclient "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" + "github.com/weaveworks/flux/checkpoint" "github.com/weaveworks/flux/cluster" "github.com/weaveworks/flux/cluster/kubernetes" "github.com/weaveworks/flux/daemon" @@ -41,6 +42,8 @@ import ( var version = "unversioned" const ( + product = "weave-flux" + // The number of connections chosen for memcache and remote GETs should match for best performance (hence the single hardcoded value) // Value chosen through performance tests on sock-shop. I was unable to get higher performance than this. defaultRemoteConnections = 125 // Chosen performance tests on sock-shop. Unable to get higher performance than this. @@ -105,7 +108,7 @@ func main() { k8sSecretName = fs.String("k8s-secret-name", "flux-git-deploy", "Name of the k8s secret used to store the private SSH key") k8sSecretVolumeMountPath = fs.String("k8s-secret-volume-mount-path", "/etc/fluxd/ssh", "Mount location of the k8s secret storing the private SSH key") k8sSecretDataKey = fs.String("k8s-secret-data-key", "identity", "Data key holding the private SSH key within the k8s secret") - k8sNamespaceWhitelist = fs.StringSlice("k8s-namespace-whitelist", []string{}, "Experimental, optional: restrict the view of the cluster to the namespaces listed. All namespaces are included if this is not set.") + k8sNamespaceWhitelist = fs.StringSlice("k8s-namespace-whitelist", []string{}, "Experimental, optional: restrict the view of the cluster to the namespaces listed. All namespaces are included if this is not set.") // SSH key generation sshKeyBits = optionalVar(fs, &ssh.KeyBitsValue{}, "ssh-keygen-bits", "-b argument to ssh-keygen (default unspecified)") sshKeyType = optionalVar(fs, &ssh.KeyTypeValue{}, "ssh-keygen-type", "-t argument to ssh-keygen (default unspecified)") @@ -342,7 +345,11 @@ func main() { // report anything before seeing if it works. So, don't start // until we have failed or succeeded. updateCheckLogger := log.With(logger, "component", "checkpoint") - checkForUpdates(clusterVersion, strconv.FormatBool(*gitURL != ""), updateCheckLogger) + checkpointFlags := map[string]string{ + "cluster-version": clusterVersion, + "git-configured": strconv.FormatBool(*gitURL != ""), + } + checkpoint.CheckForUpdates(product, version, checkpointFlags, updateCheckLogger) gitRemote := git.Remote{URL: *gitURL} gitConfig := git.Config{ diff --git a/cmd/helm-operator/main.go b/cmd/helm-operator/main.go index 9ba6d9734..f74d1640b 100644 --- a/cmd/helm-operator/main.go +++ b/cmd/helm-operator/main.go @@ -14,6 +14,7 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" + "github.com/weaveworks/flux/checkpoint" "github.com/weaveworks/flux/git" clientset "github.com/weaveworks/flux/integrations/client/clientset/versioned" ifinformers "github.com/weaveworks/flux/integrations/client/informers/externalversions" @@ -31,6 +32,8 @@ var ( logger log.Logger kubectl string + versionFlag *bool + kubeconfig *string master *string @@ -60,11 +63,14 @@ var ( ) const ( + product = "weave-flux-helm" defaultGitChartsPath = "charts" ErrOperatorFailure = "Operator failure: %q" ) +var version = "unversioned" + func init() { // Flags processing fs = pflag.NewFlagSet("default", pflag.ExitOnError) @@ -76,6 +82,8 @@ func init() { fs.PrintDefaults() } + versionFlag = fs.Bool("version", false, "Print version and exit") + kubeconfig = fs.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.") master = fs.String("master", "", "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.") @@ -104,6 +112,11 @@ func main() { fs.Parse(os.Args) + if *versionFlag { + println(version) + os.Exit(0) + } + // LOGGING ------------------------------------------------------------------------------ { logger = log.NewLogfmtLogger(os.Stderr) @@ -222,6 +235,8 @@ func main() { // Starts handling k8s events related to the given resource kind go ifInformerFactory.Start(shutdown) + checkpoint.CheckForUpdates(product, version, nil, log.With(logger, "component", "checkpoint")) + if err = opr.Run(*queueWorkerCount, shutdown, shutdownWg); err != nil { msg := fmt.Sprintf("Failure to run controller: %s", err.Error()) logger.Log("error", msg)