Skip to content
Merged
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
20 changes: 19 additions & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ on:
- 'operator/src/go.mod'
- 'operator/src/go.sum'
- 'operator/documentdb-helm-chart/**'
- 'operator/product-helm-chart/**'
pull_request:
branches: [main]
paths:
- 'operator/src/**/*.go'
- 'operator/src/go.mod'
- 'operator/src/go.sum'
- 'operator/documentdb-helm-chart/**'
- 'operator/product-helm-chart/**'

permissions:
contents: read
Expand Down Expand Up @@ -67,13 +69,29 @@ jobs:
uses: azure/setup-helm@v4

- name: Install helm-unittest plugin
run: helm plugin install --verify=false --version v1.1.0 https://github.com/helm-unittest/helm-unittest
env:
GH_TOKEN: ${{ github.token }}
run: |
version=1.1.0
archive="helm-unittest-linux-amd64-${version}.tgz"
download_dir="${RUNNER_TEMP}/helm-unittest-download/_dist"
mkdir -p "$download_dir"
gh release download "v${version}" --repo helm-unittest/helm-unittest \
--pattern "$archive" --pattern helm-unittest-checksum.sha \
--dir "$download_dir"
cd "${download_dir}/.."
sha256sum --check --strict --ignore-missing _dist/helm-unittest-checksum.sha
plugin_dir="$(helm env HELM_PLUGINS)/unittest"
mkdir -p "$plugin_dir"
tar -xzf "_dist/${archive}" -C "$plugin_dir"
helm unittest --help > /dev/null

- name: Run Helm unit tests
run: |
cd operator/documentdb-helm-chart
helm dependency update .
helm unittest .
helm unittest ../product-helm-chart

- name: Test Summary
if: always()
Expand Down
6 changes: 6 additions & 0 deletions operator/product-helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: product-operator
description: Shared API, admission and controllers configured by a product definition
type: application
version: 0.0.0-dev
appVersion: local-unmerged
5 changes: 5 additions & 0 deletions operator/product-helm-chart/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.PHONY: schemas
schemas:
cp ../src/config/crd/bases/documentdb.io_dbs.yaml schemas/cluster.yaml
cp ../src/config/crd/bases/documentdb.io_backups.yaml schemas/backup.yaml
cp ../src/config/crd/bases/documentdb.io_scheduledbackups.yaml schemas/scheduled-backup.yaml
58 changes: 58 additions & 0 deletions operator/product-helm-chart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Declarative product distribution

This opt-in chart runs the existing manager with `--product-definition`.
The same API types, adapter mapping, controllers, admission, certificates,
backups and persistent-volume handling serve every definition. The original
DocumentDB chart and no-definition manager startup remain unchanged.

The definition is data: API identity, product profile, explicit split images,
PostgreSQL defaults, topology policy and endpoint format. It cannot provide Go
callbacks. `operator/src/internal/product/testdata/widget.json` is a synthetic
example. Supply it as the `productDefinition` values object and pin manager
and optional injector images with `image.repository` and `image.digest`.
Install cert-manager and CloudNative-PG first; the injector namespace must
already exist. The bundled injector retains its actual existing RPC identity.
If another Service in that namespace advertises the same identity, reuse it
with `sidecarInjector.enabled=false`; the chart refuses duplicate registrations.
An upgrade can retain the current release's own Service. This cluster lookup
requires server-side rendering and cannot detect collisions in offline templates
or serialize simultaneous installations.
`imagePullSecrets` applies to both manager and injector pods; referenced Secrets
must exist in both namespaces. Manager replicas use leader election.

CRDs are rendered from exact copies of the canonical shared API schemas.
Rendering changes API identity and removes the legacy PostgreSQL image default,
so partial image objects cannot override the definition's PostgreSQL image.
Semantic-version definitions also receive a `schemaVersion` pattern accepting
prerelease/build identifiers; the original DocumentDB pattern is unchanged.
All other schema properties remain shared; there is no product-specific schema
or generated Go API. `make manifests` in `operator/src` automatically
synchronizes these copies after regenerating canonical CRDs; `make schemas`
here refreshes only the copies. Source-equality checks run without Helm, while
the Helm contract test also checks the narrowly scoped default overlay and
API-server defaulting behavior. CRDs are retained on uninstall.

For compatibility, the shared Go API and some JSON fields still carry their
original DocumentDB names. A definition changes API identity, not serialization
or schema semantics. Explicit unsupported cross-region/legacy version settings
are rejected, not silently ignored. Local fixed-catalog definitions disable
upgrades and verify the exact available and installed catalog versions without
inventing a semantic version. Co-location requires `localDevelopment`; non-local
definitions and effective cluster overrides require explicitly enabled, required
pod anti-affinity.

For an existing declarative cluster, extension-image changes are checked against
the live installed catalog before CNPG is patched; status alone cannot approve
an update. Changes wait for a healthy primary and reject older or unversioned/
digest-only target images. Extension identity, library/control paths and preload
libraries cannot change in place. Local pinned-catalog images cannot be replaced.
These guards do not change the legacy no-definition DocumentDB path.

