MCPcopy
hub / github.com/argoproj/argo-workflows / resolveArtifact

Method resolveArtifact

workflow/controller/scope.go:90–155  ·  view source on GitHub ↗
(ctx context.Context, art *wfv1.Artifact)

Source from the content-addressed store, hash-verified

88}
89
90func (s *wfScope) resolveArtifact(ctx context.Context, art *wfv1.Artifact) (*wfv1.Artifact, error) {
91 if art == nil || (art.From == "" && art.FromExpression == "") {
92 return nil, nil
93 }
94
95 var err error
96 var val interface{}
97
98 if art.FromExpression != "" {
99 env := env.GetFuncMap(s.scope)
100 program, err := expr.Compile(art.FromExpression, expr.Env(env))
101 if err != nil {
102 return nil, err
103 }
104 val, err = expr.Run(program, env)
105 if err != nil {
106 return nil, err
107 }
108
109 } else {
110 val, err = s.resolveVar(art.From)
111 }
112
113 if err != nil {
114 return nil, err
115 }
116 valArt, ok := val.(wfv1.Artifact)
117 if !ok {
118 // If the workflow refers itself input artifacts in fromExpression, the val type is "*wfv1.Artifact"
119 ptArt, ok := val.(*wfv1.Artifact)
120 if ok {
121 valArt = *ptArt
122 } else {
123 return nil, errors.Errorf(errors.CodeBadRequest, "Variable {{%v}} is not an artifact", art)
124 }
125 }
126
127 if art.SubPath != "" {
128 // Copy resolved artifact pointer before adding subpath
129 copyArt := valArt.DeepCopy()
130
131 subPathAsJSON, err := json.Marshal(art.SubPath)
132 if err != nil {
133 return copyArt, errors.New(errors.CodeBadRequest, "failed to marshal artifact subpath for templating")
134 }
135
136 resolvedSubPathAsJSON, err := template.Replace(ctx, string(subPathAsJSON), s.getParameters(), true)
137 if err != nil {
138 return nil, err
139 }
140
141 var resolvedSubPath string
142 err = json.Unmarshal([]byte(resolvedSubPathAsJSON), &resolvedSubPath)
143 if err != nil {
144 return copyArt, errors.New(errors.CodeBadRequest, "failed to unmarshal artifact subpath for templating")
145 }
146
147 err = copyArt.AppendToKey(resolvedSubPath)

Calls 11

resolveVarMethod · 0.95
getParametersMethod · 0.95
GetFuncMapFunction · 0.92
ErrorfFunction · 0.92
NewFunction · 0.92
ReplaceFunction · 0.92
AppendToKeyMethod · 0.80
RunMethod · 0.65
DeepCopyMethod · 0.45
MarshalMethod · 0.45
UnmarshalMethod · 0.45

Tested by 2