Skip to content

Commit 996884a

Browse files
authored
fix: set parent properly on configmaps, naming uniqueness (#45)
1 parent 6a9b558 commit 996884a

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

pkg/signet_node/signet_node.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
func NewSignetNode(ctx *pulumi.Context, args SignetNodeComponentArgs, opts ...pulumi.ResourceOption) (*SignetNodeComponent, error) {
1515
// Apply defaults before validation
1616
args.ApplyDefaults()
17-
17+
1818
if err := args.Validate(); err != nil {
1919
return nil, fmt.Errorf("invalid signet node component args: %w", err)
2020
}
@@ -54,7 +54,7 @@ func NewSignetNode(ctx *pulumi.Context, args SignetNodeComponentArgs, opts ...pu
5454
return nil, fmt.Errorf("failed to create rollup data pvc: %w", err)
5555
}
5656

57-
secretName := "execution-jwt"
57+
secretName := fmt.Sprintf("%s-execution-jwt", args.Name)
5858
secret, err := corev1.NewSecret(ctx, secretName, &corev1.SecretArgs{
5959
StringData: pulumi.StringMap{
6060
"jwt.hex": internalArgs.ExecutionJwt,
@@ -63,19 +63,20 @@ func NewSignetNode(ctx *pulumi.Context, args SignetNodeComponentArgs, opts ...pu
6363
Namespace: internalArgs.Namespace,
6464
Labels: utils.CreateResourceLabels(args.Name, secretName, args.Name, nil),
6565
},
66-
})
66+
}, pulumi.Parent(component))
6767
if err != nil {
6868
return nil, fmt.Errorf("failed to create execution jwt secret: %w", err)
6969
}
7070

7171
// Create ConfigMap for execution environment variables
72-
executionConfigMapName := "exex-configmap"
72+
executionConfigMapName := fmt.Sprintf("%s-exex-configmap", args.Name)
7373
executionConfigMap, err := utils.CreateConfigMap(
7474
ctx,
7575
executionConfigMapName,
7676
internalArgs.Namespace,
7777
utils.CreateResourceLabels(args.Name, executionConfigMapName, args.Name, nil),
7878
internalArgs.Env,
79+
component,
7980
)
8081
if err != nil {
8182
return nil, fmt.Errorf("failed to create execution configmap: %w", err)
@@ -215,7 +216,7 @@ func NewSignetNode(ctx *pulumi.Context, args SignetNodeComponentArgs, opts ...pu
215216
MountPath: internalArgs.RollupDataMountPath,
216217
},
217218
corev1.VolumeMountArgs{
218-
Name: pulumi.String("execution-jwt"),
219+
Name: pulumi.String(secretName),
219220
MountPath: internalArgs.ExecutionJwtMountPath,
220221
},
221222
},
@@ -230,7 +231,7 @@ func NewSignetNode(ctx *pulumi.Context, args SignetNodeComponentArgs, opts ...pu
230231
},
231232
},
232233
corev1.VolumeArgs{
233-
Name: pulumi.String("execution-jwt"),
234+
Name: pulumi.String(secretName),
234235
Secret: &corev1.SecretVolumeSourceArgs{
235236
SecretName: secret.Metadata.Name(),
236237
},
@@ -270,13 +271,14 @@ func NewSignetNode(ctx *pulumi.Context, args SignetNodeComponentArgs, opts ...pu
270271
Example: "example",
271272
}
272273

273-
consensusConfigMapName := "consensus-configmap-env-config"
274+
consensusConfigMapName := fmt.Sprintf("%s-consensus-configmap-env-config", args.Name)
274275
consensusConfigMap, err := utils.CreateConfigMap(
275276
ctx,
276277
consensusConfigMapName,
277278
internalArgs.Namespace,
278279
utils.CreateResourceLabels(args.Name, consensusConfigMapName, args.Name, nil),
279280
consensusEnv.toInternal(),
281+
component,
280282
)
281283
if err != nil {
282284
return nil, fmt.Errorf("failed to create consensus configmap: %w", err)

pkg/utils/env.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,33 @@ 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+
// The optional parent parameter can be provided to set the parent resource for the ConfigMap
2223
func CreateConfigMap[T EnvProvider](
2324
ctx *pulumi.Context,
2425
name string,
2526
namespace pulumi.StringInput,
2627
labels pulumi.StringMap,
2728
env T,
29+
parent ...pulumi.Resource,
2830
) (*corev1.ConfigMap, error) {
29-
// Create metadata for ConfigMap
30-
metadata := &metav1.ObjectMetaArgs{
31-
Name: pulumi.String(name),
32-
Namespace: namespace,
33-
Labels: labels,
34-
}
3531

3632
// Get environment variables as a map using the EnvProvider interface
3733
data := env.GetEnvMap()
3834

35+
// Prepare options with parent if provided
36+
var opts []pulumi.ResourceOption
37+
if len(parent) > 0 && parent[0] != nil {
38+
opts = append(opts, pulumi.Parent(parent[0]))
39+
}
40+
3941
// Create and return ConfigMap
4042
return corev1.NewConfigMap(ctx, name, &corev1.ConfigMapArgs{
41-
Metadata: metadata,
42-
Data: data,
43-
})
43+
Metadata: &metav1.ObjectMetaArgs{
44+
Namespace: namespace,
45+
Labels: labels,
46+
},
47+
Data: data,
48+
}, opts...)
4449
}
4550

4651
// CreateEnvMap converts a struct to a map of environment variables
@@ -212,7 +217,6 @@ func CreatePersistentVolumeClaim(
212217

213218
return corev1.NewPersistentVolumeClaim(ctx, name, &corev1.PersistentVolumeClaimArgs{
214219
Metadata: &metav1.ObjectMetaArgs{
215-
Name: pulumi.String(name),
216220
Labels: labels,
217221
Namespace: namespace,
218222
},

0 commit comments

Comments
 (0)