Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions charts/apisix-ingress-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,54 @@ If you have installed multiple ingress controller, add the `kubernetes.io/ingres

This chart bootstraps an apisix-ingress-controller deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.

## Cluster-owned CRD lifecycle

APISIX CRDs stay in the chart's static `crds/` directory. Helm installs missing
CRDs before rendering resources such as GatewayProxy. Existing CRDs are skipped;
Helm neither upgrades nor deletes these CRDs when upgrading or uninstalling the
application release. Do not move them into workload templates or add application
release ownership annotations to shared definitions.

Choose one cluster platform owner to manage APISIX CRD upgrades. Application
releases managed by that owner should install with `--skip-crds`. Before an
upgrade, back up CRs, inspect `status.storedVersions`, review schema and served
version changes, and apply the CRDs from the exact target chart artifact:

```sh
helm pull apisix/apisix-ingress-controller --version <target-version> --untar
kubectl diff -f apisix-ingress-controller/crds/
kubectl apply --server-side --field-manager=apisix-crd-owner -f apisix-ingress-controller/crds/
kubectl wait --for=condition=Established --timeout=60s -f apisix-ingress-controller/crds/
# Then upgrade controller/application releases using the same target version.
```

Run these commands against the intended cluster with platform authorization.
Do not use `--force-conflicts` without reviewing field ownership. Validate
existing custom resources against the new schema and follow a storage-version
migration before removing a stored version. Roll back workloads separately;
automatically reverting CRD schemas can make persisted resources unreadable.
Uninstalling an application is not permission to delete cluster CRDs or CRs.

Gateway API definitions have a separate owner and release lifecycle. For a
platform-managed Gateway API installation, disable
`crds.gatewayAPI.enabled` before installing this controller. Review the
`gateway-api-crds.yaml` template when choosing that setting; `--skip-crds` only
controls static `crds/`, not CRDs rendered by templates.

## Prerequisites

Apisix ingress controller requires Kubernetes version 1.16+.
Check the controller image and the exact CRD bundle against the target API
server before installation. The default Gateway API bundle includes
`ValidatingAdmissionPolicy` and `ValidatingAdmissionPolicyBinding` at
`admissionregistration.k8s.io/v1`; Kubernetes 1.16 alone does not satisfy this
default installation requirement. Confirm these APIs with `kubectl api-resources
--api-group=admissionregistration.k8s.io` and review the selected Gateway API
bundle's Kubernetes compatibility requirements.

These admission policies are cluster-scoped resources with the same owner and
upgrade lifecycle as the Gateway API bundle. `--skip-crds` does not skip them.
When the platform owns that bundle, set `crds.gatewayAPI.enabled=false` to skip
both its CRDs and admission policies, and supply a compatible installation.

## Get Repo Info

Expand Down Expand Up @@ -37,7 +82,12 @@ _See [helm install](https://helm.sh/docs/helm/helm_install/) for command documen
helm uninstall [RELEASE_NAME] --namespace ingress-apisix
```

This removes all the Kubernetes components associated with the chart and deletes the release.
This deletes the release and its application resources. APISIX CRDs from the
static `crds/` directory remain installed. Gateway API CRDs and admission policies
rendered by this chart also remain because they carry
`helm.sh/resource-policy: keep`. Their lifecycle belongs to the cluster platform
owner described above; review retained resources and their ownership before
reinstalling the chart or transferring management to another release.

_See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._

Expand Down
54 changes: 52 additions & 2 deletions charts/apisix-ingress-controller/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,54 @@ If you have installed multiple ingress controller, add the `kubernetes.io/ingres

This chart bootstraps an apisix-ingress-controller deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.

## Cluster-owned CRD lifecycle

APISIX CRDs stay in the chart's static `crds/` directory. Helm installs missing
CRDs before rendering resources such as GatewayProxy. Existing CRDs are skipped;
Helm neither upgrades nor deletes these CRDs when upgrading or uninstalling the
application release. Do not move them into workload templates or add application
release ownership annotations to shared definitions.

Choose one cluster platform owner to manage APISIX CRD upgrades. Application
releases managed by that owner should install with `--skip-crds`. Before an
upgrade, back up CRs, inspect `status.storedVersions`, review schema and served
version changes, and apply the CRDs from the exact target chart artifact:

```sh
helm pull apisix/apisix-ingress-controller --version <target-version> --untar
kubectl diff -f apisix-ingress-controller/crds/
kubectl apply --server-side --field-manager=apisix-crd-owner -f apisix-ingress-controller/crds/
kubectl wait --for=condition=Established --timeout=60s -f apisix-ingress-controller/crds/
# Then upgrade controller/application releases using the same target version.
```

Run these commands against the intended cluster with platform authorization.
Do not use `--force-conflicts` without reviewing field ownership. Validate
existing custom resources against the new schema and follow a storage-version
migration before removing a stored version. Roll back workloads separately;
automatically reverting CRD schemas can make persisted resources unreadable.
Uninstalling an application is not permission to delete cluster CRDs or CRs.

Gateway API definitions have a separate owner and release lifecycle. For a
platform-managed Gateway API installation, disable
`crds.gatewayAPI.enabled` before installing this controller. Review the
`gateway-api-crds.yaml` template when choosing that setting; `--skip-crds` only
controls static `crds/`, not CRDs rendered by templates.

## Prerequisites

Apisix ingress controller requires Kubernetes version 1.16+.
Check the controller image and the exact CRD bundle against the target API
server before installation. The default Gateway API bundle includes
`ValidatingAdmissionPolicy` and `ValidatingAdmissionPolicyBinding` at
`admissionregistration.k8s.io/v1`; Kubernetes 1.16 alone does not satisfy this
default installation requirement. Confirm these APIs with `kubectl api-resources
--api-group=admissionregistration.k8s.io` and review the selected Gateway API
bundle's Kubernetes compatibility requirements.

These admission policies are cluster-scoped resources with the same owner and
upgrade lifecycle as the Gateway API bundle. `--skip-crds` does not skip them.
When the platform owns that bundle, set `crds.gatewayAPI.enabled=false` to skip
both its CRDs and admission policies, and supply a compatible installation.

## Get Repo Info

Expand Down Expand Up @@ -37,7 +82,12 @@ _See [helm install](https://helm.sh/docs/helm/helm_install/) for command documen
helm uninstall [RELEASE_NAME] --namespace ingress-apisix
```

