Skip to content

Commit

Permalink
Merge branch 'main' into fix/port-forward
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol1696 authored Oct 9, 2024
2 parents 9a536c8 + ec9d0ee commit e1eba59
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 16 deletions.
1 change: 1 addition & 0 deletions clients/js/__output__/custom-pod-ports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ chains:
defaultPorts:
rpc: 26657
grpc: 9090
grpc-web: 9091
rest: 1317
exposer: 8081
faucet: 8000
Expand Down
4 changes: 4 additions & 0 deletions clients/js/packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.10.2](https://github.com/cosmology-tech/starship/compare/@starship-ci/[email protected]...@starship-ci/[email protected]) (2024-10-03)

**Note:** Version bump only for package @starship-ci/cli

## [2.10.1](https://github.com/cosmology-tech/starship/compare/@starship-ci/[email protected]...@starship-ci/[email protected]) (2024-09-17)

**Note:** Version bump only for package @starship-ci/cli
Expand Down
4 changes: 2 additions & 2 deletions clients/js/packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@starship-ci/cli",
"version": "2.10.1",
"version": "2.10.2",
"author": "Dan Lynch <[email protected]>",
"description": "Starship CLI",
"main": "index.js",
Expand Down Expand Up @@ -55,7 +55,7 @@
"@types/js-yaml": "^4.0.9"
},
"dependencies": {
"@starship-ci/client": "^2.9.1",
"@starship-ci/client": "^2.9.2",
"chalk": "^4.1.0",
"deepmerge": "^4.3.1",
"inquirerer": "^1.9.0",
Expand Down
5 changes: 4 additions & 1 deletion clients/js/packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const params: string[] = [
'repo',
'repoUrl',
'chart',
'namespace'
'namespace',
'timeout'
];

export const loadConfig = (argv: any): Config => {
Expand Down Expand Up @@ -89,6 +90,8 @@ Command-line Options:
Will overide config file settings for name.
--version <ver> Specify the version of the Helm chart, default: v0.2.6.
Will overide config file settings for version.
--timeout <time> Specify the timeout for the Helm operations, default: 10m.
Will overide config file settings for timeout.
Examples:
$ starship start --config ./config/two-chain.yaml
Expand Down
4 changes: 4 additions & 0 deletions clients/js/packages/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [2.9.2](https://github.com/cosmology-tech/starship/compare/@starship-ci/[email protected]...@starship-ci/[email protected]) (2024-10-03)

**Note:** Version bump only for package @starship-ci/client

## [2.9.1](https://github.com/cosmology-tech/starship/compare/@starship-ci/[email protected]...@starship-ci/[email protected]) (2024-09-17)

**Note:** Version bump only for package @starship-ci/client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ helm repo update
helm search repo starship/devnet --version v0.2.3
Call: deploy()
Log: Installing the helm chart. This is going to take a while.....
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3 --timeout 10m
Log: Run "starship get-pods" to check the status of the cluster
Call: startPortForward()
Log: Attempting to stop any existing port-forwards...
Expand Down Expand Up @@ -46,7 +46,7 @@ exports[`StarshipClient setup 2`] = `
"helm repo add starship https://cosmology-tech.github.io/starship/
helm repo update
helm search repo starship/devnet --version v0.2.3
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3 --timeout 10m
ps -ef | grep -i 'kubectl port-forward' | grep -v 'grep' | awk '{print $2}'
sleep 2
kubectl port-forward pods/osmosis-1-genesis-0 26657:26657 > /dev/null 2>&1 &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ helm repo update
helm search repo starship/devnet --version v0.2.3
Call: deploy()
Log: Installing the helm chart. This is going to take a while.....
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3 --timeout 10m
Log: Run "starship get-pods" to check the status of the cluster
Call: startPortForward()
Log: Attempting to stop any existing port-forwards...
Expand Down Expand Up @@ -44,7 +44,7 @@ exports[`StarshipClient setup 2`] = `
"helm repo add starship https://cosmology-tech.github.io/starship/
helm repo update
helm search repo starship/devnet --version v0.2.3
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3 --timeout 10m
ps -ef | grep -i 'kubectl port-forward' | grep -v 'grep' | awk '{print $2}'
sleep 2
kubectl port-forward pods/osmosis-1-genesis-0 1317:6767676 > /dev/null 2>&1 &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ helm repo update
helm search repo starship/devnet --version v0.2.3
Call: deploy()
Log: Installing the helm chart. This is going to take a while.....
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3 --timeout 10m
Log: Run "starship get-pods" to check the status of the cluster
Call: startPortForward()
Log: Attempting to stop any existing port-forwards...
Expand Down Expand Up @@ -44,7 +44,7 @@ exports[`StarshipClient setup 2`] = `
"helm repo add starship https://cosmology-tech.github.io/starship/
helm repo update
helm search repo starship/devnet --version v0.2.3
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3
helm install -f ../../__fixtures__/config.yaml osmojs starship/devnet --version v0.2.3 --timeout 10m
ps -ef | grep -i 'kubectl port-forward' | grep -v 'grep' | awk '{print $2}'
sleep 2
kubectl port-forward pods/osmosis-1-genesis-0 26657:26657 > /dev/null 2>&1 &
Expand Down
2 changes: 1 addition & 1 deletion clients/js/packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@starship-ci/client",
"version": "2.9.1",
"version": "2.9.2",
"author": "Dan Lynch <[email protected]>",
"description": "Starship CI Client",
"main": "index.js",
Expand Down
101 changes: 98 additions & 3 deletions clients/js/packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface StarshipContext {
namespace?: string;
verbose?: boolean;
curdir?: string;
timeout?: string;
}

export const defaultStarshipContext: Partial<StarshipContext> = {
Expand All @@ -30,7 +31,8 @@ export const defaultStarshipContext: Partial<StarshipContext> = {
repoUrl: 'https://cosmology-tech.github.io/starship/',
chart: 'starship/devnet',
namespace: '',
version: ''
version: '',
timeout: '10m'
};

export interface PodPorts {
Expand All @@ -47,7 +49,7 @@ export interface PodPorts {
}

const defaultName: string = 'starship';
const defaultVersion: string = 'v0.2.13';
const defaultVersion: string = 'v0.2.14';

// TODO talk to Anmol about moving these into yaml, if not already possible?
const defaultPorts: PodPorts = {
Expand Down Expand Up @@ -395,6 +397,8 @@ export class StarshipClient implements StarshipClientI {
this.ctx.chart,
'--version',
this.config.version,
'--timeout',
this.ctx.timeout,
...this.getDeployArgs(),
...options
];
Expand Down Expand Up @@ -507,12 +511,35 @@ export class StarshipClient implements StarshipClientI {
{ log: false, silent: true }
).trim();

const [phase, readyList, restartCountList, reason] = result.split(/\s+/);
// Ensure the output contains valid fields to split
const parts = result.split(/\s+/);
if (parts.length < 3) {
this.log(
chalk.red(`Unexpected pod status output for ${podName}: ${result}`)
);
return;
}

const [phase, readyList, restartCountList, reason] = parts;

// Validate readyList and restartCountList before applying split
if (!readyList || !restartCountList) {
this.log(
chalk.red(
`Invalid ready or restart count for pod ${podName}: ${result}`
)
);
return;
}

const ready = readyList.split(',').every((state) => state === 'true');
const restarts = restartCountList
.split(',')
.reduce((acc, count) => acc + parseInt(count, 10), 0);

// check for repeated image pull errors
this.checkImagePullFailures(podName);

this.podStatuses.set(podName, {
phase,
ready,
Expand Down Expand Up @@ -568,6 +595,74 @@ export class StarshipClient implements StarshipClientI {
});
}

public checkImagePullFailures(podName: string): void {
// Fetch events from kubectl describe for the given pod
const eventLines = this.getPodEventsFromDescribe(podName);
const errorPattern = /Failed to pull image/;
const imageErrors: { [image: string]: number } = {};

// Parse through event lines to identify image pull failures
eventLines.forEach((line) => {
const message = line || '';
if (errorPattern.test(message)) {
const imageMatch = message.match(/image "(.*?)"/);
if (imageMatch && imageMatch[1]) {
const imageName = imageMatch[1];
imageErrors[imageName] = (imageErrors[imageName] || 0) + 1;
}
}
});

// Log errors for images that have failed more than twice
Object.entries(imageErrors).forEach(([imageName, errorCount]) => {
if (errorCount >= 3) {
this.log(
`${chalk.red(
`
Error: Image '${imageName}' failed to pull ${errorCount} times for pod ${podName}.
Please check the image name and ensure it is correct.
Run "starship stop" to stop the deployment which would be in stuck state.
`
)}`
);
this.exit(1);
}
});
}

private getPodEventsFromDescribe(podName: string): string[] {
// Execute the 'kubectl describe pod' command
const result = this.exec(
['kubectl', 'describe', 'pod', podName, ...this.getArgs()],
{ log: false, silent: true }
);

// Check if the command was successful
if (result.code !== 0) {
this.log(
chalk.red(`Failed to describe pod ${podName}: ${result.stderr}`)
);
return [];
}

const describeOutput = result.stdout;

// Extract the 'Events' section from the describe output
const eventsSection = describeOutput.split('Events:')[1];
if (!eventsSection) {
this.log(chalk.yellow(`No events found for pod ${podName}`));
return [];
}

// Split the events section into individual lines
const eventLines = eventsSection
.split('\n')
.filter((line) => line.trim() !== '');
this.log(`event lints: ${eventLines.join('\n')}`);

return eventLines;
}

private forwardPort(
chain: Chain,
localPort: number,
Expand Down
19 changes: 19 additions & 0 deletions docs/pages/config/chains.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,22 @@ chains:
coins: 100000000000000uion
```

## `readinessProbe` (optional)
The `readinessProbe` directive allows you to set the readiness probe for the chain pods. This is useful when you want to test a chain with specific readiness probe settings.
Note, this is the same as the [kubernetes readiness probe](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/)

```yaml
chains:
- id: osmosis-1
name: osmosis
numValidators: 1
readinessProbe:
exec:
command:
- bash
- -c
- |
$CHAIN_BIN status 2>&1 | jq -e '.SyncInfo.catching_up == false'
initialDelaySeconds: 60
periodSeconds: 20
```
2 changes: 1 addition & 1 deletion starship/charts/devnet/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.2.14
version: 0.2.15

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
3 changes: 3 additions & 0 deletions starship/charts/devnet/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,9 @@ defaultChains:
trap 'kill $killer 2>/dev/null' EXIT
# Return the test's exit code, whether it succeeded, failed, or was killed.
wait $tester
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 15
kujira:
image: ghcr.io/cosmology-tech/starship/kujira:v1.1.0
home: /root/.kujira
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ spec:
httpGet:
path: /status
port: 26657
{{- end }}
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 15
{{- end }}
{{- end }}
- name: exposer
image: {{ $.Values.exposer.image }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ spec:
httpGet:
path: /status
port: 26657
{{- end }}
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 15
{{- end }}
{{- end }}
- name: exposer
image: {{ $.Values.exposer.image }}
Expand Down
3 changes: 3 additions & 0 deletions starship/charts/devnet/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@
"amount"
]
}
},
"readinessProbe": {
"type": "object"
}
},
"additionalProperties": false,
Expand Down

0 comments on commit e1eba59

Please sign in to comment.