Skip to content

Commit 54ea97c

Browse files
authored
Flesh out autocomplete (#90)
* Flesh out autocomplete Signed-off-by: Joseph <jvaikath@redhat.com> * binary name fix and use release-archives Signed-off-by: Joseph <jvaikath@redhat.com> * Remove bloat Signed-off-by: Joseph <jvaikath@redhat.com> --------- Signed-off-by: Joseph <jvaikath@redhat.com>
1 parent a037ba0 commit 54ea97c

File tree

6 files changed

+97
-289
lines changed

6 files changed

+97
-289
lines changed

.github/workflows/cross-arch-build-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ jobs:
215215
fail-fast: false
216216
matrix:
217217
include:
218-
- os: macos-13 # Intel
218+
- os: macos-15-intel # Intel
219219
arch: amd64
220220
binary: kubectl-oadp_${{ needs.build-all.outputs.suffix }}darwin_amd64
221221
- os: macos-latest # Apple Silicon

.github/workflows/release.yml

Lines changed: 9 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -33,126 +33,28 @@ jobs:
3333
go mod verify
3434
echo "Dependencies ready"
3535
36-
- name: Build all architectures
36+
- name: Build release archives with checksums
3737
run: |
3838
set -e
39-
echo "Building all architectures for release ${{ github.ref_name }}..."
40-
if ! make release-build VERSION="${{ github.ref_name }}"; then
41-
echo "❌ Build failed"
39+
echo "Building release binaries and archives for ${{ github.ref_name }}..."
40+
if ! make release-archives VERSION="${{ github.ref_name }}"; then
41+
echo "❌ Build or archive creation failed"
4242
exit 1
4343
fi
44-
echo "✅ All builds completed"
44+
echo "✅ All builds and archives completed"
4545
46-
- name: Create release archives
47-
run: |
48-
set -e
49-
echo "Creating release archives..."
50-
51-
# Define the platforms we want for krew (must match oadp.yaml)
52-
declare -a platforms=(
53-
"linux_amd64"
54-
"linux_arm64"
55-
"linux_ppc64le"
56-
"linux_s390x"
57-
"darwin_amd64"
58-
"darwin_arm64"
59-
"windows_amd64"
60-
"windows_arm64"
61-
)
62-
63-
# Create archives only for krew platforms
64-
for platform in "${platforms[@]}"; do
65-
if [[ "$platform" == *"windows"* ]]; then
66-
# Windows binaries have .exe extension
67-
binary="kubectl-oadp_${{ github.ref_name }}_${platform}.exe"
68-
if [[ -f "$binary" ]]; then
69-
echo "Creating archive for $platform..."
70-
cp "$binary" kubectl-oadp.exe
71-
tar -czf "kubectl-oadp_${{ github.ref_name }}_${platform}.tar.gz" kubectl-oadp.exe LICENSE
72-
rm kubectl-oadp.exe
73-
echo "✅ Created kubectl-oadp_${{ github.ref_name }}_${platform}.tar.gz"
74-
else
75-
echo "❌ Binary not found: $binary"
76-
exit 1
77-
fi
78-
else
79-
# Unix binaries (no extension)
80-
binary="kubectl-oadp_${{ github.ref_name }}_${platform}"
81-
if [[ -f "$binary" ]]; then
82-
echo "Creating archive for $platform..."
83-
cp "$binary" kubectl-oadp
84-
tar -czf "kubectl-oadp_${{ github.ref_name }}_${platform}.tar.gz" kubectl-oadp LICENSE
85-
rm kubectl-oadp
86-
echo "✅ Created kubectl-oadp_${{ github.ref_name }}_${platform}.tar.gz"
87-
else
88-
echo "❌ Binary not found: $binary"
89-
exit 1
90-
fi
91-
fi
92-
done
93-
94-
echo ""
95-
echo "Release archives created:"
96-
ls -la *.tar.gz
97-
98-
- name: Generate SHA256 checksums
99-
run: |
100-
set -e
101-
echo "Generating SHA256 checksums..."
102-
sha256sum *.tar.gz > checksums.txt
46+
# Create consolidated checksums file for release
47+
cat *.tar.gz.sha256 > checksums.txt
10348
echo ""
10449
echo "Checksums:"
10550
cat checksums.txt
10651
107-
- name: Generate final krew manifest
108-
run: |
109-
set -e
110-
echo "Generating final krew manifest with version ${{ github.ref_name }}..."
111-
112-
# Set environment variables for template substitution
113-
export VERSION="${{ github.ref_name }}"
114-
export LINUX_AMD64_SHA=$(grep "kubectl-oadp_${{ github.ref_name }}_linux_amd64.tar.gz" checksums.txt | cut -d' ' -f1)
115-
export LINUX_ARM64_SHA=$(grep "kubectl-oadp_${{ github.ref_name }}_linux_arm64.tar.gz" checksums.txt | cut -d' ' -f1)
116-
export DARWIN_AMD64_SHA=$(grep "kubectl-oadp_${{ github.ref_name }}_darwin_amd64.tar.gz" checksums.txt | cut -d' ' -f1)
117-
export DARWIN_ARM64_SHA=$(grep "kubectl-oadp_${{ github.ref_name }}_darwin_arm64.tar.gz" checksums.txt | cut -d' ' -f1)
118-
export WINDOWS_AMD64_SHA=$(grep "kubectl-oadp_${{ github.ref_name }}_windows_amd64.tar.gz" checksums.txt | cut -d' ' -f1)
119-
export WINDOWS_ARM64_SHA=$(grep "kubectl-oadp_${{ github.ref_name }}_windows_arm64.tar.gz" checksums.txt | cut -d' ' -f1)
120-
121-
# Validate all checksums were found
122-
if [[ -z "$LINUX_AMD64_SHA" || -z "$LINUX_ARM64_SHA" || -z "$DARWIN_AMD64_SHA" || -z "$DARWIN_ARM64_SHA" || -z "$WINDOWS_AMD64_SHA" || -z "$WINDOWS_ARM64_SHA" ]]; then
123-
echo "❌ Some checksums are missing!"
124-
echo "Available checksums:"
125-
cat checksums.txt
126-
exit 1
127-
fi
128-
129-
# Use envsubst to substitute environment variables in template
130-
# Save original template and generate final manifest
131-
cp oadp.yaml oadp-template.yaml
132-
envsubst < oadp-template.yaml > oadp.yaml
133-
134-
echo "✅ Final krew manifest generated successfully!"
135-
echo ""
136-
echo "Summary:"
137-
echo "Version: $VERSION"
138-
echo "Linux amd64: ${LINUX_AMD64_SHA:0:16}..."
139-
echo "Linux arm64: ${LINUX_ARM64_SHA:0:16}..."
140-
echo "Darwin amd64: ${DARWIN_AMD64_SHA:0:16}..."
141-
echo "Darwin arm64: ${DARWIN_ARM64_SHA:0:16}..."
142-
echo "Windows amd64: ${WINDOWS_AMD64_SHA:0:16}..."
143-
echo "Windows arm64: ${WINDOWS_ARM64_SHA:0:16}..."
144-
145-
echo ""
146-
echo "Final manifest preview:"
147-
grep -E "(version:|sha256:)" oadp.yaml
148-
14952
- name: Create GitHub Release
15053
uses: softprops/action-gh-release@v1
15154
with:
15255
files: |
15356
*.tar.gz
15457
checksums.txt
155-
oadp.yaml
15658
body: |
15759
## OADP CLI ${{ github.ref_name }}
15860
@@ -185,10 +87,10 @@ jobs:
18587
### Files Included
18688
- **Binary archives**: Platform-specific kubectl-oadp binaries with LICENSE
18789
- **checksums.txt**: SHA256 checksums for all binaries
188-
- **oadp.yaml**: Final krew plugin manifest with populated SHA256 values (ready for krew index)
18990
19091
### For Krew Index Maintainers
191-
The `oadp.yaml` file contains the complete krew plugin manifest with all SHA256 checksums populated and can be used directly for krew index submissions.
92+
- On creating new releases, krew-release-bot will automatically open a PR to the krew index with the new release
93+
- Must be non-prerelease semver tag
19294
draft: false
19395
prerelease: false
19496
env:

COMPLETION.md

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,51 +75,61 @@ Create the wrapper script in the same directory as your `kubectl-oadp` binary:
7575
#### For kubectl plugin completion:
7676

7777
```bash
78-
# If kubectl-oadp is in ~/.local/bin (most common)
79-
cat > ~/.local/bin/kubectl_complete-oadp << 'EOF'
78+
# Auto-detect kubectl-oadp location and create wrapper
79+
OADP_PATH=$(which kubectl-oadp)
80+
OADP_DIR=$(dirname "$OADP_PATH")
81+
82+
cat > "${OADP_DIR}/kubectl_complete-oadp" << EOF
8083
#!/bin/bash
8184
# Wrapper script for kubectl plugin completion
82-
exec ~/.local/bin/kubectl-oadp __complete "$@"
85+
exec ${OADP_PATH} __complete "\$@"
8386
EOF
84-
chmod +x ~/.local/bin/kubectl_complete-oadp
87+
chmod +x "${OADP_DIR}/kubectl_complete-oadp"
8588
```
8689

8790
#### For oc plugin completion:
8891

8992
If you also want `oc oadp` completion (using the same binary as an oc plugin):
9093

9194
```bash
92-
# Create oc completion wrapper
93-
cat > ~/.local/bin/oc_complete-oadp << 'EOF'
95+
# Create oc completion wrapper (uses same auto-detected path)
96+
OADP_PATH=$(which kubectl-oadp)
97+
OADP_DIR=$(dirname "$OADP_PATH")
98+
99+
cat > "${OADP_DIR}/oc_complete-oadp" << EOF
94100
#!/bin/bash
95101
# Wrapper script for oc plugin completion
96-
exec ~/.local/bin/kubectl-oadp __complete "$@"
102+
exec ${OADP_PATH} __complete "\$@"
97103
EOF
98-
chmod +x ~/.local/bin/oc_complete-oadp
104+
chmod +x "${OADP_DIR}/oc_complete-oadp"
99105
```
100106

101-
**For other locations:**
102-
- If using `~/bin`: Replace `~/.local/bin` with `~/bin`
103-
- If using `/usr/local/bin`: Replace `~/.local/bin` with `/usr/local/bin`
104-
105107
### 2. Configure Your Shell
106108

107109
Add completion configuration to your shell's rc file:
108110

109111
**For zsh** (add to `~/.zshrc`):
110112
```bash
111113
# kubectl-oadp completion
112-
if [ -f "$HOME/.local/bin/kubectl-oadp" ]; then
113-
source <($HOME/.local/bin/kubectl-oadp completion zsh)
114+
if command -v kubectl-oadp >/dev/null 2>&1; then
115+
source <(kubectl-oadp completion zsh)
114116
compdef _oadp kubectl-oadp
115117
fi
116118
```
117119

118120
**For bash** (add to `~/.bashrc`):
119121
```bash
120122
# kubectl-oadp completion
121-
if [ -f "$HOME/.local/bin/kubectl-oadp" ]; then
122-
source <($HOME/.local/bin/kubectl-oadp completion bash)
123+
if command -v kubectl-oadp >/dev/null 2>&1; then
124+
source <(kubectl-oadp completion bash)
125+
fi
126+
```
127+
128+
**Note for minimal environments (containers, etc.):** If you get `_get_comp_words_by_ref: command not found` errors, the bash-completion framework needs to be loaded first. Add this before the kubectl-oadp completion:
129+
```bash
130+
# Load bash-completion framework (if not auto-loaded)
131+
if [ -f /usr/share/bash-completion/bash_completion ] && ! type _get_comp_words_by_ref >/dev/null 2>&1; then
132+
source /usr/share/bash-completion/bash_completion
123133
fi
124134
```
125135

@@ -157,12 +167,14 @@ You should see available commands like `backup`, `nonadmin`, `nabsl`, etc.
157167

158168
**Check if wrapper exists:**
159169
```bash
160-
ls -la ~/.local/bin/kubectl_complete-oadp
170+
# Find where kubectl-oadp is installed
171+
OADP_DIR=$(dirname $(which kubectl-oadp))
172+
ls -la "${OADP_DIR}/kubectl_complete-oadp"
161173
```
162174

163175
**Check if it's executable:**
164176
```bash
165-
chmod +x ~/.local/bin/kubectl_complete-oadp
177+
chmod +x "${OADP_DIR}/kubectl_complete-oadp"
166178
```
167179

168180
**Test wrapper directly:**
@@ -176,28 +188,30 @@ kubectl_complete-oadp __complete kubectl oadp
176188
grep -A5 "kubectl-oadp completion" ~/.zshrc
177189

178190
# For bash
179-
grep -A3 "kubectl-oadp completion" ~/.bashrc
191+
grep -A5 "kubectl-oadp completion" ~/.bashrc
180192
```
181193

182194
### Path Issues?
183195

184196
Make sure both files are in the same directory and that directory is in your PATH:
185197
```bash
186-
echo $PATH | grep -o '[^:]*\.local/bin[^:]*'
187198
which kubectl-oadp
188199
which kubectl_complete-oadp
189200
which oc_complete-oadp # if using oc completion
201+
202+
# Check if the directory is in PATH
203+
OADP_DIR=$(dirname $(which kubectl-oadp))
204+
echo $PATH | grep -q "$OADP_DIR" && echo "✓ In PATH" || echo "✗ Not in PATH"
190205
```
191206

192207
## Uninstalling Completion
193208

194209
### Remove the Wrapper Scripts
195210
```bash
196-
# Remove kubectl completion wrapper
197-
rm ~/.local/bin/kubectl_complete-oadp
198-
199-
# Remove oc completion wrapper (if created)
200-
rm ~/.local/bin/oc_complete-oadp
211+
# Find and remove the wrapper scripts
212+
OADP_DIR=$(dirname $(which kubectl-oadp))
213+
rm "${OADP_DIR}/kubectl_complete-oadp"
214+
rm "${OADP_DIR}/oc_complete-oadp" # if you created this
201215
```
202216

203217
### Remove Shell Configuration
@@ -214,19 +228,26 @@ rm ~/.local/bin/oc_complete-oadp
214228

215229
## Advanced: Custom Locations
216230

217-
If your `kubectl-oadp` binary is in a non-standard location, update the wrapper script paths:
231+
If your `kubectl-oadp` binary is in a non-standard location, the dynamic detection will automatically handle it as long as the binary is in your `$PATH`. If it's not in your PATH, you can either:
232+
233+
1. **Add it to PATH** (recommended):
234+
```bash
235+
export PATH="/opt/oadp/bin:$PATH"
236+
# Then use the standard setup commands above
237+
```
218238

239+
2. **Use explicit paths**:
219240
```bash
220241
# Example for custom location /opt/oadp/bin
221242
cat > /opt/oadp/bin/kubectl_complete-oadp << 'EOF'
222243
#!/bin/bash
223244
exec /opt/oadp/bin/kubectl-oadp __complete "$@"
224245
EOF
246+
chmod +x /opt/oadp/bin/kubectl_complete-oadp
225247

226248
# Update shell config accordingly
227249
if [ -f "/opt/oadp/bin/kubectl-oadp" ]; then
228-
source <(/opt/oadp/bin/kubectl-oadp completion zsh)
229-
compdef _oadp kubectl-oadp
250+
source </(/opt/oadp/bin/kubectl-oadp completion bash)
230251
fi
231252
```
232253

Containerfile.download

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,11 @@ RUN go mod download && go mod verify
1313

1414
COPY . .
1515

16-
# Build ALL kubectl-oadp binaries using native Go cross-compilation (no QEMU emulation)
17-
# The download server needs to serve binaries for all platforms, not just one arch
18-
RUN make release-build && \
16+
RUN make release-archives && \
1917
mkdir -p /archives && \
20-
for binary in kubectl-oadp_*; do \
21-
archive_name=$(echo "$binary" | sed 's/\.exe$//' ).tar.gz; \
22-
tar -czf "/archives/$archive_name" "$binary"; \
23-
echo "Created /archives/$archive_name"; \
24-
done
18+
mv *.tar.gz /archives/
2519

2620
# Build the download server for the TARGET platform (the arch this container will run on)
27-
# This uses cross-compilation so the builder can run natively on amd64
2821
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o download-server ./cmd/downloads/server.go
2922

3023
# Clean up to reduce layer size

0 commit comments

Comments
 (0)