欢迎关注我的公众号:
目前刚开始写一个月,一共写了18篇原创文章,文章目录如下:
istio防故障利器,你知道几个,istio新手不要读,太难!
不懂envoyfilter也敢说精通istio系列-http-rbac-不要只会用AuthorizationPolicy配置权限
不懂envoyfilter也敢说精通istio系列-02-http-corsFilter-不要只会vs
不懂envoyfilter也敢说精通istio系列-03-http-csrf filter-再也不用再代码里写csrf逻辑了
不懂envoyfilter也敢说精通istio系列http-jwt_authn-不要只会RequestAuthorization
不懂envoyfilter也敢说精通istio系列-05-fault-filter-故障注入不止是vs
不懂envoyfilter也敢说精通istio系列-06-http-match-配置路由不只是vs
不懂envoyfilter也敢说精通istio系列-07-负载均衡配置不止是dr
不懂envoyfilter也敢说精通istio系列-08-连接池和断路器
不懂envoyfilter也敢说精通istio系列-09-http-route filter
不懂envoyfilter也敢说精通istio系列-network filter-redis proxy
不懂envoyfilter也敢说精通istio系列-network filter-HttpConnectionManager
不懂envoyfilter也敢说精通istio系列-ratelimit-istio ratelimit完全手册
————————————————
type setOptions struct {//set结构体
configAccess clientcmd.ConfigAccess
propertyName string
propertyValue string
setRawBytes cliflag.Tristate
}
//创建set命令
func NewCmdConfigSet(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command {
options := &setOptions{configAccess: configAccess}//初始化结构体
cmd := &cobra.Command{//创建cobra命令
Use: "set PROPERTY_NAME PROPERTY_VALUE",
DisableFlagsInUseLine: true,
Short: i18n.T("Sets an individual value in a kubeconfig file"),
Long: setLong,
Example: setExample,
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(options.complete(cmd))//准备
cmdutil.CheckErr(options.run())//运行
fmt.Fprintf(out, "Property %q set.\n", options.propertyName)//打印结果
},
}
f := cmd.Flags().VarPF(&options.setRawBytes, "set-raw-bytes", "", "When writing a []byte PROPERTY_VALUE, write the given string directly without base64 decoding.")//set-raw-bytes选项
f.NoOptDefVal = "true"
return cmd
}
func (o *setOptions) complete(cmd *cobra.Command) error {//准备
endingArgs := cmd.Flags().Args()//获取参数
if len(endingArgs) != 2 {//参数必须是2个
return helpErrorf(cmd, "Unexpected args: %v", endingArgs)
}
o.propertyValue = endingArgs[1]//设置propertyValue
o.propertyName = endingArgs[0]//设置propertyName
return nil
}
func (o setOptions) validate() error {//校验
if len(o.propertyValue) == 0 {//propertyValue不能为空
return errors.New("you cannot use set to unset a property")
}
if len(o.propertyName) == 0 {//propertyName不能为空
return errors.New("you must specify a property")
}
return nil
}
func (o setOptions) run() error {//运行
err := o.validate()//校验
if err != nil {
return err
}
config, err := o.configAccess.GetStartingConfig()//加载config
if err != nil {
return err
}
steps, err := newNavigationSteps(o.propertyName)//创建steps
if err != nil {
return err
}
setRawBytes := false
if o.setRawBytes.Provided() {//如果设置了set-raw-bytes,设置setRawBytes
setRawBytes = o.setRawBytes.Value()
}
err = modifyConfig(reflect.ValueOf(config), steps, o.propertyValue, false, setRawBytes)//修改配置
if err != nil {
return err
}
if err := clientcmd.ModifyConfig(o.configAccess, *config, false); err != nil {/保存配置到文件
return err
}
return nil
}