Skip to content

Commit 28b720b

Browse files
committed
Merge branch 'xc-115343-41' into 'release/4.1'
backport create sa only if it does not exist to release/4.1 See merge request weblogic-cloud/weblogic-kubernetes-operator!4544
2 parents 161aeb5 + 33b92b6 commit 28b720b

File tree

3 files changed

+40
-16
lines changed

3 files changed

+40
-16
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2024, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.kubernetes;
@@ -313,6 +313,7 @@ void testDeleteOperatorButNotDomain() {
313313
+ "after the operator was deleted");
314314
assertTrue(checkManagedServerConfiguration(domain1Namespace, domain1Uid));
315315
} finally {
316+
cleanUpSA(opNamespace);
316317
if (!isDomain1Running) {
317318
cleanUpDomainSecrets(domain1Namespace);
318319
}

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/ServiceAccount.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// Copyright (c) 2020, 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2024, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.kubernetes.actions.impl;
55

66
import io.kubernetes.client.openapi.ApiException;
77
import io.kubernetes.client.openapi.models.V1ServiceAccount;
8+
import io.kubernetes.client.openapi.models.V1ServiceAccountList;
89
import oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes;
910

1011
public class ServiceAccount {
@@ -31,4 +32,22 @@ public static boolean create(V1ServiceAccount serviceAccount) throws ApiExceptio
3132
public static boolean delete(String name, String namespace) {
3233
return Kubernetes.deleteServiceAccount(name, namespace);
3334
}
35+
36+
/**
37+
* Verify whether the service account exists in the namespace.
38+
* @param name name of the service account
39+
* @param namespace namespace where the service account exits
40+
* @return true if the service account exists, false otherwise
41+
*/
42+
public static boolean serviceAccountExists(String name, String namespace) {
43+
V1ServiceAccountList sas = Kubernetes.listServiceAccounts(namespace);
44+
if (sas != null) {
45+
for (V1ServiceAccount sa : sas.getItems()) {
46+
if (sa.getMetadata().getName().equals(name)) {
47+
return true;
48+
}
49+
}
50+
}
51+
return false;
52+
}
3453
}

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2021, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2021, 2024, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.kubernetes.utils;
@@ -10,6 +10,7 @@
1010
import io.kubernetes.client.openapi.models.V1ObjectMeta;
1111
import io.kubernetes.client.openapi.models.V1ServiceAccount;
1212
import oracle.weblogic.kubernetes.actions.impl.OperatorParams;
13+
import oracle.weblogic.kubernetes.actions.impl.ServiceAccount;
1314
import oracle.weblogic.kubernetes.actions.impl.primitive.HelmParams;
1415
import oracle.weblogic.kubernetes.logging.LoggingFacade;
1516

@@ -433,12 +434,14 @@ public static OperatorParams installAndVerifyOperator(String opNamespace,
433434
LoggingFacade logger = getLogger();
434435

435436
// Create a service account for the unique opNamespace
436-
logger.info("Creating service account");
437-
assertDoesNotThrow(() -> createServiceAccount(new V1ServiceAccount()
438-
.metadata(new V1ObjectMeta()
439-
.namespace(opNamespace)
440-
.name(opServiceAccount))));
441-
logger.info("Created service account: {0}", opServiceAccount);
437+
if (!ServiceAccount.serviceAccountExists(opServiceAccount, opNamespace)) {
438+
logger.info("Creating service account");
439+
assertDoesNotThrow(() -> createServiceAccount(new V1ServiceAccount()
440+
.metadata(new V1ObjectMeta()
441+
.namespace(opNamespace)
442+
.name(opServiceAccount))));
443+
logger.info("Created service account: {0}", opServiceAccount);
444+
}
442445

443446
operatorImage = getOperatorImageName();
444447

@@ -636,13 +639,14 @@ public static OperatorParams installAndVerifyOperator(String opNamespace,
636639
LoggingFacade logger = getLogger();
637640

638641
// Create a service account for the unique opNamespace
639-
logger.info("Creating service account");
640-
assertDoesNotThrow(() -> createServiceAccount(new V1ServiceAccount()
641-
.metadata(new V1ObjectMeta()
642-
.namespace(opNamespace)
643-
.name(opServiceAccount))));
644-
logger.info("Created service account: {0}", opServiceAccount);
645-
642+
if (!ServiceAccount.serviceAccountExists(opServiceAccount, opNamespace)) {
643+
logger.info("Creating service account");
644+
assertDoesNotThrow(() -> createServiceAccount(new V1ServiceAccount()
645+
.metadata(new V1ObjectMeta()
646+
.namespace(opNamespace)
647+
.name(opServiceAccount))));
648+
logger.info("Created service account: {0}", opServiceAccount);
649+
}
646650

647651
// get operator image name
648652
String operatorImage = getOperatorImageName();

0 commit comments

Comments
 (0)