Skip to content

Commit

Permalink
CB-7443. Populate the initial set roles (in grains) with additional p…
Browse files Browse the repository at this point in the history
…rewarmed

roles which may be set up in prewarmed images.
  • Loading branch information
sidseth authored and keyki committed Aug 27, 2020
1 parent e22f3e0 commit 7d2675c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BINARY=salt-bootstrap

VERSION=0.13.2
VERSION=0.13.3
BUILD_TIME=$(shell date +%FT%T)
LDFLAGS=-ldflags "-X github.com/hortonworks/salt-bootstrap/saltboot.Version=${VERSION} -X github.com/hortonworks/salt-bootstrap/saltboot.BuildTime=${BUILD_TIME}"
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")
Expand Down
30 changes: 30 additions & 0 deletions saltboot/salt.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package saltboot

import (
"bufio"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -193,7 +194,26 @@ func SaltMinionRunRequestHandler(w http.ResponseWriter, req *http.Request) {
}

grainConfigPath := baseDir + "/etc/salt/grains"
prewarmedRolesPath := baseDir + "/etc/salt/prewarmed_roles"
if isGrainsConfigNeeded(grainConfigPath) {
// Check if prewarmed roles exist, and add them to the roles before generating the file
if shouldAppendPrewarmedRoles(prewarmedRolesPath) {
file, err := os.Open(prewarmedRolesPath)
if err != nil {
resp = model.Response{ErrorText: err.Error(), StatusCode: http.StatusInternalServerError}
resp.WriteHttp(w)
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
s := strings.TrimSpace(scanner.Text())
if len(s) > 0 {
saltMinion.Roles = append(saltMinion.Roles, s)
}
}
}

grainConfig := GrainConfig{Roles: saltMinion.Roles, HostGroup: saltMinion.HostGroup}
grainYaml, err := yaml.Marshal(grainConfig)
if err != nil {
Expand Down Expand Up @@ -476,6 +496,16 @@ func isGrainsConfigNeeded(grainConfigLocation string) bool {
return true
}

func shouldAppendPrewarmedRoles(prewarmRoleLocation string) bool {
// Essentially a file exists check.
log.Println("[shouldAppendPrewarmedRoles] check whether prewarm roles exist, file location: " + prewarmRoleLocation)
_, err := os.Stat(prewarmRoleLocation)
if os.IsNotExist(err) {
return false
}
return true
}

func isSaltMinionRestartNeeded(servers []string) bool {
log.Println("[isSaltMinionRestartNeeded] check whether salt-minion requires restart")
masterConfFile := "/etc/salt/minion.d/master.conf"
Expand Down

0 comments on commit 7d2675c

Please sign in to comment.