Skip to content

Commit 90c4f65

Browse files
authoredMar 12, 2024··
Merge pull request #175 from spinkube/dani/fix-panic
runtimeconfig: Fix a Panic when an empty value is desired
2 parents dafe776 + 0ff0866 commit 90c4f65

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed
 

‎internal/runtimeconfig/types.go

+17-15
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,24 @@ func renderOptionsIntoMap(typeOpt, namespace string,
100100
var value string
101101
if opt.Value != "" {
102102
value = opt.Value
103-
} else if cmKeyRef := opt.ValueFrom.ConfigMapKeyRef; cmKeyRef != nil {
104-
cm, ok := configMaps[types.NamespacedName{Name: cmKeyRef.Name, Namespace: namespace}]
105-
if !ok {
106-
// This error shouldn't happen - we validate dependencies ahead of time, add this as a fallback error
107-
return nil, fmt.Errorf("unmet dependency while building config: configmap (%s/%s) not found", namespace, cmKeyRef.Name)
103+
} else if valueFrom := opt.ValueFrom; valueFrom != nil {
104+
if cmKeyRef := valueFrom.ConfigMapKeyRef; cmKeyRef != nil {
105+
cm, ok := configMaps[types.NamespacedName{Name: cmKeyRef.Name, Namespace: namespace}]
106+
if !ok {
107+
// This error shouldn't happen - we validate dependencies ahead of time, add this as a fallback error
108+
return nil, fmt.Errorf("unmet dependency while building config: configmap (%s/%s) not found", namespace, cmKeyRef.Name)
109+
}
110+
111+
value = cm.Data[cmKeyRef.Key]
112+
} else if secKeyRef := valueFrom.SecretKeyRef; secKeyRef != nil {
113+
sec, ok := secrets[types.NamespacedName{Name: secKeyRef.Name, Namespace: namespace}]
114+
if !ok {
115+
// This error shouldn't happen - we validate dependencies ahead of time, add this as a fallback error
116+
return nil, fmt.Errorf("unmet dependency while building config: secret (%s/%s) not found", namespace, secKeyRef.Name)
117+
}
118+
119+
value = string(sec.Data[secKeyRef.Key])
108120
}
109-
110-
value = cm.Data[cmKeyRef.Key]
111-
} else if secKeyRef := opt.ValueFrom.SecretKeyRef; secKeyRef != nil {
112-
sec, ok := secrets[types.NamespacedName{Name: secKeyRef.Name, Namespace: namespace}]
113-
if !ok {
114-
// This error shouldn't happen - we validate dependencies ahead of time, add this as a fallback error
115-
return nil, fmt.Errorf("unmet dependency while building config: secret (%s/%s) not found", namespace, secKeyRef.Name)
116-
}
117-
118-
value = string(sec.Data[secKeyRef.Key])
119121
}
120122

121123
options[opt.Name] = secret.String(value)

0 commit comments

Comments
 (0)
Please sign in to comment.