Skip to content

Commit a712847

Browse files
author
eliranb
committed
simplify determineWorkloadType function per PR's feedback
1 parent bb8334d commit a712847

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

api/v1beta/lightrunjavaagent_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ type LightrunJavaAgentStatus struct {
103103
//+kubebuilder:object:root=true
104104
//+kubebuilder:subresource:status
105105
//+kubebuilder:resource:shortName=lrja
106+
//+kubebuilder:printcolumn:priority=0,name=Deployment,type=string,JSONPath=".spec.deploymentName",description="Deployment name",format=""
106107
//+kubebuilder:printcolumn:priority=0,name=Workload,type=string,JSONPath=".spec.workloadName",description="Workload name",format=""
107108
//+kubebuilder:printcolumn:priority=0,name=Type,type=string,JSONPath=".spec.workloadType",description="Workload type",format=""
108109
//+kubebuilder:printcolumn:priority=0,name="Status",type=string,JSONPath=".status.workloadStatus",description="Status of Workload Reconciliation",format=""

internal/controller/lightrunjavaagent_controller.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,31 +86,30 @@ func (r *LightrunJavaAgentReconciler) Reconcile(ctx context.Context, req ctrl.Re
8686

8787
func (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

Comments
 (0)