Skip to content

Commit

Permalink
Refine criteria for top-level objects
Browse files Browse the repository at this point in the history
  • Loading branch information
hausdorff committed Jan 7, 2019
1 parent 604a3bf commit 7c2acbe
Show file tree
Hide file tree
Showing 32 changed files with 103 additions and 2,389 deletions.
48 changes: 40 additions & 8 deletions pkg/gen/typegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,41 @@ func makeType(prop map[string]interface{}, opts groupOpts) string {
}
}

func isTopLevel(d *definition) bool {
gvks, gvkExists :=
d.data["x-kubernetes-group-version-kind"].([]interface{})
hasGVK := gvkExists && len(gvks) > 0
if !hasGVK {
return false
}

// Return `false` for the handful of top-level imperative resource types that can't be managed
// by Pulumi.
switch fmt.Sprintf("%s/%s", d.gvk.GroupVersion().String(), d.gvk.Kind) {
case "policy/v1beta1/Eviction", "v1/Status", "apps/v1beta1/Scale", "apps/v1beta2/Scale",
"autoscaling/v1/Scale", "extensions/v1beta1/Scale":
return false
}

properties, hasProperties := d.data["properties"].(map[string]interface{})
if !hasProperties {
return false
}

meta, hasMetadata := properties["metadata"].(map[string]interface{})
if !hasMetadata {
return false
}

ref, hasRef := meta["$ref"]
if !hasRef {
return false
}

return ref == "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta" ||
ref == "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta"
}

// --------------------------------------------------------------------------

