use of org.ballerinax.kubernetes.models.ServiceAccountTokenModel in project kubernetes by ballerinax.
the class DeploymentHandler method populateVolumeMounts.
private List<VolumeMount> populateVolumeMounts(DeploymentModel deploymentModel) {
List<VolumeMount> volumeMounts = new ArrayList<>();
for (SecretModel secretModel : deploymentModel.getSecretModels()) {
VolumeMount volumeMount = new VolumeMountBuilder().withMountPath(secretModel.getMountPath()).withName(secretModel.getName() + "-volume").withReadOnly(secretModel.isReadOnly()).build();
volumeMounts.add(volumeMount);
}
for (ConfigMapModel configMapModel : deploymentModel.getConfigMapModels()) {
VolumeMount volumeMount = new VolumeMountBuilder().withMountPath(configMapModel.getMountPath()).withName(configMapModel.getName() + "-volume").withReadOnly(configMapModel.isReadOnly()).build();
volumeMounts.add(volumeMount);
}
for (ServiceAccountTokenModel volumeClaimModel : deploymentModel.getServiceAccountTokenModel()) {
VolumeMount volumeMount = new VolumeMountBuilder().withMountPath(volumeClaimModel.getMountPath()).withName(volumeClaimModel.getName() + "-volume").build();
volumeMounts.add(volumeMount);
}
for (PersistentVolumeClaimModel volumeClaimModel : deploymentModel.getVolumeClaimModels()) {
VolumeMount volumeMount = new VolumeMountBuilder().withMountPath(volumeClaimModel.getMountPath()).withName(volumeClaimModel.getName() + "-volume").withReadOnly(volumeClaimModel.isReadOnly()).build();
volumeMounts.add(volumeMount);
}
return volumeMounts;
}
use of org.ballerinax.kubernetes.models.ServiceAccountTokenModel in project kubernetes by ballerinax.
the class DeploymentHandler method populateVolume.
private List<Volume> populateVolume(DeploymentModel deploymentModel) {
List<Volume> volumes = new ArrayList<>();
for (SecretModel secretModel : deploymentModel.getSecretModels()) {
Volume volume = new VolumeBuilder().withName(secretModel.getName() + "-volume").withNewSecret().withSecretName(secretModel.getName()).endSecret().build();
if (secretModel.getDefaultMode() > 0) {
volume.getSecret().setDefaultMode(secretModel.getDefaultMode());
}
volumes.add(volume);
}
for (ConfigMapModel configMapModel : deploymentModel.getConfigMapModels()) {
Volume volume = new VolumeBuilder().withName(configMapModel.getName() + "-volume").withNewConfigMap().withName(configMapModel.getName()).endConfigMap().build();
if (configMapModel.getDefaultMode() > 0) {
volume.getConfigMap().setDefaultMode(configMapModel.getDefaultMode());
}
volumes.add(volume);
}
for (PersistentVolumeClaimModel volumeClaimModel : deploymentModel.getVolumeClaimModels()) {
Volume volume = new VolumeBuilder().withName(volumeClaimModel.getName() + "-volume").withNewPersistentVolumeClaim().withClaimName(volumeClaimModel.getName()).endPersistentVolumeClaim().build();
volumes.add(volume);
}
for (ServiceAccountTokenModel volumeClaimModel : deploymentModel.getServiceAccountTokenModel()) {
Volume volume = new VolumeBuilder().withName(volumeClaimModel.getName() + "-volume").withNewProjected().withSources().addNewSource().withNewServiceAccountToken().withAudience(volumeClaimModel.getAudience()).withPath(volumeClaimModel.getName() + "-volume").withExpirationSeconds((long) volumeClaimModel.getExpirationSeconds()).endServiceAccountToken().endSource().endProjected().build();
volumes.add(volume);
}
return volumes;
}
use of org.ballerinax.kubernetes.models.ServiceAccountTokenModel 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;
}
Aggregations