Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] jsii/kernel.Fault: Type 'iocilium.CiliumClusterwideNetworkPolicy' not found #2244

Open
neopointer opened this issue Nov 11, 2024 · 1 comment
Labels
bug Something isn't working needs-triage Priority and effort undetermined yet response-requested Awaiting response from author

Comments

@neopointer
Copy link

Description of the bug:

Fail to execute cdk8s after importing CiliumClusterwideNetworkPolicy.

Reproduction Steps:

cdk8s.yaml:

language: java
app:  mvn exec:java -Dexec.mainClass="com.example.Main"
imports:
  - https://raw.githubusercontent.com/cilium/cilium/refs/tags/v1.16.3/pkg/k8s/apis/cilium.io/client/crds/v2/ciliumclusterwidenetworkpolicies.yaml

Create the resource:

new CiliumClusterwideNetworkPolicy(this, "host-policy", CiliumClusterwideNetworkPolicyProps.builder()
        .metadata(ApiObjectMetadata.builder()
                .name("host-policy")
                .build())
        .spec(CiliumClusterwideNetworkPolicySpec.builder()
                .description("lock the cluster down to only what needs to be exposed")
                .nodeSelector(CiliumClusterwideNetworkPolicySpecNodeSelector.builder()
                        // as defined during bootstrap of the node
                        .matchLabels(Map.of("node-access", "ssh"))
                        .build())
                .ingress(List.of(
                        CiliumClusterwideNetworkPolicySpecIngress.builder()
                                .fromEntities(List.of(CiliumClusterwideNetworkPolicySpecIngressFromEntities.CLUSTER))
                                .toPorts(List.of(
                                        CiliumClusterwideNetworkPolicySpecIngressToPorts.builder()
                                                .ports(List.of(
                                                        CiliumClusterwideNetworkPolicySpecIngressToPortsPorts.builder()
                                                                .port("22")
                                                                .protocol(CiliumClusterwideNetworkPolicySpecIngressToPortsPortsProtocol.TCP)
                                                                .build(),
                                                        CiliumClusterwideNetworkPolicySpecIngressToPortsPorts.builder()
                                                                .port("6443")
                                                                .protocol(CiliumClusterwideNetworkPolicySpecIngressToPortsPortsProtocol.TCP)
                                                                .build()
                                                ))
                                                .build()
                                ))
                                .build()
                ))
                .build())
        .build()
);

Run import:

cdk8s import

Then try to run cdk8s:

mvn exec:java -Dexec.mainClass="com.example.Main"

Error Log:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.3.0:java (default-cli) on project kubernetes-bootstrap: An exception occurred while executing the Java class. null: ExceptionInInitializerError: Type 'iocilium.CiliumClusterwideNetworkPolicy' not found
[ERROR] @jsii/kernel.Fault: Type 'iocilium.CiliumClusterwideNetworkPolicy' not found
[ERROR]     at Kernel._Kernel_typeInfoForFqn (/private/var/folders/cd/xn0tnx691gs84m7m7rl41rxm0000gn/T/jsii-java-runtime9495449532649362104/lib/program.js:9377:23)
[ERROR]     at Kernel._Kernel_tryTypeInfoForProperty (/private/var/folders/cd/xn0tnx691gs84m7m7rl41rxm0000gn/T/jsii-java-runtime9495449532649362104/lib/program.js:9428:111)
[ERROR]     at Kernel._Kernel_typeInfoForProperty (/private/var/folders/cd/xn0tnx691gs84m7m7rl41rxm0000gn/T/jsii-java-runtime9495449532649362104/lib/program.js:9456:115)
[ERROR]     at Kernel.sget (/private/var/folders/cd/xn0tnx691gs84m7m7rl41rxm0000gn/T/jsii-java-runtime9495449532649362104/lib/program.js:8810:110)
[ERROR]     at KernelHost.processRequest (/private/var/folders/cd/xn0tnx691gs84m7m7rl41rxm0000gn/T/jsii-java-runtime9495449532649362104/lib/program.js:10715:36)
[ERROR]     at KernelHost.run (/private/var/folders/cd/xn0tnx691gs84m7m7rl41rxm0000gn/T/jsii-java-runtime9495449532649362104/lib/program.js:10675:22)
[ERROR]     at Immediate._onImmediate (/private/var/folders/cd/xn0tnx691gs84m7m7rl41rxm0000gn/T/jsii-java-runtime9495449532649362104/lib/program.js:10676:46)
[ERROR]     at process.processImmediate (node:internal/timers:483:21)
[ERROR] -> [Help 1]

