github.com/argoproj/argo-events@v1.9.1/sensors/triggers/fetch.go (about) 1 /* 2 Copyright 2020 BlackRock, Inc. 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 17 package triggers 18 19 import ( 20 "fmt" 21 22 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 23 24 "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1" 25 "github.com/argoproj/argo-events/sensors/artifacts" 26 ) 27 28 func FetchKubernetesResource(source *v1alpha1.ArtifactLocation) (*unstructured.Unstructured, error) { 29 if source == nil { 30 return nil, fmt.Errorf("trigger source for k8s is empty") 31 } 32 creds, err := artifacts.GetCredentials(source) 33 if err != nil { 34 return nil, err 35 } 36 reader, err := artifacts.GetArtifactReader(source, creds) 37 if err != nil { 38 return nil, err 39 } 40 41 // uObj will either hold the resource definition stored in the trigger or just 42 // a stub to provide enough information to fetch the object from K8s cluster 43 uObj, err := artifacts.FetchArtifact(reader) 44 if err != nil { 45 return nil, err 46 } 47 return uObj, nil 48 }