You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by gy...@apache.org on 2022/02/16 10:34:08 UTC

[flink-kubernetes-operator] 15/23: adding helm chart

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

commit 411afb3cb2e6f9bd27bc2a1fb3e19ad16b84549b
Author: Matyas Orhidi <ma...@apple.com>
AuthorDate: Wed Feb 9 10:53:08 2022 +0100

    adding helm chart
---
 .gitignore                                         |   2 +
 Dockerfile                                         |   7 +-
 README.md                                          |  39 ++++---
 helm/flink-operator/.helmignore                    |  23 ++++
 Dockerfile => helm/flink-operator/Chart.yaml       |  22 ++--
 helm/flink-operator/templates/_helpers.tpl         |  79 ++++++++++++++
 .../flink-operator/templates}/flink-operator.yaml  |  54 ++++++----
 .../flink-operator/templates}/rbac.yaml            | 117 ++++++++++-----------
 .../flink-operator/templates/serviceaccount.yaml   |  29 +++--
 Dockerfile => helm/flink-operator/values.yaml      |  29 +++--
 pom.xml                                            |  30 ++++++
 11 files changed, 283 insertions(+), 148 deletions(-)

diff --git a/.gitignore b/.gitignore
index 95cd8a3..c99feeb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,3 +36,5 @@ buildNumber.properties
 .idea
 *.iml
 
+helm/flink-operator/templates/flinkdeployments.flink.io-v1.yml
+
diff --git a/Dockerfile b/Dockerfile
index c834e97..4df54f9 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -19,11 +19,12 @@
 FROM maven:3.8.4-openjdk-11 AS build
 WORKDIR /app
 
-COPY src ./src
-COPY tools ./tools
 COPY pom.xml .
+RUN --mount=type=cache,target=/root/.m2 mvn dependency:resolve
 
-RUN mvn -f ./pom.xml clean install
+COPY src ./src
+COPY tools ./tools
+RUN --mount=type=cache,target=/root/.m2 mvn -f ./pom.xml clean install
 
 # stage
 FROM openjdk:11-jre