This removes all the Kubernetes components associated with the chart and deletes the release.
This deletes the release and its application resources. APISIX CRDs from the
static `crds/` directory remain installed. Gateway API CRDs and admission policies
rendered by this chart also remain because they carry
`helm.sh/resource-policy: keep`. Their lifecycle belongs to the cluster platform
owner described above; review retained resources and their ownership before
reinstalling the chart or transferring management to another release.

_See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._

Expand Down
73 changes: 73 additions & 0 deletions test/render/crd_lifecycle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python3
# 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.
"""Render regression checks; run with Python 3, PyYAML and Helm 3."""
import pathlib
import copy
import subprocess
import tempfile
import yaml

CHART = pathlib.Path(__file__).resolve().parents[2] / "charts/apisix"
class StrictLoader(yaml.SafeLoader):
pass

def mapping(loader, node, deep=False):
result = {}
for key_node, value_node in node.value:
key = loader.construct_object(key_node, deep=deep)
if key in result:
raise ValueError(f"Duplicate YAML key: {key}")
result[key] = loader.construct_object(value_node, deep=deep)
return result
StrictLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, mapping)

def render(values=None, release="my-apisix", fail=False):
values = copy.deepcopy(values or {})
values.setdefault("etcd", {}).setdefault("auth", {}).setdefault("token", {})["enabled"] = False
with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml") as f:
yaml.safe_dump(values or {}, f); f.flush()
proc = subprocess.run(["helm", "template", release, str(CHART), "-n", "gateway", "-f", f.name], capture_output=True, text=True)
if fail:
assert proc.returncode, "Expected invalid values to fail"
return proc.stderr
assert proc.returncode == 0, proc.stderr
docs = [d for d in yaml.load_all(proc.stdout, Loader=StrictLoader) if d]
ids = [(d["apiVersion"], d["kind"], d["metadata"].get("namespace", "gateway"), d["metadata"]["name"]) for d in docs]
assert len(ids) == len(set(ids)), "Duplicate resource identities"
for d in docs:
if d["kind"] == "ConfigMap" and "config.yaml" in d.get("data", {}):
yaml.load(d["data"]["config.yaml"], Loader=StrictLoader)
return docs

def objects(docs, kind):
return [d for d in docs if d["kind"] == kind]

def config(docs):
return yaml.safe_load(next(d["data"]["config.yaml"] for d in docs if d["kind"] == "ConfigMap" and "config.yaml" in d.get("data", {}) and "apisix" in yaml.safe_load(d["data"]["config.yaml"])))

controller = CHART.parent / "apisix-ingress-controller"
assert (controller / "crds/apisixic-crds.yaml").is_file()
assert not (controller / "templates/crds.yaml").exists()
raw = (controller / "crds/apisixic-crds.yaml").read_text()
crds = [d for d in yaml.load_all(raw, Loader=StrictLoader) if d]
assert len(crds) >= 12 and all(d["kind"] == "CustomResourceDefinition" for d in crds)
assert len({d["metadata"]["name"] for d in crds}) == len(crds)
normal = subprocess.check_output(["helm", "template", "controller", str(controller), "--set", "crds.gatewayAPI.enabled=false"], text=True)
assert not any(d and d.get("kind") == "CustomResourceDefinition" for d in yaml.safe_load_all(normal))
with_crds = subprocess.check_output(["helm", "template", "controller", str(controller), "--set", "crds.gatewayAPI.enabled=false", "--include-crds"], text=True)
assert sum(d is not None and d.get("kind") == "CustomResourceDefinition" for d in yaml.safe_load_all(with_crds)) == len(crds)

print("crd_lifecycle: passed")