use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class ResourceQuotaAnnotationPreprocessor method processResourceQuotaAnnotation.
private void processResourceQuotaAnnotation(BLangAnnotationAttachment attachmentNode) throws KubernetesPluginException {
Set<ResourceQuotaModel> resourceQuotaModels = new HashSet<>();
List<BLangRecordLiteral.BLangRecordKeyValueField> keyValues = convertRecordFields(((BLangRecordLiteral) attachmentNode.expr).getFields());
for (BLangRecordLiteral.BLangRecordKeyValueField keyValue : keyValues) {
List<BLangExpression> secretAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : secretAnnotation) {
ResourceQuotaModel resourceQuotaModel = new ResourceQuotaModel();
List<BLangRecordLiteral.BLangRecordKeyValueField> annotationValues = convertRecordFields(((BLangRecordLiteral) bLangExpression).getFields());
for (BLangRecordLiteral.BLangRecordKeyValueField annotation : annotationValues) {
ResourceQuotaConfig resourceQuotaConfig = ResourceQuotaConfig.valueOf(annotation.getKey().toString());
switch(resourceQuotaConfig) {
case name:
resourceQuotaModel.setName(getValidName(getStringValue(annotation.getValue())));
break;
case labels:
resourceQuotaModel.setLabels(getMap(annotation.getValue()));
break;
case annotations:
resourceQuotaModel.setAnnotations(getMap(annotation.getValue()));
break;
case hard:
resourceQuotaModel.setHard(getMap(annotation.getValue()));
break;
case scopes:
resourceQuotaModel.setScopes(new HashSet<>(getList(annotation.getValue())));
break;
default:
break;
}
}
resourceQuotaModels.add(resourceQuotaModel);
}
}
KubernetesContext.getInstance().getDataHolder().setResourceQuotaModels(resourceQuotaModels);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class IstioGatewayAnnotationProcessor method processIstioGatewayServerAnnotation.
/**
* Process server field of @istio:Gateway annotation.
*
* @param gatewayModel The gateway model.
* @param serversField List of servers of the gateway.
* @throws KubernetesPluginException Unable to process annotation
*/
private void processIstioGatewayServerAnnotation(IstioGatewayModel gatewayModel, BLangListConstructorExpr serversField) throws KubernetesPluginException {
List<IstioServerModel> servers = new LinkedList<>();
for (ExpressionNode serverRecord : serversField.getExpressions()) {
if (serverRecord instanceof BLangRecordLiteral) {
BLangRecordLiteral serverFieldRecord = (BLangRecordLiteral) serverRecord;
IstioServerModel server = new IstioServerModel();
for (BLangRecordLiteral.BLangRecordKeyValueField serverField : convertRecordFields(serverFieldRecord.getFields())) {
switch(ServerConfig.valueOf(serverField.getKey().toString())) {
case port:
BLangRecordLiteral portRecord = (BLangRecordLiteral) serverField.getValue();
processIstioGatewayPortAnnotation(server, convertRecordFields(portRecord.getFields()));
break;
case hosts:
server.setHosts(getList(serverField.getValue()));
break;
case tls:
BLangRecordLiteral tlsRecord = (BLangRecordLiteral) serverField.getValue();
processIstioGatewayTLSAnnotation(server, convertRecordFields(tlsRecord.getFields()));
break;
default:
throw new KubernetesPluginException("unknown field found for istio gateway server.");
}
}
servers.add(server);
}
}
gatewayModel.setServers(servers);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class KnativeConfigMapAnnotationProcessor method processConfigMaps.
private void processConfigMaps(IdentifierNode nodeID, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<ConfigMapModel> configMapModels = new HashSet<>();
List<BLangRecordLiteral.BLangRecordKeyValueField> keyValues = convertRecordFields(((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getFields());
for (BLangRecordLiteral.BLangRecordKeyValueField keyValue : keyValues) {
String key = keyValue.getKey().toString();
switch(key) {
case "configMaps":
List<BLangExpression> configAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : configAnnotation) {
ConfigMapModel configMapModel = new ConfigMapModel();
List<BLangRecordLiteral.BLangRecordKeyValueField> annotationValues = convertRecordFields(((BLangRecordLiteral) bLangExpression).getFields());
for (BLangRecordLiteral.BLangRecordKeyValueField annotation : annotationValues) {
ConfigMapMountConfig volumeMountConfig = ConfigMapMountConfig.valueOf(annotation.getKey().toString());
switch(volumeMountConfig) {
case name:
configMapModel.setName(getValidName(getStringValue(annotation.getValue())));
break;
case labels:
configMapModel.setLabels(getMap(keyValue.getValue()));
break;
case annotations:
configMapModel.setAnnotations(getMap(keyValue.getValue()));
break;
case mountPath:
// validate mount path is not set to ballerina home or ballerina runtime
final Path mountPath = Paths.get(getStringValue(annotation.getValue()));
final Path homePath = Paths.get(BALLERINA_HOME);
final Path runtimePath = Paths.get(BALLERINA_RUNTIME);
final Path confPath = Paths.get(BALLERINA_CONF_MOUNT_PATH);
if (mountPath.equals(homePath)) {
throw new KubernetesPluginException("@kubernetes:ConfigMap{} mount path " + "cannot be ballerina home: " + BALLERINA_HOME);
}
if (mountPath.equals(runtimePath)) {
throw new KubernetesPluginException("@kubernetes:ConfigMap{} mount path " + "cannot be ballerina runtime: " + BALLERINA_RUNTIME);
}
if (mountPath.equals(confPath)) {
throw new KubernetesPluginException("@kubernetes:ConfigMap{} mount path " + "cannot be ballerina conf file mount " + "path: " + BALLERINA_CONF_MOUNT_PATH);
}
configMapModel.setMountPath(getStringValue(annotation.getValue()));
break;
case data:
List<BLangExpression> data = ((BLangListConstructorExpr) annotation.valueExpr).exprs;
configMapModel.setData(getDataForConfigMap(data));
break;
case readOnly:
configMapModel.setReadOnly(getBooleanValue(annotation.getValue()));
break;
default:
break;
}
}
if (isBlank(configMapModel.getName())) {
configMapModel.setName(getValidName(nodeID.getValue()) + CONFIG_MAP_POSTFIX);
}
if (configMapModel.getData() != null && configMapModel.getData().size() > 0) {
configMapModels.add(configMapModel);
}
}
break;
case "conf":
// create a new config map model with ballerina conf and add it to data holder.
configMapModels.add(getBallerinaConfConfigMap(keyValue.getValue().toString(), nodeID.getValue()));
break;
default:
break;
}
}
KnativeContext.getInstance().getDataHolder().addConfigMaps(configMapModels);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class ConfigMapAnnotationProcessor method processConfigMaps.
private void processConfigMaps(IdentifierNode nodeID, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<ConfigMapModel> configMapModels = new HashSet<>();
List<BLangRecordLiteral.BLangRecordKeyValueField> keyValues = convertRecordFields(((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getFields());
for (BLangRecordLiteral.BLangRecordKeyValueField keyValue : keyValues) {
String key = keyValue.getKey().toString();
switch(key) {
case "configMaps":
List<BLangExpression> configAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : configAnnotation) {
ConfigMapModel configMapModel = new ConfigMapModel();
List<BLangRecordLiteral.BLangRecordKeyValueField> annotationValues = convertRecordFields(((BLangRecordLiteral) bLangExpression).getFields());
for (BLangRecordLiteral.BLangRecordKeyValueField annotation : annotationValues) {
ConfigMapMountConfig volumeMountConfig = ConfigMapMountConfig.valueOf(annotation.getKey().toString());
switch(volumeMountConfig) {
case name:
configMapModel.setName(getValidName(getStringValue(annotation.getValue())));
break;
case labels:
configMapModel.setLabels(getMap(keyValue.getValue()));
break;
case annotations:
configMapModel.setAnnotations(getMap(keyValue.getValue()));
break;
case mountPath:
// validate mount path is not set to ballerina home or ballerina runtime
final Path mountPath = Paths.get(getStringValue(annotation.getValue()));
final Path homePath = Paths.get(BALLERINA_HOME);
final Path runtimePath = Paths.get(BALLERINA_RUNTIME);
final Path confPath = Paths.get(BALLERINA_CONF_MOUNT_PATH);
if (mountPath.equals(homePath)) {
throw new KubernetesPluginException("@kubernetes:ConfigMap{} mount path " + "cannot be ballerina home: " + BALLERINA_HOME);
}
if (mountPath.equals(runtimePath)) {
throw new KubernetesPluginException("@kubernetes:ConfigMap{} mount path " + "cannot be ballerina runtime: " + BALLERINA_RUNTIME);
}
if (mountPath.equals(confPath)) {
throw new KubernetesPluginException("@kubernetes:ConfigMap{} mount path " + "cannot be ballerina conf file mount " + "path: " + BALLERINA_CONF_MOUNT_PATH);
}
configMapModel.setMountPath(getStringValue(annotation.getValue()));
break;
case data:
List<BLangExpression> data = ((BLangListConstructorExpr) annotation.valueExpr).exprs;
configMapModel.setData(getDataForConfigMap(data));
break;
case readOnly:
configMapModel.setReadOnly(getBooleanValue(annotation.getValue()));
break;
case defaultMode:
configMapModel.setDefaultMode(getIntValue(annotation.getValue()));
break;
default:
break;
}
}
if (isBlank(configMapModel.getName())) {
configMapModel.setName(getValidName(nodeID.getValue()) + CONFIG_MAP_POSTFIX);
}
if (configMapModel.getData() != null && configMapModel.getData().size() > 0) {
configMapModels.add(configMapModel);
}
}
break;
case "conf":
// create a new config map model with ballerina conf and add it to data holder.
configMapModels.add(getBallerinaConfConfigMap(keyValue.getValue().toString(), nodeID.getValue()));
break;
default:
break;
}
}
KubernetesContext.getInstance().getDataHolder().addConfigMaps(configMapModels);
}
use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.
the class SecretAnnotationProcessor method processSecret.
private void processSecret(IdentifierNode nodeID, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
Set<SecretModel> secrets = new HashSet<>();
List<BLangRecordLiteral.BLangRecordKeyValueField> keyValues = convertRecordFields(((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getFields());
for (BLangRecordLiteral.BLangRecordKeyValueField keyValue : keyValues) {
String key = keyValue.getKey().toString();
switch(key) {
case "secrets":
List<BLangExpression> configAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
for (BLangExpression bLangExpression : configAnnotation) {
SecretModel secretModel = new SecretModel();
List<BLangRecordLiteral.BLangRecordKeyValueField> annotationValues = convertRecordFields(((BLangRecordLiteral) bLangExpression).getFields());
for (BLangRecordLiteral.BLangRecordKeyValueField annotation : annotationValues) {
SecretMountConfig volumeMountConfig = SecretMountConfig.valueOf(annotation.getKey().toString());
switch(volumeMountConfig) {
case name:
secretModel.setName(getValidName(getStringValue(annotation.getValue())));
break;
case labels:
secretModel.setLabels(getMap(keyValue.getValue()));
break;
case annotations:
secretModel.setAnnotations(getMap(keyValue.getValue()));
break;
case mountPath:
// validate mount path is not set to ballerina home or ballerina runtime
final Path mountPath = Paths.get(getStringValue(annotation.getValue()));
final Path homePath = Paths.get(BALLERINA_HOME);
final Path runtimePath = Paths.get(BALLERINA_RUNTIME);
final Path confPath = Paths.get(BALLERINA_CONF_MOUNT_PATH);
if (mountPath.equals(homePath)) {
throw new KubernetesPluginException("@kubernetes:Secret{} mount path " + "cannot be ballerina home: " + BALLERINA_HOME);
}
if (mountPath.equals(runtimePath)) {
throw new KubernetesPluginException("@kubernetes:Secret{} mount path " + "cannot be ballerina runtime: " + BALLERINA_RUNTIME);
}
if (mountPath.equals(confPath)) {
throw new KubernetesPluginException("@kubernetes:Secret{} mount path " + "cannot be ballerina conf file mount " + "path: " + BALLERINA_CONF_MOUNT_PATH);
}
secretModel.setMountPath(getStringValue(annotation.getValue()));
break;
case data:
List<BLangExpression> data = ((BLangListConstructorExpr) annotation.valueExpr).exprs;
secretModel.setData(getDataForSecret(data));
break;
case readOnly:
secretModel.setReadOnly(getBooleanValue(annotation.getValue()));
break;
case defaultMode:
secretModel.setDefaultMode(getIntValue(annotation.getValue()));
break;
default:
break;
}
}
if (isBlank(secretModel.getName())) {
secretModel.setName(getValidName(nodeID.getValue()) + SECRET_POSTFIX);
}
if (secretModel.getData() != null && secretModel.getData().size() > 0) {
secrets.add(secretModel);
}
}
break;
case "conf":
// create a new secret model with ballerina conf and add it to data holder.
secrets.add(getBallerinaConfSecret(keyValue.getValue().toString(), nodeID.getValue()));
break;
default:
break;
}
}
KubernetesContext.getInstance().getDataHolder().addSecrets(secrets);
}
Aggregations