From 5fde1a0b3591c615023d92663e38442c72110706 Mon Sep 17 00:00:00 2001 From: "Timothy St. Clair" Date: Wed, 18 Jul 2018 10:29:41 -0500 Subject: [PATCH 1/3] bugfix for annotation updater. Signed-off-by: Timothy St. Clair --- pkg/plugin/aggregation/run.go | 41 ++++++++++++++++++++++---------- pkg/plugin/aggregation/update.go | 4 +++- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/pkg/plugin/aggregation/run.go b/pkg/plugin/aggregation/run.go index d95a0ae4c..5a3304105 100644 --- a/pkg/plugin/aggregation/run.go +++ b/pkg/plugin/aggregation/run.go @@ -17,6 +17,7 @@ limitations under the License. package aggregation import ( + "context" "fmt" "net" "net/http" @@ -27,10 +28,15 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/client-go/kubernetes" ) -var annotationUpdateFreq = 5 * time.Second +const ( + annotationUpdateFreq = 5 * time.Second + jitterFactor = 1.2 +) // Run runs an aggregation server and gathers results, in accordance with the // given sonobuoy configuration. @@ -113,22 +119,33 @@ func Run(client kubernetes.Interface, plugins []plugin.Interface, cfg plugin.Agg }() updater := newUpdater(expectedResults, namespace, client) - ticker := time.NewTicker(annotationUpdateFreq) - - // 3. Regularly annotate the Aggregator pod with the current run status - go func() { - defer ticker.Stop() - for range ticker.C { - updater.ReceiveAll(aggr.Results) - if err := updater.Annotate(); err != nil { + ctx, cancel := context.WithCancel(context.TODO()) + pluginsdone := false + defer func() { + if pluginsdone == false { + logrus.Info("Last update to annotations on exit") + // This is the async exit cleanup function. + // 1. Stop the annotation updater + cancel() + // 2. Try one last time to get an update out on exit + if err := updater.Annotate(aggr.Results); err != nil { logrus.WithError(err).Info("couldn't annotate sonobuoy pod") } - if aggr.isComplete() { - return - } } }() + // 3. Regularly annotate the Aggregator pod with the current run status + wait.JitterUntil(func() { + pluginsdone = aggr.isComplete() + if err := updater.Annotate(aggr.Results); err != nil { + logrus.WithError(err).Info("couldn't annotate sonobuoy pod") + } + if pluginsdone { + logrus.Info("All plugins have completed, status has been updated") + cancel() + } + }, annotationUpdateFreq, jitterFactor, true, ctx.Done()) + // 4. Launch each plugin, to dispatch workers which submit the results back for _, p := range plugins { cert, err := auth.ClientKeyPair(p.GetName()) diff --git a/pkg/plugin/aggregation/update.go b/pkg/plugin/aggregation/update.go index a5ef0841c..8fd2fa7d3 100644 --- a/pkg/plugin/aggregation/update.go +++ b/pkg/plugin/aggregation/update.go @@ -100,7 +100,8 @@ func (u *updater) Serialize() (string, error) { } // Annotate serialises the status json, then annotates the aggregator pod with the status. -func (u *updater) Annotate() error { +func (u *updater) Annotate(results map[string]*plugin.Result) error { + u.ReceiveAll(results) u.RLock() defer u.RUnlock() str, err := u.Serialize() @@ -118,6 +119,7 @@ func (u *updater) Annotate() error { return errors.Wrap(err, "couldn't patch pod annotation") } +// TODO (tstclair): Evaluate if this should be exported. // ReceiveAll takes a map of plugin.Result and calls Receive on all of them. func (u *updater) ReceiveAll(results map[string]*plugin.Result) { // Could have race conditions, but will be eventually consistent From aa795ab1ff88fc99104638b788f753086470112d Mon Sep 17 00:00:00 2001 From: "Timothy St. Clair" Date: Thu, 19 Jul 2018 12:42:18 -0500 Subject: [PATCH 2/3] Assorted fixes from testing in preparation for minor release Signed-off-by: Timothy St. Clair --- pkg/buildinfo/version.go | 6 +++--- pkg/config/config.go | 33 +++++++++++++++++++++++++++++++-- pkg/plugin/aggregation/run.go | 25 ++++++++++++++----------- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/pkg/buildinfo/version.go b/pkg/buildinfo/version.go index 30213df66..dbb40eefe 100644 --- a/pkg/buildinfo/version.go +++ b/pkg/buildinfo/version.go @@ -20,10 +20,10 @@ limitations under the License. package buildinfo // Version is the current version of Sonobuoy, set by the go linker's -X flag at build time -var Version = "v0.11.3" +var Version = "v0.11.4" // MinimumKubeVersion is the lowest API version of Kubernetes this release of Sonobuoy supports. -var MinimumKubeVersion = "1.8.0" +var MinimumKubeVersion = "1.9.0" // MaximumKubeVersion is the highest API version of Kubernetes this release of Sonobuoy supports. -var MaximumKubeVersion = "1.11.0" +var MaximumKubeVersion = "1.11.99" diff --git a/pkg/config/config.go b/pkg/config/config.go index 4e8dd5d9a..7479748d0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -73,7 +73,6 @@ var ClusterResources = []string{ "ServerGroups", "ServerVersion", "StorageClasses", - "ThirdPartyResources", } // NamespacedResources is the list of API resources that are scoped to a @@ -106,6 +105,36 @@ var NamespacedResources = []string{ "StatefulSets", } +// NamespacedDefaults is the default-list of API resources to gather +// TODO (tstclair): Clean up defaulting, this is temporary +var NamespacedDefaults = []string{ + "ConfigMaps", + "ControllerRevisions", + "CronJobs", + "DaemonSets", + "Deployments", + "Endpoints", + //"Events", + //"HorizontalPodAutoscalers", + "Ingresses", + "Jobs", + "LimitRanges", + "NetworkPolicies", + "PersistentVolumeClaims", + "PodDisruptionBudgets", + //"PodLogs", + "PodTemplates", + "Pods", + "ReplicaSets", + "ReplicationControllers", + "ResourceQuotas", + "RoleBindings", + "Roles", + "ServiceAccounts", + "Services", + "StatefulSets", +} + // FilterOptions allow operators to select sets to include in a report type FilterOptions struct { Namespaces string `json:"Namespaces"` @@ -249,7 +278,7 @@ func New() *Config { cfg.Filters.Namespaces = ".*" cfg.Resources = ClusterResources - cfg.Resources = append(cfg.Resources, NamespacedResources...) + cfg.Resources = append(cfg.Resources, NamespacedDefaults...) cfg.Namespace = DefaultNamespace diff --git a/pkg/plugin/aggregation/run.go b/pkg/plugin/aggregation/run.go index 5a3304105..00199f334 100644 --- a/pkg/plugin/aggregation/run.go +++ b/pkg/plugin/aggregation/run.go @@ -114,7 +114,7 @@ func Run(client kubernetes.Interface, plugins []plugin.Interface, cfg plugin.Agg logrus.WithFields(logrus.Fields{ "address": cfg.BindAddress, "port": cfg.BindPort, - }).Info("starting aggregation server") + }).Info("Starting aggregation server") doneServ <- srv.ListenAndServeTLS("", "") }() @@ -135,16 +135,19 @@ func Run(client kubernetes.Interface, plugins []plugin.Interface, cfg plugin.Agg }() // 3. Regularly annotate the Aggregator pod with the current run status - wait.JitterUntil(func() { - pluginsdone = aggr.isComplete() - if err := updater.Annotate(aggr.Results); err != nil { - logrus.WithError(err).Info("couldn't annotate sonobuoy pod") - } - if pluginsdone { - logrus.Info("All plugins have completed, status has been updated") - cancel() - } - }, annotationUpdateFreq, jitterFactor, true, ctx.Done()) + logrus.Info("Starting annotation update routine") + go func() { + wait.JitterUntil(func() { + pluginsdone = aggr.isComplete() + if err := updater.Annotate(aggr.Results); err != nil { + logrus.WithError(err).Info("couldn't annotate sonobuoy pod") + } + if pluginsdone { + logrus.Info("All plugins have completed, status has been updated") + cancel() + } + }, annotationUpdateFreq, jitterFactor, true, ctx.Done()) + }() // 4. Launch each plugin, to dispatch workers which submit the results back for _, p := range plugins { From 384e6178e470a09dbf8aa2d00d0618a49c4aae94 Mon Sep 17 00:00:00 2001 From: "Timothy St. Clair" Date: Thu, 19 Jul 2018 12:53:36 -0500 Subject: [PATCH 3/3] Updates version details Signed-off-by: Timothy St. Clair --- README.md | 2 +- docs/conformance-testing.md | 2 +- pkg/config/config.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index de473f6ea..55d192d18 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ for the following use cases: * Workload debugging * Custom data collection via extensible plugins -Sonobuoy supports Kubernetes versions 1.8 and later. +Sonobuoy supports Kubernetes versions 1.9 and later. [k8s]: https://github.com/kubernetes/kubernetes [e2e]: /docs/conformance-testing.md diff --git a/docs/conformance-testing.md b/docs/conformance-testing.md index 5ac084281..4b6b254a7 100644 --- a/docs/conformance-testing.md +++ b/docs/conformance-testing.md @@ -1,4 +1,4 @@ -# Conformance Testing - [1.8+][6] +# Conformance Testing - [1.9+][6] ## Overview diff --git a/pkg/config/config.go b/pkg/config/config.go index 7479748d0..a45e7c13c 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -56,7 +56,7 @@ var ( /////////////////////////////////////////////////////// // Note: The described resources are a 1:1 match // with kubectl UX for consistent user experience. -// xref: https://kubernetes.io/docs/api-reference/v1.8/ +// xref: https://kubernetes.io/docs/api-reference/v1.11/ /////////////////////////////////////////////////////// // ClusterResources is the list of API resources that are scoped to the entire