Skip to content

Commit

Permalink
Merge branch 'master' into gen-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
timothysc authored Jun 22, 2018
2 parents 2d36505 + d8008f6 commit a3d51d9
Show file tree
Hide file tree
Showing 22 changed files with 273 additions and 87 deletions.
4 changes: 3 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
builds:
- binary: sonobuoy
env:
- CGO_ENABLED=0
goos:
- windows
- darwin
Expand All @@ -8,6 +10,6 @@ builds:
- amd64
ldflags: -s -w -X github.com/heptio/sonobuoy/pkg/buildinfo.Version=v{{.Version}}
archive:
format: tar.gz
format: tar.gz
files:
- LICENSE
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM gcr.io/heptio-images/golang:1.9-alpine3.6
FROM golang:1.9-alpine3.6
MAINTAINER Timothy St. Clair "tstclair@heptio.com"

RUN apk add --no-cache ca-certificates
RUN apk add --no-cache ca-certificates bash
ADD sonobuoy /sonobuoy
ADD scripts/run_master.sh /run_master.sh
ADD scripts/run_single_node_worker.sh /run_single_node_worker.sh
Expand Down
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ ifneq ($(VERBOSE),)
VERBOSE_FLAG = -v
endif
BUILDMNT = /go/src/$(GOTARGET)
BUILD_IMAGE ?= gcr.io/heptio-images/golang:1.9-alpine3.6
BUILDCMD = go build -o $(TARGET) $(VERBOSE_FLAG) -ldflags "-X github.com/heptio/sonobuoy/pkg/buildinfo.Version=$(GIT_VERSION)"
BUILD_IMAGE ?= golang:1.9-alpine3.6
BUILDCMD = CGO_ENABLED=0 go build -o $(TARGET) $(VERBOSE_FLAG) -ldflags "-X github.com/heptio/sonobuoy/pkg/buildinfo.Version=$(GIT_VERSION)"
BUILD = $(BUILDCMD) $(GOTARGET)

TESTARGS ?= $(VERBOSE_FLAG) -timeout 60s
TEST_PKGS ?= $(GOTARGET)/cmd/... $(GOTARGET)/pkg/...
TEST_CMD = go test $(TESTARGS)
TEST = $(TEST_CMD) $(TEST_PKGS)
TEST = $(TEST_CMD) $(TEST_PKGS)

INT_TEST_PKGS ?= $(GOTARGET)/test/...
INT_TEST= $(TEST_CMD) $(INT_TEST_PKGS)
Expand All @@ -50,19 +50,19 @@ LINT = golint $(GOLINT_FLAGS) $(TEST_PKGS)
WORKDIR ?= /sonobuoy
DOCKER_BUILD ?= $(DOCKER) run --rm -v $(DIR):$(BUILDMNT) -w $(BUILDMNT) $(BUILD_IMAGE) /bin/sh -c

.PHONY: all container push clean cbuild test local-test local generate plugins int
.PHONY: all container push clean test local-test local generate plugins int

all: container

local-test:
local-test:
$(TEST)

# Unit tests
test: cbuild vet
# Unit tests
test: sonobuoy vet
$(DOCKER_BUILD) '$(TEST)'

# Integration tests
int: cbuild
int: sonobuoy
$(DOCKER_BUILD) '$(INT_TEST)'

lint:
Expand All @@ -71,14 +71,14 @@ lint:
vet:
$(DOCKER_BUILD) '$(VET)'

container:
container: sonobuoy
$(DOCKER) build \
-t $(REGISTRY)/$(TARGET):$(IMAGE_VERSION) \
-t $(REGISTRY)/$(TARGET):$(IMAGE_BRANCH) \
-t $(REGISTRY)/$(TARGET):$(GIT_REF) \
.

cbuild:
sonobuoy:
$(DOCKER_BUILD) '$(BUILD)'

push:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ welcome pull requests. Feel free to dig through the [issues][issue] and jump in.
* There is a [mailing list][list] and [Slack channel][slack] if you want to
interact with other members of the community

[coc]: https://github.com/heptio/sonobuoy/blob/master/CONTRIBUTING.md
[contrib]: https://github.com/heptio/sonobuoy/blob/master/CODE_OF_CONDUCT.md
[coc]: https://github.com/heptio/sonobuoy/blob/master/CODE_OF_CONDUCT.md
[contrib]: https://github.com/heptio/sonobuoy/blob/master/CONTRIBUTING.md
[list]: https://groups.google.com/forum/#!forum/heptio-sonobuoy
[slack]: https://kubernetes.slack.com/messages/sonobuoy

Expand Down
20 changes: 15 additions & 5 deletions cmd/sonobuoy/app/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/client-go/rest"
)

