@@ -3,7 +3,6 @@ package builder
33
44import (
55 "fmt"
6- "strconv"
76
87 "github.com/init4tech/signet-infra-components/pkg/utils"
98 crd "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/apiextensions"
@@ -15,14 +14,7 @@ import (
1514
1615// parseBuilderPort converts a port string to an integer with a default fallback
1716func parseBuilderPort (portStr pulumi.StringInput ) pulumi.IntOutput {
18- return pulumi .All (portStr ).ApplyT (func (inputs []interface {}) int {
19- portStr := inputs [0 ].(string )
20- if port , err := strconv .Atoi (portStr ); err == nil {
21- return port
22- }
23- // Default to 8080 if there's an error parsing the port
24- return 8080
25- }).(pulumi.IntOutput )
17+ return utils .ParsePortWithDefault (portStr , DefaultBuilderPort )
2618}
2719
2820// NewBuilder creates a new builder component with the given configuration.
@@ -34,13 +26,13 @@ func NewBuilder(ctx *pulumi.Context, args BuilderComponentArgs, opts ...pulumi.R
3426 component := & BuilderComponent {
3527 BuilderComponentArgs : args ,
3628 }
37- err := ctx .RegisterComponentResource ("signet:index:Builder" , args .Name , component )
29+ err := ctx .RegisterComponentResource (ComponentKind , args .Name , component )
3830 if err != nil {
3931 return nil , fmt .Errorf ("failed to register component resource: %w" , err )
4032 }
4133
4234 // Create service account
43- serviceAccountName := fmt .Sprintf ("%s-sa " , args .Name )
35+ serviceAccountName := fmt .Sprintf ("%s%s " , args .Name , ServiceAccountSuffix )
4436 sa , err := corev1 .NewServiceAccount (ctx , serviceAccountName , & corev1.ServiceAccountArgs {
4537 Metadata : & metav1.ObjectMetaArgs {
4638 Name : pulumi .String (serviceAccountName ),
@@ -54,7 +46,7 @@ func NewBuilder(ctx *pulumi.Context, args BuilderComponentArgs, opts ...pulumi.R
5446 component .ServiceAccount = sa
5547
5648 // Create ConfigMap for environment variables
57- configMapName := fmt .Sprintf ("%s-env " , args .Name )
49+ configMapName := fmt .Sprintf ("%s%s " , args .Name , ConfigMapSuffix )
5850 configMap , err := utils .CreateConfigMap (
5951 ctx ,
6052 configMapName ,
@@ -72,7 +64,7 @@ func NewBuilder(ctx *pulumi.Context, args BuilderComponentArgs, opts ...pulumi.R
7264 podLabels ["app" ] = pulumi .String (args .Name )
7365
7466 // Create deployment
75- deploymentName := fmt .Sprintf ("%s-deployment " , args .Name )
67+ deploymentName := fmt .Sprintf ("%s%s " , args .Name , DeploymentSuffix )
7668 deployment , err := appsv1 .NewDeployment (ctx , deploymentName , & appsv1.DeploymentArgs {
7769 Metadata : & metav1.ObjectMetaArgs {
7870 Name : pulumi .String (deploymentName ),
@@ -109,33 +101,24 @@ func NewBuilder(ctx *pulumi.Context, args BuilderComponentArgs, opts ...pulumi.R
109101 ContainerPort : pulumi .Int (MetricsPort ),
110102 },
111103 },
112- Resources : & corev1.ResourceRequirementsArgs {
113- Limits : pulumi.StringMap {
114- "cpu" : pulumi .String ("2" ),
115- "memory" : pulumi .String ("2Gi" ),
116- },
117- Requests : pulumi.StringMap {
118- "cpu" : pulumi .String ("1" ),
119- "memory" : pulumi .String ("1Gi" ),
120- },
121- },
104+ Resources : utils .CreateResourceRequirements (DefaultCPULimit , DefaultMemoryLimit , DefaultCPURequest , DefaultMemoryRequest ),
122105 LivenessProbe : & corev1.ProbeArgs {
123106 HttpGet : & corev1.HTTPGetActionArgs {
124- Path : pulumi .String ("/healthcheck" ),
107+ Path : pulumi .String (HealthCheckPath ),
125108 Port : parseBuilderPort (args .BuilderEnv .BuilderPort ),
126109 },
127- InitialDelaySeconds : pulumi .Int (5 ),
128- PeriodSeconds : pulumi .Int (1 ),
129- TimeoutSeconds : pulumi .Int (1 ),
130- FailureThreshold : pulumi .Int (3 ),
110+ InitialDelaySeconds : pulumi .Int (ProbeInitialDelaySeconds ),
111+ PeriodSeconds : pulumi .Int (LivenessProbePeriod ),
112+ TimeoutSeconds : pulumi .Int (ProbeTimeoutSeconds ),
113+ FailureThreshold : pulumi .Int (ProbeFailureThreshold ),
131114 },
132115 ReadinessProbe : & corev1.ProbeArgs {
133116 HttpGet : & corev1.HTTPGetActionArgs {
134- Path : pulumi .String ("/healthcheck" ),
117+ Path : pulumi .String (HealthCheckPath ),
135118 Port : parseBuilderPort (args .BuilderEnv .BuilderPort ),
136119 },
137- InitialDelaySeconds : pulumi .Int (5 ),
138- PeriodSeconds : pulumi .Int (10 ),
120+ InitialDelaySeconds : pulumi .Int (ProbeInitialDelaySeconds ),
121+ PeriodSeconds : pulumi .Int (ProbePeriodSeconds ),
139122 },
140123 },
141124 },
@@ -149,16 +132,16 @@ func NewBuilder(ctx *pulumi.Context, args BuilderComponentArgs, opts ...pulumi.R
149132 component .Deployment = deployment
150133
151134 // Create service
152- serviceName := fmt .Sprintf ("%s-service " , args .Name )
135+ serviceName := fmt .Sprintf ("%s%s " , args .Name , ServiceSuffix )
153136 service , err := corev1 .NewService (ctx , serviceName , & corev1.ServiceArgs {
154137 Metadata : & metav1.ObjectMetaArgs {
155138 Name : pulumi .String (serviceName ),
156139 Namespace : pulumi .String (args .Namespace ),
157140 Labels : utils .CreateResourceLabels (args .Name , serviceName , args .Name , nil ),
158141 Annotations : pulumi.StringMap {
159- "prometheus.io/scrape" : pulumi .String ("true" ),
160- "prometheus.io/port" : pulumi .Sprintf ("%d" , MetricsPort ),
161- "prometheus.io/path" : pulumi .String ("/metrics" ),
142+ PrometheusScrapeAnnotation : pulumi .String ("true" ),
143+ PrometheusPortAnnotation : pulumi .Sprintf ("%d" , MetricsPort ),
144+ PrometheusPathAnnotation : pulumi .String (MetricsPath ),
162145 },
163146 },
164147 Spec : & corev1.ServiceSpecArgs {
@@ -183,8 +166,8 @@ func NewBuilder(ctx *pulumi.Context, args BuilderComponentArgs, opts ...pulumi.R
183166 component .Service = service
184167
185168 // Create pod monitor
186- podMonitorName := fmt .Sprintf ("%s-pod-monitor " , args .Name )
187- _ , err = crd .NewCustomResource (ctx , fmt .Sprintf ("%s-svcmon " , args .Name ), & crd.CustomResourceArgs {
169+ podMonitorName := fmt .Sprintf ("%s%s " , args .Name , PodMonitorSuffix )
170+ _ , err = crd .NewCustomResource (ctx , fmt .Sprintf ("%s%s " , args .Name , ServiceMonitorSuffix ), & crd.CustomResourceArgs {
188171 ApiVersion : pulumi .String ("monitoring.coreos.com/v1" ),
189172 Kind : pulumi .String ("PodMonitor" ),
190173 Metadata : & metav1.ObjectMetaArgs {
0 commit comments