-
Notifications
You must be signed in to change notification settings - Fork 244
/
machine_output.go
101 lines (90 loc) · 2.69 KB
/
machine_output.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package preference
import (
"reflect"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
prefAPIVersion = "odo.dev/v1alpha1"
prefKind = "PreferenceList"
)
type PreferenceList struct {
metav1.TypeMeta `json:",inline"`
Items []PreferenceItem `json:"items,omitempty"`
}
type PreferenceItem struct {
Name string
Value interface{} // The value set by the user, this will be nil if the user hasn't set it
Default interface{} // default value of the preference if the user hasn't set the value
Type string // the type of the preference, possible values int, string, bool
Description string // The description of the preference
}
func NewPreferenceList(prefInfo PreferenceInfo) PreferenceList {
return PreferenceList{
TypeMeta: metav1.TypeMeta{
APIVersion: prefAPIVersion,
Kind: prefKind,
},
Items: toPreferenceItems(prefInfo),
}
}
func toPreferenceItems(prefInfo PreferenceInfo) []PreferenceItem {
odoSettings := prefInfo.OdoSettings
return []PreferenceItem{
{
Name: UpdateNotificationSetting,
Value: odoSettings.UpdateNotification,
Default: true,
Type: getType(prefInfo.GetUpdateNotification()), // use the Getter here to determine type
Description: UpdateNotificationSettingDescription,
},
{
Name: NamePrefixSetting,
Value: odoSettings.NamePrefix,
Default: "",
Type: getType(prefInfo.GetNamePrefix()),
Description: NamePrefixSettingDescription,
},
{
Name: TimeoutSetting,
Value: odoSettings.Timeout,
Default: DefaultTimeout,
Type: getType(prefInfo.GetTimeout()),
Description: TimeoutSettingDescription,
},
{
Name: BuildTimeoutSetting,
Value: odoSettings.BuildTimeout,
Default: DefaultBuildTimeout,
Type: getType(prefInfo.GetBuildTimeout()),
Description: BuildTimeoutSettingDescription,
},
{
Name: PushTimeoutSetting,
Value: odoSettings.PushTimeout,
Default: DefaultPushTimeout,
Type: getType(prefInfo.GetPushTimeout()),
Description: PushTimeoutSettingDescription,
},
{
Name: ExperimentalSetting,
Value: odoSettings.Experimental,
Default: false,
Type: getType(prefInfo.GetExperimental()),
Description: ExperimentalDescription,
},
{
Name: PushTargetSetting,
Value: odoSettings.PushTarget,
Default: KubePushTarget,
Type: getType(prefInfo.GetPushTarget()),
Description: PushTargetDescription,
},
}
}
func getType(v interface{}) string {
rv := reflect.ValueOf(v)
if rv.Kind() == reflect.Ptr {
return rv.Elem().Kind().String()
}
return rv.Kind().String()
}