Skip to content

Commit

Permalink
Apply patches
Browse files Browse the repository at this point in the history
  • Loading branch information
brendandburns committed Oct 10, 2024
1 parent 1b8837b commit 7e7dc60
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
36 changes: 32 additions & 4 deletions kubernetes/src/main/java/io/kubernetes/client/openapi/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import io.gsonfire.GsonFireBuilder;
import io.gsonfire.TypeSelector;

import io.kubernetes.client.gson.V1MetadataExclusionStrategy;
import io.kubernetes.client.gson.V1StatusPreProcessor;
import io.kubernetes.client.openapi.models.V1Status;
import okio.ByteString;

import java.io.IOException;
Expand All @@ -35,6 +38,9 @@
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoField;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
Expand All @@ -50,9 +56,20 @@
public class JSON {
private static Gson gson;
private static boolean isLenientOnJson = false;

private static final DateTimeFormatter RFC3339MICRO_FORMATTER =
new DateTimeFormatterBuilder()
.parseDefaulting(ChronoField.OFFSET_SECONDS, 0)
.append(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"))
.optionalStart()
.appendFraction(ChronoField.NANO_OF_SECOND, 6, 6, true)
.optionalEnd()
.appendLiteral("Z")
.toFormatter();

private static DateTypeAdapter dateTypeAdapter = new DateTypeAdapter();
private static SqlDateTypeAdapter sqlDateTypeAdapter = new SqlDateTypeAdapter();
private static OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter();
private static OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter(RFC3339MICRO_FORMATTER);
private static LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter();
private static ByteArrayAdapter byteArrayAdapter = new ByteArrayAdapter();

Expand All @@ -65,8 +82,11 @@ public class JSON {
public static GsonBuilder createGson() {
GsonFireBuilder fireBuilder = new GsonFireBuilder()
;
GsonBuilder builder = fireBuilder.createGsonBuilder();
return builder;
GsonBuilder builder =
fireBuilder
.registerPreProcessor(V1Status.class, new V1StatusPreProcessor())
.createGsonBuilder();
return builder.setExclusionStrategies(new V1MetadataExclusionStrategy());
}

private static String getDiscriminatorValue(JsonElement readElement, String discriminatorField) {
Expand Down Expand Up @@ -793,11 +813,14 @@ public static class ByteArrayAdapter extends TypeAdapter<byte[]> {

@Override
public void write(JsonWriter out, byte[] value) throws IOException {
boolean oldHtmlSafe = out.isHtmlSafe();
out.setHtmlSafe(false);
if (value == null) {
out.nullValue();
} else {
out.value(ByteString.of(value).base64());
}
out.setHtmlSafe(oldHtmlSafe);
}

@Override
Expand Down Expand Up @@ -853,7 +876,12 @@ public OffsetDateTime read(JsonReader in) throws IOException {
if (date.endsWith("+0000")) {
date = date.substring(0, date.length()-5) + "Z";
}
return OffsetDateTime.parse(date, formatter);
try {
return OffsetDateTime.parse(date, formatter);
} catch (DateTimeParseException e) {
// backward-compatibility for ISO8601 timestamp format
return OffsetDateTime.parse(date, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ public void write(JsonWriter out, V1ListMeta value) throws IOException {
@Override
public V1ListMeta read(JsonReader in) throws IOException {
JsonElement jsonElement = elementAdapter.read(in);
validateJsonElement(jsonElement);
// Disable validation so delete API can tolerate non-status return object (graceful deletion)
// validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonElement);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import io.kubernetes.client.custom.MapUtils;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -244,7 +245,7 @@ public boolean equals(Object o) {
}
V1Secret v1Secret = (V1Secret) o;
return Objects.equals(this.apiVersion, v1Secret.apiVersion) &&
Objects.equals(this.data, v1Secret.data) &&
MapUtils.equals(this.data, v1Secret.data) &&
Objects.equals(this.immutable, v1Secret.immutable) &&
Objects.equals(this.kind, v1Secret.kind) &&
Objects.equals(this.metadata, v1Secret.metadata) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ public void write(JsonWriter out, V1Status value) throws IOException {
@Override
public V1Status read(JsonReader in) throws IOException {
JsonElement jsonElement = elementAdapter.read(in);
validateJsonElement(jsonElement);
// Disable validation so delete API can tolerate non-status return object (graceful deletion)
// validateJsonObject(jsonObj);
return thisAdapter.fromJsonTree(jsonElement);
}

Expand Down

0 comments on commit 7e7dc60

Please sign in to comment.