Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ on:

env:
# Common versions
GO_VERSION: '1.25.0'
GO_VERSION: '1.25.10'
GOLANGCI_VERSION: 'v2.4.0'
DOCKER_BUILDX_VERSION: 'v0.23.0'

# These environment variables are important to the Crossplane CLI install.sh
# script. They determine what version it installs.
XP_CHANNEL: master # TODO(negz): Pin to stable once v1.14 is released.
XP_VERSION: current # TODO(negz): Pin to a version once v1.14 is released.
XP_CHANNEL: stable # TODO(negz): Pin to stable once v1.14 is released.
XP_VERSION: '' # TODO(negz): Pin to a version once v1.14 is released.

# This CI job will automatically push new builds to xpkg.upbound.io if the
# XPKG_ACCESS_ID and XPKG_TOKEN secrets are set in the GitHub respository (or
Expand Down
14 changes: 7 additions & 7 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package main

import (
"github.com/crossplane-contrib/function-patch-and-transform/input/v1beta1"
xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1"
"github.com/crossplane/crossplane-runtime/v2/pkg/errors"
"github.com/crossplane/crossplane-runtime/v2/pkg/fieldpath"
"github.com/crossplane/crossplane-runtime/v2/pkg/reconciler/managed"
xpresource "github.com/crossplane/crossplane-runtime/v2/pkg/resource"
xpv2 "github.com/crossplane/crossplane/apis/v2/core/v2"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/json"
Expand Down Expand Up @@ -126,14 +126,14 @@ func composeConnectionSecret(xr *resource.Composite, details resource.Connection
// getConnectionSecretRef creates a connection secret reference from the given
// XR and input. The patches for the reference will be applied before the
// reference is returned.
func getConnectionSecretRef(xr *resource.Composite, input *v1beta1.WriteConnectionSecretToRef) (xpv1.SecretReference, error) {
func getConnectionSecretRef(xr *resource.Composite, input *v1beta1.WriteConnectionSecretToRef) (xpv2.SecretReference, error) {
// Get the base connection secret ref to start with
ref := getBaseConnectionSecretRef(xr, input)

// Apply patches to the base connection secret ref if they've been provided
if input != nil && len(input.Patches) > 0 {
if err := applyConnectionSecretPatches(xr, &ref, input.Patches); err != nil {
return xpv1.SecretReference{}, errors.Wrap(err, "cannot apply connection secret patches")
return xpv2.SecretReference{}, errors.Wrap(err, "cannot apply connection secret patches")
}
}

Expand All @@ -149,7 +149,7 @@ func getConnectionSecretRef(xr *resource.Composite, input *v1beta1.WriteConnecti
// 2. function input.writeConnectionSecretToRef - if name or namespace is provided
// then the whole ref will be used
// 3. generate the reference from scratch, based on the XR name and namespace
func getBaseConnectionSecretRef(xr *resource.Composite, input *v1beta1.WriteConnectionSecretToRef) xpv1.SecretReference {
func getBaseConnectionSecretRef(xr *resource.Composite, input *v1beta1.WriteConnectionSecretToRef) xpv2.SecretReference {
// Check if XR author manually added writeConnectionSecretToRef to the XR's
// schema and just use that if it exists
xrRef := xr.Resource.GetWriteConnectionSecretToReference()
Expand All @@ -159,19 +159,19 @@ func getBaseConnectionSecretRef(xr *resource.Composite, input *v1beta1.WriteConn

// Use the input values if at least one of name or namespace has been provided
if input != nil && (input.Name != "" || input.Namespace != "") {
return xpv1.SecretReference{Name: input.Name, Namespace: input.Namespace}
return xpv2.SecretReference{Name: input.Name, Namespace: input.Namespace}
}

// Nothing has been provided, so generate a default name using the name of the XR
return xpv1.SecretReference{
return xpv2.SecretReference{
Name: xr.Resource.GetName() + "-connection",
Namespace: xr.Resource.GetNamespace(),
}
}

// applyConnectionSecretPatches applies all patches provided on the input to the
// connection secret reference.
func applyConnectionSecretPatches(xr *resource.Composite, ref *xpv1.SecretReference, patches []v1beta1.ConnectionSecretPatch) error {
func applyConnectionSecretPatches(xr *resource.Composite, ref *xpv2.SecretReference, patches []v1beta1.ConnectionSecretPatch) error {
// Convert the secret reference to an unstructured object so we can pass it to the patching logic
// We use a fake (but reasonable) apiVersion and kind because the unstructured converter requires them.
refObj := &unstructured.Unstructured{
Expand Down
20 changes: 10 additions & 10 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"testing"

"github.com/crossplane-contrib/function-patch-and-transform/input/v1beta1"
xpv1 "github.com/crossplane/crossplane-runtime/v2/apis/common/v1"
"github.com/crossplane/crossplane-runtime/v2/pkg/errors"
"github.com/crossplane/crossplane-runtime/v2/pkg/reconciler/managed"
xpresource "github.com/crossplane/crossplane-runtime/v2/pkg/resource"
"github.com/crossplane/crossplane-runtime/v2/pkg/resource/fake"
"github.com/crossplane/crossplane-runtime/v2/pkg/test"
xpv2 "github.com/crossplane/crossplane/apis/v2/core/v2"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestExtractConnectionDetails(t *testing.T) {
Generation: 4,
},
ConnectionSecretWriterTo: fake.ConnectionSecretWriterTo{
Ref: &xpv1.SecretReference{
Ref: &xpv2.SecretReference{
Name: "cool-secret",
Namespace: "cool-namespace",
},
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestGetConnectionSecretRef(t *testing.T) {
input *v1beta1.WriteConnectionSecretToRef
}
type want struct {
ref xpv1.SecretReference
ref xpv2.SecretReference
err error
}

Expand All @@ -174,7 +174,7 @@ func TestGetConnectionSecretRef(t *testing.T) {
input: nil,
},
want: want{
ref: xpv1.SecretReference{
ref: xpv2.SecretReference{
Name: "xr-secret",
Namespace: "xr-namespace",
},
Expand All @@ -200,7 +200,7 @@ func TestGetConnectionSecretRef(t *testing.T) {
},
},
want: want{
ref: xpv1.SecretReference{
ref: xpv2.SecretReference{
Name: "my-custom-secret",
Namespace: "custom-namespace",
},
Expand All @@ -227,7 +227,7 @@ func TestGetConnectionSecretRef(t *testing.T) {
},
},
want: want{
ref: xpv1.SecretReference{
ref: xpv2.SecretReference{
Name: "xr-secret",
Namespace: "xr-namespace",
},
Expand All @@ -250,7 +250,7 @@ func TestGetConnectionSecretRef(t *testing.T) {
input: nil,
},
want: want{
ref: xpv1.SecretReference{
ref: xpv2.SecretReference{
Name: "my-xr-connection",
Namespace: "xr-namespace",
},
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestGetConnectionSecretRef(t *testing.T) {
},
},
want: want{
ref: xpv1.SecretReference{
ref: xpv2.SecretReference{
Name: "test-uid-456-cool-creds",
Namespace: "prod",
},
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestGetConnectionSecretRef(t *testing.T) {
},
},
want: want{
ref: xpv1.SecretReference{
ref: xpv2.SecretReference{
Name: "myapp-staging-cool-creds",
Namespace: "default", // we didn't patch this, but it picks it up from the XR's namespace
},
Expand Down Expand Up @@ -379,7 +379,7 @@ func TestGetConnectionSecretRef(t *testing.T) {
},
},
want: want{
ref: xpv1.SecretReference{
ref: xpv2.SecretReference{
Name: "base-secret-name", // only namespace was patched
Namespace: "custom-ns",
},
Expand Down
67 changes: 34 additions & 33 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/crossplane-contrib/function-patch-and-transform

go 1.25.0
go 1.25.10

require (
github.com/alecthomas/kong v1.14.0
github.com/crossplane/crossplane-runtime/v2 v2.2.0
github.com/crossplane/function-sdk-go v0.6.2
github.com/crossplane/crossplane-runtime/v2 v2.3.0
github.com/crossplane/crossplane/apis/v2 v2.3.0
github.com/crossplane/function-sdk-go v0.7.0
github.com/google/go-cmp v0.7.0
github.com/pkg/errors v0.9.1
google.golang.org/protobuf v1.36.11
Expand All @@ -31,20 +32,20 @@ require (
github.com/go-json-experiment/json v0.0.0-20240815175050-ebd3a8989ca1 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.22.4 // indirect
github.com/go-openapi/jsonreference v0.21.4 // indirect
github.com/go-openapi/swag v0.25.4 // indirect
github.com/go-openapi/swag/cmdutils v0.25.4 // indirect
github.com/go-openapi/swag/conv v0.25.4 // indirect
github.com/go-openapi/swag/fileutils v0.25.4 // indirect
github.com/go-openapi/swag/jsonname v0.25.4 // indirect
github.com/go-openapi/swag/jsonutils v0.25.4 // indirect
github.com/go-openapi/swag/loading v0.25.4 // indirect
github.com/go-openapi/swag/mangling v0.25.4 // indirect
github.com/go-openapi/swag/netutils v0.25.4 // indirect
github.com/go-openapi/swag/stringutils v0.25.4 // indirect
github.com/go-openapi/swag/typeutils v0.25.4 // indirect
github.com/go-openapi/swag/yamlutils v0.25.4 // indirect
github.com/go-openapi/jsonpointer v0.22.5 // indirect
github.com/go-openapi/jsonreference v0.21.5 // indirect
github.com/go-openapi/swag v0.25.5 // indirect
github.com/go-openapi/swag/cmdutils v0.25.5 // indirect
github.com/go-openapi/swag/conv v0.25.5 // indirect
github.com/go-openapi/swag/fileutils v0.25.5 // indirect
github.com/go-openapi/swag/jsonname v0.25.5 // indirect
github.com/go-openapi/swag/jsonutils v0.25.5 // indirect
github.com/go-openapi/swag/loading v0.25.5 // indirect
github.com/go-openapi/swag/mangling v0.25.5 // indirect
github.com/go-openapi/swag/netutils v0.25.5 // indirect
github.com/go-openapi/swag/stringutils v0.25.5 // indirect
github.com/go-openapi/swag/typeutils v0.25.5 // indirect
github.com/go-openapi/swag/yamlutils v0.25.5 // indirect
github.com/gobuffalo/flect v1.0.3 // indirect
github.com/google/gnostic-models v0.7.1 // indirect
github.com/google/uuid v1.6.0 // indirect
Expand All @@ -53,11 +54,11 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-isatty v0.0.22 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.23.2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.67.5 // indirect
Expand All @@ -66,24 +67,24 @@ require (
github.com/spf13/cobra v1.10.2 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.opentelemetry.io/otel v1.40.0 // indirect
go.opentelemetry.io/otel/trace v1.40.0 // indirect
go.opentelemetry.io/otel v1.43.0 // indirect
go.opentelemetry.io/otel/trace v1.43.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.1 // indirect
go.uber.org/zap v1.28.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/mod v0.32.0 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/oauth2 v0.34.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/term v0.39.0 // indirect
golang.org/x/text v0.33.0 // indirect
golang.org/x/time v0.14.0 // indirect
golang.org/x/tools v0.41.0 // indirect
golang.org/x/mod v0.35.0 // indirect
golang.org/x/net v0.53.0 // indirect
golang.org/x/oauth2 v0.36.0 // indirect
golang.org/x/sync v0.20.0 // indirect
golang.org/x/sys v0.43.0 // indirect
golang.org/x/term v0.42.0 // indirect
golang.org/x/text v0.36.0 // indirect
golang.org/x/time v0.15.0 // indirect
golang.org/x/tools v0.44.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260203192932-546029d2fa20 // indirect
google.golang.org/grpc v1.79.3 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260427160629-7cedc36a6bc4 // indirect
google.golang.org/grpc v1.81.1 // indirect
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading
Loading