Skip to content

Commit 571ae6a

Browse files
authored
[Breaking change] Follow k8s API conventions (#136)
This PR updates the Temporal Worker Controller APIs to follow Kubernetes API conventions documented in https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md. ## What changed - Added standard `conditions` field to both status structs per k8s API conventions - Refactored `RampPercentage` in rollout spec from float to int - Changed connection references from plain strings to "ref" types (`connectionRef`, `mutualTLSSecretRef`) - Removed `Selector` field from `TemporalWorkerDeploymentSpec` (deployment selectors are now computed by the controller directly, avoiding possibility for misconfiguration) - Added validation kubebuilder annotations to several fields - Updated demo YAML examples to use new field names ## Breaking changes This requires updating existing YAML files due to field name changes and reinstalling the CRDs. ## Checklist 1. Closes #103 2. How was this tested: unit/integration tests should pass 3. Any docs updates needed?
1 parent 2c388e5 commit 571ae6a

21 files changed

+318
-250
lines changed

api/v1alpha1/temporalconnection_types.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,41 @@ import (
1010

1111
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
1212

13+
// SecretReference contains the name of a Secret resource in the same namespace.
14+
type SecretReference struct {
15+
// Name of the Secret resource.
16+
// +kubebuilder:validation:Required
17+
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
18+
Name string `json:"name"`
19+
}
20+
1321
// TemporalConnectionSpec defines the desired state of TemporalConnection
1422
type TemporalConnectionSpec struct {
1523
// The host and port of the Temporal server.
24+
// +kubebuilder:validation:Pattern=`^[a-zA-Z0-9.-]+:[0-9]+$`
1625
HostPort string `json:"hostPort"`
1726

18-
// MutualTLSSecret is the name of the Secret that contains the TLS certificate and key
27+
// MutualTLSSecretRef is the name of the Secret that contains the TLS certificate and key
1928
// for mutual TLS authentication. The secret must be `type: kubernetes.io/tls` and exist
2029
// in the same Kubernetes namespace as the TemporalConnection resource.
2130
//
2231
// More information about creating a TLS secret:
2332
// https://kubernetes.io/docs/concepts/configuration/secret/#tls-secrets
24-
MutualTLSSecret string `json:"mutualTLSSecret,omitempty"`
33+
// +optional
34+
MutualTLSSecretRef *SecretReference `json:"mutualTLSSecretRef,omitempty"`
2535
}
2636

2737
// TemporalConnectionStatus defines the observed state of TemporalConnection
2838
type TemporalConnectionStatus struct {
29-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
30-
// Important: Run "make" to regenerate code after modifying this file
39+
// TODO(jlegrone): Add additional status fields following Kubernetes API conventions
40+
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
3141
}
3242

3343
//+kubebuilder:object:root=true
3444
//+kubebuilder:subresource:status
45+
//+kubebuilder:resource:shortName=tconn
46+
//+kubebuilder:printcolumn:name="Host",type="string",JSONPath=".spec.hostPort",description="Temporal server endpoint"
47+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age"
3548

3649
// TemporalConnection is the Schema for the temporalconnections API
3750
type TemporalConnection struct {

api/v1alpha1/temporalworker_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func validateRolloutStrategy(s RolloutStrategy) []*field.Error {
112112
field.Invalid(field.NewPath("spec.rollout.steps"), rolloutSteps, "steps are required for Progressive rollout"),
113113
)
114114
}
115-
var lastRamp float32
115+
var lastRamp int
116116
for i, s := range rolloutSteps {
117117
// Check duration >= 30s
118118
if s.PauseDuration.Duration < 30*time.Second {

api/v1alpha1/worker_types.go

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,33 @@ import (
1111

1212
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
1313

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+
1423
type WorkerOptions struct {
1524
// The name of a TemporalConnection in the same namespace as the TemporalWorkerDeployment.
16-
TemporalConnection string `json:"connection"`
25+
TemporalConnectionRef TemporalConnectionReference `json:"connectionRef"`
1726
// The Temporal namespace for the worker to connect to.
27+
// +kubebuilder:validation:MinLength=1
1828
TemporalNamespace string `json:"temporalNamespace"`
1929
}
2030

2131
// TemporalWorkerDeploymentSpec defines the desired state of TemporalWorkerDeployment
2232
type TemporalWorkerDeploymentSpec struct {
23-
// Important: Run "make" to regenerate code after modifying this file
2433

2534
// Number of desired pods. This is a pointer to distinguish between explicit
2635
// zero and not specified. Defaults to 1.
2736
// This field makes TemporalWorkerDeploymentSpec implement the scale subresource, which is compatible with auto-scalers.
28-
// TODO(jlegrone): Configure min replicas per thousand workflow/activity tasks?
2937
// +optional
38+
// +kubebuilder:default=1
3039
Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"`
3140

32-
// Label selector for pods. Existing ReplicaSets whose pods are
33-
// selected by this will be the ones affected by this deployment.
34-
// It must match the pod template's labels.
35-
// +optional
36-
Selector *metav1.LabelSelector `json:"selector" protobuf:"bytes,2,opt,name=selector"`
37-
3841
// Template describes the pods that will be created.
3942
// The only allowed template.spec.restartPolicy value is "Always".
4043
Template corev1.PodTemplateSpec `json:"template"`
@@ -43,13 +46,15 @@ type TemporalWorkerDeploymentSpec struct {
4346
// without any of its container crashing, for it to be considered available.
4447
// Defaults to 0 (pod will be considered available as soon as it is ready)
4548
// +optional
49+
// +kubebuilder:default=0
4650
MinReadySeconds int32 `json:"minReadySeconds,omitempty"`
4751

4852
// The maximum time in seconds for a deployment to make progress before it
4953
// is considered to be failed. The deployment controller will continue to
5054
// process failed deployments and a condition with a ProgressDeadlineExceeded
5155
// reason will be surfaced in the deployment status. Note that progress will
5256
// not be estimated during the time a deployment is paused. Defaults to 600s.
57+
// +kubebuilder:default=600
5358
ProgressDeadlineSeconds *int32 `json:"progressDeadlineSeconds,omitempty" protobuf:"varint,9,opt,name=progressDeadlineSeconds"`
5459

5560
// How to rollout new workflow executions to the target version.
@@ -58,7 +63,7 @@ type TemporalWorkerDeploymentSpec struct {
5863
// How to manage sunsetting drained versions.
5964
SunsetStrategy SunsetStrategy `json:"sunset"`
6065

61-
// TODO(jlegrone): add godoc
66+
// WorkerOptions configures the worker's connection to Temporal.
6267
WorkerOptions WorkerOptions `json:"workerOptions"`
6368
}
6469

@@ -128,7 +133,11 @@ type TemporalWorkerDeploymentStatus struct {
128133
// VersionCount is the total number of versions currently known by the worker deployment.
129134
// This includes current, target, ramping, and deprecated versions.
130135
// +optional
136+
// +kubebuilder:validation:Minimum=0
131137
VersionCount int32 `json:"versionCount,omitempty"`
138+
139+
// TODO(jlegrone): Add additional status fields following Kubernetes API conventions
140+
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
132141
}
133142

134143
// WorkflowExecutionStatus describes the current state of a workflow.
@@ -173,11 +182,11 @@ type BaseWorkerDeploymentVersion struct {
173182

174183
// Healthy indicates whether the deployment version is healthy.
175184
// +optional
176-
HealthySince *metav1.Time `json:"healthySince"`
185+
HealthySince *metav1.Time `json:"healthySince,omitempty"`
177186

178187
// A pointer to the version's managed k8s deployment.
179188
// +optional
180-
Deployment *corev1.ObjectReference `json:"deployment"`
189+
Deployment *corev1.ObjectReference `json:"deployment,omitempty"`
181190

182191
// TaskQueues is a list of task queues that are associated with this version.
183192
TaskQueues []TaskQueue `json:"taskQueues,omitempty"`
@@ -204,15 +213,18 @@ type TargetWorkerDeploymentVersion struct {
204213
TestWorkflows []WorkflowExecution `json:"testWorkflows,omitempty"`
205214

206215
// RampPercentage is the percentage of new workflow executions that are
207-
// configured to start on this version. Only set when Status is VersionStatusRamping.
216+
// configured to start on this version. For example, 1.5 means 1.5%.
217+
// Only set when Status is VersionStatusRamping.
208218
//
209-
// Acceptable range is [0,100].
219+
// Acceptable range is [0.0,100.0] (0% to 100%).
220+
// +kubebuilder:validation:Minimum=0.0
221+
// +kubebuilder:validation:Maximum=100.0
210222
RampPercentage *float32 `json:"rampPercentage,omitempty"`
211223

212224
// RampingSince is time when the version first started ramping.
213225
// Only set when Status is VersionStatusRamping.
214226
// +optional
215-
RampingSince *metav1.Time `json:"rampingSince"`
227+
RampingSince *metav1.Time `json:"rampingSince,omitempty"`
216228

217229
// RampLastModifiedAt is the time when the ramp percentage was last changed for the target version.
218230
// +optional
@@ -227,7 +239,7 @@ type DeprecatedWorkerDeploymentVersion struct {
227239
// DrainedSince is the time at which the version became drained.
228240
// Only set when Status is VersionStatusDrained.
229241
// +optional
230-
DrainedSince *metav1.Time `json:"drainedSince"`
242+
DrainedSince *metav1.Time `json:"drainedSince,omitempty"`
231243

232244
// A Version is eligible for deletion if it is drained and has no pollers on any task queue.
233245
// After pollers stop polling, the server will still consider them present until `matching.PollerHistoryTTL`
@@ -286,11 +298,13 @@ type SunsetStrategy struct {
286298
// ScaledownDelay specifies how long to wait after a version is drained before scaling its Deployment to zero.
287299
// Defaults to 1 hour.
288300
// +optional
301+
// +kubebuilder:default="1h"
289302
ScaledownDelay *metav1.Duration `json:"scaledownDelay"`
290303

291304
// DeleteDelay specifies how long to wait after a version is drained before deleting its Deployment.
292305
// Defaults to 24 hours.
293306
// +optional
307+
// +kubebuilder:default="24h"
294308
DeleteDelay *metav1.Duration `json:"deleteDelay"`
295309
}
296310

@@ -299,37 +313,26 @@ type AllAtOnceRolloutStrategy struct{}
299313
type RolloutStep struct {
300314
// RampPercentage indicates what percentage of new workflow executions should be
301315
// routed to the new worker deployment version while this step is active.
316+
// For example, 15 means 15%.
302317
//
303-
// Acceptable range is [0,100].
304-
RampPercentage float32 `json:"rampPercentage"`
318+
// Acceptable range is [1,99] (1% to 99%).
319+
// +kubebuilder:validation:Minimum=1
320+
// +kubebuilder:validation:Maximum=99
321+
RampPercentage int `json:"rampPercentage"`
305322

306323
// PauseDuration indicates how long to pause before progressing to the next step.
307324
PauseDuration metav1.Duration `json:"pauseDuration"`
308325
}
309326

310327
type ManualRolloutStrategy struct{}
311328

312-
type QueueStatistics struct {
313-
// The approximate number of tasks backlogged in this task queue. May count expired tasks but eventually converges
314-
// to the right value.
315-
ApproximateBacklogCount int64 `json:"approximateBacklogCount,omitempty"`
316-
// Approximate age of the oldest task in the backlog based on the creation timestamp of the task at the head of the queue.
317-
ApproximateBacklogAge metav1.Duration `json:"approximateBacklogAge,omitempty"`
318-
// Approximate tasks per second added to the task queue based on activity within a fixed window. This includes both backlogged and
319-
// sync-matched tasks.
320-
TasksAddRate float32 `json:"tasksAddRate,omitempty"`
321-
// Approximate tasks per second dispatched to workers based on activity within a fixed window. This includes both backlogged and
322-
// sync-matched tasks.
323-
TasksDispatchRate float32 `json:"tasksDispatchRate,omitempty"`
324-
}
325-
326329
//+kubebuilder:object:root=true
327330
//+kubebuilder:subresource:status
328331
// +kubebuilder:resource:shortName=twd;twdeployment;tworkerdeployment
329-
//+kubebuilder:printcolumn:name="Current",type="string",JSONPath=".status.currentVersion.buildID",description="Current Version Build ID"
330-
//+kubebuilder:printcolumn:name="Target",type="string",JSONPath=".status.targetVersion.buildID",description="Build ID of the target worker (based on the pod template)"
331-
//+kubebuilder:printcolumn:name="Target-Ramp",type="number",JSONPath=".status.targetVersion.rampPercentage",description="Percentage of new workflows starting on Target Version"
332-
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
332+
//+kubebuilder:printcolumn:name="Current",type="string",JSONPath=".status.currentVersion.buildID",description="Current build ID"
333+
//+kubebuilder:printcolumn:name="Target",type="string",JSONPath=".status.targetVersion.buildID",description="Target build ID"
334+
//+kubebuilder:printcolumn:name="Ramp %",type="number",JSONPath=".status.targetVersion.rampPercentage",description="Ramp percentage"
335+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age"
333336

334337
// TemporalWorkerDeployment is the Schema for the temporalworkerdeployments API
335338
type TemporalWorkerDeployment struct {

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 42 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)