Skip to content

Commit 29cedf5

Browse files
committed
Merge conflict step improvements after recent PodHelper refactoring
1 parent 349f33c commit 29cedf5

File tree

5 files changed

+105
-38
lines changed

5 files changed

+105
-38
lines changed

operator/src/main/java/oracle/kubernetes/operator/helpers/PodHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,4 @@ private Step deletePod(String name, String namespace, Step next) {
343343
.deletePodAsync(name, namespace, deleteOptions, new DefaultResponseStep<>(next));
344344
}
345345
}
346-
}
346+
}

operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import oracle.kubernetes.operator.work.Packet;
5151
import oracle.kubernetes.operator.work.Step;
5252
import oracle.kubernetes.weblogic.domain.v1.ServerStartup;
53+
import org.apache.commons.lang3.builder.EqualsBuilder;
5354

5455
@SuppressWarnings("deprecation")
5556
public abstract class PodStepContext {
@@ -70,9 +71,8 @@ public abstract class PodStepContext {
7071
private static final String START_SERVER = "/weblogic-operator/scripts/startServer.sh";
7172
private static final String READINESS_PROBE = "/weblogic-operator/scripts/readinessProbe.sh";
7273
private static final String LIVENESS_PROBE = "/weblogic-operator/scripts/livenessProbe.sh";
73-
74-
private static final String READ_WRITE_MANY_ACCESS = "ReadWriteMany";
7574

75+
private static final String READ_WRITE_MANY_ACCESS = "ReadWriteMany";
7676

7777
private final DomainPresenceInfo info;
7878
private final Step conflictStep;
@@ -100,9 +100,33 @@ private void createSubstitutionMap() {
100100
private V1Pod getPodModel() {
101101
return podModel;
102102
}
103-
103+
104104
private Step getConflictStep() {
105-
return readPod(conflictStep);
105+
return new ConflictStep();
106+
}
107+
108+
private class ConflictStep extends Step {
109+
110+
@Override
111+
public NextAction apply(Packet packet) {
112+
return doNext(getConflictStep(), packet);
113+
}
114+
115+
@Override
116+
public boolean equals(Object other) {
117+
if (other == this) {
118+
return true;
119+
}
120+
if ((other instanceof ConflictStep) == false) {
121+
return false;
122+
}
123+
ConflictStep rhs = ((ConflictStep) other);
124+
return new EqualsBuilder().append(conflictStep, rhs.getConflictStep()).isEquals();
125+
}
126+
127+
private Step getConflictStep() {
128+
return conflictStep;
129+
}
106130
}
107131

108132
// ------------------------ data methods ----------------------------
@@ -382,17 +406,17 @@ public NextAction onFailure(Packet packet, CallResponse<V1Pod> callResponse) {
382406
}
383407
return super.onFailure(packet, callResponse);
384408
}
385-
409+
386410
@Override
387411
public NextAction onSuccess(Packet packet, CallResponse<V1Pod> callResponse) {
388412
V1Pod currentPod = callResponse.getResult();
389-
getSko().getPod().set(currentPod);
413+
setRecordedPod(currentPod);
390414
return doNext(packet);
391415
}
392416
}
393-
417+
394418
private class VerifyPodStep extends Step {
395-
419+
396420
VerifyPodStep(Step next) {
397421
super(next);
398422
}
@@ -405,13 +429,11 @@ public NextAction apply(Packet packet) {
405429
return doNext(createNewPod(getNext()), packet);
406430
} else if (canUseCurrentPod(currentPod)) {
407431
logPodExists();
408-
setRecordedPod(currentPod);
409432
return doNext(packet);
410433
} else {
411434
return doNext(replaceCurrentPod(getNext()), packet);
412435
}
413436
}
414-
415437
}
416438