Validate a definition without Kubernetes:

```sh
go run ./cmd --product-definition=internal/product/testdata/widget.json --check-product-definition
```

Run this command from `operator/src`. Fixed-catalog/local-development mode is
not production upgrade, authentication, backup or node-failure HA qualification.
248 changes: 248 additions & 0 deletions operator/product-helm-chart/schemas/backup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.17.2
labels:
app: documentdb-operator
name: backups.documentdb.io
spec:
group: documentdb.io
names:
kind: Backup
listKind: BackupList
plural: backups
singular: backup
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: Target DocumentDB cluster
jsonPath: .spec.cluster.name
name: Cluster
type: string
- description: Backup phase
jsonPath: .status.phase
name: Phase
type: string
- description: Backup start time
jsonPath: .status.startedAt
name: StartedAt
type: string
- description: Backup completion time
jsonPath: .status.stoppedAt
name: StoppedAt
type: string
- description: Backup expiration time
jsonPath: .status.expiredAt
name: ExpiredAt
type: string
- description: Backup status message
jsonPath: .status.message
name: Message
type: string
- description: DocumentDB schema version at backup time
jsonPath: .status.schemaVersion
name: SchemaVersion
type: string
deprecated: true
deprecationWarning: documentdb.io/preview is deprecated; use documentdb.io/v1
name: preview
schema:
openAPIV3Schema:
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: BackupSpec defines the desired state of Backup.
properties:
cluster:
description: |-
Cluster specifies the DocumentDB cluster to backup.
The cluster must exist in the same namespace as the Backup resource.
properties:
name:
description: Name of the referent.
type: string
required:
- name
type: object
retentionDays:
description: |-
RetentionDays specifies how many days the backup should be retained.
If not specified, the default retention period from the cluster's backup retention policy will be used.
type: integer
required:
- cluster
type: object
x-kubernetes-validations:
- message: BackupSpec is immutable once set
rule: oldSelf == self
status:
description: BackupStatus defines the observed state of Backup.
properties:
expiredAt:
description: ExpiredAt is the time when the backup is considered expired
and can be deleted.
format: date-time
type: string
message:
description: |-
Message contains additional information about the backup status.
For failed backups, this contains the error message.
For skipped backups, this explains why the backup was skipped.
type: string
phase:
description: Phase represents the current phase of the backup operation.
type: string
schemaVersion:
description: |-
SchemaVersion is the DocumentDB extension schema version of the source
cluster at backup time, captured from the source DocumentDB's
status.schemaVersion. It is used to validate restore compatibility:
a restore must target a binary version >= this schema version, otherwise
an older binary would run against a newer, irreversible schema.
type: string
startedAt:
description: StartedAt is the time when the backup operation started.
format: date-time
type: string
stoppedAt:
description: StoppedAt is the time when the backup operation completed.
format: date-time
type: string
type: object
type: object
served: true
storage: false
subresources:
status: {}
- additionalPrinterColumns:
- description: Target DocumentDB cluster
jsonPath: .spec.cluster.name
name: Cluster
type: string
- description: Backup phase
jsonPath: .status.phase
name: Phase
type: string
- description: Backup start time
jsonPath: .status.startedAt
name: StartedAt
type: string
- description: Backup completion time
jsonPath: .status.stoppedAt
name: StoppedAt
type: string
- description: Backup expiration time
jsonPath: .status.expiredAt
name: ExpiredAt
type: string
- description: Backup status message
jsonPath: .status.message
name: Message
type: string
- description: DocumentDB schema version at backup time
jsonPath: .status.schemaVersion
name: SchemaVersion
type: string
name: v1
schema:
openAPIV3Schema:
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: BackupSpec defines the desired state of Backup.
properties:
cluster:
description: |-
Cluster specifies the DocumentDB cluster to backup.
The cluster must exist in the same namespace as the Backup resource.
properties:
name:
description: Name of the referent.
type: string
required:
- name
type: object
retentionDays:
description: |-
RetentionDays specifies how many days the backup should be retained.
If not specified, the default retention period from the cluster's backup retention policy will be used.
type: integer
required:
- cluster
type: object
x-kubernetes-validations:
- message: BackupSpec is immutable once set
rule: oldSelf == self
status:
description: BackupStatus defines the observed state of Backup.
properties:
expiredAt:
description: ExpiredAt is the time when the backup is considered expired
and can be deleted.
format: date-time
type: string
message:
description: |-
Message contains additional information about the backup status.
For failed backups, this contains the error message.
For skipped backups, this explains why the backup was skipped.
type: string
phase:
description: Phase represents the current phase of the backup operation.
type: string
schemaVersion:
description: |-
SchemaVersion is the DocumentDB extension schema version of the source
cluster at backup time, captured from the source DocumentDB's
status.schemaVersion. It is used to validate restore compatibility:
a restore must target a binary version >= this schema version, otherwise
an older binary would run against a newer, irreversible schema.
type: string
startedAt:
description: StartedAt is the time when the backup operation started.
format: date-time
type: string
stoppedAt:
description: StoppedAt is the time when the backup operation completed.
format: date-time
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
Loading
Loading