proud-spoon-58287
08/07/2020, 9:04 AMexport class KsqlDbCluster {
private readonly _clusterName: string
constructor(clusterName: string) {
this._clusterName = clusterName
}
private readonly _k8nCluster: gcp.container.Cluster = this.buildCluster(this._clusterName)
I am invoking this class this way
const ksqlDbClusterName = 'ksqldb-cluster'
const ksqlDbCluster = new KsqlDbCluster(ksqlDbClusterName)
Why in the world this._clusterName
is undefined?new
does not invoke the constructor?broad-dog-22463
08/07/2020, 9:09 AMimport * as gcp from "@pulumi/gcp";
import * as pulumi from "@pulumi/pulumi";
export class NginxWebserver {
public readonly instance: gcp.compute.Instance;
public readonly instanceAddress: pulumi.Output<string>;
constructor(name: string, machineType: string, imageName: string, network: gcp.compute.Network) {
//virtual machine running nginx via a [startup script](<https://cloud.google.com/compute/docs/startupscript>)
const script =
`#!/bin/bash
apt -y update
apt -y install nginx`;
const address = new gcp.compute.Address(`${name}`);
this.instance = new gcp.compute.Instance(`${name}`, {
machineType: `${machineType}`,
bootDisk: {
initializeParams: {
image: `${imageName}`,
},
},
networkInterfaces: [{
network: network.id,
accessConfigs: [{
natIp: address.address
}]
}],
metadataStartupScript: script,
});
this.instanceAddress = address.address;
}
}
Notice that the resources are built inside the constructorproud-spoon-58287
08/07/2020, 9:14 AMprivate readonly _clusterName: string
constructor(clusterName: string) {
console.log("CONSTRUCTOR:" + clusterName)
this._clusterName = clusterName
}
broad-dog-22463
08/07/2020, 9:16 AMproud-spoon-58287
08/07/2020, 9:19 AMbroad-dog-22463
08/07/2020, 9:33 AMproud-spoon-58287
08/07/2020, 10:07 AMOnce you have confirmed the status of the interrupted operations, you can repair your stack
using 'pulumi stack export' to export your stack to a file. For each operation that succeeded,
remove that operation from the "pending_operations" section of the file. Once this is complete,
use 'pulumi stack import' to import the repaired stack.
refusing to proceed
broad-dog-22463
08/07/2020, 10:10 AMproud-spoon-58287
08/07/2020, 10:12 AMlimited-rainbow-51650
08/07/2020, 12:02 PM_k8nCluster
is initialized before the constructor is executed. This StackOverflow answer defines the complete order: https://stackoverflow.com/a/53706727proud-spoon-58287
08/07/2020, 1:06 PMclever-sunset-76585
08/07/2020, 1:09 PMpublic Class KsqlDbCluster {
private final String clusterName;
// This is not legal in Java either regardless of where you position this.
private final String k8sCluster = this.buildCluster(this.clusterName);
public KSqlDbCluster(String clusterName) {
this.clusterName = clusterName;
// This is fine. But at this point, do you want the class member clusterName at all? :)
this.k8sCluster = this.buildCluster(this.clusterName);
}
}