Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isInstance for each Kubernetes resource type #582

Merged
merged 3 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

- Enable configuring `ResourceOptions` via `transformations` (https://github.com/pulumi/pulumi-kubernetes/pull/575).
- Changing k8s cluster config now correctly causes dependent resources to be replaced (https://github.com/pulumi/pulumi-kubernetes/pull/577).
- Add user-defined type guard `isInstance` to all Kubernetes `CustomResource` implementations (https://github.com/pulumi/pulumi-kubernetes/pull/582).

### Bug fixes

Expand Down
8 changes: 2 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/Azure/go-autorest v12.0.0+incompatible // indirect
github.com/ahmetb/go-linq v3.0.0+incompatible
github.com/cbroglie/mustache v1.0.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/evanphx/json-patch v4.1.0+incompatible
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/protobuf v1.3.1
Expand All @@ -19,13 +18,11 @@ require (
github.com/jinzhu/copier v0.0.0-20180308034124-7e38e58719c3
github.com/json-iterator/go v1.1.6 // indirect
github.com/mitchellh/go-wordwrap v1.0.0
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.8.0
github.com/pulumi/pulumi v0.17.8-0.20190417182502-bea1bea93fc1
github.com/pkg/errors v0.8.1
github.com/pulumi/pulumi v0.17.15
github.com/stretchr/testify v1.2.2
github.com/yudai/gojsondiff v1.0.0
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
google.golang.org/grpc v1.20.1
k8s.io/api v0.0.0-20190313235455-40a48860b5ab
k8s.io/apimachinery v0.0.0-20190313205120-d7deff9243b1
Expand All @@ -35,7 +32,6 @@ require (
k8s.io/kubernetes v1.14.1
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7 // indirect
sigs.k8s.io/kustomize v1.0.11 // indirect
sigs.k8s.io/yaml v1.1.0 // indirect
)

replace (
Expand Down
418 changes: 418 additions & 0 deletions go.sum

Large diffs are not rendered by default.

19 changes: 17 additions & 2 deletions pkg/gen/nodejs-templates/kind.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ import { getVersion } from "../../version";
return new {{Kind}}(name, undefined, { ...opts, id: id });
}

/** @internal */
private static readonly __pulumiType = "kubernetes:{{URNAPIVersion}}:{{Kind}}";

/**
* Returns true if the given object is an instance of {{Kind}}. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
public static isInstance(obj: any): obj is {{Kind}} {
if (obj === undefined || obj === null) {
return false;
}

return obj["__pulumiType"] === {{Kind}}.__pulumiType;
}

/**
* Create a {{Group}}.{{Version}}.{{Kind}} resource with the given unique name, arguments, and options.
*
Expand All @@ -41,14 +56,14 @@ import { getVersion } from "../../version";
{{#Properties}}
inputs["{{Name}}"] = {{{DefaultValue}}};
{{/Properties}}

if (!opts) {
opts = {};
}

if (!opts.version) {
opts.version = getVersion();
}
super("kubernetes:{{URNAPIVersion}}:{{Kind}}", name, inputs, opts);
super({{Kind}}.__pulumiType, name, inputs, opts);
}
}
4 changes: 2 additions & 2 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (k *kubeProvider) DiffConfig(ctx context.Context, req *pulumirpc.DiffReques
}

// Configure configures the resource provider with "globals" that control its behavior.
func (k *kubeProvider) Configure(_ context.Context, req *pulumirpc.ConfigureRequest) (*pbempty.Empty, error) {
func (k *kubeProvider) Configure(_ context.Context, req *pulumirpc.ConfigureRequest) (*pulumirpc.ConfigureResponse, error) {
vars := req.GetVariables()

//
Expand Down Expand Up @@ -256,7 +256,7 @@ func (k *kubeProvider) Configure(_ context.Context, req *pulumirpc.ConfigureRequ
}
k.clientSet = cs

return &pbempty.Empty{}, nil
return &pulumirpc.ConfigureResponse{}, nil
}

// Invoke dynamically executes a built-in function in the provider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ import { getVersion } from "../../version";
return new MutatingWebhookConfiguration(name, undefined, { ...opts, id: id });
}

/** @internal */
private static readonly __pulumiType = "kubernetes:admissionregistration.k8s.io/v1beta1:MutatingWebhookConfiguration";

/**
* Returns true if the given object is an instance of MutatingWebhookConfiguration. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
public static isInstance(obj: any): obj is MutatingWebhookConfiguration {
if (obj === undefined || obj === null) {
return false;
}

return obj["__pulumiType"] === MutatingWebhookConfiguration.__pulumiType;
}

/**
* Create a admissionregistration.v1beta1.MutatingWebhookConfiguration resource with the given unique name, arguments, and options.
*
Expand All @@ -67,14 +82,14 @@ import { getVersion } from "../../version";
inputs["kind"] = "MutatingWebhookConfiguration";
inputs["metadata"] = args && args.metadata || undefined;
inputs["webhooks"] = args && args.webhooks || undefined;

if (!opts) {
opts = {};
}

if (!opts.version) {
opts.version = getVersion();
}
super("kubernetes:admissionregistration.k8s.io/v1beta1:MutatingWebhookConfiguration", name, inputs, opts);
super(MutatingWebhookConfiguration.__pulumiType, name, inputs, opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ import { getVersion } from "../../version";
return new MutatingWebhookConfigurationList(name, undefined, { ...opts, id: id });
}

/** @internal */
private static readonly __pulumiType = "kubernetes:admissionregistration.k8s.io/v1beta1:MutatingWebhookConfigurationList";

/**
* Returns true if the given object is an instance of MutatingWebhookConfigurationList. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
public static isInstance(obj: any): obj is MutatingWebhookConfigurationList {
if (obj === undefined || obj === null) {
return false;
}

return obj["__pulumiType"] === MutatingWebhookConfigurationList.__pulumiType;
}

/**
* Create a admissionregistration.v1beta1.MutatingWebhookConfigurationList resource with the given unique name, arguments, and options.
*
Expand All @@ -66,14 +81,14 @@ import { getVersion } from "../../version";
inputs["items"] = args && args.items || undefined;
inputs["kind"] = "MutatingWebhookConfigurationList";
inputs["metadata"] = args && args.metadata || undefined;

if (!opts) {
opts = {};
}

if (!opts.version) {
opts.version = getVersion();
}
super("kubernetes:admissionregistration.k8s.io/v1beta1:MutatingWebhookConfigurationList", name, inputs, opts);
super(MutatingWebhookConfigurationList.__pulumiType, name, inputs, opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ import { getVersion } from "../../version";
return new ValidatingWebhookConfiguration(name, undefined, { ...opts, id: id });
}

/** @internal */
private static readonly __pulumiType = "kubernetes:admissionregistration.k8s.io/v1beta1:ValidatingWebhookConfiguration";

/**
* Returns true if the given object is an instance of ValidatingWebhookConfiguration. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
public static isInstance(obj: any): obj is ValidatingWebhookConfiguration {
if (obj === undefined || obj === null) {
return false;
}

return obj["__pulumiType"] === ValidatingWebhookConfiguration.__pulumiType;
}

/**
* Create a admissionregistration.v1beta1.ValidatingWebhookConfiguration resource with the given unique name, arguments, and options.
*
Expand All @@ -67,14 +82,14 @@ import { getVersion } from "../../version";
inputs["kind"] = "ValidatingWebhookConfiguration";
inputs["metadata"] = args && args.metadata || undefined;
inputs["webhooks"] = args && args.webhooks || undefined;

if (!opts) {
opts = {};
}

if (!opts.version) {
opts.version = getVersion();
}
super("kubernetes:admissionregistration.k8s.io/v1beta1:ValidatingWebhookConfiguration", name, inputs, opts);
super(ValidatingWebhookConfiguration.__pulumiType, name, inputs, opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ import { getVersion } from "../../version";
return new ValidatingWebhookConfigurationList(name, undefined, { ...opts, id: id });
}

/** @internal */
private static readonly __pulumiType = "kubernetes:admissionregistration.k8s.io/v1beta1:ValidatingWebhookConfigurationList";

/**
* Returns true if the given object is an instance of ValidatingWebhookConfigurationList. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
public static isInstance(obj: any): obj is ValidatingWebhookConfigurationList {
if (obj === undefined || obj === null) {
return false;
}

return obj["__pulumiType"] === ValidatingWebhookConfigurationList.__pulumiType;
}

/**
* Create a admissionregistration.v1beta1.ValidatingWebhookConfigurationList resource with the given unique name, arguments, and options.
*
Expand All @@ -66,14 +81,14 @@ import { getVersion } from "../../version";
inputs["items"] = args && args.items || undefined;
inputs["kind"] = "ValidatingWebhookConfigurationList";
inputs["metadata"] = args && args.metadata || undefined;

if (!opts) {
opts = {};
}

if (!opts.version) {
opts.version = getVersion();
}
super("kubernetes:admissionregistration.k8s.io/v1beta1:ValidatingWebhookConfigurationList", name, inputs, opts);
super(ValidatingWebhookConfigurationList.__pulumiType, name, inputs, opts);
}
}
19 changes: 17 additions & 2 deletions sdk/nodejs/apiextensions/v1beta1/CustomResourceDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ import { getVersion } from "../../version";
return new CustomResourceDefinition(name, undefined, { ...opts, id: id });
}

/** @internal */
private static readonly __pulumiType = "kubernetes:apiextensions.k8s.io/v1beta1:CustomResourceDefinition";

/**
* Returns true if the given object is an instance of CustomResourceDefinition. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
public static isInstance(obj: any): obj is CustomResourceDefinition {
if (obj === undefined || obj === null) {
return false;
}

return obj["__pulumiType"] === CustomResourceDefinition.__pulumiType;
}

/**
* Create a apiextensions.v1beta1.CustomResourceDefinition resource with the given unique name, arguments, and options.
*
Expand All @@ -70,14 +85,14 @@ import { getVersion } from "../../version";
inputs["metadata"] = args && args.metadata || undefined;
inputs["spec"] = args && args.spec || undefined;
inputs["status"] = args && args.status || undefined;

if (!opts) {
opts = {};
}

if (!opts.version) {
opts.version = getVersion();
}
super("kubernetes:apiextensions.k8s.io/v1beta1:CustomResourceDefinition", name, inputs, opts);
super(CustomResourceDefinition.__pulumiType, name, inputs, opts);
}
}
19 changes: 17 additions & 2 deletions sdk/nodejs/apiextensions/v1beta1/CustomResourceDefinitionList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ import { getVersion } from "../../version";
return new CustomResourceDefinitionList(name, undefined, { ...opts, id: id });
}

/** @internal */
private static readonly __pulumiType = "kubernetes:apiextensions.k8s.io/v1beta1:CustomResourceDefinitionList";

/**
* Returns true if the given object is an instance of CustomResourceDefinitionList. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
public static isInstance(obj: any): obj is CustomResourceDefinitionList {
if (obj === undefined || obj === null) {
return false;
}

return obj["__pulumiType"] === CustomResourceDefinitionList.__pulumiType;
}

/**
* Create a apiextensions.v1beta1.CustomResourceDefinitionList resource with the given unique name, arguments, and options.
*
Expand All @@ -63,14 +78,14 @@ import { getVersion } from "../../version";
inputs["items"] = args && args.items || undefined;
inputs["kind"] = "CustomResourceDefinitionList";
inputs["metadata"] = args && args.metadata || undefined;

if (!opts) {
opts = {};
}

if (!opts.version) {
opts.version = getVersion();
}
super("kubernetes:apiextensions.k8s.io/v1beta1:CustomResourceDefinitionList", name, inputs, opts);
super(CustomResourceDefinitionList.__pulumiType, name, inputs, opts);
}
}
19 changes: 17 additions & 2 deletions sdk/nodejs/apiregistration/v1/APIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ import { getVersion } from "../../version";
return new APIService(name, undefined, { ...opts, id: id });
}

/** @internal */
private static readonly __pulumiType = "kubernetes:apiregistration/v1:APIService";

/**
* Returns true if the given object is an instance of APIService. This is designed to work even
* when multiple copies of the Pulumi SDK have been loaded into the same process.
*/
public static isInstance(obj: any): obj is APIService {
if (obj === undefined || obj === null) {
return false;
}

return obj["__pulumiType"] === APIService.__pulumiType;
}

/**
* Create a apiregistration.v1.APIService resource with the given unique name, arguments, and options.
*
Expand All @@ -69,14 +84,14 @@ import { getVersion } from "../../version";
inputs["metadata"] = args && args.metadata || undefined;
inputs["spec"] = args && args.spec || undefined;
inputs["status"] = args && args.status || undefined;

if (!opts) {
opts = {};
}

if (!opts.version) {
opts.version = getVersion();
}
super("kubernetes:apiregistration/v1:APIService", name, inputs, opts);
super(APIService.__pulumiType, name, inputs, opts);
}
}
Loading