forked from TencentBlueKing/bk-job
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 更新过程中服务间调用失败导致无损更新失效 TencentBlueKing#3242
打印负载均衡实例获取记录,分析缓存未刷新原因。
- Loading branch information
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
...-execute/src/main/java/com/tencent/bk/job/execute/config/JobK8sDiscoveryClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. | ||
* | ||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. | ||
* | ||
* License for BK-JOB蓝鲸智云作业平台: | ||
* -------------------------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and | ||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | ||
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.tencent.bk.job.execute.config; | ||
|
||
|
||
import io.kubernetes.client.informer.SharedInformer; | ||
import io.kubernetes.client.informer.SharedInformerFactory; | ||
import io.kubernetes.client.informer.cache.Lister; | ||
import io.kubernetes.client.openapi.ApiClient; | ||
import io.kubernetes.client.openapi.models.V1Endpoints; | ||
import io.kubernetes.client.openapi.models.V1EndpointsList; | ||
import io.kubernetes.client.openapi.models.V1Service; | ||
import io.kubernetes.client.openapi.models.V1ServiceList; | ||
import io.kubernetes.client.spring.extended.controller.annotation.GroupVersionResource; | ||
import io.kubernetes.client.spring.extended.controller.annotation.KubernetesInformer; | ||
import io.kubernetes.client.spring.extended.controller.annotation.KubernetesInformers; | ||
import org.springframework.cloud.kubernetes.client.discovery.KubernetesInformerDiscoveryClient; | ||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; | ||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
public class JobK8sDiscoveryClientConfig { | ||
@Bean | ||
public JobCatalogSharedInformerFactory catalogSharedInformerFactory( | ||
ApiClient apiClient) { | ||
return new JobCatalogSharedInformerFactory(); | ||
} | ||
|
||
@Bean | ||
public KubernetesInformerDiscoveryClient kubernetesInformerDiscoveryClient( | ||
KubernetesNamespaceProvider kubernetesNamespaceProvider, | ||
JobCatalogSharedInformerFactory sharedInformerFactory, Lister<V1Service> serviceLister, | ||
Lister<V1Endpoints> endpointsLister, SharedInformer<V1Service> serviceInformer, | ||
SharedInformer<V1Endpoints> endpointsInformer, KubernetesDiscoveryProperties properties) { | ||
return new JobKubernetesInformerDiscoveryClient(kubernetesNamespaceProvider.getNamespace(), | ||
sharedInformerFactory, serviceLister, endpointsLister, serviceInformer, endpointsInformer, | ||
properties); | ||
} | ||
|
||
@KubernetesInformers({ | ||
@KubernetesInformer(apiTypeClass = V1Service.class, apiListTypeClass = V1ServiceList.class, | ||
groupVersionResource = @GroupVersionResource(apiGroup = "", apiVersion = "v1", | ||
resourcePlural = "services")), | ||
@KubernetesInformer(apiTypeClass = V1Endpoints.class, apiListTypeClass = V1EndpointsList.class, | ||
groupVersionResource = @GroupVersionResource(apiGroup = "", apiVersion = "v1", | ||
resourcePlural = "endpoints"))}) | ||
class JobCatalogSharedInformerFactory extends SharedInformerFactory { | ||
|
||
// TODO: optimization to ease memory pressure from continuous list&watch. | ||
|
||
} | ||
} | ||
|
56 changes: 56 additions & 0 deletions
56
...src/main/java/com/tencent/bk/job/execute/config/JobKubernetesInformerDiscoveryClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. | ||
* | ||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. | ||
* | ||
* License for BK-JOB蓝鲸智云作业平台: | ||
* -------------------------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and | ||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | ||
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.tencent.bk.job.execute.config; | ||
|
||
import io.kubernetes.client.informer.SharedInformer; | ||
import io.kubernetes.client.informer.SharedInformerFactory; | ||
import io.kubernetes.client.informer.cache.Lister; | ||
import io.kubernetes.client.openapi.models.V1Endpoints; | ||
import io.kubernetes.client.openapi.models.V1Service; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.cloud.client.ServiceInstance; | ||
import org.springframework.cloud.kubernetes.client.discovery.KubernetesInformerDiscoveryClient; | ||
import org.springframework.cloud.kubernetes.commons.discovery.KubernetesDiscoveryProperties; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
public class JobKubernetesInformerDiscoveryClient extends KubernetesInformerDiscoveryClient { | ||
public JobKubernetesInformerDiscoveryClient(String namespace, SharedInformerFactory sharedInformerFactory, | ||
Lister<V1Service> serviceLister, Lister<V1Endpoints> endpointsLister, | ||
SharedInformer<V1Service> serviceInformer, | ||
SharedInformer<V1Endpoints> endpointsInformer, | ||
KubernetesDiscoveryProperties properties) { | ||
super(namespace, sharedInformerFactory, serviceLister, endpointsLister, serviceInformer, endpointsInformer, | ||
properties); | ||
} | ||
|
||
@Override | ||
public List<ServiceInstance> getInstances(String serviceId) { | ||
List<ServiceInstance> serviceInstanceList = super.getInstances(serviceId); | ||
log.info("serviceId={}, serviceInstanceList={}", serviceId, serviceInstanceList); | ||
return serviceInstanceList; | ||
} | ||
} |