欢迎关注我的公众号:

目前刚开始写一个月,一共写了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完全手册
加qq群,请联系:

————————————————
type ExplainOptions struct {//explain结构体
genericclioptions.IOStreams
CmdParent string
APIVersion string
Recursive bool
Mapper meta.RESTMapper
Schema openapi.Resources
}
func NewExplainOptions(parent string, streams genericclioptions.IOStreams) *ExplainOptions {
return &ExplainOptions{//初始化explain结构体
IOStreams: streams,
CmdParent: parent,
}
}
//创建explain命令
func NewCmdExplain(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
o := NewExplainOptions(parent, streams)//初始化结构体
cmd := &cobra.Command{//创建cobra命令
Use: "explain RESOURCE",
DisableFlagsInUseLine: true,
Short: i18n.T("Documentation of resources"),
Long: explainLong + "\n\n" + cmdutil.SuggestAPIResources(parent),
Example: explainExamples,
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(o.Complete(f, cmd))//准备
cmdutil.CheckErr(o.Validate(args))//校验
cmdutil.CheckErr(o.Run(args))//运行
},
}
cmd.Flags().BoolVar(&o.Recursive, "recursive", o.Recursive, "Print the fields of fields (Currently only 1 level deep)")//recursive选项
cmd.Flags().StringVar(&o.APIVersion, "api-version", o.APIVersion, "Get different explanations for particular API version")//api-version选项
return cmd
}
//准备方法
func (o *ExplainOptions) Complete(f cmdutil.Factory, cmd *cobra.Command) error {
var err error
o.Mapper, err = f.ToRESTMapper()//设置mapper
if err != nil {
return err
}
o.Schema, err = f.OpenAPISchema()//设置schema
if err != nil {
return err
}
return nil
}
//校验
func (o *ExplainOptions) Validate(args []string) error {
if len(args) == 0 {//参数不能为空
return fmt.Errorf("You must specify the type of resource to explain. %s\n", cmdutil.SuggestAPIResources(o.CmdParent))
}
if len(args) > 1 {//参数不能大于一个
return fmt.Errorf("We accept only this format: explain RESOURCE\n")
}
return nil
}
//运行
func (o *ExplainOptions) Run(args []string) error {
recursive := o.Recursive
apiVersionString := o.APIVersion
// TODO: After we figured out the new syntax to separate group and resource, allow
// the users to use it in explain (kubectl explain <group><syntax><resource>).
// Refer to issue #16039 for why we do this. Refer to PR #15808 that used "/" syntax.
inModel, fieldsPath, err := explain.SplitAndParseResourceRequest(args[0], o.Mapper)//用.分割resource和字段
if err != nil {
return err
}
// TODO: We should deduce the group for a resource by discovering the supported resources at server.
fullySpecifiedGVR, groupResource := schema.ParseResourceArg(inModel)//解析groupversionresource
gvk := schema.GroupVersionKind{}
if fullySpecifiedGVR != nil {
gvk, _ = o.Mapper.KindFor(*fullySpecifiedGVR)//从gvr获取gvk
}
if gvk.Empty() {//如果gvk为空,则获取版本为空的gvk
gvk, err = o.Mapper.KindFor(groupResource.WithVersion(""))
if err != nil {
return err
}
}
if len(apiVersionString) != 0 {//如果api-version不为空,则再次获取gvk
apiVersion, err := schema.ParseGroupVersion(apiVersionString)
if err != nil {
return err
}
gvk = apiVersion.WithKind(gvk.Kind)
}
schema := o.Schema.LookupResource(gvk)//获取schema
if schema == nil {
return fmt.Errorf("Couldn't find resource for %q", gvk)
}
return explain.PrintModelDescription(fieldsPath, o.Out, schema, gvk, recursive)//打印结果
}
370



被折叠的 条评论
为什么被折叠?



