Created
March 1, 2019 20:56
-
-
Save jjo/3f88cb6a6a6a1f893969cc4e56bb9572 to your computer and use it in GitHub Desktop.
https://github.com/bitnami-labs/kubewatch/pull/165 feedback for cmd/resource.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jjo thanks, it was really helpful. 👍