Search in sources :

Example 1 with PodTolerationModel

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

the class DeploymentHandler method populatePodTolerations.

private List<Toleration> populatePodTolerations(List<PodTolerationModel> podTolerationModels) {
    List<Toleration> tolerations = null;
    if (null != podTolerationModels && podTolerationModels.size() > 0) {
        tolerations = new LinkedList<>();
        for (PodTolerationModel podTolerationModel : podTolerationModels) {
            Toleration toleration = new TolerationBuilder().withKey(podTolerationModel.getKey()).withOperator(podTolerationModel.getOperator()).withValue(podTolerationModel.getValue()).withEffect(podTolerationModel.getEffect()).withTolerationSeconds((long) podTolerationModel.getTolerationSeconds()).build();
            tolerations.add(toleration);
        }
    }
    return tolerations;
}
Also used : TolerationBuilder(io.fabric8.kubernetes.api.model.TolerationBuilder) Toleration(io.fabric8.kubernetes.api.model.Toleration) PodTolerationModel(org.ballerinax.kubernetes.models.PodTolerationModel)

Example 2 with PodTolerationModel

use of org.ballerinax.kubernetes.models.PodTolerationModel 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)

Aggregations

PodTolerationModel (org.ballerinax.kubernetes.models.PodTolerationModel)2 Toleration (io.fabric8.kubernetes.api.model.Toleration)1 TolerationBuilder (io.fabric8.kubernetes.api.model.TolerationBuilder)1 LinkedList (java.util.LinkedList)1 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)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