-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
question: use kubectl with KubernetesServer mock #1601
Comments
This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions! |
Not stale. |
This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions! |
@palmerabollo : have you figured this out yet? I think you're right you can use it like done here: kubernetes-client/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodCrudTest.java Line 37 in 38dc6e3
|
@rohanKanojia I wasn't able to make it work back in June, but I'll double-check it as soon as I can (after Xmas) with the example you provide. Thanks for your help. |
I see there is a lot of potential in this feature and that it can be very useful if MockServer mocks could be configured by using JSON/YAML files and distributed as a binary. This way, the MockServer could be used for different technologies (JavaScript, Go, Python...) For the scope of this issue it would be nice to actually test if running the server standalone is possible and creating a documented quick start/example on how to achieve this to test a couple of |
@rohanKanojia I've tried it. The code below works. However, I'm still not able to access the server using kubectl or any other k8s client because afaik it's not possible to get a valid kubeconfig. As @manusa pointed out, I wanted to access the k8s mock server from client that uses a different technology. import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodBuilder;
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import java.io.IOException;
public class KubernetesMock {
public static void main(String[] args) throws IOException {
KubernetesServer server = new KubernetesServer(true, true);
server.before(); // mock init
KubernetesClient client = server.getClient();
Pod pod = new PodBuilder().withNewMetadata().withName("pod").endMetadata().build();
client.pods().inNamespace("ns1").create(pod);
PodList podList = client.pods().inAnyNamespace().list();
System.out.println(podList.getItems().size()); // 1
}
} |
@palmerabollo I was able to access the mockserver using kubectl...you have to configure the kubectl for that.. ^ I made some minor changes for mockserver to listen on on kubectl side
However there's a mismatch in expected responses by kubectl and response returned by mockserver, since kubectl does a lot more than being a client |
With the rise of Test Containers with support for multiple programming languages, and many other alternatives, is this issue still relevant? |
@manusa The issue is that some apps interact with kubernetes apis (api server, etc). So a k8s mock would come in handy to develop unit/component tests without deploying a real k8s cluster. For example, we use k8s locks in a fabric8 app and we find it quite hard to unit test it. |
This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions! |
@rohanKanojia is experimenting with this for a new feature on JKube. Please, @rohanKanojia provide feedback in this issue too with your findings. |
I managed to get For now, I see these problems:
|
This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions! |
I think only the "Kubernetes Aggregated Discovery endpoints" point remains as a problem now, which will be covered by #6220 Once we finish with that maybe we can create some docs explaining how this could be used in a standalone fashion. |
Is it possible to start a
KubernetesServer
mock this way:and then use a standard
kubectl
client to make requests? Thank you for you help.The text was updated successfully, but these errors were encountered: