Skip to content

Commit

Permalink
Update to Pulumi v3.21.0. (#63)
Browse files Browse the repository at this point in the history
* Update to Pulumi v3.21.0.

This brings in many improvements to code generation, including support
for default values for union-typed properties.
  • Loading branch information
pgavlin authored Jan 4, 2022
1 parent 3bed7df commit 671bb76
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 464 deletions.
4 changes: 2 additions & 2 deletions gen/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func (pg *PackageGenerator) genPythonFiles(name string) (map[string]*bytes.Buffe

// Import the actual SDK ObjectMeta types in place of our placeholder ones
if pg.HasSchemas() {
metaPath := filepath.Join(pythonPackageDir, "meta_v1", "__init__.py")
metaPath := filepath.Join(pythonPackageDir, "meta/v1", "__init__.py")
code, ok := files[metaPath]
contract.Assertf(ok, "missing meta_v1/__init__.py file")
contract.Assertf(ok, "missing meta/v1/__init__.py file")
files[metaPath] = append(code, []byte(pythonMetaFile)...)
}

Expand Down
29 changes: 20 additions & 9 deletions gen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
package gen

import (
"sort"
"strconv"
"strings"

"github.com/pkg/errors"
pschema "github.com/pulumi/pulumi/pkg/v3/codegen/schema"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
unstruct "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

Expand Down Expand Up @@ -117,20 +119,29 @@ func genPackage(types map[string]pschema.ComplexTypeSpec, resourceTokens []strin
}
}

packages := map[string]bool{DefaultName: true, "kubernetes": true}
resources := map[string]pschema.ResourceSpec{}
for _, baseRef := range resourceTokens {
complexTypeSpec := types[baseRef]
resources[baseRef] = pschema.ResourceSpec{
ObjectTypeSpec: complexTypeSpec.ObjectTypeSpec,
InputProperties: complexTypeSpec.Properties,
}
packages[string(tokens.ModuleMember(baseRef).Package())] = true
}

allowedPackages := make([]string, 0, len(packages))
for pkg := range packages {
allowedPackages = append(allowedPackages, pkg)
}
sort.Strings(allowedPackages)

pkgSpec := pschema.PackageSpec{
Name: DefaultName,
Version: Version,
Types: types,
Resources: resources,
Name: DefaultName,
Version: Version,
Types: types,
Resources: resources,
AllowedPackageNames: allowedPackages,
}

pkg, err := pschema.ImportSpec(pkgSpec, nil)
Expand Down Expand Up @@ -178,11 +189,11 @@ func AddType(schema map[string]interface{}, name string, types map[string]pschem

types[name] = pschema.ComplexTypeSpec{
ObjectTypeSpec: pschema.ObjectTypeSpec{
Type: schemaType,
Properties: propertySpecs,
Required: required,
Description: description,
}}
Type: schemaType,
Properties: propertySpecs,
Required: required,
Description: description,
}}
}

// GetTypeSpec returns the corresponding pschema.TypeSpec for a OpenAPI v3
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.16

require (
github.com/pkg/errors v0.9.1
github.com/pulumi/pulumi/pkg/v3 v3.0.0
github.com/pulumi/pulumi/sdk/v3 v3.0.0
github.com/pulumi/pulumi/pkg/v3 v3.21.0
github.com/pulumi/pulumi/sdk/v3 v3.21.0
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.6.1
Expand Down
Loading

0 comments on commit 671bb76

Please sign in to comment.