Skip to content

Commit 21ed8fe

Browse files
Merge pull request #334 from fabiobrz/issue-333
[issue-333] - Fix OpenDataHubOpenShiftOperatorProvisionerTest in order to properly remove created CRs
2 parents 846a012 + e4ea1eb commit 21ed8fe

18 files changed

+1203
-143
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ mvn test -pl testsuite/ -Pts.execution-profile.community -Pts.openshift
164164
This is useful when running the testsuite against an OpenShift cluster, so that only OpenShift integration test will be
165165
executed, while Kubernetes ones will be skipped.
166166

167+
* Run Open Data Hub/OpenShift AI integration tests:
168+
```shell
169+
mvn test -pl testsuite/ -Pts.ai
170+
```
171+
167172
## Platforms
168173

169174
Intersmash is designed to allow executions on different Kubernetes compliant platforms.

provisioners/src/main/java/org/jboss/intersmash/provision/openshift/OpenDataHubOpenShiftOperatorProvisioner.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.jboss.intersmash.application.operator.OpenDataHubOperatorApplication;
1919
import org.jboss.intersmash.provision.operator.OpenDataHubOperatorProvisioner;
20+
import org.jboss.intersmash.provision.operator.model.odh.AuthList;
2021
import org.jboss.intersmash.provision.operator.model.odh.DSCInitializationList;
2122
import org.jboss.intersmash.provision.operator.model.odh.DataScienceClusterList;
2223
import org.jboss.intersmash.provision.operator.model.odh.FeatureTrackerList;
@@ -34,6 +35,7 @@
3435
import io.opendatahub.datasciencecluster.v1.DataScienceCluster;
3536
import io.opendatahub.dscinitialization.v1.DSCInitialization;
3637
import io.opendatahub.features.v1.FeatureTracker;
38+
import io.opendatahub.platform.services.v1alpha1.Auth;
3739
import io.opendatahub.platform.services.v1alpha1.Monitoring;
3840
import lombok.NonNull;
3941

@@ -118,4 +120,9 @@ protected HasMetadataOperationsImpl<Monitoring, MonitoringList> monitoringCustom
118120
CustomResourceDefinitionContext crdc) {
119121
return OpenShifts.admin().newHasMetadataOperation(crdc, Monitoring.class, MonitoringList.class);
120122
}
123+
124+
@Override
125+
protected HasMetadataOperationsImpl<Auth, AuthList> authCustomResourcesClient(CustomResourceDefinitionContext crdc) {
126+
return OpenShifts.admin().newHasMetadataOperation(crdc, Auth.class, AuthList.class);
127+
}
121128
}

provisioners/src/main/java/org/jboss/intersmash/provision/openshift/OpenShiftAIOpenShiftOperatorProvisioner.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717

1818
import org.jboss.intersmash.application.operator.OpenShiftAIOperatorApplication;
1919
import org.jboss.intersmash.provision.operator.OpenShiftAIOperatorProvisioner;
20+
import org.jboss.intersmash.provision.operator.model.rhoai.AuthList;
2021
import org.jboss.intersmash.provision.operator.model.rhoai.DSCInitializationList;
2122
import org.jboss.intersmash.provision.operator.model.rhoai.DataScienceClusterList;
2223
import org.jboss.intersmash.provision.operator.model.rhoai.FeatureTrackerList;
2324
import org.jboss.intersmash.provision.operator.model.rhoai.MonitoringList;
2425
import org.jboss.intersmash.rhoai.datasciencecluster.v1.DataScienceCluster;
2526
import org.jboss.intersmash.rhoai.dscinitialization.v1.DSCInitialization;
2627
import org.jboss.intersmash.rhoai.features.v1.FeatureTracker;
28+
import org.jboss.intersmash.rhoai.platform.services.v1alpha1.Auth;
2729
import org.jboss.intersmash.rhoai.platform.services.v1alpha1.Monitoring;
2830

