Copilot commented on code in PR #11091:
URL: https://github.com/apache/gravitino/pull/11091#discussion_r3296659315


##########
dev/charts/gravitino/tests/ingress_test.yaml:
##########
@@ -0,0 +1,116 @@
+#
+# 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.
+#
+
+suite: test gravitino ingress
+templates:
+  - ingress.yaml
+tests:
+  - it: does not render ingress by default
+    asserts:
+      - hasDocuments:
+          count: 0
+
+  - it: renders networking v1 ingress for supported Kubernetes versions
+    release:
+      name: gravitino
+    capabilities:
+      majorVersion: 1
+      minorVersion: 29
+    set:
+      ingress:
+        enabled: true
+        className: nginx
+        annotations:
+          nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
+        hosts:
+          - host: gravitino.example.com
+            paths:
+              - path: /api
+                pathType: Prefix
+        tls:
+          - secretName: gravitino-tls
+            hosts:
+              - gravitino.example.com
+    asserts:
+      - isAPIVersion:
+          of: networking.k8s.io/v1
+      - isKind:
+          of: Ingress
+      - equal:
+          path: metadata.name
+          value: gravitino-gravitino-helm
+      - equal:
+          path: 
metadata.annotations["nginx.ingress.kubernetes.io/proxy-read-timeout"]
+          value: "3600"
+      - equal:
+          path: spec.ingressClassName
+          value: nginx
+      - equal:
+          path: spec.rules[0].host
+          value: gravitino.example.com
+      - equal:
+          path: spec.rules[0].http.paths[0].path
+          value: /api
+      - equal:
+          path: spec.rules[0].http.paths[0].pathType
+          value: Prefix
+      - equal:
+          path: spec.rules[0].http.paths[0].backend.service.name
+          value: gravitino-gravitino-helm
+      - equal:
+          path: spec.rules[0].http.paths[0].backend.service.port.number
+          value: 8090
+      - equal:
+          path: spec.tls[0].secretName
+          value: gravitino-tls
+      - contains:
+          path: spec.tls[0].hosts
+          content: gravitino.example.com
+
+  - it: renders legacy ingress class annotation for Kubernetes versions before 
1.18
+    release:
+      name: gravitino
+    capabilities:
+      majorVersion: 1
+      minorVersion: 17
+    set:

Review Comment:
   The chart declares kubeVersion: '>=1.29.0-0' (Chart.yaml), so simulating 
Kubernetes 1.17 here is outside the chart’s supported range and may cause 
`helm`/`helm unittest` to fail early with an incompatible kubeVersion error. 
Consider removing this case or updating it to a supported version range so the 
test suite aligns with the chart’s stated compatibility.



##########
.github/workflows/chart-test.yaml:
##########
@@ -58,6 +58,14 @@ jobs:
           helm repo add bitnami https://charts.bitnami.com/bitnami
           ct lint --chart-dirs=dev/charts 
--chart-yaml-schema=dev/ci/chart_schema.yaml --lint-conf=dev/ci/lintconf.yaml 
--target-branch ${{ github.event.pull_request.base.ref }} 
--check-version-increment=false
 
+      - name: Set up helm-unittest
+        if: steps.list-changed.outputs.changed == 'true'
+        run: helm plugin install 
https://github.com/helm-unittest/helm-unittest.git --version v1.1.0 
--verify=false
+
+      - name: Unit test Gravitino chart
+        if: steps.list-changed.outputs.changed == 'true'
+        run: helm unittest --with-subchart=false dev/charts/gravitino

Review Comment:
   Installing the helm-unittest plugin with `--verify=false` disables 
provenance/signature verification and pulls executable code directly from a Git 
URL in CI. Consider removing `--verify=false` (default is already no-verify) or 
switching to an installation method that validates the plugin artifact (e.g., a 
pinned release artifact/checksum) to reduce supply-chain risk.



