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

Add apiextensions.CustomResource to Go SDK #1125

Merged
merged 7 commits into from
May 15, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Support helm v3 `include-crds` argument. (https://github.com/pulumi/pulumi-kubernetes/pull/1102)
- Bump python requests version dependency. (https://github.com/pulumi/pulumi-kubernetes/pull/1121)
- Add apiextensions.CustomResource to Go SDK. (https://github.com/pulumi/pulumi-kubernetes/pull/1125)

## 2.1.1 (May 8, 2020)

Expand Down
1 change: 1 addition & 0 deletions provider/cmd/pulumi-gen-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ func writeGoClient(data map[string]interface{}, outdir string, templateDir strin
})

files["kubernetes/types.go"] = mustRenderTemplate(filepath.Join(templateDir, "types.tmpl"), templateResources)
files["kubernetes/apiextensions/customResource.go"] = mustRenderTemplate(filepath.Join(templateDir, "apiextensions", "customResource.tmpl"), templateResources)
files["kubernetes/helm/v2/chart.go"] = mustRenderTemplate(filepath.Join(templateDir, "helm", "v2", "chart.tmpl"), templateResources)
files["kubernetes/helm/v2/types.go"] = mustRenderTemplate(filepath.Join(templateDir, "helm", "v2", "types.tmpl"), templateResources)
files["kubernetes/yaml/configFile.go"] = mustRenderTemplate(filepath.Join(templateDir, "yaml", "configFile.tmpl"), templateResources)
Expand Down
4 changes: 2 additions & 2 deletions provider/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (
github.com/imdario/mergo v0.3.8
github.com/mitchellh/go-wordwrap v1.0.0
github.com/pkg/errors v0.9.1
github.com/pulumi/pulumi/pkg/v2 v2.1.1-0.20200506045153-0e512aa0ef84
github.com/pulumi/pulumi/sdk/v2 v2.1.1-0.20200506045153-0e512aa0ef84
github.com/pulumi/pulumi/pkg/v2 v2.2.2-0.20200514204320-e677c7d6dca3
github.com/pulumi/pulumi/sdk/v2 v2.2.2-0.20200514204320-e677c7d6dca3
github.com/stretchr/testify v1.5.1
google.golang.org/grpc v1.28.0
k8s.io/api v0.17.0
Expand Down
8 changes: 4 additions & 4 deletions provider/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,12 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/pulumi/pulumi/pkg/v2 v2.1.1-0.20200506045153-0e512aa0ef84 h1:IuN+CUhkLj7CwthEnWhifL25N4KRykiQEfKJXTI//mQ=
github.com/pulumi/pulumi/pkg/v2 v2.1.1-0.20200506045153-0e512aa0ef84/go.mod h1:hXaFYjGEnsQ7qGRJbCDhjuGh7sip3TsaOGNkU3ADt9s=
github.com/pulumi/pulumi/pkg/v2 v2.2.2-0.20200514204320-e677c7d6dca3 h1:s5Pol/uvx0CREUv9g7zwKT5AAl0A8q4KJozXB4RRQ50=
github.com/pulumi/pulumi/pkg/v2 v2.2.2-0.20200514204320-e677c7d6dca3/go.mod h1:hXaFYjGEnsQ7qGRJbCDhjuGh7sip3TsaOGNkU3ADt9s=
github.com/pulumi/pulumi/sdk/v2 v2.0.0 h1:3VMXbEo3bqeaU+YDt8ufVBLD0WhLYE3tG3t/nIZ3Iac=
github.com/pulumi/pulumi/sdk/v2 v2.0.0/go.mod h1:W7k1UDYerc5o97mHnlHHp5iQZKEby+oQrQefWt+2RF4=
github.com/pulumi/pulumi/sdk/v2 v2.1.1-0.20200506045153-0e512aa0ef84 h1:6qDezDHciRcIKyhQQr/dA7numrfYmm3guPlQU6bYXp4=
github.com/pulumi/pulumi/sdk/v2 v2.1.1-0.20200506045153-0e512aa0ef84/go.mod h1:QNbWpL4gvf3X0lUFT7TXA2Jo1ff/Ti2l97AyFGYwvW4=
github.com/pulumi/pulumi/sdk/v2 v2.2.2-0.20200514204320-e677c7d6dca3 h1:uCVadlcmLexcm6WHJv1EFB3E9PKqWQt/+zVuNC+WpjM=
github.com/pulumi/pulumi/sdk/v2 v2.2.2-0.20200514204320-e677c7d6dca3/go.mod h1:QNbWpL4gvf3X0lUFT7TXA2Jo1ff/Ti2l97AyFGYwvW4=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
Expand Down
129 changes: 129 additions & 0 deletions provider/pkg/gen/go-templates/apiextensions/customResource.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Copyright 2016-2020, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// *** WARNING: this file was generated by pulumigen. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

package apiextensions

import (
"fmt"
"reflect"

"github.com/pulumi/pulumi-kubernetes/sdk/v2/go/kubernetes"
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v2/go/kubernetes/meta/v1"
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)

// CustomResource represents a resource definition we'd use to create an instance of a
// Kubernetes CustomResourceDefinition (CRD). For example, the CoreOS Prometheus operator
// exposes a CRD `monitoring.coreos.com/ServiceMonitor`; to create a `ServiceMonitor`, we'd
// pass a `CustomResourceArgs` containing the `ServiceMonitor` definition to `apiextensions.CustomResource`.
type CustomResource struct {
pulumi.CustomResourceState

// APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
ApiVersion pulumi.StringOutput `pulumi:"apiVersion"`
// 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/sig-architecture/api-conventions.md#types-kinds
Kind pulumi.StringOutput `pulumi:"kind"`
// Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata.
Metadata metav1.ObjectMetaPtrOutput `pulumi:"metadata"`
// Untyped map that holds any user-defined fields.
OtherFields pulumi.MapOutput `pulumi:""`
}

// NewCustomResource registers a new resource with the given unique name, arguments, and options.
func NewCustomResource(ctx *pulumi.Context,
name string, args *CustomResourceArgs, opts ...pulumi.ResourceOption) (*CustomResource, error) {
if args == nil {
args = &CustomResourceArgs{}
}

untyped := kubernetes.UntypedArgs{}
for k, v := range args.OtherFields {
untyped[k] = v
}
untyped["apiVersion"] = args.ApiVersion
untyped["kind"] = args.Kind
untyped["metadata"] = args.Metadata
lblackstone marked this conversation as resolved.
Show resolved Hide resolved

var resource CustomResource
err := ctx.RegisterResource(fmt.Sprintf("kubernetes:%s:%s", args.ApiVersion, args.Kind), name, untyped, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}

// GetCustomResource gets an existing CustomResource resource's state with the given name, ID, and optional
// state properties that are used to uniquely qualify the lookup (nil if not required).
func GetCustomResource(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *CustomResourceState, opts ...pulumi.ResourceOption) (*CustomResource, error) {
var resource CustomResource
err := ctx.ReadResource(fmt.Sprintf("kubernetes:%s:%s", state.ApiVersion, state.Kind), name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}

// Input properties used for looking up and filtering CustomResource resources.
type customResourceState struct {
// APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
ApiVersion *string `pulumi:"apiVersion"`
// 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/sig-architecture/api-conventions.md#types-kinds
Kind *string `pulumi:"kind"`
// Standard object metadata.
Metadata *metav1.ObjectMeta `pulumi:"metadata"`
}

type CustomResourceState struct {
// APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
ApiVersion pulumi.StringPtrInput
// 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/sig-architecture/api-conventions.md#types-kinds
Kind pulumi.StringPtrInput
// Standard object metadata.
Metadata metav1.ObjectMetaPtrInput
}

func (CustomResourceState) ElementType() reflect.Type {
return reflect.TypeOf((*customResourceState)(nil)).Elem()
}

type customResourceArgs struct {
// APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
ApiVersion string `pulumi:"apiVersion"`
// 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/sig-architecture/api-conventions.md#types-kinds
Kind string `pulumi:"kind"`
// Standard object metadata.
Metadata *metav1.ObjectMeta `pulumi:"metadata"`
// Untyped map that holds any user-defined fields.
OtherFields map[string]interface{} `pulumi:""`
}

// The set of arguments for constructing a Deployment resource.
type CustomResourceArgs struct {
// APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
ApiVersion pulumi.StringInput
// 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/sig-architecture/api-conventions.md#types-kinds
Kind pulumi.StringInput
// Standard object metadata.
Metadata metav1.ObjectMetaPtrInput
// Untyped map that holds any user-defined fields.
OtherFields kubernetes.UntypedArgs
lblackstone marked this conversation as resolved.
Show resolved Hide resolved
}

func (CustomResourceArgs) ElementType() reflect.Type {
return reflect.TypeOf((*customResourceArgs)(nil)).Elem()
}
8 changes: 7 additions & 1 deletion provider/pkg/gen/go-templates/yaml/yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/pkg/errors"
"github.com/pulumi/pulumi-kubernetes/sdk/v2/go/kubernetes"
"github.com/pulumi/pulumi-kubernetes/sdk/v2/go/kubernetes/apiextensions"
{{- range .Imports}}
{{.}}
{{- end}}
Expand Down Expand Up @@ -220,6 +221,11 @@ func parseYamlObject(ctx *pulumi.Context, obj map[string]interface{}, transforma
{{`return []resourceTuple{{Name: key, Resource: &res}}, nil`}}
{{- end}}
default:
return nil, errors.Errorf("unrecognized kind %s %+v", fullKind, obj)
var res apiextensions.CustomResource
err := ctx.RegisterResource(fmt.Sprintf("kubernetes:%s:%s", apiVersion, kind), metaName, kubernetes.UntypedArgs(obj), &res, opts...)
if err != nil {
return nil, err
}
{{`return []resourceTuple{{Name: key, Resource: &res}}, nil`}}
}
}
2 changes: 1 addition & 1 deletion sdk/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.13
require (
github.com/google/go-cmp v0.4.0 // indirect
github.com/pkg/errors v0.9.1
github.com/pulumi/pulumi/sdk/v2 v2.1.1-0.20200506045153-0e512aa0ef84
github.com/pulumi/pulumi/sdk/v2 v2.2.2-0.20200514204320-e677c7d6dca3
github.com/sergi/go-diff v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
google.golang.org/genproto v0.0.0-20200318110522-7735f76e9fa5 // indirect
Expand Down
4 changes: 2 additions & 2 deletions sdk/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/pulumi/pulumi/sdk/v2 v2.1.1-0.20200506045153-0e512aa0ef84 h1:6qDezDHciRcIKyhQQr/dA7numrfYmm3guPlQU6bYXp4=
github.com/pulumi/pulumi/sdk/v2 v2.1.1-0.20200506045153-0e512aa0ef84/go.mod h1:QNbWpL4gvf3X0lUFT7TXA2Jo1ff/Ti2l97AyFGYwvW4=
github.com/pulumi/pulumi/sdk/v2 v2.2.2-0.20200514204320-e677c7d6dca3 h1:uCVadlcmLexcm6WHJv1EFB3E9PKqWQt/+zVuNC+WpjM=
github.com/pulumi/pulumi/sdk/v2 v2.2.2-0.20200514204320-e677c7d6dca3/go.mod h1:QNbWpL4gvf3X0lUFT7TXA2Jo1ff/Ti2l97AyFGYwvW4=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
Expand Down
Loading