Skip to content

Commit

Permalink
Add dependencies-v2 experimental flag
Browse files Browse the repository at this point in the history
This introduces the dependencies-v2 experimental flag, under which any
changes from PEP003 - Advanced Dependencies will be implemented.

I have updated the porter.yaml to bundle.json adapter so that if someone
is using the flag now, they get an error that it's not implemented.

Signed-off-by: Carolyn Van Slyck <[email protected]>
  • Loading branch information
carolynvs committed Jul 18, 2022
1 parent 5488a8b commit 5f30d86
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
6 changes: 6 additions & 0 deletions docs/content/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You may set a default value for a configuration value in the config file, overri
* [Experimental Feature Flags](#experimental-feature-flags)
* [Build Drivers](#build-drivers)
* [Structured Logs](#structured-logs)
* [Dependencies v2](#dependencies-v2)
* [Common Configuration Settings](#common-configuration-settings)
* [Set Current Namespace](#namespace)
* [Enable Debug Output](#debug)
Expand Down Expand Up @@ -259,6 +260,11 @@ Below is a sample Porter configuration file that demonstrates how to set each of

[otel]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.8.0/specification/protocol/exporter.md

### Dependencies v2

The `dependencies-v2` experimental flag is not yet implemented.
When it is completed, it is used to activate the features from [PEP003 - Advanced Dependencies](https://github.com/getporter/proposals/blob/main/pep/003-dependency-namespaces-and-labels.md).

## Common Configuration Settings

Some configuration settings are applicable to many of Porter's commands and to save time you may want to set these values in the configuration file or with environment variables.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ require (
github.com/osteele/liquid v1.3.0
github.com/pelletier/go-toml v1.9.4
github.com/pivotal/image-relocation v0.0.0-20191111101224-e94aff6df06c
github.com/pkg/errors v0.9.1
github.com/spf13/afero v1.5.1
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
Expand Down Expand Up @@ -174,6 +173,7 @@ require (
github.com/opencontainers/runc v1.1.2 // indirect
github.com/osteele/tuesday v1.0.3 // indirect
github.com/pierrec/lz4/v4 v4.0.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
Expand Down
26 changes: 22 additions & 4 deletions pkg/cnab/config-adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"get.porter.sh/porter/pkg/cnab"
depsv1 "get.porter.sh/porter/pkg/cnab/dependencies/v1"
"get.porter.sh/porter/pkg/config"
"get.porter.sh/porter/pkg/experimental"
"get.porter.sh/porter/pkg/manifest"
"get.porter.sh/porter/pkg/mixin"
"get.porter.sh/porter/pkg/tracing"
Expand Down Expand Up @@ -407,7 +408,24 @@ func (c *ManifestConverter) generateBundleImages() map[string]bundle.Image {
return images
}

func (c *ManifestConverter) generateDependencies() (*depsv1.Dependencies, error) {
func (c *ManifestConverter) generateDependencies() (interface{}, string, error) {
if len(c.Manifest.Dependencies.RequiredDependencies) == 0 {
return nil, "", nil
}

// Check if they are using v1 of the dependencies spec or v2
if c.config.IsFeatureEnabled(experimental.FlagDependenciesV2) {
panic("the dependencies-v2 experimental flag was specified but is not yet implemented")
}

deps, err := c.generateDependenciesV1()
if err != nil {
return nil, "", err
}
return deps, cnab.DependenciesV1ExtensionKey, nil
}

func (c *ManifestConverter) generateDependenciesV1() (*depsv1.Dependencies, error) {
if len(c.Manifest.Dependencies.RequiredDependencies) == 0 {
return nil, nil
}
Expand Down Expand Up @@ -598,12 +616,12 @@ func (c *ManifestConverter) generateCustomExtensions(b *cnab.ExtendedBundle) (ma
}

// Add the dependency extension
deps, err := c.generateDependencies()
deps, depsExtKey, err := c.generateDependencies()
if err != nil {
return nil, err
}
if deps != nil && len(deps.Requires) > 0 {
customExtensions[cnab.DependenciesV1ExtensionKey] = deps
if depsExtKey != "" {
customExtensions[depsExtKey] = deps
}

// Add the parameter sources extension
Expand Down
7 changes: 5 additions & 2 deletions pkg/cnab/config-adapter/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,11 @@ func TestManifestConverter_generateDependencies(t *testing.T) {

a := NewManifestConverter(c.Config, m, nil, nil)

deps, err := a.generateDependencies()
require.NoError(t, err, "generateDependencies failed")
depsExt, depsExtKey, err := a.generateDependencies()
require.NoError(t, err)
require.Equal(t, cnab.DependenciesV1ExtensionKey, depsExtKey, "expected the v1 dependencies extension key")
require.IsType(t, &depsv1.Dependencies{}, depsExt, "expected a v1 dependencies extension section")
deps := depsExt.(*depsv1.Dependencies)
require.Len(t, deps.Requires, 3, "incorrect number of dependencies were generated")
require.Equal(t, []string{"mysql", "ad", "storage"}, deps.Sequence, "incorrect sequence was generated")

Expand Down
8 changes: 8 additions & 0 deletions pkg/experimental/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package experimental
const (
// NoopFeature is a placeholder feature flag that allows us to test our feature flag functions even when there are no active feature flags
NoopFeature = "no-op"

// DependenciesV2 is the name of the experimental feature flag for PEP003 - Advanced Dependencies.
DependenciesV2 = "dependencies-v2"
)

// FeatureFlags is an enum of possible feature flags
Expand All @@ -11,6 +14,9 @@ type FeatureFlags int
const (
// FlagNoopFeature is a placeholder feature flag that allows us to test our feature flag functions even when there are no active feature flags
FlagNoopFeature FeatureFlags = iota + 1

// FlagDependenciesV2 gates the changes from PEP003 - Advanced Dependencies.
FlagDependenciesV2
)

// ParseFlags converts a list of feature flag names into a bit map for faster lookups.
Expand All @@ -20,6 +26,8 @@ func ParseFlags(flags []string) FeatureFlags {
switch flag {
case NoopFeature:
experimental = experimental | FlagNoopFeature
case DependenciesV2:
experimental = experimental | FlagDependenciesV2
}
}
return experimental
Expand Down

0 comments on commit 5f30d86

Please sign in to comment.