Skip to content

Commit 892f65a

Browse files
author
Jacob Woffenden
authored
✨ Cloud Platform enhancements (#11)
Signed-off-by: Jacob Woffenden <jacob.woffenden@digital.justice.gov.uk>
1 parent 48bdb68 commit 892f65a

File tree

6 files changed

+97
-2
lines changed

6 files changed

+97
-2
lines changed

features/src/cloud-platform/CHANGELOG.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- markdownlint-disable MD003 -->
1+
<!-- markdownlint-disable MD003 MD024 -->
22
# Changelog
33

44
All notable changes to this project will be documented in this file.
@@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
## [0.0.2] - 2024-01-31
12+
13+
### Added
14+
15+
- Dependency on `ghcr.io/ministryofjustice/devcontainer-feature/kubernetes`
16+
17+
- Curated Kubernetes configuration file
18+
19+
- ZSH prompt extension
20+
1121
## [0.0.1] - 2024-01-30
1222

1323
### Added
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
{
22
"id": "cloud-platform",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"name": "Cloud Platform",
55
"description": "Installs the Cloud Platform CLI",
66
"options": {
77
"cloudPlatformCliVersion": {
88
"type": "string",
99
"description": "Version of the Cloud Platform CLI to install",
1010
"default": "latest"
11+
},
12+
"installCloudPlatformKubeconfig": {
13+
"type": "boolean",
14+
"description": "Wether to install the Cloud Platform kubeconfig",
15+
"default": true
16+
},
17+
"installCloudPlatformPrompt": {
18+
"type": "boolean",
19+
"description": "Wether to install the Cloud Platform prompt",
20+
"default": true
21+
}
22+
},
23+
"dependsOn": {
24+
"ghcr.io/ministryofjustice/devcontainer-feature/kubernetes:0": {
25+
"kubernetesCliVersion": "v1.26.13"
1126
}
1227
}
1328
}

features/src/cloud-platform/install-cloud-platform-cli.sh

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ get_system_architecture
1010

1111
GITHUB_REPOSITORY="ministryofjustice/cloud-platform-cli"
1212
VERSION=${CLOUDPLATFORMCLIVERSION:-"latest"}
13+
INSTALL_CLOUD_PLATFORM_KUBECONFIG=${INSTALLCLOUDPLATFORMKUBECONFIG:-"true"}
14+
INSTALL_CLOUD_PLATFORM_PROMPT=${INSTALLCLOUDPLATFORMPROMPT:-"true"}
1315

1416
if [[ "${VERSION}" == "latest" ]]; then
1517
get_github_latest_tag "${GITHUB_REPOSITORY}"
@@ -29,4 +31,12 @@ install --owner=vscode --group=vscode --mode=775 cloud-platform /usr/local/bin/c
2931

3032
install --owner=vscode --group=vscode --mode=775 completions/cloud-platform.zsh /usr/local/share/zsh/site-functions/_cloud-platform
3133

34+
if [[ "${INSTALL_CLOUD_PLATFORM_KUBECONFIG}" == "true" ]]; then
35+
install --owner=vscode --group=vscode --mode=775 "$(dirname "${0}")"/src/home/vscode/.kube/config /home/vscode/.kube/config
36+
fi
37+
38+
if [[ "${INSTALL_CLOUD_PLATFORM_PROMPT}" == "true" ]]; then
39+
install --owner=vscode --group=vscode --mode=775 "$(dirname "${0}")"/src/home/vscode/.devcontainer/promptrc.d/cloud-platform.sh /home/vscode/.devcontainer/promptrc.d/cloud-platform.sh
40+
fi
41+
3242
rm --recursive --force LICENSE README.md completions "cloud-platform-cli_${VERSION}_linux_${ARCHITECTURE}.tar.gz"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2016
3+
4+
PROMPT+='`\
5+
kubectlCurrentContext=$(kubectl config current-context 2>/dev/null); \
6+
kubectlCurrentNamespace=$(kubectl config view --minify --output "jsonpath={..namespace}"); \
7+
kubectlClientId=$(kubectl config view --output json | jq -r ".users[0].user[\"auth-provider\"].config[\"client-id\"]"); \
8+
kubectlServerVersion=$(kubectl version --output json 2>/dev/null | jq -r .serverVersion.gitVersion | sed "s/v//"); \
9+
&& if [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ "${kubectlClientId}" == "REPLACE_WITH_CLIENT_ID" ]]; then \
10+
echo -n "[ cluster: %{$fg[yellow]%}${kubectlCurrentContext} (requires authentication)%{$reset_color%} ] "; \
11+
elif [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ ! -z "${kubectlServerVersion}" ]]; then \
12+
echo -n "[ cluster: %{$fg[green]%}${kubectlCurrentContext} (authenticated)%{$reset_color%} ] "; \
13+
else
14+
echo -n "[ cluster: %{$fg[red]%}${kubectlCurrentContext} (issue with authentication)%{$reset_color%} ] "; \
15+
fi \
16+
&& if [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ ! -z "${kubectlCurrentNamespace}" ]] && [[ "${kubectlCurrentNamespace}" == *"-prod"* ]]; then \
17+
echo -n "[ namespace: %{$fg[red]%}${kubectlCurrentNamespace}%{$reset_color%} ] "; \
18+
elif [[ "${kubectlCurrentContext}" == "cloud-platform-live" ]] && [[ ! -z "${kubectlCurrentNamespace}" ]]; then \
19+
echo -n "[ namespace: %{$fg[green]%}${kubectlCurrentNamespace}%{$reset_color%} ] "; \
20+
fi \
21+
`'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
apiVersion: v1
3+
kind: Config
4+
preferences:
5+
colors: true
6+
7+
####################################################################################################
8+
#
9+
# Changes to this file will be overwritten when rebuilding the dev container.
10+
#
11+
####################################################################################################
12+
13+
current-context: cloud-platform-live
14+
15+
clusters:
16+
- name: cloud-platform-live
17+
cluster:
18+
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeE1EWXlPREUyTXprMU5sb1hEVE14TURZeU5qRTJNemsxTmxvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBB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S0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
19+
server: https://DF366E49809688A3B16EEC29707D8C09.gr7.eu-west-2.eks.amazonaws.com
20+
21+
users:
22+
- name: auth0
23+
user:
24+
auth-provider:
25+
name: oidc
26+
config:
27+
client-id: "REPLACE_WITH_CLIENT_ID"
28+
client-secret: "REPLACE_WITH_CLIENT_SECRET"
29+
id-token: "REPLACE_WITH_ID_TOKEN"
30+
idp-issuer-url: https://justice-cloud-platform.eu.auth0.com/
31+
refresh-token: "REPLACE_WITH_REFRESH_TOKEN"
32+
33+
contexts:
34+
- name: cloud-platform-live
35+
context:
36+
cluster: cloud-platform-live
37+
user: auth0

features/test/cloud-platform/test.sh

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ source dev-container-features-test-lib
88

99
check "cloud-platform version" cloud-platform version
1010
check "cloud-platform completions existence" stat /usr/local/share/zsh/site-functions/_cloud-platform
11+
check "cloud-platform kubeconfig existence" stat /home/vscode/.kube/config
12+
check "cloud-platform prompt existence" stat /home/vscode/.devcontainer/promptrc.d/cloud-platform.sh
1113

1214
reportResults

0 commit comments

Comments
 (0)