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