公司简介模板素材进行优化
欢迎关注我的公众号:
目前刚开始写一个月,一共写了18篇原创文章,文章目录如下:
istio多集群探秘,部署了50次多集群后我得出的结论
istio多集群链路追踪,附实操视频
istio防故障利器,你知道几个,istio新手不要读,太难!
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 SetServiceAccountOptions struct {//set serviceaccount结构体PrintFlags *genericclioptions.PrintFlagsRecordFlags *genericclioptions.RecordFlagsfileNameOptions resource.FilenameOptionsdryRun boolshortOutput boolall booloutput stringlocal boolupdatePodSpecForObject polymorphichelpers.UpdatePodSpecForObjectFuncinfos []*resource.InfoserviceAccountName stringPrintObj printers.ResourcePrinterFuncRecorder genericclioptions.Recordergenericclioptions.IOStreams
}
func NewSetServiceAccountOptions(streams genericclioptions.IOStreams) *SetServiceAccountOptions {return &SetServiceAccountOptions{//初始化结构体PrintFlags: genericclioptions.NewPrintFlags("serviceaccount updated").WithTypeSetter(scheme.Scheme),RecordFlags: genericclioptions.NewRecordFlags(),Recorder: genericclioptions.NoopRecorder{},IOStreams: streams,}
}
//创建set serviceaccount命令
func NewCmdServiceAccount(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {o := NewSetServiceAccountOptions(streams)//初始化结构体cmd := &cobra.Command{//创建cobra命令Use: "serviceaccount (-f FILENAME | TYPE NAME) SERVICE_ACCOUNT",DisableFlagsInUseLine: true,Aliases: []string{"sa"},Short: i18n.T("Update ServiceAccount of a resource"),Long: serviceaccountLong,Example: serviceaccountExample,Run: func(cmd *cobra.Command, args []string) {cmdutil.CheckErr(o.Complete(f, cmd, args))//准备cmdutil.CheckErr(o.Run())//运行},}o.PrintFlags.AddFlags(cmd)//设置print选项o.RecordFlags.AddFlags(cmd)//设置record选项usage := "identifying the resource to get from a server."cmdutil.AddFilenameOptionFlags(cmd, &o.fileNameOptions, usage)//设置文件选项cmd.Flags().BoolVar(&o.all, "all", o.all, "Select all resources, including uninitialized ones, in the namespace of the specified resource types")//设置all选项cmd.Flags().BoolVar(&o.local, "local", o.local, "If true, set serviceaccount will NOT contact api-server but run locally.")//设置local选项cmdutil.AddDryRunFlag(cmd)//设置干跑选项cmdutil.AddIncludeUninitializedFlag(cmd)return cmd
}
//准备
func (o *SetServiceAccountOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {var err erroro.RecordFlags.Complete(cmd)//record completeo.Recorder, err = o.RecordFlags.ToRecorder()//recordflag转recorderif err != nil {return err}o.shortOutput = cmdutil.GetFlagString(cmd, "output") == "name"//判断output是否为nameo.dryRun = cmdutil.GetDryRunFlag(cmd)//设置干跑o.output = cmdutil.GetFlagString(cmd, "output")//设置outputo.updatePodSpecForObject = polymorphichelpers.UpdatePodSpecForObjectFn//设置updatePodSpecforObject函数if o.dryRun {o.PrintFlags.Complete("%s (dry run)")}printer, err := o.PrintFlags.ToPrinter()//printflag转printerif err != nil {return err}o.PrintObj = printer.PrintObj//设置printObj函数cmdNamespace, enforceNamespace, err := f.ToRawKubeConfigLoader().Namespace()//获取namespace和enforceNamespaceif err != nil {return err}if len(args) == 0 {//如果参数为空报错return errors.New("serviceaccount is required")}o.serviceAccountName = args[len(args)-1]resources := args[:len(args)-1]builder := f.NewBuilder().WithScheme(scheme.Scheme, scheme.Scheme.PrioritizedVersionsAllGroups()...).LocalParam(o.local).ContinueOnError().NamespaceParam(cmdNamespace).DefaultNamespace().FilenameParam(enforceNamespace, &o.fileNameOptions).Flatten()//构造info对象if !o.local {builder.ResourceTypeOrNameArgs(o.all, resources...).Latest()}o.infos, err = builder.Do().Infos()//设置info对象if err != nil {return err}return nil
}
func (o *SetServiceAccountOptions) Run() error {patchErrs := []error{}patchFn := func(obj runtime.Object) ([]byte, error) {//创建patch,修改海曙_, err := o.updatePodSpecForObject(obj, func(podSpec *v1.PodSpec) error {//更新pod specpodSpec.ServiceAccountName = o.serviceAccountName//更新serviceaccountNamereturn nil})if err != nil {return nil, err}// record this change (for rollout history)if err := o.Recorder.Record(obj); err != nil {//判断是否创建change-cause注解klog.V(4).Infof("error recording current command: %v", err)}return runtime.Encode(scheme.DefaultJSONEncoder(), obj)//对象转json}patches := CalculatePatches(o.infos, scheme.DefaultJSONEncoder(), patchFn)//计算patchfor _, patch := range patches {//遍历patchinfo := patch.Infoname := info.ObjectName()if patch.Err != nil {//patch有错误则继续patchErrs = append(patchErrs, fmt.Errorf("error: %s %v\n", name, patch.Err))continue}if o.local || o.dryRun {//local或干跑则打印对象,继续if err := o.PrintObj(info.Object, o.Out); err != nil {patchErrs = append(patchErrs, err)}continue}actual, err := resource.NewHelper(info.Client, info.Mapping).Patch(info.Namespace, info.Name, types.StrategicMergePatchType, patch.Patch, nil)//应用patch到服务端if err != nil {patchErrs = append(patchErrs, fmt.Errorf("failed to patch ServiceAccountName %v", err))continue}if err := o.PrintObj(actual, o.Out); err != nil {//打印结果patchErrs = append(patchErrs, err)}}return utilerrors.NewAggregate(patchErrs)
}