namespace resource¶
Description¶
NamespaceResource manages a cluster-scoped Kubernetes Namespace. The library's namespace configuration has no effect on this resource. Kubernetes controls Namespace status and finalizers.
Reads, updates, and deletion use the saved server, name, and UID with current credentials. A Namespace with the same name and a different UID is never adopted. Updates change annotations and labels with JSON Patch and do not wait for the Namespace to become Active.
Deletion uses a UID precondition and waits for removal. A different UID means that the managed instance is gone. Only the Terminating phase is pending; other phases and API errors fail deletion. The resource does not clear finalizers or force finalization.
Source: internal/api/core/v1/namespace_rsrc.go:37
Example usage:
imports: {
kubernetes-core-v1: 'github.com/cloudboss/unobin-library-kubernetes//api/core/v1'
}
resources: {
example: kubernetes-core-v1.namespace {
# Set input fields here.
}
}
Inputs¶
object
object
object({
metadata: object({
name: optional(string)
generate-name: optional(string)
annotations: optional(map(string))
labels: optional(map(string))
})
})
Object contains the required metadata object. Its writable fields are name, generate-name, annotations, and labels. Exactly one nonempty name or generate-name is required. Changing either configured identity field replaces the Namespace. A generated actual name is returned in object.metadata.name.
Annotations and labels accept string values, including empty strings. Omitted and empty maps are equivalent. Updates use the latest observed maps, or saved outputs when no observation exists. If that baseline map is empty, adding its first key replaces the entire remote map, including hidden keys. With a nonempty baseline, updates change individual keys and preserve unrelated remote keys.
Successful create and update outputs preserve the requested maps. Later reads return API values, filter internal Kubernetes keys and ignore patterns, and retain keys from prior outputs with their current values. Other nonignored remote keys remain visible; missing API keys disappear.
wait-for-default-service-account
optional(boolean)
WaitForDefaultServiceAccount defaults to false. When true, create waits for the default ServiceAccount in the actual created Namespace. It retries only not-found responses and completes when the account exists; it does not create an account or wait for a token. Read and update do not wait.
Create, including this wait, has a 20-minute budget bounded by caller cancellation. If the wait fails, create returns an error and the Namespace can remain. The resource does not roll back or adopt it on retry. Manual cleanup can be required before retrying.
delete-timeout
optional(string)
DeleteTimeout is a positive Go duration, such as 5m or 30s, and defaults to 5m. Deletion uses the prior input's timeout, bounded by caller cancellation, for both the delete request and the wait for removal.
ignore-annotations
optional(list(string))
IgnoreAnnotations lists regular expressions matched anywhere in annotation keys during reads. Keys present in prior outputs remain visible with their actual API values even when a pattern matches. These patterns do not prevent explicitly configured annotations from being created or updated. Invalid expressions fail validation before mutation.
ignore-labels
optional(list(string))
IgnoreLabels applies the same regular-expression and prior-output rules as ignore-annotations to label keys. It does not prevent explicitly configured labels from being created or updated.
Input Constraints¶
Object rules
Exactly one of object.metadata.name or object.metadata.generate-name.
Requirement.
Rule logic
- Require
@core.is-match(input.object.metadata.name, '^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$')
&& @core.length(input.object.metadata.name ?? '') <= 253
If set, object.metadata.generate-name must match the specified pattern.
Rule logic
- Require
@core.is-match(input.object.metadata.generate-name, '^([a-z0-9]([-a-z0-9]{0,61}[a-z0-9])?|[\\x00-\\x7f]-|[a-z0-9][-a-z0-9]{0,61}[\\x00-\\x7f]-)$')
Requirement.
Rule logic
- For each
input.object.metadata.labels ?? {}- Require
@core.is-match(@each.key, '^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?[A-Za-z0-9]([-A-Za-z0-9_.]*[A-Za-z0-9])?$')
&& @core.is-match(@each.key, '^([^/]{1,253}/)?[^/]{1,63}$')
If set, @each.value must match the specified pattern.
Rule logic
- For each
input.object.metadata.labels ?? {}- Require
@core.is-match(@each.value, '^([A-Za-z0-9]([-A-Za-z0-9_.]{0,61}[A-Za-z0-9])?)?$')
Requirement.
Rule logic
- For each
input.object.metadata.annotations ?? {}- Require
@core.is-match(@each.key, '^([a-zA-Z0-9İK]([-a-zA-Z0-9İK]*[a-zA-Z0-9İK])?(\\.[a-zA-Z0-9İK]([-a-zA-Z0-9İK]*[a-zA-Z0-9İK])?)*/)?[A-Za-z0-9İK]([-A-Za-z0-9_.İK]*[A-Za-z0-9İK])?$')
&& @core.is-match(@each.key, '^([^/]{1,253}/)?[^/]{1,63}$')
Ignore annotations rules
If set, @each.value must be a valid Go regular expression.
Rule logic
- For each
input.ignore-annotations ?? []- Require
@core.is-format(@each.value, 'regex')
Ignore labels rules
If set, @each.value must be a valid Go regular expression.
Rule logic
- For each
input.ignore-labels ?? []- Require
@core.is-format(@each.value, 'regex')
Delete timeout rules
If set, delete-timeout must be a positive duration.
Rule logic
- Require
@core.is-format(input.delete-timeout, 'positive-duration')
Outputs¶
server
string
api-version
string
kind
string
object
object
object({
metadata: object({
name: string
generate-name: string
uid: string
annotations: map(string)
labels: map(string)
})
})