@@ -86,31 +86,30 @@ func (r *LightrunJavaAgentReconciler) Reconcile(ctx context.Context, req ctrl.Re
8686
8787func (r * LightrunJavaAgentReconciler ) determineWorkloadType (lightrunJavaAgent * agentv1beta.LightrunJavaAgent ) (agentv1beta.WorkloadType , error ) {
8888 spec := lightrunJavaAgent .Spec
89+ // Check which configuration approach is being used
90+ var isDeploymentConfigured bool = spec .DeploymentName != ""
91+ var isWorkloadConfigured bool = spec .WorkloadName != "" || spec .WorkloadType != ""
8992
9093 // === Case 1: Legacy only — DeploymentName only ===
91- if spec .DeploymentName != "" && spec .WorkloadName == "" && spec .WorkloadType == "" {
94+ if isDeploymentConfigured && ! isWorkloadConfigured {
95+ r .Log .Info ("Using deprecated field deploymentName, consider migrating to workloadName and workloadType" )
9296 return agentv1beta .WorkloadTypeDeployment , nil
9397 }
9498
9599 // === Case 2: New fields — WorkloadName + WorkloadType ===
96- if spec . DeploymentName == "" && spec . WorkloadName != "" {
100+ if ! isDeploymentConfigured && isWorkloadConfigured {
97101 if spec .WorkloadType == "" {
98102 return "" , errors .New ("WorkloadType must be set when using WorkloadName" )
99103 }
104+ if spec .WorkloadName == "" {
105+ return "" , errors .New ("WorkloadName must be set when using WorkloadType" )
106+ }
100107 return spec .WorkloadType , nil
101108 }
102109
103- // === Case 3: Misconfigured — Both names are set ===
104- if spec .DeploymentName != "" && spec .WorkloadName != "" {
105- // Same names still ambiguous — rely on workloadType
106- if spec .DeploymentName == spec .WorkloadName {
107- if spec .WorkloadType == "" {
108- return "" , errors .New ("both DeploymentName and WorkloadName are set and equal; please remove DeploymentName and set workloadType explicitly" )
109- }
110- return spec .WorkloadType , nil
111- }
112- // Names differ — reject as invalid
113- return "" , errors .New ("DeploymentName and WorkloadName are both set but differ; please use only WorkloadName with WorkloadType" )
110+ // === Case 3: Misconfigured — Both fields exists or both are empty ===
111+ if isDeploymentConfigured && isWorkloadConfigured {
112+ return "" , errors .New ("invalid configuration: use either deploymentName (legacy) OR workloadName with workloadType, not both" )
114113 }
115114
116115 // === Case 4: Fully empty or malformed ===
0 commit comments