fix: removing lifecylce in initContainers

closes: #40360

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
Steven Hawkins 2025-06-16 03:48:50 -04:00 committed by GitHub
parent 78f575b53b
commit bd1496109e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -193,8 +193,9 @@ public class KeycloakUpdateJobDependentResource extends CRUDKubernetesDependentR
containerBuilder.withVolumeMounts(newVolumeMounts);
}
// remove restart policy and probes
// remove restart policy, lifecycle, and probes
containerBuilder.withRestartPolicy(null);
containerBuilder.withLifecycle(null);
containerBuilder.withReadinessProbe(null);
containerBuilder.withLivenessProbe(null);
containerBuilder.withStartupProbe(null);

View File

@ -70,6 +70,7 @@ import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.keycloak.operator.ContextUtils.DIST_CONFIGURATOR_KEY;
import static org.keycloak.operator.ContextUtils.NEW_DEPLOYMENT_KEY;
@ -739,4 +740,16 @@ public class PodTemplateTest {
assertEquals(List.of(new LocalObjectReference("new-secret"), new LocalObjectReference("secret")), job.getSpec().getTemplate().getSpec().getImagePullSecrets());
}
@Test
public void testFieldRemovalForInitContainer() {
Job job = getUpdateJob(builder -> {
}, builder -> builder.withNewUnsupported().withNewPodTemplate().withNewSpec().addNewContainer()
.withRestartPolicy("OnFailure")
.withNewLifecycle().withNewPostStart().withNewExec().withCommand("hello").endExec().endPostStart()
.endLifecycle().endContainer().endSpec().endPodTemplate().endUnsupported(), builder -> {
});
assertNull(job.getSpec().getTemplate().getSpec().getInitContainers().get(0).getLifecycle());
assertNull(job.getSpec().getTemplate().getSpec().getInitContainers().get(0).getRestartPolicy());
}
}