forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Removed usage of redundant GVR fields in k8s/workflow triggers (a…
…rgoproj#1333) * removed usage of redundent group,version,resource fields in k8s/workflow triggers Signed-off-by: Daniel Soifer <[email protected]> * fix Signed-off-by: Daniel Soifer <[email protected]>
- Loading branch information
1 parent
f763e68
commit 24ef7c6
Showing
9 changed files
with
230 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Sensor | ||
metadata: | ||
name: webhook | ||
spec: | ||
template: | ||
serviceAccountName: operate-workflow-sa | ||
dependencies: | ||
- name: test-dep | ||
eventSourceName: webhook | ||
eventName: example | ||
triggers: | ||
- template: | ||
name: argo-workflow-trigger | ||
argoWorkflow: | ||
operation: submit | ||
source: | ||
resource: | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
name: special-trigger | ||
spec: | ||
entrypoint: whalesay | ||
arguments: | ||
parameters: | ||
- name: message | ||
# the value will get overridden by event payload from test-dep | ||
value: hello world | ||
templates: | ||
- name: whalesay | ||
inputs: | ||
parameters: | ||
- name: message | ||
container: | ||
image: docker/whalesay:latest | ||
command: [cowsay] | ||
args: ["{{inputs.parameters.message}}"] | ||
parameters: | ||
- src: | ||
dependencyName: test-dep | ||
dataKey: body | ||
dest: spec.arguments.parameters.0.value |
62 changes: 62 additions & 0 deletions
62
examples/sensors/trigger-standard-k8s-resource-shortened.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Sensor | ||
metadata: | ||
name: webhook | ||
spec: | ||
template: | ||
serviceAccountName: operate-workflow-sa | ||
dependencies: | ||
- name: test-dep | ||
eventSourceName: webhook | ||
eventName: example | ||
triggers: | ||
- template: | ||
name: webhook-pod-trigger | ||
k8s: | ||
operation: create | ||
source: | ||
resource: | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
generateName: hello-world- | ||
spec: | ||
containers: | ||
- name: hello-container | ||
args: | ||
- "hello-world" | ||
command: | ||
- cowsay | ||
image: "docker/whalesay:latest" | ||
parameters: | ||
- src: | ||
dependencyName: test-dep | ||
dataKey: body | ||
dest: spec.containers.0.args.0 | ||
# - template: | ||
# name: webhook-deployment-trigger | ||
# k8s: | ||
# operation: create | ||
# source: | ||
# resource: | ||
# apiVersion: apps/v1 | ||
# kind: Deployment | ||
# metadata: | ||
# generateName: hello-world- | ||
# spec: | ||
# replicas: 1 | ||
# selector: | ||
# matchLabels: | ||
# app: mydeploy | ||
# template: | ||
# metadata: | ||
# labels: | ||
# app: mydeploy | ||
# spec: | ||
# containers: | ||
# - name: hello-container | ||
# args: | ||
# - "hello world" | ||
# command: | ||
# - cowsay | ||
# image: "docker/whalesay:latest" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Sensor | ||
metadata: | ||
name: webhook | ||
spec: | ||
template: | ||
serviceAccountName: operate-workflow-sa | ||
dependencies: | ||
- name: test-dep | ||
eventSourceName: webhook | ||
eventName: example | ||
triggers: | ||
- template: | ||
name: webhook-workflow-trigger | ||
k8s: | ||
operation: create | ||
source: | ||
resource: | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: webhook- | ||
spec: | ||
entrypoint: whalesay | ||
arguments: | ||
parameters: | ||
- name: message | ||
# the value will get overridden by event payload from test-dep | ||
value: hello world | ||
templates: | ||
- name: whalesay | ||
inputs: | ||
parameters: | ||
- name: message | ||
container: | ||
image: docker/whalesay:latest | ||
command: [cowsay] | ||
args: ["{{inputs.parameters.message}}"] | ||
parameters: | ||
- src: | ||
dependencyName: test-dep | ||
dataKey: body | ||
dest: spec.arguments.parameters.0.value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Copyright 2020 BlackRock, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package triggers | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
func GetGroupVersionResource(obj *unstructured.Unstructured) schema.GroupVersionResource { | ||
gvk := obj.GroupVersionKind() | ||
return schema.GroupVersionResource{ | ||
Group: gvk.Group, | ||
Version: gvk.Version, | ||
Resource: fmt.Sprintf("%ss", strings.ToLower(gvk.Kind)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright 2020 BlackRock, Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package triggers | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetGroupVersionResource(t *testing.T) { | ||
deployment := newUnstructured("apps/v1", "Deployment", "fake", "test") | ||
expectedGVR := schema.GroupVersionResource{ | ||
Group: "apps", | ||
Version: "v1", | ||
Resource: "deployments", | ||
} | ||
result := GetGroupVersionResource(deployment) | ||
assert.Equal(t, expectedGVR, result) | ||
} |