gyfora commented on a change in pull request #112: URL: https://github.com/apache/flink-kubernetes-operator/pull/112#discussion_r835766658
########## File path: flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/controller/FlinkSessionJobController.java ########## @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.kubernetes.operator.controller; + +import org.apache.flink.kubernetes.operator.config.DefaultConfig; +import org.apache.flink.kubernetes.operator.config.FlinkOperatorConfiguration; +import org.apache.flink.kubernetes.operator.crd.FlinkSessionJob; +import org.apache.flink.kubernetes.operator.exception.ReconciliationException; +import org.apache.flink.kubernetes.operator.observer.Observer; +import org.apache.flink.kubernetes.operator.reconciler.Reconciler; +import org.apache.flink.kubernetes.operator.reconciler.ReconciliationUtils; +import org.apache.flink.kubernetes.operator.validation.InternalValidator; + +import io.fabric8.kubernetes.client.KubernetesClient; +import io.javaoperatorsdk.operator.api.reconciler.Context; +import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration; +import io.javaoperatorsdk.operator.api.reconciler.DeleteControl; +import io.javaoperatorsdk.operator.api.reconciler.ErrorStatusHandler; +import io.javaoperatorsdk.operator.api.reconciler.RetryInfo; +import io.javaoperatorsdk.operator.api.reconciler.UpdateControl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Optional; + +/** Controller that runs the main reconcile loop for {@link FlinkSessionJob}. */ +@ControllerConfiguration +public class FlinkSessionJobController + implements io.javaoperatorsdk.operator.api.reconciler.Reconciler<FlinkSessionJob>, + ErrorStatusHandler<FlinkSessionJob> { + + private static final Logger LOG = LoggerFactory.getLogger(FlinkSessionJobController.class); + private final KubernetesClient kubernetesClient; + + private final InternalValidator<FlinkSessionJob> validator; + private final Reconciler<FlinkSessionJob> reconciler; + private final Observer<FlinkSessionJob> observer; + private final DefaultConfig defaultConfig; + private final FlinkOperatorConfiguration operatorConfiguration; + + private FlinkControllerConfig<FlinkSessionJob> controllerConfig; + + public FlinkSessionJobController( + DefaultConfig defaultConfig, + FlinkOperatorConfiguration operatorConfiguration, + KubernetesClient kubernetesClient, + InternalValidator<FlinkSessionJob> validator, + Reconciler<FlinkSessionJob> reconciler, + Observer<FlinkSessionJob> observer) { + this.defaultConfig = defaultConfig; + this.operatorConfiguration = operatorConfiguration; + this.kubernetesClient = kubernetesClient; + this.validator = validator; + this.reconciler = reconciler; + this.observer = observer; + } + + @Override + public UpdateControl<FlinkSessionJob> reconcile( + FlinkSessionJob flinkSessionJob, Context context) { + FlinkSessionJob originalCopy = ReconciliationUtils.clone(flinkSessionJob); + LOG.info("Starting reconciliation"); + Optional<String> validationError = validator.validate(flinkSessionJob); + if (validationError.isPresent()) { + LOG.error("Validation failed: " + validationError.get()); + ReconciliationUtils.updateForReconciliationError( + flinkSessionJob, validationError.get()); + return ReconciliationUtils.toUpdateControl(originalCopy, flinkSessionJob); + } + + try { + // TODO refactor the reconciler interface to return UpdateControl directly Review comment: I think this is a good idea and will make the code cleaner. I wonder if it makes sense to restrict the context to contain 1 specific resource, what if we need 2? We can iterate more on this design after the release. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
