import ballerina/http;
import ballerina/log;
import ballerina/kubernetes;
import ballerina/openshift;
@kubernetes:Service {}
@openshift:Route {
host: "www.oc-example.com"
}
listener http:Listener helloEP = new(9090);
@kubernetes:Deployment {
namespace: "hello-api",
registry: "172.30.1.1:5000",
image: "hello-service:v1.0",
buildImage: false,
buildExtension: openshift:BUILD_EXTENSION_OPENSHIFT
}
@http:ServiceConfig {
basePath: "/hello"
}
service hello on helloEP {
@http:ResourceConfig {
methods: ["GET"],
path: "/{user}"
}
resource function sayHello(http:Caller caller, http:Request request, string user) {
string payload = string `Hello ${<@untainted string> user}!`;
var responseResult = caller->respond(payload);
if (responseResult is error) {
error err = responseResult;
log:printError("Error sending response", err);
}
}
}
OpenShift DeploymentBallerina supports generating the OpenShift Route, BuildConfig, and ImageStream artifacts based on annotations.
Docker image of the Ballerina service is built using the BuildConfig, which then can be used by the generated Kubernetes Deployment.
A generated OpenShift Route exposes the Kubernetes Service of the Ballerina Service.
This example deploys an HTTP service, which responses “Hello” followed by a name. |
|
|
|
Add the |
|
Add the |
|
Add the |
|
OpenShift project name. |
|
IP and port of the OpenShift docker registry. If you are using minishift, use the |
|
Generate a Docker image with the name |
|
Disable the image being built by default so that the OpenShift BuildConfig can build it. |
|
Generate the OpenShift BuildConfig for building the Docker image. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|