This is an automated email from the ASF dual-hosted git repository.

gyfora pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-kubernetes-operator.git


The following commit(s) were added to refs/heads/main by this push:
     new 763c0f9  [FLINK-27520] Use admission-controller-framework in Webhook
763c0f9 is described below

commit 763c0f98f9c9888b1cdef85f990d1a935c3c5335
Author: Matyas Orhidi <[email protected]>
AuthorDate: Mon May 16 07:51:58 2022 +0200

    [FLINK-27520] Use admission-controller-framework in Webhook
---
 Dockerfile                                         |  4 +-
 flink-kubernetes-webhook/pom.xml                   | 54 ++++++++++++-
 .../operator/admission/AdmissionHandler.java       | 11 ++-
 .../operator/admission/FlinkValidator.java         | 19 +++--
 .../admissioncontroller/AdmissionController.java   | 53 -------------
 .../AdmissionControllerException.java              | 44 -----------
 .../admissioncontroller/AdmissionUtils.java        | 66 ----------------
 .../admissioncontroller/NotAllowedException.java   | 90 ----------------------
 .../admission/admissioncontroller/Operation.java   | 26 -------
 .../admissioncontroller/RequestHandler.java        | 27 -------
 .../admissioncontroller/clone/Cloner.java          | 30 --------
 .../clone/ObjectMapperCloner.java                  | 41 ----------
 .../mutation/DefaultRequestMutator.java            | 63 ---------------
 .../admissioncontroller/mutation/Mutator.java      | 29 -------
 .../validation/DefaultRequestValidator.java        | 59 --------------
 .../admissioncontroller/validation/Validator.java  | 31 --------
 .../src/main/resources/META-INF/NOTICE             |  5 +-
 .../operator/admission/AdmissionHandlerTest.java   |  2 +-
 pom.xml                                            |  1 +
 19 files changed, 70 insertions(+), 585 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index dd7d7d2..3efa771 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -44,7 +44,7 @@ RUN --mount=type=cache,target=/root/.m2 mvn -ntp clean 
install -pl !flink-kubern
 
 RUN cd /app/tools/license; mkdir jars; cd jars; \
     cp 
/app/flink-kubernetes-operator/target/flink-kubernetes-operator-*-shaded.jar . 
&& \
-    cp /app/flink-kubernetes-webhook/target/flink-kubernetes-webhook-*.jar . 
&& \
+    cp 
/app/flink-kubernetes-webhook/target/flink-kubernetes-webhook-*-shaded.jar . && 
\
     cp /app/flink-kubernetes-shaded/target/flink-kubernetes-shaded-*.jar . && \
     cp -r /app/flink-kubernetes-operator/target/plugins ./plugins && \
     cd ../ && ./collect_license_files.sh ./jars ./licenses-output
@@ -54,7 +54,7 @@ FROM openjdk:11-jre
 ENV FLINK_HOME=/opt/flink
 ENV OPERATOR_VERSION=1.1-SNAPSHOT
 ENV OPERATOR_JAR=flink-kubernetes-operator-$OPERATOR_VERSION-shaded.jar
-ENV WEBHOOK_JAR=flink-kubernetes-webhook-$OPERATOR_VERSION.jar
+ENV WEBHOOK_JAR=flink-kubernetes-webhook-$OPERATOR_VERSION-shaded.jar
 ENV FLINK_KUBERNETES_SHADED_JAR=flink-kubernetes-shaded-$OPERATOR_VERSION.jar
 
 WORKDIR /flink-kubernetes-operator
diff --git a/flink-kubernetes-webhook/pom.xml b/flink-kubernetes-webhook/pom.xml
index bed0c99..0daa0f9 100644
--- a/flink-kubernetes-webhook/pom.xml
+++ b/flink-kubernetes-webhook/pom.xml
@@ -21,10 +21,10 @@ under the License.
     <modelVersion>4.0.0</modelVersion>
 
     <parent>
-      <groupId>org.apache.flink</groupId>
-      <artifactId>flink-kubernetes-operator-parent</artifactId>
-      <version>1.1-SNAPSHOT</version>
-      <relativePath>..</relativePath>
+        <groupId>org.apache.flink</groupId>
+        <artifactId>flink-kubernetes-operator-parent</artifactId>
+        <version>1.1-SNAPSHOT</version>
+        <relativePath>..</relativePath>
     </parent>
 
     <artifactId>flink-kubernetes-webhook</artifactId>
