Skip to content

Commit 7d2675c

Browse files
sidsethkeyki
authored andcommitted
CB-7443. Populate the initial set roles (in grains) with additional prewarmed
roles which may be set up in prewarmed images.
1 parent e22f3e0 commit 7d2675c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BINARY=salt-bootstrap
22

3-
VERSION=0.13.2
3+
VERSION=0.13.3
44
BUILD_TIME=$(shell date +%FT%T)
55
LDFLAGS=-ldflags "-X github.com/hortonworks/salt-bootstrap/saltboot.Version=${VERSION} -X github.com/hortonworks/salt-bootstrap/saltboot.BuildTime=${BUILD_TIME}"
66
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./.git/*")

saltboot/salt.go

+30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package saltboot
22

33
import (
4+
"bufio"
45
"encoding/json"
56
"errors"
67
"fmt"
@@ -193,7 +194,26 @@ func SaltMinionRunRequestHandler(w http.ResponseWriter, req *http.Request) {
193194
}
194195

195196
grainConfigPath := baseDir + "/etc/salt/grains"
197+
prewarmedRolesPath := baseDir + "/etc/salt/prewarmed_roles"
196198
if isGrainsConfigNeeded(grainConfigPath) {
199+
// Check if prewarmed roles exist, and add them to the roles before generating the file
200+
if shouldAppendPrewarmedRoles(prewarmedRolesPath) {
201+
file, err := os.Open(prewarmedRolesPath)
202+
if err != nil {
203+
resp = model.Response{ErrorText: err.Error(), StatusCode: http.StatusInternalServerError}
204+
resp.WriteHttp(w)
205+
return
206+
}
207+
defer file.Close()
208+
scanner := bufio.NewScanner(file)
209+
for scanner.Scan() {
210+
s := strings.TrimSpace(scanner.Text())
211+
if len(s) > 0 {
212+
saltMinion.Roles = append(saltMinion.Roles, s)
213+
}
214+
}
215+
}
216+
197217
grainConfig := GrainConfig{Roles: saltMinion.Roles, HostGroup: saltMinion.HostGroup}
198218
grainYaml, err := yaml.Marshal(grainConfig)
199219
if err != nil {
@@ -476,6 +496,16 @@ func isGrainsConfigNeeded(grainConfigLocation string) bool {
476496
return true
477497
}
478498

499+
func shouldAppendPrewarmedRoles(prewarmRoleLocation string) bool {
500+
// Essentially a file exists check.
501+
log.Println("[shouldAppendPrewarmedRoles] check whether prewarm roles exist, file location: " + prewarmRoleLocation)
502+
_, err := os.Stat(prewarmRoleLocation)
503+
if os.IsNotExist(err) {
504+
return false
505+
}
506+
return true
507+
}
508+
479509
func isSaltMinionRestartNeeded(servers []string) bool {
480510
log.Println("[isSaltMinionRestartNeeded] check whether salt-minion requires restart")
481511
masterConfFile := "/etc/salt/minion.d/master.conf"

0 commit comments

Comments
 (0)