Skip to content
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

Query ServerGroups to see supported API versions #66

Merged
merged 1 commit into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"ResourceQuotas",
"RoleBindings",
"Roles",
"ServerGroups",
"ServiceAccounts",
"Services",
"StatefulSets"
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ See [Parameter Reference][3] for a more detailed description of each setting.
"RoleBindings",
"Roles",
"Secrets",
"ServerGroups",
"ServiceAccounts",
"Services",
"StatefulSets"
Expand Down
1 change: 1 addition & 0 deletions examples/ksonnet/components/10-configmaps.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ local sonobuoyConfigData = {
"ResourceQuotas",
"RoleBindings",
"Roles",
"ServerGroups",
"ServiceAccounts",
"Services",
"StatefulSets"
Expand Down
1 change: 1 addition & 0 deletions examples/quickstart/aggregate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ data:
"ResourceQuotas",
"RoleBindings",
"Roles",
"ServerGroups",
"ServiceAccounts",
"Services",
"StatefulSets"
Expand Down
1 change: 1 addition & 0 deletions examples/quickstart/components/10-configmaps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ data:
"ResourceQuotas",
"RoleBindings",
"Roles",
"ServerGroups",
"ServiceAccounts",
"Services",
"StatefulSets"
Expand Down
11 changes: 9 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ var ClusterResources = []string{
"Nodes",
"PersistentVolumes",
"PodSecurityPolicies",
"ServerVersion",
"StorageClasses",
"ThirdPartyResources",
}
Expand All @@ -55,7 +54,6 @@ var NamespacedResources = []string{
"LimitRanges",
"PersistentVolumeClaims",
"PodDisruptionBudgets",
"PodLogs",
"PodPresets",
"PodTemplates",
"Pods",
Expand All @@ -70,6 +68,14 @@ var NamespacedResources = []string{
"StatefulSets",
}

// SpecialResources are resources that aren't queried (or stored) the same was
// as the rest, so need special casing for querying them.
var SpecialResources = []string{
"PodLogs",
"ServerGroups",
"ServerVersion",
}

// FilterOptions allow operators to select sets to include in a report
type FilterOptions struct {
Namespaces string `json:"Namespaces"`
Expand Down Expand Up @@ -147,6 +153,7 @@ func NewWithDefaults() *Config {

cfg.Resources = ClusterResources
cfg.Resources = append(cfg.Resources, NamespacedResources...)
cfg.Resources = append(cfg.Resources, SpecialResources...)

cfg.PluginNamespace = metav1.NamespaceSystem

Expand Down
33 changes: 18 additions & 15 deletions pkg/discovery/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,13 @@ func QueryNSResources(kubeClient kubernetes.Interface, recorder *QueryRecorder,

// 3. Execute the ns-query
for resourceKind := range resources {
// We use annotations to tag resources as being namespaced vs not, skip any
// that aren't "ns"
if resourceKind != "PodLogs" {
lister := func() (runtime.Object, error) { return queryNsResource(ns, resourceKind, opts, kubeClient) }
query := func() (time.Duration, error) { return objListQuery(outdir+"/", resourceKind+".json", lister) }
timedQuery(recorder, resourceKind, ns, query)
}
lister := func() (runtime.Object, error) { return queryNsResource(ns, resourceKind, opts, kubeClient) }
query := func() (time.Duration, error) { return objListQuery(outdir+"/", resourceKind+".json", lister) }
timedQuery(recorder, resourceKind, ns, query)
}

if resources["PodLogs"] {
specialResources := cfg.FilterResources(config.SpecialResources)
if specialResources["PodLogs"] {
start := time.Now()
err := gatherPodLogs(kubeClient, ns, opts, cfg)
if err != nil {
Expand Down Expand Up @@ -257,12 +254,9 @@ func QueryClusterResources(kubeClient kubernetes.Interface, recorder *QueryRecor

// 2. Execute the non-ns-query
for resourceKind := range resources {
// Eliminate special cases.
if resourceKind != "ServerVersion" {
lister := func() (runtime.Object, error) { return queryNonNsResource(resourceKind, kubeClient) }
query := func() (time.Duration, error) { return objListQuery(outdir+"/", resourceKind+".json", lister) }
timedQuery(recorder, resourceKind, "", query)
}
lister := func() (runtime.Object, error) { return queryNonNsResource(resourceKind, kubeClient) }
query := func() (time.Duration, error) { return objListQuery(outdir+"/", resourceKind+".json", lister) }
timedQuery(recorder, resourceKind, "", query)
}

// cfg.Nodes configures whether users want to gather the Nodes resource in the
Expand All @@ -277,13 +271,22 @@ func QueryClusterResources(kubeClient kubernetes.Interface, recorder *QueryRecor
recorder.RecordQuery("Nodes", "", duration, err)
}

if resources["ServerVersion"] {
specialResources := cfg.FilterResources(config.SpecialResources)
if specialResources["ServerVersion"] {
objqry := func() (interface{}, error) { return kubeClient.Discovery().ServerVersion() }
query := func() (time.Duration, error) {
return untypedQuery(cfg.OutputDir(), "serverversion.json", objqry)
}
timedQuery(recorder, "serverversion", "", query)
}

if specialResources["ServerGroups"] {
objqry := func() (interface{}, error) { return kubeClient.Discovery().ServerGroups() }
query := func() (time.Duration, error) {
return untypedQuery(cfg.OutputDir(), "servergroups.json", objqry)
}
timedQuery(recorder, "servergroups", "", query)
}

return nil
}
6 changes: 6 additions & 0 deletions pkg/discovery/queryrecorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"os"
"path"
"time"

"github.com/heptio/sonobuoy/pkg/errlog"
"github.com/pkg/errors"
)

type QueryRecorder struct {
Expand All @@ -42,6 +45,9 @@ type queryData struct {
}

func (q *QueryRecorder) RecordQuery(name string, namespace string, duration time.Duration, recerr error) {
if recerr != nil {
errlog.LogError(errors.Wrapf(recerr, "error querying %v", name))
}
summary := &queryData{
QueryObj: name,
Namespace: namespace,
Expand Down