@@ -85,35 +85,33 @@ func (r *LightrunJavaAgentReconciler) Reconcile(ctx context.Context, req ctrl.Re
85
85
}
86
86
87
87
func (r * LightrunJavaAgentReconciler ) determineWorkloadType (lightrunJavaAgent * agentv1beta.LightrunJavaAgent ) (agentv1beta.WorkloadType , error ) {
88
+ // Get the spec from the LightrunJavaAgent resource
88
89
spec := lightrunJavaAgent .Spec
89
- // Check which configuration approach is being used
90
+
91
+ // Check if legacy deploymentName field is configured
90
92
var isDeploymentConfigured bool = spec .DeploymentName != ""
91
- var isWorkloadConfigured bool = spec .WorkloadName != "" || spec .WorkloadType != ""
93
+ // Check if new workload configuration fields are set
94
+ var isWorkloadConfigured bool = spec .WorkloadName != "" && spec .WorkloadType != ""
92
95
93
- // === Case 1: Legacy only — DeploymentName only ===
94
- if isDeploymentConfigured && ! isWorkloadConfigured {
95
- r .Log .Info ("Using deprecated field deploymentName, consider migrating to workloadName and workloadType" )
96
- return agentv1beta .WorkloadTypeDeployment , nil
96
+ // Error if both legacy and new configuration methods are used
97
+ if isDeploymentConfigured && isWorkloadConfigured {
98
+ return "" , errors .New ("invalid configuration: use either deploymentName (legacy) OR workloadName with workloadType, not both" )
97
99
}
98
100
99
- // === Case 2: New fields — WorkloadName + WorkloadType ===
100
- if ! isDeploymentConfigured && isWorkloadConfigured {
101
- if spec .WorkloadType == "" {
102
- return "" , errors .New ("workloadType must be set when using workloadName" )
103
- }
104
- if spec .WorkloadName == "" {
105
- return "" , errors .New ("workloadName must be set when workloadType is specified" )
106
- }
107
- return spec .WorkloadType , nil
101
+ // Error if neither configuration method is used
102
+ if ! isDeploymentConfigured && ! isWorkloadConfigured {
103
+ return "" , errors .New ("invalid configuration: must set either DeploymentName (legacy) or WorkloadName with WorkloadType" )
108
104
}
109
105
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" )
106
+ switch {
107
+ case isDeploymentConfigured :
108
+ r .Log .Info ("Using deprecated field deploymentName, consider migrating to workloadName and workloadType" )
109
+ return agentv1beta .WorkloadTypeDeployment , nil
110
+ case isWorkloadConfigured :
111
+ return spec .WorkloadType , nil
112
+ default :
113
+ return "" , errors .New ("unable to determine workload type, please check your configuration" )
113
114
}
114
-
115
- // === Case 4: Fully empty or malformed ===
116
- return "" , errors .New ("invalid configuration: must set either DeploymentName (legacy) or WorkloadName with WorkloadType" )
117
115
}
118
116
119
117
// reconcileDeployment handles the reconciliation logic for Deployment workloads
0 commit comments