2931
import cz.xtf.core.openshift.OpenShifts;
@@ -47,7 +49,7 @@ public class OpenShiftAIOpenShiftOperatorProvisioner
4749
// ... and common OpenShift provisioning logic, too
4850
implements OpenShiftProvisioner<OpenShiftAIOperatorApplication> {
4951

50-
private static final String OPENSHIFT_OPERATORS_NAMESPACE = "openshift-operators";
52+
private static final String OPENSHIFT_OPERATORS_NAMESPACE = "openshift-operators"; // --> redhat-ods-operator
5153

5254
public OpenShiftAIOpenShiftOperatorProvisioner(
5355
@NonNull OpenShiftAIOperatorApplication application) {
@@ -118,4 +120,9 @@ protected HasMetadataOperationsImpl<Monitoring, MonitoringList> monitoringCustom
118120
CustomResourceDefinitionContext crdc) {
119121
return OpenShifts.admin().newHasMetadataOperation(crdc, Monitoring.class, MonitoringList.class);
120122
}
123+
124+
@Override
125+
protected HasMetadataOperationsImpl<Auth, AuthList> authCustomResourcesClient(CustomResourceDefinitionContext crdc) {
126+
return OpenShifts.admin().newHasMetadataOperation(crdc, Auth.class, AuthList.class);
127+
}
121128
}

provisioners/src/main/java/org/jboss/intersmash/provision/operator/OpenDataHubOperatorProvisioner.java

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.jboss.intersmash.IntersmashConfig;
2121
import org.jboss.intersmash.application.operator.OpenDataHubOperatorApplication;
2222
import org.jboss.intersmash.provision.Provisioner;
23+
import org.jboss.intersmash.provision.operator.model.odh.AuthList;
2324
import org.jboss.intersmash.provision.operator.model.odh.DSCInitializationList;
2425
import org.jboss.intersmash.provision.operator.model.odh.DataScienceClusterList;
2526
import org.jboss.intersmash.provision.operator.model.odh.FeatureTrackerList;
@@ -39,6 +40,7 @@
3940
import io.opendatahub.datasciencecluster.v1.DataScienceCluster;
4041
import io.opendatahub.dscinitialization.v1.DSCInitialization;
4142
import io.opendatahub.features.v1.FeatureTracker;
43+
import io.opendatahub.platform.services.v1alpha1.Auth;
4244
import io.opendatahub.platform.services.v1alpha1.Monitoring;
4345
import lombok.extern.slf4j.Slf4j;
4446