Environment:

  • Framework Version: cdk8s cli 2.198.260
  • OS: MacOS

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>test</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>test</name>
  <url>http://maven.apache.org</url>

  <properties>
    <maven.compiler.source>23</maven.compiler.source>
    <maven.compiler.target>23</maven.compiler.target>
    <cdk8s.version>2.69.11</cdk8s.version>
    <cdk8s-plus.version>2.0.2</cdk8s-plus.version>
  </properties>


  <dependencies>
    <dependency>
      <groupId>org.cdk8s</groupId>
      <artifactId>cdk8s</artifactId>
      <version>${cdk8s.version}</version>
    </dependency>
    <dependency>
      <groupId>org.cdk8s</groupId>
      <artifactId>cdk8s-plus-31</artifactId>
      <version>${cdk8s-plus.version}</version>
    </dependency>
    <dependency>
      <groupId>software.constructs</groupId>
      <artifactId>constructs</artifactId>
      <version>10.4.2</version>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>32.0.1-jre</version>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <testSourceDirectory>src/test/java</testSourceDirectory>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.13.0</version>
        <configuration>
          <enablePreview>true</enablePreview>
          <useIncrementalCompilation>true</useIncrementalCompilation>
          <source>${maven.compiler.source}</source>
          <target>${maven.compiler.target}</target>
        </configuration>
      </plugin>
    </plugins>

  </build>
</project>

Other:


This is 🐛 Bug Report

@neopointer neopointer added bug Something isn't working needs-triage Priority and effort undetermined yet labels Nov 11, 2024
@iliapolo
Copy link
Member

I'm unable to reproduce this. I'm pasting here all the configuration i've used, I believe its the same as yours but maybe you can spot a difference I overlooked.

+ pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>my-app</name>
  <url>http://maven.apache.org</url>

  <properties>
    <maven.compiler.source>23</maven.compiler.source>
    <maven.compiler.target>23</maven.compiler.target>
    <cdk8s.version>2.69.11</cdk8s.version>
    <cdk8s-plus.version>2.0.2</cdk8s-plus.version>    
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.cdk8s</groupId>
      <artifactId>cdk8s</artifactId>
      <version>${cdk8s.version}</version>
    </dependency>
    <dependency>
      <groupId>org.cdk8s</groupId>
      <artifactId>cdk8s-plus-31</artifactId>
      <version>${cdk8s-plus.version}</version>
    </dependency>
    <dependency>
      <groupId>software.constructs</groupId>
      <artifactId>constructs</artifactId>
      <version>10.4.2</version>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>32.0.1-jre</version>
    </dependency>
  </dependencies>

  <build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <testSourceDirectory>src/test/java</testSourceDirectory>

    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.13.0</version>
        <configuration>
          <enablePreview>true</enablePreview>
          <useIncrementalCompilation>true</useIncrementalCompilation>
          <source>${maven.compiler.source}</source>
          <target>${maven.compiler.target}</target>
        </configuration>
      </plugin>
    </plugins>

  </build>
</project>

+ cdk8s.yaml

language: java
app:  mvn exec:java -Dexec.mainClass="com.mycompany.app.Main"
imports:
  - k8s
  - https://raw.githubusercontent.com/cilium/cilium/refs/tags/v1.16.3/pkg/k8s/apis/cilium.io/client/crds/v2/ciliumclusterwidenetworkpolicies.yaml

+ Main.java

package com.mycompany.app;

import software.constructs.Construct;

import java.util.List;
import java.util.Map;

import org.cdk8s.ApiObjectMetadata;
import org.cdk8s.App;
import org.cdk8s.Chart;
import org.cdk8s.ChartProps;

import imports.io.cilium.CiliumClusterwideNetworkPolicy;
import imports.io.cilium.CiliumClusterwideNetworkPolicyProps;
import imports.io.cilium.CiliumClusterwideNetworkPolicySpec;
import imports.io.cilium.CiliumClusterwideNetworkPolicySpecIngress;
import imports.io.cilium.CiliumClusterwideNetworkPolicySpecIngressFromEntities;
import imports.io.cilium.CiliumClusterwideNetworkPolicySpecIngressToPorts;
import imports.io.cilium.CiliumClusterwideNetworkPolicySpecIngressToPortsPorts;
import imports.io.cilium.CiliumClusterwideNetworkPolicySpecIngressToPortsPortsProtocol;
import imports.io.cilium.CiliumClusterwideNetworkPolicySpecNodeSelector;

