package io.fabric8.app.gerrit;

import io.fabric8.kubernetes.generator.annotation.KubernetesModelProcessor;
import io.fabric8.openshift.api.model.template.TemplateBuilder;

@KubernetesModelProcessor
public class GerritModelProcessor {

    public void onList(TemplateBuilder builder) {
        builder.addNewServiceObject()
                .withNewMetadata()
                  .withName("gerrit-http-service")
                  .addToLabels("component", "gerrit")
                  .addToLabels("provider", "fabric8")
                .endMetadata()
                .withNewSpec()
                  .addNewPort()
                    .withProtocol("http")
                    .withPort(80)
                      .withNewTargetPort(8080)
                    .endPort()
                    .addToSelector("component", "gerrit")
                    .addToSelector("provider", "fabric8")
                .endSpec()
                .endServiceObject()
                // Second service
                .addNewServiceObject()
                .withNewMetadata()
                  .withName("gerrit-ssh-service")
                  .addToLabels("component", "gerrit")
                  .addToLabels("provider", "fabric8")
                .endMetadata()
                .withNewSpec()
                  .addNewPort()
                    .withProtocol("ssh")
                    .withPort(29418)
                      .withNewTargetPort(29418)
                    .endPort()
                    .addToSelector("component", "gerrit")
                    .addToSelector("provider", "fabric8")
                .endSpec()
                .endServiceObject()
                .build();
    }
}

package io.fabric8.app.gerrit;

import io.fabric8.kubernetes.generator.annotation.KubernetesModelProcessor;
import io.fabric8.openshift.api.model.template.TemplateBuilder;

@KubernetesModelProcessor
public class GerritModelProcessor {

    public void onList(TemplateBuilder builder) {
        builder.addNewServiceObject()
                .withNewMetadata()
                  .withName("gerrit-http-service")
                  .addToLabels("component", "gerrit")
                  .addToLabels("provider", "fabric8")
                .endMetadata()
                .withNewSpec()
                  .addNewPort()
/*                    .withProtocol("HTTP")*/
                    .withPort(80)
                      .withNewTargetPort(8080)
                    .endPort()
                    .addToSelector("component", "gerrit")
                    .addToSelector("provider", "fabric8")
                .endSpec()
                .endServiceObject()
                // Second service
                .addNewServiceObject()
                .withNewMetadata()
                  .withName("gerrit-ssh-service")
                  .addToLabels("component", "gerrit")
                  .addToLabels("provider", "fabric8")
                .endMetadata()
                .withNewSpec()
                  .addNewPort()
/*                    .withProtocol("SSH")*/
                    .withPort(29418)
                      .withNewTargetPort(29418)
                    .endPort()
                    .addToSelector("component", "gerrit")
                    .addToSelector("provider", "fabric8")
                .endSpec()
                .endServiceObject()
                .build();
    }
}

Comment line with protocol to avoid this error javax.ws.rs.WebApplicationException: HTTP 422 Service 'gerrit-http-service' is invalid: spec.ports[0].protocol: unsupported value 'HTTP'
Comment line with protocol to avoid this error javax.ws.rs.WebApplicationException: HTTP 422 Service 'gerrit-http-service' is invalid: spec.ports[0].protocol: unsupported value 'HTTP'
