use of org.apache.flink.kubernetes.operator.validation.FlinkResourceValidator in project flink-kubernetes-operator by apache.
the class FlinkValidator method validateSessionJob.
private void validateSessionJob(KubernetesResource resource) {
FlinkSessionJob sessionJob = objectMapper.convertValue(resource, FlinkSessionJob.class);
var namespace = sessionJob.getMetadata().getNamespace();
var deploymentName = sessionJob.getSpec().getDeploymentName();
var key = Cache.namespaceKeyFunc(namespace, deploymentName);
var deployment = informerManager.getFlinkDepInformer(namespace).getStore().getByKey(key);
for (FlinkResourceValidator validator : validators) {
Optional<String> validationError = validator.validateSessionJob(sessionJob, Optional.ofNullable(deployment));
if (validationError.isPresent()) {
throw new NotAllowedException(validationError.get());
}
}
}
use of org.apache.flink.kubernetes.operator.validation.FlinkResourceValidator in project flink-kubernetes-operator by apache.
the class ValidatorUtils method discoverValidators.
public static Set<FlinkResourceValidator> discoverValidators(FlinkConfigManager configManager) {
Set<FlinkResourceValidator> resourceValidators = new HashSet<>();
DefaultValidator defaultValidator = new DefaultValidator(configManager);
defaultValidator.configure(configManager.getDefaultConfig());
resourceValidators.add(defaultValidator);
PluginUtils.createPluginManagerFromRootFolder(configManager.getDefaultConfig()).load(FlinkResourceValidator.class).forEachRemaining(validator -> {
LOG.info("Discovered resource validator from plugin directory[{}]: {}.", System.getenv().getOrDefault(ConfigConstants.ENV_FLINK_PLUGINS_DIR, ConfigConstants.DEFAULT_FLINK_PLUGINS_DIRS), validator.getClass().getName());
validator.configure(configManager.getDefaultConfig());
resourceValidators.add(validator);
});
return resourceValidators;
}
use of org.apache.flink.kubernetes.operator.validation.FlinkResourceValidator in project flink-kubernetes-operator by apache.
the class FlinkOperatorWebhook method main.
public static void main(String[] args) throws Exception {
EnvUtils.logEnvironmentInfo(LOG, "Flink Kubernetes Webhook", args);
FlinkConfigManager configManager = new FlinkConfigManager();
Set<FlinkResourceValidator> validators = ValidatorUtils.discoverValidators(configManager);
AdmissionHandler endpoint = new AdmissionHandler(new FlinkValidator(validators, configManager));
ChannelInitializer<SocketChannel> initializer = createChannelInitializer(endpoint);
NioEventLoopGroup bossGroup = new NioEventLoopGroup(1);
NioEventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(initializer);
Channel serverChannel = bootstrap.bind(getPort()).sync().channel();
InetSocketAddress bindAddress = (InetSocketAddress) serverChannel.localAddress();
InetAddress inetAddress = bindAddress.getAddress();
LOG.info("Webhook listening at {}" + ':' + "{}", inetAddress.getHostAddress(), bindAddress.getPort());
serverChannel.closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
Aggregations