helm v3源码分析之总体

发布一个k8s部署视频:https://edu.csdn.net/course/detail/26967

课程内容:各种k8s部署方式。包括minikube部署,kubeadm部署,kubeasz部署,rancher部署,k3s部署。包括开发测试环境部署k8s,和生产环境部署k8s。

腾讯课堂连接地址https://ke.qq.com/course/478827?taid=4373109931462251&tuin=ba64518

第二个视频发布  https://edu.csdn.net/course/detail/27109

腾讯课堂连接地址https://ke.qq.com/course/484107?tuin=ba64518

介绍主要的k8s资源的使用配置和命令。包括configmap,pod,service,replicaset,namespace,deployment,daemonset,ingress,pv,pvc,sc,role,rolebinding,clusterrole,clusterrolebinding,secret,serviceaccount,statefulset,job,cronjob,podDisruptionbudget,podSecurityPolicy,networkPolicy,resourceQuota,limitrange,endpoint,event,conponentstatus,node,apiservice,controllerRevision等。

第三个视频发布:https://edu.csdn.net/course/detail/27574

详细介绍helm命令,学习helm chart语法,编写helm chart。深入分析各项目源码,学习编写helm插件

第四个课程发布:https://edu.csdn.net/course/detail/28488

本课程将详细介绍k8s所有命令,以及命令的go源码分析,学习知其然,知其所以然

-----------------------------------------------------------------------------------------------------

func main() {//程序入口
	initKubeLogs()//初始化kube日志

	actionConfig := new(action.Configuration)
	cmd := newRootCmd(actionConfig, os.Stdout, os.Args[1:])//创建根命令

	if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), os.Getenv("HELM_DRIVER"), debug); err != nil {//初始化
		log.Fatal(err)
	}

	if err := cmd.Execute(); err != nil {执行命令
		debug("%+v", err)
		switch e := err.(type) {
		case pluginError:
			os.Exit(e.code)
		default:
			os.Exit(1)
		}
	}
}
func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string) *cobra.Command {//获取根命令
	cmd := &cobra.Command{//创建cobra命令
		Use:                    "helm",
		Short:                  "The Helm package manager for Kubernetes.",
		Long:                   globalUsage,
		SilenceUsage:           true,
		Args:                   require.NoArgs,
		BashCompletionFunction: fmt.Sprintf("%s%s", contextCompFunc, completion.GetBashCustomFunction()),
	}
	flags := cmd.PersistentFlags()

	settings.AddFlags(flags)//添加选项

	flag := flags.Lookup("namespace")
	// Setup shell completion for the namespace flag
	completion.RegisterFlagCompletionFunc(flag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, completion.BashCompDirective) {//自动补全
		if client, err := actionConfig.KubernetesClientSet(); err == nil {
			// Choose a long enough timeout that the user notices somethings is not working
			// but short enough that the user is not made to wait very long
			to := int64(3)
			completion.CompDebugln(fmt.Sprintf("About to call kube client for namespaces with timeout of: %d", to))

			nsNames := []string{}
			if namespaces, err := client.CoreV1().Namespaces().List(metav1.ListOptions{TimeoutSeconds: &to}); err == nil {
				for _, ns := range namespaces.Items {
					if strings.HasPrefix(ns.Name, toComplete) {
						nsNames = append(nsNames, ns.Name)
					}
				}
				return nsNames, completion.BashCompDirectiveNoFileComp
			}
		}
		return nil, completion.BashCompDirectiveDefault
	})

	// We can safely ignore any errors that flags.Parse encounters since
	// those errors will be caught later during the call to cmd.Execution.
	// This call is required to gather configuration information prior to
	// execution.
	flags.ParseErrorsWhitelist.UnknownFlags = true
	flags.Parse(args)

	// Add subcommands
	cmd.AddCommand(//添加子命令
		// chart commands
		newCreateCmd(out),// 添加create命令
		newDependencyCmd(out),// 添加dependency命令
		newPullCmd(out),//添加pull命令
		newShowCmd(out),//添加show命令
		newLintCmd(out),//添加lint命令
		newPackageCmd(out),//添加package命令
		newRepoCmd(out),//添加repo命令
		newSearchCmd(out),//添加search命令
		newVerifyCmd(out),//添加verify命令

		// release commands
		newGetCmd(actionConfig, out),//添加get命令
		newHistoryCmd(actionConfig, out),//添加history命令
		newInstallCmd(actionConfig, out),//添加install命令
		newListCmd(actionConfig, out),//添加list命令
		newReleaseTestCmd(actionConfig, out),//添加test命令
		newRollbackCmd(actionConfig, out),//添加rollback命令
		newStatusCmd(actionConfig, out),//添加status命令
		newTemplateCmd(actionConfig, out),//添加template命令
		newUninstallCmd(actionConfig, out),//添加uninstall命令
		newUpgradeCmd(actionConfig, out),//添加upgrade命令

		newCompletionCmd(out),//添加completion命令
		newEnvCmd(out),//添加env命令
		newPluginCmd(out),//添加plugin命令
		newVersionCmd(out),// 添加version命令

		// Hidden documentation generator command: 'helm docs'
		newDocsCmd(out),//添加docs命令

		// Setup the special hidden __complete command to allow for dynamic auto-completion
		completion.NewCompleteCmd(settings, out),
	)

	// Add annotation to flags for which we can generate completion choices
	for name, completion := range bashCompletionFlags {
		if cmd.Flag(name) != nil {
			if cmd.Flag(name).Annotations == nil {
				cmd.Flag(name).Annotations = map[string][]string{}
			}
			cmd.Flag(name).Annotations[cobra.BashCompCustom] = append(
				cmd.Flag(name).Annotations[cobra.BashCompCustom],
				completion,
			)
		}
	}

	// Add *experimental* subcommands
	registryClient, err := registry.NewClient(
		registry.ClientOptDebug(settings.Debug),
		registry.ClientOptWriter(out),
	)
	if err != nil {
		// TODO: don't panic here, refactor newRootCmd to return error
		panic(err)
	}
	actionConfig.RegistryClient = registryClient
	cmd.AddCommand(
		newRegistryCmd(actionConfig, out),//添加registry命令
		newChartCmd(actionConfig, out),//添加chart命令
	)

	// Find and add plugins
	loadPlugins(cmd, out)//加载插件

	return cmd
}

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(k8s实战之helm源码分析,运维,k8s)