public MesosSlaveInfo getMesosSlaveInfoForLabel(Label label) {
    if (!matchesLabel(label)) {
      return null;
    }

    if (label == null) {
      if (getLabelString() == null) {
        return this;
      } else {
        return null;
      }
    }

    if (label.matches(Label.parse(getLabelString()))) {
      return this;
    }

    if (!containerInfo.getDockerImageCustomizable()) {
      return null;
    }

    String customImage = getCustomImage(label);
    if (customImage == null) {
      return null;
    }

    return copyWithDockerImage(label.toString(), customImage);
  }
  /**
   * Check if the label in the slave matches the provided label, either both are null or are the
   * same.
   *
   * @param label
   * @return Whether the slave label matches.
   */
  public boolean matchesLabel(@CheckForNull Label label) {

    if (label == null || getLabelString() == null) {
      return label == null && getLabelString() == null;
    }

    if (label.matches(Label.parse(getLabelString()))) {
      return true;
    }

    if (containerInfo == null || !containerInfo.getDockerImageCustomizable()) {
      return false;
    }

    String customImage = getCustomImage(label);
    return customImage != null
        && getLabelWithoutCustomImage(label, customImage).matches(Label.parse(getLabelString()));
  }