type e2eFlags struct {
Expand Down Expand Up @@ -75,11 +76,17 @@ func e2es(cmd *cobra.Command, args []string) {
os.Exit(1)
}
defer gzr.Close()
restConfig, err := e2eflags.kubecfg.Get()
if err != nil {
errlog.LogError(errors.Wrap(err, "couldn't get REST client"))
os.Exit(1)

var restConfig *rest.Config
// If we are doing a rerun, only then, we need kubeconfig
if e2eflags.rerun {
restConfig, err = e2eflags.kubecfg.Get()
if err != nil {
errlog.LogError(errors.Wrap(err, "couldn't get REST client"))
os.Exit(1)
}
}

sonobuoy, err := client.NewSonobuoyClient(restConfig)
if err != nil {
errlog.LogError(errors.Wrap(err, "could not create sonobuoy client"))
Expand All @@ -105,7 +112,10 @@ func e2es(cmd *cobra.Command, args []string) {
}

if !e2eflags.skipPreflight {
if errs := sonobuoy.PreflightChecks(&client.PreflightConfig{e2eflags.namespace}); len(errs) > 0 {
errs := sonobuoy.PreflightChecks(&client.PreflightConfig{
Namespace: e2eflags.namespace,
})
if len(errs) > 0 {
errlog.LogError(errors.New("Preflight checks failed"))
for _, err := range errs {
errlog.LogError(err)
Expand Down
9 changes: 3 additions & 6 deletions cmd/sonobuoy/app/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,9 @@ func genManifest(cmd *cobra.Command, args []string) {
errlog.LogError(err)
os.Exit(1)
}
kubeCfg, err := genflags.kubecfg.Get()
if err != nil {
errlog.LogError(errors.Wrap(err, "couldn't get kubernetes config"))
os.Exit(1)
}
sbc, err := client.NewSonobuoyClient(kubeCfg)
// Passing in `nil` and no `kubeconfig` because it is not required by the method
// for generating any manifests
sbc, err := client.NewSonobuoyClient(nil)
if err != nil {
errlog.LogError(errors.Wrap(err, "could not create sonobuoy client"))
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/sonobuoy/app/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func checkRBACEnabled(client rest.Interface) (bool, error) {

groups, ok := result.(*metav1.APIGroupList)
if !ok {
return false, fmt.Errorf("Unknown type for API group %t", groups)
return false, fmt.Errorf("Unknown type for API group %T", groups)
}

for _, group := range groups.Groups {
Expand Down
25 changes: 17 additions & 8 deletions cmd/sonobuoy/app/sonobuoyconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"encoding/json"
"io/ioutil"

"github.com/imdario/mergo"

"github.com/heptio/sonobuoy/pkg/client"
"github.com/heptio/sonobuoy/pkg/config"
"github.com/pkg/errors"
Expand Down Expand Up @@ -68,18 +70,25 @@ func (c *SonobuoyConfig) Get() *config.Config {
}

// GetConfigWithMode creates a config with the following algorithm:
// If the SonobuoyConfig isn't nil, use that
// If not, use the supplied Mode to modify a default config
// If no config is supplied defaults will be returned.
// If a config is supplied then the default values will be merged into the supplied config
// in order to allow users to supply a minimal config that will still work.
func GetConfigWithMode(sonobuoyCfg *SonobuoyConfig, mode client.Mode) *config.Config {
conf := config.New()

suppliedConfig := sonobuoyCfg.Get()
if suppliedConfig != nil {
return suppliedConfig
// Provide defaults but don't overwrite any customized configuration.
mergo.Merge(suppliedConfig, conf)
conf = suppliedConfig
}

defaultConfig := config.New()
modeConfig := mode.Get()
if modeConfig != nil {
defaultConfig.PluginSelections = modeConfig.Selectors
// if there are no plugins yet, set some based on the mode, otherwise use whatever was supplied.
if len(conf.PluginSelections) == 0 {
modeConfig := mode.Get()
if modeConfig != nil {
conf.PluginSelections = modeConfig.Selectors
}
}
return defaultConfig
return conf
}
117 changes: 117 additions & 0 deletions cmd/sonobuoy/app/sonobuoyconfig_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
Copyright 2018 Heptio Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package app

import (
"testing"

"github.com/heptio/sonobuoy/pkg/client"
"github.com/heptio/sonobuoy/pkg/config"
"github.com/heptio/sonobuoy/pkg/plugin"
)

func TestGetConfigWithMode(t *testing.T) {
defaultPluginSearchPath := config.New().PluginSearchPath
tcs := []struct {
name string
mode client.Mode
inputcm *SonobuoyConfig
expected *config.Config
}{
{
name: "Conformance mode when supplied config is nil (nothing interesting happens)",
mode: client.Conformance,
inputcm: &SonobuoyConfig{},
expected: &config.Config{
PluginSelections: []plugin.Selection{
plugin.Selection{Name: "e2e"},
plugin.Selection{Name: "systemd-logs"},
},
PluginSearchPath: defaultPluginSearchPath,
},
},
{
name: "Quick mode and a non-nil supplied config",
mode: client.Quick,
inputcm: &SonobuoyConfig{
Config: config.Config{
Aggregation: plugin.AggregationConfig{
BindAddress: "10.0.0.1",
},
},
// TODO(chuckha) consider exporting raw or not depending on it.
raw: "not nil",
},
expected: &config.Config{
PluginSelections: []plugin.Selection{
plugin.Selection{Name: "e2e"},
},
Aggregation: plugin.AggregationConfig{
BindAddress: "10.0.0.1",
BindPort: config.DefaultAggregationServerBindPort,
},
PluginSearchPath: defaultPluginSearchPath,
},
},
{
name: "Conformance mode with plugin selection specified",
mode: client.Conformance,
inputcm: &SonobuoyConfig{
Config: config.Config{
PluginSelections: []plugin.Selection{
plugin.Selection{
Name: "systemd-logs",
},
},
},
raw: "not empty",
},
expected: &config.Config{
PluginSelections: []plugin.Selection{
plugin.Selection{
Name: "systemd-logs",
},
},
PluginSearchPath: defaultPluginSearchPath,
Aggregation: plugin.AggregationConfig{
BindAddress: config.DefaultAggregationServerBindAddress,
BindPort: config.DefaultAggregationServerBindPort,
},
},
},
}

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
conf := GetConfigWithMode(tc.inputcm, tc.mode)
if len(conf.PluginSelections) != len(tc.expected.PluginSelections) {
t.Fatalf("expected %v plugin selections but found %v", tc.expected.PluginSelections, conf.PluginSelections)
}
for _, ps := range conf.PluginSelections {
found := false
for _, expectedPs := range tc.expected.PluginSelections {
if ps.Name == expectedPs.Name {
found = true
}
}
if !found {
t.Fatalf("looking for plugin selection %v but did not find it", ps)
}
}
})
}
}
2 changes: 1 addition & 1 deletion cmd/sonobuoy/app/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var statusFlags struct {
func init() {
cmd := &cobra.Command{
Use: "status",
Short: "Gets a summarizes status of a sonobuoy run",
Short: "Gets a summarized status of a sonobuoy run",
Run: getStatus,
Args: cobra.ExactArgs(0),
}
Expand Down
13 changes: 13 additions & 0 deletions docs/release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Release

## Steps to cut a release

1. Bump the version defined in the code. As of the time of writing it is in
`pkg/buildinfo/version.go`.
2. Commit and open a pull request.
3. Create a tag after that pull request gets squashed onto master. `git tag -a
v0.11.1`.
4. Push the tag with `git push --tags` (note this will push all tags). To push
just one tag do something like: `git push <remote> refs/tags/v0.11.1` where
`<remote>` refers to github.com/heptio/sonobuoy (this might be something like
`upstream` or `origin`). If you are unsure, use the first option.
2 changes: 1 addition & 1 deletion pkg/buildinfo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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.0"
var Version = "v0.11.3"

// MinimumKubeVersion is the lowest API version of Kubernetes this release of Sonobuoy supports.
var MinimumKubeVersion = "1.8.0"
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

// GetTests extracts the junit results from a sonobuoy archive and returns the requested tests.
func (c *SonobuoyClient) GetTests(reader io.Reader, show string) ([]reporters.JUnitTestCase, error) {
func (*SonobuoyClient) GetTests(reader io.Reader, show string) ([]reporters.JUnitTestCase, error) {
read := results.NewReaderWithVersion(reader, "irrelevant")
junitResults := reporters.JUnitTestSuite{}
err := read.WalkFiles(func(path string, info os.FileInfo, err error) error {
Expand Down
7 changes: 1 addition & 6 deletions pkg/client/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ import (
"encoding/json"
"strings"

"github.com/imdario/mergo"

"github.com/pkg/errors"

"github.com/heptio/sonobuoy/pkg/buildinfo"
"github.com/heptio/sonobuoy/pkg/config"
"github.com/heptio/sonobuoy/pkg/templates"
)

Expand All @@ -45,9 +42,7 @@ type templateValues struct {
}

// GenerateManifest fills in a template with a Sonobuoy config
func (c *SonobuoyClient) GenerateManifest(cfg *GenConfig) ([]byte, error) {
// Provide defaults but don't overwrite any customized configuration.
mergo.Merge(cfg.Config, config.New())
func (*SonobuoyClient) GenerateManifest(cfg *GenConfig) ([]byte, error) {
marshalledConfig, err := json.Marshal(cfg.Config)
if err != nil {
return nil, errors.Wrap(err, "couldn't marshall selector")
Expand Down
Loading

0 comments on commit a3d51d9

Please sign in to comment.