Skip to content

Commit 9e11c8e

Browse files
authored
fix(driver): enable metadata when required by base image (#44)
- fix(driver): enable metadata when required by base image - chore(lib): update upcloud-go-api to v5.1.0 - chore(lib): drop deprecated io/ioutil package
1 parent b2a539a commit 9e11c8e

31 files changed

+274
-359
lines changed

.github/workflows/docs.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@ name: Documentation
33
on:
44
pull_request:
55
types:
6-
- closed
6+
- closed
77
branches:
8-
- main
9-
- test-docs-generator # for testing
8+
- main
9+
- test-docs-generator # for testing
1010

1111
jobs:
1212
update:
1313
name: Update
1414
if: github.event.pull_request.merged == true
1515
runs-on: ubuntu-latest
1616
steps:
17-
- name: Setup Go
18-
uses: actions/setup-go@v2
19-
with:
20-
go-version: "1.17"
21-
- name: Checkout
22-
uses: actions/checkout@v2
23-
- name: Generate documentation
24-
run: make generate
25-
- name: Create PR for docs update
26-
uses: peter-evans/create-pull-request@v4
27-
with:
28-
add-paths: docs/
29-
branch: chore/update-docs
30-
commit-message: "chore(docs): update documentation for #${{ github.event.number }}"
31-
committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
32-
reviewers: ${{ github.actor }}
33-
title: Update documentation
34-
body: "This is an automatically created PR. Changes were created by running `make docs` after merging #${{ github.event.number }} (${{ github.sha }})."
35-
base: ${{ github.event.pull_request.base.ref }}
17+
- name: Setup Go
18+
uses: actions/setup-go@v3
19+
with:
20+
go-version: "1.18"
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
- name: Generate documentation
24+
run: make generate
25+
- name: Create PR for docs update
26+
uses: peter-evans/create-pull-request@v4
27+
with:
28+
add-paths: docs/
29+
branch: chore/update-docs
30+
commit-message: "chore(docs): update documentation for #${{ github.event.number }}"
31+
committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
32+
reviewers: ${{ github.actor }}
33+
title: Update documentation
34+
body: "This is an automatically created PR. Changes were created by running `make docs` after merging #${{ github.event.number }} (${{ github.sha }})."
35+
base: ${{ github.event.pull_request.base.ref }}

.github/workflows/lint.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Lint
2+
on:
3+
pull_request:
4+
jobs:
5+
golangci-lint:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/setup-go@v3
9+
with:
10+
go-version: 1.18
11+
- uses: actions/checkout@v3
12+
- uses: golangci/golangci-lint-action@v3
13+
with:
14+
version: latest
15+
args: --timeout 10m

.github/workflows/release.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ name: release
22
on:
33
push:
44
tags:
5-
- 'v*'
5+
- "v*"
66
jobs:
77
goreleaser:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout
11-
uses: actions/checkout@v2
11+
uses: actions/checkout@v3
1212

1313
- name: Unshallow
1414
run: git fetch --prune --unshallow
1515

1616
- name: Set up Go
17-
uses: actions/setup-go@v2
17+
uses: actions/setup-go@v3
1818
with:
19-
go-version: 1.17
19+
go-version: 1.18
2020

2121
- name: Describe plugin
2222
id: plugin_describe

.github/workflows/test.yaml

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,37 @@ on: [push]
44

55
jobs:
66
test:
7-
87
strategy:
98
matrix:
10-
go-version: [1.17.x]
9+
go-version: [1.18.x]
1110
os: [ubuntu-latest, macos-latest, windows-latest]
1211

1312
runs-on: ${{ matrix.os }}
1413

1514
steps:
16-
- uses: actions/checkout@v2
17-
18-
- name: Setup
19-
uses: actions/setup-go@v2
20-
with:
21-
go-version: ${{ matrix.go-version }}
22-
23-
- name: Dependencies
24-
run: |
25-
go version
26-
go get -u golang.org/x/lint/golint
27-
28-
- name: Build
29-
run: make build
30-
31-
- name: Code Style
32-
run: make lint
33-
34-
- name: Test PR
35-
if: github.ref != 'refs/heads/main'
36-
run: make test
37-
38-
- name: Test main
39-
if: github.ref == 'refs/heads/main'
40-
env:
15+
- uses: actions/checkout@v3
16+
17+
- name: Setup
18+
uses: actions/setup-go@v3
19+
with:
20+
go-version: ${{ matrix.go-version }}
21+
22+
- name: Dependencies
23+
run: |
24+
go version
25+
go get -u golang.org/x/lint/golint
26+
27+
- name: Build
28+
run: make build
29+
30+
- name: Test PR
31+
if: github.ref != 'refs/heads/main'
32+
run: make test
33+
34+
- name: Test main
35+
if: github.ref == 'refs/heads/main'
36+
env:
4137
UPCLOUD_API_USER: ${{ secrets.UPCLOUD_API_USER }}
4238
UPCLOUD_API_PASSWORD: ${{ secrets.UPCLOUD_API_PASSWORD }}
4339
PACKER_ACC: 1
44-
run: make test_integration
40+
run: make test_integration

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ vendor
66
docs.zip
77
crash.log
88
*hcl.txt
9+
tmp
910
/go.work
1011
/go.work.sum

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)
55

