@Override
    public boolean validate(WorkflowContext workflowContext) throws HyscaleException {
        logger.info("Validating Network Policies");
        ServiceSpec serviceSpec = workflowContext.getServiceSpec();
        boolean external = BooleanUtils.toBoolean(serviceSpec.get(HyscaleSpecFields.external, boolean.class));
        List<NetworkTrafficRule> networkTrafficRules = serviceSpec.get(HyscaleSpecFields.allowTraffic, new TypeReference<>() {
        });

        if (external && networkTrafficRules != null) {
            logger.info("External Cannot be True to Apply Network Traffic Rules");
            addErrorMessage(ValidatorActivity.INVALID_EXTERNAL_VALUE);
            WorkflowLogger.persist(ValidatorActivity.INVALID_EXTERNAL_VALUE, LoggerTags.ERROR);
            return false;
        }
        if (external || CollectionUtils.isEmpty(networkTrafficRules)) {
            return true;
        }
        return validateTrafficRules(networkTrafficRules, portsProvider.getExposedPorts(serviceSpec, true));
    }
This class covers different cases
for validity of network traffic rules
before they can be applied.
workflow-controller/controller-service/src/main/java/io/hyscale/controller/validator/impl/NetworkPoliciesValidator.java