operator-framework / josdk-spring-boot-starter

Apache License 2.0
39 stars 20 forks source link

Unable to start operator #133

Open stefanbethke opened 7 months ago

stefanbethke commented 7 months ago

With these dependencies:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter:3.2.3'
//    developmentOnly 'org.springframework.boot:spring-boot-devtools:3.2.0'
    implementation 'org.springframework.boot:spring-boot-starter-actuator:3.2.3'
    implementation 'org.springframework.boot:spring-boot-starter-web:3.2.3'
    implementation 'io.javaoperatorsdk:operator-framework-spring-boot-starter:5.4.1'
    implementation 'org.bouncycastle:bcpkix-jdk15on:1.70'
    // required for the fabric8 k8s client to grok k3d certificates
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor:3.2.3'
    compileOnly 'org.projectlombok:lombok'
    testCompileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    annotationProcessor 'io.fabric8:crd-generator-apt:6.10.0'
    testImplementation 'org.springframework.boot:spring-boot-starter-test:3.2.3'
    testImplementation 'io.javaoperatorsdk:operator-framework-spring-boot-starter-test:5.4.1'
}

I'm getting this error on startup:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'coreMediaContentCloudReconciler' defined in com.tsystemsmms.cmcc.cmccoperator.CMCCOperatorApplication: Unsatisfied dependency expressed through method 'coreMediaContentCloudReconciler' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kubernetesClient' defined in class path resource [io/javaoperatorsdk/operator/springboot/starter/OperatorAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.fabric8.kubernetes.client.KubernetesClient]: Factory method 'kubernetesClient' threw exception; nested exception is java.lang.IncompatibleClassChangeError: class io.fabric8.kubernetes.client.okhttp.OkHttpClientImpl overrides final method io.fabric8.kubernetes.client.http.StandardHttpClient.close()V
...
Caused by: java.lang.IncompatibleClassChangeError: class io.fabric8.kubernetes.client.okhttp.OkHttpClientImpl overrides final method io.fabric8.kubernetes.client.http.StandardHttpClient.close()V
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    at io.fabric8.kubernetes.client.okhttp.OkHttpClientBuilderImpl.completeBuild(OkHttpClientBuilderImpl.java:122)
    at io.fabric8.kubernetes.client.okhttp.OkHttpClientBuilderImpl.initialBuild(OkHttpClientBuilderImpl.java:94)
    at io.fabric8.kubernetes.client.okhttp.OkHttpClientBuilderImpl.build(OkHttpClientBuilderImpl.java:55)
    at io.fabric8.kubernetes.client.okhttp.OkHttpClientBuilderImpl.build(OkHttpClientBuilderImpl.java:36)
    at io.fabric8.kubernetes.client.KubernetesClientBuilder.getHttpClient(KubernetesClientBuilder.java:94)
    at io.fabric8.kubernetes.client.KubernetesClientBuilder.build(KubernetesClientBuilder.java:79)
    at io.javaoperatorsdk.operator.springboot.starter.OperatorAutoConfiguration.lambda$kubernetesClient$3(OperatorAutoConfiguration.java:61)

I'm not sure what to do here.

csviri commented 7 months ago

Hi @stefanbethke this seems to be a dependency mismatch, can you compare the version of fabric8 client and OkHttp within this repo and yours?

bullshit commented 7 months ago

@stefanbethke it would be a good idea to use spring dependency-management and spring boot plugin and let them manage the version numbers.

I can give you an example in for gradle with kotlin.

build.gradle.kts

plugins {
  id("org.springframework.boot") version "3.2.3"
  id("io.spring.dependency-management") version "1.1.4"
  kotlin("jvm") version "1.9.22"
  kotlin("plugin.spring") version "1.9.22"
}

dependencies {
  implementation("org.springframework.boot:spring-boot-starter-actuator")
  implementation("org.springframework.boot:spring-boot-starter-web")
  // kotlin dependencies
  implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
  implementation("org.jetbrains.kotlin:kotlin-reflect")

  /* OperatorSDK Spring Boot starter */
  implementation("io.javaoperatorsdk:operator-framework-spring-boot-starter:5.4.1")
  // Generating CustomResourceDefinitions from Java classes
  annotationProcessor("io.fabric8:crd-generator-apt")

  annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
  testImplementation("org.springframework.boot:spring-boot-starter-test")

  // Test OperatorSDK
  testImplementation("io.javaoperatorsdk:operator-framework-spring-boot-starter-test:5.4.1") {
    /* Exclude sample code that gets unnecessary packaged
    fixed with PR https://github.com/operator-framework/josdk-spring-boot-starter/pull/127
    next version will include the fix
    */
    exclude(
        group = "io.javaoperatorsdk",
        module = "operator-framework-spring-boot-starter-samples-common")
  }
}

configurations {
  all {
    /*
        Exclude log4j-slf4j2-impl from io.javaoperatorsdk
        conflicts with spring-boot-starter-logging
    */
    exclude(group = "org.apache.logging.log4j", module = "log4j-slf4j2-impl")
  }
}