use of org.ballerinax.kubernetes.models.knative.ServiceModel in project kubernetes by ballerinax.
the class KnativeServiceAnnotationProcessor method processAnnotation.
@Override
public void processAnnotation(ServiceNode serviceNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
BLangService bService = (BLangService) serviceNode;
for (BLangExpression attachedExpr : bService.getAttachedExprs()) {
// If not anonymous endpoint throw error.
if (attachedExpr instanceof BLangSimpleVarRef) {
// throw new KubernetesPluginException("adding @knative:Service{} annotation to a service is only " +
// "supported when the service has an anonymous listener");
ServiceModel serviceModelAttched = processService(attachmentNode);
serviceModelAttched.addPort(serviceModelAttched.getPort());
if (KnativeUtils.isBlank(serviceModelAttched.getName())) {
serviceModelAttched.setName(KnativeUtils.getValidName(serviceNode.getName().getValue()) + KNATIVE_SVC_POSTFIX);
}
return;
}
}
ServiceModel serviceModel = processService(attachmentNode);
if (KnativeUtils.isBlank(serviceModel.getName())) {
serviceModel.setName(KnativeUtils.getValidName(serviceNode.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) bService.getAttachedExprs().get(0);
if (serviceModel.getPort() == 8080) {
if (extractPort(bListener) == 9090 || extractPort(bListener) == 9091 || extractPort(bListener) == 8013 || extractPort(bListener) == 8012) {
throw new KubernetesPluginException("listner port is conflicts with knative port");
}
serviceModel.addPort(extractPort(bListener));
}
}
use of org.ballerinax.kubernetes.models.knative.ServiceModel in project kubernetes by ballerinax.
the class KnativeServiceAnnotationProcessor method processService.
private ServiceModel processService(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
ServiceModel serviceModel = new ServiceModel();
List<BLangRecordLiteral.BLangRecordKeyValueField> keyValues = convertRecordFields(((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getFields());
for (BLangRecordLiteral.BLangRecordKeyValueField keyValue : keyValues) {
ServiceConfiguration serviceConfiguration = ServiceConfiguration.valueOf(keyValue.getKey().toString());
switch(serviceConfiguration) {
case name:
serviceModel.setName(getValidName(getStringValue(keyValue.getValue())));
break;
case labels:
serviceModel.setLabels(getMap(keyValue.getValue()));
break;
case annotations:
serviceModel.setAnnotations(getMap(keyValue.getValue()));
break;
case dockerHost:
serviceModel.setDockerHost(getStringValue(keyValue.getValue()));
break;
case dockerCertPath:
serviceModel.setDockerCertPath(getStringValue(keyValue.getValue()));
break;
case registry:
serviceModel.setRegistry(getStringValue(keyValue.getValue()));
break;
case username:
serviceModel.setUsername(getStringValue(keyValue.getValue()));
break;
case password:
serviceModel.setPassword(getStringValue(keyValue.getValue()));
break;
case baseImage:
serviceModel.setBaseImage(getStringValue(keyValue.getValue()));
break;
case image:
serviceModel.setImage(getStringValue(keyValue.getValue()));
break;
case buildImage:
serviceModel.setBuildImage(getBooleanValue(keyValue.getValue()));
break;
case push:
serviceModel.setPush(getBooleanValue(keyValue.getValue()));
break;
case cmd:
serviceModel.setCmd(getStringValue(keyValue.getValue()));
break;
case copyFiles:
serviceModel.setCopyFiles(getExternalFileMap(keyValue));
break;
case singleYAML:
serviceModel.setSingleYAML(getBooleanValue(keyValue.getValue()));
break;
case namespace:
KnativeContext.getInstance().getDataHolder().setNamespace(getStringValue(keyValue.getValue()));
break;
case replicas:
serviceModel.setReplicas(getIntValue(keyValue.getValue()));
break;
case livenessProbe:
serviceModel.setLivenessProbe(parseProbeConfiguration(keyValue.getValue()));
break;
case readinessProbe:
serviceModel.setReadinessProbe(parseProbeConfiguration(keyValue.getValue()));
break;
case imagePullPolicy:
serviceModel.setImagePullPolicy(getStringValue(keyValue.getValue()));
break;
case env:
serviceModel.setEnv(getEnvVarMap(keyValue.getValue()));
break;
case podAnnotations:
serviceModel.setPodAnnotations(getMap(keyValue.getValue()));
break;
case podTolerations:
serviceModel.setPodTolerations(parsePodTolerationConfiguration(keyValue.getValue()));
break;
case dependsOn:
serviceModel.setDependsOn(getDependsOn(keyValue));
break;
case imagePullSecrets:
serviceModel.setImagePullSecrets(getImagePullSecrets(keyValue));
break;
case containerConcurrency:
serviceModel.setContainerConcurrency(getIntValue(keyValue.getValue()));
break;
case timeoutSeconds:
serviceModel.setTimeoutSeconds(getIntValue(keyValue.getValue()));
break;
case port:
serviceModel.setPort(getIntValue(keyValue.getValue()));
break;
default:
break;
}
}
String dockerHost = System.getenv(DOCKER_HOST);
if (!isBlank(dockerHost)) {
serviceModel.setDockerHost(dockerHost);
}
String dockerCertPath = System.getenv(DOCKER_CERT_PATH);
if (!isBlank(dockerCertPath)) {
serviceModel.setDockerCertPath(dockerCertPath);
}
KnativeContext.getInstance().getDataHolder().setServiceModel(serviceModel);
return serviceModel;
}
use of org.ballerinax.kubernetes.models.knative.ServiceModel in project kubernetes by ballerinax.
the class KnativeArtifactManager method populateDeploymentModel.
public void populateDeploymentModel() {
ServiceModel serviceModel = knativeDataHolder.getServiceModel();
knativeDataHolder.setServiceModel(serviceModel);
String balxFileName = extractJarName(knativeDataHolder.getUberJarPath());
if (isBlank(serviceModel.getName())) {
if (balxFileName != null) {
serviceModel.setName(getValidName(balxFileName) + DEPLOYMENT_POSTFIX);
}
}
if (isBlank(serviceModel.getImage())) {
serviceModel.setImage(balxFileName + DOCKER_LATEST_TAG);
}
serviceModel.addLabel(KubernetesConstants.KUBERNETES_SELECTOR_KEY, balxFileName);
knativeDataHolder.setServiceModel(serviceModel);
}
use of org.ballerinax.kubernetes.models.knative.ServiceModel in project kubernetes by ballerinax.
the class KnativeContainerHandler method createArtifacts.
@Override
public void createArtifacts() throws KubernetesPluginException {
// Service
ServiceModel deploymentModel = knativeDataHolder.getServiceModel();
Map<String, KnativeContainerModel> serviceModels = knativeDataHolder.getbListenerToK8sServiceMap();
int count = 0;
for (KnativeContainerModel serviceModel : serviceModels.values()) {
count++;
String balxFileName = extractJarName(KnativeContext.getInstance().getDataHolder().getUberJarPath());
serviceModel.addLabel(KubernetesConstants.KUBERNETES_SELECTOR_KEY, balxFileName);
serviceModel.setSelector(balxFileName);
generate(serviceModel);
deploymentModel.addPort(serviceModel.getTargetPort());
}
}
use of org.ballerinax.kubernetes.models.knative.ServiceModel in project kubernetes by ballerinax.
the class KnativeConfigMapHandler method createArtifacts.
@Override
public void createArtifacts() throws KubernetesPluginException {
// configMap
int count = 0;
Collection<ConfigMapModel> configMapModels = knativeDataHolder.getConfigMapModelSet();
if (configMapModels.size() > 0) {
OUT.println();
}
for (ConfigMapModel configMapModel : configMapModels) {
count++;
if (!isBlank(configMapModel.getBallerinaConf())) {
if (configMapModel.getData().size() != 1) {
throw new KubernetesPluginException("there can be only 1 ballerina config file");
}
ServiceModel serviceModel = knativeDataHolder.getServiceModel();
serviceModel.setCommandArgs(" --b7a.config.file=${CONFIG_FILE}");
EnvVarValueModel envVarValueModel = new EnvVarValueModel(configMapModel.getMountPath() + BALLERINA_CONF_FILE_NAME);
serviceModel.addEnv("CONFIG_FILE", envVarValueModel);
knativeDataHolder.setServiceModel(serviceModel);
}
generate(configMapModel);
OUT.print("\t@knative:ConfigMap \t\t\t - complete " + count + "/" + configMapModels.size() + "\r");
}
}
Aggregations