Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add clusterIP override for headless svc and add ClusterDomain(cluster.local) override #435

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/v1/cosmosfullnode_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ type ServiceSpec struct {
// Overrides for the single RPC service.
// +optional
RPCTemplate ServiceOverridesSpec `json:"rpcTemplate"`

// Overrides for default cluster domain name.
// +optional
ClusterDomain *string `json:"clusterDomain"`
}

// ServiceOverridesSpec allows some overrides for the created, single RPC service.
Expand All @@ -743,6 +747,11 @@ type ServiceOverridesSpec struct {
// +optional
Type *corev1.ServiceType `json:"type"`

// Setting this to "None" makes a "headless service" (no virtual IP), which is useful when direct endpoint connections are preferred and proxying is not required.
// If not set, defaults to "".
// +optional
ClusterIP *string `json:"clusterIP"`

// Sets endpoint and routing behavior.
// See: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#caveats-and-limitations-when-preserving-source-ips
// If not set, defaults to "Cluster".
Expand Down
10 changes: 10 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5674,6 +5674,9 @@ spec:
This allows a k8s admin to use the service in an Ingress, for example.
Additionally, multiple p2p services are created for CometBFT peer exchange.
properties:
clusterDomain:
description: Overrides for default cluster domain name.
type: string
maxP2PExternalAddresses:
description: |-
Max number of external p2p services to create for CometBFT peer exchange.
Expand All @@ -5688,6 +5691,11 @@ spec:
description: Overrides for all P2P services that need external
addresses.
properties:
clusterIP:
description: |-
Setting this to "None" makes a "headless service" (no virtual IP), which is useful when direct endpoint connections are preferred and proxying is not required.
If not set, defaults to "".
type: string
externalTrafficPolicy:
description: |-
Sets endpoint and routing behavior.
Expand Down Expand Up @@ -5729,6 +5737,11 @@ spec:
rpcTemplate:
description: Overrides for the single RPC service.
properties:
clusterIP:
description: |-
Setting this to "None" makes a "headless service" (no virtual IP), which is useful when direct endpoint connections are preferred and proxying is not required.
If not set, defaults to "".
type: string
externalTrafficPolicy:
description: |-
Sets endpoint and routing behavior.
Expand Down
7 changes: 6 additions & 1 deletion internal/fullnode/peer_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ func NewPeerCollector(client Getter) *PeerCollector {
// Collect peer information given the crd.
func (c PeerCollector) Collect(ctx context.Context, crd *cosmosv1.CosmosFullNode) (Peers, kube.ReconcileError) {
peers := make(Peers)

clusterDomain := "cluster.local"
if crd.Spec.Service.ClusterDomain != nil {
clusterDomain = *crd.Spec.Service.ClusterDomain
}
for i := int32(0); i < crd.Spec.Replicas; i++ {
secretName := nodeKeySecretName(crd, i)
var secret corev1.Secret
Expand All @@ -121,7 +126,7 @@ func (c PeerCollector) Collect(ctx context.Context, crd *cosmosv1.CosmosFullNode
svcName := p2pServiceName(crd, i)
peers[c.objectKey(crd, i)] = Peer{
NodeID: nodeKey.ID(),
PrivateAddress: fmt.Sprintf("%s.%s.svc.cluster.local:%d", svcName, secret.Namespace, p2pPort),
PrivateAddress: fmt.Sprintf("%s.%s.svc.%s:%d", svcName, secret.Namespace, clusterDomain, p2pPort),
}
if err := c.addExternalAddress(ctx, peers, crd, i); err != nil {
return nil, kube.TransientError(err)
Expand Down
4 changes: 4 additions & 0 deletions internal/fullnode/service_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func BuildServices(crd *cosmosv1.CosmosFullNode) []diff.Resource[*corev1.Service
svc.Spec.ExternalTrafficPolicy = *valOrDefault(crd.Spec.Service.P2PTemplate.ExternalTrafficPolicy, ptr(corev1.ServiceExternalTrafficPolicyTypeLocal))
} else {
svc.Spec.Type = corev1.ServiceTypeClusterIP
svc.Spec.ClusterIP = *valOrDefault(crd.Spec.Service.P2PTemplate.ClusterIP, ptr(""))
}

p2ps[i] = diff.Adapt(&svc, i)
Expand Down Expand Up @@ -131,6 +132,9 @@ func rpcService(crd *cosmosv1.CosmosFullNode) *corev1.Service {
if v := rpcSpec.Type; v != nil {
svc.Spec.Type = *v
}
if v := rpcSpec.ClusterIP; v != nil {
svc.Spec.ClusterIP = *v
}

return &svc
}
Expand Down
Loading