Skip to content

Commit

Permalink
Make flag names easier to understand
Browse files Browse the repository at this point in the history
Now you specify a role instead of controlling the internal behaviour
  • Loading branch information
bboreham committed Oct 12, 2018
1 parent 1279a02 commit 78eaf93
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions prog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type probeFlags struct {
criEndpoint string

kubernetesEnabled bool
kubernetesTagOnly bool
kubernetesRole string
kubernetesNodeName string
kubernetesClientConfig kubernetes.ClientConfig
kubernetesKubeletPort uint
Expand Down Expand Up @@ -315,7 +315,7 @@ func setupFlags(flags *flags) {

// K8s
flag.BoolVar(&flags.probe.kubernetesEnabled, "probe.kubernetes", false, "collect kubernetes-related attributes for containers")
flag.BoolVar(&flags.probe.kubernetesTagOnly, "probe.kubernetes-tag", false, "tag containers with kubernetes parents")
flag.StringVar(&flags.probe.kubernetesRole, "probe.kubernetes.role", "", "host, cluster or blank for everything")
flag.StringVar(&flags.probe.kubernetesClientConfig.Server, "probe.kubernetes.api", "", "The address and port of the Kubernetes API server (deprecated in favor of equivalent probe.kubernetes.server)")
flag.StringVar(&flags.probe.kubernetesClientConfig.CertificateAuthority, "probe.kubernetes.certificate-authority", "", "Path to a cert. file for the certificate authority")
flag.StringVar(&flags.probe.kubernetesClientConfig.ClientCertificate, "probe.kubernetes.client-certificate", "", "Path to a client certificate file for TLS")
Expand Down
18 changes: 16 additions & 2 deletions prog/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ import (
const (
versionCheckPeriod = 6 * time.Hour
defaultServiceHost = "https://cloud.weave.works.:443"

kubernetesRoleHost = "host"
kubernetesRoleCluster = "cluster"
)

var (
Expand Down Expand Up @@ -230,6 +233,17 @@ func probeMain(flags probeFlags, targets []appclient.Target) {
defer endpointReporter.Stop()
p.AddReporter(endpointReporter)

switch flags.kubernetesRole {
case "": // nothing special
case kubernetesRoleHost:
flags.kubernetesEnabled = true
case kubernetesRoleCluster:
flags.kubernetesKubeletPort = 0
flags.kubernetesEnabled = true
default:
log.Warnf("unrecognized --probe.kubernetes.role: %s", flags.kubernetesRole)
}

if flags.dockerEnabled {
// Don't add the bridge in Kubernetes since container IPs are global and
// shouldn't be scoped
Expand Down Expand Up @@ -267,7 +281,7 @@ func probeMain(flags probeFlags, targets []appclient.Target) {
}
}

if flags.kubernetesEnabled {
if flags.kubernetesEnabled && flags.kubernetesRole != kubernetesRoleHost {
if client, err := kubernetes.NewClient(flags.kubernetesClientConfig); err == nil {
defer client.Stop()
reporter := kubernetes.NewReporter(client, clients, probeID, hostID, p, handlerRegistry, flags.kubernetesNodeName, flags.kubernetesKubeletPort)
Expand All @@ -279,7 +293,7 @@ func probeMain(flags probeFlags, targets []appclient.Target) {
}
}

if flags.kubernetesEnabled || flags.kubernetesTagOnly {
if flags.kubernetesEnabled {
p.AddTagger(&kubernetes.Tagger{})
}

Expand Down

0 comments on commit 78eaf93

Please sign in to comment.