forked from flanksource/karina
/
apply.go
37 lines (32 loc) · 888 Bytes
/
apply.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package cmd
import (
"io/ioutil"
"github.com/flanksource/commons/text"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var Apply = &cobra.Command{
Use: "apply",
Short: "Apply a configuration to a resource by filename",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ns, _ := cmd.Flags().GetString("namespace")
p := getPlatform(cmd)
for _, spec := range args {
data, err := ioutil.ReadFile(spec)
if err != nil {
log.Fatalf("Could not read %s: %v", spec, err)
}
template, err := text.Template(string(data), p.PlatformConfig)
if err != nil {
log.Fatalf("failed to template %s: %v", spec, err)
}
if err := p.ApplyText(ns, template); err != nil {
log.Fatalf("failed to apply %s: %v", spec, err)
}
}
},
}
func init() {
Apply.Flags().StringP("namespace", "n", "", "The namespace to apply")
}