Skip to content

Commit

Permalink
various bits of cleanup (pulumi#1259)
Browse files Browse the repository at this point in the history
* various bits of cleanup

* linting errors

* lint errors
  • Loading branch information
MitchellGerdisch committed Aug 10, 2022
1 parent 5c1dd82 commit e5da914
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 46 deletions.
2 changes: 1 addition & 1 deletion azure-ts-aks-helm/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as tls from "@pulumi/tls";

const config = new pulumi.Config();

export const k8sVersion = config.get("k8sVersion") || "1.19.11";
export const k8sVersion = config.get("k8sVersion") || "1.24.0";

export const password = config.get("password") || new random.RandomPassword("pw", {
length: 20,
Expand Down
11 changes: 6 additions & 5 deletions azure-ts-aks-helm/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
import * as pulumi from "@pulumi/pulumi";

import * as k8s from "@pulumi/kubernetes";

import * as cluster from "./cluster";

export let clusterName = cluster.k8sCluster.name;

export let kubeconfig = cluster.kubeconfig;
export let kubeconfig = pulumi.secret(cluster.kubeconfig);

const apache = new k8s.helm.v3.Chart(
"apache-chart",
{
chart: "apache",
version: "8.3.2",
version: "9.1.17",
fetchOpts: {
repo: "https://charts.bitnami.com/bitnami",
},
},
{ provider: cluster.k8sProvider },
);

export let apacheServiceIP = apache
.getResourceProperty("v1/Service", "apache-chart", "status")
.apply(status => status.loadBalancer.ingress[0].ip);
export let apacheServiceIP = cluster.kubeconfig.apply(kubeconfig => apache
.getResourceProperty("v1/Service", "default", "apache-chart", "status")
.apply(status => status.loadBalancer.ingress[0].ip));
2 changes: 1 addition & 1 deletion azure-ts-aks-helm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"@pulumi/kubernetes": "^3.0.0",
"@pulumi/pulumi": "^3.0.0",
"@pulumi/random": "^4.0.0",
"@pulumi/tls": "^3.4.0"
"@pulumi/tls": "^4.0.0"
}
}
12 changes: 2 additions & 10 deletions azure-ts-aks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@ const adSp = new azuread.ServicePrincipal("aksSp", {
applicationId: adApp.applicationId,
});

// Generate random password
const password = new random.RandomPassword("password", {
length: 20,
special: true,
});

// Create the Service Principal Password
const adSpPassword = new azuread.ServicePrincipalPassword("aksSpPassword", {
servicePrincipalId: adSp.id,
value: password.result,
endDate: "2099-01-01T00:00:00Z",
});

Expand All @@ -37,7 +30,6 @@ const sshKey = new tls.PrivateKey("ssh-key", {
rsaBits: 4096,
});


const config = new pulumi.Config();
const managedClusterName = config.get("managedClusterName") || "azure-aks";
const cluster = new containerservice.ManagedCluster(managedClusterName, {
Expand All @@ -55,7 +47,7 @@ const cluster = new containerservice.ManagedCluster(managedClusterName, {
}],
dnsPrefix: resourceGroup.name,
enableRBAC: true,
kubernetesVersion: "1.18.14",
kubernetesVersion: "1.24.0",
linuxProfile: {
adminUsername: "testuser",
ssh: {
Expand All @@ -77,4 +69,4 @@ const creds = containerservice.listManagedClusterUserCredentialsOutput({
});

const encoded = creds.kubeconfigs[0].value;
export const kubeconfig = encoded.apply(enc => Buffer.from(enc, "base64").toString());
export const kubeconfig = pulumi.secret(encoded.apply(enc => Buffer.from(enc, "base64").toString()));
2 changes: 1 addition & 1 deletion azure-ts-aks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"@pulumi/azuread": "^4.0.0",
"@pulumi/pulumi": "^3.0.0",
"@pulumi/random": "^4.0.0",
"@pulumi/tls": "^3.4.0"
"@pulumi/tls": "^4.0.0"
}
}
2 changes: 0 additions & 2 deletions classic-azure-ts-aks-helm/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const adApp = new azuread.Application("aks", {
const adSp = new azuread.ServicePrincipal("aksSp", { applicationId: adApp.applicationId });
const adSpPassword = new azuread.ServicePrincipalPassword("aksSpPassword", {
servicePrincipalId: adSp.id,
value: config.password,
endDate: "2099-01-01T00:00:00Z",
});

// Now allocate an AKS cluster.
Expand Down
10 changes: 6 additions & 4 deletions classic-azure-ts-aks-helm/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.

import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
import { k8sCluster, k8sProvider } from "./cluster";

const apache = new k8s.helm.v3.Chart(
"apache",
{
repo: "bitnami",
chart: "apache",
version: "8.3.2",
version: "9.1.17",
fetchOpts: {
repo: "https://charts.bitnami.com/bitnami",
},
Expand All @@ -18,6 +19,7 @@ const apache = new k8s.helm.v3.Chart(

export let cluster = k8sCluster.name;
export let kubeConfig = k8sCluster.kubeConfigRaw;
export let serviceIP = apache
.getResourceProperty("v1/Service", "apache", "status")
.apply(status => status.loadBalancer.ingress[0].ip);
// Wait for the cluster to be ready before trying to get the IP info.
export let serviceIP = pulumi.unsecret(k8sCluster.kubeConfigRaw.apply(kubeconfig => apache
.getResourceProperty("v1/Service", "default", "apache", "status")
.apply(status => status.loadBalancer.ingress[0].ip)));
2 changes: 1 addition & 1 deletion classic-azure-ts-aks-mean/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ npm install

---outputs:---
cluster : "aksclusterbfb9388b"
frontendAddress: "40.76.25.71"
kubeconfig : "[secret]"

info: 12 changes performed:
+ 12 resources created
Expand Down
2 changes: 0 additions & 2 deletions classic-azure-ts-aks-mean/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const adApp = new azuread.Application("aks", {displayName: "aks"});
const adSp = new azuread.ServicePrincipal("aksSp", { applicationId: adApp.applicationId });
const adSpPassword = new azuread.ServicePrincipalPassword("aksSpPassword", {
servicePrincipalId: adSp.id,
value: config.password,
endDate: "2099-01-01T00:00:00Z",
});

// Now allocate an AKS cluster.
Expand Down
9 changes: 3 additions & 6 deletions classic-azure-ts-aks-mean/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const cosmosdb = new azure.cosmosdb.Account("cosmosDb", {
resourceGroupName: config.resourceGroup.name,
consistencyPolicy: {
consistencyLevel: "BoundedStaleness",
maxIntervalInSeconds: 10,
maxStalenessPrefix: 200,
maxIntervalInSeconds: 300,
maxStalenessPrefix: 100000,
},
offerType: "Standard",
enableAutomaticFailover: true,
Expand All @@ -40,7 +40,7 @@ const node = new k8s.helm.v3.Chart(
"node",
{
chart: "node",
version: "4.0.1",
version: "19.0.2",
fetchOpts: {
repo: "https://charts.bitnami.com/bitnami",
},
Expand All @@ -57,6 +57,3 @@ const node = new k8s.helm.v3.Chart(
// be accessed from the CLI, like: `pulumi stack output kubeconfig --show-secrets > kubeconfig.yaml`.
export const kubeconfig = k8sCluster.kubeConfigRaw;
export const cluster = k8sCluster.name;
export const frontendAddress = node
.getResourceProperty("v1/Service", "node-node", "status")
.apply(status => status.loadBalancer.ingress[0].ip);
9 changes: 6 additions & 3 deletions classic-azure-ts-aks-mean/mongoHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,22 @@ export function parseConnString(
return Buffer.from(s).toString("base64");
}

return conns.apply(conns => {
const conn = conns[0];
const retVal: pulumi.Output<{ [key: string]: string }> = conns.apply(conns => {

const conn = conns[0] ?? "mongodb:https://username:password@host:port/[database]?ssl=true";
const noProtocol = conn.replace(/^mongodb\:\/\//, "");
const [username, rest1, rest2] = noProtocol.split(":", 3);
const [password, host] = rest1.split("@", 2);
const [port, rest3] = rest2.split("/", 2);
const database = rest3.replace(/\?ssl=true$/, "");
return {
const connector: { [key: string]: string } = {
host: toBase64(host),
port: toBase64(port),
username: toBase64(username),
password: toBase64(encodeURIComponent(password)),
database: toBase64(database === "" ? "test" : database),
};
return connector;
});
return retVal;
}
4 changes: 2 additions & 2 deletions kubernetes-ts-helm-wordpress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ View Live: https://app.pulumi.com/example/wordpress/ts-helm-wordpress/updates/7
+ └─ kubernetes:apps:Deployment wpdev-wordpress created

Outputs:
frontendIp: "35.193.210.254"
wordpressIP: "35.193.210.254"

Resources:
+ 10 created
Expand Down Expand Up @@ -108,7 +108,7 @@ View Live: https://app.pulumi.com/example/wordpress/ts-helm-wordpress/updates/8
- └─ kubernetes:apps:Deployment wpdev-wordpress deleted

Outputs:
- frontendIp: "35.193.210.254"
- wordpressIP: "35.193.210.254"

Resources:
- 10 deleted
Expand Down
13 changes: 5 additions & 8 deletions kubernetes-ts-helm-wordpress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import * as k8s from "@pulumi/kubernetes";

// Deploy the bitnami/wordpress chart.
const wordpress = new k8s.helm.v3.Chart("wpdev", {
version: "9.6.0",
version: "15.0.5",
chart: "wordpress",
fetchOpts: {
repo: "https://charts.bitnami.com/bitnami",
},
});

// Get the status field from the wordpress service, and then grab a reference to the ingress field.
const frontend = wordpress.getResourceProperty("v1/Service", "wpdev-wordpress", "status");
const ingress = frontend.loadBalancer.ingress[0];

// Export the public IP for Wordpress.
// Depending on the k8s cluster, this value may be an IP address or a hostname.
export const frontendIp = ingress.apply(x => x.ip ?? x.hostname);
// Get the IP address once the chart is deployed and ready.
export let wordpressIP = wordpress.ready.apply(ready => wordpress
.getResourceProperty("v1/Service", "default", "wpdev-wordpress", "status")
.apply(status => status.loadBalancer.ingress[0].ip));

0 comments on commit e5da914

Please sign in to comment.