Skip to content

Commit 0f6f2c6

Browse files
committed
review fixes
1 parent 1c6d9a1 commit 0f6f2c6

File tree

6 files changed

+50
-12
lines changed

6 files changed

+50
-12
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
- [Configuration](./framework/developer_environment/toml.md)
77
- [Basic Usage](./framework/getting_started.md)
88
- [Getting Started](./framework/getting_started.md)
9-
- [Running in Kubernetes](./framework/kubernetes.md)
109
- [Advanced Usage](./framework/configuration.md)
1110
- [CLI](./framework/cli.md)
1211
- [Configuration](./framework/configuration.md)
@@ -26,6 +25,7 @@
2625
- [Fake Services](framework/components/mocking.md)
2726
- [Detecting Resource Leaks](framework/resource_leaks.md)
2827
- [Copying Files](framework/copying_files.md)
28+
- [Running in Kubernetes](./framework/kubernetes.md)
2929
- [External Environment](framework/components/external.md)
3030
- [Observability Stack](framework/observability/observability_stack.md)
3131
- [Overview](framework/observability/observability_stack.md)

book/src/framework/kubernetes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ Set up Kubernetes context for `main.stage` and add namespace variable to run `de
44
```bash
55
kubectl config use-context staging-eks-admin
66
export KUBERNETES_NAMESPACE="devenv-1"
7+
```
8+
9+
Each Pod always has a service, you can found programmatic connection data in `.out`.
10+
11+
To forward all the services locally use [kubefwd]()
12+
```bash
13+
sudo -E kubefwd svc -n $KUBERNETES_NAMESPACE
714
```

framework/components/clnode/clnode.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,18 @@ func generateEntryPoint() []string {
181181
return entrypoint
182182
}
183183

184+
// natPortsToK8sFormat transforms nat.PortMap
185+
// to Pods port pair format: $external_port:$internal_port
186+
func natPortsToK8sFormat(nat nat.PortMap) []string {
187+
out := make([]string, 0)
188+
for port, portBinding := range nat {
189+
for _, b := range portBinding {
190+
out = append(out, fmt.Sprintf("%s:%s", b.HostPort, strconv.Itoa(port.Int())))
191+
}
192+
}
193+
return out
194+
}
195+
184196
// generatePortBindings generates exposed ports and port bindings
185197
// exposes default CL node port
186198
// exposes custom_ports in format "host:docker" or map 1-to-1 if only "host" port is provided
@@ -302,10 +314,7 @@ func newNode(ctx context.Context, in *Input, pgOut *postgres.Output) (*NodeOut,
302314
Env: pods.EnvsFromMap(in.Node.EnvVars),
303315
Requests: pods.ResourcesMedium(),
304316
Limits: pods.ResourcesMedium(),
305-
Ports: []string{
306-
fmt.Sprintf("%d:%s", in.Node.HTTPPort, DefaultHTTPPort),
307-
fmt.Sprintf("%d:%s", in.Node.P2PPort, DefaultP2PPort),
308-
},
317+
Ports: natPortsToK8sFormat(portBindings),
309318
ContainerSecurityContext: &v1.SecurityContext{
310319
// these are specific things we need for staging cluster
311320
RunAsNonRoot: pods.Ptr(true),

framework/components/postgres/postgres.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,21 @@ func NewWithContext(ctx context.Context, in *Input) (*Output, error) {
136136
Env: []v1.EnvVar{
137137
{
138138
Name: "POSTGRES_USER",
139-
Value: "chainlink",
139+
Value: User,
140140
},
141141
{
142142
Name: "POSTGRES_PASSWORD",
143-
Value: "thispasswordislongenough",
143+
Value: Password,
144144
},
145145
{
146146
Name: "POSTGRES_DB",
147-
Value: "chainlink",
147+
Value: Database,
148148
},
149149
},
150150
Requests: pods.ResourcesLarge(),
151151
Limits: pods.ResourcesLarge(),
152+
// container and pod security settings are specific to
153+
// 'postgres' Docker image
152154
ContainerSecurityContext: &v1.SecurityContext{
153155
RunAsUser: pods.Ptr[int64](999),
154156
RunAsGroup: pods.Ptr[int64](999),
@@ -189,6 +191,24 @@ func NewWithContext(ctx context.Context, in *Input) (*Output, error) {
189191
Database,
190192
),
191193
}
194+
if in.JDDatabase {
195+
o.JDInternalURL = fmt.Sprintf(
196+
"postgresql://%s:%s@%s:%s/%s?sslmode=disable",
197+
User,
198+
Password,
199+
fmt.Sprintf("%s-svc", in.Name),
200+
Port,
201+
JDDatabase,
202+
)
203+
o.JDUrl = fmt.Sprintf(
204+
"postgresql://%s:%s@%s:%d/%s?sslmode=disable",
205+
User,
206+
Password,
207+
fmt.Sprintf("%s-svc", in.Name),
208+
portToExpose,
209+
JDDatabase,
210+
)
211+
}
192212
return o, nil
193213
}
194214
// local deployment

framework/pods/defaults.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ func SizedVolumeClaim(size string) []v1.PersistentVolumeClaim {
8080
AccessModes: []v1.PersistentVolumeAccessMode{
8181
v1.ReadWriteOnce,
8282
},
83-
StorageClassName: Ptr("gp3"),
8483
Resources: v1.VolumeResourceRequirements{
8584
Requests: v1.ResourceList{
8685
v1.ResourceStorage: storageQuantity,

framework/pods/forward.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import (
1717
)
1818

1919
const (
20-
RetryDelay = 1 * time.Second
20+
RetryDelay = 1 * time.Second
21+
K8sAPITimeout = 2 * time.Minute
2122
)
2223

2324
// PortForwardConfig represents a single port forward configuration
@@ -210,15 +211,17 @@ func (m *PortForwardManager) attemptForward(cfg PortForwardConfig) error {
210211

211212
// getTargetPodAndPort finds the target pod and resolves the port
212213
func (m *PortForwardManager) getTargetPodAndPort(cfg PortForwardConfig, namespace string) (*corev1.Pod, int, error) {
213-
service, err := m.cs.CoreV1().Services(namespace).Get(context.TODO(), cfg.ServiceName, metav1.GetOptions{})
214+
ctx, cancel := context.WithTimeout(context.Background(), K8sAPITimeout)
215+
defer cancel()
216+
service, err := m.cs.CoreV1().Services(namespace).Get(ctx, cfg.ServiceName, metav1.GetOptions{})
214217
if err != nil {
215218
return nil, 0, fmt.Errorf("failed to get service: %w", err)
216219
}
217220

218221
if len(service.Spec.Selector) == 0 {
219222
return nil, 0, fmt.Errorf("service %s has no selector", cfg.ServiceName)
220223
}
221-
pods, err := m.cs.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{
224+
pods, err := m.cs.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{
222225
LabelSelector: labels.FormatLabels(service.Spec.Selector),
223226
})
224227
if err != nil {

0 commit comments

Comments
 (0)