diff --git a/README.md b/README.md
index 0f8de60..da958d4 100644
--- a/README.md
+++ b/README.md
@@ -1,32 +1,22 @@
 # flink-kubernetes-operator
 Temporary repository for Flink Kubernetes Operator. The content will be moved to OSS repo once created an IPR. Check [FLIP-212](https://cwiki.apache.org/confluence/display/FLINK/FLIP-212%3A+Introduce+Flink+Kubernetes+Operator) further info.
 
-## How to Build
-```
-mvn clean install
-```
+## Installation
 
-## How to Run
-* Make Sure that `FlinkDeployment` Custom Resource Definition is already applied onto the cluster. If not, issue the following commands to apply:
-```
-kubectl create -f target/classes/META-INF/fabric8/flinkdeployments.flink.io-v1.yml
-```
-* (Optional) Build Docker Image
-```
-docker build . -t docker.apple.com/gyula_fora/flink-java-operator:latest
-```
-* Start flink-operator deployment. A new `ServiceAccount` "flink-operator" will be created with enough permission to create/list pods and services.
+The operator is managed helm chart. To install run:
 ```
-kubectl create -f deploy/rbac.yaml
-kubectl create -f deploy/flink-operator.yaml
+ cd helm/flink-operator
+ helm install flink-operator .
 ```
-* Create a new Flink deployment
+
+## User Guide
+### Create a new Flink deployment
 The flink-operator will watch the CRD resources and submit a new Flink deployment once the CR it applied.
 ```
 kubectl create -f examples/basic.yaml
 ```
 
-* Delete a Flink deployment
+### Delete a Flink deployment
 ```
 kubectl delete -f create/basic.yaml
 
@@ -35,17 +25,24 @@ OR
 kubectl delete flinkdep {dep_name}
 ```
 
-* Get/List Flink deployments
+### Get/List Flink deployments
 Get all the Flink deployments running in the K8s cluster
 ```
 kubectl get flinkdep
 ```
-
 Describe a specific Flink deployment to show the status(including job status, savepoint, ect.)
 ```
 kubectl describe flinkdep {dep_name}
 ```
-## How to Debug
+## Developer Guide
+
+### Building docker images
+```
+docker build . -t <repo>/flink-java-operator:latest
+docker push <repo>flink-java-operator:latest
+helm install flink-operator . --set image.repository=<repo> --set image.tag=latest
+```
+### Running the operator locally
 You can run or debug the `FlinkOperator` from your preferred IDE. The operator itself is accessing the deployed Flink clusters through the REST interface. When running locally the `rest.port` and `rest.address` Flink configuration parameters must be modified to a locally accessible value. 
 
 When using `minikube tunnel` the rest service is exposed on `localhost:8081`
diff --git a/helm/flink-operator/.helmignore b/helm/flink-operator/.helmignore
new file mode 100644
index 0000000..0e8a0eb
--- /dev/null
+++ b/helm/flink-operator/.helmignore
@@ -0,0 +1,23 @@
+# Patterns to ignore when building packages.
+# This supports shell glob matching, relative path matching, and
+# negation (prefixed with !). Only one pattern per line.
+.DS_Store
+# Common VCS dirs
+.git/
+.gitignore
+.bzr/
+.bzrignore
+.hg/
+.hgignore
+.svn/
+# Common backup files
+*.swp
+*.bak
+*.tmp
+*.orig
+*~
+# Various IDEs
+.project
+.idea/
+*.tmproj
+.vscode/
diff --git a/Dockerfile b/helm/flink-operator/Chart.yaml
similarity index 76%
copy from Dockerfile
copy to helm/flink-operator/Chart.yaml
index c834e97..435fe32 100644
--- a/Dockerfile
+++ b/helm/flink-operator/Chart.yaml
@@ -15,19 +15,11 @@
 #  See the License for the specific language governing permissions and
 # limitations under the License.
 ################################################################################
-# Build
-FROM maven:3.8.4-openjdk-11 AS build
-WORKDIR /app
 
-COPY src ./src
-COPY tools ./tools
-COPY pom.xml .
-
-RUN mvn -f ./pom.xml clean install
-
-# stage
-FROM openjdk:11-jre
-
-COPY --from=build /app/target/flink-operator-1.0-SNAPSHOT.jar /
-
-CMD ["java", "-jar", "/flink-operator-1.0-SNAPSHOT.jar"]
+---
+apiVersion: v2
+name: flink-operator
+description: A Helm chart for flink-operator
+type: application
+version: 0.1.0
+appVersion: "1.0.13"
diff --git a/helm/flink-operator/templates/_helpers.tpl b/helm/flink-operator/templates/_helpers.tpl
new file mode 100644
index 0000000..ab9e968
--- /dev/null
+++ b/helm/flink-operator/templates/_helpers.tpl
@@ -0,0 +1,79 @@
+################################################################################
+#  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.
+################################################################################
+
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "flink-operator.name" -}}
+{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Create a default fully qualified app name.
+We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
+If release name contains chart name it will be used as a full name.
+*/}}
+{{- define "flink-operator.fullname" -}}
+{{- if .Values.fullnameOverride }}
+{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
+{{- else }}
+{{- $name := default .Chart.Name .Values.nameOverride }}
+{{- if contains $name .Release.Name }}
+{{- .Release.Name | trunc 63 | trimSuffix "-" }}
+{{- else }}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
+{{- end }}
+{{- end }}
+{{- end }}
+
+{{/*
+Create chart name and version as used by the chart label.
+*/}}
+{{- define "flink-operator.chart" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Common labels
+*/}}
+{{- define "flink-operator.labels" -}}
+{{ include "flink-operator.selectorLabels" . }}
+{{- if .Chart.AppVersion }}
+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
+{{- end }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+helm.sh/chart: {{ include "flink-operator.chart" . }}
+{{- end }}
+
+{{/*
+Selector labels
+*/}}
+{{- define "flink-operator.selectorLabels" -}}
+app.kubernetes.io/name: {{ include "flink-operator.name" . }}
+{{- end }}
+
+{{/*
+Create the name of the service account to use
+*/}}
+{{- define "flink-operator.serviceAccountName" -}}
+{{- if .Values.serviceAccount.create }}
+{{- default (include "flink-operator.fullname" .) .Values.serviceAccount.name }}
+{{- else }}
+{{- default "default" .Values.serviceAccount.name }}
+{{- end }}
+{{- end }}
diff --git a/deploy/flink-operator.yaml b/helm/flink-operator/templates/flink-operator.yaml
similarity index 74%
rename from deploy/flink-operator.yaml
rename to helm/flink-operator/templates/flink-operator.yaml
index b7574b5..6ea9f71 100644
--- a/deploy/flink-operator.yaml
+++ b/helm/flink-operator/templates/flink-operator.yaml
@@ -16,49 +16,57 @@
 # limitations under the License.
 ################################################################################
 
+---
 apiVersion: apps/v1
 kind: Deployment
 metadata:
-  name: flink-operator
+  name: {{ include "flink-operator.name" . }}
+  namespace: {{ .Values.operatorNamespace.name }}
+  labels:
+    {{- include "flink-operator.labels" . | nindent 4 }}
 spec:
   replicas: 1
   selector:
     matchLabels:
-      app: flink-operator
+      {{- include "flink-operator.selectorLabels" . | nindent 6 }}
   template:
     metadata:
       labels:
-        app: flink-operator
+        {{- include "flink-operator.selectorLabels" . | nindent 8 }}
     spec:
-      serviceAccountName: flink-operator
+      {{- with .Values.imagePullSecrets }}
+      imagePullSecrets:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      serviceAccountName: {{ include "flink-operator.serviceAccountName" . }}
       containers:
-      - name: flink-operator
-        image: docker.apple.com/aiml/dpi-flink/flink-operator:1.0.7
-        imagePullPolicy: Always
-        env:
-          - name: FLINK_CONF_DIR
-            value: /opt/flink/conf
-        volumeMounts:
-        - name: flink-config-volume
-          mountPath: /opt/flink/conf
+        - name: {{ .Chart.Name }}
+          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
+          imagePullPolicy: {{ .Values.image.pullPolicy }}
+          env:
+            - name: FLINK_CONF_DIR
+              value: /opt/flink/conf
+          volumeMounts:
+            - name: flink-config-volume
+              mountPath: /opt/flink/conf
       volumes:
-      - name: flink-config-volume
-        configMap:
-          name: flink-operator-config
-          items:
-          - key: flink-conf.yaml
-            path: flink-conf.yaml
-          - key: log4j-console.properties
-            path: log4j-console.properties
-
+        - name: flink-config-volume
+          configMap:
+            name: flink-operator-config
+            items:
+              - key: flink-conf.yaml
+                path: flink-conf.yaml
+              - key: log4j-console.properties
+                path: log4j-console.properties
 ---
 
 apiVersion: v1
 kind: ConfigMap
 metadata:
   name: flink-operator-config
+  namespace: {{ .Values.operatorNamespace.name }}
   labels:
-    app: flink
+    {{- include "flink-operator.labels" . | nindent 4 }}
 data:
   flink-conf.yaml: |+
     taskmanager.numberOfTaskSlots: 2
diff --git a/deploy/rbac.yaml b/helm/flink-operator/templates/rbac.yaml
similarity index 53%
rename from deploy/rbac.yaml
rename to helm/flink-operator/templates/rbac.yaml
index b273b8b..c83bb0c 100644
--- a/deploy/rbac.yaml
+++ b/helm/flink-operator/templates/rbac.yaml
@@ -17,78 +17,75 @@
 ################################################################################
 
 ---
-
-apiVersion: v1
-kind: ServiceAccount
-metadata:
-  name: flink-operator
-  namespace: default
-
+{{- if .Values.rbac.create }}
 ---
-
 apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRole
 metadata:
   name: flink-operator
+  namespace: {{ .Values.operatorNamespace.name }}
+  labels:
+    {{- include "flink-operator.labels" . | nindent 4 }}
 rules:
-- apiGroups:
-  - flink-operator
-  resources:
-  - "*"
-  verbs:
-  - "*"
-- apiGroups:
-  - ""
-  resources:
-  - pods
-  - services
-  - endpoints
-  - persistentvolumeclaims
-  - events
-  - configmaps
-  - secrets
-  - nodes
-  verbs:
-  - "*"
-- apiGroups:
-  - apps
-  resources:
-  - deployments
-  - replicasets
-  verbs:
-  - "*"
-- apiGroups:
-  - extensions
-  resources:
-  - deployments
-  - ingresses
-  verbs:
-  - "*"
-- apiGroups:
-  - flink.io
-  resources:
-  - flinkdeployments
-  - flinkdeployments/status
-  verbs:
-  - "*"
-- apiGroups:
-  - networking.k8s.io
-  resources:
-  - ingresses
-  verbs:
-  - "*"
-
+  - apiGroups:
+      - flink-operator
+    resources:
+      - "*"
+    verbs:
+      - "*"
+  - apiGroups:
+      - ""
+    resources:
+      - pods
+      - services
+      - endpoints
+      - persistentvolumeclaims
+      - events
+      - configmaps
+      - secrets
+    verbs:
+      - "*"
+  - apiGroups:
+      - apps
+    resources:
+      - deployments
+      - replicasets
+    verbs:
+      - "*"
+  - apiGroups:
+      - extensions
+    resources:
+      - deployments
+      - ingresses
+    verbs:
+      - "*"
+  - apiGroups:
+      - flink.io
+    resources:
+      - flinkdeployments
+      - flinkdeployments/status
+    verbs:
+      - "*"
+  - apiGroups:
+      - networking.k8s.io
+    resources:
+      - ingresses
+    verbs:
+      - "*"
 ---
-
 apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRoleBinding
 metadata:
   name: flink-operator-cluster-role-binding
-subjects:
-- kind: ServiceAccount
-  name: flink-operator
-  namespace: default
+  namespace: {{ .Values.operatorNamespace.name }}
+  labels:
+    {{- include "flink-operator.labels" . | nindent 4 }}
 roleRef:
   kind: ClusterRole
   name: flink-operator
   apiGroup: rbac.authorization.k8s.io
+subjects:
+  - kind: ServiceAccount
+    name: {{ template "flink-operator.serviceAccountName" . }}
+    namespace: {{ .Values.operatorNamespace.name }}
+{{- end }}
diff --git a/Dockerfile b/helm/flink-operator/templates/serviceaccount.yaml
similarity index 71%
copy from Dockerfile
copy to helm/flink-operator/templates/serviceaccount.yaml
index c834e97..5e22cbc 100644
--- a/Dockerfile
+++ b/helm/flink-operator/templates/serviceaccount.yaml
@@ -15,19 +15,18 @@
 #  See the License for the specific language governing permissions and
 # limitations under the License.
 ################################################################################
-# Build
-FROM maven:3.8.4-openjdk-11 AS build
-WORKDIR /app
 
-COPY src ./src
-COPY tools ./tools
-COPY pom.xml .
-
-RUN mvn -f ./pom.xml clean install
-
-# stage
-FROM openjdk:11-jre
-
-COPY --from=build /app/target/flink-operator-1.0-SNAPSHOT.jar /
-
-CMD ["java", "-jar", "/flink-operator-1.0-SNAPSHOT.jar"]
+---
+{{- if .Values.serviceAccount.create -}}
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  name: {{ include "flink-operator.serviceAccountName" . }}
+  namespace: {{ .Values.operatorNamespace.name }}
+  labels:
+    {{- include "flink-operator.labels" . | nindent 4 }}
+  {{- with .Values.serviceAccount.annotations }}
+  annotations:
+    {{- toYaml . | nindent 4 }}
+  {{- end }}
+{{- end }}
diff --git a/Dockerfile b/helm/flink-operator/values.yaml
similarity index 76%
copy from Dockerfile
copy to helm/flink-operator/values.yaml
index c834e97..1972658 100644
--- a/Dockerfile
+++ b/helm/flink-operator/values.yaml
@@ -15,19 +15,26 @@
 #  See the License for the specific language governing permissions and
 # limitations under the License.
 ################################################################################
-# Build
-FROM maven:3.8.4-openjdk-11 AS build
-WORKDIR /app
 
-COPY src ./src
-COPY tools ./tools
-COPY pom.xml .
+---
 
-RUN mvn -f ./pom.xml clean install
+operatorNamespace:
+  name: default
 
-# stage
-FROM openjdk:11-jre
+image:
+  repository: flink-operator
+  pullPolicy: IfNotPresent
+  tag: latest
 
-COPY --from=build /app/target/flink-operator-1.0-SNAPSHOT.jar /
+rbac:
+  create: true
+
+serviceAccount:
+  create: true
+  annotations: {}
+  name: "flink-operator"
+
+imagePullSecrets: []
+nameOverride: ""
+fullnameOverride: ""
 
-CMD ["java", "-jar", "/flink-operator-1.0-SNAPSHOT.jar"]
diff --git a/pom.xml b/pom.xml
index 709e48d..c44c4f4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,6 +30,7 @@ under the License.
         <maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
         <maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>
         <maven-failsafe-plugin.version>3.0.0-M4</maven-failsafe-plugin.version>
+        <maven-resources-plugin.version>3.2.0</maven-resources-plugin.version>
 
         <operator.sdk.version>2.0.1</operator.sdk.version>
         <fabric8.version>5.12.1</fabric8.version>
@@ -142,6 +143,33 @@ under the License.
 
     <build>
         <plugins>
+
+            <plugin>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>${maven-resources-plugin.version}</version>
+                <executions>
+                    <execution>
+                        <id>copy-resources</id>
+                        <phase>process-classes</phase>
+                        <goals>
+                            <goal>copy-resources</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${basedir}/helm/flink-operator/templates</outputDirectory>
+                            <resources>
+                                <resource>
+                                    <directory>${project.build.outputDirectory}/META-INF/fabric8</directory>
+                                    <includes>
+                                        <include>flinkdeployments.flink.io-v1.yml</include>
+                                    </includes>
+                                    <filtering>false</filtering>
+                                </resource>
+                            </resources>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-shade-plugin</artifactId>
@@ -321,6 +349,8 @@ under the License.
       						<exclude>apache-maven-3.2.5/**</exclude>
       						<!-- PyCharm -->
       						<exclude>**/.idea/**</exclude>
+                  <!-- Generated CRD -->
+                  <exclude>helm/flink-operator/templates/flinkdeployments.flink.io-v1.yml</exclude>
       					</excludes>
       				</configuration>
       			</plugin>