-
Notifications
You must be signed in to change notification settings - Fork 0
DEVOPS-2689-extend-k-8-s-operator-support-to-include-stateful-sets #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
65d209c
e9b798a
f343dcc
9bff8c2
f000a8e
4f3ebf2
0ee5505
2cf6070
585ac87
dc55550
de2ba95
1d5c1f2
191419b
9115f02
124b19f
21978cb
a104886
4a18f67
b8d4a04
2df1dbc
56e5f55
05c6fb9
44ed3c3
924923b
8c1ad6e
bb8334d
a712847
5e1b54d
b948101
52c042c
d462f06
1af59a3
33831b3
22505e3
2a68b3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,11 +97,13 @@ type LightrunJavaAgentStatus struct { | |
| LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"` | ||
| Conditions []metav1.Condition `json:"conditions,omitempty"` | ||
| WorkloadStatus string `json:"workloadStatus,omitempty"` | ||
| DeploymentStatus string `json:"deploymentStatus,omitempty"` | ||
| } | ||
|
|
||
| //+kubebuilder:object:root=true | ||
| //+kubebuilder:subresource:status | ||
| //+kubebuilder:resource:shortName=lrja | ||
| //+kubebuilder:printcolumn:priority=0,name=Deployment,type=string,JSONPath=".spec.deploymentName",description="Deployment name",format="" | ||
|
||
| //+kubebuilder:printcolumn:priority=0,name=Workload,type=string,JSONPath=".spec.workloadName",description="Workload name",format="" | ||
| //+kubebuilder:printcolumn:priority=0,name=Type,type=string,JSONPath=".spec.workloadType",description="Workload type",format="" | ||
| //+kubebuilder:printcolumn:priority=0,name="Status",type=string,JSONPath=".status.workloadStatus",description="Status of Workload Reconciliation",format="" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,10 @@ spec: | |
| scope: Namespaced | ||
| versions: | ||
| - additionalPrinterColumns: | ||
| - description: Deployment name | ||
|
||
| jsonPath: .spec.deploymentName | ||
| name: Deployment | ||
| type: string | ||
| - description: Workload name | ||
| jsonPath: .spec.workloadName | ||
| name: Workload | ||
|
|
@@ -211,6 +215,8 @@ spec: | |
| - type | ||
| type: object | ||
| type: array | ||
| deploymentStatus: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is generated by kubebuilder according to type LightrunJavaAgentStatus struct {
LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
WorkloadStatus string `json:"workloadStatus,omitempty"`
DeploymentStatus string `json:"deploymentStatus,omitempty"`
}we need to keep DeploymentStatus so we will be able to update Status field accordingly |
||
| type: string | ||
| lastScheduleTime: | ||
| format: date-time | ||
| type: string | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,31 +86,30 @@ func (r *LightrunJavaAgentReconciler) Reconcile(ctx context.Context, req ctrl.Re | |
|
|
||
| func (r *LightrunJavaAgentReconciler) determineWorkloadType(lightrunJavaAgent *agentv1beta.LightrunJavaAgent) (agentv1beta.WorkloadType, error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, we should support 2 configurations:
if deploymentName is set you should log a warning that it's deprecated in favor of workloadName and workloadType. If we agree you can add: if both are true/false you return an error. |
||
| spec := lightrunJavaAgent.Spec | ||
| // Check which configuration approach is being used | ||
| var isDeploymentConfigured bool = spec.DeploymentName != "" | ||
| var isWorkloadConfigured bool = spec.WorkloadName != "" || spec.WorkloadType != "" | ||
|
||
|
|
||
moshiko-s marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // === Case 1: Legacy only — DeploymentName only === | ||
| if spec.DeploymentName != "" && spec.WorkloadName == "" && spec.WorkloadType == "" { | ||
| if isDeploymentConfigured && !isWorkloadConfigured { | ||
|
||
| r.Log.Info("Using deprecated field deploymentName, consider migrating to workloadName and workloadType") | ||
moshiko-s marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return agentv1beta.WorkloadTypeDeployment, nil | ||
| } | ||
|
|
||
| // === Case 2: New fields — WorkloadName + WorkloadType === | ||
| if spec.DeploymentName == "" && spec.WorkloadName != "" { | ||
| if !isDeploymentConfigured && isWorkloadConfigured { | ||
|
||
| if spec.WorkloadType == "" { | ||
| return "", errors.New("WorkloadType must be set when using WorkloadName") | ||
| return "", errors.New("workloadType must be set when using workloadName") | ||
| } | ||
| if spec.WorkloadName == "" { | ||
| return "", errors.New("workloadName must be set when workloadType is specified") | ||
| } | ||
| return spec.WorkloadType, nil | ||
| } | ||
|
|
||
| // === Case 3: Misconfigured — Both names are set === | ||
| if spec.DeploymentName != "" && spec.WorkloadName != "" { | ||
| // Same names still ambiguous — rely on workloadType | ||
| if spec.DeploymentName == spec.WorkloadName { | ||
| if spec.WorkloadType == "" { | ||
| return "", errors.New("both DeploymentName and WorkloadName are set and equal; please remove DeploymentName and set workloadType explicitly") | ||
| } | ||
| return spec.WorkloadType, nil | ||
| } | ||
| // Names differ — reject as invalid | ||
| return "", errors.New("DeploymentName and WorkloadName are both set but differ; please use only WorkloadName with WorkloadType") | ||
| // === Case 3: Misconfigured — Both fields exists or both are empty === | ||
| if isDeploymentConfigured && isWorkloadConfigured { | ||
moshiko-s marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return "", errors.New("invalid configuration: use either deploymentName (legacy) OR workloadName with workloadType, not both") | ||
| } | ||
|
|
||
| // === Case 4: Fully empty or malformed === | ||
|
|
@@ -126,7 +125,9 @@ func (r *LightrunJavaAgentReconciler) reconcileDeployment(ctx context.Context, l | |
| // Fall back to legacy field if WorkloadName isn't set | ||
| deploymentName = lightrunJavaAgent.Spec.DeploymentName | ||
| } | ||
|
|
||
| if deploymentName == "" { | ||
| return r.errorStatus(ctx, lightrunJavaAgent, errors.New("unable to reconcile deployment: missing workloadName or deploymentName(legacy and deprecated)")) | ||
| } | ||
| log := r.Log.WithValues("lightrunJavaAgent", lightrunJavaAgent.Name, "deployment", deploymentName) | ||
| fieldManager := "lightrun-conrtoller" | ||
|
|
||
|
|
@@ -357,7 +358,10 @@ func (r *LightrunJavaAgentReconciler) reconcileDeployment(ctx context.Context, l | |
| func (r *LightrunJavaAgentReconciler) reconcileStatefulSet(ctx context.Context, lightrunJavaAgent *agentv1beta.LightrunJavaAgent, namespace string) (ctrl.Result, error) { | ||
| log := r.Log.WithValues("lightrunJavaAgent", lightrunJavaAgent.Name, "statefulSet", lightrunJavaAgent.Spec.WorkloadName) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add a check if workloadName is empty |
||
| fieldManager := "lightrun-controller" | ||
|
|
||
| statefulSetName := lightrunJavaAgent.Spec.WorkloadName | ||
| if statefulSetName == "" { | ||
| return r.errorStatus(ctx, lightrunJavaAgent, errors.New("unable to reconcile statefulset: missing workloadName field")) | ||
| } | ||
| stsNamespacedObj := client.ObjectKey{ | ||
| Name: lightrunJavaAgent.Spec.WorkloadName, | ||
| Namespace: namespace, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.