Search in sources :

Example 1 with PodTolerationModel

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

the class KnativeServiceAnnotationProcessor 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.knative.PodTolerationModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)1 PodTolerationModel (org.ballerinax.kubernetes.models.knative.PodTolerationModel)1 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)1 BLangListConstructorExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr)1 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)1