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
6 changes: 5 additions & 1 deletion functions/branch/010-state-status.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@
{{- $sourceContentManifest := $sourceContentAtProvider.manifest | default dict }}
{{- $sourceContentSpec := $sourceContentManifest.spec | default dict }}
{{- $sourceContentSource := $sourceContentSpec.source | default dict }}
{{- $sourceSnapshotHandle := $sourceContentSource.snapshotHandle | default "" }}
{{- $sourceContentStatus := $sourceContentManifest.status | default dict }}
# Dynamic content identifies the source volume in spec.source.volumeHandle;
# the CSI snapshot ID is published in status.snapshotHandle. Pre-provisioned
# content can supply that ID in spec.source.snapshotHandle before status exists.
{{- $sourceSnapshotHandle := $sourceContentStatus.snapshotHandle | default $sourceContentSource.snapshotHandle | default "" }}
{{- $sourceSnapshotDriver := $sourceContentSpec.driver | default "" }}
{{- $sourceSnapshotVolumeMode := $sourceContentSpec.sourceVolumeMode | default "" }}
{{- $sourceSnapshotClassName := $sourceContentSpec.volumeSnapshotClassName | default "" }}
Expand Down
107 changes: 107 additions & 0 deletions tests/test-branch/main.k
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,36 @@ _ready_source_snapshot_content = lambda namespace, name {
}
}

_ready_dynamic_source_snapshot_content = lambda namespace, name {
{
apiVersion = "kubernetes.m.crossplane.io/v1alpha1"
kind = "Object"
metadata = {
name = name
namespace = namespace
annotations = {
"crossplane.io/composition-resource-name" = "source-snapshot-content"
"gotemplating.fn.crossplane.io/composition-resource-name" = "source-snapshot-content"
}
}
status = {
conditions = [{type = "Ready", status = "True"}]
atProvider.manifest = {
spec = {
driver = "ebs.csi.eks.amazonaws.com"
source.volumeHandle = "vol-0123456789abcdef0"
sourceVolumeMode = "Filesystem"
volumeSnapshotClassName = "psql"
}
status = {
snapshotHandle = "snap-dynamic0123456789"
readyToUse = True
}
}
}
}
}

_ready_branch_snapshot_content = lambda namespace, name {
{
apiVersion = "kubernetes.m.crossplane.io/v1alpha1"
Expand Down Expand Up @@ -367,6 +397,83 @@ _items = [
}
}

# Dynamic CSI content stores the source volume in spec and the resulting
# snapshot in status. Import the snapshot ID, never the source volume ID.
metav1alpha1.CompositionTest {
metadata.name = "cross-ns-imports-dynamic-status-snapshot-handle"
spec = {
compositionPath = "apis/psqlbranches/composition.yaml"
xrdPath = "apis/psqlbranches/definition.yaml"
timeoutSeconds = 60
validate = False
xr = stacksv1alpha1.PSQLBranch {
metadata = {name = "br-x", namespace = "preview-pr-1"}
spec = {
clusterName = "prod"
source = {name = "src-app", namespace = "team-app"}
}
}
observedResources = [
_ready_source_cluster("preview-pr-1", "br-x-source-cluster"),
{
apiVersion = "kubernetes.m.crossplane.io/v1alpha1"
kind = "Object"
metadata = {
name = "br-x-source-snapshot"
namespace = "preview-pr-1"
annotations = {
"crossplane.io/composition-resource-name" = "source-snapshot"
"gotemplating.fn.crossplane.io/composition-resource-name" = "source-snapshot"
}
}
status = {
conditions = [{type = "Ready", status = "True"}]
atProvider.manifest.status = {
boundVolumeSnapshotContentName = "snapcontent-from-source"
readyToUse = True
}
}
}
_ready_dynamic_source_snapshot_content("preview-pr-1", "br-x-source-snapshot-content")
]
assertResources = [
{
apiVersion = "kubernetes.m.crossplane.io/v1alpha1"
kind = "Object"
metadata.name = "br-x-branch-snapshot-content"
spec.forProvider.manifest.spec = {
deletionPolicy = "Retain"
driver = "ebs.csi.eks.amazonaws.com"
source.snapshotHandle = "snap-dynamic0123456789"
volumeSnapshotRef = {
name = "br-x-snap"
namespace = "preview-pr-1"
}
}
}
{
apiVersion = "kubernetes.m.crossplane.io/v1alpha1"
kind = "Object"
metadata.name = "br-x-branch-snapshot"
spec.forProvider.manifest.spec.source.volumeSnapshotContentName = "preview-pr-1-br-x-6a6f418e5232e5cb-content"
}
{
apiVersion = "hops.ops.com.ai/v1alpha1"
kind = "PSQLBranch"
metadata.name = "br-x"
status = {
ready = False
conditions = [
{type = "Responsive", status = "True"}
{type = "Synced", status = "True"}
{type = "Ready", status = "False"}
]
}
}
]
}
}

# ==========================================================================
# Cluster-scoped content names include a length-delimited identity hash, so
# delimiter-equivalent readable prefixes cannot collide.
Expand Down
3 changes: 2 additions & 1 deletion tests/test-branch/observed/cross-namespace-ready.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ status:
deletionPolicy: Delete
driver: ebs.csi.eks.amazonaws.com
source:
snapshotHandle: snap-0123456789abcdef0
volumeHandle: vol-0123456789abcdef0
sourceVolumeMode: Filesystem
volumeSnapshotClassName: psql
status:
snapshotHandle: snap-0123456789abcdef0
readyToUse: true
---
apiVersion: kubernetes.m.crossplane.io/v1alpha1
Expand Down
3 changes: 2 additions & 1 deletion tests/test-branch/observed/cross-namespace-staged.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ status:
spec:
driver: ebs.csi.eks.amazonaws.com
source:
snapshotHandle: snap-0123456789abcdef0
volumeHandle: vol-0123456789abcdef0
sourceVolumeMode: Filesystem
volumeSnapshotClassName: psql
status:
snapshotHandle: snap-0123456789abcdef0
readyToUse: true
Loading