Skip to content

Commit

Permalink
Feature upgrade to adapt ASO v2 (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatsinnit authored Apr 19, 2022
1 parent f58e9f5 commit 9e1b68e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 45 deletions.
4 changes: 2 additions & 2 deletions resources/yaml/azureoperatorsettings.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: azureoperatorsettings
namespace: operators
name: aso-controller-settings
namespace: azureserviceoperator-system
stringData:
AZURE_TENANT_ID: <TENANT_ID>
AZURE_SUBSCRIPTION_ID: <SUB_ID>
Expand Down
39 changes: 11 additions & 28 deletions src/commands/azureServiceOperators/helpers/azureservicehelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,12 @@ export async function startInstallation(
return undefined;
}

// 1) Install OLM is the pre-requisite of this work, using the apply YAML instructions here: https://github.com/operator-framework/operator-lifecycle-manager/releases/.
// 1) Install Cert-Manager https://azure.github.io/azure-service-operator/.
// Also, page to refer: https://operatorhub.io/operator/azure-service-operator (Click Install button as top of the page)
installationResponse.installOlmCrdResult = await longRunning(`Installing Operator Lifecycle Manager CRD resource...`,
() => installOlmCrd(kubectl, clusterKubeConfig.result)
installationResponse.installCertManagerResult = await longRunning(`Installing Cert-Manager resource...`,
() => installCertManager(kubectl, clusterKubeConfig.result)
);
if (!isInstallationSuccessfull(webview, extensionPath, installationResponse.installOlmCrdResult, installationResponse)) return undefined;

installationResponse.installOlmResult = await longRunning(`Installing Operator Lifecycle Manager resource...`,
() => installOlm(kubectl, clusterKubeConfig.result)
);
if (!isInstallationSuccessfull(webview, extensionPath, installationResponse.installOlmResult, installationResponse)) return undefined;
if (!isInstallationSuccessfull(webview, extensionPath, installationResponse.installCertManagerResult, installationResponse)) return undefined;

installationResponse.installOperatorResult = await longRunning(`Installing Opreator Namespace...`,
() => installOperator(kubectl, clusterKubeConfig.result)
Expand All @@ -50,7 +45,7 @@ export async function startInstallation(
);
if (!isInstallationSuccessfull(webview, extensionPath, installationResponse.installOperatorSettingsResult, installationResponse)) return undefined;

// 3) Final step: Get the azure service operator pod. - kubectl get pods -n operators
// 3) Final step: Get the azure service operator pod. - kubectl get pods -n azureserviceoperator-system
installationResponse.getOperatorsPodResult = await longRunning(`Getting Azure Service Operator Pod...`,
() => getOperatorsPod(kubectl, clusterKubeConfig.result)
);
Expand All @@ -64,47 +59,35 @@ async function getOperatorsPod(
clusterKubeConfig: string
): Promise<k8s.KubectlV1.ShellResult | undefined> {
// kubectl get pods -n operators
const command = `get pods -n operators`;
const failureDescription = "Get operator pod had following error";
const command = `get pods -n azureserviceoperator-system`;
const failureDescription = "Get azureserviceoperator-system pod had following error";

const result = await invokeKubectlCommand(kubectl, clusterKubeConfig, command, failureDescription);
return result;
}

async function installOlmCrd(
async function installCertManager(
kubectl: k8s.KubectlV1,
clusterKubeConfig: string
): Promise<k8s.KubectlV1.ShellResult | undefined> {
try {
const asoCrdYamlFile = "https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.18.3/crds.yaml";
const asoCrdYamlFile = "https://github.com/jetstack/cert-manager/releases/download/v1.7.1/cert-manager.yaml";
const runResult = await tmpfile.withOptionalTempFile<k8s.KubectlV1.ShellResult | undefined>(
clusterKubeConfig, "yaml",
(f) => kubectl.invokeCommand(`create -f ${asoCrdYamlFile} --kubeconfig="${f}"`));

return runResult;
} catch (e) {
vscode.window.showErrorMessage(`Installing operator lifecycle manager CRD resource had following error: ${e}`);
vscode.window.showErrorMessage(`Installing cert-manager resource had following error: ${e}`);
return undefined;
}
}

async function installOlm(
kubectl: k8s.KubectlV1,
clusterKubeConfig: string
): Promise<k8s.KubectlV1.ShellResult | undefined> {
const asoOlmYamlFile = "https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.18.3/olm.yaml";
const command = `create -f ${asoOlmYamlFile}`;
const failureDescription = "Installing operator lifecycle manager resource had following error";

const result = await invokeKubectlCommand(kubectl, clusterKubeConfig, command, failureDescription);
return result;
}

async function installOperator(
kubectl: k8s.KubectlV1,
clusterKubeConfig: string
): Promise<k8s.KubectlV1.ShellResult | undefined> {
const asoYamlFile = "https://operatorhub.io/install/azure-service-operator.yaml";
const asoYamlFile = "https://github.com/Azure/azure-service-operator/releases/download/v2.0.0-beta.0/azureserviceoperator_v2.0.0-beta.0.yaml";
const command = `create -f ${asoYamlFile}`;
const failureDescription = "Installing operator resoruce had following error";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ function getOrganisedInstallResult(
installationResponse: InstallationResponse
) {
const installResults: InstallResult = {};
const olmCrdResult = installationResponse.installOlmCrdResult;
const olmResult = installationResponse.installOlmResult;
const certManagerResult = installationResponse.installCertManagerResult;
const operatorResult = installationResponse.installOperatorSettingsResult;
const operatorSettingsResult = installationResponse.installOperatorResult;
const getOperatorsPodResult = installationResponse.getOperatorsPodResult;

const installResultCollection = [olmCrdResult, olmResult, operatorResult, operatorSettingsResult, getOperatorsPodResult];
const installResultCollection = [certManagerResult, operatorResult, operatorSettingsResult, getOperatorsPodResult];
installResults.succeeded = installationExitCodeResponse(installResultCollection);

if (installResults.succeeded) {
Expand All @@ -81,11 +80,10 @@ function installationLogsResponse(
const logs: LogSection[] = [];

const logsTitle: { [order: number]: string } = {
0: "Install Operator Lifecycle CRD Output",
1: "Install Operator Lifecycle Output",
2: "Install Operator Output",
3: "Setting Apply Operator Output",
4: "Operator pod output",
0: "Install Cert Manager Output",
1: "Install Operator Output",
2: "Setting Apply Operator Output",
3: "Operator pod output",
};

installShellResult.filter(Boolean).forEach((sr, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function install(
vscode.window.showErrorMessage(extensionPath.error);
return undefined;
}

// Create webview with user input required.
createASOWebView(webview, extensionPath.result, installationResponse, true);

Expand Down
9 changes: 3 additions & 6 deletions src/commands/azureServiceOperators/ui/azureservicebrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function getAPIResourceCommandResult(): Promise<Errorable<AzureServiceKind
if (!kubectl.available) {
return { succeeded: false, error: `Kubectl is unavailable.` };
}
const asoAPIResourceCommandResult = await kubectl.api.invokeCommand("api-resources --api-group azure.microsoft.com --no-headers");
const asoAPIResourceCommandResult = await kubectl.api.invokeCommand("get crds -o='custom-columns=Name:.metadata.name' | grep azure.com");

if (!asoAPIResourceCommandResult) { // Fail to invoke command.
return { succeeded: false, error: `Azure Service Operator api-resources failed to invoke command.` };
Expand All @@ -54,13 +54,10 @@ async function getAPIResourceCommandResult(): Promise<Errorable<AzureServiceKind
}

function parseServiceResource(apiResourceLineItem: string): AzureServiceKind | undefined {
const apiResource = apiResourceLineItem.split(' ').filter((s) => s.length > 0);
const apiResource = apiResourceLineItem.split('.').filter((s) => s.length > 0);
if (apiResource.length === 4) {
// name, apigroup, namespaced, kind
return { displayName: apiResource[3], manifestKind: apiResource[3], abbreviation: apiResource[0] };
} else if (apiResource.length === 5) {
// name, shortnames, apigroup, namespaced, kind
return { displayName: apiResource[4], manifestKind: apiResource[4], abbreviation: apiResource[0] };
return { displayName: apiResource[0], manifestKind: apiResource[1], abbreviation: apiResource[0] };
} else {
vscode.window.showWarningMessage(`Invalid api-resource output from azure service operator.`);
return undefined;
Expand Down

0 comments on commit 9e1b68e

Please sign in to comment.