Skip to content

Commit c23d500

Browse files
committed
redefine deprecated CRDs in Go
1 parent 6fef525 commit c23d500

7 files changed

Lines changed: 354 additions & 4 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
2+
//
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2024 Datadog, Inc.
4+
5+
package v1alpha1
6+
7+
import (
8+
corev1 "k8s.io/api/core/v1"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
)
11+
12+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
13+
14+
// TemporalConnectionSpec defines the desired state of TemporalConnection
15+
// +kubebuilder:validation:XValidation:rule="!(has(self.mutualTLSSecretRef) && has(self.apiKeySecretRef))",message="Only one of mutualTLSSecretRef or apiKeySecretRef may be set"
16+
type TemporalConnectionSpec struct {
17+
// The host and port of the Temporal server.
18+
// +kubebuilder:validation:Pattern=`^[a-zA-Z0-9.-]+:[0-9]+$`
19+
HostPort string `json:"hostPort"`
20+
21+
// MutualTLSSecretRef is the name of the Secret that contains the TLS certificate and key
22+
// for mutual TLS authentication. The secret must be `type: kubernetes.io/tls` or
23+
// `type: Opaque` and exist in the same Kubernetes namespace as the TemporalConnection
24+
// resource. Opaque secrets are useful when bundling tls.crt, tls.key, and ca.crt into
25+
// a single secret (e.g. multi-file cert-manager outputs).
26+
//
27+
// More information about creating a TLS secret:
28+
// https://kubernetes.io/docs/concepts/configuration/secret/#tls-secrets
29+
// +optional
30+
MutualTLSSecretRef *SecretReference `json:"mutualTLSSecretRef,omitempty"`
31+
32+
// APIKeySecretRef selects the Secret key that contains the API key used for authentication.
33+
// The Secret must be `type: kubernetes.io/opaque` and exist in the same Kubernetes namespace as
34+
// the TemporalConnection resource. This is a corev1.SecretKeySelector and encodes both:
35+
// - LocalObjectReference.Name: the name of the Secret resource
36+
// - Key: the data key within Secret.Data whose value is the API key token
37+
// +optional
38+
APIKeySecretRef *corev1.SecretKeySelector `json:"apiKeySecretRef,omitempty"`
39+
}
40+
41+
// TemporalConnectionStatus defines the observed state of TemporalConnection
42+
type TemporalConnectionStatus struct {
43+
// TODO(jlegrone): Add additional status fields following Kubernetes API conventions
44+
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
45+
}
46+
47+
//+kubebuilder:object:root=true
48+
//+kubebuilder:subresource:status
49+
//+kubebuilder:resource:shortName=tconn
50+
//+kubebuilder:printcolumn:name="Host",type="string",JSONPath=".spec.hostPort",description="Temporal server endpoint"
51+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age"
52+
// +kubebuilder:validation:XValidation:rule="oldSelf != null",message="TemporalConnection is deprecated and cannot be created. Use Connection instead."
53+
// +kubebuilder:deprecatedversion:warning="TemporalConnection is deprecated. Use Connection instead."
54+
55+
// TemporalConnection is the Schema for the temporalconnections API
56+
type TemporalConnection struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ObjectMeta `json:"metadata,omitempty"`
59+
60+
Spec TemporalConnectionSpec `json:"spec,omitempty"`
61+
Status TemporalConnectionStatus `json:"status,omitempty"`
62+
}
63+
64+
//+kubebuilder:object:root=true
65+
66+
// TemporalConnectionList contains a list of TemporalConnection
67+
type TemporalConnectionList struct {
68+
metav1.TypeMeta `json:",inline"`
69+
metav1.ListMeta `json:"metadata,omitempty"`
70+
Items []TemporalConnection `json:"items"`
71+
}
72+
73+
func init() {
74+
SchemeBuilder.Register(&TemporalConnection{}, &TemporalConnectionList{})
75+
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License.
2+
//
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2024 Datadog, Inc.
4+
5+
package v1alpha1
6+
7+
import (
8+
corev1 "k8s.io/api/core/v1"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
)
11+
12+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
13+
14+
// TemporalConnectionReference contains the name of a TemporalConnection resource
15+
// in the same namespace as the TemporalWorkerDeployment.
16+
type TemporalConnectionReference struct {
17+
// Name of the TemporalConnection resource.
18+
// +kubebuilder:validation:Required
19+
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
20+
Name string `json:"name"`
21+
}
22+
23+
type DeprecatedWorkerOptions struct {
24+
// The name of a TemporalConnection in the same namespace as the TemporalWorkerDeployment.
25+
TemporalConnectionRef TemporalConnectionReference `json:"connectionRef"`
26+
// The Temporal namespace for the worker to connect to.
27+
// +kubebuilder:validation:MinLength=1
28+
TemporalNamespace string `json:"temporalNamespace"`
29+
// UnsafeCustomBuildID optionally overrides the auto-generated build ID for this worker deployment.
30+
// When set, the controller uses this value instead of computing a build ID from the
31+
// pod template hash. This enables rolling updates for non-workflow code changes
32+
// (bug fixes, config changes) while preserving the same build ID.
33+
//
34+
// WARNING: Using a custom build ID requires careful management. If workflow code changes
35+
// but UnsafeCustomBuildID stays the same, pinned workflows may execute on workers running incompatible
36+
// code. Only use this when you have a reliable way to detect changes in your workflow
37+
// definitions (e.g., hashing workflow source files in CI/CD).
38+
//
39+
// When the UnsafeCustomBuildID is stable but pod template spec changes, the controller triggers
40+
// a rolling update instead of creating a new deployment version. The controller uses
41+
// a hash of the user-provided pod template spec to detect ANY changes, including
42+
// container images, env vars, commands, volumes, resources, and all other fields.
43+
// +optional
44+
// +kubebuilder:validation:MaxLength=63
45+
// +kubebuilder:validation:Pattern=`^[a-zA-Z0-9]([a-zA-Z0-9._-]*[a-zA-Z0-9])?$`
46+
UnsafeCustomBuildID string `json:"unsafeCustomBuildID,omitempty"`
47+
}
48+
49+
// TemporalWorkerDeploymentSpec defines the desired state of TemporalWorkerDeployment
50+
type TemporalWorkerDeploymentSpec struct {
51+
52+
// Number of desired pods. When set, the controller manages replicas for all active
53+
// worker versions. When omitted (nil), the controller creates versioned Deployments
54+
// with nil replicas and never calls UpdateScale on active versions — following the
55+
// Kubernetes-recommended pattern for HPA and other external autoscalers
56+
// (https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#migrating-deployments-and-statefulsets-to-horizontal-autoscaling).
57+
// The controller still scales drained versions (and inactive versions that are not
58+
// the rollout target) to zero regardless.
59+
// This field makes TemporalWorkerDeploymentSpec implement the scale subresource, which is compatible with auto-scalers.
60+
// +optional
61+
Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"`
62+
63+
// Template describes the pods that will be created.
64+
// The only allowed template.spec.restartPolicy value is "Always".
65+
Template corev1.PodTemplateSpec `json:"template"`
66+
67+
// Minimum number of seconds for which a newly created pod should be ready
68+
// without any of its container crashing, for it to be considered available.
69+
// Defaults to 0 (pod will be considered available as soon as it is ready)
70+
// +optional
71+
// +kubebuilder:default=0
72+
MinReadySeconds int32 `json:"minReadySeconds,omitempty"`
73+
74+
// The maximum time in seconds for a deployment to make progress before it
75+
// is considered to be failed. The deployment controller will continue to
76+
// process failed deployments and a condition with a ProgressDeadlineExceeded
77+
// reason will be surfaced in the deployment status. Note that progress will
78+
// not be estimated during the time a deployment is paused. Defaults to 600s.
79+
// +kubebuilder:default=600
80+
ProgressDeadlineSeconds *int32 `json:"progressDeadlineSeconds,omitempty" protobuf:"varint,9,opt,name=progressDeadlineSeconds"`
81+
82+
// How to rollout new workflow executions to the target version.
83+
RolloutStrategy RolloutStrategy `json:"rollout"`
84+
85+
// How to manage sunsetting drained versions.
86+
SunsetStrategy SunsetStrategy `json:"sunset"`
87+
88+
// WorkerOptions configures the worker's connection to Temporal.
89+
WorkerOptions DeprecatedWorkerOptions `json:"workerOptions"`
90+
}
91+
92+
// Condition reason constants for TemporalWorkerDeployment.
93+
//
94+
// These strings appear in status.conditions[].reason and are part of the CRD's
95+
// status API. Operators, monitoring rules, and scripts may depend on them.
96+
// They should be treated as stable within an API version and renamed only with
97+
// a corresponding version bump.
98+
const (
99+
// ReasonTemporalConnectionNotFound is set on ConditionProgressing=False when the
100+
// referenced TemporalConnection resource cannot be found.
101+
ReasonTemporalConnectionNotFound = "TemporalConnectionNotFound"
102+
103+
// Deprecated: Use ReasonRolloutComplete on ConditionReady instead.
104+
ReasonTemporalConnectionHealthy = "TemporalConnectionHealthy"
105+
)
106+
107+
// TemporalWorkerDeploymentStatus defines the observed state of TemporalWorkerDeployment
108+
type TemporalWorkerDeploymentStatus struct {
109+
// Remember, status should be able to be reconstituted from the state of the world,
110+
// so it's generally not a good idea to read from the status of the root object.
111+
// Instead, you should reconstruct it every run.
112+
113+
// TargetVersion is the desired next version. If TargetVersion.Deployment is nil,
114+
// then the controller should create it. If not nil, the controller should
115+
// wait for it to become healthy and then move it to the CurrentVersion.
116+
TargetVersion TargetWorkerDeploymentVersion `json:"targetVersion"`
117+
118+
// CurrentVersion is the version that is currently registered with
119+
// Temporal as the current version of its worker deployment. This will be nil
120+
// during initial bootstrap until a version is registered and set as current.
121+
CurrentVersion *CurrentWorkerDeploymentVersion `json:"currentVersion,omitempty"`
122+
123+
// DeprecatedVersions are deployment versions that are no longer the default. Any
124+
// deployment versions that are unreachable should be deleted by the controller.
125+
DeprecatedVersions []*DeprecatedWorkerDeploymentVersion `json:"deprecatedVersions,omitempty"`
126+
127+
// VersionConflictToken prevents concurrent modifications to the deployment status.
128+
// It ensures reconciliation operations don't inadvertently override changes made
129+
// by external systems while processing is underway.
130+
VersionConflictToken []byte `json:"versionConflictToken,omitempty"`
131+
132+
// LastModifierIdentity is the identity of the client that most recently modified the worker deployment.
133+
// +optional
134+
LastModifierIdentity string `json:"lastModifierIdentity,omitempty"`
135+
136+
// ManagerIdentity is the identity that has exclusive rights to modify this Worker Deployment's routing config.
137+
// When set, clients whose identity does not match will be blocked from making routing changes.
138+
// Empty by default. Use `temporal worker deployment manager-identity set/unset` to change.
139+
// +optional
140+
ManagerIdentity string `json:"managerIdentity,omitempty"`
141+
142+
// VersionCount is the total number of versions currently known by the worker deployment.
143+
// This includes current, target, ramping, and deprecated versions.
144+
// +optional
145+
// +kubebuilder:validation:Minimum=0
146+
VersionCount int32 `json:"versionCount,omitempty"`
147+
148+
// Conditions represent the latest available observations of the TemporalWorkerDeployment's current state.
149+
// +optional
150+
Conditions []metav1.Condition `json:"conditions,omitempty"`
151+
}
152+
153+
//+kubebuilder:object:root=true
154+
//+kubebuilder:subresource:status
155+
// +kubebuilder:resource:shortName=twd;twdeployment;tworkerdeployment
156+
//+kubebuilder:printcolumn:name="Current",type="string",JSONPath=".status.currentVersion.buildID",description="Current build ID"
157+
//+kubebuilder:printcolumn:name="Target",type="string",JSONPath=".status.targetVersion.buildID",description="Target build ID"
158+
//+kubebuilder:printcolumn:name="Ramp %",type="number",JSONPath=".status.targetVersion.rampPercentage",description="Ramp percentage"
159+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age"
160+
// +kubebuilder:validation:XValidation:rule="size(self.metadata.name) <= 63",message="name cannot be more than 63 characters"
161+
// +kubebuilder:validation:XValidation:rule="oldSelf != null",message="TemporalWorkerDeployment is deprecated and cannot be created. Use WorkerDeployment instead."
162+
// +kubebuilder:deprecatedversion:warning="TemporalWorkerDeployment is deprecated. Use WorkerDeployment instead."
163+
164+
// TemporalWorkerDeployment is the Schema for the temporalworkerdeployments API
165+
type TemporalWorkerDeployment struct {
166+
metav1.TypeMeta `json:",inline"`
167+
metav1.ObjectMeta `json:"metadata,omitempty"`
168+
169+
Spec TemporalWorkerDeploymentSpec `json:"spec,omitempty"`
170+
Status TemporalWorkerDeploymentStatus `json:"status,omitempty"`
171+
}
172+
173+
//+kubebuilder:object:root=true
174+
175+
// TemporalWorkerDeploymentList contains a list of TemporalWorkerDeployment
176+
type TemporalWorkerDeploymentList struct {
177+
metav1.TypeMeta `json:",inline"`
178+
metav1.ListMeta `json:"metadata,omitempty"`
179+
Items []TemporalWorkerDeployment `json:"items"`
180+
}
181+
182+
func init() {
183+
SchemeBuilder.Register(&TemporalWorkerDeployment{}, &TemporalWorkerDeploymentList{})
184+
}

config/rbac/role.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: manager-role
6+
rules:
7+
- apiGroups:
8+
- ""
9+
resources:
10+
- events
11+
verbs:
12+
- create
13+
- patch
14+
- apiGroups:
15+
- ""
16+
resources:
17+
- secrets
18+
verbs:
19+
- get
20+
- list
21+
- watch
22+
- apiGroups:
23+
- apps
24+
resources:
25+
- deployments
26+
verbs:
27+
- create
28+
- delete
29+
- get
30+
- list
31+
- patch
32+
- update
33+
- watch
34+
- apiGroups:
35+
- apps
36+
resources:
37+
- deployments/scale
38+
verbs:
39+
- update
40+
- apiGroups:
41+
- authorization.k8s.io
42+
resources:
43+
- subjectaccessreviews
44+
verbs:
45+
- create
46+
- apiGroups:
47+
- temporal.io
48+
resources:
49+
- connections
50+
- temporalconnections
51+
- workerresourcetemplates
52+
verbs:
53+
- get
54+
- list
55+
- patch
56+
- update
57+
- watch
58+
- apiGroups:
59+
- temporal.io
60+
resources:
61+
- connections/finalizers
62+
- temporalconnections/finalizers
63+
- temporalworkerdeployments/finalizers
64+
- workerdeployments/finalizers
65+
verbs:
66+
- update
67+
- apiGroups:
68+
- temporal.io
69+
resources:
70+
- temporalconnections/status
71+
- temporalworkerdeployments/status
72+
- workerdeployments/status
73+
- workerresourcetemplates/status
74+
verbs:
75+
- get
76+
- patch
77+
- update
78+
- apiGroups:
79+
- temporal.io
80+
resources:
81+
- temporalworkerdeployments
82+
- workerdeployments
83+
verbs:
84+
- create
85+
- delete
86+
- get
87+
- list
88+
- patch
89+
- update
90+
- watch

helm/temporal-worker-controller-crds/templates/temporal.io_temporalconnections.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ spec:
2525
jsonPath: .metadata.creationTimestamp
2626
name: Age
2727
type: date
28+
deprecated: true
29+
deprecationWarning: TemporalConnection is deprecated. Use Connection instead.
2830
name: v1alpha1
2931
schema:
3032
openAPIV3Schema:
@@ -74,8 +76,6 @@ spec:
7476
- message: TemporalConnection is deprecated and cannot be created. Use Connection
7577
instead.
7678
rule: oldSelf != null
77-
deprecated: true
78-
deprecationWarning: TemporalConnection is deprecated. Use Connection instead.
7979
served: true
8080
storage: true
8181
subresources:

helm/temporal-worker-controller-crds/templates/temporal.io_temporalworkerdeployments.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ spec:
3535
jsonPath: .metadata.creationTimestamp
3636
name: Age
3737
type: date
38+
deprecated: true
39+
deprecationWarning: TemporalWorkerDeployment is deprecated. Use WorkerDeployment
40+
instead.
3841
name: v1alpha1
3942
schema:
4043
openAPIV3Schema:
@@ -4214,8 +4217,6 @@ spec:
42144217
- message: TemporalWorkerDeployment is deprecated and cannot be created. Use
42154218
WorkerDeployment instead.
42164219
rule: oldSelf != null
4217-
deprecated: true
4218-
deprecationWarning: TemporalWorkerDeployment is deprecated. Use WorkerDeployment instead.
42194220
served: true
42204221
storage: true
42214222
subresources:

0 commit comments

Comments
 (0)