Skip to content

Commit

Permalink
Allow the nnf-mfu release to be specified. (#64)
Browse files Browse the repository at this point in the history
Allow the nnf-mfu release to be specified.

Allow a build environment to be specified for the repositories.

Add an environment variable to indicate which version of nnf-mfu should be
used.

Signed-off-by: Dean Roehrich <[email protected]>
  • Loading branch information
roehrich-hpe authored May 16, 2023
1 parent ce5c402 commit cfd0b67
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 31 deletions.
32 changes: 20 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021, 2022 Hewlett Packard Enterprise Development LP
* Copyright 2021-2023 Hewlett Packard Enterprise Development LP
* Other additional copyright holders may be indicated within.
*
* The entirety of this work is licensed under the Apache License,
Expand Down Expand Up @@ -171,43 +171,51 @@ func (system *System) Verify() error {
}

type RepositoryConfigFile struct {
Repositories []Repository `yaml:"repositories"`
Repositories []Repository `yaml:"repositories"`
BuildConfig BuildConfiguration `yaml:"buildConfiguration"`
}

type Repository struct {
Name string
Overlays []string `yaml:",flow"`
Development string
Master string
UseRemoteK bool `yaml:"useRemoteK,omitempty"`
Name string `yaml:"name"`
Overlays []string `yaml:"overlays,flow"`
Development string `yaml:"development"`
Master string `yaml:"master"`
UseRemoteK bool `yaml:"useRemoteK,omitempty"`
RemoteReference struct {
Build string `yaml:"build"`
Url string `yaml:"url"`
} `yaml:"remoteReference,omitempty"`
}

func FindRepository(module string) (*Repository, error) {
type BuildConfiguration struct {
Env []struct {
Name string `yaml:"name"`
Value string `yaml:"value"`
} `yaml:"env"`
}

func FindRepository(module string) (*Repository, *BuildConfiguration, error) {

configFile, err := os.ReadFile(DefaultRepoCfgPath)
if err != nil {
configFile, err = os.ReadFile(filepath.Join("..", DefaultRepoCfgPath))
if err != nil {
return nil, err
return nil, nil, err
}
}

config := new(RepositoryConfigFile)
if err := yaml.UnmarshalStrict(configFile, config); err != nil {
return nil, err
return nil, nil, err
}

for _, repository := range config.Repositories {
if module == repository.Name {
return &repository, nil
return &repository, &config.BuildConfig, nil
}
}

return nil, fmt.Errorf("Repository '%s' Not Found", module)
return nil, nil, fmt.Errorf("Repository '%s' Not Found", module)
}

type Daemon struct {
Expand Down
12 changes: 12 additions & 0 deletions config/repositories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,15 @@ repositories:
remoteReference:
build: v0.0.3
url: https://github.com/NearNodeFlash/lustre-fs-operator.git/config/default/?ref=%s

buildConfiguration:
# Environment variables to set when calling the any 'make' or 'deploy'
# command in a submodule.
env:
# The nnf-mfu container to use.
# Example values:
# - A specific release build: 0.0.1 (without the "v" prefix)
# - The most recent build from the master branch: master
- name: NNFMFU_VERSION
value: 0.0.1

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
)

require (
github.com/NearNodeFlash/nnf-ec v0.0.0-20230427164720-dc73727a986f // indirect
github.com/NearNodeFlash/nnf-ec v0.0.0-20230512221456-5fa47fb42560 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/NearNodeFlash/nnf-ec v0.0.0-20230427164720-dc73727a986f h1:kJetY6ACr44dAKEbJkXCwDdbnqqx4KKx63cjXPCHktQ=
github.com/NearNodeFlash/nnf-ec v0.0.0-20230427164720-dc73727a986f/go.mod h1:11Ol46sAWdqlj3WmIFTzKO+UxQX3lvWBqpe6yaiMEIg=
github.com/NearNodeFlash/nnf-ec v0.0.0-20230512221456-5fa47fb42560 h1:ewsW6a7EFrueIrjoMgS7oBCiaAU0Nc7wKwl5fW95NLg=
github.com/NearNodeFlash/nnf-ec v0.0.0-20230512221456-5fa47fb42560/go.mod h1:11Ol46sAWdqlj3WmIFTzKO+UxQX3lvWBqpe6yaiMEIg=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4=
Expand Down
45 changes: 31 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,18 @@ func runMakeCommand(ctx *Context, system *config.System, module string, command
return err
}

fmt.Print(" Finding Repository...")
repo, buildConfig, err := config.FindRepository(module)
if err != nil {
return err
}
fmt.Printf(" %s\n", repo.Name)
for idx := range buildConfig.Env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", buildConfig.Env[idx].Name, buildConfig.Env[idx].Value))
}

if len(overlay) != 0 {
cmd.Env = append(os.Environ(),
cmd.Env = append(cmd.Env,
"OVERLAY="+overlay,
)
}
Expand Down Expand Up @@ -267,7 +277,7 @@ func (cmd *InstallCmd) Run(ctx *Context) error {

if !cmd.NoBuild && d.Bin != "" {
cmd := exec.Command("go", "build", "-o", d.Bin)
cmd.Env = append(os.Environ(),
cmd.Env = append(cmd.Env,
"CGO_ENABLED=0",
"GOOS=linux",
"GOARCH=amd64",
Expand Down Expand Up @@ -468,7 +478,7 @@ func (cmd *InitCmd) Run(ctx *Context) error {

for _, module := range modulesAllowedRemote {
var applyK string
repo, err := config.FindRepository(module)
repo, _, err := config.FindRepository(module)
if err != nil {
return err
}
Expand Down Expand Up @@ -738,7 +748,7 @@ func addTag(tag string) error {

func getOverlay(system *config.System, module string) (string, error) {

repo, err := config.FindRepository(module)
repo, _, err := config.FindRepository(module)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -784,26 +794,29 @@ func deployModule(ctx *Context, system *config.System, module string) error {
return err
}

fmt.Print(" Finding Repository...")
repo, buildConfig, err := config.FindRepository(module)
if err != nil {
return err
}
fmt.Printf(" %s\n", repo.Name)
for idx := range buildConfig.Env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", buildConfig.Env[idx].Name, buildConfig.Env[idx].Value))
}

if system.Name == "kind" {
// TODO: Do a sanity check to make sure the image is present on the kind nodes. This ensures
// that a "kind-push" was done. This would _not_ guarantee that a docker-build was done with
// the latest code but at least we wouldn't get an ImagePullFailure. One can get the list of
// images present on a cluster node by using `docker exec -it [NODE NAME] crictl images`

if len(overlay) != 0 {
cmd.Env = append(os.Environ(),
cmd.Env = append(cmd.Env,
"OVERLAY="+overlay)
}

} else {

fmt.Print(" Finding Repository...")
repo, err := config.FindRepository(module)
if err != nil {
return err
}
fmt.Printf(" %s\n", repo.Name)

fmt.Printf(" Loading Current Branch...")
branch, err := currentBranch()
if err != nil {
Expand Down Expand Up @@ -833,7 +846,7 @@ func deployModule(ctx *Context, system *config.System, module string) error {
version := commit
imageTagBase := strings.TrimSuffix(strings.TrimPrefix(url, "https://"), "/") // According to Tony; docker assumes a secure repo and prepends https when it fetches the image; so we drop it here.

cmd.Env = append(os.Environ(),
cmd.Env = append(cmd.Env,
"IMAGE_TAG_BASE="+imageTagBase,
"VERSION="+version,
"OVERLAY="+overlay,
Expand All @@ -848,9 +861,13 @@ func deployModule(ctx *Context, system *config.System, module string) error {
func runCommand(ctx *Context, cmd *exec.Cmd) ([]byte, error) {
if ctx.DryRun {
fmt.Printf(" Dry-Run: Skipping command '%s'\n", cmd.String())
fmt.Printf(" Additional env: %v\n", cmd.Env)
return nil, nil
}

if len(cmd.Env) > 0 {
cmd.Env = append(cmd.Env, os.Environ()...)
}
stdoutStderr, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf("%s\n", stdoutStderr)
Expand Down Expand Up @@ -892,7 +909,7 @@ func shouldSkipModule(module string, permittedModulesOrEmpty []string) bool {
// Modules that are being installed via remote should be skipped.
for _, remoteModule := range modulesAllowedRemote {
if module == remoteModule {
repo, err := config.FindRepository(module)
repo, _, err := config.FindRepository(module)
if err != nil {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion nnf-dm
2 changes: 1 addition & 1 deletion nnf-sos
Submodule nnf-sos updated 198 files

0 comments on commit cfd0b67

Please sign in to comment.