Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.

Commit 6357148

Browse files
committed
chore: Initial import
Signed-off-by: Rashed Kamal <krashed@vmware.com>
1 parent 630a93d commit 6357148

4,612 files changed

Lines changed: 1329540 additions & 19 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/zz_generated.*.go linguist-generated=true
2+
hack/** linguist-generated=true
3+
vendor/** linguist-generated=true

.github/dependabot.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
- package-ecosystem: gomod
9+
directory: "/"
10+
schedule:
11+
interval: daily
12+
open-pull-requests-limit: 10
13+
- package-ecosystem: gomod
14+
directory: "/hack"
15+
schedule:
16+
interval: daily
17+
open-pull-requests-limit: 10

.github/samples/pod.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
apiVersion: v1
3+
kind: Pod
4+
metadata:
5+
name: static-web
6+
labels:
7+
carto.run/workload-name: petclinic
8+
spec:
9+
containers:
10+
- name: web
11+
image: ubuntu
12+
args:
13+
- /bin/sh
14+
- -c
15+
- >
16+
while true;
17+
do
18+
date
19+
sleep 1
20+
done

.github/workflows/ci.yaml

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
- '!dependabot/**'
8+
tags:
9+
- '**'
10+
pull_request: {}
11+
12+
jobs:
13+
14+
unit:
15+
env:
16+
TANZU_CLI_NO_INIT: true
17+
TANZU_HOME: $HOME/tanzu
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
- uses: actions/setup-go@v2
22+
with:
23+
go-version: 1.17.x
24+
- name: Grype scan
25+
run: |
26+
echo "##[group]Install grype"
27+
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
28+
echo "##[endgroup]"
29+
echo "##[group]Scan source ."
30+
grype dir:. --exclude ./hack,./vendor
31+
echo "##[endgroup]"
32+
- name: Install tanzu cli
33+
run: |
34+
TANZU_VERSION=$(cat TANZU_VERSION)
35+
env
36+
mkdir -p ${TANZU_HOME}
37+
curl -Lo tanzu-framework.tar.gz https://github.com/vmware-tanzu/tanzu-framework/releases/download/${TANZU_VERSION}/tanzu-framework-linux-amd64.tar.gz
38+
tar -xzf tanzu-framework.tar.gz -C ${TANZU_HOME}
39+
sudo mv ${TANZU_HOME}/cli/core/${TANZU_VERSION}/tanzu-core-linux_amd64 /usr/local/bin/tanzu
40+
chmod +x /usr/local/bin/tanzu
41+
tanzu init
42+
tanzu plugin repo add -b tanzu-cli-admin-plugins -n admin -p artifacts-admin
43+
curl -Lo admin-plugins.tar.gz https://github.com/vmware-tanzu/tanzu-framework/releases/download/${TANZU_VERSION}/tanzu-framework-plugins-admin-linux-amd64.tar.gz
44+
tar -xzf admin-plugins.tar.gz -C ${TANZU_HOME}
45+
tanzu plugin install builder --local ${TANZU_HOME}/admin-plugins
46+
tanzu plugin install test --local ${TANZU_HOME}/admin-plugins
47+
tanzu plugin list
48+
- name: Test
49+
run: make test
50+
- uses: codecov/codecov-action@v2
51+
with:
52+
token: c6e0ea67-1493-464a-b879-d8f06da7d313
53+
- name: Build Version
54+
run: echo "BUILD_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
55+
if: startsWith(github.ref, 'refs/tags/')
56+
- name: Build
57+
run: make publish
58+
- uses: actions/upload-artifact@v2
59+
with:
60+
name: tanzu-apps-plugin.tar.gz
61+
path: tanzu-apps-plugin*.tar.gz
62+
retention-days: 1
63+
- name: Install
64+
run: make install
65+
- name: Verify docs
66+
run: |
67+
rm -rf docs/command-reference
68+
tanzu apps docs --directory docs/command-reference
69+
git diff --exit-code docs
70+
continue-on-error: true
71+
72+
acceptance:
73+
needs: unit
74+
runs-on: ubuntu-latest
75+
strategy:
76+
matrix:
77+
k8s:
78+
- 1.20.2
79+
- 1.21.2
80+
- 1.22.5
81+
env:
82+
REGISTRY_NAME: registry.local
83+
REGISTRY_PORT: 5000
84+
TANZU_CLI_NO_INIT: true
85+
TANZU_HOME: $HOME/tanzu
86+
OS_ARCH: linux-amd64
87+
steps:
88+
- uses: actions/checkout@v3
89+
- uses: vmware-tanzu/carvel-setup-action@v1
90+
- name: Download plugin bundle
91+
uses: actions/download-artifact@v2
92+
with:
93+
name: tanzu-apps-plugin.tar.gz
94+
- name: Install tanzu cli
95+
run: |
96+
TANZU_VERSION=$(cat TANZU_VERSION)
97+
mkdir -p ${TANZU_HOME}
98+
curl -Lo tanzu-framework.tar.gz https://github.com/vmware-tanzu/tanzu-framework/releases/download/${TANZU_VERSION}/tanzu-framework-linux-amd64.tar.gz
99+
tar -xzf tanzu-framework.tar.gz -C ${TANZU_HOME}
100+
sudo mv ${TANZU_HOME}/cli/core/${TANZU_VERSION}/tanzu-core-linux_amd64 /usr/local/bin/tanzu
101+
chmod +x /usr/local/bin/tanzu
102+
env
103+
tanzu init
104+
- name: Build Version
105+
run: echo "BUILD_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
106+
if: startsWith(github.ref, 'refs/tags/')
107+
- name: Install CLI
108+
run: |
109+
set -o errexit
110+
set -o nounset
111+
set -o pipefail
112+
113+
tar -xvf tanzu-apps-plugin.tar.gz
114+
tanzu plugin install apps --local ./${OS_ARCH} --version ${BUILD_VERSION:-v0.0.0-dev}
115+
- name: Install kind
116+
run: |
117+
cd $(mktemp -d -t kind.XXXX)
118+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-$(go env GOHOSTOS)-$(go env GOHOSTARCH)
119+
chmod +x ./kind
120+
sudo mv ./kind /usr/local/bin
121+
cd -
122+
- name: Create Cluster
123+
run: |
124+
set -o errexit
125+
set -o nounset
126+
set -o pipefail
127+
128+
# KinD configuration.
129+
cat > kind.yaml <<EOF
130+
apiVersion: kind.x-k8s.io/v1alpha4
131+
kind: Cluster
132+
nodes:
133+
- role: control-plane
134+
image: kindest/node:v${{ matrix.k8s }}
135+
EOF
136+
kind create cluster --wait 5m --config kind.yaml
137+
- name: Deploy Cartographer
138+
run: |
139+
set -o errexit
140+
set -o nounset
141+
set -o pipefail
142+
143+
echo "##[group]Apply cartographer"
144+
kubectl create namespace cartographer-system
145+
kapp deploy -y -a cartographer -n kube-system -f ./acceptance/vendor/cartographer/
146+
echo "##[endgroup]"
147+
echo "##[group]Apply static pod"
148+
kubectl apply -f ./.github/samples/pod.yaml
149+
echo "##[endgroup]"
150+
- name: Test CLI commands
151+
run: |
152+
set -o errexit
153+
set -o nounset
154+
set -o pipefail
155+
156+
echo "##[group]Create workload"
157+
tanzu apps workload create petclinic --git-repo example.com --git-branch main --annotation serving.knative.dev/maxScale=10 --yes
158+
echo "##[endgroup]"
159+
echo "##[group]List workload"
160+
tanzu apps workload list
161+
echo "##[endgroup]"
162+
echo "##[group]Get workload"
163+
tanzu apps workload get petclinic
164+
echo "##[endgroup]"
165+
echo "##[group]Update workload"
166+
tanzu apps workload update petclinic --label cli.ci/new-label=true --yes
167+
echo "##[endgroup]"
168+
- name: Collect diagnostics
169+
run: |
170+
echo "##[group]Static Pod"
171+
kubectl describe pod static-web
172+
echo "##[endgroup]"
173+
echo "##[group]Workload"
174+
kubectl describe workload petclinic
175+
echo "##[endgroup]"
176+
continue-on-error: true
177+
- name: Delete Gracefully
178+
run: |
179+
set -o errexit
180+
set -o nounset
181+
set -o pipefail
182+
183+
echo "##[group]Delete workload"
184+
printf 'y' | tanzu apps workload delete petclinic
185+
echo "##[endgroup]"
186+
echo "##[group]Delete pod"
187+
kubectl delete -f ./.github/samples/pod.yaml
188+
echo "##[endgroup]"
189+
echo "##[group]Delete cartographer"
190+
kapp delete -y -a cartographer -n kube-system
191+
kubectl delete namespace cartographer-system
192+
echo "##[endgroup]"
193+
if: always()
194+
- name: Cleanup cluster
195+
run: kind delete cluster
196+
if: always()
197+
198+
create-release:
199+
needs:
200+
- unit
201+
- acceptance
202+
if: startsWith(github.ref, 'refs/tags/')
203+
runs-on: ubuntu-latest
204+
steps:
205+
- name: Get the version
206+
id: get_version
207+
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
208+
- name: Draft release
209+
id: create_release
210+
uses: actions/create-release@v1.1.4
211+
env:
212+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
213+
with:
214+
tag_name: ${{ github.ref }}
215+
release_name: Release ${{ steps.get_version.outputs.VERSION }}
216+
draft: true
217+
- name: Create release info files
218+
run: |
219+
echo "${{ steps.get_version.outputs.VERSION }}" > RELEASE_INFO_VERSION
220+
echo "${{ steps.create_release.outputs.upload_url }}" > RELEASE_INFO_UPLOAD_URL
221+
- name: Upload release files
222+
uses: actions/upload-artifact@v2
223+
with:
224+
name: tanzu-apps-plugin.tar.gz
225+
path: RELEASE_INFO_*
226+
retention-days: 1
227+
228+
229+
release:
230+
needs:
231+
- create-release
232+
if: startsWith(github.ref, 'refs/tags/')
233+
strategy:
234+
matrix:
235+
os-arch: ["", -darwin-amd64, -linux-amd64, -windows-amd64]
236+
runs-on: ubuntu-latest
237+
env:
238+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
239+
steps:
240+
- name: Download staged CLI binaries${{ matrix.os-arch }}
241+
uses: actions/download-artifact@v2.0.10
242+
with:
243+
name: tanzu-apps-plugin.tar.gz
244+
- name: Get release info
245+
run: |
246+
echo "RELEASE_VERSION=$(cat RELEASE_INFO_VERSION)" >> $GITHUB_ENV
247+
echo "UPLOAD_URL=$(cat RELEASE_INFO_UPLOAD_URL)" >> $GITHUB_ENV
248+
- name: Upload CLI release${{ matrix.os-arch }}
249+
uses: actions/upload-release-asset@v1.0.2
250+
with:
251+
upload_url: ${{ env.UPLOAD_URL }}
252+
asset_path: tanzu-apps-plugin${{ matrix.os-arch }}.tar.gz
253+
asset_name: tanzu-apps-plugin${{ matrix.os-arch }}-${{ env.RELEASE_VERSION }}.tar.gz
254+
asset_content_type: application/gzip
255+

.gitignore

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Ignore everything in this directory
2-
*
3-
# Except this file
4-
!.gitignore
1+
/artifacts
2+
/bin
3+
/cover.out
4+
/coverage.txt
5+
/tanzu-apps-plugin*.tar.gz
6+
.vscode/
7+
.idea
8+
.DS_Store

DEVELOPMENT.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
- [Local builds](#local-builds)
2+
- [Command documentation](#command-documentation)
3+
- [Unit testing](#unit-testing)
4+
- [Acceptance testing](#acceptance-testing)
5+
- [Installing Cartographer](#installing-cartographer)
6+
- [Debug Code Completion](#debug-code-completion)
7+
8+
---
9+
10+
## Local builds
11+
12+
Building the CLI plugin locally requires both go 1.17 and the [Tanzu CLI](https://github.com/vmware-tanzu/tanzu-framework/tree/main/cmd/cli#installation) with the builder plugin installed.
13+
14+
Install the Tanzu builder and test plugins:
15+
16+
```sh
17+
tanzu init
18+
```
19+
20+
```sh
21+
tanzu plugin repo add -b tanzu-cli-admin-plugins -n admin -p artifacts-admin
22+
```
23+
24+
```sh
25+
tanzu plugin install builder
26+
```
27+
28+
```sh
29+
tanzu plugin install test
30+
```
31+
32+
To build and install the apps plugin, run: (repeat this step any time you pull new source code to get the latest)
33+
34+
```sh
35+
make install
36+
```
37+
38+
## Command documentation
39+
40+
Command argument and flag documentation is available in the [docs](./docs/tanzu_apps.md) directory. CI will fail if this content is not kept up to date.
41+
42+
To regenerate the docs, run:
43+
44+
```sh
45+
make docs
46+
```
47+
48+
## Unit testing
49+
50+
All unit tests can be run on any machine with go 1.16+ installed.
51+
52+
```sh
53+
make test
54+
```
55+
56+
## Acceptance testing
57+
58+
In order to use the CLI, the runtime dependencies need to be installed into the target cluster.
59+
60+
Dependencies:
61+
- Cartographer
62+
63+
### Installing Cartographer
64+
65+
See Cartographer install documentation [here](https://github.com/vmware-tanzu/cartographer#installation)
66+
67+
## Debug Code Completion
68+
69+
To enable code completion follow the instructions in `tanzu help completion`.
70+
71+
To ease testing add the prefix `__complete` to your command e.g.
72+
```sh
73+
tanzu __complete apps workload tail spring-petclinic --component=
74+
```
75+
This will output the completion suggestions and the ShellCompDirective
76+
Add logs using `cobra.CompDebugln(msg string, printToStdErr bool)` and set `BASH_COMP_DEBUG_FILE` env variable to a local file path to see logs without adding new entries to the suggestions
77+
Make sure to remove any logs before sending a PR

0 commit comments

Comments
 (0)