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

[4.8.0] HorizontalPodAutoscalers uses wrong endpoint on OpenShift 3.11 #2015

Closed
avano opened this issue Feb 21, 2020 · 6 comments
Closed

[4.8.0] HorizontalPodAutoscalers uses wrong endpoint on OpenShift 3.11 #2015

avano opened this issue Feb 21, 2020 · 6 comments
Assignees

Comments

@avano
Copy link

avano commented Feb 21, 2020

Following code fails with 4.8.0 client version and OpenShift 3.11:

OpenShiftClient c = new DefaultOpenShiftClient(
            new ConfigBuilder().withMasterUrl(<3.11 cluster>)
                .withUsername(<user>)
                .withPassword(<pw>)
                .build()
        );
c.autoscaling().horizontalPodAutoscalers().list()

with:

io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: GET at: <3.11 cluster>/apis/autoscaling/v2beta2/namespaces/<namespace>/horizontalpodautoscalers. Message: the server could not find the requested resource. Received status: Status(apiVersion=v1, code=404, details=StatusDetails(causes=[], group=null, kind=null, name=null, retryAfterSeconds=null, uid=null, additionalProperties={}), kind=Status, message=the server could not find the requested resource, metadata=ListMeta(_continue=null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=NotFound, status=Failure, additionalProperties={}).
	at io.fabric8.kubernetes.client.dsl.base.OperationSupport.requestFailure(OperationSupport.java:568)
	at io.fabric8.kubernetes.client.dsl.base.OperationSupport.assertResponseCode(OperationSupport.java:507)
	at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:471)
	at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:430)
	at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:412)
	at io.fabric8.kubernetes.client.dsl.base.BaseOperation.listRequestHelper(BaseOperation.java:151)
	at io.fabric8.kubernetes.client.dsl.base.BaseOperation.list(BaseOperation.java:608)
	at io.fabric8.kubernetes.client.dsl.base.BaseOperation.list(BaseOperation.java:70)
	at com.test.ClientTest.clientTest(ClientTest.java:19)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

The correct apiVersion should be v1:

 oc get hpa --loglevel 8
I0221 09:23:12.915549    7608 loader.go:359] Config loaded from file /home/avano/.kube/config
I0221 09:23:12.953564    7608 loader.go:359] Config loaded from file /home/avano/.kube/config
I0221 09:23:13.005136    7608 loader.go:359] Config loaded from file /home/avano/.kube/config
I0221 09:23:13.048352    7608 loader.go:359] Config loaded from file /home/avano/.kube/config
I0221 09:23:13.050641    7608 round_trippers.go:416] GET https://<3.11 cluster>/apis/autoscaling/v1/namespaces/<namespace>/horizontalpodautoscalers?limit=500
...

The same code works against 4.3 OpenShift and the issue is not present in 4.7.1 client version

@manusa manusa added the bug label Feb 21, 2020
@manusa manusa self-assigned this Feb 21, 2020
@manusa
Copy link
Member

manusa commented Feb 21, 2020

"Caused" by: #1983

Hi @avano, are you sure this is not happening in v4.7.1 too?

public void testList() {
server.expect().withPath("/apis/autoscaling/v2beta1/namespaces/test/horizontalpodautoscalers").andReturn(200, new HorizontalPodAutoscalerListBuilder().build()).once();
server.expect().withPath("/apis/autoscaling/v2beta1/namespaces/ns1/horizontalpodautoscalers").andReturn(200, new HorizontalPodAutoscalerListBuilder()
.addNewItem().and()
.addNewItem().and()
.build()).once();
KubernetesClient client = server.getClient();
HorizontalPodAutoscalerList horizontalPodAutoscalerList = client.autoscaling().horizontalPodAutoscalers().inNamespace("test").list();
assertNotNull(horizontalPodAutoscalerList);
assertEquals(0, horizontalPodAutoscalerList.getItems().size());
horizontalPodAutoscalerList = client.autoscaling().horizontalPodAutoscalers().inNamespace("ns1").list();
assertNotNull(horizontalPodAutoscalerList);
assertEquals(2, horizontalPodAutoscalerList.getItems().size());
}

@manusa
Copy link
Member

manusa commented Feb 21, 2020

Ok, just checked myself and v4.7.1 is not targeting v1 but v2beta1 which apparently is supported in Open Shift 3.11:

image

@manusa manusa removed the bug label Feb 21, 2020
@avano
Copy link
Author

avano commented Feb 21, 2020

@manusa correct, seems like oc uses v1 apiVersion, executing the request manually against v2beta1 also works, but the 4.8.0 client version uses v2beta2 that doesn't work

@manusa
Copy link
Member

manusa commented Feb 21, 2020

I'll check with the team if we want to provide backwards compatibility for this one.

It may be feasable as v2 is still beta so it can make sense to keep compatibility with V1.
We've also added some improvements to the model generator that can make something like oc.autoscalingV1() possible.

@rohanKanojia
Copy link
Member

@manusa
Copy link
Member

manusa commented Feb 24, 2020

I don't like very much that interceptor.

It assumes that beta versions of existing APIs are backwards-compatible which in many cases won't be true.

IMHO it's better if main entry-points always target the stable API version and have extra entry-points to target beta or alpha versions of the API. This way users requesting access to new features can opt-in by invoking for example oc.autoscalingBeta() while other users can remain calm because the client will remain compatible and no code changes will be required (until a new major version is released).

This would enable us to target different API versions with the same KubernetesClient version, making upgrades for projects depending on FKC much easier and possible.

I can submit a PR with my proposal so the team can evaluate its feasibility.

@manusa manusa removed their assignment Apr 22, 2020
@rohanKanojia rohanKanojia self-assigned this Apr 28, 2020
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Apr 28, 2020
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Apr 28, 2020
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Apr 28, 2020
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants