-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename master to aggregator #847
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ limitations under the License. | |
package app | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/heptio/sonobuoy/pkg/config" | ||
|
@@ -27,47 +28,61 @@ import ( | |
"github.com/spf13/cobra" | ||
) | ||
|
||
var noExit bool | ||
var kubecfg Kubeconfig | ||
type aggregatorInput struct { | ||
noExit bool | ||
kubecfg Kubeconfig | ||
} | ||
|
||
func NewCmdMaster() *cobra.Command { | ||
// NewCmdAggregator returns the command that runs Sonobuoy as an aggregator. It will | ||
// load the config, launch plugins, gather results, and query the cluster for data. | ||
func NewCmdAggregator() *cobra.Command { | ||
input := aggregatorInput{} | ||
cmd := &cobra.Command{ | ||
Use: "master", | ||
Short: "Runs the master/aggregator component (for internal use)", | ||
Long: "Sonobuoy is an introspective kubernetes component that generates reports on cluster conformance, configuration, and more", | ||
Run: runMaster, | ||
Use: "aggregator", | ||
Short: "Runs the aggregator component (for internal use)", | ||
Long: "Sonobuoy is an introspective kubernetes component that generates reports on cluster conformance, configuration, and more", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't want to change this to |
||
if err := runAggregator(input); err != nil { | ||
errlog.LogError(err) | ||
os.Exit(1) | ||
} | ||
}, | ||
Hidden: true, | ||
Args: cobra.ExactArgs(0), | ||
|
||
// Original command but no longer used. Kept for backward compatibility. | ||
Aliases: []string{"master"}, | ||
} | ||
cmd.PersistentFlags().BoolVar( | ||
&noExit, "no-exit", false, | ||
&input.noExit, "no-exit", false, | ||
"Use this if you want sonobuoy to block and not exit. Useful when you want to explicitly grab results.tar.gz", | ||
) | ||
AddKubeconfigFlag(&kubecfg, cmd.Flags()) | ||
AddKubeconfigFlag(&input.kubecfg, cmd.Flags()) | ||
return cmd | ||
} | ||
|
||
func runMaster(cmd *cobra.Command, args []string) { | ||
|
||
func runAggregator(input aggregatorInput) error { | ||
cfg, err := config.LoadConfig() | ||
if err != nil { | ||
errlog.LogError(errors.Wrap(err, "error loading sonobuoy configuration")) | ||
os.Exit(1) | ||
return errors.Wrap(err, "error loading sonobuoy configuration") | ||
} | ||
|
||
kcfg, err := kubecfg.Get() | ||
kcfg, err := input.kubecfg.Get() | ||
if err != nil { | ||
errlog.LogError(err) | ||
os.Exit(1) | ||
return errors.Wrap(err, "getting kubeconfig") | ||
} | ||
|
||
// Run Discovery (gather API data, run plugins) | ||
errcount := discovery.Run(kcfg, cfg) | ||
|
||
if noExit { | ||
if input.noExit { | ||
logrus.Info("no-exit was specified, sonobuoy is now blocking") | ||
select {} | ||
} | ||
|
||
os.Exit(errcount) | ||
if errcount > 0 { | ||
return fmt.Errorf("%v errors encountered during execution", errcount) | ||
} | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,12 +35,13 @@ import ( | |
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewCmdWorker is the cobra command that acts as the entrypoint for Sonobuoy when running | ||
// as a sidecar with a plugin. It will wait for a 'done' file then transmit the results to the | ||
// aggregator pod. | ||
func NewCmdWorker() *cobra.Command { | ||
|
||
var workerCmd = &cobra.Command{ | ||
Use: "worker", | ||
Short: "Gather and send data to the sonobuoy master instance (for internal use)", | ||
Run: runGatherHelp, | ||
Short: "Gather and send data to the sonobuoy aggregator instance (for internal use)", | ||
Hidden: true, | ||
Args: cobra.ExactArgs(0), | ||
} | ||
|
@@ -65,10 +66,6 @@ var singleNodeCmd = &cobra.Command{ | |
Args: cobra.ExactArgs(0), | ||
} | ||
|
||
func runGatherHelp(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to add this, if you don't set a |
||
|
||
// sigHandler returns a channel that will receive a message after the timeout | ||
// elapses after a SIGTERM is received. | ||
func sigHandler(timeout time.Duration) <-chan struct{} { | ||
|
@@ -138,12 +135,15 @@ func runGather(global bool) error { | |
return errors.Wrap(err, "getting HTTP client") | ||
} | ||
|
||
// A single-node results URL looks like: | ||
// http://sonobuoy-master:8080/api/v1/results/by-node/node1/systemd_logs | ||
url := cfg.MasterURL + "/" + cfg.NodeName + "/" + cfg.ResultType | ||
url := "" | ||
if global { | ||
// http://sonobuoy-master:8080/api/v1/results/global/systemd_logs | ||
// A global results URL looks like: | ||
// http://sonobuoy-aggregator:8080/api/v1/results/global/systemd_logs | ||
url = cfg.MasterURL + "/" + cfg.ResultType | ||
} else { | ||
// A single-node results URL looks like: | ||
// http://sonobuoy-aggregator:8080/api/v1/results/by-node/node1/systemd_logs | ||
url = cfg.MasterURL + "/" + cfg.NodeName + "/" + cfg.ResultType | ||
} | ||
|
||
err = worker.GatherResults(cfg.ResultsDir+"/done", url, client, sigHandler(plugin.GracefulShutdownPeriod*time.Second)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ const ( | |
) | ||
|
||
// Plugin is a plugin driver that dispatches containers to each node, | ||
// expecting each pod to report to the master. | ||
// expecting each pod to report to the aggregator. | ||
type Plugin struct { | ||
driver.Base | ||
} | ||
|
@@ -51,7 +51,7 @@ type Plugin struct { | |
var _ plugin.Interface = &Plugin{} | ||
|
||
// NewPlugin creates a new DaemonSet plugin from the given Plugin Definition | ||
// and sonobuoy master address. | ||
// and sonobuoy aggregator address. | ||
func NewPlugin(dfn manifest.Manifest, namespace, sonobuoyImage, imagePullPolicy, imagePullSecrets string, customAnnotations map[string]string) *Plugin { | ||
return &Plugin{ | ||
driver.Base{ | ||
|
@@ -81,7 +81,7 @@ func (p *Plugin) ExpectedResults(nodes []v1.Node) []plugin.ExpectedResult { | |
return ret | ||
} | ||
|
||
func getMasterAddress(hostname string) string { | ||
func getAggregatorAddress(hostname string) string { | ||
return fmt.Sprintf("https://%s/api/v1/results/by-node", hostname) | ||
} | ||
|
||
|
@@ -107,7 +107,7 @@ func (p *Plugin) createDaemonSetDefinition(hostname string, cert *tls.Certificat | |
Labels: labels, | ||
Annotations: annotations, | ||
OwnerReferences: []metav1.OwnerReference{ | ||
metav1.OwnerReference{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a gofmt change; I have my editor set to use |
||
{ | ||
APIVersion: "v1", | ||
Kind: "Pod", | ||
Name: ownerPod.GetName(), | ||
|
@@ -160,7 +160,7 @@ func (p *Plugin) createDaemonSetDefinition(hostname string, cert *tls.Certificat | |
|
||
// Run dispatches worker pods according to the DaemonSet's configuration. | ||
func (p *Plugin) Run(kubeclient kubernetes.Interface, hostname string, cert *tls.Certificate, ownerPod *v1.Pod) error { | ||
daemonSet := p.createDaemonSetDefinition(getMasterAddress(hostname), cert, ownerPod) | ||
daemonSet := p.createDaemonSetDefinition(getAggregatorAddress(hostname), cert, ownerPod) | ||
|
||
secret, err := p.MakeTLSSecret(cert) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,7 +116,7 @@ type AggregationConfig struct { | |
|
||
// WorkerConfig is the file given to the sonobuoy worker to configure it to phone home. | ||
type WorkerConfig struct { | ||
// MasterURL is the URL we talk to for submitting results | ||
// MasterURL is the URL we talk to the aggregator pod on for submitting results | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did not change this since it is part of an exported struct/config. |
||
MasterURL string `json:"masterurl,omitempty" mapstructure:"masterurl"` | ||
// NodeName is the node name we should call ourselves when sending results | ||
NodeName string `json:"nodename,omitempty" mapstructure:"nodename"` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
|
||
## How it works now | ||
|
||
Sonobuoy uses a worker-master model, where a master delegates tasks to worker | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one line from some old docs had gotten updated; I don't really care about the older ones. If its no different to anyone else I'll just leave it rather than trying to fix up other sections in this (or other older docs) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these files even linked to from the site? I can't find any references to them. :-/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The enhancements aren't linked but they do actually exist if you manually write the URL. They were really for internal discussion/documentation back then; I made the decision that I didn't really want/need them to be displayed in our online docs site though. |
||
Sonobuoy uses a worker-master model, where an aggregator delegates tasks to worker | ||
pods. When those pods have finished, they need to report the results of their | ||
work back to the master. Presently this is done over an ill-defined, ad hoc | ||
REST-ish client/server model embedded in the server. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a single type/variable instead of 2 globals. I then create a single instance of this variable below in
NewCmdAggregator
which returns a closure around that instance.