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;
}
Aggregations