Skip to content

Commit

Permalink
Merge branch 'add-flux-oci-edge' into edge
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingdon Barrett committed Aug 5, 2022
2 parents bf0907e + e0e5b6c commit 910c9c8
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 8 deletions.
48 changes: 46 additions & 2 deletions .github/workflows/build-vsix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,52 @@ jobs:
with:
version: v0.12.0
image: kindest/node:v1.20.7
- run: 'wget https://fluxcd.io/install.sh'
- run: 'bash install.sh'

# - run: 'wget https://fluxcd.io/install.sh'
# - run: 'bash install.sh'

- name: Prepare
id: prep
run: |
GIT_TAG=${GITHUB_REF/refs\/tags\/release\//}
FLUX_PATH=${GITHUB_WORKSPACE}/bin
# FLUX_OCI_SHA=2b1cc62
# mkdir flux2 && pushd flux2
# git init
# git remote add origin https://github.com/fluxcd/flux2
git clone --depth 1 https://github.com/fluxcd/flux2 -b oci
# git fetch --depth 1 origin $FLUX_OCI_SHA
# git checkout FETCH_HEAD
pushd flux2
FLUX_OCI_SHA=$(git rev-parse --short HEAD)
popd
mkdir -p "${FLUX_PATH}"
echo "${FLUX_PATH}" >> $GITHUB_PATH
echo ::set-output name=GIT_TAG::${GIT_TAG}
echo ::set-output name=FLUX_PATH::${FLUX_PATH}
echo ::set-output name=FLUX_OCI_SHA::${FLUX_OCI_SHA}
- name: Cache Flux OCI (prerelease)
id: cache-flux
uses: actions/cache@v3
env:
cache-name: flux
with:
path: ${{ steps.prep.outputs.FLUX_PATH }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ steps.prep.outputs.FLUX_OCI_SHA }}

# (if cache is not populated at this point we are not ready to run CI and we should fail)

- name: Download latest OCI Flux
if: steps.cache-flux.outputs.cache-hit != 'true'
run: |
echo "ERROR: Flux CLI binary cannot be restored from cache"
echo " (hint: check out the 'Build Flux OCI Binary (Pre-release)' job which should "
echo " have populated the cache, or just try pushing one more commit)"
exit 1
- name: Run Tests
uses: GabrielBB/xvfb-action@v1
with:
Expand Down
47 changes: 45 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,51 @@ jobs:
with:
version: v0.12.0
image: kindest/node:v1.20.7
- run: 'wget https://fluxcd.io/install.sh'
- run: 'bash install.sh'

# - run: 'wget https://fluxcd.io/install.sh'
# - run: 'bash install.sh'

- name: Prepare
id: prep
run: |
GIT_TAG=${GITHUB_REF/refs\/tags\/release\//}
FLUX_PATH=${GITHUB_WORKSPACE}/bin
# FLUX_OCI_SHA=2b1cc62
# mkdir flux2 && pushd flux2
# git init
# git remote add origin https://github.com/fluxcd/flux2
git clone --depth 1 https://github.com/fluxcd/flux2 -b oci
# git fetch --depth 1 origin $FLUX_OCI_SHA
# git checkout FETCH_HEAD
pushd flux2
FLUX_OCI_SHA=$(git rev-parse --short HEAD)
popd
mkdir -p "${FLUX_PATH}"
echo "${FLUX_PATH}" >> $GITHUB_PATH
echo ::set-output name=GIT_TAG::${GIT_TAG}
echo ::set-output name=FLUX_PATH::${FLUX_PATH}
echo ::set-output name=FLUX_OCI_SHA::${FLUX_OCI_SHA}
- name: Cache Flux OCI (prerelease)
id: cache-flux
uses: actions/cache@v3
env:
cache-name: flux
with:
path: ${{ steps.prep.outputs.FLUX_PATH }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ steps.prep.outputs.FLUX_OCI_SHA }}

# (if cache is not populated at this point we are not ready to run CI and we should fail)

