Search in sources :

Example 6 with SecretModel

use of org.ballerinax.kubernetes.models.SecretModel in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method processSecrets.

/**
 * Process Secrets annotations.
 *
 * @param attachmentNode Attachment Node
 * @return List of @{@link SecretModel} objects
 */
Set<SecretModel> processSecrets(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    Set<SecretModel> secrets = new HashSet<>();
    List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
    for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
        List<BLangExpression> secretAnnotation = ((BLangArrayLiteral) keyValue.valueExpr).exprs;
        for (BLangExpression bLangExpression : secretAnnotation) {
            SecretModel secretModel = new SecretModel();
            List<BLangRecordLiteral.BLangRecordKeyValue> annotationValues = ((BLangRecordLiteral) bLangExpression).getKeyValuePairs();
            for (BLangRecordLiteral.BLangRecordKeyValue annotation : annotationValues) {
                VolumeMountConfig volumeMountConfig = VolumeMountConfig.valueOf(annotation.getKey().toString());
                String annotationValue = resolveValue(annotation.getValue().toString());
                switch(volumeMountConfig) {
                    case name:
                        secretModel.setName(getValidName(annotationValue));
                        break;
                    case mountPath:
                        secretModel.setMountPath(annotationValue);
                        break;
                    case data:
                        List<BLangExpression> data = ((BLangArrayLiteral) annotation.valueExpr).exprs;
                        secretModel.setData(getDataForSecret(data));
                        break;
                    case readOnly:
                        secretModel.setReadOnly(Boolean.parseBoolean(annotationValue));
                        break;
                    default:
                        break;
                }
            }
            secrets.add(secretModel);
        }
    }
    return secrets;
}
Also used : BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral) SecretModel(org.ballerinax.kubernetes.models.SecretModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Aggregations

SecretModel (org.ballerinax.kubernetes.models.SecretModel)6 HashSet (java.util.HashSet)3 ConfigMapModel (org.ballerinax.kubernetes.models.ConfigMapModel)3 PersistentVolumeClaimModel (org.ballerinax.kubernetes.models.PersistentVolumeClaimModel)3 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)2 ServiceModel (org.ballerinax.kubernetes.models.ServiceModel)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 Map (java.util.Map)1 Set (java.util.Set)1 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)1 DeploymentModel (org.ballerinax.kubernetes.models.DeploymentModel)1 IngressModel (org.ballerinax.kubernetes.models.IngressModel)1 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)1 BLangArrayLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral)1