Skip to content

Commit 28cecad

Browse files
authored
Merge pull request #702 from darkowlzz/warn-manifest-missing
cmd/test: do not append empty manifests
2 parents ed28ca8 + cb27183 commit 28cecad

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

commands/operator-sdk/cmd/test/local.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,24 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
7878
saFile := filepath.Join(scaffold.DeployDir, scaffold.ServiceAccountYamlFile)
7979
sa, err := ioutil.ReadFile(saFile)
8080
if err != nil {
81-
log.Fatalf("could not find the manifest %s: %v", saFile, err)
81+
log.Printf("WARN: could not find the manifest %s: %v", saFile, err)
8282
}
8383
role, err := ioutil.ReadFile(filepath.Join(scaffold.DeployDir, scaffold.RoleYamlFile))
8484
if err != nil {
85-
log.Fatalf("could not find role manifest: %v", err)
85+
log.Printf("WARN: could not find role manifest: %v", err)
8686
}
8787
roleBinding, err := ioutil.ReadFile(filepath.Join(scaffold.DeployDir, scaffold.RoleBindingYamlFile))
8888
if err != nil {
89-
log.Fatalf("could not find role_binding manifest: %v", err)
89+
log.Printf("WARN: could not find role_binding manifest: %v", err)
9090
}
9191
operator, err := ioutil.ReadFile(filepath.Join(scaffold.DeployDir, scaffold.OperatorYamlFile))
9292
if err != nil {
9393
log.Fatalf("could not find operator manifest: %v", err)
9494
}
95-
combined := append(sa, []byte("\n---\n")...)
96-
combined = append(combined, role...)
97-
combined = append(combined, []byte("\n---\n")...)
98-
combined = append(combined, roleBinding...)
99-
combined = append(combined, []byte("\n---\n")...)
95+
combined := []byte{}
96+
combined = combineManifests(combined, sa)
97+
combined = combineManifests(combined, role)
98+
combined = combineManifests(combined, roleBinding)
10099
combined = append(combined, operator...)
101100
err = ioutil.WriteFile(tlConfig.namespacedManPath, combined, os.FileMode(fileutil.DefaultFileMode))
102101
if err != nil {
@@ -168,3 +167,13 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
168167
log.Fatalf("failed to exec `go %s`: %v", strings.Join(testArgs, " "), err)
169168
}
170169
}
170+
171+
// combineManifests combines a given manifest with a base manifest and adds yaml
172+
// style separation. Nothing is appended if the manifest is empty.
173+
func combineManifests(base, manifest []byte) []byte {
174+
if len(manifest) > 0 {
175+
base = append(base, manifest...)
176+
return append(base, []byte("\n---\n")...)
177+
}
178+
return base
179+
}

0 commit comments

Comments
 (0)