@@ -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
356358func (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