66
## [Unreleased]
77

8+
### Fixed
9+
- enable server metadata automatically when required by base image
10+
811
### Changed
912
- update `packer-plugin-sdk` to [v0.3.0](https://github.com/hashicorp/packer-plugin-sdk/blob/main/CHANGELOG.md#030-june-09-2022)
13+
- update upcloud-go-api to v5.1.0
1014

1115
## [1.5.1] - 2022-06-10
1216

builder/upcloud/artifact.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77

88
"github.com/UpCloudLtd/packer-plugin-upcloud/internal/driver"
9-
"github.com/UpCloudLtd/upcloud-go-api/v4/upcloud"
9+
"github.com/UpCloudLtd/upcloud-go-api/v5/upcloud"
1010
"github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
1111
)
1212

@@ -54,8 +54,10 @@ func (a *Artifact) State(name string) interface{} {
5454
}
5555

5656
func (a *Artifact) Destroy() error {
57+
ctx, cancel := contextWithDefaultTimeout()
58+
defer cancel()
5759
for _, t := range a.Templates {
58-
err := a.driver.DeleteTemplate(t.UUID)
60+
err := a.driver.DeleteTemplate(ctx, t.UUID)
5961
if err != nil {
6062
return err
6163
}

builder/upcloud/artifact_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"testing"
66

7-
"github.com/UpCloudLtd/upcloud-go-api/v4/upcloud"
7+
"github.com/UpCloudLtd/upcloud-go-api/v5/upcloud"
88
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
99
"github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
1010
"github.com/stretchr/testify/assert"

builder/upcloud/builder.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package upcloud
33
import (
44
"context"
55
"fmt"
6+
"time"
67

78
"github.com/UpCloudLtd/packer-plugin-upcloud/internal/driver"
8-
"github.com/UpCloudLtd/upcloud-go-api/v4/upcloud"
9+
"github.com/UpCloudLtd/upcloud-go-api/v5/upcloud"
910
"github.com/hashicorp/hcl/v2/hcldec"
1011
"github.com/hashicorp/packer-plugin-sdk/communicator"
1112
"github.com/hashicorp/packer-plugin-sdk/multistep"
@@ -14,7 +15,10 @@ import (
1415
"github.com/hashicorp/packer-plugin-sdk/packerbuilderdata"
1516
)
1617

17-
const BuilderId = "upcloud.builder"
18+
const (
19+
BuilderId = "upcloud.builder"
20+
defaultTimeout time.Duration = 1 * time.Hour
21+
)
1822

1923
type Builder struct {
2024
config Config
@@ -42,6 +46,8 @@ func (b *Builder) Prepare(raws ...interface{}) (generatedVars []string, warnings
4246
}
4347

4448
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
49+
// NOTE: context deadline is not set by default.
50+
4551
// Setup the state bag and initial state for the steps
4652
b.driver = driver.NewDriver(&driver.DriverConfig{
4753
Username: b.config.Username,

builder/upcloud/builder_acc_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
_ "embed"
55
"errors"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"os"
99
"os/exec"
1010
"regexp"
@@ -161,7 +161,7 @@ func readLog(logfile string) (string, error) {
161161
}
162162
defer logs.Close()
163163

164-
logsBytes, err := ioutil.ReadAll(logs)
164+
logsBytes, err := io.ReadAll(logs)
165165
if err != nil {
166166
return "", fmt.Errorf("Unable to read %s", logfile)
167167
}
@@ -214,9 +214,9 @@ func getUuidsFromLog(log string) ([]string, error) {
214214

215215
func teardown(testName string) func() error {
216216
logfile := fmt.Sprintf("packer_log_%s.txt", testName)
217-
218217
return func() error {
219-
218+
ctx, cancel := contextWithDefaultTimeout()
219+
defer cancel()
220220
log, err := readLog(logfile)
221221
if err != nil {
222222
return err
@@ -235,7 +235,7 @@ func teardown(testName string) func() error {
235235

236236
for _, u := range uuids {
237237
fmt.Printf("Cleaning up created templates: %s\n", u)
238-
if err := drv.DeleteTemplate(u); err != nil {
238+
if err := drv.DeleteTemplate(ctx, u); err != nil {
239239
return err
240240
}
241241
}

0 commit comments

Comments
 (0)