Skip to content

Commit 0011c0d

Browse files
authored
Create multiple secrets if BASE_IMAGES_REPO and REPO_REGISTRY are different (#3024)
* Create multiple secrets if BASE_IMAGES_REPO and REPO_REGISTRY are different
1 parent f7a22e4 commit 0011c0d

File tree

6 files changed

+71
-40
lines changed

6 files changed

+71
-40
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItIntrospectVersion.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.nio.file.Paths;
1212
import java.time.OffsetDateTime;
1313
import java.util.ArrayList;
14-
import java.util.Arrays;
1514
import java.util.LinkedHashMap;
1615
import java.util.List;
1716
import java.util.Map;
@@ -59,10 +58,11 @@
5958
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_PASSWORD_PATCH;
6059
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT;
6160
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_PATCH;
62-
import static oracle.weblogic.kubernetes.TestConstants.BASE_IMAGES_REPO_SECRET;
6361
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_API_VERSION;
6462
import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST;
6563
import static oracle.weblogic.kubernetes.TestConstants.KIND_REPO;
64+
import static oracle.weblogic.kubernetes.TestConstants.OCIR_REGISTRY;
65+
import static oracle.weblogic.kubernetes.TestConstants.OCIR_WEBLOGIC_IMAGE_NAME;
6666
import static oracle.weblogic.kubernetes.TestConstants.OKD;
6767
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_NAME;
6868
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_TO_USE_IN_SPEC;
@@ -95,7 +95,6 @@
9595
import static oracle.weblogic.kubernetes.utils.ConfigMapUtils.createConfigMapForDomainCreation;
9696
import static oracle.weblogic.kubernetes.utils.DeployUtil.deployUsingRest;
9797
import static oracle.weblogic.kubernetes.utils.DomainUtils.createDomainAndVerify;
98-
import static oracle.weblogic.kubernetes.utils.ImageUtils.createSecretForBaseImages;
9998
import static oracle.weblogic.kubernetes.utils.ImageUtils.dockerLoginAndPushImageToRegistry;
10099
import static oracle.weblogic.kubernetes.utils.JobUtils.createDomainJob;
101100
import static oracle.weblogic.kubernetes.utils.JobUtils.getIntrospectJobName;
@@ -114,6 +113,7 @@
114113
import static oracle.weblogic.kubernetes.utils.PodUtils.getPodsWithTimeStamps;
115114
import static oracle.weblogic.kubernetes.utils.PodUtils.setPodAntiAffinity;
116115
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword;
116+
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretsForImageRepos;
117117
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
118118
import static oracle.weblogic.kubernetes.utils.WLSTUtils.executeWLSTScript;
119119
import static org.apache.commons.io.FileUtils.copyDirectory;
@@ -204,10 +204,6 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
204204
// install operator and verify its running in ready state
205205
installAndVerifyOperator(opNamespace, introDomainNamespace);
206206

207-
// create pull secrets for WebLogic image when running in non Kind Kubernetes cluster
208-
// this secret is used only for non-kind cluster
209-
createSecretForBaseImages(introDomainNamespace);
210-
211207
// build the clusterview application
212208
Path targetDir = Paths.get(WORK_DIR,
213209
ItIntrospectVersion.class.getName() + "/clusterviewapp");
@@ -710,7 +706,7 @@ void testUpdateImageName() {
710706
String imageTag = CommonTestUtils.getDateAndTimeStamp();
711707
String imageUpdate = KIND_REPO != null ? KIND_REPO
712708
+ (WEBLOGIC_IMAGE_NAME + ":" + imageTag).substring(TestConstants.BASE_IMAGES_REPO.length() + 1)
713-
: WEBLOGIC_IMAGE_NAME + ":" + imageTag;
709+
: OCIR_REGISTRY + "/" + OCIR_WEBLOGIC_IMAGE_NAME + ":" + imageTag;
714710
dockerTag(imageName, imageUpdate);
715711
dockerLoginAndPushImageToRegistry(imageUpdate);
716712

@@ -1024,9 +1020,6 @@ private static void createDomain() {
10241020
.domainHomeSourceType("PersistentVolume") // set the domain home source type as pv
10251021
.image(WEBLOGIC_IMAGE_TO_USE_IN_SPEC)
10261022
.imagePullPolicy("IfNotPresent")
1027-
.imagePullSecrets(Arrays.asList(
1028-
new V1LocalObjectReference()
1029-
.name(BASE_IMAGES_REPO_SECRET))) // this secret is used only in non-kind cluster
10301023
.webLogicCredentialsSecret(new V1SecretReference()
10311024
.name(wlSecretName)
10321025
.namespace(introDomainNamespace))
@@ -1069,6 +1062,14 @@ private static void createDomain() {
10691062
.clusterName(cluster1Name)
10701063
.replicas(cluster1ReplicaCount)
10711064
.serverStartState("RUNNING")));
1065+
1066+
// create secrets
1067+
List<V1LocalObjectReference> secrets = new ArrayList<>();
1068+
for (String secret : createSecretsForImageRepos(introDomainNamespace)) {
1069+
secrets.add(new V1LocalObjectReference().name(secret));
1070+
}
1071+
domain.spec().setImagePullSecrets(secrets);
1072+
10721073
setPodAntiAffinity(domain);
10731074
// verify the domain custom resource is created
10741075
createDomainAndVerify(domain, introDomainNamespace);

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiAuxiliaryImage.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_APP_NAME;
4545
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_TAG;
4646
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_WDT_MODEL_FILE;
47-
import static oracle.weblogic.kubernetes.TestConstants.OCIR_SECRET_NAME;
47+
import static oracle.weblogic.kubernetes.TestConstants.OCIR_REGISTRY;
48+
import static oracle.weblogic.kubernetes.TestConstants.OCIR_WEBLOGIC_IMAGE_NAME;
4849
import static oracle.weblogic.kubernetes.TestConstants.OPERATOR_RELEASE_NAME;
4950
import static oracle.weblogic.kubernetes.TestConstants.RESULTS_ROOT;
5051
import static oracle.weblogic.kubernetes.TestConstants.WDT_TEST_VERSION;
@@ -100,6 +101,7 @@
100101
import static oracle.weblogic.kubernetes.utils.PodUtils.getPodCreationTime;
101102
import static oracle.weblogic.kubernetes.utils.PodUtils.getPodsWithTimeStamps;
102103
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword;
104+
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretsForImageRepos;
103105
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
104106
import static org.awaitility.Awaitility.with;
105107
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -134,6 +136,7 @@ class ItMiiAuxiliaryImage {
134136
private String adminSvcExtHost = null;
135137
private String adminSecretName = "weblogic-credentials";
136138
private String encryptionSecretName = "encryptionsecret";
139+
private static String[] imageSecrets;
137140

138141
ConditionFactory withStandardRetryPolicy
139142
= with().pollDelay(0, SECONDS)
@@ -187,10 +190,6 @@ void testCreateDomainUsingMultipleAuxiliaryImages() {
187190
final String auxiliaryImageVolumeName = "auxiliaryImageVolume1";
188191
final String auxiliaryImagePath = "/auxiliary";
189192

190-
// Create the repo secret to pull the image
191-
// this secret is used only for non-kind cluster
192-
createOcirRepoSecret(domainNamespace);
193-
194193
// create secret for admin credentials
195194
logger.info("Create secret for admin credentials");
196195
String adminSecretName = "weblogic-credentials";
@@ -284,7 +283,7 @@ void testCreateDomainUsingMultipleAuxiliaryImages() {
284283
logger.info("Creating domain custom resource with domainUid {0} and auxiliary images {1} {2}",
285284
domainUid, miiAuxiliaryImage1, miiAuxiliaryImage2);
286285
Domain domainCR = createDomainResource(domainUid, domainNamespace,
287-
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, OCIR_SECRET_NAME,
286+
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, createSecretsForImageRepos(domainNamespace),
288287
encryptionSecretName, replicaCount, "cluster-1", auxiliaryImagePath,
289288
auxiliaryImageVolumeName, miiAuxiliaryImage1, miiAuxiliaryImage2);
290289

@@ -407,7 +406,7 @@ void testUpdateBaseImageName() {
407406
String imageTag = getDateAndTimeStamp();
408407
String imageUpdate = KIND_REPO != null ? KIND_REPO
409408
+ (WEBLOGIC_IMAGE_NAME + ":" + imageTag).substring(TestConstants.BASE_IMAGES_REPO.length() + 1)
410-
: WEBLOGIC_IMAGE_NAME + ":" + imageTag;
409+
: OCIR_REGISTRY + "/" + OCIR_WEBLOGIC_IMAGE_NAME + ":" + imageTag;
411410
dockerTag(imageName, imageUpdate);
412411
dockerLoginAndPushImageToRegistry(imageUpdate);
413412

@@ -608,7 +607,7 @@ void testErrorPathDomainMismatchMountPath() {
608607
logger.info("Creating domain custom resource with domainUid {0} and auxiliary image {1}",
609608
domainUid, errorPathAuxiliaryImage1);
610609
Domain domainCR = createDomainResource(domainUid, errorpathDomainNamespace,
611-
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, OCIR_SECRET_NAME,
610+
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, createSecretsForImageRepos(errorpathDomainNamespace),
612611
encryptionSecretName, replicaCount, "cluster-1", auxiliaryImagePath,
613612
auxiliaryImageVolumeName, errorPathAuxiliaryImage1);
614613

@@ -691,7 +690,7 @@ void testErrorPathDomainMissingWDTBinary() {
691690
logger.info("Creating domain custom resource with domainUid {0} and auxiliary image {1}",
692691
domainUid, errorPathAuxiliaryImage2);
693692
Domain domainCR = createDomainResource(domainUid, errorpathDomainNamespace,
694-
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, OCIR_SECRET_NAME,
693+
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, createSecretsForImageRepos(errorpathDomainNamespace),
695694
encryptionSecretName, replicaCount, "cluster-1", auxiliaryImagePath,
696695
auxiliaryImageVolumeName, errorPathAuxiliaryImage2);
697696

@@ -781,7 +780,7 @@ void testErrorPathDomainMissingDomainConfig() {
781780
logger.info("Creating domain custom resource with domainUid {0} and auxiliary image {1}",
782781
domainUid, errorPathAuxiliaryImage3);
783782
Domain domainCR = createDomainResource(domainUid, errorpathDomainNamespace,
784-
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, OCIR_SECRET_NAME,
783+
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, createSecretsForImageRepos(errorpathDomainNamespace),
785784
encryptionSecretName, replicaCount, "cluster-1", auxiliaryImagePath,
786785
auxiliaryImageVolumeName, errorPathAuxiliaryImage3);
787786

@@ -890,7 +889,7 @@ void testErrorPathFilePermission() {
890889
logger.info("Creating domain custom resource with domainUid {0} and auxiliary image {1}",
891890
domainUid, errorPathAuxiliaryImage4);
892891
Domain domainCR = createDomainResource(domainUid, errorpathDomainNamespace,
893-
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, OCIR_SECRET_NAME,
892+
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, createSecretsForImageRepos(errorpathDomainNamespace),
894893
encryptionSecretName, replicaCount, "cluster-1", auxiliaryImagePath,
895894
auxiliaryImageVolumeName, errorPathAuxiliaryImage4);
896895

@@ -1056,7 +1055,7 @@ void testUpdateWDTVersionUsingMultipleAuxiliaryImages() {
10561055
logger.info("Creating domain custom resource with domainUid {0} and auxiliary images {1} {2}",
10571056
domainUid, miiAuxiliaryImage4, miiAuxiliaryImage5);
10581057
Domain domainCR = createDomainResource(domainUid, wdtDomainNamespace,
1059-
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, OCIR_SECRET_NAME,
1058+
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, createSecretsForImageRepos(wdtDomainNamespace),
10601059
encryptionSecretName, replicaCount, "cluster-1", auxiliaryImagePath,
10611060
auxiliaryImageVolumeName, miiAuxiliaryImage4, miiAuxiliaryImage5);
10621061

@@ -1252,10 +1251,6 @@ private void createAuxiliaryImage(String stageDirPath, String dockerFileLocation
12521251
}
12531252

12541253
private void createSecretsForDomain(String adminSecretName, String encryptionSecretName, String domainNamespace) {
1255-
if (!secretExists(OCIR_SECRET_NAME, domainNamespace)) {
1256-
createOcirRepoSecret(domainNamespace);
1257-
}
1258-
12591254
// create secret for admin credentials
12601255
logger.info("Create secret for admin credentials");
12611256
if (!secretExists(adminSecretName, domainNamespace)) {
@@ -1270,6 +1265,7 @@ private void createSecretsForDomain(String adminSecretName, String encryptionSec
12701265
}
12711266
}
12721267

1268+
12731269
private void checkConfiguredJMSresouce(String domainNamespace, String adminServerPodName) {
12741270
int adminServiceNodePort
12751271
= getServiceNodePort(domainNamespace, getExternalServicePodName(adminServerPodName), "default");
@@ -1353,5 +1349,4 @@ private void verifyIntrospectorPodLogContainsExpectedErrorMsg(String domainUid,
13531349
.until(() ->
13541350
introspectorPodLogContainsExpectedErrorMsg(domainUid, namespace, expectedErrorMsg));
13551351
}
1356-
13571352
}

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiAuxiliaryImageCluster.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_IMAGES_REPO;
3636
import static oracle.weblogic.kubernetes.TestConstants.MII_AUXILIARY_IMAGE_NAME;
3737
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_TAG;
38-
import static oracle.weblogic.kubernetes.TestConstants.OCIR_SECRET_NAME;
3938
import static oracle.weblogic.kubernetes.TestConstants.RESULTS_ROOT;
4039
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_TO_USE_IN_SPEC;
4140
import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR;
@@ -54,6 +53,7 @@
5453
import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator;
5554
import static oracle.weblogic.kubernetes.utils.PodUtils.getExternalServicePodName;
5655
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword;
56+
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretsForImageRepos;
5757
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
5858
import static org.awaitility.Awaitility.with;
5959
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -190,7 +190,7 @@ void testCreateDomainUsingAuxiliaryImagesWClusterConfig() {
190190
logger.info("Creating domain custom resource with domainUid {0} and auxiliary images {1} {2}",
191191
domainUid, auxiliaryImageDomainScopeNames.toString(), auxiliaryImageClusterScopeNames.toString());
192192
Domain domainCR = createDomainResourceWithAuxiliaryImageClusterScope(domainUid, domainNamespace,
193-
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, OCIR_SECRET_NAME,
193+
WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, createSecretsForImageRepos(domainNamespace),
194194
encryptionSecretName, replicaCount, clusterName,
195195
Map.of(auxiliaryImagePath, List.of(auxiliaryImageVolumeName)),
196196
auxiliaryImageDomainScopeNames, auxiliaryImageClusterScopeNames);
@@ -362,7 +362,7 @@ void testPatchDomainToAddModelsToClusterConfigIgnored() {
362362

363363
private void createAuxiliaryImage(String stageDirPath, String dockerFileLocation, String auxiliaryImage) {
364364
//replace the BUSYBOX_IMAGE and BUSYBOX_TAG in Dockerfile
365-
Path dockerDestFile = Paths.get(WORK_DIR, "auximages", "Dockerfile");
365+
Path dockerDestFile = Paths.get(WORK_DIR, "auximagescluster", "Dockerfile");
366366
assertDoesNotThrow(() -> {
367367
Files.createDirectories(dockerDestFile.getParent());
368368
Files.copy(Paths.get(dockerFileLocation),

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomainModelInPV.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_NAME;
4848
import static oracle.weblogic.kubernetes.TestConstants.OCIR_PASSWORD;
4949
import static oracle.weblogic.kubernetes.TestConstants.OCIR_REGISTRY;
50-
import static oracle.weblogic.kubernetes.TestConstants.OCIR_SECRET_NAME;
5150
import static oracle.weblogic.kubernetes.TestConstants.OCIR_USERNAME;
5251
import static oracle.weblogic.kubernetes.TestConstants.OKD;
5352
import static oracle.weblogic.kubernetes.TestConstants.OKE_CLUSTER;
@@ -83,6 +82,7 @@
8382
import static oracle.weblogic.kubernetes.utils.PodUtils.execInPod;
8483
import static oracle.weblogic.kubernetes.utils.PodUtils.getExternalServicePodName;
8584
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword;
85+
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretsForImageRepos;
8686
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
8787
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
8888
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -254,7 +254,8 @@ void testMiiDomainWithModelAndApplicationInPV(Entry<String, String> params) {
254254
logger.info("Creating domain custom resource with domainUid {0} and image {1}",
255255
domainUid, image);
256256
Domain domainCR = CommonMiiTestUtils.createDomainResource(domainUid, domainNamespace,
257-
image, adminSecretName, OCIR_SECRET_NAME, encryptionSecretName, replicaCount, clusterName);
257+
image, adminSecretName, createSecretsForImageRepos(domainNamespace),
258+
encryptionSecretName, replicaCount, clusterName);
258259
domainCR.spec().configuration().model().withModelHome(modelMountPath + "/model");
259260
domainCR.spec().serverPod()
260261
.addVolumesItem(new V1Volume()

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/CommonMiiTestUtils.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public static Domain createMiiDomainAndVerify(
171171
domainNamespace,
172172
imageName,
173173
adminSecretName,
174-
OCIR_SECRET_NAME,
174+
new String[]{OCIR_SECRET_NAME},
175175
encryptionSecretName,
176176
replicaCount,
177177
"cluster-1");
@@ -223,11 +223,16 @@ public static Domain createDomainResource(
223223
String domNamespace,
224224
String imageName,
225225
String adminSecretName,
226-
String repoSecretName,
226+
String[] repoSecretName,
227227
String encryptionSecretName,
228228
int replicaCount,
229229
String clusterName) {
230230

231+
// create secrets
232+
List<V1LocalObjectReference> secrets = new ArrayList<>();
233+
for (String secret : repoSecretName) {
234+
secrets.add(new V1LocalObjectReference().name(secret));
235+
}
231236
// create the domain CR
232237
Domain domain = new Domain()
233238
.apiVersion(DOMAIN_API_VERSION)
@@ -239,8 +244,6 @@ public static Domain createDomainResource(
239244
.domainUid(domainResourceName)
240245
.domainHomeSourceType("FromModel")
241246
.image(imageName)
242-
.addImagePullSecretsItem(new io.kubernetes.client.openapi.models.V1LocalObjectReference()
243-
.name(repoSecretName))
244247
.webLogicCredentialsSecret(new io.kubernetes.client.openapi.models.V1SecretReference()
245248
.name(adminSecretName)
246249
.namespace(domNamespace))
@@ -268,6 +271,7 @@ public static Domain createDomainResource(
268271
.domainType("WLS")
269272
.runtimeEncryptionSecret(encryptionSecretName))
270273
.introspectorJobActiveDeadlineSeconds(300L)));
274+
domain.spec().setImagePullSecrets(secrets);
271275

272276
setPodAntiAffinity(domain);
273277
return domain;
@@ -296,7 +300,7 @@ public static Domain createDomainResource(
296300
String domNamespace,
297301
String baseImageName,
298302
String adminSecretName,
299-
String repoSecretName,
303+
String[] repoSecretName,
300304
String encryptionSecretName,
301305
int replicaCount,
302306
String clusterName,
@@ -343,7 +347,7 @@ public static Domain createDomainResourceWithAuxiliaryImage(
343347
String domNamespace,
344348
String baseImageName,
345349
String adminSecretName,
346-
String repoSecretName,
350+
String[] repoSecretName,
347351
String encryptionSecretName,
348352
int replicaCount,
349353
String clusterName,
@@ -394,7 +398,7 @@ public static Domain createDomainResourceWithAuxiliaryImageClusterScope(
394398
String domNamespace,
395399
String baseImageName,
396400
String adminSecretName,
397-
String repoSecretName,
401+
String[] repoSecretName,
398402
String encryptionSecretName,
399403
int replicaCount,
400404
String clusterName,

0 commit comments

Comments
 (0)