question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Kubernetes issue with user permission

See original GitHub issue

Citrus Version 3.3.0

Question Hi, i am trying to test a Kubernetes client.I use the default Fabric8 Kubernetes Client that is supported by Citrus v3.3.0:

@Configuration
public class EndpointConfig {
    @Bean
    public KubernetesClient k8sClient() {
        return new KubernetesClientBuilder()
                .build();
	}		
}	

And these are my tests

public class SampleConnectionToKubernetesIT extends TestNGCitrusSpringSupport {

    @CitrusEndpoint
    private KubernetesClient k8sClient;

    @CitrusResource
    private TestContext context;


    // This works
    @Test(priority = 1, description = "TestInfo")
    @CitrusTest
    public void TestInfo() {
        run(kubernetes().info()
                .validate((info, context) -> Assert.assertEquals(info.getResult().getApiVersion(), "v1")));
    }

 
    // This returns the exception below
    @Test(priority = 2, description = "TestPods")
    @CitrusTest
    public void TestPods() {
        run(kubernetes()
                .client(k8sClient)
                .pods()
                .list()
                .validate("$..status.phase", "Running"));
    }
  
}

The exception for the “TestPods” test is the below:

ERROR LoggingReporter:267 - TEST FAILED SampleConnectionToKubernetesIT.listPodsTest <com.ccneb.ssv> Nested exception is: 
com.consol.citrus.exceptions.TestCaseFailedException: Unable to perform kubernetes command
	at com.consol.citrus.DefaultTestCase.executeAction(DefaultTestCase.java:144)
	at com.consol.citrus.DefaultTestCaseRunner.run(DefaultTestCaseRunner.java:125)
	at com.consol.citrus.testng.spring.TestNGCitrusSpringSupport.run(TestNGCitrusSpringSupport.java:278)
	at com.ccneb.ssv.SampleConnectionToKubernetesIT.listPodsTest(SampleConnectionToKubernetesIT.java:136)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282)
	at com.consol.citrus.testng.TestNGHelper.invokeTestMethod(TestNGHelper.java:113)
	at com.consol.citrus.testng.spring.TestNGCitrusSpringSupport.run(TestNGCitrusSpringSupport.java:166)
	at com.consol.citrus.testng.spring.TestNGCitrusSpringSupport.run(TestNGCitrusSpringSupport.java:90)
	at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:252)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:595)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.testng.TestRunner.privateRun(TestRunner.java:764)
	at org.testng.TestRunner.run(TestRunner.java:585)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
	at org.testng.SuiteRunner.run(SuiteRunner.java:286)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
	at org.testng.TestNG.runSuites(TestNG.java:1069)
	at org.testng.TestNG.run(TestNG.java:1037)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Caused by: com.consol.citrus.exceptions.CitrusRuntimeException: Unable to perform kubernetes command
	at com.consol.citrus.kubernetes.actions.KubernetesExecuteAction.doExecute(KubernetesExecuteAction.java:137)
	at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:58)
	at com.consol.citrus.DefaultTestCase.executeAction(DefaultTestCase.java:137)
	... 34 more
Caused by: io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: GET at: https://myurl/api/v1/pods. Message: Forbidden! User myuser doesn't have permission.
	at io.fabric8.kubernetes.client.dsl.base.OperationSupport.requestFailure(OperationSupport.java:318)
	at io.fabric8.kubernetes.client.dsl.base.OperationSupport.assertResponseCode(OperationSupport.java:265)
	at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:237)
	at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:230)
	at io.fabric8.kubernetes.client.dsl.base.BaseOperation.list(BaseOperation.java:537)
	at io.fabric8.kubernetes.client.dsl.base.BaseOperation.list(BaseOperation.java:65)
	at com.consol.citrus.kubernetes.command.AbstractListCommand.execute(AbstractListCommand.java:40)
	at com.consol.citrus.kubernetes.command.AbstractClientCommand.execute(AbstractClientCommand.java:65)
	at com.consol.citrus.kubernetes.actions.KubernetesExecuteAction.doExecute(KubernetesExecuteAction.java:129)

(myurl and myuser are placeholders)

I saw that the kubernetes client embedded in Citrus is really outdated (v1.4.34) since the official fabric8 kubernetes client now is v6.1.1.

What I’ve tried so far I have tried add explicity the Fabric8 kubernetes client v2.0.6 and higher but the execution does not start at all, since it fails in Citrus beforeSuite method.

