Search in sources :

Example 1 with FlinkResourceValidator

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());
        }
    }
}
Also used : NotAllowedException(io.javaoperatorsdk.admissioncontroller.NotAllowedException) FlinkResourceValidator(org.apache.flink.kubernetes.operator.validation.FlinkResourceValidator) FlinkSessionJob(org.apache.flink.kubernetes.operator.crd.FlinkSessionJob)

Example 2 with FlinkResourceValidator

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;
}
Also used : DefaultValidator(org.apache.flink.kubernetes.operator.validation.DefaultValidator) FlinkResourceValidator(org.apache.flink.kubernetes.operator.validation.FlinkResourceValidator) HashSet(java.util.HashSet)

Example 3 with FlinkResourceValidator

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();
    }
}
Also used : NioServerSocketChannel(org.apache.flink.shaded.netty4.io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(org.apache.flink.shaded.netty4.io.netty.channel.socket.SocketChannel) NioServerSocketChannel(org.apache.flink.shaded.netty4.io.netty.channel.socket.nio.NioServerSocketChannel) InetSocketAddress(java.net.InetSocketAddress) NioServerSocketChannel(org.apache.flink.shaded.netty4.io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(org.apache.flink.shaded.netty4.io.netty.channel.socket.SocketChannel) Channel(org.apache.flink.shaded.netty4.io.netty.channel.Channel) FlinkConfigManager(org.apache.flink.kubernetes.operator.config.FlinkConfigManager) FlinkResourceValidator(org.apache.flink.kubernetes.operator.validation.FlinkResourceValidator) ServerBootstrap(org.apache.flink.shaded.netty4.io.netty.bootstrap.ServerBootstrap) InetAddress(java.net.InetAddress) NioEventLoopGroup(org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup)

Aggregations

FlinkResourceValidator (org.apache.flink.kubernetes.operator.validation.FlinkResourceValidator)3 NotAllowedException (io.javaoperatorsdk.admissioncontroller.NotAllowedException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 HashSet (java.util.HashSet)1 FlinkConfigManager (org.apache.flink.kubernetes.operator.config.FlinkConfigManager)1 FlinkSessionJob (org.apache.flink.kubernetes.operator.crd.FlinkSessionJob)1 DefaultValidator (org.apache.flink.kubernetes.operator.validation.DefaultValidator)1 ServerBootstrap (org.apache.flink.shaded.netty4.io.netty.bootstrap.ServerBootstrap)1 Channel (org.apache.flink.shaded.netty4.io.netty.channel.Channel)1 NioEventLoopGroup (org.apache.flink.shaded.netty4.io.netty.channel.nio.NioEventLoopGroup)1 SocketChannel (org.apache.flink.shaded.netty4.io.netty.channel.socket.SocketChannel)1 NioServerSocketChannel (org.apache.flink.shaded.netty4.io.netty.channel.socket.nio.NioServerSocketChannel)1