Пример #1
0
  public ServiceInstance(Service service) {
    this.service = service;
    this.id = getName(service);
    ServiceSpec spec = KubernetesHelper.getOrCreateSpec(service);
    List<ServicePort> ports = spec.getPorts();
    if (spec.getPortalIP().equals(HEADLESS_PORTAL_IP)) {
      // do nothing service is headless
    } else if (ports != null && !ports.isEmpty()) {
      for (ServicePort servicePort : ports) {
        servicePorts.add(toNamedServicePort(id, servicePort));
      }
    } else {
      throw new IllegalArgumentException(
          "Service: " + id + " doesn't have a valid port configuration.");
    }
    this.selector = KubernetesHelper.getSelector(service);
    Objects.notNull(this.selector, "No selector for service " + id);
    if (selector.isEmpty()) {
      throw new IllegalArgumentException("Empty selector for service " + id);
    }
    this.filter = KubernetesHelper.createPodFilter(selector);

    // TODO should we use some service metadata to choose the load balancer?
    this.loadBalancer = new RoundRobinLoadBalancer();
  }
Пример #2
0
 private Set<MavenProject> sameParent(MavenProject parent, List<MavenProject> projects) {
   Set<MavenProject> answer = new LinkedHashSet<>();
   for (MavenProject zip : projects) {
     if (Objects.equal(parent, zip.getParent())) {
       answer.add(zip);
     }
   }
   return answer;
 }
Пример #3
0
 private static boolean hasAncestor(MavenProject root, MavenProject target) {
   if (target.getParent() == null) {
     return false;
   }
   if (Objects.equal(root, target.getParent())) {
     return true;
   } else {
     return hasAncestor(root, target.getParent());
   }
 }
 public KubernetesClient getKubernetes() {
   if (kubernetes == null) {
     String kubernetesAddress = kubernetesUrl.getValue();
     if (Strings.isNotBlank(kubernetesAddress)) {
       kubernetes =
           new DefaultKubernetesClient(
               new ConfigBuilder().withMasterUrl(kubernetesAddress).build());
     } else {
       kubernetes = new DefaultKubernetesClient();
     }
   }
   Objects.notNull(kubernetes, "kubernetes");
   return kubernetes;
 }
Пример #5
0
  @Override
  public Result execute(UIExecutionContext context) throws Exception {
    String buildConfigName = buildName.getValue();
    Objects.assertNotNull(buildConfigName, "buildName");
    Map<String, String> labels = BuildConfigs.createBuildLabels(buildConfigName);
    String ouputImageName = imageName.getValue();
    String gitUrlText = getOrFindGitUrl(context, gitUri.getValue());
    String imageText = outputImage.getValue();
    Model mavenModel = getMavenModel(context);
    if (Strings.isNullOrBlank(imageText) && mavenModel != null) {
      imageText = mavenModel.getProperties().getProperty("docker.image");
    }

    String webhookSecretText = webHookSecret.getValue();
    if (Strings.isNullOrBlank(webhookSecretText)) {
      // TODO generate a really good secret!
      webhookSecretText = "secret101";
    }
    BuildConfig buildConfig =
        BuildConfigs.createBuildConfig(
            buildConfigName, labels, gitUrlText, ouputImageName, imageText, webhookSecretText);

    System.out.println("Generated BuildConfig: " + toJson(buildConfig));

    ImageStream imageRepository = BuildConfigs.imageRepository(buildConfigName, labels);

    Controller controller = createController();
    controller.applyImageStream(
        imageRepository, "generated ImageStream: " + toJson(imageRepository));
    controller.applyBuildConfig(buildConfig, "generated BuildConfig: " + toJson(buildConfig));
    return Results.success(
        "Added BuildConfig: "
            + Builds.getName(buildConfig)
            + " to OpenShift at master: "
            + getKubernetes().getAddress());
  }
 @PostConstruct
 public void activate() {
   vertx = vertxFactory.createVertx();
   Objects.notNull(vertx, "vertx");
 }