Search in sources :

Example 1 with ServiceAccountTokenModel

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;
}
Also used : ConfigMapModel(org.ballerinax.kubernetes.models.ConfigMapModel) ServiceAccountTokenModel(org.ballerinax.kubernetes.models.ServiceAccountTokenModel) ArrayList(java.util.ArrayList) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) PersistentVolumeClaimModel(org.ballerinax.kubernetes.models.PersistentVolumeClaimModel) SecretModel(org.ballerinax.kubernetes.models.SecretModel) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder)

Example 2 with ServiceAccountTokenModel

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;
}
Also used : ConfigMapModel(org.ballerinax.kubernetes.models.ConfigMapModel) ServiceAccountTokenModel(org.ballerinax.kubernetes.models.ServiceAccountTokenModel) Volume(io.fabric8.kubernetes.api.model.Volume) ArrayList(java.util.ArrayList) PersistentVolumeClaimModel(org.ballerinax.kubernetes.models.PersistentVolumeClaimModel) SecretModel(org.ballerinax.kubernetes.models.SecretModel) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder)

Example 3 with ServiceAccountTokenModel

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;
}
Also used : ServiceAccountTokenModel(org.ballerinax.kubernetes.models.ServiceAccountTokenModel) BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) LinkedList(java.util.LinkedList)

Aggregations

ServiceAccountTokenModel (org.ballerinax.kubernetes.models.ServiceAccountTokenModel)3 ArrayList (java.util.ArrayList)2 ConfigMapModel (org.ballerinax.kubernetes.models.ConfigMapModel)2 PersistentVolumeClaimModel (org.ballerinax.kubernetes.models.PersistentVolumeClaimModel)2 SecretModel (org.ballerinax.kubernetes.models.SecretModel)2 Volume (io.fabric8.kubernetes.api.model.Volume)1 VolumeBuilder (io.fabric8.kubernetes.api.model.VolumeBuilder)1 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)1 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)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