Repository navigation
Conversation
nmechack27
left a comment
There was a problem hiding this comment.
Thanks for putting this pr up so quickly. I left a couple of comments but overall looks good!
| // Replicas are the regions where the Namespace is placed. | ||
| // Maps to Temporal Cloud proto `NamespaceSpec.replicas`. | ||
| // +required | ||
| // Required and is enforced by the temporal-cloud-namespace-validation admission policy. |
There was a problem hiding this comment.
| // Required and is enforced by the temporal-cloud-namespace-validation admission policy. | |
| // Required unless the cloud.temporal.io/adoption-policy annotation is | |
| // "adopt"; enforced by the temporal-cloud-namespace-validation admission | |
| // policy, and by the operator before it creates or updates a Namespace. |
| // Maps to Temporal Cloud proto `NamespaceSpec.retention_days`. | ||
| // +required | ||
| RetentionDays int32 `json:"retentionDays"` | ||
| // Required and is enforced by the temporal-cloud-namespace-validation admission policy. |
There was a problem hiding this comment.
| // Required and is enforced by the temporal-cloud-namespace-validation admission policy. | |
| // Required unless the cloud.temporal.io/adoption-policy annotation is | |
| // "adopt"; enforced by the temporal-cloud-namespace-validation admission | |
| // policy, and by the operator before it creates or updates a Namespace. |
| expression: >- | ||
| !has(object.spec) ? [] : | ||
| (has(object.spec.replicas) ? [] : ['spec.replicas']) + | ||
| (has(object.spec.retentionDays) ? [] : ['spec.retentionDays']) |
There was a problem hiding this comment.
I think this would let retentionDays: 0 through. We can do object.spec.retentionDays > 0 here.
| - name: resourceID | ||
| expression: "object.?metadata.annotations['cloud.temporal.io/resource-id'].orValue('')" |
There was a problem hiding this comment.
Keeping resource-id here makes sense for resources that need an ID to adopt. For namespaces, though, adoption path looks the Namespace up by name in ResourceSetLatest, so it shouldn't require resource-id. Since this policy currently matches namespaces, the "resource-id is required when adopting" rule would reject a namespace adopt CR without one.
I think this should either move the resource-id rules into the per-resource policies and leave them out of namespace_validation_policy.yaml, or skip them for namespaces here (e.g. `request.resource.resource == 'namespaces' || ...)?
| - expression: >- | ||
| !variables.adoptionPolicy.hasValue() || | ||
| variables.adoptionPolicy.value() in ['adopt', 'adopt-or-create'] | ||
| messageExpression: >- | ||
| 'metadata.annotations[cloud.temporal.io/adoption-policy]: Unsupported value: "' + | ||
| variables.adoptionPolicy.value() + '": supported values: "adopt", "adopt-or-create"' | ||
| reason: Invalid |
There was a problem hiding this comment.
My pr only supports adopt for now so adopt-or-create would be treated as an invalid value. We can add it when it lands.
| - name: adoptionPolicy | ||
| expression: "object.?metadata.annotations['cloud.temporal.io/adoption-policy']" | ||
| - name: adopt | ||
| expression: "variables.adoptionPolicy.orValue('') == 'adopt'" |
There was a problem hiding this comment.
The operator lowercases and trims the annotation before validating so Adopt or adopt work here but these comparisons are exact the policy would reject them.
There's probably a way to by case sensitivity here.
There was a problem hiding this comment.
@nmechack27 we could lowercase the variable adoptionPolicy by changing its expression to:
expression: "object.?metadata.annotations['cloud.temporal.io/adoption-policy'].lowerAscii()"| @@ -0,0 +1,3 @@ | |||
| resources: | |||
| - cloud_resource_validation_policy.yaml | |||
| - namespace_validation_policy.yaml | |||
There was a problem hiding this comment.
Is this admission/ folder included in the top-level kustomization that make install uses?
Part of #56
Summary
adoptoradopt-or-createcloud.temporal.io/resource-idmust be set togetheradopt.replicasandretentionDayswhenever spec is set.spec,replicasandretentionDaysoptional in the CRD so an adopted namespace can omit spec.Testing
Note: A follow up PR will add GDT tests for the following manual testing