// Core grouping logic.
Expand Down Expand Up @@ -424,10 +459,8 @@ func createGroups(definitionsJSON map[string]interface{}, opts groupOpts) []*Gro
// `admissionregistration.k8s.io/v1alpha1` instead of `admissionregistration/v1alpha1`).
defaultGroupVersion := d.gvk.Group
var fqGroupVersion string
gvks, gvkExists :=
d.data["x-kubernetes-group-version-kind"].([]interface{})
isTopLevel := gvkExists && len(gvks) > 0
if isTopLevel {
isTopLevel := isTopLevel(d)
if gvks, gvkExists := d.data["x-kubernetes-group-version-kind"].([]interface{}); gvkExists && len(gvks) > 0 {
gvk := gvks[0].(map[string]interface{})
group := gvk["group"].(string)
version := gvk["version"].(string)
Expand Down Expand Up @@ -527,14 +560,13 @@ func createGroups(definitionsJSON map[string]interface{}, opts groupOpts) []*Gro
return linq.From([]*KindConfig{})
}

props := d.data["properties"].(map[string]interface{})
_, kindExists := props["kind"]
_, apiVersionExists := props["apiVersion"]
if opts.generatorType == provider && (!kindExists || !apiVersionExists) {
if opts.generatorType == provider && (!isTopLevel) {
return linq.From([]*KindConfig{})
}

var typeGuard string
props := d.data["properties"].(map[string]interface{})
_, apiVersionExists := props["apiVersion"]
if apiVersionExists {
typeGuard = fmt.Sprintf(`
export function is%s(o: any): o is %s {
Expand Down
1,643 changes: 15 additions & 1,628 deletions sdk/nodejs/provider.ts

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions sdk/nodejs/types/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2823,15 +2823,15 @@ export namespace apps {
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion?: pulumi.Input<"apps/v1beta1">
apiVersion?: pulumi.Input<string>

/**
* Kind is a string value representing the REST resource this object represents. Servers may
* infer this from the endpoint the client submits requests to. Cannot be updated. In
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind?: pulumi.Input<"DeploymentRollback">
kind?: pulumi.Input<string>

/**
* The annotations to be updated to a deployment
Expand Down Expand Up @@ -3043,15 +3043,15 @@ export namespace apps {
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion?: pulumi.Input<"apps/v1beta1">
apiVersion?: pulumi.Input<string>

/**
* Kind is a string value representing the REST resource this object represents. Servers may
* infer this from the endpoint the client submits requests to. Cannot be updated. In
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind?: pulumi.Input<"Scale">
kind?: pulumi.Input<string>

/**
* Standard object metadata; More info:
Expand Down Expand Up @@ -4218,15 +4218,15 @@ export namespace apps {
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion?: pulumi.Input<"apps/v1beta2">
apiVersion?: pulumi.Input<string>

/**
* Kind is a string value representing the REST resource this object represents. Servers may
* infer this from the endpoint the client submits requests to. Cannot be updated. In
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind?: pulumi.Input<"Scale">
kind?: pulumi.Input<string>

/**
* Standard object metadata; More info:
Expand Down Expand Up @@ -6059,15 +6059,15 @@ export namespace autoscaling {
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion?: pulumi.Input<"autoscaling/v1">
apiVersion?: pulumi.Input<string>

/**
* Kind is a string value representing the REST resource this object represents. Servers may
* infer this from the endpoint the client submits requests to. Cannot be updated. In
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind?: pulumi.Input<"Scale">
kind?: pulumi.Input<string>

/**
* Standard object metadata; More info:
Expand Down Expand Up @@ -15157,15 +15157,15 @@ export namespace extensions {
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion?: pulumi.Input<"extensions/v1beta1">
apiVersion?: pulumi.Input<string>

/**
* Kind is a string value representing the REST resource this object represents. Servers may
* infer this from the endpoint the client submits requests to. Cannot be updated. In
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind?: pulumi.Input<"DeploymentRollback">
kind?: pulumi.Input<string>

/**
* The annotations to be updated to a deployment
Expand Down Expand Up @@ -16401,15 +16401,15 @@ export namespace extensions {
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion?: pulumi.Input<"extensions/v1beta1">
apiVersion?: pulumi.Input<string>

/**
* Kind is a string value representing the REST resource this object represents. Servers may
* infer this from the endpoint the client submits requests to. Cannot be updated. In
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind?: pulumi.Input<"Scale">
kind?: pulumi.Input<string>

/**
* Standard object metadata; More info:
Expand Down Expand Up @@ -16523,15 +16523,15 @@ export namespace meta {
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion?: pulumi.Input<"v1">
apiVersion?: pulumi.Input<string>

/**
* Kind is a string value representing the REST resource this object represents. Servers may
* infer this from the endpoint the client submits requests to. Cannot be updated. In
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind?: pulumi.Input<"APIGroup">
kind?: pulumi.Input<string>

/**
* preferredVersion is the version preferred by the API server, which probably is the storage
Expand Down Expand Up @@ -16571,15 +16571,15 @@ export namespace meta {
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion?: pulumi.Input<"v1">
apiVersion?: pulumi.Input<string>

/**
* Kind is a string value representing the REST resource this object represents. Servers may
* infer this from the endpoint the client submits requests to. Cannot be updated. In
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind?: pulumi.Input<"APIGroupList">
kind?: pulumi.Input<string>

}

Expand Down Expand Up @@ -16666,15 +16666,15 @@ export namespace meta {
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion?: pulumi.Input<"v1">
apiVersion?: pulumi.Input<string>

/**
* Kind is a string value representing the REST resource this object represents. Servers may
* infer this from the endpoint the client submits requests to. Cannot be updated. In
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind?: pulumi.Input<"APIResourceList">
kind?: pulumi.Input<string>

}

Expand Down Expand Up @@ -16709,15 +16709,15 @@ export namespace meta {
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion?: pulumi.Input<"v1">
apiVersion?: pulumi.Input<string>

/**
* Kind is a string value representing the REST resource this object represents. Servers may
* infer this from the endpoint the client submits requests to. Cannot be updated. In
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind?: pulumi.Input<"APIVersions">
kind?: pulumi.Input<string>

}

Expand All @@ -16735,7 +16735,7 @@ export namespace meta {
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion?: pulumi.Input<"v1">
apiVersion?: pulumi.Input<string>

/**
* When present, indicates that modifications should not be persisted. An invalid or
Expand All @@ -16758,7 +16758,7 @@ export namespace meta {
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind?: pulumi.Input<"DeleteOptions">
kind?: pulumi.Input<string>

/**
* Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should
Expand Down Expand Up @@ -17722,7 +17722,7 @@ export namespace policy {
* values. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
*/
apiVersion?: pulumi.Input<"policy/v1beta1">
apiVersion?: pulumi.Input<string>

/**
* DeleteOptions may be provided
Expand All @@ -17735,7 +17735,7 @@ export namespace policy {
* CamelCase. More info:
* https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
*/
kind?: pulumi.Input<"Eviction">
kind?: pulumi.Input<string>

/**
* ObjectMeta describes the pod that is being evicted.
Expand Down
Loading

0 comments on commit 7c2acbe

Please sign in to comment.