Skip to content

Commit 146f757

Browse files
committed
fix: add generics for better devex
1 parent af51ea4 commit 146f757

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

pkg/ethereum/execution/types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package execution
22

33
import (
4+
"github.com/init4tech/signet-infra-components/pkg/utils"
45
appsv1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/apps/v1"
56
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1"
67
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
@@ -44,6 +45,8 @@ type ExecutionClientArgs struct {
4445
Bootnodes pulumi.StringArray `pulumi:"bootnodes,optional"`
4546
// AdditionalArgs are additional command line arguments
4647
AdditionalArgs pulumi.StringArray `pulumi:"additionalArgs,optional"`
48+
// Environment variables
49+
ExecutionClientEnv ExecutionClientEnv `pulumi:"executionClientEnv,optional"`
4750
}
4851

4952
// ExecutionClientComponent represents an execution client deployment
@@ -67,3 +70,14 @@ type ExecutionClientComponent struct {
6770
// StatefulSet is the stateful set
6871
StatefulSet *appsv1.StatefulSet
6972
}
73+
74+
// ExecutionClientEnv contains environment variables for the execution client
75+
type ExecutionClientEnv struct {
76+
// Add any environment variables needed by the execution client
77+
RustLog pulumi.StringInput `pulumi:"rustLog"`
78+
}
79+
80+
// GetEnvMap implements the utils.EnvProvider interface
81+
func (e ExecutionClientEnv) GetEnvMap() pulumi.StringMap {
82+
return utils.CreateEnvMap(e)
83+
}

pkg/quincey/quincey.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func createDeployment(ctx *pulumi.Context, args *QuinceyComponentArgs, parent *Q
140140
func createConfigMap(ctx *pulumi.Context, args *QuinceyComponentArgs, parent *QuinceyComponent) (*corev1.ConfigMap, error) {
141141
labels := utils.CreateResourceLabels(ComponentName, ServiceName, DefaultAppSelector, nil)
142142

143-
return utils.CreateConfigMap(ctx, ServiceName, args.Namespace, labels, args.Env)
143+
return utils.CreateConfigMap(ctx, ServiceName, args.Namespace, labels, &args.Env)
144144
}
145145

146146
// createContainer creates the container specification for the Quincey service

pkg/signet_node/signet_node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ func NewSignetNode(ctx *pulumi.Context, args SignetNodeComponentArgs, opts ...pu
292292
}
293293

294294
// Create ConfigMap for consensus environment variables
295-
consensusEnv := map[string]pulumi.StringInput{
296-
"EXAMPLE": pulumi.String("example"),
295+
consensusEnv := ConsensusEnv{
296+
Example: pulumi.String("example"),
297297
}
298298

299299
consensusConfigMapName := "consensus-configmap-env-config"

pkg/signet_node/types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ func (e SignetNodeEnv) GetEnvMap() pulumi.StringMap {
7575
return utils.CreateEnvMap(e)
7676
}
7777

78+
// ConsensusEnv contains environment variables for the consensus client
79+
type ConsensusEnv struct {
80+
Example pulumi.StringInput `pulumi:"example"`
81+
}
82+
83+
// GetEnvMap implements the utils.EnvProvider interface
84+
func (e ConsensusEnv) GetEnvMap() pulumi.StringMap {
85+
return utils.CreateEnvMap(e)
86+
}
87+
7888
// SignetNode interface defines methods that the SignetNodeComponent must implement
7989
type SignetNode interface {
8090
}

pkg/utils/env.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ type EnvProvider interface {
1919

2020
// CreateConfigMap creates a Kubernetes ConfigMap from an environment variables struct
2121
// It automatically converts field names to environment variable format (UPPER_SNAKE_CASE)
22-
func CreateConfigMap(
22+
func CreateConfigMap[T EnvProvider](
2323
ctx *pulumi.Context,
2424
name string,
2525
namespace pulumi.StringInput,
2626
labels pulumi.StringMap,
27-
env interface{},
27+
env T,
2828
) (*corev1.ConfigMap, error) {
2929
// Create metadata for ConfigMap
3030
metadata := &metav1.ObjectMetaArgs{
@@ -33,16 +33,8 @@ func CreateConfigMap(
3333
Labels: labels,
3434
}
3535

36-
// Get environment variables as a map
37-
data := pulumi.StringMap{}
38-
39-
// If the env object implements EnvProvider, use its GetEnvMap method
40-
if provider, ok := env.(EnvProvider); ok {
41-
data = provider.GetEnvMap()
42-
} else {
43-
// Otherwise use reflection to extract fields
44-
data = CreateEnvMap(env)
45-
}
36+
// Get environment variables as a map using the EnvProvider interface
37+
data := env.GetEnvMap()
4638

4739
// Create and return ConfigMap
4840
return corev1.NewConfigMap(ctx, name, &corev1.ConfigMapArgs{
@@ -53,7 +45,7 @@ func CreateConfigMap(
5345

5446
// CreateEnvMap converts a struct to a map of environment variables
5547
// Field names are converted from camelCase to UPPER_SNAKE_CASE
56-
func CreateEnvMap(env interface{}) pulumi.StringMap {
48+
func CreateEnvMap[T any](env T) pulumi.StringMap {
5749
result := pulumi.StringMap{}
5850
t := reflect.TypeOf(env)
5951
v := reflect.ValueOf(env)

0 commit comments

Comments
 (0)