Skip to content

Commit a073b0e

Browse files
authored
first iteration - deepcopy (#131)
* first iteration - deepcopy Signed-off-by: spolti <[email protected]> * review additions Signed-off-by: spolti <[email protected]> * add builders for the object types Signed-off-by: spolti <[email protected]> Signed-off-by: spolti <[email protected]>
1 parent bb8e1d9 commit a073b0e

30 files changed

+1946
-35
lines changed

.github/workflows/Go-SDK-PR-Check.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ jobs:
5757
make addheaders
5858
changed_files=$(git status -s | grep -v 'go.mod\|go.sum\|tools.mod\|tools.sum' || :)
5959
[[ -z "$changed_files" ]] || (printf "Some files are missing the headers: \n$changed_files\n Did you run 'make lint' before sending the PR" && exit 1)
60+
- name: Check DeepCopy Generation
61+
run: |
62+
export GOPATH=$(go env GOPATH)
63+
make deepcopy
6064
- name: Check Formatting
6165
run: |
6266
make fmt

.lift.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ignoreFiles = """
2+
model/zz_generated.deepcopy.go
3+
"""

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ lint:
1414

1515
.PHONY: test
1616
coverage="false"
17-
test:
17+
test: deepcopy
1818
make lint
1919
@go test ./...
20+
21+
.PHONY: deepcopy
22+
deepcopy: $(DEEPCOPY_GEN) ## Download deeepcopy-gen locally if necessary.
23+
./hack/deepcopy-gen.sh deepcopy

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/pkg/errors v0.9.1
88
github.com/senseyeio/duration v0.0.0-20180430131211-7c2a214ada46
99
github.com/stretchr/testify v1.7.0
10+
gopkg.in/yaml.v3 v3.0.1
1011
k8s.io/apimachinery v0.25.1
1112
sigs.k8s.io/yaml v1.3.0
1213
)
@@ -24,7 +25,6 @@ require (
2425
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
2526
golang.org/x/text v0.3.7 // indirect
2627
gopkg.in/yaml.v2 v2.4.0 // indirect
27-
gopkg.in/yaml.v3 v3.0.1 // indirect
2828
k8s.io/klog/v2 v2.70.1 // indirect
2929
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
3030
)

hack/boilerplate.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2022 The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.

hack/deepcopy-gen.sh

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2022 The Serverless Workflow Specification Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# retrieved from https://github.com/kubernetes/code-generator/blob/master/generate-internal-groups.sh
17+
# and adapted to only install and run the deepcopy-gen
18+
19+
set -o errexit
20+
set -o nounset
21+
set -o pipefail
22+
23+
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
24+
echo "Script root is $SCRIPT_ROOT"
25+
26+
GENS="$1"
27+
shift 1
28+
29+
(
30+
# To support running this script from anywhere, first cd into this directory,
31+
# and then install with forced module mode on and fully qualified name.
32+
# make sure your GOPATH env is properly set.
33+
# it will go under $GOPATH/bin
34+
cd "$(dirname "${0}")"
35+
GO111MODULE=on go install k8s.io/code-generator/cmd/deepcopy-gen@latest
36+
)
37+
38+
function codegen::join() { local IFS="$1"; shift; echo "$*"; }
39+
40+
if [ "${GENS}" = "all" ] || grep -qw "deepcopy" <<<"${GENS}"; then
41+
echo "Generating deepcopy funcs"
42+
export GO111MODULE=on
43+
# for debug purposes, increase the log level by updating the -v flag to higher numbers, e.g. -v 4
44+
"${GOPATH}/bin/deepcopy-gen" -v 1 \
45+
--input-dirs ./model -O zz_generated.deepcopy \
46+
--go-header-file "${SCRIPT_ROOT}/hack/boilerplate.txt" \
47+
"$@"
48+
fi

