3
3
import com .openshift .cloud .beans .AccessTokenSecretTool ;
4
4
import com .openshift .cloud .beans .KafkaApiClient ;
5
5
import com .openshift .cloud .beans .KafkaK8sClients ;
6
+ import com .openshift .cloud .utils .InvalidUserInputException ;
6
7
import com .openshift .cloud .v1alpha .models .CloudServicesRequest ;
7
8
import com .openshift .cloud .v1alpha .models .UserKafka ;
8
9
import io .javaoperatorsdk .operator .api .*;
@@ -26,11 +27,7 @@ public class CloudServicesRequestController
26
27
27
28
public CloudServicesRequestController () {}
28
29
29
- /**
30
- * @param resource the resource to check for new kafkas
31
- * @return true if there were changes, false otherwise
32
- * @throws ApiException if something goes wrong connecting to services
33
- */
30
+ /** @return true if there were changes, false otherwise */
34
31
@ Override
35
32
public void init (EventSourceManager eventSourceManager ) {
36
33
LOG .info ("Init! This is where we would add watches for child resources" );
@@ -39,9 +36,10 @@ public void init(EventSourceManager eventSourceManager) {
39
36
@ Override
40
37
void doCreateOrUpdateResource (
41
38
CloudServicesRequest resource , Context <CloudServicesRequest > context )
42
- throws ConditionAwareException {
39
+ throws ConditionAwareException , InvalidUserInputException {
43
40
var accessTokenSecretName = resource .getSpec ().getAccessTokenSecretName ();
44
41
var namespace = resource .getMetadata ().getNamespace ();
42
+ validateResource (resource );
45
43
String accessToken = null ;
46
44
accessToken = accessTokenSecretTool .getAccessToken (accessTokenSecretName , namespace );
47
45
@@ -69,4 +67,11 @@ void doCreateOrUpdateResource(
69
67
70
68
resource .getStatus ().setUserKafkas (userKafkas );
71
69
}
70
+
71
+ void validateResource (CloudServicesRequest resource ) throws InvalidUserInputException {
72
+ ConditionUtil .assertNotNull (resource .getSpec (), "spec" );
73
+ ConditionUtil .assertNotNull (
74
+ resource .getSpec ().getAccessTokenSecretName (), "spec.accessTokenSecretName" );
75
+ ConditionUtil .assertNotNull (resource .getMetadata ().getNamespace (), "metadata.namespace" );
76
+ }
72
77
}
0 commit comments