417439
private ResponseStep<V1Pod> createResponse(Step next) {

operator/src/test/java/oracle/kubernetes/operator/helpers/AdminPodHelperTest.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import static org.hamcrest.Matchers.empty;
1515
import static org.hamcrest.Matchers.equalTo;
1616
import static org.hamcrest.Matchers.not;
17-
import static org.hamcrest.Matchers.sameInstance;
1817
import static org.hamcrest.junit.MatcherAssert.assertThat;
1918

2019
import io.kubernetes.client.ApiException;
@@ -77,7 +76,8 @@ private void verifyAdminPodReplacedWhen(PodMutator mutator) {
7776

7877
V1Pod existingPod = createPodModel();
7978
mutator.mutate(existingPod);
80-
expectReadPod(getPodName()).returning(existingPod);
79+
initializeExistingPod(existingPod);
80+
expectListPersistentVolume().returning(createPersistentVolumeList());
8181
expectDeletePod(getPodName()).returning(new V1Status());
8282
expectCreatePod(podWithName(getPodName())).returning(createPodModel());
8383

@@ -101,7 +101,8 @@ public void whenDeleteReportsNotFound_replaceAdminPod() {
101101
PodAwaiterStepFactory.class,
102102
(pod, next) -> terminalStep);
103103

104-
expectReadPod(getPodName()).returning(getIncompatiblePod());
104+
initializeExistingPod(getIncompatiblePod());
105+
expectListPersistentVolume().returning(createPersistentVolumeList());
105106
expectDeletePod(getPodName()).failingWithStatus(CallBuilder.NOT_FOUND);
106107
expectCreatePod(podWithName(getPodName())).returning(createPodModel());
107108

@@ -119,7 +120,8 @@ private V1Pod getIncompatiblePod() {
119120
@Test
120121
public void whenAdminPodDeletionFails_retryOnFailure() {
121122
testSupport.addRetryStrategy(retryStrategy);
122-
expectReadPod(getPodName()).returning(getIncompatiblePod());
123+
initializeExistingPod(getIncompatiblePod());
124+
expectListPersistentVolume().returning(createPersistentVolumeList());
123125
expectDeletePod(getPodName()).failingWithStatus(401);
124126
expectStepsAfterCreation();
125127

@@ -128,13 +130,13 @@ public void whenAdminPodDeletionFails_retryOnFailure() {
128130
testSupport.runSteps(initialStep);
129131

130132
testSupport.verifyCompletionThrowable(ApiException.class);
131-
assertThat(retryStrategy.getConflictStep(), sameInstance(initialStep));
132133
}
133134

134135
@Test
135136
public void whenAdminPodReplacementFails_retryOnFailure() {
136137
testSupport.addRetryStrategy(retryStrategy);
137-
expectReadPod(getPodName()).returning(getIncompatiblePod());
138+
initializeExistingPod(getIncompatiblePod());
139+
expectListPersistentVolume().returning(createPersistentVolumeList());
138140
expectDeletePod(getPodName()).returning(new V1Status());
139141
expectCreatePod(podWithName(getPodName())).failingWithStatus(401);
140142
expectStepsAfterCreation();
@@ -144,7 +146,6 @@ public void whenAdminPodReplacementFails_retryOnFailure() {
144146
testSupport.runSteps(initialStep);
145147

146148
testSupport.verifyCompletionThrowable(ApiException.class);
147-
assertThat(retryStrategy.getConflictStep(), sameInstance(initialStep));
148149
}
149150

150151
@Test
@@ -209,11 +210,13 @@ public void whenExistingAdminPodSpecContainerHasWrongEnvFrom_replaceIt() {
209210

210211
@Test
211212
public void whenAdminPodCreated_specHasPodNameAsHostName() {
213+
expectListPersistentVolume().returning(createPersistentVolumeList());
212214
assertThat(getCreatedPod().getSpec().getHostname(), equalTo(getPodName()));
213215
}
214216

215217
@Test
216218
public void whenAdminPodCreated_containerHasStartServerCommand() {
219+
expectListPersistentVolume().returning(createPersistentVolumeList());
217220
assertThat(
218221
getCreatedPodSpecContainer().getCommand(),
219222
contains("/weblogic-operator/scripts/startServer.sh", UID, getServerName(), DOMAIN_NAME));
@@ -222,6 +225,7 @@ public void whenAdminPodCreated_containerHasStartServerCommand() {
222225
@Test
223226
public void whenAdminPodCreated_hasOperatorCertEnvVariable() {
224227
putTuningParameter(INTERNAL_OPERATOR_CERT_FILE_PARAM, CERTFILE);
228+
expectListPersistentVolume().returning(createPersistentVolumeList());
225229
assertThat(
226230
getCreatedPodSpecContainer().getEnv(),
227231
hasEnvVar(INTERNAL_OPERATOR_CERT_ENV_NAME, CERTFILE));
@@ -231,6 +235,7 @@ public void whenAdminPodCreated_hasOperatorCertEnvVariable() {
231235
public void whenDomainPresenceHasNullEnvironmentItems_createAdminPodStartupWithDefaultItems() {
232236
domainPresenceInfo.getDomain().getSpec().setServerStartup(null);
233237

238+
expectListPersistentVolume().returning(createPersistentVolumeList());
234239
assertThat(getCreatedPodSpecContainer().getEnv(), not(empty()));
235240
}
236241

@@ -245,6 +250,7 @@ public void whenDomainPresenceHasEnvironmentItems_createAdminPodStartupWithThem(
245250
.withVar("item2", "value2")
246251
.build());
247252

253+
expectListPersistentVolume().returning(createPersistentVolumeList());
248254
assertThat(
249255
getCreatedPodSpecContainer().getEnv(),
250256
allOf(hasEnvVar("item1", "value1"), hasEnvVar("item2", "value2")));
@@ -261,6 +267,7 @@ public void whenDomainPresenceHasEnvironmentItemsWithVariables_createAdminPodSta
261267
.withVar("item2", "$(SERVER_NAME) is $(ADMIN_NAME):$(ADMIN_PORT)")
262268
.build());
263269

270+
expectListPersistentVolume().returning(createPersistentVolumeList());
264271
assertThat(
265272
getCreatedPodSpecContainer().getEnv(),
266273
allOf(
@@ -287,6 +294,11 @@ List<ServerStartup> build() {
287294
}
288295
}
289296

297+
@Override
298+
protected void onAdminExpectListPersistentVolume() {
299+
expectListPersistentVolume().returning(createPersistentVolumeList());
300+
}
301+
290302
@Override
291303
V1Pod createPodModel() {
292304
return new V1Pod().metadata(createPodMetadata()).spec(createPodSpec());

operator/src/test/java/oracle/kubernetes/operator/helpers/ManagedPodHelperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private void verifyRollManagedPodWhen(PodMutator mutator) {
226226

227227
V1Pod existingPod = createPodModel();
228228
mutator.mutate(existingPod);
229-
expectReadPod(getPodName()).returning(existingPod);
229+
initializeExistingPod(existingPod);
230230

231231
testSupport.runSteps(getStepFactory(), terminalStep);
232232

0 commit comments

Comments
 (0)