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

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new ad5e87332 [INLONG-3473][CI] Add support for chart testing (#3676)
ad5e87332 is described below

commit ad5e87332c93dc8ecf268626932d886558ccc432
Author: Yuanhao Ji <[email protected]>
AuthorDate: Sun May 8 17:27:39 2022 +0800

    [INLONG-3473][CI] Add support for chart testing (#3676)
---
 .github/actions/chart-testing-action               |  1 +
 .github/actions/kind-action                        |  1 +
 .../templates/zookeeper-pdb.yaml => .github/ct.yml | 19 +----
 .../zookeeper-pdb.yaml => .github/kind.yml         | 27 +++---
 .github/labeler.yml                                |  1 +
 .github/workflows/ci_chart_test.yml                | 98 ++++++++++++++++++++++
 .gitmodules                                        | 23 +++++
 docker/kubernetes/Chart.yaml                       | 15 +++-
 docker/kubernetes/README.md                        | 59 ++++++++++++-
 docker/kubernetes/templates/tubemq-broker-pdb.yaml |  4 +
 docker/kubernetes/templates/tubemq-master-pdb.yaml |  4 +
 docker/kubernetes/templates/zookeeper-pdb.yaml     |  4 +
 12 files changed, 217 insertions(+), 39 deletions(-)

diff --git a/.github/actions/chart-testing-action 
b/.github/actions/chart-testing-action
new file mode 160000
index 000000000..dae259e86
--- /dev/null
+++ b/.github/actions/chart-testing-action
@@ -0,0 +1 @@
+Subproject commit dae259e86a35ff09145c0805e2d7dd3f7207064a
diff --git a/.github/actions/kind-action b/.github/actions/kind-action
new file mode 160000
index 000000000..94729529f
--- /dev/null
+++ b/.github/actions/kind-action
@@ -0,0 +1 @@
+Subproject commit 94729529f85113b88f4f819c17ce61382e6d8478
diff --git a/docker/kubernetes/templates/zookeeper-pdb.yaml b/.github/ct.yml
similarity index 59%
copy from docker/kubernetes/templates/zookeeper-pdb.yaml
copy to .github/ct.yml
index 4cd82a8a7..80dbb57a4 100644
--- a/docker/kubernetes/templates/zookeeper-pdb.yaml
+++ b/.github/ct.yml
@@ -15,19 +15,6 @@
 # limitations under the License.
 #
 
-{{- if .Values.zookeeper.pdb.usePolicy }}
-apiVersion: policy/v1
-kind: PodDisruptionBudget
-metadata:
-  name: {{ template "inlong.fullname" . }}-{{ .Values.zookeeper.component }}
-  namespace: {{ .Release.Namespace }}
-  labels:
-    {{- include "inlong.commonLabels" . | nindent 4 }}
-    component: {{ .Values.zookeeper.component }}
-spec:
-  selector:
-    matchLabels:
-      {{- include "inlong.matchLabels" . | nindent 6 }}
-      component: {{ .Values.zookeeper.component }}
-  maxUnavailable: {{ .Values.zookeeper.pdb.maxUnavailable }}
-{{- end }}
+chart-dirs:
+  - 'docker'
+validate-maintainers: true
diff --git a/docker/kubernetes/templates/zookeeper-pdb.yaml b/.github/kind.yml
similarity index 59%
copy from docker/kubernetes/templates/zookeeper-pdb.yaml
copy to .github/kind.yml
index 4cd82a8a7..fa6ec5ddd 100644
--- a/docker/kubernetes/templates/zookeeper-pdb.yaml
+++ b/.github/kind.yml
@@ -15,19 +15,14 @@
 # limitations under the License.
 #
 
-{{- if .Values.zookeeper.pdb.usePolicy }}
-apiVersion: policy/v1
-kind: PodDisruptionBudget
-metadata:
-  name: {{ template "inlong.fullname" . }}-{{ .Values.zookeeper.component }}
-  namespace: {{ .Release.Namespace }}
-  labels:
-    {{- include "inlong.commonLabels" . | nindent 4 }}
-    component: {{ .Values.zookeeper.component }}
-spec:
-  selector:
-    matchLabels:
-      {{- include "inlong.matchLabels" . | nindent 6 }}
-      component: {{ .Values.zookeeper.component }}
-  maxUnavailable: {{ .Values.zookeeper.pdb.maxUnavailable }}
-{{- end }}
+kind: Cluster
+apiVersion: kind.x-k8s.io/v1alpha4
+name: inlong-cluster
+nodes:
+  - role: control-plane
+  - role: worker
+  - role: worker
+  - role: worker
+  - role: worker
+  - role: worker
+  - role: worker
diff --git a/.github/labeler.yml b/.github/labeler.yml
index 45a8b311d..161054015 100644
--- a/.github/labeler.yml
+++ b/.github/labeler.yml
@@ -43,6 +43,7 @@ inlong-sdk:
   - 'inlong-sdk/**/*'
 
 ci:
+  - '.github/actions/**/*'
   - '.github/workflows/**/*'
 
 docker:
diff --git a/.github/workflows/ci_chart_test.yml 
b/.github/workflows/ci_chart_test.yml
new file mode 100644
index 000000000..4e1a35e30
--- /dev/null
+++ b/.github/workflows/ci_chart_test.yml
@@ -0,0 +1,98 @@
+#
+# 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.
+#
+
+name: InLong Helm Charts Lint and Test
+
+on:
+  push:
+    paths:
+      - '.github/workflows/ci_chart_test.yml'
+      - '.github/ct.yml'
+      - '.github/kind.yml'
+      - 'docker/kubernetes/**'
+      - '!docker/kubernetes/NOTES.txt'
+      - '!*.md'
+
+  pull_request:
+    paths:
+      - '.github/workflows/ci_chart_test.yml'
+      - '.github/ct.yml'
+      - '.github/kind.yml'
+      - 'docker/kubernetes/**'
+      - '!docker/kubernetes/NOTES.txt'
+      - '!*.md'
+
+env:
+  CT_CONFIG_PATH: '.github/ct.yml'
+  KIND_CONFIG_PATH: '.github/kind.yml'
+
+jobs:
+  chart-test:
+    name: Lint and test charts
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        kubernetes-version:
+          - 'kindest/node:v1.14.10'
+          - 'kindest/node:v1.18.20'
+          - 'kindest/node:v1.21.10'
+          - 'kindest/node:v1.23.4'
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+        with:
+          fetch-depth: 0
+          submodules: true
+
+      - name: Set up helm
+        uses: azure/setup-helm@v1
+        with:
+          version: v3.5.0
+
+      - name: Set up python
+        uses: actions/setup-python@v2
+        with:
+          python-version: 3.7
+
+      - name: Set up chart-testing
+        uses: ./.github/actions/chart-testing-action
+
+      - name: List changed charts
+        id: list-changed
+        run: |
+          changed=$(ct list-changed --config ${{ env.CT_CONFIG_PATH }} 
--target-branch ${{ github.event.repository.default_branch }})
+          if [[ -n "$changed" ]]; then
+            echo "::set-output name=changed::true"
+            echo -e "\e[96mchanged charts: $changed\e[0m"
+          else
+            echo -e "\e[91mCharts are not changed, they will not be linted, 
validated, installed and tested.\e[0m"
+          fi
+
+      # NOTE: If the charts have not changed, they will not be linted, 
validated, installed and tested.
+      - name: Lint and validate charts
+        run: ct lint --config ${{ env.CT_CONFIG_PATH }}
+
+      - name: Create kind cluster
+        if: ${{ steps.list-changed.outputs.changed == 'true' }}
+        uses: ./.github/actions/kind-action
+        with:
+          config: ${{ env.KIND_CONFIG_PATH }}
+          node_image: ${{ matrix.kubernetes-version }}
+
+      - name: Install and test charts
+        if: ${{ success() && steps.list-changed.outputs.changed == 'true' }}
+        run: ct install --config ${{ env.CT_CONFIG_PATH }}
diff --git a/.gitmodules b/.gitmodules
index 9793f024b..5587a4888 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,4 +1,27 @@
+# Licensed to 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. Apache Software Foundation (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.
+
 [submodule 
"inlong-tubemq/tubemq-client-twins/tubemq-client-cpp/third_party/rapidjson"]
        path = 
inlong-tubemq/tubemq-client-twins/tubemq-client-cpp/third_party/rapidjson
        url = https://github.com/Tencent/rapidjson.git
        tag = v1.1.0
+[submodule ".github/actions/kind-action"]
+       path = .github/actions/kind-action
+       url = https://github.com/helm/kind-action.git
+[submodule ".github/actions/chart-testing-action"]
+       path = .github/actions/chart-testing-action
+       url = https://github.com/helm/chart-testing-action.git
diff --git a/docker/kubernetes/Chart.yaml b/docker/kubernetes/Chart.yaml
index faf48baac..b5a9591c6 100644
--- a/docker/kubernetes/Chart.yaml
+++ b/docker/kubernetes/Chart.yaml
@@ -17,10 +17,8 @@
 
 apiVersion: v2
 name: inlong
-description: A Helm Chart for Apache InLong
 type: application
-version: 2.0.0
-appVersion: 1.2.0
+description: A Helm Chart for Apache InLong
 home: https://inlong.apache.org
 icon: https://inlong.apache.org/img/first-page-bg.png
 sources:
@@ -28,10 +26,19 @@ sources:
 keywords:
   - inlong
   - tubemq
+
+# The chart version number should be incremented each time you make changes
+# to the chart and its templates.
+version: 2.0.1
+
+# This is the version number of the application being deployed. This version 
number should be
+# incremented each time you make changes to the application.
+appVersion: 1.2.0
+
 maintainers:
   - name: dockerzhang
     email: [email protected]
     url: https://github.com/dockerzhang
   - name: shink
-    email: [email protected]
+    email: [email protected]
     url: https://github.com/shink
diff --git a/docker/kubernetes/README.md b/docker/kubernetes/README.md
index 136bb0bbe..7ccc22123 100644
--- a/docker/kubernetes/README.md
+++ b/docker/kubernetes/README.md
@@ -131,10 +131,11 @@ It runs a local Kubernetes cluster in Docker container. 
Therefore, it requires v
 
 You can install kind by following the [Quick 
Start](https://kind.sigs.k8s.io/docs/user/quick-start) section of their 
official documentation.
 
-After installing kind, you can create a Kubernetes cluster with the 
[configuration file](../../.github/kind.yml), try:
+After installing kind, you can create a Kubernetes cluster with the 
[configuration file](../../.github/kind.yml).
+Try in the project root:
 
 ```shell
-kind create cluster --config ../../.github/kind.yml
+kind create cluster --config .github/kind.yml
 ```
 
 To specify another image use the `--image` flag – `kind create cluster 
--image=....`.
@@ -155,7 +156,7 @@ Please follow the [installation 
guide](https://helm.sh/docs/intro/install) in th
 
 ### Install the chart
 
-To create the namespace and Install the chart, try:
+To create the namespace and install the chart, in the [docker/kubernetes](.) 
folder, try:
 
 ```shell
 kubectl create namespace inlong
@@ -180,6 +181,58 @@ helm template ./ --output-dir ./result
 
 Then, you can check the rendered templates in the `result` directory.
 
+#### Quick start with Chart Testing
+
+Also, you can use the 
[helm/chart-testing](https://github.com/helm/chart-testing) tool to test your 
Helm chart.
+You can follow the 
[installation](https://github.com/helm/chart-testing#installation) section in 
the official documentation to install it.
+But for simplicity, their [Docker 
image](https://quay.io/repository/helmpack/chart-testing?tab=tags) is 
recommended.
+
+To list changed charts, in the project root, try:
+
+```shell
+docker run -it --rm \
+               --name ct \
+               --workdir=/data \
+               --volume "$(pwd)":/data \
+               quay.io/helmpack/chart-testing \
+               ct list-changed --chart-dirs docker --target-branch master
+```
+
+To lint and validate the chart, try:
+
+```shell
+docker run -it --rm \
+               --name ct \
+               --workdir=/data \
+               --volume "$(pwd)":/data \
+               quay.io/helmpack/chart-testing \
+               ct lint --chart-dirs docker
+```
+
+To install and test the chart, try:
+
+```shell
+docker run -it --rm \
+               --name ct \
+               --workdir=/data \
+               --volume "$(pwd)":/data \
+               quay.io/helmpack/chart-testing \
+               ct install --chart-dirs docker
+```
+
+> NOTE: If the charts have not changed, they will not be linted, validated, 
installed and tested.
+
+## Contribution
+
+When you decide to contribute, you should follow these steps:
+
+1. Develop the chart locally and verify your changes.
+2. Don't forget to bump up the version in [Chart.yaml](Chart.yaml).
+3. Feel free to make a [Pull 
Request](https://github.com/apache/incubator-inlong/compare)!
+4. Finally, you can view the status of the [lint and test 
workflow](https://github.com/apache/incubator-inlong/actions/workflows/ci_chart_test.yml).
+   > In this workflow, changes between your branch and the master branch will 
be checked and listed.
+   > All changed charts will be linted, validated, installed and tested.
+
 ## Troubleshooting
 
 We've done our best to make these charts as seamless as possible, but 
occasionally there are circumstances beyond our control.
diff --git a/docker/kubernetes/templates/tubemq-broker-pdb.yaml 
b/docker/kubernetes/templates/tubemq-broker-pdb.yaml
index 64b33a980..17d12ee95 100644
--- a/docker/kubernetes/templates/tubemq-broker-pdb.yaml
+++ b/docker/kubernetes/templates/tubemq-broker-pdb.yaml
@@ -16,7 +16,11 @@
 #
 
 {{- if .Values.tubemqBroker.pdb.usePolicy }}
+{{- if .Capabilities.APIVersions.Has "policy/v1" }}
 apiVersion: policy/v1
+{{- else }}
+apiVersion: policy/v1beta1
+{{- end }}
 kind: PodDisruptionBudget
 metadata:
   name: {{ template "inlong.fullname" . }}-{{ .Values.tubemqBroker.component }}
diff --git a/docker/kubernetes/templates/tubemq-master-pdb.yaml 
b/docker/kubernetes/templates/tubemq-master-pdb.yaml
index 72a948d4b..ce0a12e15 100644
--- a/docker/kubernetes/templates/tubemq-master-pdb.yaml
+++ b/docker/kubernetes/templates/tubemq-master-pdb.yaml
@@ -16,7 +16,11 @@
 #
 
 {{- if .Values.tubemqMaster.pdb.usePolicy }}
+{{- if .Capabilities.APIVersions.Has "policy/v1" }}
 apiVersion: policy/v1
+{{- else }}
+apiVersion: policy/v1beta1
+{{- end }}
 kind: PodDisruptionBudget
 metadata:
   name: {{ template "inlong.fullname" . }}-{{ .Values.tubemqMaster.component }}
diff --git a/docker/kubernetes/templates/zookeeper-pdb.yaml 
b/docker/kubernetes/templates/zookeeper-pdb.yaml
index 4cd82a8a7..6a3613df4 100644
--- a/docker/kubernetes/templates/zookeeper-pdb.yaml
+++ b/docker/kubernetes/templates/zookeeper-pdb.yaml
@@ -16,7 +16,11 @@
 #
 
 {{- if .Values.zookeeper.pdb.usePolicy }}
+{{- if .Capabilities.APIVersions.Has "policy/v1" }}
 apiVersion: policy/v1
+{{- else }}
+apiVersion: policy/v1beta1
+{{- end }}
 kind: PodDisruptionBudget
 metadata:
   name: {{ template "inlong.fullname" . }}-{{ .Values.zookeeper.component }}

Reply via email to