Skip to content

Commit 5e1b54d

Browse files
author
eliranb
committed
add checks for missing workloadName in reconcileDeployment and reconcileStatefulSet functions to improve error handling.
1 parent a712847 commit 5e1b54d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

internal/controller/lightrunjavaagent_controller.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ func (r *LightrunJavaAgentReconciler) determineWorkloadType(lightrunJavaAgent *a
9999
// === Case 2: New fields — WorkloadName + WorkloadType ===
100100
if !isDeploymentConfigured && isWorkloadConfigured {
101101
if spec.WorkloadType == "" {
102-
return "", errors.New("WorkloadType must be set when using WorkloadName")
102+
return "", errors.New("workloadType must be set when using workloadName")
103103
}
104104
if spec.WorkloadName == "" {
105-
return "", errors.New("WorkloadName must be set when using WorkloadType")
105+
return "", errors.New("workloadName must be set when workloadType is specified")
106106
}
107107
return spec.WorkloadType, nil
108108
}
@@ -125,7 +125,9 @@ func (r *LightrunJavaAgentReconciler) reconcileDeployment(ctx context.Context, l
125125
// Fall back to legacy field if WorkloadName isn't set
126126
deploymentName = lightrunJavaAgent.Spec.DeploymentName
127127
}
128-
128+
if deploymentName == "" {
129+
return r.errorStatus(ctx, lightrunJavaAgent, errors.New("unable to reconcile deployment: missing workloadName or deploymentName(legacy and deprecated)"))
130+
}
129131
log := r.Log.WithValues("lightrunJavaAgent", lightrunJavaAgent.Name, "deployment", deploymentName)
130132
fieldManager := "lightrun-conrtoller"
131133

@@ -356,7 +358,10 @@ func (r *LightrunJavaAgentReconciler) reconcileDeployment(ctx context.Context, l
356358
func (r *LightrunJavaAgentReconciler) reconcileStatefulSet(ctx context.Context, lightrunJavaAgent *agentv1beta.LightrunJavaAgent, namespace string) (ctrl.Result, error) {
357359
log := r.Log.WithValues("lightrunJavaAgent", lightrunJavaAgent.Name, "statefulSet", lightrunJavaAgent.Spec.WorkloadName)
358360
fieldManager := "lightrun-controller"
359-
361+
statefulSetName := lightrunJavaAgent.Spec.WorkloadName
362+
if statefulSetName == "" {
363+
return r.errorStatus(ctx, lightrunJavaAgent, errors.New("unable to reconcile statefulset: missing workloadName field"))
364+
}
360365
stsNamespacedObj := client.ObjectKey{
361366
Name: lightrunJavaAgent.Spec.WorkloadName,
362367
Namespace: namespace,

0 commit comments

Comments
 (0)