model/action.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ type FunctionRef struct {
6969
RefName string `json:"refName" validate:"required"`
7070
// Function arguments
7171
// TODO: validate it as required if function type is graphql
72-
Arguments map[string]interface{} `json:"arguments,omitempty"`
72+
Arguments map[string]Object `json:"arguments,omitempty"`
7373
// String containing a valid GraphQL selection set
7474
// TODO: validate it as required if function type is graphql
7575
SelectionSet string `json:"selectionSet,omitempty"`
76-
7776
// Invoke specifies if the subflow should be invoked sync or async.
7877
// Defaults to sync.
7978
Invoke InvokeKind `json:"invoke,omitempty" validate:"required,oneof=async sync"`

model/auth.go

+15
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ type AuthProperties interface {
110110
GetMetadata() *Metadata
111111
// GetSecret ...
112112
GetSecret() string
113+
// DeepCopyAuthProperties fixes in.Properties.DeepCopyAuthProperties undefined (type AuthProperties has no
114+
// field or method DeepCopyAuthProperties)
115+
DeepCopyAuthProperties() AuthProperties
113116
}
114117

115118
// BaseAuthProperties ...
@@ -148,6 +151,10 @@ func (b *BaseAuthProperties) GetSecret() string {
148151
return b.Secret
149152
}
150153

154+
func (b *BasicAuthProperties) DeepCopyAuthProperties() AuthProperties {
155+
return b
156+
}
157+
151158
// BasicAuthProperties Basic Auth Info
152159
type BasicAuthProperties struct {
153160
BaseAuthProperties
@@ -186,6 +193,10 @@ type BearerAuthProperties struct {
186193
Token string `json:"token" validate:"required"`
187194
}
188195

196+
func (b *BearerAuthProperties) DeepCopyAuthProperties() AuthProperties {
197+
return b
198+
}
199+
189200
// UnmarshalJSON ...
190201
func (b *BearerAuthProperties) UnmarshalJSON(data []byte) error {
191202
properties := make(map[string]json.RawMessage)
@@ -232,6 +243,10 @@ type OAuth2AuthProperties struct {
232243
RequestedIssuer string `json:"requestedIssuer,omitempty" validate:"omitempty,min=1"`
233244
}
234245

246+
func (b *OAuth2AuthProperties) DeepCopyAuthProperties() AuthProperties {
247+
return b
248+
}
249+
235250
// TODO: use reflection to unmarshal the keys and think on a generic approach to handle them
236251

237252
// UnmarshalJSON ...

model/callback_state.go

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ type CallbackState struct {
2828
EventDataFilter EventDataFilter `json:"eventDataFilter,omitempty"`
2929
}
3030

31+
func (in *CallbackState) DeepCopyState() State {
32+
return in
33+
}
34+
3135
// CallbackStateTimeout defines timeout settings for callback state
3236
type CallbackStateTimeout struct {
3337
StateExecTimeout *StateExecTimeout `json:"stateExecTimeout,omitempty"`

model/common.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ type Common struct {
2121
}
2222

2323
// Metadata information
24-
type Metadata map[string]interface{}
24+
type Metadata map[string]Object

model/delay_state.go

+4
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ type DelayState struct {
2020
// Amount of time (ISO 8601 format) to delay
2121
TimeDelay string `json:"timeDelay" validate:"required,iso8601duration"`
2222
}
23+
24+
func (in *DelayState) DeepCopyState() State {
25+
return in
26+
}

model/doc.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2022 The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package model
16+
17+
// +k8s:deepcopy-gen=package
18+
// +k8s:deepcopy-gen:nonpointer-interfaces=true

model/event.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
// EventKindConsumed means the event continuation of workflow instance execution
3131
EventKindConsumed EventKind = "consumed"
3232

33-
// EventKindProduced means the event was created during worflow instance execution
33+
// EventKindProduced means the event was created during workflow instance execution
3434
EventKindProduced EventKind = "produced"
3535
)
3636

@@ -98,13 +98,11 @@ type EventRef struct {
9898
ResultEventRef string `json:"resultEventRef" validate:"required"`
9999
// ResultEventTimeout defines maximum amount of time (ISO 8601 format) to wait for the result event. If not defined it be set to the actionExecutionTimeout
100100
ResultEventTimeout string `json:"resultEventTimeout,omitempty" validate:"omitempty,iso8601duration"`
101-
// TODO: create StringOrMap structure
102101
// If string type, an expression which selects parts of the states data output to become the data (payload) of the event referenced by 'triggerEventRef'.
103102
// If object type, a custom object to become the data (payload) of the event referenced by 'triggerEventRef'.
104-
Data interface{} `json:"data,omitempty"`
103+
Data Object `json:"data,omitempty"`
105104
// Add additional extension context attributes to the produced event
106-
ContextAttributes map[string]interface{} `json:"contextAttributes,omitempty"`
107-
105+
ContextAttributes map[string]Object `json:"contextAttributes,omitempty"`
108106
// Invoke specifies if the subflow should be invoked sync or async.
109107
// Defaults to sync.
110108
Invoke InvokeKind `json:"invoke,omitempty" validate:"required,oneof=async sync"`

model/event_state.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ type EventState struct {
3434
Timeouts *EventStateTimeout `json:"timeouts,omitempty"`
3535
}
3636

37+
func (e *EventState) DeepCopyState() State {
38+
return e
39+
}
40+
3741
type eventStateForUnmarshal EventState
3842

3943
// UnmarshalJSON unmarshal EventState object from json bytes
@@ -50,7 +54,7 @@ func (e *EventState) UnmarshalJSON(data []byte) error {
5054
return nil
5155
}
5256

53-
// OnEvents define which actions are be be performed for the one or more events.
57+
// OnEvents define which actions are be performed for the one or more events.
5458
type OnEvents struct {
5559
// References one or more unique event names in the defined workflow events
5660
EventRefs []string `json:"eventRefs" validate:"required,min=1"`

model/foreach_state.go

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ type ForEachState struct {
6161
Mode ForEachModeType `json:"mode,omitempty"`
6262
}
6363

64+
func (f *ForEachState) DeepCopyState() State {
65+
return f
66+
}
67+
6468
type forEachStateForUnmarshal ForEachState
6569

6670
func (f *ForEachState) UnmarshalJSON(data []byte) error {

model/inject_state.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ package model
1818
type InjectState struct {
1919
BaseState
2020
// JSON object which can be set as states data input and can be manipulated via filters
21-
Data map[string]interface{} `json:"data" validate:"required,min=1"`
21+
Data map[string]Object `json:"data" validate:"required,min=1"`
2222
// State specific timeouts
2323
Timeouts *InjectStateTimeout `json:"timeouts,omitempty"`
2424
}
2525

26+
func (in *InjectState) DeepCopyState() State {
27+
return in
28+
}
29+
2630
// InjectStateTimeout defines timeout settings for inject state
2731
type InjectStateTimeout struct {
2832
StateExecTimeout *StateExecTimeout `json:"stateExecTimeout,omitempty"`

0 commit comments

Comments
 (0)