Skip to content

Commit f31fcd6

Browse files
committed
remove duplicate temporalconnection check
1 parent 3303469 commit f31fcd6

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

internal/controller/worker_controller.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ func (r *WorkerDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req
198198
}
199199
}
200200

201+
// TODO(jlegrone): Set defaults via webhook rather than manually
202+
if err := workerDeploy.Default(ctx, &workerDeploy); err != nil {
203+
l.Error(err, "WorkerDeployment defaulter failed")
204+
return ctrl.Result{}, err
205+
}
206+
201207
// Fallback validation for spec constraints the CRD schema cannot enforce (rampPercentage
202208
// ordering, gate input/inputFrom exclusivity). When the optional TWD webhook is disabled
203209
// these checks would otherwise go unreported; this surfaces them as a condition and event.
@@ -212,11 +218,11 @@ func (r *WorkerDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req
212218
// Note: ConnectionRef.Name is validated by webhook due to +kubebuilder:validation:Required
213219

214220
// Fetch the connection parameters
215-
var temporalConnection temporaliov1alpha1.Connection
221+
var connection temporaliov1alpha1.Connection
216222
if err := r.Get(ctx, types.NamespacedName{
217223
Name: workerDeploy.Spec.WorkerOptions.ConnectionRef.Name,
218224
Namespace: workerDeploy.Namespace,
219-
}, &temporalConnection); err != nil {
225+
}, &connection); err != nil {
220226
l.Error(err, "unable to fetch Connection")
221227
r.recordWarningAndSetBlocked(ctx, &workerDeploy,
222228
temporaliov1alpha1.ReasonConnectionNotFound,
@@ -226,33 +232,26 @@ func (r *WorkerDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req
226232
}
227233

228234
// Ensure our finalizer is on the Connection so it cannot be deleted
229-
// while this TWD still references it. This guarantees the connection is available
230-
// during TWD deletion cleanup.
231-
if err := r.ensureConnectionFinalizer(ctx, l, &temporalConnection); err != nil {
232-
return ctrl.Result{}, err
233-
}
234-
235-
// Ensure our finalizer is on the TemporalConnection so it cannot be deleted
236-
// while this TWD still references it. This guarantees the connection is available
237-
// during TWD deletion cleanup.
238-
if err := r.ensureConnectionFinalizer(ctx, l, &temporalConnection); err != nil {
235+
// while this WD still references it. This guarantees the connection is available
236+
// during WD deletion cleanup.
237+
if err := r.ensureConnectionFinalizer(ctx, l, &connection); err != nil {
239238
return ctrl.Result{}, err
240239
}
241240

242241
// Get the Auth Mode and Secret Name
243-
authMode, secretName, err := resolveAuthSecretName(&temporalConnection)
242+
authMode, secretName, err := resolveAuthSecretName(&connection)
244243
if err != nil {
245244
l.Error(err, "unable to resolve auth secret name")
246245
r.recordWarningAndSetBlocked(ctx, &workerDeploy,
247246
temporaliov1alpha1.ReasonAuthSecretInvalid,
248-
fmt.Sprintf("Unable to resolve auth secret from Connection %q: %v", temporalConnection.Name, err),
247+
fmt.Sprintf("Unable to resolve auth secret from Connection %q: %v", connection.Name, err),
249248
fmt.Sprintf("Unable to resolve auth secret: %v", err))
250249
return ctrl.Result{}, err
251250
}
252251

253252
// Get or update temporal client for connection
254253
clientPoolKey := clientpool.ClientPoolKey{
255-
HostPort: temporalConnection.Spec.HostPort,
254+
HostPort: connection.Spec.HostPort,
256255
Namespace: workerDeploy.Spec.WorkerOptions.TemporalNamespace,
257256
SecretName: secretName,
258257
AuthMode: authMode,
@@ -262,14 +261,14 @@ func (r *WorkerDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req
262261
clientOpts, key, clientAuth, err := r.TemporalClientPool.ParseClientSecret(ctx, secretName, authMode, clientpool.NewClientOptions{
263262
K8sNamespace: workerDeploy.Namespace,
264263
TemporalNamespace: workerDeploy.Spec.WorkerOptions.TemporalNamespace,
265-
Spec: temporalConnection.Spec,
264+
Spec: connection.Spec,
266265
Identity: getControllerIdentity(),
267266
})
268267
if err != nil {
269268
l.Error(err, "invalid Temporal auth secret")
270269
r.recordWarningAndSetBlocked(ctx, &workerDeploy,
271270
temporaliov1alpha1.ReasonAuthSecretInvalid,
272-
fmt.Sprintf("Invalid Temporal auth secret for %s:%s: %v", temporalConnection.Spec.HostPort, workerDeploy.Spec.WorkerOptions.TemporalNamespace, err),
271+
fmt.Sprintf("Invalid Temporal auth secret for %s:%s: %v", connection.Spec.HostPort, workerDeploy.Spec.WorkerOptions.TemporalNamespace, err),
273272
fmt.Sprintf("Invalid auth secret: %v", err))
274273
return ctrl.Result{}, err
275274
}
@@ -279,7 +278,7 @@ func (r *WorkerDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req
279278
l.Error(err, "unable to create TemporalClient")
280279
r.recordWarningAndSetBlocked(ctx, &workerDeploy,
281280
temporaliov1alpha1.ReasonTemporalClientCreationFailed,
282-
fmt.Sprintf("Unable to create Temporal client for %s:%s: %v", temporalConnection.Spec.HostPort, workerDeploy.Spec.WorkerOptions.TemporalNamespace, err),
281+
fmt.Sprintf("Unable to create Temporal client for %s:%s: %v", connection.Spec.HostPort, workerDeploy.Spec.WorkerOptions.TemporalNamespace, err),
283282
fmt.Sprintf("Failed to connect to Temporal: %v", err))
284283
return ctrl.Result{}, err
285284
}
@@ -341,7 +340,7 @@ func (r *WorkerDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Req
341340
workerDeploy.Status = *status
342341

343342
// Generate a plan to get to desired spec from current status
344-
plan, err := r.generatePlan(ctx, l, &workerDeploy, temporalConnection.Spec, temporalState)
343+
plan, err := r.generatePlan(ctx, l, &workerDeploy, connection.Spec, temporalState)
345344
if err != nil {
346345
r.recordWarningAndSetBlocked(ctx, &workerDeploy,
347346
ReasonPlanGenerationFailed,

0 commit comments

Comments
 (0)