Search in sources :

Example 6 with ServiceModel

use of org.ballerinax.kubernetes.models.knative.ServiceModel in project kubernetes by ballerinax.

the class KnativeServiceHandler method createArtifacts.

@Override
public void createArtifacts() throws KubernetesPluginException {
    try {
        ServiceModel serviceModel = knativeDataHolder.getServiceModel();
        serviceModel.setPodAutoscalerModel(knativeDataHolder.getPodAutoscalerModel());
        serviceModel.setSecretModels(knativeDataHolder.getSecretModelSet());
        serviceModel.setConfigMapModels(knativeDataHolder.getConfigMapModelSet());
        if (null != serviceModel.getLivenessProbe() && serviceModel.getLivenessProbe().getPort() == 0) {
            // set first port as liveness port
            serviceModel.getLivenessProbe().setPort(serviceModel.getPorts().iterator().next());
        }
        if (null != serviceModel.getReadinessProbe() && serviceModel.getReadinessProbe().getPort() == 0) {
            // set first port as readiness port
            serviceModel.getReadinessProbe().setPort(serviceModel.getPorts().iterator().next());
        }
        generate(serviceModel);
        OUT.println();
        OUT.print("\t@knative:Service \t\t\t - complete 1/1");
        knativeDataHolder.setDockerModel(getDockerModel(serviceModel));
    } catch (DockerGenException e) {
        throw new KubernetesPluginException("error occurred creating docker image.", e);
    }
}
Also used : DockerGenException(org.ballerinax.docker.generator.exceptions.DockerGenException) ServiceModel(org.ballerinax.kubernetes.models.knative.ServiceModel) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException)

Example 7 with ServiceModel

use of org.ballerinax.kubernetes.models.knative.ServiceModel in project kubernetes by ballerinax.

the class KnativeServiceAnnotationProcessor method processAnnotation.

@Override
public void processAnnotation(SimpleVariableNode variableNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    ServiceModel serviceModel = processService(attachmentNode);
    if (KnativeUtils.isBlank(serviceModel.getName())) {
        serviceModel.setName(KnativeUtils.getValidName(variableNode.getName().getValue()) + KNATIVE_SVC_POSTFIX);
    }
    // If service annotation port is not empty, then listener port is used for the k8s svc target port while
    // service annotation port is used for k8s port.
    // If service annotation port is empty, then listener port is used for both port and target port of the k8s
    // svc.
    BLangTypeInit bListener = (BLangTypeInit) ((BLangSimpleVariable) variableNode).expr;
    if (serviceModel.getPort() == 8080) {
        serviceModel.addPort(extractPort(bListener));
    }
}
Also used : BLangTypeInit(org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit) ServiceModel(org.ballerinax.kubernetes.models.knative.ServiceModel)

Aggregations

ServiceModel (org.ballerinax.kubernetes.models.knative.ServiceModel)7 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)3 BLangTypeInit (org.wso2.ballerinalang.compiler.tree.expressions.BLangTypeInit)2 DockerGenException (org.ballerinax.docker.generator.exceptions.DockerGenException)1 ConfigMapModel (org.ballerinax.kubernetes.models.knative.ConfigMapModel)1 EnvVarValueModel (org.ballerinax.kubernetes.models.knative.EnvVarValueModel)1 KnativeContainerModel (org.ballerinax.kubernetes.models.knative.KnativeContainerModel)1 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)1 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)1 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)1 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)1