Search in sources :

Example 1 with SecretModel

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

the class KnativeSecretHandler method createArtifacts.

@Override
public void createArtifacts() throws KubernetesPluginException {
    // secret
    int count = 0;
    Collection<SecretModel> secretModels = knativeDataHolder.getSecretModelSet();
    if (secretModels.size() > 0) {
        OUT.println();
    }
    for (SecretModel secretModel : secretModels) {
        count++;
        generate(secretModel);
        OUT.print("\t@kubernetes:Secret \t\t\t - complete " + count + "/" + secretModels.size() + "\r");
    }
}
Also used : SecretModel(org.ballerinax.kubernetes.models.knative.SecretModel)

Example 2 with SecretModel

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

the class KnativeServiceHandler method populateVolumeMounts.

private List<VolumeMount> populateVolumeMounts(ServiceModel serviceModel) {
    List<VolumeMount> volumeMounts = new ArrayList<>();
    for (SecretModel secretModel : serviceModel.getSecretModels()) {
        VolumeMount volumeMount = new VolumeMountBuilder().withMountPath(secretModel.getMountPath()).withName(secretModel.getName() + VOLUME_DEFINE).withReadOnly(secretModel.isReadOnly()).build();
        volumeMounts.add(volumeMount);
    }
    for (ConfigMapModel configMapModel : serviceModel.getConfigMapModels()) {
        VolumeMount volumeMount = new VolumeMountBuilder().withMountPath(configMapModel.getMountPath()).withName(configMapModel.getName() + VOLUME_DEFINE).withReadOnly(configMapModel.isReadOnly()).build();
        volumeMounts.add(volumeMount);
    }
    return volumeMounts;
}
Also used : ConfigMapModel(org.ballerinax.kubernetes.models.knative.ConfigMapModel) ArrayList(java.util.ArrayList) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) SecretModel(org.ballerinax.kubernetes.models.knative.SecretModel) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder)

Example 3 with SecretModel

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

the class KnativeSecretAnnotationProcesser method processSecret.

private void processSecret(IdentifierNode nodeID, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    Set<SecretModel> secrets = new HashSet<>();
    List<BLangRecordLiteral.BLangRecordKeyValueField> keyValues = convertRecordFields(((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getFields());
    for (BLangRecordLiteral.BLangRecordKeyValueField keyValue : keyValues) {
        List<BLangExpression> secretAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
        for (BLangExpression bLangExpression : secretAnnotation) {
            SecretModel secretModel = new SecretModel();
            List<BLangRecordLiteral.BLangRecordKeyValueField> annotationValues = convertRecordFields(((BLangRecordLiteral) bLangExpression).getFields());
            for (BLangRecordLiteral.BLangRecordKeyValueField annotation : annotationValues) {
                SecretMountConfig secretMountConfig = SecretMountConfig.valueOf(annotation.getKey().toString());
                switch(secretMountConfig) {
                    case name:
                        secretModel.setName(getValidName(getStringValue(annotation.getValue())));
                        break;
                    case labels:
                        secretModel.setLabels(getMap(keyValue.getValue()));
                        break;
                    case annotations:
                        secretModel.setAnnotations(getMap(keyValue.getValue()));
                        break;
                    case mountPath:
                        secretModel.setMountPath(getStringValue(annotation.getValue()));
                        break;
                    case data:
                        List<BLangExpression> data = ((BLangListConstructorExpr) annotation.valueExpr).exprs;
                        secretModel.setData(getDataForSecret(data));
                        break;
                    case readOnly:
                        secretModel.setReadOnly(getBooleanValue(annotation.getValue()));
                        break;
                    default:
                        break;
                }
            }
            if (isBlank(secretModel.getName())) {
                secretModel.setName(getValidName(nodeID.getValue()) + SECRET_POSTFIX);
            }
            secrets.add(secretModel);
        }
    }
    KnativeContext.getInstance().getDataHolder().addSecrets(secrets);
}
Also used : BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) SecretModel(org.ballerinax.kubernetes.models.knative.SecretModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Example 4 with SecretModel

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

the class KnativeServiceHandler method populateVolume.

private List<Volume> populateVolume(ServiceModel serviceModel) {
    List<Volume> volumes = new ArrayList<>();
    for (SecretModel secretModel : serviceModel.getSecretModels()) {
        Volume volume = new VolumeBuilder().withName(secretModel.getName() + VOLUME_DEFINE).withNewSecret().withSecretName(secretModel.getName()).endSecret().build();
        volumes.add(volume);
    }
    for (ConfigMapModel configMapModel : serviceModel.getConfigMapModels()) {
        Volume volume = new VolumeBuilder().withName(configMapModel.getName() + VOLUME_DEFINE).withNewConfigMap().withName(configMapModel.getName()).endConfigMap().build();
        volumes.add(volume);
    }
    return volumes;
}
Also used : ConfigMapModel(org.ballerinax.kubernetes.models.knative.ConfigMapModel) Volume(io.fabric8.kubernetes.api.model.Volume) ArrayList(java.util.ArrayList) SecretModel(org.ballerinax.kubernetes.models.knative.SecretModel) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder)

Aggregations

SecretModel (org.ballerinax.kubernetes.models.knative.SecretModel)4 ArrayList (java.util.ArrayList)2 ConfigMapModel (org.ballerinax.kubernetes.models.knative.ConfigMapModel)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 HashSet (java.util.HashSet)1 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)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