Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pack: Author field no longer supported in metadata #317

Merged
merged 9 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

IMPROVEMENTS:
* deps: Update the Nomad OpenAPI depedency [[GH-288](https://github.com/hashicorp/nomad-pack/pull/288)] and require Go 1.18 as a build dependency
* pack: Author field no longer supported in pack metadata [[GH-317](https://github.com/hashicorp/nomad-pack/pull/317)]
* template: Render other templates than jobspecs inside `templates/` [[GH-303](https://github.com/hashicorp/nomad-pack/pull/303)]
* template: Automatically format templates before outputting [[GH-311](https://github.com/hashicorp/nomad-pack/pull/311)]
* template: Skip templates that would render to just whitespace [[GH-313](https://github.com/hashicorp/nomad-pack/pull/313)]
Expand Down
3 changes: 0 additions & 3 deletions docs/writing-packs.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ The directory should have the following contents:
The `metadata.hcl` file contains important key value information regarding the pack. It contains the following blocks and their associated fields:

- "app {url}" - The HTTP(S) url to the homepage of the application to provide a quick reference to the documentation and help pages.
- "app {author}" - An identifier to the author and maintainer of the pack.
- "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.
Expand All @@ -61,7 +60,6 @@ An example `metadata.hcl` file:
```
app {
url = "https://github.com/mikenomitch/hello_world_server"
author = "Mike Nomitch"
}

pack {
Expand Down Expand Up @@ -240,7 +238,6 @@ First, packs must define their dependencies in `metadata.hcl`. A pack stanza wit
```
app {
url = "https://some-url-for-the-application.dev"
author = "Borman Norlaug"
}

pack {
Expand Down
1 change: 0 additions & 1 deletion fixtures/bad_pack/metadata.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

app {
url = "https://learn.hashicorp.com/tutorials/nomad/get-started-run?in=nomad/get-started"
author = "HashiCorp"
}

pack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# SPDX-License-Identifier: MPL-2.0

app {
url = ""
author = "HashiCorp"
url = ""
}

pack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# SPDX-License-Identifier: MPL-2.0

app {
url = ""
author = "HashiCorp"
url = ""
}

pack {
Expand Down
2 changes: 1 addition & 1 deletion fixtures/test_registry/packs/my_alias_test/metadata.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

app {
url = ""
author = "HashiCorp"
author = "Nomad Team"
}

pack {
Expand Down
2 changes: 1 addition & 1 deletion fixtures/test_registry/packs/simple_raw_exec/metadata.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

app {
url = ""
author = "HashiCorp"
author = "Nomad Team" # author field deprecated, left here to make sure we don't panic and fail gracefully
}

pack {
Expand Down
3 changes: 1 addition & 2 deletions fixtures/variable_test/variable_test/metadata.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# SPDX-License-Identifier: MPL-2.0

app {
url = ""
author = "HashiCorp"
url = ""
}

pack {
Expand Down
7 changes: 4 additions & 3 deletions internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
"testing"
"time"

"github.com/hashicorp/nomad/command/agent"
"github.com/mitchellh/cli"
"github.com/stretchr/testify/require"

ct "github.com/hashicorp/nomad-pack/internal/cli/testhelper"
"github.com/hashicorp/nomad-pack/internal/pkg/cache"
flag "github.com/hashicorp/nomad-pack/internal/pkg/flag"
Expand All @@ -23,9 +27,6 @@ import (
"github.com/hashicorp/nomad-pack/internal/pkg/version"
"github.com/hashicorp/nomad-pack/internal/runner/job"
"github.com/hashicorp/nomad-pack/internal/testui"
"github.com/hashicorp/nomad/command/agent"
"github.com/mitchellh/cli"
"github.com/stretchr/testify/require"
)

// TODO: Test job run with diffs
Expand Down
6 changes: 0 additions & 6 deletions internal/cli/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ func (c *InfoCommand) Run(args []string) int {
glint.Text(pack.Metadata.App.URL),
).Row())

doc.Append(glint.Layout(
glint.Style(glint.Text("Application Author "), glint.Bold()),
glint.Text(pack.Metadata.App.Author),
glint.Text("\n"),
).Row())

for pName, variables := range parsedVars.Vars {

doc.Append(glint.Layout(
Expand Down
3 changes: 1 addition & 2 deletions internal/creator/templates/pack_metadata.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# SPDX-License-Identifier: MPL-2.0

app {
url = ""
author = ""
url = ""
}
pack {
name = "{{.PackName}}"
Expand Down
4 changes: 0 additions & 4 deletions internal/pkg/cache/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ func invalidPackDefinition(provider cacheOperationProvider) *Pack {
Ref: provider.AtRef(),
Pack: &pack.Pack{
Metadata: &pack.Metadata{
App: &pack.MetadataApp{
URL: "",
Author: "",
},
Pack: &pack.MetadataPack{
Name: provider.ForPackName(),
Description: "",
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"github.com/hashicorp/hcl/v2/hclsimple"

"github.com/hashicorp/nomad-pack/sdk/pack"
)

Expand Down
11 changes: 6 additions & 5 deletions sdk/pack/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ type MetadataApp struct {

// Author is an identifier to the author and maintainer of the pack such as
// HashiCorp or James Rasell
Author string `hcl:"author"`
//
// Deprecated: Nomad Pack tech preview 4 removes this field, we keep it here for
// backwards compatibility only.
Author string `hcl:"author,optional"`

// TODO: Add Version here, may need to be a block or series of entries to
// support packs that contain multiple apps.
Expand Down Expand Up @@ -59,8 +62,7 @@ func (md *Metadata) ConvertToMapInterface() map[string]interface{} {
return map[string]interface{}{
"nomad_pack": map[string]interface{}{
"app": map[string]interface{}{
"url": md.App.URL,
"author": md.App.Author,
"url": md.App.URL,
},
"pack": map[string]interface{}{
"name": md.Pack.Name,
Expand All @@ -78,8 +80,7 @@ func (md *Metadata) ConvertToMapInterface() map[string]interface{} {
func (md *Metadata) AddToInterfaceMap(m map[string]interface{}) map[string]interface{} {
m["nomad_pack"] = map[string]interface{}{
"app": map[string]interface{}{
"url": md.App.URL,
"author": md.App.Author,
"url": md.App.URL,
},
"pack": map[string]interface{}{
"name": md.Pack.Name,
Expand Down
32 changes: 24 additions & 8 deletions sdk/pack/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ func TestMetadata_ConvertToMapInterface(t *testing.T) {
{
inputMetadata: &Metadata{
App: &MetadataApp{
URL: "https://example.com",
Author: "Timothy J. Berners-Lee",
URL: "https://example.com",
},
Pack: &MetadataPack{
Name: "Example",
Expand All @@ -31,8 +30,7 @@ func TestMetadata_ConvertToMapInterface(t *testing.T) {
expectedOutput: map[string]interface{}{
"nomad_pack": map[string]interface{}{
"app": map[string]interface{}{
"url": "https://example.com",
"author": "Timothy J. Berners-Lee",
"url": "https://example.com",
},
"pack": map[string]interface{}{
"name": "Example",
Expand All @@ -58,8 +56,7 @@ func TestMetadata_ConvertToMapInterface(t *testing.T) {
expectedOutput: map[string]interface{}{
"nomad_pack": map[string]interface{}{
"app": map[string]interface{}{
"url": "https://example.com",
"author": "",
"url": "https://example.com",
},
"pack": map[string]interface{}{
"name": "Example",
Expand All @@ -71,6 +68,26 @@ func TestMetadata_ConvertToMapInterface(t *testing.T) {
},
name: "some metadata values populated",
},
{
inputMetadata: &Metadata{
App: &MetadataApp{
URL: "https://example.com",
Author: "The Nomad Team",
},
Pack: &MetadataPack{},
},
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": ""},
},
},
// 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",
},
}

for _, tc := range testCases {
Expand All @@ -88,8 +105,7 @@ func TestMetadata_Validate(t *testing.T) {
{
inputMetadata: &Metadata{
App: &MetadataApp{
URL: "https://example.com",
Author: "Timothy J. Berners-Lee",
URL: "https://example.com",
},
Pack: &MetadataPack{
Name: "Example",
Expand Down