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

Update to sdk v0.3.0 and v1 proto #144

Merged
merged 4 commits into from
Nov 26, 2024
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: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ on:

env:
# Common versions
GO_VERSION: '1.21.3'
GOLANGCI_VERSION: 'v1.54.2'
GO_VERSION: '1.23.3'
GOLANGCI_VERSION: 'v1.62.0'
DOCKER_BUILDX_VERSION: 'v0.11.2'

# These environment variables are important to the Crossplane CLI install.sh
Expand Down
4 changes: 2 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import (
"dario.cat/mergo"
"github.com/crossplane/function-sdk-go/errors"
fnv1beta1 "github.com/crossplane/function-sdk-go/proto/v1beta1"
fnv1 "github.com/crossplane/function-sdk-go/proto/v1"
)

// MergeContext merges existing Context with new values provided
func (f *Function) MergeContext(req *fnv1beta1.RunFunctionRequest, val map[string]interface{}) (map[string]interface{}, error) {
func (f *Function) MergeContext(req *fnv1.RunFunctionRequest, val map[string]interface{}) (map[string]interface{}, error) {
mergedContext := req.GetContext().AsMap()
if len(val) == 0 {
return mergedContext, nil
Expand Down
8 changes: 4 additions & 4 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/crossplane/crossplane-runtime/pkg/logging"
fnv1beta1 "github.com/crossplane/function-sdk-go/proto/v1beta1"
fnv1 "github.com/crossplane/function-sdk-go/proto/v1"
"github.com/crossplane/function-sdk-go/resource"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
Expand All @@ -14,7 +14,7 @@ import (
func TestMergeContext(t *testing.T) {
type args struct {
val map[string]interface{}
req *fnv1beta1.RunFunctionRequest
req *fnv1.RunFunctionRequest
}
type want struct {
us map[string]any
Expand All @@ -29,7 +29,7 @@ func TestMergeContext(t *testing.T) {
"NoContextAtKey": {
reason: "When there is no existing context data at the key to merge, return the value",
args: args{
req: &fnv1beta1.RunFunctionRequest{
req: &fnv1.RunFunctionRequest{
Context: nil,
},
val: map[string]interface{}{"hello": "world"},
Expand All @@ -42,7 +42,7 @@ func TestMergeContext(t *testing.T) {
"SuccessfulMerge": {
reason: "Confirm that keys are merged with source overwriting destination",
args: args{
req: &fnv1beta1.RunFunctionRequest{
req: &fnv1.RunFunctionRequest{
Context: resource.MustStructJSON(`{"apiextensions.crossplane.io/environment":{"complex":{"a":"b","c":{"d":"e","f":"1","overWrite": "fromContext"}}}}`),
},
val: map[string]interface{}{
Expand Down
16 changes: 8 additions & 8 deletions extraresources.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package main

import (
fnv1beta1 "github.com/crossplane/function-sdk-go/proto/v1beta1"
fnv1 "github.com/crossplane/function-sdk-go/proto/v1"
)

// ExtraResourcesRequirements defines the requirements for extra resources.
type ExtraResourcesRequirements map[string]ExtraResourcesRequirement

// ExtraResourcesRequirement defines a single requirement for extra resources.
// Needed to have camelCase keys instead of the snake_case keys as defined
// through json tags by fnv1beta1.ResourceSelector.
// through json tags by fnv1.ResourceSelector.
type ExtraResourcesRequirement struct {
// APIVersion of the resource.
APIVersion string `json:"apiVersion"`
Expand All @@ -23,20 +23,20 @@ type ExtraResourcesRequirement struct {
MatchName string `json:"matchName,omitempty"`
}

// ToResourceSelector converts the ExtraResourcesRequirement to a fnv1beta1.ResourceSelector.
func (e *ExtraResourcesRequirement) ToResourceSelector() *fnv1beta1.ResourceSelector {
out := &fnv1beta1.ResourceSelector{
// ToResourceSelector converts the ExtraResourcesRequirement to a fnv1.ResourceSelector.
func (e *ExtraResourcesRequirement) ToResourceSelector() *fnv1.ResourceSelector {
out := &fnv1.ResourceSelector{
ApiVersion: e.APIVersion,
Kind: e.Kind,
}
if e.MatchName == "" {
out.Match = &fnv1beta1.ResourceSelector_MatchLabels{
MatchLabels: &fnv1beta1.MatchLabels{Labels: e.MatchLabels},
out.Match = &fnv1.ResourceSelector_MatchLabels{
MatchLabels: &fnv1.MatchLabels{Labels: e.MatchLabels},
}
return out
}

out.Match = &fnv1beta1.ResourceSelector_MatchName{
out.Match = &fnv1.ResourceSelector_MatchName{
MatchName: e.MatchName,
}
return out
Expand Down
10 changes: 5 additions & 5 deletions fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/crossplane/function-sdk-go/errors"
"github.com/crossplane/function-sdk-go/logging"
fnv1beta1 "github.com/crossplane/function-sdk-go/proto/v1beta1"
fnv1 "github.com/crossplane/function-sdk-go/proto/v1"
"github.com/crossplane/function-sdk-go/request"
"github.com/crossplane/function-sdk-go/resource"
"github.com/crossplane/function-sdk-go/response"
Expand All @@ -38,7 +38,7 @@ func (*osFS) Open(name string) (fs.File, error) {

// Function uses Go templates to compose resources.
type Function struct {
fnv1beta1.UnimplementedFunctionRunnerServiceServer
fnv1.UnimplementedFunctionRunnerServiceServer

log logging.Logger
fsys fs.FS
Expand All @@ -52,7 +52,7 @@ const (
)

// RunFunction runs the Function.
func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequest) (*fnv1beta1.RunFunctionResponse, error) {
func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest) (*fnv1.RunFunctionResponse, error) {
f.log.Info("Running Function", "tag", req.GetMeta().GetTag())

rsp := response.To(req, response.DefaultTTL)
Expand Down Expand Up @@ -145,7 +145,7 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequ
}

// Initialize the requirements.
requirements := &fnv1beta1.Requirements{ExtraResources: make(map[string]*fnv1beta1.ResourceSelector)}
requirements := &fnv1.Requirements{ExtraResources: make(map[string]*fnv1.ResourceSelector)}

// Convert the rendered manifests to a list of desired composed resources.
for _, obj := range objs {
Expand Down Expand Up @@ -283,7 +283,7 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequ
return rsp, nil
}

func convertToMap(req *fnv1beta1.RunFunctionRequest) (map[string]any, error) {
func convertToMap(req *fnv1.RunFunctionRequest) (map[string]any, error) {
jReq, err := protojson.Marshal(req)
if err != nil {
return nil, errors.Wrap(err, "cannot marshal request from proto to json")
Expand Down
Loading