karmada-io / karmada

Open, Multi-Cloud, Multi-Cluster Kubernetes Orchestration
https://karmada.io
Apache License 2.0
4.11k stars 803 forks source link

[Karmada operator] Code consult #3582

Closed yanggangtony closed 6 months ago

yanggangtony commented 11 months ago

Please provide an in-depth description of the question you have: I rough read the operator code. I found the operator/pkg/deinit.go 's remoteClient define.

type deInitData struct {
    name         string
    namespace    string
    remoteClient clientset.Interface
}

and operator/pkg/init.go 's remoteClient define.

type initData struct {
          ...
    remoteClient        clientset.Interface
    karmadaClient       clientset.Interface
       ...  
}

Its just initialized in condition

if opt.Karmada.Spec.HostCluster.SecretRef == nil && len(opt.Karmada.Spec.HostCluster.APIEndpoint) == 0 {

But in the next logic about the task execute loop. Its will immediate be called by tasks.. Like the init task

func NewKarmadaApiserverTask() workflow.Task {
    return workflow.Task{
        Name:        "apiserver",
        Run:         runApiserver,
        RunSubTasks: true,
        Tasks: []workflow.Task{
            {
                Name: constants.KarmadaAPIserverComponent,
                Run:  runKarmadaAPIServer,

Also the deinit case is the same..

I want to know if is a known problem? Or If it is can be initialize like the

func (data *initData) KarmadaClient() clientset.Interface {
    if data.karmadaClient == nil {
        data.Once.Do(func() {
            client, err := clientset.NewForConfig(data.controlplaneConifig)
            if err != nil {
                klog.Errorf("error when init karmada client, err: %w", err)
            }
            data.karmadaClient = client
        })
    }

    return data.karmadaClient
}

If its really a problem . I will assign and handle it.. Thanks.

What do you think about this question?: Karmada operator

yanggangtony commented 11 months ago

@calvin0327 @lonelyCZ @Poor12 @RainbowMango

calvin0327 commented 11 months ago

@yanggangtony Thanks for pointing this out.

Indeed, now we not support installing karmada on remote clusters. if user provides the cluster APIEndpoint or a kubeconfig secret, we should init a remoteClient with these message.

And there are two clients: karmadaClinet: connect to karmada controlplane remoteClient: connect to the target cluster to install karmada

If you're interested in it, you can assign this.

yanggangtony commented 11 months ago

@calvin0327 Thanks for the quick response. I will make a pr to the

remoteClient's fuction.

/assign

yanggangtony commented 10 months ago

Sorry for the late response . Recentely have lots of other works to to. Have no more time pay for the pr. 🥲🥲