Skip to content

Commit

Permalink
fix: Added cluster resources support in k8s trigger (#1323)
Browse files Browse the repository at this point in the history
* added cluster resources support in k8s trigger

Signed-off-by: daniel-codefresh <daniel.soifer@codefresh.io>
Signed-off-by: Daniel Soifer <daniel.soifer@codefresh.io>

* added Codefresh to USERS.md

Signed-off-by: daniel-codefresh <daniel.soifer@codefresh.io>
Signed-off-by: Daniel Soifer <daniel.soifer@codefresh.io>

Co-authored-by: Derek Wang <whynowy@gmail.com>
  • Loading branch information
daniel-codefresh and whynowy authored Aug 31, 2021
1 parent d8cf6e0 commit dde50f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions USERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Organizations below are **officially** using Argo Events. Please send a PR with
1. [BioBox Analytics](https://biobox.io)
1. [BlackRock](https://www.blackrock.com/)
1. [Canva](https://www.canva.com/)
1. [Codefresh](https://codefresh.io/)
1. [DevSamurai](https://www.devsamurai.com/)
1. [Fairwinds](https://fairwinds.com/)
1. [Greenhouse Software](https://www.greenhouse.io/)
Expand Down
20 changes: 15 additions & 5 deletions sensors/triggers/standard-k8s/standar-k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ import (
"github.com/argoproj/argo-events/sensors/triggers"
)

var clusterResources = map[string]bool{
"namespaces": true,
"nodes": true,
}

// StandardK8STrigger implements Trigger interface for standard Kubernetes resources
type StandardK8sTrigger struct {
// K8sClient is kubernetes client
Expand Down Expand Up @@ -110,8 +115,10 @@ func (k8sTrigger *StandardK8sTrigger) FetchResource(ctx context.Context) (interf
if objName == "" {
return nil, fmt.Errorf("resource name must be specified for fetching live object")
}

objNamespace := uObj.GetNamespace()
if objNamespace == "" {
_, isClusterResource := clusterResources[trigger.Template.K8s.GroupVersionResource.Resource]
if objNamespace == "" && !isClusterResource {
return nil, fmt.Errorf("resource namespace must be specified for fetching live object")
}
rObj, err = k8sTrigger.namespableDynamicClient.Namespace(objNamespace).Get(ctx, objName, metav1.GetOptions{})
Expand Down Expand Up @@ -145,10 +152,13 @@ func (k8sTrigger *StandardK8sTrigger) Execute(ctx context.Context, events map[st
return nil, errors.New("failed to interpret the trigger resource")
}

namespace := obj.GetNamespace()
// Defaults to sensor's namespace
if namespace == "" {
namespace = k8sTrigger.Sensor.Namespace
namespace := ""
if _, isClusterResource := clusterResources[trigger.Template.K8s.GroupVersionResource.Resource]; !isClusterResource {
namespace = obj.GetNamespace()
// Defaults to sensor's namespace
if namespace == "" {
namespace = k8sTrigger.Sensor.Namespace
}
}
obj.SetNamespace(namespace)

Expand Down

0 comments on commit dde50f2

Please sign in to comment.