private KubernetesClusterCreateTask buildPatch(
      TaskState.TaskStage stage,
      TaskState.SubStage subStage,
      @Nullable ServiceErrorResponse errorResponse) {

    KubernetesClusterCreateTask state = new KubernetesClusterCreateTask();
    state.taskState = new TaskState();
    state.taskState.stage = stage;
    state.taskState.subStage = subStage;
    state.taskState.failure = errorResponse;
    return state;
  }
  /**
   * This method creates a Kubernetes Cluster Service instance. On successful creation, the method
   * moves the sub-stage to SETUP_MASTER.
   *
   * @param currentState
   * @param imageId
   */
  private void createClusterService(
      final KubernetesClusterCreateTask currentState, final String imageId) {

    ClusterService.State cluster = new ClusterService.State();
    cluster.clusterState = ClusterState.CREATING;
    cluster.clusterName = currentState.clusterName;
    cluster.clusterType = ClusterType.KUBERNETES;
    cluster.imageId = imageId;
    cluster.projectId = currentState.projectId;
    cluster.diskFlavorName = currentState.diskFlavorName;
    cluster.masterVmFlavorName = currentState.masterVmFlavorName;
    cluster.otherVmFlavorName = currentState.otherVmFlavorName;
    cluster.vmNetworkId = currentState.vmNetworkId;
    cluster.slaveCount = currentState.slaveCount;
    cluster.extendedProperties = new HashMap<>();
    cluster.extendedProperties.put(ClusterManagerConstants.EXTENDED_PROPERTY_DNS, currentState.dns);
    cluster.extendedProperties.put(
        ClusterManagerConstants.EXTENDED_PROPERTY_GATEWAY, currentState.gateway);
    cluster.extendedProperties.put(
        ClusterManagerConstants.EXTENDED_PROPERTY_NETMASK, currentState.netmask);
    cluster.extendedProperties.put(
        ClusterManagerConstants.EXTENDED_PROPERTY_CONTAINER_NETWORK, currentState.containerNetwork);
    cluster.extendedProperties.put(
        ClusterManagerConstants.EXTENDED_PROPERTY_ETCD_IPS,
        NodeTemplateUtils.serializeAddressList(currentState.etcdIps));
    cluster.extendedProperties.put(
        ClusterManagerConstants.EXTENDED_PROPERTY_MASTER_IP, currentState.masterIp);
    cluster.documentSelfLink = currentState.clusterId;

    sendRequest(
        HostUtils.getCloudStoreHelper(this)
            .createPost(ClusterServiceFactory.SELF_LINK)
            .setBody(cluster)
            .setCompletion(
                (operation, throwable) -> {
                  if (null != throwable) {
                    failTask(throwable);
                    return;
                  }

                  KubernetesClusterCreateTask patchState =
                      buildPatch(TaskState.TaskStage.STARTED, TaskState.SubStage.SETUP_ETCD);
                  patchState.imageId = imageId;
                  TaskUtils.sendSelfPatch(this, patchState);
                }));
  }