Skip to content

Commit

Permalink
fix: Validate the type of configmap before loading parameters. Fixes #…
Browse files Browse the repository at this point in the history
…7312 (#7314)

Signed-off-by: Yuan Tang <terrytangyuan@gmail.com>
  • Loading branch information
terrytangyuan authored and sarabala1979 committed Dec 15, 2021
1 parent a142ac2 commit 6bcedb1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion util/configmap.go → workflow/common/configmap.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package util
package common

import (
"fmt"
Expand All @@ -18,6 +18,11 @@ func GetConfigMapValue(configMapInformer cache.SharedIndexInformer, namespace, n
if !ok {
return "", fmt.Errorf("unable to convert object %s to configmap when syncing ConfigMaps", name)
}
if cmType := cm.Labels[LabelKeyConfigMapType]; cmType != LabelValueTypeConfigMapParameter {
return "", fmt.Errorf(
"ConfigMap '%s' needs to have the label %s: %s to load parameters",
name, LabelKeyConfigMapType, LabelValueTypeConfigMapParameter)
}
cmValue, ok := cm.Data[key]
if !ok {
return "", fmt.Errorf("ConfigMap '%s' does not have the key '%s'", name, key)
Expand Down
2 changes: 1 addition & 1 deletion workflow/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func ProcessArgs(tmpl *wfv1.Template, args wfv1.ArgumentsProvider, globalParams,
}
if inParam.ValueFrom != nil && inParam.ValueFrom.ConfigMapKeyRef != nil {
if configMapInformer != nil {
cmValue, err := util.GetConfigMapValue(configMapInformer, namespace, inParam.ValueFrom.ConfigMapKeyRef.Name, inParam.ValueFrom.ConfigMapKeyRef.Key)
cmValue, err := GetConfigMapValue(configMapInformer, namespace, inParam.ValueFrom.ConfigMapKeyRef.Name, inParam.ValueFrom.ConfigMapKeyRef.Key)
if err != nil {
return nil, errors.Errorf(errors.CodeBadRequest, "unable to retrieve inputs.parameters.%s from ConfigMap: %s", inParam.Name, err)
}
Expand Down
2 changes: 1 addition & 1 deletion workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func (woc *wfOperationCtx) setGlobalParameters(executionParameters wfv1.Argument
woc.globalParams["workflow.parameters."+param.Name] = param.Value.String()
} else if param.ValueFrom != nil {
if param.ValueFrom.ConfigMapKeyRef != nil {
cmValue, err := util.GetConfigMapValue(woc.controller.configMapInformer, woc.wf.ObjectMeta.Namespace, param.ValueFrom.ConfigMapKeyRef.Name, param.ValueFrom.ConfigMapKeyRef.Key)
cmValue, err := common.GetConfigMapValue(woc.controller.configMapInformer, woc.wf.ObjectMeta.Namespace, param.ValueFrom.ConfigMapKeyRef.Name, param.ValueFrom.ConfigMapKeyRef.Key)
if err != nil {
return fmt.Errorf("failed to set global parameter %s from configmap with name %s and key %s: %w",
param.Name, param.ValueFrom.ConfigMapKeyRef.Name, param.ValueFrom.ConfigMapKeyRef.Key, err)
Expand Down

0 comments on commit 6bcedb1

Please sign in to comment.