Skip to content

Commit 252694a

Browse files
authored
Merge pull request #1551 from GoogleCloudPlatform/release-candidate
Release v1.20.0
2 parents d6a3ef4 + 6227b7c commit 252694a

File tree

201 files changed

+4405
-1959
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+4405
-1959
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ MIN_GOLANG_VERSION=1.18 # for building ghpc
1010
terraform-format packer-format \
1111
check-tflint check-pre-commit
1212

13+
SHELL=/bin/bash -o pipefail
1314
ENG = ./cmd/... ./pkg/...
1415
TERRAFORM_FOLDERS=$(shell find ./modules ./community/modules ./tools -type f -name "*.tf" -not -path '*/\.*' -exec dirname "{}" \; | sort -u)
1516
PACKER_FOLDERS=$(shell find ./modules ./community/modules ./tools -type f -name "*.pkr.hcl" -not -path '*/\.*' -exec dirname "{}" \; | sort -u)

cmd/create.go

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"hpc-toolkit/pkg/config"
2424
"hpc-toolkit/pkg/modulewriter"
2525
"log"
26-
"os"
26+
"path/filepath"
2727
"strings"
2828

2929
"github.com/spf13/cobra"
@@ -77,19 +77,27 @@ var (
7777

7878
func runCreateCmd(cmd *cobra.Command, args []string) {
7979
dc := expandOrDie(args[0])
80-
if err := modulewriter.WriteDeployment(dc, outputDir, overwriteDeployment); err != nil {
81-
var target *modulewriter.OverwriteDeniedError
82-
if errors.As(err, &target) {
83-
fmt.Printf("\n%s\n", err.Error())
84-
os.Exit(1)
85-
} else {
86-
log.Fatal(err)
87-
}
88-
}
80+
deplName, err := dc.Config.DeploymentName()
81+
cobra.CheckErr(err)
82+
deplDir := filepath.Join(outputDir, deplName)
83+
cobra.CheckErr(modulewriter.WriteDeployment(dc, deplDir, overwriteDeployment))
84+
85+
fmt.Println("To deploy your infrastructure please run:")
86+
fmt.Println()
87+
fmt.Printf("./ghpc deploy %s\n", deplDir)
88+
fmt.Println()
89+
printAdvancedInstructionsMessage(deplDir)
90+
}
91+
92+
func printAdvancedInstructionsMessage(deplDir string) {
93+
fmt.Println("Find instructions for cleanly destroying infrastructure and advanced manual")
94+
fmt.Println("deployment instructions at:")
95+
fmt.Println()
96+
fmt.Printf("%s\n", modulewriter.InstructionsPath(deplDir))
8997
}
9098

9199
func expandOrDie(path string) config.DeploymentConfig {
92-
dc, err := config.NewDeploymentConfig(path)
100+
dc, ctx, err := config.NewDeploymentConfig(path)
93101
if err != nil {
94102
log.Fatal(err)
95103
}
@@ -113,12 +121,30 @@ func expandOrDie(path string) config.DeploymentConfig {
113121

114122
// Expand the blueprint
115123
if err := dc.ExpandConfig(); err != nil {
116-
log.Fatal(err)
124+
log.Fatal(renderError(err, ctx))
117125
}
118126

119127
return dc
120128
}
121129

130+
func renderError(err error, ctx config.YamlCtx) string {
131+
var be config.BpError
132+
if errors.As(err, &be) {
133+
if pos, ok := ctx.Pos(be.Path); ok {
134+
return renderRichError(be.Err, pos, ctx)
135+
}
136+
}
137+
return err.Error()
138+
}
139+
140+
func renderRichError(err error, pos config.Pos, ctx config.YamlCtx) string {
141+
return fmt.Sprintf(`
142+
Error: %s
143+
on line %d, column %d:
144+
%d: %s
145+
`, err, pos.Line, pos.Column, pos.Line, ctx.Lines[pos.Line-1])
146+
}
147+
122148
func setCLIVariables(bp *config.Blueprint, s []string) error {
123149
for _, cliVar := range s {
124150
arr := strings.SplitN(cliVar, "=", 2)

cmd/create_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package cmd
1616

1717
import (
18+
"errors"
1819
"hpc-toolkit/pkg/config"
1920

2021
"github.com/zclconf/go-cty/cty"
@@ -128,3 +129,31 @@ func (s *MySuite) TestValidationLevels(c *C) {
128129

129130
c.Check(setValidationLevel(&bp, "INVALID"), NotNil)
130131
}
132+
133+
func (s *MySuite) TestRenderError(c *C) {
134+
{ // simple
135+
err := errors.New("arbuz")
136+
got := renderError(err, config.YamlCtx{})
137+
c.Check(got, Equals, "arbuz")
138+
}
139+
{ // has pos, but context is missing
140+
ctx := config.NewYamlCtx([]byte(``))
141+
pth := config.Root.Vars.Dot("kale")
142+
err := config.BpError{Path: pth, Err: errors.New("arbuz")}
143+
got := renderError(err, ctx)
144+
c.Check(got, Equals, "vars.kale: arbuz")
145+
}
146+
{ // has pos, has context
147+
ctx := config.NewYamlCtx([]byte(`
148+
vars:
149+
kale: dos`))
150+
pth := config.Root.Vars.Dot("kale")
151+
err := config.BpError{Path: pth, Err: errors.New("arbuz")}
152+
got := renderError(err, ctx)
153+
c.Check(got, Equals, `
154+
Error: arbuz
155+
on line 3, column 9:
156+
3: kale: dos
157+
`)
158+
}
159+
}

cmd/deploy.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package cmd
1818
import (
1919
"fmt"
2020
"hpc-toolkit/pkg/config"
21+
"hpc-toolkit/pkg/modulewriter"
2122
"hpc-toolkit/pkg/shell"
2223
"log"
2324
"path/filepath"
@@ -48,7 +49,7 @@ var (
4849
Args: cobra.MatchAll(cobra.ExactArgs(1), checkDir),
4950
ValidArgsFunction: matchDirs,
5051
PreRunE: parseDeployArgs,
51-
RunE: runDeployCmd,
52+
Run: runDeployCmd,
5253
SilenceUsage: true,
5354
}
5455
)
@@ -72,40 +73,33 @@ func getApplyBehavior(autoApprove bool) shell.ApplyBehavior {
7273
return shell.PromptBeforeApply
7374
}
7475

75-
func runDeployCmd(cmd *cobra.Command, args []string) error {
76+
func runDeployCmd(cmd *cobra.Command, args []string) {
7677
expandedBlueprintFile := filepath.Join(artifactsDir, expandedBlueprintFilename)
77-
dc, err := config.NewDeploymentConfig(expandedBlueprintFile)
78-
if err != nil {
79-
return err
80-
}
81-
82-
if err := shell.ValidateDeploymentDirectory(dc.Config.DeploymentGroups, deploymentRoot); err != nil {
83-
return err
84-
}
78+
dc, _, err := config.NewDeploymentConfig(expandedBlueprintFile)
79+
cobra.CheckErr(err)
80+
cobra.CheckErr(shell.ValidateDeploymentDirectory(dc.Config.DeploymentGroups, deploymentRoot))
8581

8682
for _, group := range dc.Config.DeploymentGroups {
8783
groupDir := filepath.Join(deploymentRoot, string(group.Name))
88-
if err = shell.ImportInputs(groupDir, artifactsDir, expandedBlueprintFile); err != nil {
89-
return err
90-
}
84+
cobra.CheckErr(shell.ImportInputs(groupDir, artifactsDir, expandedBlueprintFile))
9185

9286
var err error
9387
switch group.Kind {
9488
case config.PackerKind:
9589
// Packer groups are enforced to have length 1
96-
moduleDir := filepath.Join(groupDir, string(group.Modules[0].ID))
90+
subPath, e := modulewriter.DeploymentSource(group.Modules[0])
91+
cobra.CheckErr(e)
92+
moduleDir := filepath.Join(groupDir, subPath)
9793
err = deployPackerGroup(moduleDir)
9894
case config.TerraformKind:
9995
err = deployTerraformGroup(groupDir)
10096
default:
10197
err = fmt.Errorf("group %s is an unsupported kind %s", groupDir, group.Kind.String())
10298
}
103-
if err != nil {
104-
return err
105-
}
106-
99+
cobra.CheckErr(err)
107100
}
108-
return nil
101+
fmt.Println("\n###############################")
102+
printAdvancedInstructionsMessage(deploymentRoot)
109103
}
110104

111105
func deployPackerGroup(moduleDir string) error {

cmd/destroy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func parseDestroyArgs(cmd *cobra.Command, args []string) error {
6464

6565
func runDestroyCmd(cmd *cobra.Command, args []string) error {
6666
expandedBlueprintFile := filepath.Join(artifactsDir, expandedBlueprintFilename)
67-
dc, err := config.NewDeploymentConfig(expandedBlueprintFile)
67+
dc, _, err := config.NewDeploymentConfig(expandedBlueprintFile)
6868
if err != nil {
6969
return err
7070
}

cmd/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func runExportCmd(cmd *cobra.Command, args []string) error {
8787
}
8888

8989
expandedBlueprintFile := filepath.Join(artifactsDir, expandedBlueprintFilename)
90-
dc, err := config.NewDeploymentConfig(expandedBlueprintFile)
90+
dc, _, err := config.NewDeploymentConfig(expandedBlueprintFile)
9191
if err != nil {
9292
return err
9393
}

cmd/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func runImportCmd(cmd *cobra.Command, args []string) error {
5151
}
5252

5353
expandedBlueprintFile := filepath.Join(artifactsDir, expandedBlueprintFilename)
54-
dc, err := config.NewDeploymentConfig(expandedBlueprintFile)
54+
dc, _, err := config.NewDeploymentConfig(expandedBlueprintFile)
5555
if err != nil {
5656
return err
5757
}

cmd/root.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ HPC deployments on the Google Cloud Platform.`,
5050
log.Fatalf("cmd.Help function failed: %s", err)
5151
}
5252
},
53-
Version: "v1.19.1",
53+
Version: "v1.20.0",
5454
Annotations: annotation,
5555
}
5656
)
5757

5858
// Execute the root command
5959
func Execute() error {
60+
// Don't prefix messages with data & time to improve readability.
61+
// See https://pkg.go.dev/log#pkg-constants
62+
log.SetFlags(0)
6063

6164
mismatch, branch, hash, dir := checkGitHashMismatch()
6265
if mismatch {
@@ -125,6 +128,9 @@ func hpcToolkitRepo() (repo *git.Repository, dir string, err error) {
125128
// found. If it's the hpc-toolkit repo, return it.
126129
// repo := new(git.Repository)
127130
dir, err = os.Getwd()
131+
if err != nil {
132+
return nil, "", err
133+
}
128134
subdir := filepath.Dir(dir)
129135
o := git.PlainOpenOptions{DetectDotGit: true}
130136
repo, err = git.PlainOpenWithOptions(dir, &o)
@@ -168,8 +174,5 @@ func hpcToolkitRepo() (repo *git.Repository, dir string, err error) {
168174
func isHpcToolkitRepo(r git.Repository) bool {
169175
h := plumbing.NewHash(GitInitialHash)
170176
_, err := r.CommitObject(h)
171-
if err == nil {
172-
return true
173-
}
174-
return false
177+
return err == nil
175178
}

cmd/root_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func checkPathsEqual(c *C, a, b string) {
199199
if err != nil {
200200
c.Fatal(err)
201201
}
202-
b, err = filepath.EvalSymlinks(a)
202+
b, err = filepath.EvalSymlinks(b)
203203
if err != nil {
204204
c.Fatal(err)
205205
}
@@ -241,6 +241,9 @@ func initTestRepo(path string) (repo *git.Repository, initHash plumbing.Hash, er
241241
}
242242

243243
initHash, err = commit("Init")
244+
if err != nil {
245+
return
246+
}
244247
_, err = commit("Last")
245248
return
246249
}

community/examples/hpc-slurm-chromedesktop.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ deployment_groups:
5454
disable_public_ips: false
5555
instance_image:
5656
family: slurm-gcp-5-7-debian-11
57-
project: projects/schedmd-slurm-public/global/images/family
57+
project: schedmd-slurm-public
5858
guest_accelerator:
5959
- type: nvidia-tesla-t4-vws
6060
count: 1

0 commit comments

Comments
 (0)