Skip to content

Instantly share code, notes, and snippets.

@jjo
Created March 1, 2019 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjo/3f88cb6a6a6a1f893969cc4e56bb9572 to your computer and use it in GitHub Desktop.
Save jjo/3f88cb6a6a6a1f893969cc4e56bb9572 to your computer and use it in GitHub Desktop.
var resourceConfigAddCmd = &cobra.Command{
Use: "add",
Short: "adds specific resources to be watched",
Long: `adds specific resources to be watched`,
Run: func(cmd *cobra.Command, args []string) {
conf, err := config.New()
if err != nil {
logrus.Fatal(err)
}
flags := []struct {
flagStr string
flagVal *bool
}{
{
"svc",
&conf.Resource.Services,
},
{
"deploy",
&conf.Resource.Deployment,
},
{
"po",
&conf.Resource.Pod,
},
{
"rs",
&conf.Resource.ReplicaSet,
},
{
"rc",
&conf.Resource.ReplicationController,
},
{
"ns",
&conf.Resource.Namespace,
},
{
"jobs",
&conf.Resource.Job,
},
{
"pv",
&conf.Resource.PersistentVolume,
},
{
"ds",
&conf.Resource.DaemonSet,
},
{
"secret",
&conf.Resource.Secret,
},
{
"cm",
&conf.Resource.ConfigMap,
},
{
"ing",
&conf.Resource.Ingress,
},
}
var b bool
for _, flag := range flags {
b, err = cmd.Flags().GetBool(flag.flagStr)
if err == nil {
if b == true {
*flag.flagVal = b
logrus.Infof("resource %s configured", flag.flagStr)
}
} else {
logrus.Fatal(flag.flagStr, err)
}
}
if err = conf.Write(); err != nil {
logrus.Fatal(err)
}
},
}
@codenio
Copy link

codenio commented Mar 2, 2019

@jjo thanks, it was really helpful. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment