@@ -30,8 +30,14 @@ func BuildServices(crd *cosmosv1.CosmosFullNode) []diff.Resource[*corev1.Service
30
30
max = * v
31
31
}
32
32
maxExternal := lo .Clamp (max , 0 , crd .Spec .Replicas )
33
- p2ps := make ([]diff.Resource [* corev1.Service ], crd .Spec .Replicas )
34
- for i := int32 (0 ); i < crd .Spec .Replicas ; i ++ {
33
+ svcs := make ([]diff.Resource [* corev1.Service ], func (nodeType cosmosv1.FullNodeType ) int32 {
34
+ if nodeType == cosmosv1 .Sentry {
35
+ return crd .Spec .Replicas * 2
36
+ }
37
+ return crd .Spec .Replicas
38
+ }(crd .Spec .Type ))
39
+ startOrdinal := crd .Spec .Ordinals .Start
40
+ for i := startOrdinal ; i < startOrdinal + crd .Spec .Replicas ; i ++ {
35
41
ordinal := crd .Spec .Ordinals .Start + i
36
42
var svc corev1.Service
37
43
svc .Name = p2pServiceName (crd , ordinal )
@@ -61,10 +67,48 @@ func BuildServices(crd *cosmosv1.CosmosFullNode) []diff.Resource[*corev1.Service
61
67
svc .Spec .Type = corev1 .ServiceTypeClusterIP
62
68
svc .Spec .ClusterIP = * valOrDefault (crd .Spec .Service .P2PTemplate .ClusterIP , ptr ("" ))
63
69
}
64
- p2ps [i ] = diff .Adapt (& svc , int (i ))
70
+ svcs [i ] = diff .Adapt (& svc , int (i ))
65
71
}
66
72
rpc := rpcService (crd )
67
- return append (p2ps , diff .Adapt (rpc , len (p2ps )))
73
+ if crd .Spec .Type == cosmosv1 .Sentry {
74
+ for i := int32 (0 ); i < crd .Spec .Replicas ; i ++ {
75
+ ordinal := i
76
+ var svc corev1.Service
77
+ svc .Name = sentryServiceName (crd , ordinal )
78
+ svc .Namespace = crd .Namespace
79
+ svc .Kind = "Service"
80
+ svc .APIVersion = "v1"
81
+
82
+ svc .Labels = defaultLabels (crd ,
83
+ kube .InstanceLabel , instanceName (crd , ordinal ),
84
+ kube .ComponentLabel , "cosmos-sentry" ,
85
+ )
86
+ svc .Annotations = map [string ]string {}
87
+
88
+ svc .Spec .Ports = []corev1.ServicePort {
89
+ {
90
+ // https://github.com/strangelove-ventures/horcrux-proxy/blob/23a7d31806ce62481162a64adcca848fd879bc52/cmd/watcher.go#L162
91
+ Name : "sentry-privval" ,
92
+ Protocol : corev1 .ProtocolTCP ,
93
+ Port : privvalPort ,
94
+ TargetPort : intstr .FromString ("privval" ),
95
+ },
96
+ }
97
+ svc .Spec .Selector = map [string ]string {kube .InstanceLabel : instanceName (crd , ordinal )}
98
+
99
+ preserveMergeInto (svc .Labels , crd .Spec .Service .P2PTemplate .Metadata .Labels )
100
+ preserveMergeInto (svc .Annotations , crd .Spec .Service .P2PTemplate .Metadata .Annotations )
101
+ svc .Spec .Type = corev1 .ServiceTypeClusterIP
102
+
103
+ // If you run pod as sentry mode, it'll be unhealthy cause of no API from app.
104
+ // But to run cosmos app, horcrux-proxy should connect to pod even pod's status is unhealthy.
105
+ // therefore, you should allow this option.
106
+ svc .Spec .PublishNotReadyAddresses = true
107
+
108
+ svcs [i ] = diff .Adapt (& svc , i )
109
+ }
110
+ }
111
+ return append (svcs , diff .Adapt (rpc , len (svcs )))
68
112
}
69
113
70
114
func rpcService (crd * cosmosv1.CosmosFullNode ) * corev1.Service {
@@ -131,6 +175,10 @@ func p2pServiceName(crd *cosmosv1.CosmosFullNode, ordinal int32) string {
131
175
return fmt .Sprintf ("%s-p2p-%d" , appName (crd ), ordinal )
132
176
}
133
177
178
+ func sentryServiceName (crd * cosmosv1.CosmosFullNode , ordinal int32 ) string {
179
+ return fmt .Sprintf ("%s-privval-%d" , appName (crd ), ordinal )
180
+ }
181
+
134
182
func rpcServiceName (crd * cosmosv1.CosmosFullNode ) string {
135
183
return fmt .Sprintf ("%s-rpc" , appName (crd ))
136
184
}
0 commit comments