Skip to content

Commit

Permalink
Merge branch 'main' into docs-check-links
Browse files Browse the repository at this point in the history
  • Loading branch information
kichristensen authored May 22, 2024
2 parents 0d6200e + 16f5d6a commit e6cbd74
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 51 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/porter-integration-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
- main
paths-ignore:
- 'docs/**'
pull_request:
branches:
- main

env:
GOVERSION: 1.21.3
Expand Down
12 changes: 6 additions & 6 deletions docs/hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,37 @@ enableInlineShortcodes= true
# Docs Navigation
[[menu.main]]
name = "Install"
url = "/docs/getting-started/install-porter"
url = "/docs/getting-started/install-porter/"
identifier = "install-porter"
weight = 1

[[menu.main]]
name = "QuickStart"
url = "/docs/quickstart"
url = "/docs/quickstart/"
identifier = "quickstart"
weight = 2

[[menu.main]]
name = "Blog"
url = "/blog"
url = "/blog/"
identifier = "blog"
weight = 3

[[menu.main]]
name = "Community"
url = "/community"
url = "/community/"
identifier = "community"
weight = 4

[[menu.main]]
name = "Learning"
url = "/docs/learn"
url = "/docs/learn/"
identifier = "learn"
weight = 5

[[menu.main]]
name = "Docs"
url = "/docs"
url = "/docs/"
identifier = "docs"
weight = 6

Expand Down
4 changes: 2 additions & 2 deletions pkg/build/dockerfile-generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestPorter_generateDockerfile(t *testing.T) {
require.NoError(t, err)

// Verify that we logged the dockerfile contents
tests.RequireOutputContains(t, c.TestContext.GetError(), string(gotDockerfile), "expected the dockerfile to be printed to the logs")
tests.RequireOutputContains(t, c.TestContext.GetOutput(), string(gotDockerfile), "expected the dockerfile to be printed to the logs")
test.CompareGoldenFile(t, "testdata/buildkit.Dockerfile", string(gotDockerfile))

// Verify that we didn't generate a Dockerfile at the root of the bundle dir
Expand Down Expand Up @@ -305,7 +305,7 @@ COPY mybin /cnab/app/
require.NoError(t, err)

// Verify that we logged the dockerfile contents
tests.RequireOutputContains(t, c.TestContext.GetError(), string(gotDockerfile), "expected the dockerfile to be printed to the logs")
tests.RequireOutputContains(t, c.TestContext.GetOutput(), string(gotDockerfile), "expected the dockerfile to be printed to the logs")
assert.Equal(t, customFrom, string(gotDockerfile))
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func TestManifest_Validate_SchemaVersion(t *testing.T) {

// Check that a warning is printed
// We aren't returning an error because we want to give it a chance to work first. Later we may turn this into a hard error after people have had time to migrate.
assert.Contains(t, cfg.TestContext.GetError(), invalidVersionErr)
assert.Contains(t, cfg.TestContext.GetOutput(), invalidVersionErr)
})
}

Expand Down Expand Up @@ -549,7 +549,7 @@ func TestSetDefaults(t *testing.T) {
err := m.validateMetadata(ctx, cfg.Config)
require.NoError(t, err)
require.Contains(t,
cfg.TestContext.GetError(),
cfg.TestContext.GetOutput(),
"WARNING: both registry and reference were provided; using the reference value of getporter/org/mybun:v1.2.3 for the bundle reference\n",
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/porter/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (p *Porter) CredentialsApply(ctx context.Context, o ApplyOptions) error {
return err
}

span.Infof("Applied %s credential set", creds)
fmt.Fprintf(p.Out, "Applied %s credential set\n", creds)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/porter/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ func (p *Porter) ParametersApply(ctx context.Context, o ApplyOptions) error {
return err
}

span.Infof("Applied %s parameter set", params)
fmt.Fprintf(p.Out, "Applied %s parameter set\n", params)
return nil
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/porter/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestPorter_IsInstallationInSync(t *testing.T) {
insync, err := p.IsInstallationInSync(p.RootContext, i, nil, opts)
require.NoError(t, err)
assert.True(t, insync)
assert.Contains(t, p.TestConfig.TestContext.GetError(), "Ignoring because installation.uninstalled is true but the installation doesn't exist yet")
assert.Contains(t, p.TestConfig.TestContext.GetOutput(), "Ignoring because installation.uninstalled is true but the installation doesn't exist yet")
})

t.Run("new installation with uninstalled false", func(t *testing.T) {
Expand All @@ -51,7 +51,7 @@ func TestPorter_IsInstallationInSync(t *testing.T) {
insync, err := p.IsInstallationInSync(p.RootContext, i, nil, opts)
require.NoError(t, err)
assert.False(t, insync)
assert.Contains(t, p.TestConfig.TestContext.GetError(), "Triggering because the installation has not completed successfully yet")
assert.Contains(t, p.TestConfig.TestContext.GetOutput(), "Triggering because the installation has not completed successfully yet")
})

t.Run("installed - no changes", func(t *testing.T) {
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestPorter_IsInstallationInSync(t *testing.T) {
insync, err := p.IsInstallationInSync(p.RootContext, i, &run, upgradeOpts)
require.NoError(t, err)
assert.False(t, insync)
assert.Contains(t, p.TestConfig.TestContext.GetError(), "Triggering because the bundle definition has changed")
assert.Contains(t, p.TestConfig.TestContext.GetOutput(), "Triggering because the bundle definition has changed")
})

t.Run("installed - param changed", func(t *testing.T) {
Expand All @@ -123,7 +123,7 @@ func TestPorter_IsInstallationInSync(t *testing.T) {
insync, err := p.IsInstallationInSync(p.RootContext, i, &run, upgradeOpts)
require.NoError(t, err)
assert.False(t, insync)
assert.Contains(t, p.TestConfig.TestContext.GetError(), "Triggering because the parameters have changed")
assert.Contains(t, p.TestConfig.TestContext.GetOutput(), "Triggering because the parameters have changed")

})

Expand All @@ -146,7 +146,7 @@ func TestPorter_IsInstallationInSync(t *testing.T) {
insync, err := p.IsInstallationInSync(p.RootContext, i, &run, upgradeOpts)
require.NoError(t, err)
assert.False(t, insync)
assert.Contains(t, p.TestConfig.TestContext.GetError(), "Triggering because the credential set names have changed")
assert.Contains(t, p.TestConfig.TestContext.GetOutput(), "Triggering because the credential set names have changed")

})

Expand All @@ -165,7 +165,7 @@ func TestPorter_IsInstallationInSync(t *testing.T) {
insync, err := p.IsInstallationInSync(p.RootContext, i, nil, opts)
require.NoError(t, err)
assert.False(t, insync)
assert.Contains(t, p.TestConfig.TestContext.GetError(), "Triggering because installation.uninstalled is true")
assert.Contains(t, p.TestConfig.TestContext.GetOutput(), "Triggering because installation.uninstalled is true")
})

t.Run("uninstalled: uninstalled set to back to false", func(t *testing.T) {
Expand All @@ -185,6 +185,6 @@ func TestPorter_IsInstallationInSync(t *testing.T) {
insync, err := p.IsInstallationInSync(p.RootContext, i, nil, NewUninstallOptions())
require.NoError(t, err)
assert.True(t, insync)
assert.Contains(t, p.TestConfig.TestContext.GetError(), "Ignoring because the installation is uninstalled")
assert.Contains(t, p.TestConfig.TestContext.GetOutput(), "Ignoring because the installation is uninstalled")
})
}
25 changes: 23 additions & 2 deletions pkg/portercontext/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,18 @@ func (c *Context) configureLoggingWith(ctx context.Context, baseLogger zapcore.C
func (c *Context) makeConsoleLogger() zapcore.Core {
encoding := c.makeLogEncoding()

stdout := c.Out
stderr := c.Err
if f, ok := stdout.(*os.File); ok {
if isatty.IsTerminal(f.Fd()) {
stdout = colorable.NewColorable(f)
encoding.EncodeLevel = zapcore.LowercaseColorLevelEncoder
}
}

if f, ok := stderr.(*os.File); ok {
if isatty.IsTerminal(f.Fd()) {
stderr = colorable.NewColorable(f)
stdout = colorable.NewColorable(f)
encoding.EncodeLevel = zapcore.LowercaseColorLevelEncoder
}
}
Expand All @@ -227,7 +235,20 @@ func (c *Context) makeConsoleLogger() zapcore.Core {
encoding.LevelKey = ""
}
consoleEncoder := zapcore.NewConsoleEncoder(encoding)
return zapcore.NewCore(consoleEncoder, zapcore.AddSync(stderr), c.logCfg.Verbosity)

isInformational := func(lvl zapcore.Level) bool {
return lvl < zapcore.ErrorLevel && lvl >= c.logCfg.Verbosity
}
stdoutEnabler := zap.LevelEnablerFunc(isInformational)
stderrEnabler := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
return !isInformational(lvl) && lvl >= zapcore.ErrorLevel
})

return zapcore.NewTee(
zapcore.NewCore(consoleEncoder, zapcore.AddSync(stdout), stdoutEnabler),
zapcore.NewCore(consoleEncoder, zapcore.AddSync(stderr), stderrEnabler),
)
// return zapcore.NewCore(consoleEncoder, zapcore.AddSync(stdout), c.logCfg.Verbosity)
}

func (c *Context) configureFileLog(dir string) (zapcore.Core, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/portercontext/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func TestContext_LogToFile(t *testing.T) {

// Compare the human readable logs sent to stderr
if runtime.GOOS == "windows" {
c.CompareGoldenFile("testdata/expected-output-windows.txt", c.GetError())
c.CompareGoldenFile("testdata/expected-output-windows.txt", c.GetAllLogs())
} else {
c.CompareGoldenFile("testdata/expected-output.txt", c.GetError())
c.CompareGoldenFile("testdata/expected-output.txt", c.GetAllLogs())
}
}
12 changes: 10 additions & 2 deletions pkg/portercontext/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type TestContext struct {
cleanupDirs []string
capturedErr *bytes.Buffer
capturedOut *bytes.Buffer
captureLogs *bytes.Buffer
T *testing.T
}

Expand All @@ -37,10 +38,11 @@ type TestContext struct {
func NewTestContext(t *testing.T) *TestContext {
// Provide a way for tests to provide and capture stdin and stdout
// Copy output to the test log simultaneously, use go test -v to see the output
logs := &bytes.Buffer{}
err := &bytes.Buffer{}
aggErr := io.MultiWriter(err, test.Logger{T: t})
aggErr := io.MultiWriter(err, test.Logger{T: t}, logs)
out := &bytes.Buffer{}
aggOut := io.MultiWriter(out, test.Logger{T: t})
aggOut := io.MultiWriter(out, test.Logger{T: t}, logs)

innerContext := New()
innerContext.correlationId = "0"
Expand All @@ -64,6 +66,7 @@ func NewTestContext(t *testing.T) *TestContext {
Context: innerContext,
capturedOut: out,
capturedErr: err,
captureLogs: logs,
T: t,
}

Expand Down Expand Up @@ -266,6 +269,11 @@ func (c *TestContext) GetError() string {
return c.capturedErr.String()
}

// GetAllLogs returns all text logged both on stdout and stderr
func (c *TestContext) GetAllLogs() string {
return c.captureLogs.String()
}

func (c *TestContext) ClearOutputs() {
c.capturedOut.Truncate(0)
c.capturedErr.Truncate(0)
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"

"get.porter.sh/porter/pkg"
Expand Down Expand Up @@ -133,9 +134,11 @@ func TestRebuild(t *testing.T) {
bumpBundle()

// Explain the bundle, with --autobuild-disabled. It should work since the bundle has been built
explainJson, output := test.RequirePorter("explain", "--autobuild-disabled", "-o=json")
explainJson, output := test.RequirePorter("explain", "--autobuild-disabled", "-o=json", "--verbosity=warn")
tests.RequireOutputContains(t, output, "WARNING: The bundle is out-of-date. Skipping autobuild because --autobuild-disabled was specified")
require.NotContains(t, output, "Building bundle ===>")
// todo(kichristensen): in the future this should be improved
explainJson = strings.ReplaceAll(explainJson, "WARNING: The bundle is out-of-date. Skipping autobuild because --autobuild-disabled was specified", "")
var explainResult map[string]interface{}
err = json.Unmarshal([]byte(explainJson), &explainResult)
require.NoError(t, err, "could not marshal explain output as json")
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/invoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestInvokeCustomAction(t *testing.T) {

// Check that debug output from the porter runtime was printed by the bundle and porter collected it
// This checks that the PORTER_DEBUG parameter is being properly passed to a bundle when run with porter invoke --debug
gotStderr := p.TestConfig.TestContext.GetError()
gotStderr := p.TestConfig.TestContext.GetOutput()
tests.RequireOutputContains(t, gotStderr, runtimeDebugOutputCheck, "expected debug output from the porter runtime to be output by the bundle")

// Verify that the custom action was recorded properly
Expand Down
32 changes: 16 additions & 16 deletions tests/integration/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,46 @@ func TestMigration(t *testing.T) {
_, output := test.RequirePorter("storage", "migrate", "--old-home", oldHome, "--old-account=src", "--namespace", destNamespace)

// Verify that the installations were migrated to the specified namespace
output, _ = test.RequirePorter("list", "--namespace", destNamespace, "--output=json")
output, _ = test.RequirePorter("list", "--namespace", destNamespace, "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "installations-list-output.json"), output)

// Verify that all the previous runs were migrated
output, _ = test.RequirePorter("installation", "runs", "list", "--namespace", destNamespace, "hello1", "--output=json")
output, _ = test.RequirePorter("installation", "runs", "list", "--namespace", destNamespace, "hello1", "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "runs-list-hello1-output.json"), output)

output, _ = test.RequirePorter("installation", "runs", "list", "--namespace", destNamespace, "hello-llama", "--output=json")
output, _ = test.RequirePorter("installation", "runs", "list", "--namespace", destNamespace, "hello-llama", "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "runs-list-hello-llama-output.json"), output)

output, _ = test.RequirePorter("installation", "runs", "list", "--namespace", destNamespace, "creds-tutorial", "--output=json")
output, _ = test.RequirePorter("installation", "runs", "list", "--namespace", destNamespace, "creds-tutorial", "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "runs-list-creds-tutorial-output.json"), output)

output, _ = test.RequirePorter("installation", "runs", "list", "--namespace", destNamespace, "sensitive-data", "--output=json")
output, _ = test.RequirePorter("installation", "runs", "list", "--namespace", destNamespace, "sensitive-data", "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "runs-list-sensitive-data-output.json"), output)

// Verify that outputs were migrated, all the installations except sensitive-data only have logs (which aren't printed by installation outputs list)
// Show the logs from installing hello1
output, _ = test.RequirePorter("installation", "logs", "show", "--namespace", destNamespace, "-r=01G1VJGY43HT3KZN82DS6DDPWK")
output, _ = test.RequirePorter("installation", "logs", "show", "--namespace", destNamespace, "-r=01G1VJGY43HT3KZN82DS6DDPWK", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "logs-install-hello1.txt"), output)

// Show the logs from the last run of hello-llama
output, _ = test.RequirePorter("installation", "logs", "show", "--namespace", destNamespace, "-i=hello-llama")
output, _ = test.RequirePorter("installation", "logs", "show", "--namespace", destNamespace, "-i=hello-llama", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "logs-hello-llama.txt"), output)

// Show the outputs of the sensitive-data bundle
output, _ = test.RequirePorter("installation", "outputs", "list", "--namespace", destNamespace, "sensitive-data", "--output=json")
output, _ = test.RequirePorter("installation", "outputs", "list", "--namespace", destNamespace, "sensitive-data", "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "outputs-list-sensitive-data-output.json"), output)

// Dump out the migrated installations and make sure that all the fields are set correctly
output, _ = test.RequirePorter("installation", "show", "--namespace", destNamespace, "hello1", "--output=json")
output, _ = test.RequirePorter("installation", "show", "--namespace", destNamespace, "hello1", "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "installation-show-hello1-output.json"), output)

output, _ = test.RequirePorter("installation", "show", "--namespace", destNamespace, "hello-llama", "--output=json")
output, _ = test.RequirePorter("installation", "show", "--namespace", destNamespace, "hello-llama", "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "installation-show-hello-llama-output.json"), output)

output, _ = test.RequirePorter("installation", "show", "--namespace", destNamespace, "creds-tutorial", "--output=json")
output, _ = test.RequirePorter("installation", "show", "--namespace", destNamespace, "creds-tutorial", "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "installation-show-creds-tutorial-output.json"), output)

output, _ = test.RequirePorter("installation", "show", "--namespace", destNamespace, "sensitive-data", "--output=json")
output, _ = test.RequirePorter("installation", "show", "--namespace", destNamespace, "sensitive-data", "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "installation-show-sensitive-data-output.json"), output)

// Verify that the sensitive-data installation stored sensitive values in the secret store
Expand All @@ -86,18 +86,18 @@ func TestMigration(t *testing.T) {
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "secrets/01G6K8CZ08T78WXTJYHR0NTYBS-password"), string(secretParam))

// Verify that the parameter sets were migrated to the specified namespace
output, _ = test.RequirePorter("parameters", "list", "--namespace", destNamespace, "--output=json")
output, _ = test.RequirePorter("parameters", "list", "--namespace", destNamespace, "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "parameters-list-output.json"), output)

// Dump out the migrated parameter sets and make sure that all the fields are set correctly
output, _ = test.RequirePorter("parameters", "show", "--namespace", destNamespace, "hello-llama", "--output=json")
output, _ = test.RequirePorter("parameters", "show", "--namespace", destNamespace, "hello-llama", "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "parameters-show-hello-llama-output.json"), output)

// Verify that the credential sets were migrated to the specified namespace
output, _ = test.RequirePorter("credentials", "list", "--namespace", destNamespace, "--output=json")
output, _ = test.RequirePorter("credentials", "list", "--namespace", destNamespace, "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "credentials-list-output.json"), output)

// Dump out the migrated credential sets and make sure that all the fields are set correctly
output, _ = test.RequirePorter("credentials", "show", "--namespace", destNamespace, "credentials-tutorial", "--output=json")
output, _ = test.RequirePorter("credentials", "show", "--namespace", destNamespace, "credentials-tutorial", "--output=json", "--verbosity=info")
testhelpers.CompareGoldenFile(t, filepath.Join(testdata, "credentials-show-credentials-tutorial-output.json"), output)
}
8 changes: 4 additions & 4 deletions tests/integration/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ func TestPublish(t *testing.T) {
test.RequirePorter("create")

// Try to publish with autobuild disabled, it should fail
_, _, err = test.RunPorter("publish", "--autobuild-disabled")
require.ErrorContains(t, err, "Skipping autobuild because --autobuild-disabled was specified")
_, output, _ := test.RunPorter("publish", "--autobuild-disabled")
tests.RequireOutputContains(t, output, "Skipping autobuild because --autobuild-disabled was specified")

// Try again with autobuild disabled via a config setting instead of a flag
// This is a regression test for https://github.com/getporter/porter/issues/2735
test.EditYaml(path.Join(test.PorterHomeDir, "config.yaml"), func(yq *yaml.Editor) error {
return yq.SetValue("autobuild-disabled", "true")
})
_, output, err := test.RunPorter("publish")
_, output, _ = test.RunPorter("publish")
fmt.Println(output)
require.ErrorContains(t, err, "Skipping autobuild because --autobuild-disabled was specified")
tests.RequireOutputContains(t, output, "Skipping autobuild because --autobuild-disabled was specified")

// Build with version override
test.RequirePorter("build", "--version=0.0.0")
Expand Down
Loading

0 comments on commit e6cbd74

Please sign in to comment.