operator-framework / josdk-spring-boot-starter

Apache License 2.0
36 stars 19 forks source link

On startup: java.lang.NoSuchFieldError: readTimeout #80

Closed stefanbethke closed 6 months ago

stefanbethke commented 1 year ago

Bug Report

The Kubernetes connection cannot be created because of an exception when I start my operator.

What did you do?

Using io.javaoperatorsdk:operator-framework-spring-boot-starter:5.1.0 I'm instantiating my Reconciler through the annotation.

What did you expect to see?

My operator starts running.

What did you see instead? Under which circumstances?

14:51:19.800 INFO  c.t.c.c.CMCCOperatorApplication - Starting CMCCOperatorApplication using Java 17.0.7 on XXXX with PID 90946 (/Users/stbe/develop/cmcc-operator/build/classes/java/main started by stbe in /Users/stbe/develop/cmcc-operator)
14:51:19.802 DEBUG c.t.c.c.CMCCOperatorApplication - Running with Spring Boot v2.7.13, Spring v5.3.28
14:51:19.802 INFO  c.t.c.c.CMCCOperatorApplication - The following 1 profile is active: "dev"
14:51:20.300 INFO  o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port(s): 8080 (http)
14:51:20.304 INFO  o.a.catalina.core.StandardService - Starting service [Tomcat]
14:51:20.304 INFO  o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.76]
14:51:20.381 INFO  o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
14:51:20.381 INFO  o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 561 ms
14:51:20.860 WARN  o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: 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.NoSuchFieldError: readTimeout
14:51:20.862 INFO  o.a.catalina.core.StandardService - Stopping service [Tomcat]
14:51:20.870 INFO  o.s.b.a.l.ConditionEvaluationReportLoggingListener - 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
14:51:20.880 ERROR o.s.boot.SpringApplication - Application run failed
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.NoSuchFieldError: readTimeout
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:920)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
    at com.tsystemsmms.cmcc.cmccoperator.CMCCOperatorApplication.main(CMCCOperatorApplication.java:97)
Caused by: 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.NoSuchFieldError: readTimeout
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
    at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
    ... 19 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.fabric8.kubernetes.client.KubernetesClient]: Factory method 'kubernetesClient' threw exception; nested exception is java.lang.NoSuchFieldError: readTimeout
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
    ... 33 common frames omitted
Caused by: java.lang.NoSuchFieldError: readTimeout
    at io.fabric8.kubernetes.client.okhttp.OkHttpClientBuilderImpl.derivedBuild(OkHttpClientBuilderImpl.java:94)
    at io.fabric8.kubernetes.client.okhttp.OkHttpClientBuilderImpl.initialBuild(OkHttpClientBuilderImpl.java:90)
    at io.fabric8.kubernetes.client.okhttp.OkHttpClientBuilderImpl.build(OkHttpClientBuilderImpl.java:52)
    at io.fabric8.kubernetes.client.okhttp.OkHttpClientBuilderImpl.build(OkHttpClientBuilderImpl.java:33)
    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:60)
    at java.base/java.util.Optional.orElseGet(Optional.java:364)
    at io.javaoperatorsdk.operator.springboot.starter.OperatorAutoConfiguration.kubernetesClient(OperatorAutoConfiguration.java:59)
    at io.javaoperatorsdk.operator.springboot.starter.OperatorAutoConfiguration$$EnhancerBySpringCGLIB$$2ec03ae0.CGLIB$kubernetesClient$7(<generated>)
    at io.javaoperatorsdk.operator.springboot.starter.OperatorAutoConfiguration$$EnhancerBySpringCGLIB$$2ec03ae0$$FastClassBySpringCGLIB$$94def8d5.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
    at io.javaoperatorsdk.operator.springboot.starter.OperatorAutoConfiguration$$EnhancerBySpringCGLIB$$2ec03ae0.kubernetesClient(<generated>)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 34 common frames omitted

Environment

n/a

Possible Solution

There seems to be a discrepancy in the version for io.fabric8:kubernetes-httpclient-okhttp. When I force 6.7.1 through gradle, it appears to be working correctly.

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter:3.1.1'
//    developmentOnly 'org.springframework.boot:spring-boot-devtools:3.1.1'
    implementation 'org.springframework.boot:spring-boot-starter-actuator:3.1.1'
    implementation 'org.springframework.boot:spring-boot-starter-web:3.1.1'
    implementation 'io.javaoperatorsdk:operator-framework-spring-boot-starter:5.1.0'
    constraints {
        implementation('io.fabric8:kubernetes-httpclient-okhttp:6.7.1') {
            because 'some internal dependencies seem to be for 6.6.2 which works differently'
        }
    }
    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.1.1'
    compileOnly 'org.projectlombok:lombok'
    testCompileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    annotationProcessor 'io.fabric8:crd-generator-apt:6.5.0'
    testImplementation 'org.springframework.boot:spring-boot-starter-test:3.1.1'
    testImplementation 'io.javaoperatorsdk:operator-framework-spring-boot-starter-test:5.1.0'
}
csviri commented 1 year ago

Hi @stefanbethke , thx for the issue, will take a look when back from holiday ( in 10 days)

csviri commented 1 year ago

Hi @stefanbethke I made a new release, could you maybe try with that? Tbh I did not see any issue in the dependcy tree on our side, will take a look again if does not work for you with the new version.