Interface FlinkKubeClient
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
Fabric8FlinkKubeClient
The client to talk with kubernetes. The interfaces will be called both in Client and
ResourceManager. To avoid potentially blocking the execution of RpcEndpoint's main thread, these
interfaces
createTaskManagerPod(KubernetesPod), stopPod(String) should be
implemented asynchronously.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceCallback handler for kubernetes resources. -
Method Summary
Modifier and TypeMethodDescriptioncheckAndUpdateConfigMap(String configMapName, Function<KubernetesConfigMap, Optional<KubernetesConfigMap>> updateFunction) Update an existing ConfigMap with the data.voidclose()Close the Kubernetes client with no exception.createConfigMap(KubernetesConfigMap configMap) Create the ConfigMap with specified content.Create a shared watcher for ConfigMaps with specified name.voidcreateJobManagerComponent(KubernetesJobManagerSpecification kubernetesJMSpec) Create the Master components, this can include the Deployment, the ConfigMap(s), and the Service(s).createLeaderElector(KubernetesLeaderElectionConfiguration leaderElectionConfiguration, KubernetesLeaderElector.LeaderCallbackHandler leaderCallbackHandler) Create a leader elector service based on Kubernetes api.createTaskManagerPod(KubernetesPod kubernetesPod) Create task manager pod.deleteConfigMap(String configMapName) Delete a Kubernetes ConfigMap by name.getConfigMap(String name) Get the ConfigMap with specified name.getPodsWithLabels(Map<String, String> labels) List the pods with specified labels.getRestEndpoint(String clusterId) Get the rest endpoint for access outside cluster.getService(String serviceName) Get the kubernetes service of the given flink clusterId.loadPodFromTemplateFile(File podTemplateFile) Load pod from template file.voidstopAndCleanupCluster(String clusterId) Stop cluster and clean up all resources, include services, auxiliary services and all running pods.Stop a specified pod by name.updateServiceTargetPort(String serviceName, String portName, int targetPort) Update the target ports of the given Kubernetes service.watchPodsAndDoCallback(Map<String, String> labels, FlinkKubeClient.WatchCallbackHandler<KubernetesPod> podCallbackHandler) Watch the pods selected by labels and do theFlinkKubeClient.WatchCallbackHandler.
-
Method Details
-
createJobManagerComponent
Create the Master components, this can include the Deployment, the ConfigMap(s), and the Service(s).- Parameters:
kubernetesJMSpec- jobmanager specification
-
createTaskManagerPod
Create task manager pod.- Parameters:
kubernetesPod- taskmanager pod- Returns:
- Return the taskmanager pod creation future
-
stopPod
Stop a specified pod by name.- Parameters:
podName- pod name- Returns:
- Return the pod stop future
-
stopAndCleanupCluster
Stop cluster and clean up all resources, include services, auxiliary services and all running pods.- Parameters:
clusterId- cluster id
-
getService
Get the kubernetes service of the given flink clusterId.- Parameters:
serviceName- the name of the service- Returns:
- Return the optional kubernetes service of the specified name.
-
getRestEndpoint
Get the rest endpoint for access outside cluster.- Parameters:
clusterId- cluster id- Returns:
- Return empty if the service does not exist or could not extract the Endpoint from the service.
-
getPodsWithLabels
List the pods with specified labels.- Parameters:
labels- labels to filter the pods- Returns:
- pod list
-
watchPodsAndDoCallback
CompletableFuture<KubernetesWatch> watchPodsAndDoCallback(Map<String, String> labels, FlinkKubeClient.WatchCallbackHandler<KubernetesPod> podCallbackHandler) throws ExceptionWatch the pods selected by labels and do theFlinkKubeClient.WatchCallbackHandler.- Parameters:
labels- labels to filter the pods to watchpodCallbackHandler- podCallbackHandler which reacts to pod events- Returns:
- Return a watch for pods. It needs to be closed after use.
- Throws:
Exception
-
createLeaderElector
KubernetesLeaderElector createLeaderElector(KubernetesLeaderElectionConfiguration leaderElectionConfiguration, KubernetesLeaderElector.LeaderCallbackHandler leaderCallbackHandler) Create a leader elector service based on Kubernetes api.- Parameters:
leaderElectionConfiguration- election configurationleaderCallbackHandler- Callback when the current instance is leader or not.- Returns:
- Return the created leader elector. It should be started manually via
KubernetesLeaderElector#run.
-
createConfigMap
Create the ConfigMap with specified content. If the ConfigMap already exists, aKubernetesExceptionwill be thrown.- Parameters:
configMap- ConfigMap to be created.- Returns:
- Return the ConfigMap create future. The returned future will be completed exceptionally if the ConfigMap already exists.
-
getConfigMap
Get the ConfigMap with specified name.- Parameters:
name- name of the ConfigMap to retrieve.- Returns:
- Return the ConfigMap, or empty if the ConfigMap does not exist.
-
checkAndUpdateConfigMap
CompletableFuture<Boolean> checkAndUpdateConfigMap(String configMapName, Function<KubernetesConfigMap, Optional<KubernetesConfigMap>> updateFunction) Update an existing ConfigMap with the data. Benefit from resource version and combined withgetConfigMap(String), we could perform a get-check-and-update transactional operation. Since concurrent modification could happen on a same ConfigMap, the update operation may fail. We need to retry internally in the implementation.- Parameters:
configMapName- configMapName specifies the name of the ConfigMap which shall be updated.updateFunction- Function to be applied to the obtained ConfigMap and get a new updated one. If the returned optional is empty, we will not do the update.- Returns:
- Return the ConfigMap update future. The boolean result indicates whether the
ConfigMap is updated. The returned future will be completed exceptionally if the
ConfigMap does not exist. A failure during the update operation will result in the future
failing with a
PossibleInconsistentStateExceptionindicating that no clear decision can be made on whether the update was successful or not. ThePossibleInconsistentStateExceptionnot being present indicates that the failure happened before writing the updated ConfigMap to Kubernetes. For the latter case, it can be assumed that the ConfigMap was not updated.
-
deleteConfigMap
Delete a Kubernetes ConfigMap by name.- Parameters:
configMapName- ConfigMap name- Returns:
- Return the delete future.
-
close
void close()Close the Kubernetes client with no exception.- Specified by:
closein interfaceAutoCloseable
-
loadPodFromTemplateFile
Load pod from template file.- Parameters:
podTemplateFile- The pod template file.- Returns:
- Return a Kubernetes pod loaded from the template.
-
updateServiceTargetPort
CompletableFuture<Void> updateServiceTargetPort(String serviceName, String portName, int targetPort) Update the target ports of the given Kubernetes service.- Parameters:
serviceName- The name of the service which needs to be updatedportName- The port name which needs to be updatedtargetPort- The updated target port- Returns:
- Return the update service target port future
-