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

Fix incorrect schema consts for apiVersion and kind #1153

Merged
merged 1 commit into from
Jun 8, 2020
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
- Fixed the type of some properties in `JSONSchemaPropsArgs` (there's no need to have 2nd-level inputs there):
- `InputList<InputJson>` -> `InputList<JsonElement>`
- `InputMap<Union<TArgs, InputList<string>>>` -> `InputMap<Union<TArgs, ImmutableArray<string>>>`

### Bug Fixes

- Fix incorrect schema consts for apiVersion and kind (https://github.com/pulumi/pulumi-kubernetes/pull/1153)

## 2.2.2 (May 27, 2020)

Expand Down
12 changes: 3 additions & 9 deletions provider/pkg/gen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,9 @@ func genPropertySpec(p Property, resourceGV string, resourceKind string) pschema
contract.Assert(err == nil)

constValue := func() *string {
if p.name == "apiVersion" {
if strings.HasPrefix(resourceGV, "core/") {
dv := strings.TrimPrefix(resourceGV, "core/")
return &dv
}
return &resourceGV
}
if p.name == "kind" {
return &resourceKind
cv := p.ConstValue()
if len(cv) != 0 {
return &cv
}

return nil
Expand Down
16 changes: 15 additions & 1 deletion provider/pkg/gen/typegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ type Property struct {
inputsAPIType string
outputsAPIType string
providerType string
constValue string
defaultValue string
isLast bool
dotnetVarName string
Expand Down Expand Up @@ -249,7 +250,10 @@ func (p Property) OutputsAPIType() string { return p.outputsAPIType }
// ProviderType returns the type of the property for the provider API.
func (p Property) ProviderType() string { return p.providerType }

// DefaultValue returns the type of the property.
// DefaultValue returns the constant value of the property.
func (p Property) ConstValue() string { return p.constValue }

// DefaultValue returns the default value of the property.
func (p Property) DefaultValue() string { return p.defaultValue }

// IsLast returns whether the property is the last in the list of properties.
Expand Down Expand Up @@ -1224,17 +1228,26 @@ func createGroups(definitionsJSON map[string]interface{}, opts groupOpts) []Grou
// `-` is invalid in TS variable names, so replace with `_`
propName = strings.ReplaceAll(propName, "-", "_")

// Create a const value for the field.
var constValue string

// Create a default value for the field.
defaultValue := fmt.Sprintf("args?.%s", propName)
switch propName {
case "apiVersion":
if d.isTopLevel() {
constValue = defaultGroupVersion
}
defaultValue = fmt.Sprintf(`"%s"`, defaultGroupVersion)
if opts.language == typescript && isTopLevel {
inputsAPIType = fmt.Sprintf(`pulumi.Input<"%s">`, defaultGroupVersion)
outputsAPIType = fmt.Sprintf(`"%s"`, defaultGroupVersion)
providerType = fmt.Sprintf(`pulumi.Output<"%s">`, defaultGroupVersion)
}
case "kind":
if d.isTopLevel() {
constValue = d.gvk.Kind
}
defaultValue = fmt.Sprintf(`"%s"`, d.gvk.Kind)
if opts.language == typescript && isTopLevel {
inputsAPIType = fmt.Sprintf(`pulumi.Input<"%s">`, d.gvk.Kind)
Expand Down Expand Up @@ -1294,6 +1307,7 @@ func createGroups(definitionsJSON map[string]interface{}, opts groupOpts) []Grou
name: propName,
languageName: languageName,
dotnetVarName: dotnetVarName,
constValue: constValue,
defaultValue: defaultValue,
isLast: false,
dotnetIsListOrMap: isListOrMap,
Expand Down
2 changes: 1 addition & 1 deletion sdk/dotnet/Meta/V1/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private Status(string name, Input<string> id, CustomResourceOptions? options = n
private static Pulumi.Kubernetes.Types.Inputs.Meta.V1.StatusArgs? MakeArgs(Pulumi.Kubernetes.Types.Inputs.Meta.V1.StatusArgs? args)
{
args ??= new Pulumi.Kubernetes.Types.Inputs.Meta.V1.StatusArgs();
args.ApiVersion = "meta/v1";
args.ApiVersion = "v1";
args.Kind = "Status";
return args;
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/go/kubernetes/meta/v1/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewStatus(ctx *pulumi.Context,
if args == nil {
args = &StatusArgs{}
}
args.ApiVersion = pulumi.StringPtr("meta/v1")
args.ApiVersion = pulumi.StringPtr("v1")
args.Kind = pulumi.StringPtr("Status")
var resource Status
err := ctx.RegisterResource("kubernetes:meta/v1:Status", name, args, &resource, opts...)
Expand Down