From 060cb0d79de7e9dec79c3d0041a142836f2318b4 Mon Sep 17 00:00:00 2001 From: Karolis Rusenas Date: Sat, 20 Jun 2020 13:45:58 +0100 Subject: [PATCH 1/2] only override custom domain if it's set --- .../forward/v1/webhookrelayforward_types.go | 2 +- pkg/apis/forward/v1/zz_generated.deepcopy.go | 5 +++ .../webhookrelayforward/sync_inputs.go | 38 ++++++++++++++----- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/pkg/apis/forward/v1/webhookrelayforward_types.go b/pkg/apis/forward/v1/webhookrelayforward_types.go index 1358dda..484c409 100644 --- a/pkg/apis/forward/v1/webhookrelayforward_types.go +++ b/pkg/apis/forward/v1/webhookrelayforward_types.go @@ -71,7 +71,7 @@ type InputSpec struct { // CustomDomain can be used to assign a permanent domain name for your input // such as example.hooks.webhookrelay.com - CustomDomain string `json:"customDomain,omitempty"` + CustomDomain *string `json:"customDomain,omitempty"` // PathPrefix can be combined together with CustomDomain to create 'API like' // functionality where calls from: // petshop.com/dogs -> are forwarded to [dogs store] diff --git a/pkg/apis/forward/v1/zz_generated.deepcopy.go b/pkg/apis/forward/v1/zz_generated.deepcopy.go index a2d5883..2300ca0 100644 --- a/pkg/apis/forward/v1/zz_generated.deepcopy.go +++ b/pkg/apis/forward/v1/zz_generated.deepcopy.go @@ -56,6 +56,11 @@ func (in *InputSpec) DeepCopyInto(out *InputSpec) { (*out)[key] = outVal } } + if in.CustomDomain != nil { + in, out := &in.CustomDomain, &out.CustomDomain + *out = new(string) + **out = **in + } return } diff --git a/pkg/controller/webhookrelayforward/sync_inputs.go b/pkg/controller/webhookrelayforward/sync_inputs.go index 91148bd..9ac8704 100644 --- a/pkg/controller/webhookrelayforward/sync_inputs.go +++ b/pkg/controller/webhookrelayforward/sync_inputs.go @@ -104,19 +104,39 @@ func inputSpecToInput(spec *forwardv1.InputSpec, bucket *webhookrelay.Bucket) *w } } - return &webhookrelay.Input{ - Name: spec.Name, - BucketID: bucket.ID, - FunctionID: spec.FunctionID, - Headers: spec.ResponseHeaders, - StatusCode: spec.ResponseStatusCode, - Body: spec.ResponseBody, - + computedInput := &webhookrelay.Input{ + Name: spec.Name, + BucketID: bucket.ID, + FunctionID: spec.FunctionID, + Headers: spec.ResponseHeaders, + StatusCode: spec.ResponseStatusCode, + Body: spec.ResponseBody, ResponseFromOutput: spec.ResponseFromOutput, - CustomDomain: spec.CustomDomain, PathPrefix: spec.PathPrefix, Description: spec.Description, } + + if spec.CustomDomain != nil { + // set, using it + computedInput.CustomDomain = *spec.CustomDomain + } else { + // not set, checking whether there was set one originally and preserving it + original, ok := getInputFromBucket(spec.Name, bucket) + if ok { + computedInput.CustomDomain = original.CustomDomain + } + } + + return computedInput +} + +func getInputFromBucket(name string, bucket *webhookrelay.Bucket) (*webhookrelay.Input, bool) { + for _, input := range bucket.Inputs { + if input.Name == name { + return input, true + } + } + return nil, false } func getInputsDiff(current, desired []*webhookrelay.Input) *inputsDiff { From aeadf50747e4457708ffd8644b75fb51073f8184 Mon Sep 17 00:00:00 2001 From: Karolis Rusenas Date: Sat, 20 Jun 2020 13:46:05 +0100 Subject: [PATCH 2/2] copy crd into the chart --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index e4353db..43161a3 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ build: go-gen: $(OPERATOR_SDK) generate k8s $(OPERATOR_SDK) generate crds + cp deploy/crds/forward.webhookrelay.com_webhookrelayforwards_crd.yaml charts/webhookrelay-operator/crds/crd.yaml # Run tests test: