Interface FlinkKubeClient

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
Fabric8FlinkKubeClient

public interface FlinkKubeClient extends AutoCloseable
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.
  • Method Details

    • createJobManagerComponent

      void createJobManagerComponent(KubernetesJobManagerSpecification kubernetesJMSpec)
      Create the Master components, this can include the Deployment, the ConfigMap(s), and the Service(s).
      Parameters:
      kubernetesJMSpec - jobmanager specification
    • createTaskManagerPod

      CompletableFuture<Void> createTaskManagerPod(KubernetesPod kubernetesPod)
      Create task manager pod.
      Parameters:
      kubernetesPod - taskmanager pod
      Returns:
      Return the taskmanager pod creation future
    • stopPod

      CompletableFuture<Void> stopPod(String podName)
      Stop a specified pod by name.
      Parameters:
      podName - pod name
      Returns:
      Return the pod stop future
    • stopAndCleanupCluster

      void stopAndCleanupCluster(String clusterId)
      Stop cluster and clean up all resources, include services, auxiliary services and all running pods.
      Parameters:
      clusterId - cluster id
    • getService

      Optional<KubernetesService> getService(String serviceName)
      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

      Optional<Endpoint> getRestEndpoint(String clusterId)
      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<KubernetesPod> getPodsWithLabels(Map<String,String> labels)
      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 Exception
      Watch the pods selected by labels and do the FlinkKubeClient.WatchCallbackHandler.
      Parameters:
      labels - labels to filter the pods to watch
      podCallbackHandler - 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 configuration
      leaderCallbackHandler - Callback when the current instance is leader or not.
      Returns:
      Return the created leader elector. It should be started manually via KubernetesLeaderElector#run.
    • createConfigMap

      CompletableFuture<Void> createConfigMap(KubernetesConfigMap configMap)
      Create the ConfigMap with specified content. If the ConfigMap already exists, a KubernetesException will 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

      Optional<KubernetesConfigMap> getConfigMap(String name)
      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 with getConfigMap(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 PossibleInconsistentStateException indicating that no clear decision can be made on whether the update was successful or not. The PossibleInconsistentStateException not 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

      CompletableFuture<Void> deleteConfigMap(String configMapName)
      Delete a Kubernetes ConfigMap by name.
      Parameters:
      configMapName - ConfigMap name
      Returns:
      Return the delete future.
    • createConfigMapSharedWatcher

      KubernetesConfigMapSharedWatcher createConfigMapSharedWatcher(String name)
      Create a shared watcher for ConfigMaps with specified name.
      Parameters:
      name - name of the ConfigMap to watch.
      Returns:
      Return a shared watcher.
    • close

      void close()
      Close the Kubernetes client with no exception.
      Specified by:
      close in interface AutoCloseable
    • loadPodFromTemplateFile

      KubernetesPod loadPodFromTemplateFile(File podTemplateFile)
      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 updated
      portName - The port name which needs to be updated
      targetPort - The updated target port
      Returns:
      Return the update service target port future