Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syn configmap using the old way to query api server in Hub Mode #3568

Open
kylinsoong opened this issue Sep 24, 2024 · 4 comments
Open

syn configmap using the old way to query api server in Hub Mode #3568

kylinsoong opened this issue Sep 24, 2024 · 4 comments

Comments

@kylinsoong
Copy link

syn configmap using the old way to query api server in Hub Mode

While syn configmap, the service usually resident the watched namespce, and had appInf bounded, however getServicesForHubMode stilll use the old way, this can further enhance to performance.

func (appMgr *Manager) getServicesForHubMode(selector, namespace string, isTenantNameServiceNamespace bool) ([]v1.Service, error) {
    var svcItems []v1.Service
    if isTenantNameServiceNamespace {
        if appInf, infFound := appMgr.getNamespaceInformer(namespace); infFound {
            svcInformer := appInf.svcInformer
            svcLister := listerscorev1.NewServiceLister(svcInformer.GetIndexer())
            ls, _ := createLabel(selector)
            svcListed, _ := svcLister.Services(namespace).List(ls)

            for n, _ := range svcListed {
                svcItems = append(svcItems, *svcListed[n])
            }
            log.Debugf("[CORE] Extract service via watch-list informer '%s'", namespace)
            return svcItems, nil
        }
    }
    // Leaving the old way for hubMode for now.
    svcListOptions := metav1.ListOptions{
        LabelSelector: selector,
    }
    services, err := appMgr.kubeClient.CoreV1().Services(v1.NamespaceAll).List(context.TODO(), svcListOptions)

    if err != nil {
        log.Errorf("[CORE] Error getting service list. %v", err)
        return nil, err
    }
    svcItems = services.Items
    log.Debugf("[CORE] Query service via '%v'", selector)
    return svcItems, nil
}

The invocation of this function in syncConfigMaps looks:

members, err := appMgr.getEndpoints(selector, sKey.Namespace, false)
@kylinsoong
Copy link
Author

Samiliar requirements in getEndpointForHub:

func (appMgr *Manager) getEndpointsForHubMode(svcName, svcNamespace string, isTenantNameServiceNamespace bool) (*v1.Endpoints, error) {
	var eps *v1.Endpoints
	if isTenantNameServiceNamespace {
		if appInf, infFound := appMgr.getNamespaceInformer(svcNamespace); infFound {
			if item, found, _ := appInf.endptInformer.GetStore().GetByKey(svcNamespace + "/" + svcName); found {
				eps, _ = item.(*v1.Endpoints)
			}
			return eps, nil
		}
	}
	// Leaving the old way for hubMode for now.
	endpointsList, err := appMgr.kubeClient.CoreV1().Endpoints(svcNamespace).List(context.TODO(),
		metav1.ListOptions{
			FieldSelector: "metadata.name=" + svcName,
		},
	)
	if err != nil {
		return nil, err
	}
	if len(endpointsList.Items) == 0 {
		return eps, nil
	}
	eps = &endpointsList.Items[0]
	return eps, nil
}

@vklohiya
Copy link
Contributor

@kylinsoong , As in the hubmode services can exist in any namespace other-than the configMap namespace hence, we need to query using kube-api server, as informer may or may not exist for the namespace, where service is residing.

If you use isTenantNameServiceNamespace label, it will use the informers and if informers are not found than fall back to kube-api server query.

@kylinsoong
Copy link
Author

Thanks @vklohiya, can we use the similar logic in appMgr's syncConfigMaps?

Currently only AS3 Manager get GetEndpoints use the IsTenantNameServiceNamespace, however the APP Manager get GetEndpoints passed false, which thoughts the IsTenantNameServiceNamespace is not set.

On the other side, periodicly syn virtual server are always against the service that has watched with informer referenced.

members, err := appMgr.getEndpoints(selector, sKey.Namespace, false)

The below is getEndpoints in AS3 Manager

				if val, ok := rscCfgMap.Label[IsTenantNameServiceNamespace]; ok && val == TrueLabel {
					eps, err = rscCfgMap.GetEndpoints(am.getSelector(tnt, app, pn), string(tnt), true)
				} else {
					eps, err = rscCfgMap.GetEndpoints(am.getSelector(tnt, app, pn), rscCfgMap.Namespace, false)
				}

@trinaths
Copy link
Contributor

Created [CONTCNTR-4952] for internal tracking.

@trinaths trinaths added JIRA and removed untriaged no JIRA created labels Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants