|
| 1 | +package com.github.dockerjava.k8s.command; |
| 2 | + |
| 3 | +import com.github.dockerjava.api.command.VersionCmd; |
| 4 | +import com.github.dockerjava.api.exception.DockerException; |
| 5 | +import io.kubernetes.client.openapi.ApiClient; |
| 6 | +import io.kubernetes.client.openapi.ApiException; |
| 7 | +import io.kubernetes.client.openapi.models.VersionInfo; |
| 8 | +import io.kubernetes.client.util.version.Version; |
| 9 | +import org.apache.commons.lang3.builder.ToStringBuilder; |
| 10 | +import org.apache.commons.lang3.builder.ToStringStyle; |
| 11 | +import org.slf4j.Logger; |
| 12 | +import org.slf4j.LoggerFactory; |
| 13 | + |
| 14 | +import java.io.IOException; |
| 15 | + |
| 16 | +public class VersionCmdImpl implements VersionCmd { |
| 17 | + |
| 18 | + private static final Logger LOGGER = LoggerFactory.getLogger(VersionCmdImpl.class); |
| 19 | + |
| 20 | + private final ApiClient client; |
| 21 | + |
| 22 | + public VersionCmdImpl(final ApiClient client) { |
| 23 | + this.client = client; |
| 24 | + } |
| 25 | + |
| 26 | + @Override |
| 27 | + public com.github.dockerjava.api.model.Version exec() { |
| 28 | + Version k8sVersion = new Version(client); |
| 29 | + VersionInfo info; |
| 30 | + try { |
| 31 | + info = k8sVersion.getVersion(); |
| 32 | + LOGGER.info("Got K8s {}", ToStringBuilder.reflectionToString(info, ToStringStyle.SHORT_PREFIX_STYLE)); |
| 33 | + } catch (ApiException | IOException e) { |
| 34 | + throw new DockerException("Could not get K8s version.", 500, e); |
| 35 | + } |
| 36 | + |
| 37 | + com.github.dockerjava.api.model.Version dockerVersion = new com.github.dockerjava.api.model.Version(); |
| 38 | + return dockerVersion; |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public void close() { |
| 43 | + } |
| 44 | +} |
0 commit comments