Skip to content

Commit

Permalink
Merge branch 'main' into callHostSecretsPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kichristensen authored Aug 1, 2024
2 parents f9f58a1 + 6292541 commit 855a150
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,41 @@ install:
database-password: ${ bundle.dependencies.mysql.outputs.mysql-password }
```

##### Dependecies v2 (experimental)

The second version of dependencies, called DependenciesV2, is available under the
[**experimental** flag](https://porter.sh/docs/configuration/configuration/#experimental-feature-flags).

You can enable the experimental flag by setting an environment variable as follows:

```
PORTER_EXPERIMENTAL=dependencies-v2
```

When DependenciesV2 is enabled, it is possible to use templating inside the dependency output section, like this:

```yaml
dependencies:
requires:
- name: mysql
bundle:
reference: getporter/mysql:v0.1.3
outputs:
connection-string: "Server=mysql;Database=myDb;Uid=${bundle.parameters.uid};Pwd=${bundles.dependencies.mysql.mysql-password};"
```

If referencing an output from the same dependency, the format `outputs.OUTPUT_NAME` can also be used.

```yaml
dependencies:
requires:
- name: mysql
bundle:
reference: getporter/mysql:v0.1.3
outputs:
connection-string: "Server=mysql;Database=myDb;Uid=${bundle.parameters.uid};Pwd=${outputs.mysql-password};"
```

#### images

The bundle.images variable contains metadata about [referenced images] in the bundle.
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ require (
go.mongodb.org/mongo-driver v1.13.1
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0
go.opentelemetry.io/otel/sdk v1.28.0
go.opentelemetry.io/otel/trace v1.28.0
go.uber.org/zap v1.27.0
golang.org/x/sync v0.7.0
google.golang.org/grpc v1.64.1
google.golang.org/protobuf v1.34.1
google.golang.org/protobuf v1.34.2
gopkg.in/AlecAivazis/survey.v1 v1.8.8
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -226,7 +226,7 @@ require (
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.44.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
Expand All @@ -237,8 +237,8 @@ require (
golang.org/x/time v0.5.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -920,10 +920,10 @@ go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 h1:Xs2Ncz0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0/go.mod h1:vy+2G/6NvVMpwGX/NyLqcC41fxepnuKHk16E6IZUcJc=
go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo=
go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 h1:R9DE4kQ4k+YtfLI2ULwX82VtNQ2J8yZmA7ZIF/D+7Mc=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0/go.mod h1:OQFyQVrDlbe+R7xrEyDr/2Wr67Ol0hRUgsfA+V5A95s=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY=
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 h1:R3X6ZXmNPRR8ul6i3WgFURCHzaXjHdm0karRG/+dj3s=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0/go.mod h1:QWFXnDavXWwMx2EEcZsf3yxgEKAqsxQ+Syjp+seyInw=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 h1:QY7/0NeRPKlzusf40ZE4t1VlMKbqSNT7cJRYzWuja0s=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0/go.mod h1:HVkSiDhTM9BoUJU8qE6j2eSWLLXvi1USXjyd2BXT8PY=
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.28.0 h1:EVSnY9JbEEW92bEkIYOVMw4q1WJxIAGoFTrtYOzWuRQ=
Expand All @@ -934,8 +934,8 @@ go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBq
go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg=
go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g=
go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI=
go.opentelemetry.io/proto/otlp v1.2.0 h1:pVeZGk7nXDC9O2hncA6nHldxEjm6LByfA2aN8IOkz94=
go.opentelemetry.io/proto/otlp v1.2.0/go.mod h1:gGpR8txAl5M03pDhMC79G6SdqNV26naRm/KDsgaHD8A=
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
Expand Down Expand Up @@ -1184,10 +1184,10 @@ google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvx
google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY=
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:VUhTRKeHn9wwcdrk73nvdC9gF178Tzhmt/qyaFcPLSo=
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 h1:P8OJ/WCl/Xo4E4zoe4/bifHpSmmKwARqyqE4nW6J2GQ=
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5/go.mod h1:RGnPtTG7r4i8sPlNyDeikXF99hMM+hN6QMm4ooG9g2g=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5 h1:Q2RxlXqh1cgzzUgV261vBO2jI5R/3DD1J2pM0nI4NhU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240520151616-dc85e6b867a5/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 h1:0+ozOGcrp+Y8Aq8TLNN2Aliibms5LEzsq99ZZmAGYm0=
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094/go.mod h1:fJ/e3If/Q67Mj99hin0hMhiNyCRmt6BQ2aWIJshUSJw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.0.5/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
Expand All @@ -1212,8 +1212,8 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/AlecAivazis/survey.v1 v1.8.8 h1:5UtTowJZTz1j7NxVzDGKTz6Lm9IWm8DDF6b7a2wq9VY=
gopkg.in/AlecAivazis/survey.v1 v1.8.8/go.mod h1:CaHjv79TCgAvXMSFJSVgonHXYWxnhzI3eoHtnX5UgUo=
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
Expand Down
2 changes: 1 addition & 1 deletion pkg/cnab/config-adapter/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func LoadTestBundle(t *testing.T, config *config.Config, path string) cnab.ExtendedBundle {
ctx := context.Background()
m, err := manifest.ReadManifest(config.Context, path)
m, err := manifest.ReadManifest(config.Context, path, config)
require.NoError(t, err)
b, err := ConvertToTestBundle(ctx, config, m)
require.NoError(t, err)
Expand Down
22 changes: 22 additions & 0 deletions pkg/cnab/config-adapter/testdata/myenv-depsv2.bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
"env": "LOGLEVEL"
}
},
"porter-app-port-dep-output": {
"definition": "porter-app-port-dep-output",
"description": "Wires up the app dependency port output for use as a parameter. Porter internal parameter that should not be set manually.",
"destination": {
"env": "PORTER_APP_PORT_DEP_OUTPUT"
}
},
"porter-debug": {
"definition": "porter-debug-parameter",
"description": "Print debug information from Porter when executing the bundle",
Expand Down Expand Up @@ -69,6 +76,10 @@
"default": "info",
"type": "string"
},
"porter-app-port-dep-output": {
"$comment": "porter-internal",
"$id": "https://porter.sh/generated-bundle/#porter-parameter-source-definition"
},
"porter-debug-parameter": {
"$comment": "porter-internal",
"$id": "https://porter.sh/generated-bundle/#porter-debug",
Expand Down Expand Up @@ -99,6 +110,17 @@
],
"custom": {
"io.cnab.parameter-sources": {
"porter-app-port-dep-output": {
"priority": [
"dependencies.output"
],
"sources": {
"dependencies.output": {
"dependency": "app",
"name": "port"
}
}
},
"porter-infra-ip-dep-output": {
"priority": [
"dependencies.output"
Expand Down
9 changes: 5 additions & 4 deletions pkg/linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"

"get.porter.sh/porter/pkg/config"
"get.porter.sh/porter/pkg/manifest"
"get.porter.sh/porter/pkg/mixin/query"
"get.porter.sh/porter/pkg/pkgmgmt"
Expand Down Expand Up @@ -160,7 +161,7 @@ type action struct {
steps manifest.Steps
}

func (l *Linter) Lint(ctx context.Context, m *manifest.Manifest) (Results, error) {
func (l *Linter) Lint(ctx context.Context, m *manifest.Manifest, config *config.Config) (Results, error) {
// Check for reserved porter prefix on parameter names
reservedPrefixes := []string{"porter-", "porter_"}
params := m.Parameters
Expand Down Expand Up @@ -205,7 +206,7 @@ func (l *Linter) Lint(ctx context.Context, m *manifest.Manifest) (Results, error
actions = append(actions, action{actionName, steps})
}
for _, action := range actions {
res, err := validateParamsAppliesToAction(m, action.steps, tmplParams, action.name)
res, err := validateParamsAppliesToAction(m, action.steps, tmplParams, action.name, config)
if err != nil {
return nil, span.Error(fmt.Errorf("error validating action: %s", action.name))
}
Expand Down Expand Up @@ -266,15 +267,15 @@ func (l *Linter) Lint(ctx context.Context, m *manifest.Manifest) (Results, error
return results, nil
}

func validateParamsAppliesToAction(m *manifest.Manifest, steps manifest.Steps, tmplParams manifest.ParameterDefinitions, actionName string) (Results, error) {
func validateParamsAppliesToAction(m *manifest.Manifest, steps manifest.Steps, tmplParams manifest.ParameterDefinitions, actionName string, config *config.Config) (Results, error) {
var results Results
for stepNumber, step := range steps {
data, err := yaml.Marshal(step.Data)
if err != nil {
return nil, fmt.Errorf("error during marshalling: %w", err)
}

tmplResult, err := m.ScanManifestTemplating(data)
tmplResult, err := m.ScanManifestTemplating(data, config)
if err != nil {
return nil, fmt.Errorf("error parsing templating: %w", err)
}
Expand Down
29 changes: 18 additions & 11 deletions pkg/linter/linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

"get.porter.sh/porter/pkg/config"
"get.porter.sh/porter/pkg/manifest"
"get.porter.sh/porter/pkg/mixin"
"get.porter.sh/porter/pkg/portercontext"
Expand All @@ -13,6 +14,8 @@ import (

func TestLinter_Lint(t *testing.T) {
ctx := context.Background()
testConfig := config.NewTestConfig(t).Config

t.Run("no results", func(t *testing.T) {
cxt := portercontext.NewTestContext(t)
mixins := mixin.NewTestMixinProvider()
Expand All @@ -26,7 +29,7 @@ func TestLinter_Lint(t *testing.T) {
}
mixins.LintResults = nil

results, err := l.Lint(ctx, m)
results, err := l.Lint(ctx, m, testConfig)
require.NoError(t, err, "Lint failed")
require.Len(t, results, 0, "linter should have returned 0 results")
})
Expand All @@ -50,7 +53,7 @@ func TestLinter_Lint(t *testing.T) {
},
}

results, err := l.Lint(ctx, m)
results, err := l.Lint(ctx, m, testConfig)
require.NoError(t, err, "Lint failed")
require.Len(t, results, 1, "linter should have returned 1 result")
require.Equal(t, mixins.LintResults, results, "unexpected lint results")
Expand All @@ -68,7 +71,7 @@ func TestLinter_Lint(t *testing.T) {
},
}

results, err := l.Lint(ctx, m)
results, err := l.Lint(ctx, m, testConfig)
require.NoError(t, err, "Lint failed")
require.Len(t, results, 0, "linter should ignore mixins that doesn't support the lint command")
})
Expand Down Expand Up @@ -121,7 +124,7 @@ func TestLinter_Lint(t *testing.T) {
},
}

results, err := l.Lint(ctx, m)
results, err := l.Lint(ctx, m, testConfig)
require.NoError(t, err, "Lint failed")
require.Len(t, results, 1, "linter should have returned 1 result")
require.Equal(t, mixins.LintResults, results, "unexpected lint results")
Expand Down Expand Up @@ -149,7 +152,7 @@ func TestLinter_Lint(t *testing.T) {
},
}

results, err := l.Lint(ctx, m)
results, err := l.Lint(ctx, m, testConfig)
require.NoError(t, err, "Lint failed")
require.Len(t, results, 0, "linter should have returned 1 result")
})
Expand All @@ -168,7 +171,7 @@ func TestLinter_Lint(t *testing.T) {
Parameters: param,
}

results, err := l.Lint(ctx, m)
results, err := l.Lint(ctx, m, testConfig)
require.NoError(t, err, "Lint failed")
require.Len(t, results, 1, "linter should have returned 1 result")
require.NotContains(t, results[0].String(), ": 0th step in the mixin ()")
Expand All @@ -189,6 +192,7 @@ func TestLinter_Lint_ParameterDoesNotApplyTo(t *testing.T) {
m.CustomActions["customAction"] = steps
}},
}
testConfig := config.NewTestConfig(t).Config

for _, tc := range testCases {
t.Run(tc.action, func(t *testing.T) {
Expand Down Expand Up @@ -236,7 +240,7 @@ func TestLinter_Lint_ParameterDoesNotApplyTo(t *testing.T) {
URL: "https://porter.sh/docs/references/linter/#porter-101",
},
}
results, err := l.Lint(ctx, m)
results, err := l.Lint(ctx, m, testConfig)
require.NoError(t, err, "Lint failed")
require.Len(t, results, 1, "linter should have returned 1 result")
require.Equal(t, lintResults, results, "unexpected lint results")
Expand All @@ -258,6 +262,7 @@ func TestLinter_Lint_ParameterAppliesTo(t *testing.T) {
m.CustomActions["customAction"] = steps
}},
}
testConfig := config.NewTestConfig(t).Config

for _, tc := range testCases {
t.Run(tc.action, func(t *testing.T) {
Expand Down Expand Up @@ -290,14 +295,16 @@ func TestLinter_Lint_ParameterAppliesTo(t *testing.T) {
}
tc.setSteps(m, steps)

results, err := l.Lint(ctx, m)
results, err := l.Lint(ctx, m, testConfig)
require.NoError(t, err, "Lint failed")
require.Len(t, results, 0, "linter should have returned 1 result")
})
}
}

func TestLinter_DependencyMultipleTimes(t *testing.T) {
testConfig := config.NewTestConfig(t).Config

t.Run("dependency defined multiple times", func(t *testing.T) {
cxt := portercontext.NewTestContext(t)
mixins := mixin.NewTestMixinProvider()
Expand All @@ -321,7 +328,7 @@ func TestLinter_DependencyMultipleTimes(t *testing.T) {
},
}

results, err := l.Lint(context.Background(), m)
results, err := l.Lint(context.Background(), m, testConfig)
require.NoError(t, err, "Lint failed")
require.Len(t, results, 1, "linter should have returned 1 result")
require.Equal(t, expectedResult, results, "unexpected lint results")
Expand All @@ -340,7 +347,7 @@ func TestLinter_DependencyMultipleTimes(t *testing.T) {
},
}

results, err := l.Lint(context.Background(), m)
results, err := l.Lint(context.Background(), m, testConfig)
require.NoError(t, err, "Lint failed")
require.Len(t, results, 0, "linter should have returned 0 result")
})
Expand All @@ -351,7 +358,7 @@ func TestLinter_DependencyMultipleTimes(t *testing.T) {

m := &manifest.Manifest{}

results, err := l.Lint(context.Background(), m)
results, err := l.Lint(context.Background(), m, testConfig)
require.NoError(t, err, "Lint failed")
require.Len(t, results, 0, "linter should have returned 0 result")
})
Expand Down
Loading

0 comments on commit 855a150

Please sign in to comment.