Search in sources :

Example 11 with BLangListConstructorExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.

the class KubernetesUtils method getImagePullSecrets.

/**
 * Get Image pull secrets.
 *
 * @param keyValue Value of imagePullSecret field of Job annotation.
 * @return A set of image pull secrets.
 */
public static Set<String> getImagePullSecrets(BLangRecordLiteral.BLangRecordKeyValueField keyValue) throws KubernetesPluginException {
    Set<String> imagePullSecrets = new HashSet<>();
    List<BLangExpression> configAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
    for (BLangExpression bLangExpression : configAnnotation) {
        imagePullSecrets.add(getStringValue(bLangExpression));
    }
    return imagePullSecrets;
}
Also used : BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Example 12 with BLangListConstructorExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.

the class KubernetesUtils method getExternalFileMap.

/**
 * Get the set of external files to copy to docker image.
 *
 * @param keyValue Value of copyFiles field of Job annotation.
 * @return A set of external files
 * @throws KubernetesPluginException if an error occur while getting the paths
 */
public static Set<CopyFileModel> getExternalFileMap(BLangRecordLiteral.BLangRecordKeyValueField keyValue) throws KubernetesPluginException {
    Set<CopyFileModel> externalFiles = new HashSet<>();
    List<BLangExpression> configAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
    for (BLangExpression bLangExpression : configAnnotation) {
        List<BLangRecordLiteral.BLangRecordKeyValueField> annotationValues = convertRecordFields(((BLangRecordLiteral) bLangExpression).getFields());
        CopyFileModel externalFileModel = new CopyFileModel();
        for (BLangRecordLiteral.BLangRecordKeyValueField annotation : annotationValues) {
            switch(annotation.getKey().toString()) {
                case "sourceFile":
                    externalFileModel.setSource(getStringValue(annotation.getValue()));
                    break;
                case "target":
                    externalFileModel.setTarget(getStringValue(annotation.getValue()));
                    break;
                default:
                    break;
            }
        }
        if (isBlank(externalFileModel.getSource())) {
            throw new KubernetesPluginException("@kubernetes:Deployment copyFiles source cannot be empty.");
        }
        if (isBlank(externalFileModel.getTarget())) {
            throw new KubernetesPluginException("@kubernetes:Deployment copyFiles target cannot be empty.");
        }
        externalFiles.add(externalFileModel);
    }
    return externalFiles;
}
Also used : BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) CopyFileModel(org.ballerinax.docker.generator.models.CopyFileModel) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Example 13 with BLangListConstructorExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.

the class DeploymentAnnotationProcessor method parsePodTolerationConfiguration.

/**
 * Parse pod toleration configurations from a record array.
 *
 * @param podTolerationValues Pod toleration configuration records.
 * @return Pod toleration models.
 * @throws KubernetesPluginException When an unknown field is found.
 */
private List<PodTolerationModel> parsePodTolerationConfiguration(BLangExpression podTolerationValues) throws KubernetesPluginException {
    List<PodTolerationModel> podTolerationModels = new LinkedList<>();
    List<BLangExpression> podTolerations = ((BLangListConstructorExpr) podTolerationValues).exprs;
    for (BLangExpression podTolerationFieldsAsExpression : podTolerations) {
        List<BLangRecordLiteral.BLangRecordKeyValueField> podTolerationFields = convertRecordFields(((BLangRecordLiteral) podTolerationFieldsAsExpression).getFields());
        PodTolerationModel podTolerationModel = new PodTolerationModel();
        for (BLangRecordLiteral.BLangRecordKeyValueField podTolerationField : podTolerationFields) {
            PodTolerationConfiguration podTolerationFieldName = PodTolerationConfiguration.valueOf(podTolerationField.getKey().toString());
            switch(podTolerationFieldName) {
                case key:
                    podTolerationModel.setKey(getStringValue(podTolerationField.getValue()));
                    break;
                case operator:
                    podTolerationModel.setOperator(getStringValue(podTolerationField.getValue()));
                    break;
                case value:
                    podTolerationModel.setValue(getStringValue(podTolerationField.getValue()));
                    break;
                case effect:
                    podTolerationModel.setEffect(getStringValue(podTolerationField.getValue()));
                    break;
                case tolerationSeconds:
                    podTolerationModel.setTolerationSeconds(getIntValue(podTolerationField.getValue()));
                    break;
                default:
                    throw new KubernetesPluginException("unknown pod toleration field found: " + podTolerationField.getKey().toString());
            }
        }
        podTolerationModels.add(podTolerationModel);
    }
    return podTolerationModels;
}
Also used : BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) PodTolerationModel(org.ballerinax.kubernetes.models.PodTolerationModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) LinkedList(java.util.LinkedList)

