Skip to content

Commit 68c65da

Browse files
authored
Merge pull request #395 from oracle/issue_393
Issue 393
2 parents db69668 + 76c0e98 commit 68c65da

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

kubernetes/internal/create-weblogic-domain.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ function createYamlFiles {
560560
sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${dcrOutput}
561561
sed -i -e "s:%ADMIN_SERVER_NAME%:${adminServerName}:g" ${dcrOutput}
562562
sed -i -e "s:%WEBLOGIC_IMAGE%:${weblogicImage}:g" ${dcrOutput}
563+
sed -i -e "s:%WEBLOGIC_IMAGE_PULL_SECRET_NAME%:${weblogicImagePullSecretName}:g" ${dcrOutput}
563564
sed -i -e "s:%ADMIN_PORT%:${adminPort}:g" ${dcrOutput}
564565
sed -i -e "s:%INITIAL_MANAGED_SERVER_REPLICAS%:${initialManagedServerReplicas}:g" ${dcrOutput}
565566
sed -i -e "s:%EXPOSE_T3_CHANNEL_PREFIX%:${exposeAdminT3ChannelPrefix}:g" ${dcrOutput}

kubernetes/internal/domain-custom-resource-template.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ spec:
2424
image: "%WEBLOGIC_IMAGE%"
2525
# imagePullPolicy defaults to "Always" if image version is :latest
2626
imagePullPolicy: "IfNotPresent"
27+
# Identify which Secret contains the credentials for pulling an image
28+
imagePullSecret:
29+
name: %WEBLOGIC_IMAGE_PULL_SECRET_NAME%
2730
# Identify which Secret contains the WebLogic Admin credentials (note that there is an example of
2831
# how to create that Secret at the end of this file)
2932
adminSecret:

kubernetes/src/test/java/oracle/kubernetes/operator/create/CreateDomainGeneratedFilesBaseTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ protected Domain getExpectedDomain() {
434434
.withDomainName(getInputs().getDomainName())
435435
.withImage("store/oracle/weblogic:12.2.1.3")
436436
.withImagePullPolicy("IfNotPresent")
437+
.withImagePullSecretName(getInputs().getWeblogicImagePullSecretName())
437438
.withAdminSecret(
438439
newSecretReference().name(getInputs().getWeblogicCredentialsSecretName()))
439440
.withAsName(getInputs().getAdminServerName())

model/src/main/java/oracle/kubernetes/weblogic/domain/v1/DomainSpec.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
package oracle.kubernetes.weblogic.domain.v1;
66

7+
import com.google.common.base.Strings;
78
import com.google.gson.annotations.Expose;
89
import com.google.gson.annotations.SerializedName;
10+
import io.kubernetes.client.models.V1LocalObjectReference;
911
import io.kubernetes.client.models.V1SecretReference;
1012
import java.util.ArrayList;
1113
import java.util.HashMap;
@@ -59,6 +61,16 @@ public class DomainSpec {
5961
@Deprecated
6062
private String imagePullPolicy;
6163

64+
/**
65+
* Reference to the secret used to authenticate a request for an image pull.
66+
*
67+
* <p>More info:
68+
* https://kubernetes.io/docs/concepts/containers/images/#referring-to-an-imagepullsecrets-on-a-pod
69+
*/
70+
@SerializedName("imagePullSecret")
71+
@Expose
72+
private V1LocalObjectReference imagePullSecret;
73+
6274
/**
6375
* Reference to secret containing domain administrator username and password. Secret must contain
6476
* keys names 'username' and 'password' (Required)
@@ -366,6 +378,41 @@ public DomainSpec withImagePullPolicy(String imagePullPolicy) {
366378
return this;
367379
}
368380

381+
/**
382+
* Returns the reference to the secret used to authenticate a request for an image pull.
383+
*
384+
* <p>More info:
385+
* https://kubernetes.io/docs/concepts/containers/images/#referring-to-an-imagepullsecrets-on-a-pod
386+
*/
387+
public V1LocalObjectReference getImagePullSecret() {
388+
return hasImagePullSecret() ? imagePullSecret : null;
389+
}
390+
391+
private boolean hasImagePullSecret() {
392+
return imagePullSecret != null && !Strings.isNullOrEmpty(imagePullSecret.getName());
393+
}
394+
395+
/**
396+
* Reference to the secret used to authenticate a request for an image pull.
397+
*
398+
* <p>More info:
399+
* https://kubernetes.io/docs/concepts/containers/images/#referring-to-an-imagepullsecrets-on-a-pod
400+
*/
401+
public void setImagePullSecret(V1LocalObjectReference imagePullSecret) {
402+
this.imagePullSecret = imagePullSecret;
403+
}
404+
405+
/**
406+
* The name of the secret used to authenticate a request for an image pull.
407+
*
408+
* <p>More info:
409+
* https://kubernetes.io/docs/concepts/containers/images/#referring-to-an-imagepullsecrets-on-a-pod
410+
*/
411+
public DomainSpec withImagePullSecretName(String imagePullSecretName) {
412+
this.imagePullSecret = new V1LocalObjectReference().name(imagePullSecretName);
413+
return this;
414+
}
415+
369416
/**
370417
* Reference to secret containing domain administrator username and password. Secret must contain
371418
* keys names 'username' and 'password' (Required)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.kubernetes.client.models.V1ExecAction;
1616
import io.kubernetes.client.models.V1Handler;
1717
import io.kubernetes.client.models.V1Lifecycle;
18+
import io.kubernetes.client.models.V1LocalObjectReference;
1819
import io.kubernetes.client.models.V1ObjectMeta;
1920
import io.kubernetes.client.models.V1PersistentVolume;
2021
import io.kubernetes.client.models.V1PersistentVolumeClaim;
@@ -609,6 +610,10 @@ protected V1PodSpec createSpec(TuningParameters tuningParameters) {
609610
.name(KubernetesConstants.DOMAIN_CONFIG_MAP_NAME)
610611
.defaultMode(ALL_READ_AND_EXECUTE)));
611612

613+
V1LocalObjectReference imagePullSecret = info.getDomain().getSpec().getImagePullSecret();
614+
if (imagePullSecret != null) {
615+
podSpec.addImagePullSecretsItem(imagePullSecret);
616+
}
612617
if (!getClaims().isEmpty()) {
613618
podSpec.addVolumesItem(
614619
new V1Volume()

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io.kubernetes.client.models.V1ExecAction;
3636
import io.kubernetes.client.models.V1Handler;
3737
import io.kubernetes.client.models.V1Lifecycle;
38+
import io.kubernetes.client.models.V1LocalObjectReference;
3839
import io.kubernetes.client.models.V1ObjectMeta;
3940
import io.kubernetes.client.models.V1PersistentVolume;
4041
import io.kubernetes.client.models.V1PersistentVolumeClaim;
@@ -233,6 +234,19 @@ public void whenPodCreatedWithVersionedImage_useIfNotPresentPolicy() {
233234
assertThat(v1Container.getImagePullPolicy(), equalTo(IFNOTPRESENT_IMAGEPULLPOLICY));
234235
}
235236

237+
@Test
238+
public void whenPodCreatedWithoutPullSecret_doNotAddToPod() {
239+
assertThat(getCreatedPod().getSpec().getImagePullSecrets(), nullValue());
240+
}
241+
242+
@Test
243+
public void whenPodCreatedWithPullSecret_addToPod() {
244+
V1LocalObjectReference imagePullSecret = new V1LocalObjectReference().name("secret");
245+
domainPresenceInfo.getDomain().getSpec().setImagePullSecret(imagePullSecret);
246+
247+
assertThat(getCreatedPod().getSpec().getImagePullSecrets(), hasItem(imagePullSecret));
248+
}
249+
236250
@Test
237251
public void whenPodCreated_containerHasExpectedVolumeMounts() {
238252
assertThat(

0 commit comments

Comments
 (0)