Skip to content

Commit 489aa09

Browse files
committed
fix: getKubernetesVersion works in Kubernetes v1.33.0
Signed-off-by: Marc Nuri <[email protected]>
1 parent 620b779 commit 489aa09

File tree

4 files changed

+110
-93
lines changed

4 files changed

+110
-93
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* Fix #6930: Add support for Boolean enums in the java-generator
1414
* Fix #6941: HasMetadata.getApiVersion no slash when empty group
1515
* Fix #6982: (java-generator) Double default field values with `d` suffix
16-
* FIX #6987: Kube API Test startup fails on readiness SSL check
16+
* Fix #6987: Kube API Test startup fails on readiness SSL check
17+
* Fix #7037: getKubernetesVersion works in Kubernetes v1.33.0
1718

1819
#### Improvements
1920
* Fix #6763: (crd-generator) YAML output customization

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

+93-74
Original file line numberDiff line numberDiff line change
@@ -15,144 +15,163 @@
1515
*/
1616
package io.fabric8.kubernetes.client;
1717

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

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

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

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

8549
private VersionInfo() {
8650
}
8751

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

9167
public Builder() {
9268
}
9369

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

10888
public Builder withBuildDate(String buildDate) throws ParseException {
10989
if (buildDate != null) {
110-
this.versionInfo.buildDate = new SimpleDateFormat(VersionKeys.BUILD_DATE_FORMAT).parse(buildDate);
90+
this.buildDate = new SimpleDateFormat(VersionKeys.BUILD_DATE_FORMAT).parse(buildDate);
11191
}
11292
return this;
11393
}
11494

115-
public Builder withGitCommit(String gitCommit) {
116-
this.versionInfo.gitCommit = gitCommit;
95+
public Builder withMajor(String major) {
96+
this.major = major;
11797
return this;
11898
}
11999

120-
public Builder withGitVersion(String gitVersion) {
121-
this.versionInfo.gitVersion = gitVersion;
100+
public Builder withMinor(String minor) {
101+
this.minor = minor;
122102
return this;
123103
}
124104

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

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

135135
public Builder withGitTreeState(String gitTreeState) {
136-
this.versionInfo.gitTreeState = gitTreeState;
136+
this.gitTreeState = gitTreeState;
137137
return this;
138138
}
139139

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

145145
public Builder withGoVersion(String goVersion) {
146-
this.versionInfo.goVersion = goVersion;
146+
this.goVersion = goVersion;
147147
return this;
148148
}
149149

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

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

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

-11
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;
@@ -37,7 +36,6 @@
3736
import java.util.Queue;
3837

3938
import static org.assertj.core.api.Assertions.assertThat;
40-
import static org.junit.jupiter.api.Assertions.assertThrows;
4139

4240
class MixedCrudTest {
4341

@@ -58,15 +56,6 @@ void tearDown() {
5856
server.destroy();
5957
}
6058

61-
@Test
62-
@DisplayName("client.getKubernetesVersion, with no expectations, should throw Exception")
63-
void versionWithNoExpectationsShouldFail() {
64-
// When
65-
final RuntimeException exception = assertThrows(RuntimeException.class, client::getKubernetesVersion);
66-
// Then
67-
assertThat(exception).isNotNull().isInstanceOf(KubernetesClientException.class);
68-
}
69-
7059
@Test
7160
@DisplayName("client.getKubernetesVersion, with expectation for version, should return version")
7261
void versionWithExpectationsShouldReturnVersion() {

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

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

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

6169
@Test

0 commit comments

Comments
 (0)