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

bugfix for annotation updater. #490

Merged
merged 3 commits into from
Jul 19, 2018
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/conformance-testing.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Conformance Testing - [1.8+][6]
# Conformance Testing - [1.9+][6]

## Overview

Expand Down
6 changes: 3 additions & 3 deletions pkg/buildinfo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
35 changes: 32 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -73,7 +73,6 @@ var ClusterResources = []string{
"ServerGroups",
"ServerVersion",
"StorageClasses",
"ThirdPartyResources",
}

// NamespacedResources is the list of API resources that are scoped to a
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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

Expand Down
40 changes: 30 additions & 10 deletions pkg/plugin/aggregation/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package aggregation

import (
"context"
"fmt"
"net"
"net/http"
Expand All @@ -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.
Expand Down Expand Up @@ -108,25 +114,39 @@ 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("", "")
}()

updater := newUpdater(expectedResults, namespace, client)
ticker := time.NewTicker(annotationUpdateFreq)
ctx, cancel := context.WithCancel(context.TODO())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be .Background()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this case, nope.

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")
}
}
}()

// 3. Regularly annotate the Aggregator pod with the current run status
logrus.Info("Starting annotation update routine")
go func() {
defer ticker.Stop()
for range ticker.C {
updater.ReceiveAll(aggr.Results)
if err := updater.Annotate(); err != nil {
wait.JitterUntil(func() {
pluginsdone = aggr.isComplete()
if err := updater.Annotate(aggr.Results); err != nil {
logrus.WithError(err).Info("couldn't annotate sonobuoy pod")
}
if aggr.isComplete() {
return
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
Expand Down
4 changes: 3 additions & 1 deletion pkg/plugin/aggregation/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down