File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,8 @@ limitations under the License.
1717package v1alpha1
1818
1919import (
20+ "encoding/json"
21+
2022 corev1 "k8s.io/api/core/v1"
2123 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2224)
@@ -259,6 +261,27 @@ type EnvVarCfg struct {
259261 ValueFrom * corev1.EnvVarSource `json:"valueFrom,omitempty"`
260262}
261263
264+ // UnmarshalJSON implements json.Unmarshaler for EnvVarCfg.
265+ // It allows unmarshalling a plain string into the Value field, or an object into Value/ValueFrom.
266+ func (e * EnvVarCfg ) UnmarshalJSON (data []byte ) error {
267+ // Try to unmarshal as a string
268+ var str string
269+ if err := json .Unmarshal (data , & str ); err == nil {
270+ e .Value = str
271+ return nil
272+ }
273+
274+ // If not a string, try to unmarshal as an object
275+ type rawEnvVarCfg EnvVarCfg // Use a new type to avoid infinite recursion
276+ var raw rawEnvVarCfg
277+ if err := json .Unmarshal (data , & raw ); err != nil {
278+ return err
279+ }
280+ e .Value = raw .Value
281+ e .ValueFrom = raw .ValueFrom
282+ return nil
283+ }
284+
262285// InitContainerConfig defines the configuration for the init container.
263286type InitContainerConfig struct {
264287 // Image defines the full image reference for the init container.
You can’t perform that action at this time.
0 commit comments