master
dongming 2 years ago
parent 9b77fdace3
commit b3b4703c48

@ -27,6 +27,7 @@ import (
demov1 "mashibing.com/demo/app/api/v1"
)
// Reconciler对象里面封装了我们调和函数需要的资源
// AppReconciler reconciles a App object
type AppReconciler struct {
client.Client
@ -54,9 +55,10 @@ func (r *AppReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
return ctrl.Result{}, nil
}
// 完成了将 reconciler 加入 controller中之后将controller加入manager中
// SetupWithManager sets up the controller with the Manager.
func (r *AppReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&demov1.App{}).
For(&demov1.App{}). // 将我们当前的crd加入“过滤器”可以让controller订阅到crd的变化
Complete(r)
}

@ -90,7 +90,7 @@ func main() {
os.Exit(1)
}
// Reconciler 存在于manager下
// Controller 存在于manager下Reconciler 存在于 Controller 中
if err = (&controllers.AppReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),

@ -335,8 +335,10 @@ type LeaderElectionRunnable interface {
// New returns a new Manager for creating Controllers.
func New(config *rest.Config, options Options) (Manager, error) {
// Set default values for options fields
// 设置一些默认的选项,这里可能包含一些默认的方法。
options = setOptionsDefaults(options)
// 创建 cluster里面会包含一些与 cluster 通讯的必要组件
cluster, err := cluster.New(config, func(clusterOptions *cluster.Options) {
clusterOptions.Scheme = options.Scheme
clusterOptions.MapperProvider = options.MapperProvider
@ -356,11 +358,13 @@ func New(config *rest.Config, options Options) (Manager, error) {
// Create the recorder provider to inject event recorders for the components.
// TODO(directxman12): the log for the event provider should have a context (name, tags, etc) specific
// to the particular controller that it's being injected into, rather than a generic one like is here.
// 创建一个记录器
recorderProvider, err := options.newRecorderProvider(config, cluster.GetScheme(), options.Logger.WithName("events"), options.makeBroadcaster)
if err != nil {
return nil, err
}
// 集群调度相关的数据
// Create the resource lock to enable leader election)
var leaderConfig *rest.Config
var leaderRecorderProvider *intrec.Provider
@ -386,6 +390,7 @@ func New(config *rest.Config, options Options) (Manager, error) {
return nil, err
}
// 创建一个监控相关的数据
// Create the metrics listener. This will throw an error if the metrics bind
// address is invalid or already in use.
metricsListener, err := options.newMetricsListener(options.MetricsBindAddress)
@ -403,6 +408,7 @@ func New(config *rest.Config, options Options) (Manager, error) {
return nil, err
}
// 重点关注runnables。
errChan := make(chan error)
runnables := newRunnables(options.BaseContext, errChan)

Loading…
Cancel
Save