Skip to content

Commit a8675ba

Browse files
committed
refactor(controller): standardize environment variable names
Updated deployment and service specifications to use consistent environment variable names across various controllers. This change improves code readability and maintainability by using defined constants for service names, health paths, and mount paths.
1 parent 4e4537b commit a8675ba

56 files changed

Lines changed: 254 additions & 219 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/controller/alert_system_deployment.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ func (r *AlertSystemReconciler) updateDeployment(dep *appsv1.Deployment, alert *
5050

5151
func defaultAlertSystemDeploymentSpec() *appsv1.DeploymentSpec {
5252
labels := map[string]string{
53-
"app": "alert",
53+
AppLabel: "alert",
5454
"deployment": "alert",
5555
"project": "service",
5656
}
5757
envFrom := []corev1.EnvFromSource{}
5858
env := []corev1.EnvVar{
5959
{
60-
Name: "SERVICE_NAME",
60+
Name: ServiceNameEnvVar,
6161
Value: "alert-service",
6262
},
6363
}
@@ -92,7 +92,7 @@ func defaultAlertSystemDeploymentSpec() *appsv1.DeploymentSpec {
9292
ReadinessProbe: &corev1.Probe{
9393
ProbeHandler: corev1.ProbeHandler{
9494
HTTPGet: &corev1.HTTPGetAction{
95-
Path: "/health/readiness",
95+
Path: HealthReadinessPath,
9696
Port: intstr.FromInt32(HealthPort),
9797
},
9898
},
@@ -104,7 +104,7 @@ func defaultAlertSystemDeploymentSpec() *appsv1.DeploymentSpec {
104104
LivenessProbe: &corev1.Probe{
105105
ProbeHandler: corev1.ProbeHandler{
106106
HTTPGet: &corev1.HTTPGetAction{
107-
Path: "/health/liveness",
107+
Path: HealthLivenessPath,
108108
Port: intstr.FromInt32(HealthPort),
109109
},
110110
},
@@ -116,7 +116,7 @@ func defaultAlertSystemDeploymentSpec() *appsv1.DeploymentSpec {
116116
StartupProbe: &corev1.Probe{
117117
ProbeHandler: corev1.ProbeHandler{
118118
HTTPGet: &corev1.HTTPGetAction{
119-
Path: "/health/readiness",
119+
Path: HealthReadinessPath,
120120
Port: intstr.FromInt32(HealthPort),
121121
},
122122
},

internal/controller/alert_system_service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (r *AlertSystemReconciler) updateService(svc *corev1.Service, alert *terano
4444

4545
func defaultAlertSystemServiceSpec() *corev1.ServiceSpec {
4646
labels := map[string]string{
47-
"app": "alert",
47+
AppLabel: "alert",
4848
}
4949
return &corev1.ServiceSpec{
5050
Selector: labels,
@@ -56,7 +56,7 @@ func defaultAlertSystemServiceSpec() *corev1.ServiceSpec {
5656
Protocol: corev1.ProtocolTCP,
5757
},
5858
{
59-
Name: "health",
59+
Name: HealthPortName,
6060
Port: int32(HealthPort),
6161
TargetPort: intstr.FromInt32(HealthPort),
6262
Protocol: corev1.ProtocolTCP,
@@ -68,7 +68,7 @@ func defaultAlertSystemServiceSpec() *corev1.ServiceSpec {
6868
Protocol: corev1.ProtocolTCP,
6969
},
7070
{
71-
Name: "profiler",
71+
Name: ProfilerPortName,
7272
Port: int32(ProfilerPort),
7373
TargetPort: intstr.FromInt32(ProfilerPort),
7474
Protocol: corev1.ProtocolTCP,

internal/controller/alertsystem_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var _ = Describe("AlertSystem Controller", func() {
3737

3838
typeNamespacedName := types.NamespacedName{
3939
Name: resourceName,
40-
Namespace: "default", // TODO(user):Modify as needed
40+
Namespace: defaultNamespace, // TODO(user):Modify as needed
4141
}
4242
alertsystem := &teranodev1alpha1.AlertSystem{}
4343

@@ -48,7 +48,7 @@ var _ = Describe("AlertSystem Controller", func() {
4848
resource := &teranodev1alpha1.AlertSystem{
4949
ObjectMeta: metav1.ObjectMeta{
5050
Name: resourceName,
51-
Namespace: "default",
51+
Namespace: defaultNamespace,
5252
},
5353
// TODO(user): Specify other spec details if needed.
5454
}

internal/controller/asset_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var _ = Describe("Asset Controller", func() {
3737

3838
typeNamespacedName := types.NamespacedName{
3939
Name: resourceName,
40-
Namespace: "default", // TODO(user):Modify as needed
40+
Namespace: defaultNamespace, // TODO(user):Modify as needed
4141
}
4242
asset := &teranodev1alpha1.Asset{}
4343

@@ -48,7 +48,7 @@ var _ = Describe("Asset Controller", func() {
4848
resource := &teranodev1alpha1.Asset{
4949
ObjectMeta: metav1.ObjectMeta{
5050
Name: resourceName,
51-
Namespace: "default",
51+
Namespace: defaultNamespace,
5252
},
5353
// TODO(user): Specify other spec details if needed.
5454
}

internal/controller/asset_deployment.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func defaultAssetDeploymentSpec() *appsv1.DeploymentSpec {
5454
envFrom := []corev1.EnvFromSource{}
5555
env := []corev1.EnvVar{
5656
{
57-
Name: "SERVICE_NAME",
57+
Name: ServiceNameEnvVar,
5858
Value: "asset-service",
5959
},
6060
}
@@ -92,7 +92,7 @@ func defaultAssetDeploymentSpec() *appsv1.DeploymentSpec {
9292
ReadinessProbe: &corev1.Probe{
9393
ProbeHandler: corev1.ProbeHandler{
9494
HTTPGet: &corev1.HTTPGetAction{
95-
Path: "/health/readiness",
95+
Path: HealthReadinessPath,
9696
Port: intstr.FromInt32(HealthPort),
9797
},
9898
},
@@ -104,7 +104,7 @@ func defaultAssetDeploymentSpec() *appsv1.DeploymentSpec {
104104
LivenessProbe: &corev1.Probe{
105105
ProbeHandler: corev1.ProbeHandler{
106106
HTTPGet: &corev1.HTTPGetAction{
107-
Path: "/health/liveness",
107+
Path: HealthLivenessPath,
108108
Port: intstr.FromInt32(HealthPort),
109109
},
110110
},
@@ -116,7 +116,7 @@ func defaultAssetDeploymentSpec() *appsv1.DeploymentSpec {
116116
StartupProbe: &corev1.Probe{
117117
ProbeHandler: corev1.ProbeHandler{
118118
HTTPGet: &corev1.HTTPGetAction{
119-
Path: "/health/readiness",
119+
Path: HealthReadinessPath,
120120
Port: intstr.FromInt32(HealthPort),
121121
},
122122
},
@@ -147,7 +147,7 @@ func defaultAssetDeploymentSpec() *appsv1.DeploymentSpec {
147147
},
148148
VolumeMounts: []corev1.VolumeMount{
149149
{
150-
MountPath: "/data",
150+
MountPath: DataMountPath,
151151
Name: SharedPVCName,
152152
},
153153
},

internal/controller/asset_service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (r *AssetReconciler) updateService(svc *corev1.Service, asset *teranodev1al
4444

4545
func defaultAssetServiceSpec() *corev1.ServiceSpec {
4646
labels := map[string]string{
47-
"app": "asset",
47+
AppLabel: "asset",
4848
}
4949
return &corev1.ServiceSpec{
5050
Selector: labels,
@@ -56,13 +56,13 @@ func defaultAssetServiceSpec() *corev1.ServiceSpec {
5656
Protocol: corev1.ProtocolTCP,
5757
},
5858
{
59-
Name: "health",
59+
Name: HealthPortName,
6060
Port: int32(HealthPort),
6161
TargetPort: intstr.FromInt32(HealthPort),
6262
Protocol: corev1.ProtocolTCP,
6363
},
6464
{
65-
Name: "profiler",
65+
Name: ProfilerPortName,
6666
Port: int32(ProfilerPort),
6767
TargetPort: intstr.FromInt32(ProfilerPort),
6868
Protocol: corev1.ProtocolTCP,

internal/controller/blockassembly_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var _ = Describe("BlockAssembly Controller", func() {
3737

3838
typeNamespacedName := types.NamespacedName{
3939
Name: resourceName,
40-
Namespace: "default", // TODO(user):Modify as needed
40+
Namespace: defaultNamespace, // TODO(user):Modify as needed
4141
}
4242
blockassembly := &teranodev1alpha1.BlockAssembly{}
4343

@@ -48,7 +48,7 @@ var _ = Describe("BlockAssembly Controller", func() {
4848
resource := &teranodev1alpha1.BlockAssembly{
4949
ObjectMeta: metav1.ObjectMeta{
5050
Name: resourceName,
51-
Namespace: "default",
51+
Namespace: defaultNamespace,
5252
},
5353
// TODO(user): Specify other spec details if needed.
5454
}

internal/controller/blockassembly_deployment.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func defaultBlockAssemblyDeploymentSpec() *appsv1.DeploymentSpec {
5353
envFrom := []corev1.EnvFromSource{}
5454
env := []corev1.EnvVar{
5555
{
56-
Name: "SERVICE_NAME",
56+
Name: ServiceNameEnvVar,
5757
Value: "blockassembly-service",
5858
},
5959
{
@@ -95,7 +95,7 @@ func defaultBlockAssemblyDeploymentSpec() *appsv1.DeploymentSpec {
9595
ReadinessProbe: &corev1.Probe{
9696
ProbeHandler: corev1.ProbeHandler{
9797
HTTPGet: &corev1.HTTPGetAction{
98-
Path: "/health/readiness",
98+
Path: HealthReadinessPath,
9999
Port: intstr.FromInt32(HealthPort),
100100
},
101101
},
@@ -107,7 +107,7 @@ func defaultBlockAssemblyDeploymentSpec() *appsv1.DeploymentSpec {
107107
LivenessProbe: &corev1.Probe{
108108
ProbeHandler: corev1.ProbeHandler{
109109
HTTPGet: &corev1.HTTPGetAction{
110-
Path: "/health/liveness",
110+
Path: HealthLivenessPath,
111111
Port: intstr.FromInt32(HealthPort),
112112
},
113113
},
@@ -119,7 +119,7 @@ func defaultBlockAssemblyDeploymentSpec() *appsv1.DeploymentSpec {
119119
StartupProbe: &corev1.Probe{
120120
ProbeHandler: corev1.ProbeHandler{
121121
HTTPGet: &corev1.HTTPGetAction{
122-
Path: "/health/readiness",
122+
Path: HealthReadinessPath,
123123
Port: intstr.FromInt32(HealthPort),
124124
},
125125
},

internal/controller/blockassembly_service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (r *BlockAssemblyReconciler) updateService(svc *corev1.Service, blockassemb
4444

4545
func defaultBlockAssemblyServiceSpec() *corev1.ServiceSpec {
4646
labels := map[string]string{
47-
"app": "block-assembly",
47+
AppLabel: "block-assembly",
4848
}
4949
return &corev1.ServiceSpec{
5050
Selector: labels,
@@ -56,13 +56,13 @@ func defaultBlockAssemblyServiceSpec() *corev1.ServiceSpec {
5656
Protocol: corev1.ProtocolTCP,
5757
},
5858
{
59-
Name: "health",
59+
Name: HealthPortName,
6060
Port: int32(HealthPort),
6161
TargetPort: intstr.FromInt32(HealthPort),
6262
Protocol: corev1.ProtocolTCP,
6363
},
6464
{
65-
Name: "profiler",
65+
Name: ProfilerPortName,
6666
Port: int32(ProfilerPort),
6767
TargetPort: intstr.FromInt32(ProfilerPort),
6868
Protocol: corev1.ProtocolTCP,

internal/controller/blockchain_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (r *BlockchainReconciler) Reconcile(ctx context.Context, req ctrl.Request)
110110
func getAppLabels(service string) map[string]string {
111111
return map[string]string{
112112
teranodev1alpha1.TeranodeLabel: "true",
113-
"app": service,
113+
AppLabel: service,
114114
}
115115
}
116116

0 commit comments

Comments
 (0)