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