##########
dev/charts/gravitino/tests/deployment_test.yaml:
##########
@@ -0,0 +1,267 @@
+#
+# 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.
+#
+
+suite: test gravitino deployment
+templates:
+  - deployment.yaml
+  - configmap.yaml
+tests:
+  - it: renders the default deployment
+    template: deployment.yaml
+    release:
+      name: gravitino
+      namespace: gravitino-system
+    asserts:
+      - isKind:
+          of: Deployment
+      - equal:
+          path: metadata.namespace
+          value: gravitino-system
+      - equal:
+          path: spec.replicas
+          value: 1
+      - equal:
+          path: spec.selector.matchLabels.release
+          value: gravitino
+      - equal:
+          path: spec.template.spec.serviceAccountName
+          value: default
+      - contains:
+          path: spec.template.spec.initContainers
+          content:
+            name: sqlfile
+          any: true
+      - matchRegex:
+          path: spec.template.spec.containers[0].image
+          pattern: "^docker\\.io/apache/gravitino:.+"
+      - contains:
+          path: spec.template.spec.containers[0].env
+          content:
+            name: GRAVITINO_HOME
+            value: /opt/gravitino
+          any: true
+      - contains:
+          path: spec.template.spec.containers[0].ports
+          content:
+            name: http
+            containerPort: 8090
+            protocol: TCP
+          any: true
+      - contains:
+          path: spec.template.spec.volumes
+          content:
+            name: storage
+            emptyDir: {}
+          any: true
+
+  - it: renders pod customization, templated env, and an existing storage claim
+    release:
+      name: gravitino-custom
+    template: deployment.yaml
+    set:
+      replicas: 2
+      serviceAccountName: gravitino-sa
+      global:
+        imagePullSecrets:
+          - name: registry-secret
+      podLabels:
+        app.kubernetes.io/part-of: gravitino
+      podAnnotations:
+        prometheus.io/scrape: "true"
+      envWithTpl:
+        - name: RELEASE_NAME
+          value: "{{ .Release.Name }}"
+      envFrom:
+        - configMapRef:
+            name: gravitino-env
+      persistence:
+        enabled: true
+        existingClaim: gravitino-data
+      extraVolumes:
+        - name: audit-config
+          configMap:
+            name: audit-config
+      extraVolumeMounts:
+        - name: audit-config
+          mountPath: /opt/gravitino/audit
+    asserts:
+      - equal:
+          path: spec.replicas
+          value: 2
+      - equal:
+          path: spec.template.spec.serviceAccountName
+          value: gravitino-sa
+      - contains:
+          path: spec.template.spec.imagePullSecrets
+          content:
+            name: registry-secret
+      - equal:
+          path: spec.template.metadata.labels["app.kubernetes.io/part-of"]
+          value: gravitino
+      - equal:
+          path: spec.template.metadata.annotations["prometheus.io/scrape"]
+          value: "true"
+      - contains:
+          path: spec.template.spec.containers[0].env
+          content:
+            name: RELEASE_NAME
+            value: gravitino-custom
+          any: true
+      - contains:
+          path: spec.template.spec.containers[0].envFrom
+          content:
+            configMapRef:
+              name: gravitino-env
+      - contains:
+          path: spec.template.spec.volumes
+          content:
+            name: storage
+            persistentVolumeClaim:
+              claimName: gravitino-data
+          any: true
+      - contains:
+          path: spec.template.spec.volumes
+          content:
+            name: audit-config
+            configMap:
+              name: audit-config
+          any: true
+      - contains:
+          path: spec.template.spec.containers[0].volumeMounts
+          content:
+            name: audit-config
+            mountPath: /opt/gravitino/audit
+
+  - it: renders security contexts, resources, and custom probes
+    template: deployment.yaml
+    set:
+      podSecurityContext:
+        fsGroup: 1000
+      initContainerSecurityContext:
+        runAsNonRoot: true
+        runAsUser: 2000
+      containerSecurityContext:
+        runAsNonRoot: true
+        runAsUser: 1000
+        capabilities:
+          drop:
+            - ALL
+      resources:
+        requests:
+          cpu: 500m
+          memory: 1Gi
+        limits:
+          cpu: "2"
+          memory: 2Gi
+      initResources:
+        requests:
+          cpu: 50m
+          memory: 128Mi
+        limits:
+          cpu: 100m
+          memory: 256Mi
+      livenessProbe:
+        httpGet:
+          path: /api/version
+          port: http
+        initialDelaySeconds: 30
+        timeoutSeconds: 3
+      readinessProbe:
+        httpGet:
+          path: /api/health
+          port: http
+        initialDelaySeconds: 10
+        timeoutSeconds: 2
+    asserts:
+      - equal:
+          path: spec.template.spec.securityContext.fsGroup
+          value: 1000
+      - equal:
+          path: spec.template.spec.initContainers[0].securityContext.runAsUser
+          value: 2000
+      - equal:
+          path: spec.template.spec.initContainers[0].resources.requests.cpu
+          value: 50m
+      - equal:
+          path: spec.template.spec.initContainers[0].resources.limits.memory
+          value: 256Mi
+      - equal:
+          path: spec.template.spec.containers[0].securityContext.runAsUser
+          value: 1000
+      - contains:
+          path: 
spec.template.spec.containers[0].securityContext.capabilities.drop
+          content: ALL
+      - equal:
+          path: spec.template.spec.containers[0].resources.requests.memory
+          value: 1Gi
+      - equal:
+          path: spec.template.spec.containers[0].resources.limits.cpu
+          value: "2"
+      - equal:
+          path: spec.template.spec.containers[0].livenessProbe.httpGet.path
+          value: /api/version
+      - equal:
+          path: spec.template.spec.containers[0].readinessProbe.httpGet.path
+          value: /api/health
+
+  - it: renders MySQL initialization when MySQL is enabled
+    template: deployment.yaml
+    release:
+      name: gravitino
+    set:
+      mysql:
+        enabled: true
+    asserts:
+      - contains:
+          path: spec.template.spec.initContainers
+          content:
+            name: init-mysql
+          any: true
+      - matchRegex:
+          path: spec.template.spec.initContainers[1].command[2]
+          pattern: "Waiting for MySQL to be ready"
+      - contains:
+          path: spec.template.spec.initContainers[1].env
+          content:
+            name: GRAVITINO_DB
+            value: gravitino
+          any: true
+
+  - it: renders PostgreSQL initialization when PostgreSQL is enabled
+    template: deployment.yaml
+    release:
+      name: gravitino
+    set:
+      postgresql:
+        enabled: true
+    asserts:
+      - contains:
+          path: spec.template.spec.initContainers
+          content:
+            name: init-postgresql
+          any: true
+      - matchRegex:
+          path: spec.template.spec.initContainers[1].command[2]
+          pattern: "Waiting for PostgreSQL to be ready"
+      - contains:
+          path: spec.template.spec.initContainers[1].env
+          content:
+            name: GRAVITINO_DB
+            value: gravitino
+          any: true