- name: Download latest OCI Flux
if: steps.cache-flux.outputs.cache-hit != 'true'
run: |
echo "ERROR: Flux CLI binary cannot be restored from cache"
echo " (hint: check out the 'Build Flux OCI Binary (Pre-release)' job which should "
echo " have populated the cache, or just try pushing one more commit)"
exit 1
- name: extension test
uses: GabrielBB/xvfb-action@86d97bde4a65fe9b290c0b3fb92c2c4ed0e5302d # pin@v1
with:
Expand Down
2 changes: 2 additions & 0 deletions src/azure/azureTools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { window } from 'vscode';
import safesh from 'shell-escape-tag';
import { telemetry } from '../extension';
import { kubernetesTools } from '../kubernetes/kubernetesTools';
import { ClusterProvider, ConfigMap } from '../kubernetes/kubernetesTypes';
Expand Down Expand Up @@ -40,6 +41,7 @@ class AzureTools {
clusterProvider: AzureClusterProvider,
): Promise<undefined | ShellResult> {

contextName = safesh.escape(contextName);
let azureMetadata = await this.getAzureMetadata(contextName, clusterProvider);
if (!azureMetadata) {
azureMetadata = await askUserForAzureMetadata(contextName);
Expand Down
3 changes: 2 additions & 1 deletion src/commands/fluxCheck.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import safesh from 'shell-escape-tag';
import { shell } from '../shell';
import { ClusterContextNode } from '../views/nodes/clusterContextNode';

Expand All @@ -6,5 +7,5 @@ import { ClusterContextNode } from '../views/nodes/clusterContextNode';
* @param clusterNode target cluster node (from tree node context menu)
*/
export async function fluxCheck(clusterNode: ClusterContextNode) {
shell.execWithOutput(`flux check --context ${clusterNode.contextName}`);
shell.execWithOutput(safesh`flux check --context ${clusterNode.contextName}`);
}
7 changes: 4 additions & 3 deletions src/flux/fluxTools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { window } from 'vscode';
import safesh from 'shell-escape-tag';
import { telemetry } from '../extension';
import { KubernetesObjectKinds } from '../kubernetes/kubernetesTypes';
import { shell } from '../shell';
Expand Down Expand Up @@ -51,7 +52,7 @@ class FluxTools {
* https://github.com/fluxcd/flux2/blob/main/cmd/flux/check.go
*/
async check(context: string): Promise<{ prerequisites: FluxPrerequisite[]; controllers: FluxController[]; } | undefined> {
const result = await shell.execWithOutput(`flux check --context ${context}`, { revealOutputView: false });
const result = await shell.execWithOutput(safesh`flux check --context ${context}`, { revealOutputView: false });

if (result.code !== 0) {
telemetry.sendError(TelemetryErrorEventNames.FAILED_TO_RUN_FLUX_CHECK);
Expand Down Expand Up @@ -137,7 +138,7 @@ class FluxTools {
async install(context: string) {
let contextArg = '';
if (context) {
contextArg = `--context=${context}`;
contextArg = safesh`--context=${context}`;
}
const installShellResult = await shell.execWithOutput(`flux install ${contextArg}`);
if (installShellResult.code !== 0) {
Expand All @@ -154,7 +155,7 @@ class FluxTools {
async uninstall(context = '') {
let contextArg = '';
if (context) {
contextArg = `--context=${context}`;
contextArg = safesh`--context=${context}`;
}
const uninstallShellResult = await shell.execWithOutput(`flux uninstall --silent ${contextArg}`);
if (uninstallShellResult.code !== 0) {
Expand Down
16 changes: 16 additions & 0 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ suite('Extension Test Suite', () => {
assert.strictEqual(source, undefined, 'Removing a GitSource and refreshing all views should unlist it');
});

test('OCI Sources are listed', async function() {
this.timeout(15000);

await api.shell.execWithOutput('flux create source oci podinfo --url=oci://ghcr.io/kingdonb/podinfo/deploy --tag-semver 6.1.x');
await vscode.commands.executeCommand('gitops.views.refreshSourceTreeView');

let source = await getTreeItem(api.data.sourceTreeViewProvider, 'OCIRepository: podinfo');
assert.notStrictEqual(source, undefined, 'Adding a OCI Source and refreshing the view should list it');

await api.shell.execWithOutput('flux delete source oci podinfo -s');
await vscode.commands.executeCommand('gitops.views.refreshAllTreeViews'); // refresh all'

source = await getTreeItem(api.data.sourceTreeViewProvider, 'OCIRepository: podinfo');
assert.strictEqual(source, undefined, 'Removing an OCI Source and refreshing all views should unlist it');
});

test('Kustomizations are listed', async function() {
this.timeout(10000);

Expand Down

0 comments on commit 910c9c8

Please sign in to comment.