Skip to content

Commit

Permalink
Auto-alias resource apiVersions
Browse files Browse the repository at this point in the history
Kubernetes apiVersions are mostly forward/backward
compatible, so for cases where we know it's safe, we
auto-alias the apiVersions so that the engine does not
force a replacement when a resource is updated to a
compatible apiVersion.
  • Loading branch information
lblackstone committed Sep 24, 2019
1 parent 397e9d9 commit 105cefd
Show file tree
Hide file tree
Showing 375 changed files with 2,319 additions and 182 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Improvements

- Automatically mark Secret data and stringData as secret. (https://github.com/pulumi/pulumi-kubernetes/pull/803).
- Auto-alias resource apiVersions. (https://github.com/pulumi/pulumi-kubernetes/pull/798).
- Provide detailed error for removed apiVersions. (https://github.com/pulumi/pulumi-kubernetes/pull/809).

## 1.1.0 (September 18, 2019)
Expand Down
8 changes: 8 additions & 0 deletions pkg/gen/nodejs-templates/kind.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
{{#Aliases}}
{ parent: opts.parent, type: "{{.}}", name: name },
{{/Aliases}}
...((opts && opts.aliases) || []),
];

super({{Kind}}.__pulumiType, name, props, opts);
}
}
1 change: 1 addition & 0 deletions pkg/gen/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func NodeJSClient(swagger map[string]interface{}, templateDir string,
"RequiredInputProperties": kind.RequiredInputProperties(),
"OptionalInputProperties": kind.OptionalInputProperties(),
"AdditionalSecretOutputs": kind.AdditionalSecretOutputs(),
"Aliases": kind.Aliases(),
"URNAPIVersion": kind.URNAPIVersion(),
"Version": version.Version(),
"PulumiComment": kind.pulumiComment,
Expand Down
10 changes: 9 additions & 1 deletion pkg/gen/python-templates/kind.py.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ class {{Kind}}(pulumi.CustomResource):
opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(
version=version.get_version(), additional_secret_outputs=additional_secret_outputs))

opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(version=version.get_version()))
parent = opts.parent if opts and opts.parent else None
aliases = [
{{#Aliases}}
pulumi.Alias(parent=parent, type_="{{.}}", name=resource_name),
{{/Aliases}}
]

opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(
version=version.get_version(), aliases=aliases))

super({{Kind}}, self).__init__(
"kubernetes:{{URNAPIVersion}}:{{Kind}}",
Expand Down
55 changes: 55 additions & 0 deletions pkg/gen/typegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ type KindConfig struct {
requiredInputProperties []*Property
optionalInputProperties []*Property
additionalSecretOutputs []string
aliases []string

gvk *schema.GroupVersionKind // Used for sorting.
apiVersion string
Expand Down Expand Up @@ -173,6 +174,10 @@ func (kc *KindConfig) OptionalInputProperties() []*Property { return kc.optional
// Kubernetes API kind.
func (kc *KindConfig) AdditionalSecretOutputs() []string { return kc.additionalSecretOutputs }

// Aliases returns the list of aliases for a Kubernetes API kind.
func (kc *KindConfig) Aliases() []string { return kc.aliases }


// APIVersion returns the fully-qualified apiVersion (e.g., `storage.k8s.io/v1` for storage, etc.)
func (kc *KindConfig) APIVersion() string { return kc.apiVersion }

Expand Down Expand Up @@ -835,6 +840,7 @@ func createGroups(definitionsJSON map[string]interface{}, opts groupOpts) []*Gro
requiredInputProperties: requiredInputProperties,
optionalInputProperties: optionalInputProperties,
additionalSecretOutputs: additionalSecretOutputs(d.gvk),
aliases: aliasesForGVK(d.gvk),
gvk: &d.gvk,
apiVersion: fqGroupVersion,
rawAPIVersion: defaultGroupVersion,
Expand Down Expand Up @@ -918,3 +924,52 @@ func additionalSecretOutputs(gvk schema.GroupVersionKind) []string {
return []string{}
}
}

func aliasesForGVK(gvk schema.GroupVersionKind) []string {
kind := kinds.Kind(gvk.Kind)

// It's unsafe to move between `extensions/v1beta1`, and the newer apiVersions due to differences in
// the behavior of the Deployment and ReplicaSet. Even if the apiVersion is changed,
// the resource will continue to use the old behavior, which will break the await logic. Without an
// alias set, the engine will recreate the resource with the newer apiVersion.
if gvk.GroupVersion().String() == "extensions/v1beta1" {
switch kind {
case kinds.DaemonSet, kinds.Deployment, kinds.ReplicaSet, kinds.StatefulSet:
return []string{}
}
}

switch kind {
case kinds.DaemonSet:
return []string{
"kubernetes:apps/v1:DaemonSet",
// For some reason, there is no `apps/v1beta1:DaemonSet`.
"kubernetes:apps/v1beta2:DaemonSet",
}
case kinds.Deployment:
return []string{
"kubernetes:apps/v1:Deployment",
"kubernetes:apps/v1beta1:Deployment",
"kubernetes:apps/v1beta2:Deployment",
}
case kinds.Ingress:
return []string{
"kubernetes:networking/v1beta1:Ingress",
"kubernetes:extensions/v1beta1:Ingress",
}
case kinds.ReplicaSet:
return []string{
"kubernetes:apps/v1:ReplicaSet",
// For some reason, there is no `apps/v1beta1:ReplicaSet`.
"kubernetes:apps/v1beta2:ReplicaSet",
}
case kinds.StatefulSet:
return []string{
"kubernetes:apps/v1:StatefulSet",
"kubernetes:apps/v1beta1:StatefulSet",
"kubernetes:apps/v1beta2:StatefulSet",
}
default:
return []string{}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(MutatingWebhookConfiguration.__pulumiType, name, props, opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(MutatingWebhookConfigurationList.__pulumiType, name, props, opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(ValidatingWebhookConfiguration.__pulumiType, name, props, opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(ValidatingWebhookConfigurationList.__pulumiType, name, props, opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(MutatingWebhookConfiguration.__pulumiType, name, props, opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(MutatingWebhookConfigurationList.__pulumiType, name, props, opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(ValidatingWebhookConfiguration.__pulumiType, name, props, opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(ValidatingWebhookConfigurationList.__pulumiType, name, props, opts);
}
}
5 changes: 5 additions & 0 deletions sdk/nodejs/apiextensions/v1/CustomResourceDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(CustomResourceDefinition.__pulumiType, name, props, opts);
}
}
5 changes: 5 additions & 0 deletions sdk/nodejs/apiextensions/v1/CustomResourceDefinitionList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(CustomResourceDefinitionList.__pulumiType, name, props, opts);
}
}
5 changes: 5 additions & 0 deletions sdk/nodejs/apiextensions/v1beta1/CustomResourceDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(CustomResourceDefinition.__pulumiType, name, props, opts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(CustomResourceDefinitionList.__pulumiType, name, props, opts);
}
}
5 changes: 5 additions & 0 deletions sdk/nodejs/apiregistration/v1/APIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(APIService.__pulumiType, name, props, opts);
}
}
5 changes: 5 additions & 0 deletions sdk/nodejs/apiregistration/v1/APIServiceList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(APIServiceList.__pulumiType, name, props, opts);
}
}
5 changes: 5 additions & 0 deletions sdk/nodejs/apiregistration/v1beta1/APIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(APIService.__pulumiType, name, props, opts);
}
}
5 changes: 5 additions & 0 deletions sdk/nodejs/apiregistration/v1beta1/APIServiceList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(APIServiceList.__pulumiType, name, props, opts);
}
}
5 changes: 5 additions & 0 deletions sdk/nodejs/apps/v1/ControllerRevision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(ControllerRevision.__pulumiType, name, props, opts);
}
}
5 changes: 5 additions & 0 deletions sdk/nodejs/apps/v1/ControllerRevisionList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(ControllerRevisionList.__pulumiType, name, props, opts);
}
}
7 changes: 7 additions & 0 deletions sdk/nodejs/apps/v1/DaemonSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
{ parent: opts.parent, type: "kubernetes:apps/v1:DaemonSet", name: name },
{ parent: opts.parent, type: "kubernetes:apps/v1beta2:DaemonSet", name: name },
...((opts && opts.aliases) || []),
];

super(DaemonSet.__pulumiType, name, props, opts);
}
}
5 changes: 5 additions & 0 deletions sdk/nodejs/apps/v1/DaemonSetList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(DaemonSetList.__pulumiType, name, props, opts);
}
}
8 changes: 8 additions & 0 deletions sdk/nodejs/apps/v1/Deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
{ parent: opts.parent, type: "kubernetes:apps/v1:Deployment", name: name },
{ parent: opts.parent, type: "kubernetes:apps/v1beta1:Deployment", name: name },
{ parent: opts.parent, type: "kubernetes:apps/v1beta2:Deployment", name: name },
...((opts && opts.aliases) || []),
];

super(Deployment.__pulumiType, name, props, opts);
}
}
5 changes: 5 additions & 0 deletions sdk/nodejs/apps/v1/DeploymentList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ import { getVersion } from "../../version";
...((opts && opts.additionalSecretOutputs) || []),

];

opts.aliases = [
...((opts && opts.aliases) || []),
];

super(DeploymentList.__pulumiType, name, props, opts);
}
}
Loading

0 comments on commit 105cefd

Please sign in to comment.