Skip to content

Commit

Permalink
Merge pull request #1570 from yue9944882/cherrypick-11-eventlogger-patch
Browse files Browse the repository at this point in the history
Cherrypick for RELEASE-11: Fixes event-logger patch content
  • Loading branch information
k8s-ci-robot authored Mar 2, 2021
2 parents d597d79 + a10b0bd commit c6915b7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ public MutablePair<CoreV1Event, V1Patch> observe(CoreV1Event event, String key)
event.getMetadata().setName(lastObserved.name);
event.getMetadata().setResourceVersion(lastObserved.resourceVersion);

patch =
new V1Patch(
String.format(
"{\"message\":\"%s\",\"count\":\"%d\",\"lastTimestamp\":%s}",
event.getMessage(),
event.getCount(),
Configuration.getDefaultApiClient().getJSON().serialize(now)));
patch = buildEventPatch(event.getCount(), event.getMessage(), now);
}
EventLog log = new EventLog();
log.count = event.getCount();
Expand All @@ -73,4 +67,11 @@ private static class EventLog {
private String name;
private String resourceVersion;
}

static V1Patch buildEventPatch(int count, String message, OffsetDateTime now) {
return new V1Patch(
String.format(
"{\"message\":\"%s\",\"count\":%d,\"lastTimestamp\":%s}",
message, count, Configuration.getDefaultApiClient().getJSON().serialize(now)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package io.kubernetes.client.extended.event.legacy;

import static org.junit.Assert.*;

import io.kubernetes.client.custom.V1Patch;
import java.time.OffsetDateTime;
import org.junit.Test;

public class EventLoggerTest {

@Test
public void buildEventPatch() {
String expectedStr = "2021-03-02T15:02:48.179000Z";
OffsetDateTime expected = OffsetDateTime.parse("2021-03-02T15:02:48.179000Z");
V1Patch patch = EventLogger.buildEventPatch(1, "foo", expected);
assertEquals(
"{\"message\":\"foo\",\"count\":1,\"lastTimestamp\":\"" + expectedStr + "\"}",
patch.getValue());
}
}

0 comments on commit c6915b7

Please sign in to comment.