Example 14 with BLangListConstructorExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.

the class DeploymentAnnotationProcessor method parseProjectedVolumeConfiguration.

/**
 * Parse pod toleration configurations from a record array.
 *
 * @param projectedVolumeSources Pod toleration configuration records.
 * @return Pod toleration models.
 * @throws KubernetesPluginException When an unknown field is found.
 */
private List<ServiceAccountTokenModel> parseProjectedVolumeConfiguration(BLangExpression projectedVolumeSources) throws KubernetesPluginException {
    List<ServiceAccountTokenModel> serviceAccountTokenModels = new LinkedList<>();
    List<BLangExpression> sources = ((BLangListConstructorExpr) ((BLangRecordLiteral.BLangRecordKeyValueField) (((BLangRecordLiteral) projectedVolumeSources).getFields()).get(0)).valueExpr).getExpressions();
    for (BLangExpression projectionMountFieldsAsExpression : sources) {
        List<BLangRecordLiteral.BLangRecordKeyValueField> fields = convertRecordFields(((BLangRecordLiteral) projectionMountFieldsAsExpression).getFields());
        ServiceAccountTokenModel serviceAccountTokenModel = new ServiceAccountTokenModel();
        for (BLangRecordLiteral.BLangRecordKeyValueField projectionMountField : fields) {
            ServiceAccountConfig fieldName = ServiceAccountConfig.valueOf(projectionMountField.getKey().toString());
            switch(fieldName) {
                case name:
                    serviceAccountTokenModel.setName(getStringValue(projectionMountField.getValue()));
                    break;
                case mountPath:
                    serviceAccountTokenModel.setMountPath(getStringValue(projectionMountField.getValue()));
                    break;
                case expirationSeconds:
                    serviceAccountTokenModel.setExpirationSeconds(getIntValue(projectionMountField.getValue()));
                    break;
                case audience:
                    serviceAccountTokenModel.setAudience(getStringValue(projectionMountField.getValue()));
                    break;
                default:
                    throw new KubernetesPluginException("unknown pod toleration field found: " + projectionMountField.getKey().toString());
            }
        }
        serviceAccountTokenModels.add(serviceAccountTokenModel);
    }
    return serviceAccountTokenModels;
}
Also used : ServiceAccountTokenModel(org.ballerinax.kubernetes.models.ServiceAccountTokenModel) BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) LinkedList(java.util.LinkedList)

Example 15 with BLangListConstructorExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.

the class KnativeUtils method getImagePullSecrets.

/**
 * Get Image pull secrets.
 *
 * @param keyValue Value of imagePullSecret field of Job annotation.
 * @return A set of image pull secrets.
 */
public static Set<String> getImagePullSecrets(BLangRecordLiteral.BLangRecordKeyValueField keyValue) throws KubernetesPluginException {
    Set<String> imagePullSecrets = new HashSet<>();
    List<BLangExpression> configAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
    for (BLangExpression bLangExpression : configAnnotation) {
        imagePullSecrets.add(getStringValue(bLangExpression));
    }
    return imagePullSecrets;
}
Also used : BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Aggregations

BLangListConstructorExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr)18 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)16 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)15 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)13 HashSet (java.util.HashSet)12 LinkedList (java.util.LinkedList)7 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)5 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)4 Path (java.nio.file.Path)3 CopyFileModel (org.ballerinax.docker.generator.models.CopyFileModel)2 IstioHttpRoute (org.ballerinax.kubernetes.models.istio.IstioHttpRoute)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)1 ConfigMapModel (org.ballerinax.kubernetes.models.ConfigMapModel)1 PersistentVolumeClaimModel (org.ballerinax.kubernetes.models.PersistentVolumeClaimModel)1 PodTolerationModel (org.ballerinax.kubernetes.models.PodTolerationModel)1 ResourceQuotaModel (org.ballerinax.kubernetes.models.ResourceQuotaModel)1 SecretModel (org.ballerinax.kubernetes.models.SecretModel)1 ServiceAccountTokenModel (org.ballerinax.kubernetes.models.ServiceAccountTokenModel)1 IstioDestination (org.ballerinax.kubernetes.models.istio.IstioDestination)1 IstioDestinationWeight (org.ballerinax.kubernetes.models.istio.IstioDestinationWeight)1