@@ -36,6 +36,19 @@ under the License.
             <groupId>org.apache.flink</groupId>
             <artifactId>flink-kubernetes-operator</artifactId>
             <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>io.javaoperatorsdk</groupId>
+            <artifactId>operator-framework-framework-core</artifactId>
+            <version>${operator.sdk.admission-controller.version}</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>*</groupId>
+                    <artifactId>*</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
 
         <!-- Test -->
@@ -53,4 +66,37 @@ under the License.
             <scope>test</scope>
         </dependency>
     </dependencies>
+
+    <build>
+
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>shade-flink-webhook</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                        <configuration>
+                            
<shadedArtifactAttached>true</shadedArtifactAttached>
+                            <artifactSet>
+                                <includes combine.children="append">
+                                    
<include>io.javaoperatorsdk:operator-framework-framework-core</include>
+                                </includes>
+                            </artifactSet>
+                            <transformers combine.children="append">
+                                <transformer
+                                        
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                                    
<mainClass>org.apache.flink.kubernetes.operator.admission.FlinkOperatorWebhook</mainClass>
+                                </transformer>
+                            </transformers>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
 </project>
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/AdmissionHandler.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/AdmissionHandler.java
index 07e4a54..b204699 100644
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/AdmissionHandler.java
+++ 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/AdmissionHandler.java
@@ -17,9 +17,6 @@
 
 package org.apache.flink.kubernetes.operator.admission;
 
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.AdmissionController;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.validation.Validator;
-
 import org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf;
 import org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream;
 import org.apache.flink.shaded.netty4.io.netty.buffer.Unpooled;
@@ -40,8 +37,10 @@ import 
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.LastHttpConten
 import 
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
-import io.fabric8.kubernetes.api.model.KubernetesResource;
+import io.fabric8.kubernetes.api.model.HasMetadata;
 import io.fabric8.kubernetes.api.model.admission.v1.AdmissionReview;
+import io.javaoperatorsdk.admissioncontroller.AdmissionController;
+import io.javaoperatorsdk.admissioncontroller.validation.Validator;
 import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -64,9 +63,9 @@ public class AdmissionHandler extends 