@@ -95,8 +97,12 @@ public void deploy() {
9597
@Override
9698
public void undeploy() {
9799
// remove the CRs
98-
List<StatusDetails> deletionDetails = dataScienceCluster().delete();
99-
boolean deleted = deletionDetails.stream().allMatch(d -> d.getCauses().isEmpty());
100+
List<StatusDetails> deletionDetails;
101+
boolean deleted;
102+
final String appName = getApplication().getName();
103+
104+
deletionDetails = dataScienceCluster().delete();
105+
deleted = deletionDetails.stream().allMatch(d -> d.getCauses().isEmpty());
100106
if (!deleted) {
101107
log.warn("Wasn't able to remove the 'DataScienceCluster' resource");
102108
}
@@ -105,20 +111,25 @@ public void undeploy() {
105111
.level(Level.DEBUG)
106112
.waitFor();
107113

108-
if (getApplication().getDSCInitialization() != null) {
109-
final String appName = getApplication().getName();
110-
deletionDetails = dscInitializationClient().withName(appName).delete();
111-
deleted = deletionDetails.stream().allMatch(d -> d.getCauses().isEmpty());
112-
if (!deleted) {
113-
log.warn("Wasn't able to remove the 'DSCInitialization' resources created for '{}' instance!",
114-
appName);
115-
}
116-
new SimpleWaiter(() -> dscInitializationClient().list().getItems().isEmpty()).level(Level.DEBUG).waitFor();
114+
deletionDetails = dscInitializationClient().withName(appName).delete();
115+
deleted = deletionDetails.stream().allMatch(d -> d.getCauses().isEmpty());
116+
if (!deleted) {
117+
log.warn("Wasn't able to remove the 'DSCInitialization' resources created for '{}' instance!",
118+
appName);
119+
}
120+
new SimpleWaiter(() -> dscInitializationClient().list().getItems().isEmpty()).level(Level.DEBUG).waitFor();
121+
122+
deletionDetails = authClient().delete();
123+
deleted = deletionDetails.stream().allMatch(d -> d.getCauses().isEmpty());
124+
if (!deleted) {
125+
log.warn("Wasn't able to remove the 'Auth' resource");
117126
}
127+
new SimpleWaiter(() -> authClient().list().getItems().isEmpty()).level(Level.DEBUG).waitFor();
128+
118129
// delete the OLM subscription
119130
unsubscribe();
120131
new SimpleWaiter(() -> getPods().isEmpty())
121-
.reason("Waiting for the all the HyperFoil pods to be stopped.")
132+
.reason("Waiting for the all the Open Data Hub operator pods to be stopped.")
122133
.level(Level.DEBUG)
123134
.waitFor();
124135
}
@@ -147,6 +158,8 @@ public void scale(int replicas, boolean wait) {
147158

148159
protected static String ODH_MONITORING_CRD_NAME = "monitorings.services.platform.opendatahub.io";
149160

161+
protected static String ODH_AUTH_CRD_NAME = "auths.services.platform.opendatahub.io";
162+
150163
/**
151164
* Generic CRD client which is used by client builders default implementation to build the CRDs client
152165
*
@@ -170,10 +183,15 @@ protected abstract HasMetadataOperationsImpl<FeatureTracker, FeatureTrackerList>
170183
protected abstract HasMetadataOperationsImpl<Monitoring, MonitoringList> monitoringCustomResourcesClient(
171184
CustomResourceDefinitionContext crdc);
172185

186+
// auths.services.platform.opendatahub.io
187+
protected abstract HasMetadataOperationsImpl<Auth, AuthList> authCustomResourcesClient(
188+
CustomResourceDefinitionContext crdc);
189+
173190
private static NonNamespaceOperation<DataScienceCluster, DataScienceClusterList, Resource<DataScienceCluster>> ODH_DATA_SCIENCE_CLUSTER_CLIENT;
174191
private static NonNamespaceOperation<DSCInitialization, DSCInitializationList, Resource<DSCInitialization>> ODH_DSC_INITIALIZATION_CLIENT;
175192
private static NonNamespaceOperation<FeatureTracker, FeatureTrackerList, Resource<FeatureTracker>> ODH_FEATURE_TRACKER_CLIENT;
176193
private static NonNamespaceOperation<Monitoring, MonitoringList, Resource<Monitoring>> ODH_MONITORING_CLIENT;
194+
private static NonNamespaceOperation<Auth, AuthList, Resource<Auth>> ODH_AUTH_CLIENT;
177195

178196
/**
179197
* Get a client capable of working with {@link OpenDataHubOperatorProvisioner#ODH_DATA_SCIENCE_CLUSTER_CLIENT} custom resource.
@@ -249,6 +267,24 @@ public NonNamespaceOperation<Monitoring, MonitoringList, Resource<Monitoring>> m
249267
return ODH_MONITORING_CLIENT;
250268
}
251269

270+
/**
271+
* Get a client capable of working with {@link OpenDataHubOperatorProvisioner#ODH_AUTH_CLIENT} custom resource.
272+
*
273+
* @return client for operations with {@link OpenDataHubOperatorProvisioner#ODH_AUTH_CLIENT} custom resource
274+
*/
275+
public NonNamespaceOperation<Auth, AuthList, Resource<Auth>> authClient() {
276+
if (ODH_AUTH_CLIENT == null) {
277+
CustomResourceDefinition crd = customResourceDefinitionsClient()
278+
.withName(ODH_AUTH_CRD_NAME).get();
279+
if (crd == null) {
280+
throw new RuntimeException(String.format("[%s] custom resource is not provided by [%s] operator.",
281+
ODH_AUTH_CRD_NAME, OPERATOR_ID));
282+
}
283+
ODH_AUTH_CLIENT = authCustomResourcesClient(CustomResourceDefinitionContext.fromCrd(crd));
284+
}
285+
return ODH_AUTH_CLIENT;
286+
}
287+
252288
/**
253289
* Get a reference to an {@link DataScienceCluster} instance.
254290
* Use get() to obtain the actual object, or null in case it does not exist on tested cluster.

provisioners/src/main/java/org/jboss/intersmash/provision/operator/OpenShiftAIOperatorProvisioner.java

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
import org.jboss.intersmash.IntersmashConfig;
2121
import org.jboss.intersmash.application.operator.OpenShiftAIOperatorApplication;
2222
import org.jboss.intersmash.provision.Provisioner;
23+
import org.jboss.intersmash.provision.operator.model.rhoai.AuthList;
2324
import org.jboss.intersmash.provision.operator.model.rhoai.DSCInitializationList;
2425
import org.jboss.intersmash.provision.operator.model.rhoai.DataScienceClusterList;
2526
import org.jboss.intersmash.provision.operator.model.rhoai.FeatureTrackerList;
2627
import org.jboss.intersmash.provision.operator.model.rhoai.MonitoringList;
2728
import org.jboss.intersmash.rhoai.datasciencecluster.v1.DataScienceCluster;
2829
import org.jboss.intersmash.rhoai.dscinitialization.v1.DSCInitialization;
2930
import org.jboss.intersmash.rhoai.features.v1.FeatureTracker;
31+
import org.jboss.intersmash.rhoai.platform.services.v1alpha1.Auth;
3032
import org.jboss.intersmash.rhoai.platform.services.v1alpha1.Monitoring;
3133
import org.slf4j.event.Level;
3234

@@ -82,8 +84,6 @@ public void deploy() {
8284

8385
subscribe();
8486

85-
dscInitializationClient().createOrReplace(getApplication().getDSCInitialization());
86-
8787
dataScienceClusterClient().createOrReplace(getApplication().getDataScienceCluster());
8888
new SimpleWaiter(() -> dataScienceCluster().get().getStatus() != null)
8989
.failFast(ffCheck)
@@ -95,8 +95,12 @@ public void deploy() {
9595
@Override
9696
public void undeploy() {
9797
// remove the CRs
98-
List<StatusDetails> deletionDetails = dataScienceCluster().delete();
99-
boolean deleted = deletionDetails.stream().allMatch(d -> d.getCauses().isEmpty());
98+
List<StatusDetails> deletionDetails;
99+
boolean deleted;
100+
final String appName = getApplication().getName();
101+
102+
deletionDetails = dataScienceCluster().delete();
103+
deleted = deletionDetails.stream().allMatch(d -> d.getCauses().isEmpty());
100104
if (!deleted) {
101105
log.warn("Wasn't able to remove the 'DataScienceCluster' resource");
102106
}
@@ -105,16 +109,21 @@ public void undeploy() {
105109
.level(Level.DEBUG)
106110
.waitFor();
107111

108-
if (getApplication().getDSCInitialization() != null) {
109-
final String appName = getApplication().getName();
110-
deletionDetails = dscInitializationClient().withName(appName).delete();
111-
deleted = deletionDetails.stream().allMatch(d -> d.getCauses().isEmpty());
112-
if (!deleted) {
113-
log.warn("Wasn't able to remove the 'DSCInitialization' resources created for '{}' instance!",
114-
appName);
115-
}
116-
new SimpleWaiter(() -> dscInitializationClient().list().getItems().isEmpty()).level(Level.DEBUG).waitFor();
112+
deletionDetails = dscInitializationClient().delete();
113+
deleted = deletionDetails.stream().allMatch(d -> d.getCauses().isEmpty());
114+
if (!deleted) {
115+
log.warn("Wasn't able to remove the 'DSCInitialization' resources created for '{}' instance!",
116+
appName);
117117
}
118+
new SimpleWaiter(() -> dscInitializationClient().list().getItems().isEmpty()).level(Level.DEBUG).waitFor();
119+
120+
deletionDetails = authClient().delete();
121+
deleted = deletionDetails.stream().allMatch(d -> d.getCauses().isEmpty());
122+
if (!deleted) {
123+
log.warn("Wasn't able to remove the 'Auth' resource");
124+
}
125+
new SimpleWaiter(() -> authClient().list().getItems().isEmpty()).level(Level.DEBUG).waitFor();
126+
118127
// delete the OLM subscription
119128
unsubscribe();
120129
new SimpleWaiter(() -> getPods().isEmpty())
@@ -147,6 +156,8 @@ public void scale(int replicas, boolean wait) {
147156

148157
protected static String ODH_MONITORING_CRD_NAME = "monitorings.services.platform.opendatahub.io";
149158

159+
protected static String ODH_AUTH_CRD_NAME = "auths.services.platform.opendatahub.io";
160+
150161
/**
151162
* Generic CRD client which is used by client builders default implementation to build the CRDs client
152163
*
@@ -170,10 +181,15 @@ protected abstract HasMetadataOperationsImpl<FeatureTracker, FeatureTrackerList>
170181
protected abstract HasMetadataOperationsImpl<Monitoring, MonitoringList> monitoringCustomResourcesClient(
171182
CustomResourceDefinitionContext crdc);
172183

184+
// auths.services.platform.opendatahub.io
185+
protected abstract HasMetadataOperationsImpl<Auth, AuthList> authCustomResourcesClient(
186+
CustomResourceDefinitionContext crdc);
187+
173188
private static NonNamespaceOperation<DataScienceCluster, DataScienceClusterList, Resource<DataScienceCluster>> ODH_DATA_SCIENCE_CLUSTER_CLIENT;
174189
private static NonNamespaceOperation<DSCInitialization, DSCInitializationList, Resource<DSCInitialization>> ODH_DSC_INITIALIZATION_CLIENT;
175190
private static NonNamespaceOperation<FeatureTracker, FeatureTrackerList, Resource<FeatureTracker>> ODH_FEATURE_TRACKER_CLIENT;
176191
private static NonNamespaceOperation<Monitoring, MonitoringList, Resource<Monitoring>> ODH_MONITORING_CLIENT;
192+
private static NonNamespaceOperation<Auth, AuthList, Resource<Auth>> ODH_AUTH_CLIENT;
177193

178194
/**
179195
* Get a client capable of working with {@link OpenShiftAIOperatorProvisioner#ODH_DATA_SCIENCE_CLUSTER_CLIENT} custom resource.
@@ -249,6 +265,24 @@ public NonNamespaceOperation<Monitoring, MonitoringList, Resource<Monitoring>> m
249265
return ODH_MONITORING_CLIENT;
250266
}
251267

268+
/**
269+
* Get a client capable of working with {@link OpenShiftAIOperatorProvisioner#ODH_AUTH_CLIENT} custom resource.
270+
*
271+
* @return client for operations with {@link OpenShiftAIOperatorProvisioner#ODH_AUTH_CLIENT} custom resource
272+
*/
273+
public NonNamespaceOperation<Auth, AuthList, Resource<Auth>> authClient() {
274+
if (ODH_AUTH_CLIENT == null) {
275+
CustomResourceDefinition crd = customResourceDefinitionsClient()
276+
.withName(ODH_AUTH_CRD_NAME).get();
277+
if (crd == null) {
278+
throw new RuntimeException(String.format("[%s] custom resource is not provided by [%s] operator.",
279+
ODH_AUTH_CRD_NAME, OPERATOR_ID));
280+
}
281+
ODH_AUTH_CLIENT = authCustomResourcesClient(CustomResourceDefinitionContext.fromCrd(crd));
282+
}
283+
return ODH_AUTH_CLIENT;
284+
}
285+
252286
/**
253287
* Get a reference to an {@link DataScienceCluster} instance.
254288
* Use get() to obtain the actual object, or null in case it does not exist on tested cluster.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (C) 2024 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.jboss.intersmash.provision.operator.model.odh;
17+
18+
import io.fabric8.kubernetes.client.CustomResourceList;
19+
import io.opendatahub.platform.services.v1alpha1.Auth;
20+
21+
/**
22+
* Used by {@link org.jboss.intersmash.provision.operator.OpenDataHubOperatorProvisioner} client methods,
23+
* this class represents a concrete {@link java.util.List} of {@link Auth} instances.
24+
*/
25+
public class AuthList extends CustomResourceList<Auth> {
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2024 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.jboss.intersmash.provision.operator.model.rhoai;
17+
18+
import org.jboss.intersmash.rhoai.platform.services.v1alpha1.Auth;
19+
20+
import io.fabric8.kubernetes.client.CustomResourceList;
21+
22+
/**
23+
* Used by {@link org.jboss.intersmash.provision.operator.OpenDataHubOperatorProvisioner} client methods,
24+
* this class represents a concrete {@link java.util.List} of {@link Auth} instances.
25+
*/
26+
public class AuthList extends CustomResourceList<Auth> {
27+
}

0 commit comments

Comments
 (0)