public class Main extends Chart 
{

    public Main(final Construct scope, final String id) {
        this(scope, id, null);
    }

    public Main(final Construct scope, final String id, final ChartProps options) {
        super(scope, id, options);


        new CiliumClusterwideNetworkPolicy(this, "host-policy", CiliumClusterwideNetworkPolicyProps.builder()
                .metadata(ApiObjectMetadata.builder()
                        .name("host-policy")
                        .build())
                .spec(CiliumClusterwideNetworkPolicySpec.builder()
                        .description("lock the cluster down to only what needs to be exposed")
                        .nodeSelector(CiliumClusterwideNetworkPolicySpecNodeSelector.builder()
                                // as defined during bootstrap of the node
                                .matchLabels(Map.of("node-access", "ssh"))
                                .build())
                        .ingress(List.of(
                                CiliumClusterwideNetworkPolicySpecIngress.builder()
                                        .fromEntities(List.of(CiliumClusterwideNetworkPolicySpecIngressFromEntities.CLUSTER))
                                        .toPorts(List.of(
                                                CiliumClusterwideNetworkPolicySpecIngressToPorts.builder()
                                                        .ports(List.of(
                                                                CiliumClusterwideNetworkPolicySpecIngressToPortsPorts.builder()
                                                                        .port("22")
                                                                        .protocol(CiliumClusterwideNetworkPolicySpecIngressToPortsPortsProtocol.TCP)
                                                                        .build(),
                                                                CiliumClusterwideNetworkPolicySpecIngressToPortsPorts.builder()
                                                                        .port("6443")
                                                                        .protocol(CiliumClusterwideNetworkPolicySpecIngressToPortsPortsProtocol.TCP)
                                                                        .build()
                                                        ))
                                                        .build()
                                        ))
                                        .build()
                        ))
                        .build())
                .build()
        );        

        
        
    }

    public static void main(String[] args) {
        final App app = new App();
        new Main(app, "cdk8s-issue2244");
        app.synth();
    }
}
mvn clean compile && mvn exec:java -Dexec.mainClass="com.mycompany.app.Main"                                                                                                                                                                             [09:15:00]
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< com.mycompany.app:my-app >----------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- clean:3.2.0:clean (default-clean) @ my-app ---
[INFO] Deleting /private/tmp/cdk8s-issue2244/target
[INFO] 
[INFO] --- resources:3.3.0:resources (default-resources) @ my-app ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 4 resources
[INFO] 
[INFO] --- compiler:3.13.0:compile (default-compile) @ my-app ---
[INFO] Recompiling the module because of changed source code.
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 804 source files with javac [debug preview target 23] to target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  17.379 s
[INFO] Finished at: 2024-12-10T09:15:20+02:00
[INFO] ------------------------------------------------------------------------
[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< com.mycompany.app:my-app >----------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- exec:3.1.0:java (default-cli) @ my-app ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.255 s
[INFO] Finished at: 2024-12-10T09:15:28+02:00
[INFO] ------------------------------------------------------------------------
mvn -v                                                                                                                                                                                                                                                   [09:25:32]
Apache Maven 3.9.1 (2e178502fcdbffc201671fb2537d0cb4b4cc58f8)
Maven home: /Users/epolon/dev/runtime/apache-maven-v3.9.1
Java version: 23.0.1, vendor: Oracle Corporation, runtime: /Users/epolon/dev/runtime/jdk-23.0.1.jdk/Contents/Home
Default locale: en_IL, platform encoding: UTF-8
OS name: "mac os x", version: "15.1.1", arch: "x86_64", family: "mac"

It feels like the jsii generated files are somehow corrupted in your case. Are you sure you are running a clean build? Could you paste the contents of the following directory: src/main/resources/imports/io/cilium?

@iliapolo iliapolo added the response-requested Awaiting response from author label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Priority and effort undetermined yet response-requested Awaiting response from author
Projects
None yet
Development

No branches or pull requests

2 participants