Skip to content
Prev Previous commit
Next Next commit
do not override language settings in pkgSpec
  • Loading branch information
rquitales committed Sep 13, 2024
commit e552c1a1d5c3612a668d008783d7c3eb5ee7c5f2
13 changes: 0 additions & 13 deletions pkg/codegen/dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"fmt"

ijson "github.com/pulumi/crd2pulumi/internal/json"
"github.com/pulumi/crd2pulumi/internal/versions"
"github.com/pulumi/pulumi/pkg/v3/codegen/dotnet"
"golang.org/x/text/cases"
Expand Down Expand Up @@ -59,18 +58,6 @@ func GenerateDotNet(pg *PackageGenerator, name string) (map[string]*bytes.Buffer
oldName := pkg.Name
pkg.Name = name
var err error
pkg.Language["csharp"], err = ijson.RawMessage(map[string]any{
"packageReferences": map[string]string{
"Pulumi": "3.*",
"Pulumi.Kubernetes": "4.*",
},
"compatibility": "kubernetes20",
"dictionaryConstructors": true,
"namespaces": namespaces,
})
if err != nil {
return nil, fmt.Errorf("failed to marshal JSON message: %w", err)
}

files, err := dotnet.GeneratePackage(PulumiToolName, pkg, nil, nil)
if err != nil {
Expand Down
14 changes: 0 additions & 14 deletions pkg/codegen/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"path/filepath"
"strings"

ijson "github.com/pulumi/crd2pulumi/internal/json"
"github.com/pulumi/pulumi/pkg/v3/codegen"
goGen "github.com/pulumi/pulumi/pkg/v3/codegen/go"
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
Expand Down Expand Up @@ -58,19 +57,6 @@ func GenerateGo(pg *PackageGenerator, name string) (buffers map[string]*bytes.Bu
}
moduleToPackage["meta/v1"] = "meta/v1"

jsonData, err := ijson.RawMessage(map[string]any{
"importBasePath": "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes",
"internalModuleName": "utilities",
"moduleToPackage": moduleToPackage,
"packageImportAliases": map[string]any{
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/meta/v1": "metav1",
},
})
if err != nil {
return nil, fmt.Errorf("failed to marshal language metadata: %w", err)
}
pkg.Language[langName] = jsonData

files, err := goGen.GeneratePackage("crd2pulumi", pkg, nil)
if err != nil {
return nil, fmt.Errorf("could not generate Go package: %w", err)
Expand Down
13 changes: 0 additions & 13 deletions pkg/codegen/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"regexp"

ijson "github.com/pulumi/crd2pulumi/internal/json"
"github.com/pulumi/crd2pulumi/internal/versions"
javaGen "github.com/pulumi/pulumi-java/pkg/codegen/java"
)
Expand Down Expand Up @@ -50,18 +49,6 @@ func GenerateJava(pg *PackageGenerator, name string) (map[string]*bytes.Buffer,
oldName := pkg.Name
pkg.Name = name

jsonData, err := ijson.RawMessage(map[string]any{
"buildFiles": "gradle",
"dependencies": map[string]string{
"com.pulumi:kubernetes": "4.9.0",
},
"packages": packages,
})
if err != nil {
return nil, fmt.Errorf("failed to marshal language metadata: %w", err)
}
pkg.Language[langName] = jsonData

files, err := javaGen.GeneratePackage("crd2pulumi", pkg, nil, true)
if err != nil {
return nil, fmt.Errorf("could not generate Java package: %w", err)
Expand Down
24 changes: 2 additions & 22 deletions pkg/codegen/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"fmt"

ijson "github.com/pulumi/crd2pulumi/internal/json"
"github.com/pulumi/pulumi/pkg/v3/codegen/nodejs"
)

Expand All @@ -27,25 +26,13 @@ const nodejsMetaPath = "meta/v1.ts"
const nodejsMetaFile = `import * as k8s from "@pulumi/kubernetes";

export type ObjectMeta = k8s.types.input.meta.v1.ObjectMeta;
export type ObjectMetaPatch = k8s.types.input.meta.v1.ObjectMetaPatch;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now generate Patch variants so need to update our imports to address this.

`

func GenerateNodeJS(pg *PackageGenerator, name string) (map[string]*bytes.Buffer, error) {
pkg := pg.SchemaPackage()
oldName := pkg.Name
pkg.Name = name
moduleToPackage, err := pg.ModuleToPackage()
if err != nil {
return nil, fmt.Errorf("%w", err)
}
pkg.Language[nodejsName], err = ijson.RawMessage(map[string]any{
"moduleToPackage": moduleToPackage,
"dependencies": map[string]string{
"@pulumi/kubernetes": "^4.0.0",
},
})
if err != nil {
return nil, err
}

files, err := nodejs.GeneratePackage(PulumiToolName, pkg, nil, nil, true)
if err != nil {
Expand All @@ -55,21 +42,14 @@ func GenerateNodeJS(pg *PackageGenerator, name string) (map[string]*bytes.Buffer
pkg.Name = oldName
delete(pkg.Language, nodejsName)

// Remove ${VERSION} in package.json
packageJSON, ok := files["package.json"]
if !ok {
return nil, fmt.Errorf("cannot find generated package.json")
}
files["package.json"] = bytes.ReplaceAll(packageJSON, []byte("${VERSION}"), []byte(""))

// Pin the kubernetes provider version used
utilities, ok := files["utilities.ts"]
if !ok {
return nil, fmt.Errorf("cannot find generated utilities.ts")
}
files["utilities.ts"] = bytes.ReplaceAll(utilities,
[]byte("export function getVersion(): string {"),
[]byte(`export const getVersion: () => string = () => "4.5.5"
[]byte(`export const getVersion: () => string = () => "4.18.0"

function unusedGetVersion(): string {`),
)
Expand Down
19 changes: 0 additions & 19 deletions pkg/codegen/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"path/filepath"

ijson "github.com/pulumi/crd2pulumi/internal/json"
"github.com/pulumi/pulumi/pkg/v3/codegen/python"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)
Expand All @@ -35,24 +34,6 @@ func GeneratePython(pg *PackageGenerator, name string) (map[string]*bytes.Buffer
oldName := pkg.Name
pkg.Name = name

moduleToPackage, err := pg.ModuleToPackage()
if err != nil {
return nil, fmt.Errorf("%w", err)
}
pkg.Language[langName], err = ijson.RawMessage(map[string]any{
"compatibility": "kubernetes20",
"moduleNameOverrides": moduleToPackage,
"requires": map[string]string{
"pulumi": "\u003e=3.0.0,\u003c4.0.0",
"pyyaml": "\u003e=5.3",
"requests": "\u003e=2.21.0,\u003c2.22.0",
},
"ignorePyNamePanic": true,
})
if err != nil {
return nil, fmt.Errorf("failed to marshal language metadata: %w", err)
}

files, err := python.GeneratePackage(PulumiToolName, pkg, nil)
if err != nil {
return nil, fmt.Errorf("could not generate Go package: %w", err)
Expand Down