SimpleChannelInboundHandler<HttpRequest> {
     private static final ObjectMapper objectMapper = new ObjectMapper();
     protected static final String VALIDATE_REQUEST_PATH = "/validate";
 
-    private final AdmissionController<KubernetesResource> validatingController;
+    private final AdmissionController<HasMetadata> validatingController;
 
-    public AdmissionHandler(Validator<KubernetesResource> validator) {
+    public AdmissionHandler(Validator<HasMetadata> validator) {
         this.validatingController = new AdmissionController<>(validator);
     }
 
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/FlinkValidator.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/FlinkValidator.java
index 5882a54..a1cb2bb 100644
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/FlinkValidator.java
+++ 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/FlinkValidator.java
@@ -17,9 +17,6 @@
 
 package org.apache.flink.kubernetes.operator.admission;
 
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.NotAllowedException;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.Operation;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.validation.Validator;
 import org.apache.flink.kubernetes.operator.config.FlinkConfigManager;
 import org.apache.flink.kubernetes.operator.crd.CrdConstants;
 import org.apache.flink.kubernetes.operator.crd.FlinkDeployment;
@@ -28,10 +25,13 @@ import 
org.apache.flink.kubernetes.operator.informer.InformerManager;
 import org.apache.flink.kubernetes.operator.validation.FlinkResourceValidator;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
-import io.fabric8.kubernetes.api.model.GroupVersionKind;
+import io.fabric8.kubernetes.api.model.HasMetadata;
 import io.fabric8.kubernetes.api.model.KubernetesResource;
 import io.fabric8.kubernetes.client.DefaultKubernetesClient;
 import io.fabric8.kubernetes.client.informers.cache.Cache;
+import io.javaoperatorsdk.admissioncontroller.NotAllowedException;
+import io.javaoperatorsdk.admissioncontroller.Operation;
+import io.javaoperatorsdk.admissioncontroller.validation.Validator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,7 +39,7 @@ import java.util.Optional;
 import java.util.Set;
 
 /** Validator for FlinkDeployment creation and updates. */
-public class FlinkValidator implements Validator<KubernetesResource> {
+public class FlinkValidator implements Validator<HasMetadata> {
     private static final Logger LOG = 
LoggerFactory.getLogger(FlinkValidator.class);
     private static final ObjectMapper objectMapper = new ObjectMapper();
 
@@ -56,16 +56,15 @@ public class FlinkValidator implements 
Validator<KubernetesResource> {
     }
 
     @Override
-    public void validate(KubernetesResource resource, Operation operation, 
GroupVersionKind kind)
-            throws NotAllowedException {
+    public void validate(HasMetadata resource, Operation operation) throws 
NotAllowedException {
         LOG.debug("Validating resource {}", resource);
 
-        if (CrdConstants.KIND_FLINK_DEPLOYMENT.equals(kind.getKind())) {
+        if (CrdConstants.KIND_FLINK_DEPLOYMENT.equals(resource.getKind())) {
             validateDeployment(resource);
-        } else if (CrdConstants.KIND_SESSION_JOB.equals(kind.getKind())) {
+        } else if (CrdConstants.KIND_SESSION_JOB.equals(resource.getKind())) {
             validateSessionJob(resource);
         } else {
-            throw new NotAllowedException("Unexpected resource: " + 
kind.getKind());
+            throw new NotAllowedException("Unexpected resource: " + 
resource.getKind());
         }
     }
 
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/AdmissionController.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/AdmissionController.java
deleted file mode 100644
index b262166..0000000
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/AdmissionController.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.admission.admissioncontroller;
-
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.mutation.DefaultRequestMutator;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.mutation.Mutator;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.validation.DefaultRequestValidator;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.validation.Validator;
-
-import io.fabric8.kubernetes.api.model.KubernetesResource;
-import io.fabric8.kubernetes.api.model.admission.v1.AdmissionResponse;
-import io.fabric8.kubernetes.api.model.admission.v1.AdmissionReview;
-
-/** Copied as is from 
https://github.com/java-operator-sdk/admission-controller-framework. */
-public class AdmissionController<T extends KubernetesResource> {
-
-    private final RequestHandler requestHandler;
-
-    public AdmissionController(Mutator<T> mutator) {
-        this(new DefaultRequestMutator<>(mutator));
-    }
-
-    public AdmissionController(Validator<T> validator) {
-        this(new DefaultRequestValidator<>(validator));
-    }
-
-    public AdmissionController(RequestHandler requestHandler) {
-        this.requestHandler = requestHandler;
-    }
-
-    public AdmissionReview handle(AdmissionReview admissionReview) {
-        AdmissionResponse response = 
requestHandler.handle(admissionReview.getRequest());
-        AdmissionReview responseAdmissionReview = new AdmissionReview();
-        responseAdmissionReview.setResponse(response);
-        response.setUid(admissionReview.getRequest().getUid());
-        return responseAdmissionReview;
-    }
-}
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/AdmissionControllerException.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/AdmissionControllerException.java
deleted file mode 100644
index 8bff353..0000000
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/AdmissionControllerException.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.admission.admissioncontroller;
-
-/** Copied as is from 
https://github.com/java-operator-sdk/admission-controller-framework. */
-public class AdmissionControllerException extends RuntimeException {
-
-    public AdmissionControllerException() {}
-
-    public AdmissionControllerException(String message) {
-        super(message);
-    }
-
-    public AdmissionControllerException(String message, Throwable cause) {
-        super(message, cause);
-    }
-
-    public AdmissionControllerException(Throwable cause) {
-        super(cause);
-    }
-
-    public AdmissionControllerException(
-            String message,
-            Throwable cause,
-            boolean enableSuppression,
-            boolean writableStackTrace) {
-        super(message, cause, enableSuppression, writableStackTrace);
-    }
-}
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/AdmissionUtils.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/AdmissionUtils.java
deleted file mode 100644
index 8adf162..0000000
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/AdmissionUtils.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.admission.admissioncontroller;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import io.fabric8.kubernetes.api.model.KubernetesResource;
-import io.fabric8.kubernetes.api.model.admission.v1.AdmissionRequest;
-import io.fabric8.kubernetes.api.model.admission.v1.AdmissionResponse;
-import io.fabric8.zjsonpatch.JsonDiff;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Base64;
-
-/** Copied as is from 
https://github.com/java-operator-sdk/admission-controller-framework. */
-public class AdmissionUtils {
-
-    public static final String JSON_PATCH = "JSONPatch";
-    private static final ObjectMapper mapper = new ObjectMapper();
-
-    public static AdmissionResponse notAllowedExceptionToAdmissionResponse(
-            NotAllowedException notAllowedException) {
-        AdmissionResponse admissionResponse = new AdmissionResponse();
-        admissionResponse.setAllowed(false);
-        admissionResponse.setStatus(notAllowedException.getStatus());
-        return admissionResponse;
-    }
-
-    public static KubernetesResource getTargetResource(
-            AdmissionRequest admissionRequest, Operation operation) {
-        return operation == Operation.DELETE
-                ? admissionRequest.getOldObject()
-                : admissionRequest.getObject();
-    }
-
-    public static AdmissionResponse admissionResponseFromMutation(
-            KubernetesResource originalResource, KubernetesResource 
mutatedResource) {
-        AdmissionResponse admissionResponse = new AdmissionResponse();
-        admissionResponse.setAllowed(true);
-        admissionResponse.setPatchType(JSON_PATCH);
-        JsonNode originalResNode = mapper.valueToTree(originalResource);
-        JsonNode mutatedResNode = mapper.valueToTree(mutatedResource);
-
-        JsonNode diff = JsonDiff.asJson(originalResNode, mutatedResNode);
-        String base64Diff =
-                Base64.getEncoder()
-                        
.encodeToString(diff.toString().getBytes(StandardCharsets.UTF_8));
-        admissionResponse.setPatch(base64Diff);
-        return admissionResponse;
-    }
-}
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/NotAllowedException.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/NotAllowedException.java
deleted file mode 100644
index 457d398..0000000
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/NotAllowedException.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.admission.admissioncontroller;
-
-import io.fabric8.kubernetes.api.model.Status;
-
-/** Copied as is from 
https://github.com/java-operator-sdk/admission-controller-framework. */
-public class NotAllowedException extends AdmissionControllerException {
-
-    private Status status = new Status();
-
-    public NotAllowedException() {
-        status.setCode(403);
-    }
-
-    public NotAllowedException(Status status) {
-        this.status = status;
-    }
-
-    public NotAllowedException(Throwable cause, Status status) {
-        super(cause);
-        this.status = status;
-    }
-
-    public NotAllowedException(
-            String message,
-            Throwable cause,
-            boolean enableSuppression,
-            boolean writableStackTrace,
-            Status status) {
-        super(message, cause, enableSuppression, writableStackTrace);
-        this.status = status;
-    }
-
-    public NotAllowedException(String message) {
-        super(message);
-        this.status.setMessage(message);
-        this.status.setCode(403);
-    }
-
-    public NotAllowedException(int code) {
-        this.status.setCode(code);
-    }
-
-    public NotAllowedException(String message, int code) {
-        super(message);
-        this.status.setCode(code);
-        this.status.setMessage(message);
-    }
-
-    public NotAllowedException(String message, Throwable cause, int code) {
-        super(message, cause);
-        this.status.setCode(code);
-        this.status.setMessage(message);
-    }
-
-    public NotAllowedException(Throwable cause, int code) {
-        super(cause);
-        this.status.setCode(code);
-    }
-
-    public NotAllowedException(
-            String message,
-            Throwable cause,
-            boolean enableSuppression,
-            boolean writableStackTrace,
-            int code) {
-        super(message, cause, enableSuppression, writableStackTrace);
-        status.setCode(code);
-    }
-
-    public Status getStatus() {
-        return status;
-    }
-}
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/Operation.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/Operation.java
deleted file mode 100644
index e2065e2..0000000
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/Operation.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.admission.admissioncontroller;
-
-/** Copied as is from 
https://github.com/java-operator-sdk/admission-controller-framework. */
-public enum Operation {
-    CREATE,
-    UPDATE,
-    DELETE,
-    CONNECT
-}
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/RequestHandler.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/RequestHandler.java
deleted file mode 100644
index 3899d03..0000000
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/RequestHandler.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.admission.admissioncontroller;
-
-import io.fabric8.kubernetes.api.model.admission.v1.AdmissionRequest;
-import io.fabric8.kubernetes.api.model.admission.v1.AdmissionResponse;
-
-/** Copied as is from 
https://github.com/java-operator-sdk/admission-controller-framework. */
-public interface RequestHandler {
-
-    AdmissionResponse handle(AdmissionRequest admissionRequest);
-}
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/clone/Cloner.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/clone/Cloner.java
deleted file mode 100644
index 24605a4..0000000
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/clone/Cloner.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.admission.admissioncontroller.clone;
-
-/** Copied as is from 
https://github.com/java-operator-sdk/admission-controller-framework. */
-public interface Cloner<R> {
-
-    /**
-     * Returns a deep copy of the given object if not {@code null} or {@code 
null} otherwise.
-     *
-     * @param object the object to be cloned
-     * @return a deep copy of the given object if it isn't {@code null}, 
{@code null} otherwise
-     */
-    R clone(R object);
-}
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/clone/ObjectMapperCloner.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/clone/ObjectMapperCloner.java
deleted file mode 100644
index 296cd31..0000000
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/clone/ObjectMapperCloner.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.admission.admissioncontroller.clone;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-/** Copied as is from 
https://github.com/java-operator-sdk/admission-controller-framework. */
-public class ObjectMapperCloner<T> implements Cloner<T> {
-
-    private final ObjectMapper objectMapper = new ObjectMapper();
-
-    @Override
-    public T clone(T object) {
-        if (object == null) {
-            return null;
-        }
-        try {
-            return (T)
-                    objectMapper.readValue(
-                            objectMapper.writeValueAsString(object), 
object.getClass());
-        } catch (JsonProcessingException e) {
-            throw new IllegalStateException(e);
-        }
-    }
-}
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/mutation/DefaultRequestMutator.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/mutation/DefaultRequestMutator.java
deleted file mode 100644
index 1d500e7..0000000
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/mutation/DefaultRequestMutator.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.admission.admissioncontroller.mutation;
-
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.AdmissionUtils;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.NotAllowedException;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.Operation;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.RequestHandler;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.clone.Cloner;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.clone.ObjectMapperCloner;
-
-import io.fabric8.kubernetes.api.model.KubernetesResource;
-import io.fabric8.kubernetes.api.model.admission.v1.AdmissionRequest;
-import io.fabric8.kubernetes.api.model.admission.v1.AdmissionResponse;
-
-import static 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.AdmissionUtils.admissionResponseFromMutation;
-import static 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.AdmissionUtils.getTargetResource;
-
-/** Copied as is from 
https://github.com/java-operator-sdk/admission-controller-framework. */
-public class DefaultRequestMutator<T extends KubernetesResource> implements 
RequestHandler {
-
-    private final Mutator<T> mutator;
-    private final Cloner<T> cloner;
-
-    public DefaultRequestMutator(Mutator<T> mutator) {
-        this(mutator, new ObjectMapperCloner<>());
-    }
-
-    public DefaultRequestMutator(Mutator<T> mutator, Cloner<T> cloner) {
-        this.mutator = mutator;
-        this.cloner = cloner;
-    }
-
-    @Override
-    public AdmissionResponse handle(AdmissionRequest admissionRequest) {
-        Operation operation = 
Operation.valueOf(admissionRequest.getOperation());
-        T originalResource = (T) getTargetResource(admissionRequest, 
operation);
-        T clonedResource = cloner.clone(originalResource);
-        AdmissionResponse admissionResponse;
-        try {
-            T mutatedResource = mutator.mutate(clonedResource, operation);
-            admissionResponse = 
admissionResponseFromMutation(originalResource, mutatedResource);
-        } catch (NotAllowedException e) {
-            admissionResponse = 
AdmissionUtils.notAllowedExceptionToAdmissionResponse(e);
-        }
-        return admissionResponse;
-    }
-}
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/mutation/Mutator.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/mutation/Mutator.java
deleted file mode 100644
index 3443233..0000000
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/mutation/Mutator.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.admission.admissioncontroller.mutation;
-
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.NotAllowedException;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.Operation;
-
-import io.fabric8.kubernetes.api.model.KubernetesResource;
-
-/** Copied as is from 
https://github.com/java-operator-sdk/admission-controller-framework. */
-public interface Mutator<T extends KubernetesResource> {
-
-    T mutate(T resource, Operation operation) throws NotAllowedException;
-}
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/validation/DefaultRequestValidator.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/validation/DefaultRequestValidator.java
deleted file mode 100644
index f1235ef..0000000
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/validation/DefaultRequestValidator.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.admission.admissioncontroller.validation;
-
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.AdmissionUtils;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.NotAllowedException;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.Operation;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.RequestHandler;
-
-import io.fabric8.kubernetes.api.model.KubernetesResource;
-import io.fabric8.kubernetes.api.model.admission.v1.AdmissionRequest;
-import io.fabric8.kubernetes.api.model.admission.v1.AdmissionResponse;
-
-import static 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.AdmissionUtils.getTargetResource;
-
-/** Copied as is from 
https://github.com/java-operator-sdk/admission-controller-framework. */
-public class DefaultRequestValidator<T extends KubernetesResource> implements 
RequestHandler {
-
-    private final Validator<T> validator;
-
-    public DefaultRequestValidator(Validator<T> validator) {
-        this.validator = validator;
-    }
-
-    @Override
-    public AdmissionResponse handle(AdmissionRequest admissionRequest) {
-        Operation operation = 
Operation.valueOf(admissionRequest.getOperation());
-        T originalResource = (T) getTargetResource(admissionRequest, 
operation);
-        AdmissionResponse admissionResponse;
-        try {
-            validator.validate(originalResource, operation, 
admissionRequest.getKind());
-            admissionResponse = allowedAdmissionResponse();
-        } catch (NotAllowedException e) {
-            admissionResponse = 
AdmissionUtils.notAllowedExceptionToAdmissionResponse(e);
-        }
-        return admissionResponse;
-    }
-
-    private AdmissionResponse allowedAdmissionResponse() {
-        AdmissionResponse admissionResponse = new AdmissionResponse();
-        admissionResponse.setAllowed(true);
-        return admissionResponse;
-    }
-}
diff --git 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/validation/Validator.java
 
b/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/validation/Validator.java
deleted file mode 100644
index e96a28f..0000000
--- 
a/flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller/validation/Validator.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.admission.admissioncontroller.validation;
-
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.NotAllowedException;
-import 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.Operation;
-
-import io.fabric8.kubernetes.api.model.GroupVersionKind;
-import io.fabric8.kubernetes.api.model.KubernetesResource;
-
-/** Copied as is from 
https://github.com/java-operator-sdk/admission-controller-framework. */
-public interface Validator<T extends KubernetesResource> {
-
-    void validate(T resource, Operation operation, GroupVersionKind kind)
-            throws NotAllowedException;
-}
diff --git a/flink-kubernetes-webhook/src/main/resources/META-INF/NOTICE 
b/flink-kubernetes-webhook/src/main/resources/META-INF/NOTICE
index 288830c..150a7f2 100644
--- a/flink-kubernetes-webhook/src/main/resources/META-INF/NOTICE
+++ b/flink-kubernetes-webhook/src/main/resources/META-INF/NOTICE
@@ -4,7 +4,6 @@ Copyright 2014-2022 The Apache Software Foundation
 This product includes software developed at
 The Apache Software Foundation (http://www.apache.org/).
 
-This project contains copied and modified source code that is licensed under 
the Apache Software License 2.0 
(http://www.apache.org/licenses/LICENSE-2.0.txt) from the following projects:
+This project bundles the following dependencies under the Apache Software 
License 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt)
 
-- admission-controller-framework 
(https://github.com/java-operator-sdk/admission-controller-framework)
-  The copied sources can be located under 
flink-kubernetes-webhook/src/main/java/org/apache/flink/kubernetes/operator/admission/admissioncontroller
+- io.javaoperatorsdk:operator-framework-framework-core:jar:0.2.0
diff --git 
a/flink-kubernetes-webhook/src/test/java/org/apache/flink/kubernetes/operator/admission/AdmissionHandlerTest.java
 
b/flink-kubernetes-webhook/src/test/java/org/apache/flink/kubernetes/operator/admission/AdmissionHandlerTest.java
index 2e260be..71adc90 100644
--- 
a/flink-kubernetes-webhook/src/test/java/org/apache/flink/kubernetes/operator/admission/AdmissionHandlerTest.java
+++ 
b/flink-kubernetes-webhook/src/test/java/org/apache/flink/kubernetes/operator/admission/AdmissionHandlerTest.java
@@ -37,8 +37,8 @@ import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 
+import static io.javaoperatorsdk.admissioncontroller.Operation.CREATE;
 import static 
org.apache.flink.kubernetes.operator.admission.AdmissionHandler.VALIDATE_REQUEST_PATH;
-import static 
org.apache.flink.kubernetes.operator.admission.admissioncontroller.Operation.CREATE;
 import static 
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod.GET;
 import static 
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR;
 import static 
org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus.OK;
diff --git a/pom.xml b/pom.xml
index 99687ef..db2f344 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,6 +67,7 @@ under the License.
         
<git-commit-id-maven-plugin.version>5.0.0</git-commit-id-maven-plugin.version>
 
         <operator.sdk.version>2.1.4</operator.sdk.version>
+        
<operator.sdk.admission-controller.version>0.2.0</operator.sdk.admission-controller.version>
         <fabric8.version>5.12.2</fabric8.version>
         <lombok.version>1.18.22</lombok.version>
 

Reply via email to