Skip to content

Commit 44a566a

Browse files
manusadkostyrev
authored andcommitted
fix: getKubernetesVersion works in Kubernetes v1.33.0
Signed-off-by: Marc Nuri <marc@marcnuri.com> # Conflicts: # CHANGELOG.md
1 parent 9101a2f commit 44a566a

3 files changed

Lines changed: 108 additions & 92 deletions

File tree

kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/VersionInfo.java

Lines changed: 93 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -16,144 +16,163 @@
1616

1717
package io.fabric8.kubernetes.client;
1818

19+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
20+
import lombok.Getter;
21+
1922
import java.text.ParseException;
2023
import java.text.SimpleDateFormat;
2124
import java.util.Date;
2225

26+
@JsonIgnoreProperties(ignoreUnknown = true)
27+
@Getter
2328
public class VersionInfo {
2429
public static final class VersionKeys {
2530
private VersionKeys() {
2631
}
2732

28-
public static final String BUILD_DATE = "buildDate";
29-
public static final String GIT_COMMIT = "gitCommit";
30-
public static final String GIT_VERSION = "gitVersion";
31-
public static final String MAJOR = "major";
32-
public static final String MINOR = "minor";
33-
public static final String GIT_TREE_STATE = "gitTreeState";
34-
public static final String PLATFORM = "platform";
35-
public static final String GO_VERSION = "goVersion";
36-
public static final String COMPILER = "compiler";
3733
public static final String BUILD_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssX";
3834
}
3935

40-
private Date buildDate;
41-
private String gitCommit;
42-
private String gitVersion;
4336
private String major;
4437
private String minor;
38+
private Integer emulationMajor;
39+
private Integer emulationMinor;
40+
private Integer minCompatibilityMajor;
41+
private Integer minCompatibilityMinor;
42+
private String gitCommit;
43+
private String gitVersion;
4544
private String gitTreeState;
46-
private String platform;
45+
private Date buildDate;
4746
private String goVersion;
4847
private String compiler;
49-
50-
public Date getBuildDate() {
51-
return buildDate;
52-
}
53-
54-
public String getGitCommit() {
55-
return gitCommit;
56-
}
57-
58-
public String getGitVersion() {
59-
return gitVersion;
60-
}
61-
62-
public String getMajor() {
63-
return major;
64-
}
65-
66-
public String getMinor() {
67-
return minor;
68-
}
69-
70-
public String getGitTreeState() {
71-
return gitTreeState;
72-
}
73-
74-
public String getPlatform() {
75-
return platform;
76-
}
77-
78-
public String getGoVersion() {
79-
return goVersion;
80-
}
81-
82-
public String getCompiler() {
83-
return compiler;
84-
}
48+
private String platform;
8549

8650
private VersionInfo() {
8751
}
8852

89-
public static class Builder {
90-
private VersionInfo versionInfo = new VersionInfo();
53+
public static final class Builder {
54+
private String major;
55+
private String minor;
56+
private Integer emulationMajor;
57+
private Integer emulationMinor;
58+
private Integer minCompatibilityMajor;
59+
private Integer minCompatibilityMinor;
60+
private String gitCommit;
61+
private String gitVersion;
62+
private String gitTreeState;
63+
private Date buildDate;
64+
private String goVersion;
65+
private String compiler;
66+
private String platform;
9167

9268
public Builder() {
9369
}
9470

9571
public Builder(VersionInfo versionInfo) {
9672
if (versionInfo != null) {
97-
this.versionInfo.buildDate = versionInfo.getBuildDate();
98-
this.versionInfo.gitCommit = versionInfo.getGitCommit();
99-
this.versionInfo.gitVersion = versionInfo.getGitVersion();
100-
this.versionInfo.major = versionInfo.getMajor();
101-
this.versionInfo.minor = versionInfo.getMinor();
102-
this.versionInfo.gitTreeState = versionInfo.getGitTreeState();
103-
this.versionInfo.platform = versionInfo.getPlatform();
104-
this.versionInfo.goVersion = versionInfo.getGoVersion();
105-
this.versionInfo.compiler = versionInfo.getCompiler();
73+
this.major = versionInfo.getMajor();
74+
this.minor = versionInfo.getMinor();
75+
this.emulationMajor = versionInfo.getEmulationMajor();
76+
this.emulationMinor = versionInfo.getEmulationMinor();
77+
this.minCompatibilityMajor = versionInfo.getMinCompatibilityMajor();
78+
this.minCompatibilityMinor = versionInfo.getMinCompatibilityMinor();
79+
this.gitCommit = versionInfo.getGitCommit();
80+
this.gitVersion = versionInfo.getGitVersion();
81+
this.gitTreeState = versionInfo.getGitTreeState();
82+
this.buildDate = versionInfo.getBuildDate();
83+
this.goVersion = versionInfo.getGoVersion();
84+
this.compiler = versionInfo.getCompiler();
85+
this.platform = versionInfo.getPlatform();
10686
}
10787
}
10888

10989
public Builder withBuildDate(String buildDate) throws ParseException {
11090
if (buildDate != null) {
111-
this.versionInfo.buildDate = new SimpleDateFormat(VersionKeys.BUILD_DATE_FORMAT).parse(buildDate);
91+
this.buildDate = new SimpleDateFormat(VersionKeys.BUILD_DATE_FORMAT).parse(buildDate);
11292
}
11393
return this;
11494
}
11595

116-
public Builder withGitCommit(String gitCommit) {
117-
this.versionInfo.gitCommit = gitCommit;
96+
public Builder withMajor(String major) {
97+
this.major = major;
11898
return this;
11999
}
120100

121-
public Builder withGitVersion(String gitVersion) {
122-
this.versionInfo.gitVersion = gitVersion;
101+
public Builder withMinor(String minor) {
102+
this.minor = minor;
123103
return this;
124104
}
125105

126-
public Builder withMajor(String major) {
127-
this.versionInfo.major = major;
106+
public Builder withEmulationMajor(Integer emulationMajor) {
107+
this.emulationMajor = emulationMajor;
128108
return this;
129109
}
130110

131-
public Builder withMinor(String minor) {
132-
this.versionInfo.minor = minor;
111+
public Builder withEmulationMinor(Integer emulationMinor) {
112+
this.emulationMinor = emulationMinor;
113+
return this;
114+
}
115+
116+
public Builder withMinCompatibilityMajor(Integer minCompatibilityMajor) {
117+
this.minCompatibilityMajor = minCompatibilityMajor;
118+
return this;
119+
}
120+
121+
public Builder withMinCompatibilityMinor(Integer minCompatibilityMinor) {
122+
this.minCompatibilityMinor = minCompatibilityMinor;
123+
return this;
124+
}
125+
126+
public Builder withGitCommit(String gitCommit) {
127+
this.gitCommit = gitCommit;
128+
return this;
129+
}
130+
131+
public Builder withGitVersion(String gitVersion) {
132+
this.gitVersion = gitVersion;
133133
return this;
134134
}
135135

136136
public Builder withGitTreeState(String gitTreeState) {
137-
this.versionInfo.gitTreeState = gitTreeState;
137+
this.gitTreeState = gitTreeState;
138138
return this;
139139
}
140140

141-
public Builder withPlatform(String platform) {
142-
this.versionInfo.platform = platform;
141+
public Builder withBuildDate(Date buildDate) {
142+
this.buildDate = buildDate;
143143
return this;
144144
}
145145

146146
public Builder withGoVersion(String goVersion) {
147-
this.versionInfo.goVersion = goVersion;
147+
this.goVersion = goVersion;
148148
return this;
149149
}
150150

151151
public Builder withCompiler(String compiler) {
152-
this.versionInfo.compiler = compiler;
152+
this.compiler = compiler;
153+
return this;
154+
}
155+
156+
public Builder withPlatform(String platform) {
157+
this.platform = platform;
153158
return this;
154159
}
155160

156161
public VersionInfo build() {
162+
VersionInfo versionInfo = new VersionInfo();
163+
versionInfo.compiler = this.compiler;
164+
versionInfo.gitCommit = this.gitCommit;
165+
versionInfo.minCompatibilityMajor = this.minCompatibilityMajor;
166+
versionInfo.goVersion = this.goVersion;
167+
versionInfo.platform = this.platform;
168+
versionInfo.gitVersion = this.gitVersion;
169+
versionInfo.major = this.major;
170+
versionInfo.emulationMajor = this.emulationMajor;
171+
versionInfo.emulationMinor = this.emulationMinor;
172+
versionInfo.minor = this.minor;
173+
versionInfo.minCompatibilityMinor = this.minCompatibilityMinor;
174+
versionInfo.gitTreeState = this.gitTreeState;
175+
versionInfo.buildDate = this.buildDate;
157176
return versionInfo;
158177
}
159178
}

kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/MixedCrudTest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import io.fabric8.kubernetes.api.model.Pod;
1919
import io.fabric8.kubernetes.api.model.PodBuilder;
2020
import io.fabric8.kubernetes.client.KubernetesClient;
21-
import io.fabric8.kubernetes.client.KubernetesClientException;
2221
import io.fabric8.kubernetes.client.VersionInfo;
2322
import io.fabric8.kubernetes.client.server.mock.KubernetesMixedDispatcher;
2423
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
@@ -38,7 +37,6 @@
3837
import java.util.Queue;
3938

4039
import static org.assertj.core.api.Assertions.assertThat;
41-
import static org.junit.jupiter.api.Assertions.assertThrows;
4240

4341
class MixedCrudTest {
4442

@@ -63,15 +61,6 @@ void tearDown() {
6361
server.destroy();
6462
}
6563

66-
@Test
67-
@DisplayName("client.getKubernetesVersion, with no expectations, should throw Exception")
68-
void versionWithNoExpectationsShouldFail() {
69-
// When
70-
final RuntimeException exception = assertThrows(RuntimeException.class, client::getKubernetesVersion);
71-
// Then
72-
assertThat(exception).isNotNull().isInstanceOf(KubernetesClientException.class);
73-
}
74-
7564
@Test
7665
@DisplayName("client.getKubernetesVersion, with expectation for version, should return version")
7766
void versionWithExpectationsShouldReturnVersion() {

kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/VersionInfoTest.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,24 @@ void testClusterVersioning() throws ParseException {
4747
" \"gitCommit\": \"e6301f88a8\"," +
4848
" \"gitVersion\": \"v1.6.1+5115d708d7\"," +
4949
" \"major\": \"3\"," +
50-
" \"minor\": \"6\"" +
50+
" \"minor\": \"6\"," +
51+
" \"emulationMajor\": \"1\"," +
52+
" \"emulationMinor\": \"33\"," +
53+
" \"minCompatibilityMajor\": \"1\"," +
54+
" \"minCompatibilityMinor\": \"32\"" +
5155
"}").always();
5256

53-
assertEquals("v1.6.1+5115d708d7", client.getVersion().getGitVersion());
54-
assertEquals("e6301f88a8", client.getVersion().getGitCommit());
55-
assertEquals("3", client.getVersion().getMajor());
56-
assertEquals("6", client.getVersion().getMinor());
57-
assertEquals(118, client.getVersion().getBuildDate().getYear());
57+
assertEquals("v1.6.1+5115d708d7", client.getKubernetesVersion().getGitVersion());
58+
assertEquals("e6301f88a8", client.getKubernetesVersion().getGitCommit());
59+
assertEquals("3", client.getKubernetesVersion().getMajor());
60+
assertEquals("6", client.getKubernetesVersion().getMinor());
61+
assertEquals(1, client.getKubernetesVersion().getEmulationMajor());
62+
assertEquals(33, client.getKubernetesVersion().getEmulationMinor());
63+
assertEquals(1, client.getKubernetesVersion().getMinCompatibilityMajor());
64+
assertEquals(32, client.getKubernetesVersion().getMinCompatibilityMinor());
65+
assertEquals(118, client.getKubernetesVersion().getBuildDate().getYear());
5866
assertEquals(new SimpleDateFormat(VersionInfo.VersionKeys.BUILD_DATE_FORMAT).parse("2018-03-01T14:27:17Z").getTime(),
59-
client.getVersion().getBuildDate().getTime());
67+
client.getKubernetesVersion().getBuildDate().getTime());
6068
}
6169

6270
@Test

0 commit comments

Comments
 (0)