use of org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel in project kubernetes by ballerinax.
the class IstioVirtualServiceHandler method createArtifacts.
@Override
public void createArtifacts() throws KubernetesPluginException {
Map<String, IstioVirtualServiceModel> istioVSModels = dataHolder.getIstioVirtualServiceModels();
int size = istioVSModels.size();
if (size > 0) {
OUT.println();
}
int count = 0;
for (Map.Entry<String, IstioVirtualServiceModel> vsModel : istioVSModels.entrySet()) {
count++;
IstioGatewayModel gwModel = KubernetesContext.getInstance().getDataHolder().getIstioGatewayModel(vsModel.getKey());
if ((null == vsModel.getValue().getGateways() || vsModel.getValue().getGateways().size() == 0) && null != gwModel) {
if (null == vsModel.getValue().getGateways()) {
vsModel.getValue().setGateways(new LinkedList<>());
}
if (vsModel.getValue().getGateways().size() == 0) {
vsModel.getValue().getGateways().add(gwModel.getName());
} else if (vsModel.getValue().getHosts().size() == 1 && vsModel.getValue().getHosts().contains("*")) {
throw new KubernetesPluginException("unable to resolve a gateway for '" + vsModel + "' " + "virtual service. Add @istio:Gateway{} annotation" + " to your listener or service, else explicitly state to " + "use the 'mesh' gateway.");
}
}
generate(vsModel.getKey(), vsModel.getValue());
OUT.print("\t@istio:VirtualService \t\t\t - complete " + count + "/" + size + "\r");
}
}
use of org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel in project kubernetes by ballerinax.
the class IstioVirtualServiceAnnotationProcessor method processIstioVSAnnotation.
/**
* Process @istio:VirtualService annotation.
*
* @param vsFields Fields of the virtual service annotation.
* @throws KubernetesPluginException Unable to process annotations.
*/
private IstioVirtualServiceModel processIstioVSAnnotation(List<BLangRecordLiteral.BLangRecordKeyValueField> vsFields) throws KubernetesPluginException {
IstioVirtualServiceModel vsModel = new IstioVirtualServiceModel();
for (BLangRecordLiteral.BLangRecordKeyValueField vsField : vsFields) {
switch(VSConfig.valueOf(vsField.getKey().toString())) {
case name:
vsModel.setName(getValidName(getStringValue(vsField.getValue())));
break;
case labels:
vsModel.setLabels(getMap(vsField.getValue()));
break;
case annotations:
vsModel.setAnnotations(getMap(vsField.getValue()));
break;
case hosts:
vsModel.setHosts(getList(vsField.getValue()));
break;
case gateways:
vsModel.setGateways(getList(vsField.getValue()));
break;
case http:
BLangListConstructorExpr httpFields = (BLangListConstructorExpr) vsField.getValue();
List<IstioHttpRoute> httpModels = processHttpAnnotation(httpFields);
vsModel.setHttp(httpModels);
break;
default:
throw new KubernetesPluginException("unknown field found for istio virtual service: " + vsField.getKey().toString());
}
}
return vsModel;
}
use of org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel in project kubernetes by ballerinax.
the class IstioVirtualServiceAnnotationProcessor method processAnnotation.
@Override
public void processAnnotation(SimpleVariableNode variableNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
List<BLangRecordLiteral.BLangRecordKeyValueField> keyValues = convertRecordFields(((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getFields());
IstioVirtualServiceModel vsModel = this.processIstioVSAnnotation(keyValues);
if (isBlank(vsModel.getName())) {
vsModel.setName(getValidName(variableNode.getName().getValue()) + ISTIO_VIRTUAL_SERVICE_POSTFIX);
}
setDefaultValues(vsModel);
KubernetesContext.getInstance().getDataHolder().addIstioVirtualServiceModel(variableNode.getName().getValue(), vsModel);
}
use of org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel in project kubernetes by ballerinax.
the class IstioVirtualServiceAnnotationProcessor method processAnnotation.
@Override
public void processAnnotation(ServiceNode serviceNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
List<BLangRecordLiteral.BLangRecordKeyValueField> keyValues = convertRecordFields(((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getFields());
IstioVirtualServiceModel vsModel = this.processIstioVSAnnotation(keyValues);
if (isBlank(vsModel.getName())) {
vsModel.setName(getValidName(serviceNode.getName().getValue()) + ISTIO_VIRTUAL_SERVICE_POSTFIX);
}
setDefaultValues(vsModel);
KubernetesContext.getInstance().getDataHolder().addIstioVirtualServiceModel(serviceNode.getName().getValue(), vsModel);
}
Aggregations