Search in sources :

Example 1 with RollingUpdateDeployment

use of io.fabric8.kubernetes.api.model.apps.RollingUpdateDeployment in project kubernetes by ballerinax.

the class DeploymentAnnotationProcessor method getStrategy.

/**
 * Get Deployment strategy.
 *
 * @param keyValue Value of strategy field of deployment annotation.
 * @return DeploymentStrategy..
 */
private DeploymentStrategy getStrategy(BLangRecordLiteral.BLangRecordKeyValueField keyValue) throws KubernetesPluginException {
    DeploymentStrategy strategy = new DeploymentStrategy();
    if (keyValue.getValue().type.getKind() == TypeKind.STRING) {
        // Rolling Update for Recreate with default values
        strategy.setType((getStringValue(keyValue.getValue())));
        return strategy;
    }
    RollingUpdateDeployment rollingParams = new RollingUpdateDeployment();
    strategy.setType("RollingUpdate");
    for (BLangRecordLiteral.RecordField strategyField : ((BLangRecordLiteral) keyValue.valueExpr).fields) {
        BLangRecordLiteral.BLangRecordKeyValueField strategyKeyValueField = ((BLangRecordLiteral.BLangRecordKeyValueField) strategyField);
        switch(strategyKeyValueField.getKey().toString()) {
            case "maxUnavailable":
                if (strategyKeyValueField.getValue().type.getKind() == TypeKind.INT) {
                    rollingParams.setMaxUnavailable(new IntOrString(getIntValue(strategyKeyValueField.getValue())));
                } else {
                    rollingParams.setMaxUnavailable(new IntOrString(getStringValue(strategyKeyValueField.getValue())));
                }
                break;
            case "maxSurge":
                if (strategyKeyValueField.getValue().type.getKind() == TypeKind.INT) {
                    rollingParams.setMaxSurge(new IntOrString(getIntValue(strategyKeyValueField.getValue())));
                } else {
                    rollingParams.setMaxSurge(new IntOrString(getStringValue(strategyKeyValueField.getValue())));
                }
                break;
            default:
                break;
        }
    }
    strategy.setRollingUpdate(rollingParams);
    return strategy;
}
Also used : RollingUpdateDeployment(io.fabric8.kubernetes.api.model.apps.RollingUpdateDeployment) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) DeploymentStrategy(io.fabric8.kubernetes.api.model.apps.DeploymentStrategy)

Aggregations

IntOrString (io.fabric8.kubernetes.api.model.IntOrString)1 DeploymentStrategy (io.fabric8.kubernetes.api.model.apps.DeploymentStrategy)1 RollingUpdateDeployment (io.fabric8.kubernetes.api.model.apps.RollingUpdateDeployment)1 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)1