This is the exception:

ERROR org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@591f6f83] to prepare test instance [com.ccneb.ssv.SampleConnectionToKubernetesIT@26b894bd]
java.lang.IllegalStateException: Failed to load ApplicationContext
   at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132) ~[spring-test-5.3.6.jar:5.3.6]
   at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124) ~[spring-test-5.3.6.jar:5.3.6]
   at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:118) ~[spring-test-5.3.6.jar:5.3.6]
   at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) ~[spring-test-5.3.6.jar:5.3.6]
   at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:244) [spring-test-5.3.6.jar:5.3.6]
   at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:149) [spring-test-5.3.6.jar:5.3.6]
   at com.consol.citrus.testng.spring.TestNGCitrusSpringSupport.beforeSuite(TestNGCitrusSpringSupport.java:207) [citrus-testng-3.2.1.jar:?]
   at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
   at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
   at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
   at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
   at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132) [testng-7.3.0.jar:?]
   at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:61) [testng-7.3.0.jar:?]
   at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:366) [testng-7.3.0.jar:?]
   at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:320) [testng-7.3.0.jar:?]
   at org.testng.SuiteRunner.privateRun(SuiteRunner.java:327) [testng-7.3.0.jar:?]
   at org.testng.SuiteRunner.run(SuiteRunner.java:286) [testng-7.3.0.jar:?]
   at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53) [testng-7.3.0.jar:?]
   at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96) [testng-7.3.0.jar:?]
   at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218) [testng-7.3.0.jar:?]
   at org.testng.TestNG.runSuitesLocally(TestNG.java:1140) [testng-7.3.0.jar:?]
   at org.testng.TestNG.runSuites(TestNG.java:1069) [testng-7.3.0.jar:?]
   at org.testng.TestNG.run(TestNG.java:1037) [testng-7.3.0.jar:?]
   at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66) [testng-rt.jar:?]
   at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109) [testng-rt.jar:?]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'k8sClient' defined in class path resource [com/ccneb/ssv/EndpointConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.consol.citrus.kubernetes.client.KubernetesClient]: Factory method 'k8sClient' threw exception; nested exception is java.lang.NoSuchMethodError: com.fasterxml.jackson.dataformat.yaml.YAMLFactory._createContentReference(Ljava/lang/Object;)Lcom/fasterxml/jackson/core/io/ContentReference;
   at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.18.jar:5.3.18]
   at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.18.jar:5.3.18]
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.18.jar:5.3.18]
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.18.jar:5.3.18]
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.18.jar:5.3.18]
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.18.jar:5.3.18]
   at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.18.jar:5.3.18]
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.18.jar:5.3.18]
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.18.jar:5.3.18]
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.18.jar:5.3.18]
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.18.jar:5.3.18]
   at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.18.jar:5.3.18]
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.18.jar:5.3.18]
   at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:127) ~[spring-test-5.3.6.jar:5.3.6]
   at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) ~[spring-test-5.3.6.jar:5.3.6]
   at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:275) ~[spring-test-5.3.6.jar:5.3.6]
   at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) ~[spring-test-5.3.6.jar:5.3.6]
   at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) ~[spring-test-5.3.6.jar:5.3.6]
   at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) ~[spring-test-5.3.6.jar:5.3.6]
   ... 24 more

Any ideas how to overcome the issue?

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
christophdcommented, Sep 27, 2022

we really need to update the Kubernetes client library! I am pretty sure that the Kubernetes API has evolved a lot and the client needs to be updated.

0reactions
louposkcommented, Nov 17, 2022

Hi guys, thanks for your time. Please keep us posted for updates.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix permission errors in pods using service accounts
The pod encountered permission errors because a user is running it without sufficient privileges. Log in as a user with the cluster admin...
Read more >
Using RBAC Authorization | Kubernetes
A role binding grants the permissions defined in a role to a user or set of users. It holds a list of subjects...
Read more >
Authorization Overview - Kubernetes
In Kubernetes, you must be authenticated (logged in) before your request can be authorized (granted permission to access).
Read more >
Configure a Security Context for a Pod or Container
Discretionary Access Control : Permission to access an object, like a file, is based on user ID (UID) and group ID (GID).
Read more >
Role Based Access Control Good Practices - Kubernetes
Within Kubernetes RBAC there are a number of privileges which, if granted, can allow a user or a service account to escalate their...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found