From 360d92c59885fc3c1962ebede02a37adafc8d7f3 Mon Sep 17 00:00:00 2001 From: Piotr Kazmierczak <470696+pkazmierczak@users.noreply.github.com> Date: Wed, 17 May 2023 11:58:00 +0200 Subject: [PATCH] pack: url field no longer supported in pack metadata --- docs/writing-packs.md | 3 --- fixtures/bad_pack/metadata.hcl | 1 - .../my_alias_test/deps/child1/metadata.hcl | 1 - .../my_alias_test/deps/child2/metadata.hcl | 1 - .../packs/simple_raw_exec/metadata.hcl | 2 +- .../variable_test/variable_test/metadata.hcl | 1 - internal/pkg/cache/pack.go | 1 - sdk/pack/metadata.go | 7 ++++--- sdk/pack/metadata_test.go | 21 +++++++++---------- 9 files changed, 15 insertions(+), 23 deletions(-) diff --git a/docs/writing-packs.md b/docs/writing-packs.md index 9f2af9f..57bb8c1 100644 --- a/docs/writing-packs.md +++ b/docs/writing-packs.md @@ -50,7 +50,6 @@ The `metadata.hcl` file contains important key value information regarding the p - "app {url}" - The HTTP(S) url to the homepage of the application to provide a quick reference to the documentation and help pages. - "pack {name}" - The name of the pack. - "pack {description}" - A small overview of the application that is deployed by the pack. -- "pack {url}" - The source URL for the pack itself. - "pack {version}" - The version of the pack. - "dependency {name}" - The dependencies that the pack has on other packs. Multiple dependencies can be supplied. - "dependency {source}" - The source URL for this dependency. @@ -65,7 +64,6 @@ app { pack { name = "hello_world" description = "This pack contains a single job that renders hello world, or a different greeting, to the screen." - url = "https://github.com/hashicorp/nomad-pack-community-registry/hello_world" version = "0.3.2" } ``` @@ -243,7 +241,6 @@ app { pack { name = "simple_service" description = "This pack contains a simple service job, and depends on another pack." - url = "https://github.com/hashicorp/nomad-pack-community-registry/simple_service" version = "0.2.1" } diff --git a/fixtures/bad_pack/metadata.hcl b/fixtures/bad_pack/metadata.hcl index 7ab39bb..91dd9a4 100644 --- a/fixtures/bad_pack/metadata.hcl +++ b/fixtures/bad_pack/metadata.hcl @@ -8,6 +8,5 @@ app { pack { name = "simple_service" description = "This deploys a simple service job to Nomad that runs a docker container." - url = "https://github.com/hashicorp/nomad-pack-community-registry/simple_service" version = "0.0.1" } diff --git a/fixtures/test_registry/packs/my_alias_test/deps/child1/metadata.hcl b/fixtures/test_registry/packs/my_alias_test/deps/child1/metadata.hcl index 126d876..98df8da 100644 --- a/fixtures/test_registry/packs/my_alias_test/deps/child1/metadata.hcl +++ b/fixtures/test_registry/packs/my_alias_test/deps/child1/metadata.hcl @@ -8,6 +8,5 @@ app { pack { name = "child1" description = "render-only child dependency" - url = "github.com/hashicorp/nomad-pack/fixtures/test_registry/packs/simple-raw-exec" version = "0.0.1" } diff --git a/fixtures/test_registry/packs/my_alias_test/deps/child2/metadata.hcl b/fixtures/test_registry/packs/my_alias_test/deps/child2/metadata.hcl index 00f3590..c56be01 100644 --- a/fixtures/test_registry/packs/my_alias_test/deps/child2/metadata.hcl +++ b/fixtures/test_registry/packs/my_alias_test/deps/child2/metadata.hcl @@ -8,6 +8,5 @@ app { pack { name = "child2" description = "render-only child dependency" - url = "github.com/hashicorp/nomad-pack/fixtures/test_registry/packs/simple-raw-exec" version = "0.0.1" } diff --git a/fixtures/test_registry/packs/simple_raw_exec/metadata.hcl b/fixtures/test_registry/packs/simple_raw_exec/metadata.hcl index 73bfd6d..eecf56a 100644 --- a/fixtures/test_registry/packs/simple_raw_exec/metadata.hcl +++ b/fixtures/test_registry/packs/simple_raw_exec/metadata.hcl @@ -9,6 +9,6 @@ app { pack { name = "simple_raw_exec" description = "This is a test fixture pack used because all platforms support raw_exec" - url = "github.com/hashicorp/nomad-pack/fixtures/test_registry/packs/simple-raw-exec" + url = "github.com/hashicorp/nomad-pack/fixtures/test_registry/packs/simple-raw-exec" # url field deprecated, left here to make sure we don't panic and fail gracefully version = "0.0.1" } diff --git a/fixtures/variable_test/variable_test/metadata.hcl b/fixtures/variable_test/variable_test/metadata.hcl index d3bb9d3..8d0e008 100644 --- a/fixtures/variable_test/variable_test/metadata.hcl +++ b/fixtures/variable_test/variable_test/metadata.hcl @@ -8,6 +8,5 @@ app { pack { name = "variable_test_pack" description = "This pack tests variable overrides" - url = "" version = "0.0.1" } diff --git a/internal/pkg/cache/pack.go b/internal/pkg/cache/pack.go index 36a0d9e..5aa3455 100644 --- a/internal/pkg/cache/pack.go +++ b/internal/pkg/cache/pack.go @@ -76,7 +76,6 @@ func invalidPackDefinition(provider cacheOperationProvider) *Pack { Pack: &pack.MetadataPack{ Name: provider.ForPackName(), Description: "", - URL: "", Version: "Invalid pack definition", }, }, diff --git a/sdk/pack/metadata.go b/sdk/pack/metadata.go index 668080c..5e874dd 100644 --- a/sdk/pack/metadata.go +++ b/sdk/pack/metadata.go @@ -48,7 +48,10 @@ type MetadataPack struct { // URL is the HTTP(S) url of the pack which is acts as a convenience when // managing packs within a registry. - URL string `hcl:"url"` + // + // Deprecated: Nomad Pack tech preview 4 removes this field, we keep it here for + // backwards compatibility only. + URL string `hcl:"url,optional"` // Version is the version of the pack which is acts as a convenience when // managing packs within a registry. @@ -67,7 +70,6 @@ func (md *Metadata) ConvertToMapInterface() map[string]interface{} { "pack": map[string]interface{}{ "name": md.Pack.Name, "description": md.Pack.Description, - "url": md.Pack.URL, "version": md.Pack.Version, }, }, @@ -85,7 +87,6 @@ func (md *Metadata) AddToInterfaceMap(m map[string]interface{}) map[string]inter "pack": map[string]interface{}{ "name": md.Pack.Name, "description": md.Pack.Description, - "url": md.Pack.URL, "version": md.Pack.Version, }, } diff --git a/sdk/pack/metadata_test.go b/sdk/pack/metadata_test.go index 82d02dc..667fdbe 100644 --- a/sdk/pack/metadata_test.go +++ b/sdk/pack/metadata_test.go @@ -6,7 +6,7 @@ package pack import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/shoenig/test/must" ) func TestMetadata_ConvertToMapInterface(t *testing.T) { @@ -23,7 +23,6 @@ func TestMetadata_ConvertToMapInterface(t *testing.T) { Pack: &MetadataPack{ Name: "Example", Description: "The most basic, yet awesome, example", - URL: "https://example.com", Version: "v0.0.1", }, }, @@ -35,7 +34,6 @@ func TestMetadata_ConvertToMapInterface(t *testing.T) { "pack": map[string]interface{}{ "name": "Example", "description": "The most basic, yet awesome, example", - "url": "https://example.com", "version": "v0.0.1", }, }, @@ -61,7 +59,6 @@ func TestMetadata_ConvertToMapInterface(t *testing.T) { "pack": map[string]interface{}{ "name": "Example", "description": "", - "url": "https://example.com", "version": "v0.0.1", }, }, @@ -74,25 +71,27 @@ func TestMetadata_ConvertToMapInterface(t *testing.T) { URL: "https://example.com", Author: "The Nomad Team", }, - Pack: &MetadataPack{}, + Pack: &MetadataPack{ + URL: "https://example.com", + }, }, expectedOutput: map[string]interface{}{ "nomad_pack": map[string]interface{}{ "app": map[string]interface{}{ "url": "https://example.com", }, - "pack": map[string]interface{}{"name": "", "description": "", "url": "", "version": ""}, + "pack": map[string]interface{}{"name": "", "description": "", "version": ""}, }, }, // TODO test added to cover graceful failure while we're in the process of - // retiring "Author" metadata field. Can be removed later. - name: "author field ignored gracefully", + // retiring "Author" and "URL" metadata fields. Can be removed in the future. + name: "author and url fields ignored gracefully", }, } for _, tc := range testCases { actualOutput := tc.inputMetadata.ConvertToMapInterface() - assert.Equal(t, tc.expectedOutput, actualOutput, tc.name) + must.Eq(t, tc.expectedOutput, actualOutput, must.Sprint(tc.name)) } } @@ -125,9 +124,9 @@ func TestMetadata_Validate(t *testing.T) { for _, tc := range testCases { err := tc.inputMetadata.Validate() if tc.expectError { - assert.NotNil(t, err, tc.name) + must.NotNil(t, err, must.Sprint(tc.name)) } else { - assert.Nil(t, err, tc.name) + must.Nil(t, err, must.Sprint(tc.name)) } } }