Review Comment:
   Similarly, this test assumes `initContainers[1]` is the PostgreSQL init 
container. If initContainers are reordered or additional initContainers are 
introduced, this indexed assertion may fail even though the expected init 
container is present. Consider adding an explicit `equal` on 
`initContainers[1].name` or otherwise avoiding index-based targeting.



##########
dev/charts/gravitino/tests/deployment_test.yaml:
##########
@@ -0,0 +1,267 @@
+#
+# 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.
+#
+
+suite: test gravitino deployment
+templates:
+  - deployment.yaml
+  - configmap.yaml
+tests:
+  - it: renders the default deployment
+    template: deployment.yaml
+    release:
+      name: gravitino
+      namespace: gravitino-system
+    asserts:
+      - isKind:
+          of: Deployment
+      - equal:
+          path: metadata.namespace
+          value: gravitino-system
+      - equal:
+          path: spec.replicas
+          value: 1
+      - equal:
+          path: spec.selector.matchLabels.release
+          value: gravitino
+      - equal:
+          path: spec.template.spec.serviceAccountName
+          value: default
+      - contains:
+          path: spec.template.spec.initContainers
+          content:
+            name: sqlfile
+          any: true
+      - matchRegex:
+          path: spec.template.spec.containers[0].image
+          pattern: "^docker\\.io/apache/gravitino:.+"
+      - contains:
+          path: spec.template.spec.containers[0].env
+          content:
+            name: GRAVITINO_HOME
+            value: /opt/gravitino
+          any: true
+      - contains:
+          path: spec.template.spec.containers[0].ports
+          content:
+            name: http
+            containerPort: 8090
+            protocol: TCP
+          any: true
+      - contains:
+          path: spec.template.spec.volumes
+          content:
+            name: storage
+            emptyDir: {}
+          any: true
+
+  - it: renders pod customization, templated env, and an existing storage claim
+    release:
+      name: gravitino-custom
+    template: deployment.yaml
+    set:
+      replicas: 2
+      serviceAccountName: gravitino-sa
+      global:
+        imagePullSecrets:
+          - name: registry-secret
+      podLabels:
+        app.kubernetes.io/part-of: gravitino
+      podAnnotations:
+        prometheus.io/scrape: "true"
+      envWithTpl:
+        - name: RELEASE_NAME
+          value: "{{ .Release.Name }}"
+      envFrom:
+        - configMapRef:
+            name: gravitino-env
+      persistence:
+        enabled: true
+        existingClaim: gravitino-data
+      extraVolumes:
+        - name: audit-config
+          configMap:
+            name: audit-config
+      extraVolumeMounts:
+        - name: audit-config
+          mountPath: /opt/gravitino/audit
+    asserts:
+      - equal:
+          path: spec.replicas
+          value: 2
+      - equal:
+          path: spec.template.spec.serviceAccountName
+          value: gravitino-sa
+      - contains:
+          path: spec.template.spec.imagePullSecrets
+          content:
+            name: registry-secret
+      - equal:
+          path: spec.template.metadata.labels["app.kubernetes.io/part-of"]
+          value: gravitino
+      - equal:
+          path: spec.template.metadata.annotations["prometheus.io/scrape"]
+          value: "true"
+      - contains:
+          path: spec.template.spec.containers[0].env
+          content:
+            name: RELEASE_NAME
+            value: gravitino-custom
+          any: true
+      - contains:
+          path: spec.template.spec.containers[0].envFrom
+          content:
+            configMapRef:
+              name: gravitino-env
+      - contains:
+          path: spec.template.spec.volumes
+          content:
+            name: storage
+            persistentVolumeClaim:
+              claimName: gravitino-data
+          any: true
+      - contains:
+          path: spec.template.spec.volumes
+          content:
+            name: audit-config
+            configMap:
+              name: audit-config
+          any: true
+      - contains:
+          path: spec.template.spec.containers[0].volumeMounts
+          content:
+            name: audit-config
+            mountPath: /opt/gravitino/audit
+
+  - it: renders security contexts, resources, and custom probes
+    template: deployment.yaml
+    set:
+      podSecurityContext:
+        fsGroup: 1000
+      initContainerSecurityContext:
+        runAsNonRoot: true
+        runAsUser: 2000
+      containerSecurityContext:
+        runAsNonRoot: true
+        runAsUser: 1000
+        capabilities:
+          drop:
+            - ALL
+      resources:
+        requests:
+          cpu: 500m
+          memory: 1Gi
+        limits:
+          cpu: "2"
+          memory: 2Gi
+      initResources:
+        requests:
+          cpu: 50m
+          memory: 128Mi
+        limits:
+          cpu: 100m
+          memory: 256Mi
+      livenessProbe:
+        httpGet:
+          path: /api/version
+          port: http
+        initialDelaySeconds: 30
+        timeoutSeconds: 3
+      readinessProbe:
+        httpGet:
+          path: /api/health
+          port: http
+        initialDelaySeconds: 10
+        timeoutSeconds: 2
+    asserts:
+      - equal:
+          path: spec.template.spec.securityContext.fsGroup
+          value: 1000
+      - equal:
+          path: spec.template.spec.initContainers[0].securityContext.runAsUser
+          value: 2000
+      - equal:
+          path: spec.template.spec.initContainers[0].resources.requests.cpu
+          value: 50m
+      - equal:
+          path: spec.template.spec.initContainers[0].resources.limits.memory
+          value: 256Mi
+      - equal:
+          path: spec.template.spec.containers[0].securityContext.runAsUser
+          value: 1000
+      - contains:
+          path: 
spec.template.spec.containers[0].securityContext.capabilities.drop
+          content: ALL
+      - equal:
+          path: spec.template.spec.containers[0].resources.requests.memory
+          value: 1Gi
+      - equal:
+          path: spec.template.spec.containers[0].resources.limits.cpu
+          value: "2"
+      - equal:
+          path: spec.template.spec.containers[0].livenessProbe.httpGet.path
+          value: /api/version
+      - equal:
+          path: spec.template.spec.containers[0].readinessProbe.httpGet.path
+          value: /api/health
+
+  - it: renders MySQL initialization when MySQL is enabled
+    template: deployment.yaml
+    release:
+      name: gravitino
+    set:
+      mysql:
+        enabled: true
+    asserts:
+      - contains:
+          path: spec.template.spec.initContainers
+          content:
+            name: init-mysql
+          any: true
+      - matchRegex:
+          path: spec.template.spec.initContainers[1].command[2]
+          pattern: "Waiting for MySQL to be ready"
+      - contains:
+          path: spec.template.spec.initContainers[1].env
+          content:
+            name: GRAVITINO_DB
+            value: gravitino
+          any: true

Review Comment:
   These assertions depend on `initContainers[1]` being the MySQL/PostgreSQL 
init container. That makes the tests brittle if another initContainer is 
added/reordered (the earlier `contains` check would still pass, but the indexed 
`matchRegex`/`contains` could fail). Consider asserting the expected name at 
index 1 first, or restructuring the assertion to avoid relying on array 
ordering.



-- 
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]

Reply via email to