[ADD] image parameter to ke install npd
Signed-off-by: FingerLiu <liupeng.dalian@gmail.com>
This commit is contained in:
parent
86f495b414
commit
3b022cfd00
|
@ -22,11 +22,13 @@ import (
|
|||
"kubeeye/pkg/validator"
|
||||
)
|
||||
|
||||
var npdImage string
|
||||
|
||||
var addCmd = &cobra.Command{
|
||||
Use: "install npd",
|
||||
Short: "install the npd",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
err := validator.Add(cmd.Context())
|
||||
err := validator.Add(cmd.Context(), npdImage)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
@ -36,4 +38,5 @@ var addCmd = &cobra.Command{
|
|||
func init() {
|
||||
rootCmd.AddCommand(addCmd)
|
||||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
|
||||
addCmd.Flags().StringVarP(&npdImage, "image", "i", "k8s.gcr.io/node-problem-detector:v0.8.1", "Customize npd image")
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ spec:
|
|||
- --logtostderr
|
||||
- --apiserver-wait-timeout=10s
|
||||
- --config.system-log-monitor=/config/kernel-monitor.json,/config/docker-monitor.json
|
||||
image: k8s.gcr.io/node-problem-detector:v0.8.1
|
||||
image: {{.NpdImage}}
|
||||
resources:
|
||||
limits:
|
||||
cpu: 10m
|
||||
|
@ -71,4 +71,4 @@ spec:
|
|||
- key: kernel-monitor.json
|
||||
path: kernel-monitor.json
|
||||
- key: docker-monitor.json
|
||||
path: docker-monitor.json
|
||||
path: docker-monitor.json
|
||||
|
|
|
@ -29,13 +29,20 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/yaml"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/config"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
var configBox = (*packr.Box)(nil)
|
||||
|
||||
func Add(ctx context.Context) error {
|
||||
type ImageName struct {
|
||||
NpdImage string
|
||||
}
|
||||
|
||||
func Add(ctx context.Context, npdImage string) error {
|
||||
var rawBytes []byte
|
||||
|
||||
imageName := ImageName{ NpdImage: npdImage }
|
||||
|
||||
// configMap create
|
||||
rawBytes, err := getConfigBox().Find("npd-rule.yaml")
|
||||
if err != nil {
|
||||
|
@ -80,11 +87,24 @@ func Add(ctx context.Context) error {
|
|||
return errors.Wrap(err4, "Failed to create clusterRoleBinding")
|
||||
}
|
||||
// daemonSet create
|
||||
dsBytes, err := getConfigBox().Find("daemonSet.yaml")
|
||||
var tplWriter bytes.Buffer
|
||||
dsTmplString, err := getConfigBox().FindString("daemonSet.yaml")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to get daemonSet.yaml")
|
||||
}
|
||||
ds := dsParse(dsBytes)
|
||||
|
||||
dsTemplate, err := template.New("npd").Parse(dsTmplString)
|
||||
if dsTemplate == nil || err != nil{
|
||||
return errors.Wrap(err, "Failed to get daemonSet.yaml template")
|
||||
}
|
||||
err = dsTemplate.Execute(&tplWriter, imageName)
|
||||
if err != nil{
|
||||
return errors.Wrap(err, "Failed to render daemonSet.yaml template")
|
||||
}
|
||||
|
||||
tplWriter.Bytes()
|
||||
|
||||
ds := dsParse(tplWriter.Bytes())
|
||||
_, err5 := createDaemonSet(ctx, ds)
|
||||
if err5 != nil {
|
||||
return errors.Wrap(err5, "Failed to create daemonSet")
|
||||
|
|
Loading…
Reference in New Issue