From 30fd6553112cc9406c260d654936d4c4c3ecc629 Mon Sep 17 00:00:00 2001 From: Brian Dwyer Date: Wed, 5 Jul 2023 17:14:44 -0400 Subject: [PATCH 1/4] Add support for nested objects in output --- README.md | 2 +- apis/v1beta1/workspace_types.go | 5 +++-- apis/v1beta1/zz_generated.deepcopy.go | 5 +++-- internal/controller/workspace/workspace.go | 9 ++++----- .../controller/workspace/workspace_test.go | 19 ++++++++++--------- package/crds/tf.upbound.io_workspaces.yaml | 2 +- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index dc0c1f7..a06241f 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ spec: source: Inline module: | // All outputs are written to the connection secret. Non-sensitive outputs - // are stored as string values in the status.atProvider.outputs object. + // are stored in the status.atProvider.outputs object. output "url" { value = google_storage_bucket.example.self_link } diff --git a/apis/v1beta1/workspace_types.go b/apis/v1beta1/workspace_types.go index 9b895dc..b87461d 100644 --- a/apis/v1beta1/workspace_types.go +++ b/apis/v1beta1/workspace_types.go @@ -18,6 +18,7 @@ package v1beta1 import ( xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + extensionsV1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -134,8 +135,8 @@ type WorkspaceParameters struct { // WorkspaceObservation are the observable fields of a Workspace. type WorkspaceObservation struct { - Checksum string `json:"checksum,omitempty"` - Outputs map[string]string `json:"outputs,omitempty"` + Checksum string `json:"checksum,omitempty"` + Outputs map[string]extensionsV1.JSON `json:"outputs,omitempty"` } // A WorkspaceSpec defines the desired state of a Workspace. diff --git a/apis/v1beta1/zz_generated.deepcopy.go b/apis/v1beta1/zz_generated.deepcopy.go index 7dbe2d0..c332a16 100644 --- a/apis/v1beta1/zz_generated.deepcopy.go +++ b/apis/v1beta1/zz_generated.deepcopy.go @@ -22,6 +22,7 @@ limitations under the License. package v1beta1 import ( + "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -421,9 +422,9 @@ func (in *WorkspaceObservation) DeepCopyInto(out *WorkspaceObservation) { *out = *in if in.Outputs != nil { in, out := &in.Outputs, &out.Outputs - *out = make(map[string]string, len(*in)) + *out = make(map[string]v1.JSON, len(*in)) for key, val := range *in { - (*out)[key] = val + (*out)[key] = *val.DeepCopy() } } } diff --git a/internal/controller/workspace/workspace.go b/internal/controller/workspace/workspace.go index 6643418..b7b37a3 100644 --- a/internal/controller/workspace/workspace.go +++ b/internal/controller/workspace/workspace.go @@ -28,6 +28,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/afero" corev1 "k8s.io/api/core/v1" + extensionsV1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -474,14 +475,12 @@ func op2cd(o []terraform.Output) managed.ConnectionDetails { // workspace_type.Workspace. func generateWorkspaceObservation(op []terraform.Output) v1beta1.WorkspaceObservation { wo := v1beta1.WorkspaceObservation{ - Outputs: make(map[string]string, len(op)), + Outputs: make(map[string]extensionsV1.JSON, len(op)), } for _, o := range op { if !o.Sensitive { - if o.Type == terraform.OutputTypeString { - wo.Outputs[o.Name] = o.StringValue() - } else if j, err := o.JSONValue(); err == nil { - wo.Outputs[o.Name] = string(j) + if j, err := o.JSONValue(); err == nil { + wo.Outputs[o.Name] = extensionsV1.JSON{Raw: j} } } } diff --git a/internal/controller/workspace/workspace_test.go b/internal/controller/workspace/workspace_test.go index 2d7f88f..3bdf368 100644 --- a/internal/controller/workspace/workspace_test.go +++ b/internal/controller/workspace/workspace_test.go @@ -27,6 +27,7 @@ import ( "github.com/pkg/errors" "github.com/spf13/afero" corev1 "k8s.io/api/core/v1" + extensionsV1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" @@ -852,7 +853,7 @@ func TestObserve(t *testing.T) { }, wo: v1beta1.WorkspaceObservation{ Checksum: tfChecksum, - Outputs: map[string]string{}, + Outputs: map[string]extensionsV1.JSON{}, }, }, }, @@ -882,7 +883,7 @@ func TestObserve(t *testing.T) { }, wo: v1beta1.WorkspaceObservation{ Checksum: tfChecksum, - Outputs: map[string]string{}, + Outputs: map[string]extensionsV1.JSON{}, }, }, }, @@ -958,7 +959,7 @@ func TestObserve(t *testing.T) { }, wo: v1beta1.WorkspaceObservation{ Checksum: tfChecksum, - Outputs: map[string]string{}, + Outputs: map[string]extensionsV1.JSON{}, }, }, }, @@ -999,8 +1000,8 @@ func TestObserve(t *testing.T) { }, wo: v1beta1.WorkspaceObservation{ Checksum: tfChecksum, - Outputs: map[string]string{ - "string": "", + Outputs: map[string]extensionsV1.JSON{ + "string": {Raw: []byte("null")}, }, }, }, @@ -1042,8 +1043,8 @@ func TestObserve(t *testing.T) { }, wo: v1beta1.WorkspaceObservation{ Checksum: tfChecksum, - Outputs: map[string]string{ - "string": "", + Outputs: map[string]extensionsV1.JSON{ + "string": {Raw: []byte("null")}, }, }, }, @@ -1265,8 +1266,8 @@ func TestCreate(t *testing.T) { }, }, wo: v1beta1.WorkspaceObservation{ - Outputs: map[string]string{ - "object": "null", + Outputs: map[string]extensionsV1.JSON{ + "object": {Raw: []byte("null")}, }, }, }, diff --git a/package/crds/tf.upbound.io_workspaces.yaml b/package/crds/tf.upbound.io_workspaces.yaml index 6f78e0e..e002315 100644 --- a/package/crds/tf.upbound.io_workspaces.yaml +++ b/package/crds/tf.upbound.io_workspaces.yaml @@ -365,7 +365,7 @@ spec: type: string outputs: additionalProperties: - type: string + x-kubernetes-preserve-unknown-fields: true type: object type: object conditions: From edec8fe942d312bb3bc8c6234d6d65d356f3159d Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Thu, 10 Aug 2023 14:28:19 +0200 Subject: [PATCH 2/4] Add example for a map value in the output Signed-off-by: Yury Tsarev --- examples/workspace-inline-aws.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/workspace-inline-aws.yaml b/examples/workspace-inline-aws.yaml index 00d8b71..6b9dc30 100644 --- a/examples/workspace-inline-aws.yaml +++ b/examples/workspace-inline-aws.yaml @@ -21,8 +21,11 @@ spec: output "vpc_id" { value = aws_vpc.main.id } - output "subnet_id" { - value = aws_subnet.main.id + output "subnet_data" { + value = { + "id" = aws_subnet.main.id + "arn" = aws_subnet.main.arn + } } variable "vpcName" { description = "VPC name" From 4ed4ef02e4555e63e8ff4fa292222ad907170a0e Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Thu, 10 Aug 2023 14:37:41 +0200 Subject: [PATCH 3/4] Update build module go.mod, inherit golangci-lint from the `build` Signed-off-by: Yury Tsarev --- Makefile | 4 +++- build | 2 +- go.mod | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 83aa355..f160da6 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,9 @@ PLATFORMS ?= linux_amd64 linux_arm64 # Setup Go NPROCS ?= 1 -GOLANGCILINT_VERSION ?= 1.50.0 +# GOLANGCILINT_VERSION is inherited from build submodule by default. +# Uncomment below if you need to override the version. +# GOLANGCILINT_VERSION ?= 1.50.0 GO_TEST_PARALLEL := $(shell echo $$(( $(NPROCS) / 2 ))) GO_STATIC_PACKAGES = $(GO_PROJECT)/cmd/provider GO_LDFLAGS += -X $(GO_PROJECT)/pkg/version.Version=$(VERSION) diff --git a/build b/build index 7da2fde..bd5297b 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit 7da2fdeb3dc1ebbce8210a58616debe34ef0fd97 +Subproject commit bd5297bd16c113cbc5ed1905b1d96aa1cb3078ec diff --git a/go.mod b/go.mod index acd1cac..11f9ac0 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( golang.org/x/sync v0.1.0 gopkg.in/alecthomas/kingpin.v2 v2.2.6 k8s.io/api v0.26.3 + k8s.io/apiextensions-apiserver v0.26.1 k8s.io/apimachinery v0.26.3 k8s.io/client-go v0.26.3 sigs.k8s.io/controller-runtime v0.14.6 @@ -126,7 +127,6 @@ require ( gopkg.in/square/go-jose.v2 v2.5.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/apiextensions-apiserver v0.26.1 // indirect k8s.io/component-base v0.26.1 // indirect k8s.io/klog/v2 v2.80.1 // indirect k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect From 4d21b7f3b471fc103fcb33cbe1201f731893a1d6 Mon Sep 17 00:00:00 2001 From: Yury Tsarev Date: Thu, 10 Aug 2023 14:46:48 +0200 Subject: [PATCH 4/4] Fix pipeline by inheriting build module version of k8s tools Signed-off-by: Yury Tsarev --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f160da6..dacd4d1 100644 --- a/Makefile +++ b/Makefile @@ -24,9 +24,10 @@ GO111MODULE = on # ==================================================================================== # Setup Kubernetes tools -KIND_VERSION = v0.15.0 -UP_VERSION = v0.14.0 -UP_CHANNEL = stable +# Uncomment below to override the versions from the build module +# KIND_VERSION = v0.15.0 +# UP_VERSION = v0.14.0 +# UP_CHANNEL = stable UPTEST_VERSION = v0.5.0 -include build/makelib/k8s_tools.mk