@@ -56,9 +56,12 @@ type InstallPreferences struct {
56
56
}
57
57
58
58
func runApplyCommandE (command * cobra.Command , _ []string ) error {
59
-
60
59
prefs := InstallPreferences {}
61
60
61
+ if os .Getuid () == 0 {
62
+ return fmt .Errorf ("do not run this tool as root, or on your server. Run it from your own client remotely" )
63
+ }
64
+
62
65
files , err := command .Flags ().GetStringArray ("file" )
63
66
if err != nil {
64
67
return err
@@ -85,49 +88,40 @@ func runApplyCommandE(command *cobra.Command, _ []string) error {
85
88
return fmt .Errorf ("provide one or more --file arguments" )
86
89
}
87
90
88
- if os .Getuid () == 0 {
89
- return fmt .Errorf ("do not run this tool as root, or on your server. Run it from your own client remotely" )
90
- }
91
-
92
91
plans := []types.Plan {}
93
-
94
- log .Printf ("Loading %d plan(s)..OK.\n " , len (files ))
95
92
for _ , yamlFile := range files {
96
93
97
- yamlBytes , yamlErr := ioutil .ReadFile (yamlFile )
98
- if yamlErr != nil {
99
- return fmt .Errorf ("loading --file %s gave error: %s" , yamlFile , yamlErr .Error ())
94
+ yamlBytes , err := ioutil .ReadFile (yamlFile )
95
+ if err != nil {
96
+ return fmt .Errorf ("loading --file %s gave error: %s" , yamlFile , err .Error ())
100
97
}
101
98
102
99
plan := types.Plan {}
103
- unmarshalErr := yaml .Unmarshal (yamlBytes , & plan )
104
- if unmarshalErr != nil {
105
- return fmt .Errorf ("unmarshal of --file %s gave error: %s" , yamlFile , unmarshalErr .Error ())
100
+ if err := yaml .Unmarshal (yamlBytes , & plan );err != nil {
101
+ return fmt .Errorf ("unmarshal of --file %s gave error: %s" , yamlFile , err .Error ())
106
102
}
103
+
107
104
log .Printf ("%s loaded\n " , yamlFile )
108
105
plans = append (plans , plan )
109
106
}
110
107
111
- planMerged , mergeErr := types . MergePlans ( plans )
112
-
113
- if mergeErr != nil {
114
- return mergeErr
108
+ log . Printf ( "Loaded %d plan(s) \n " , len ( files ) )
109
+ planMerged , err := types . MergePlans ( plans )
110
+ if err != nil {
111
+ return err
115
112
}
116
113
117
114
if printPlan {
118
-
119
115
out , _ := yaml .Marshal (planMerged )
120
116
fmt .Println (string (out ))
121
-
122
117
os .Exit (0 )
123
118
}
124
119
125
120
plan := * planMerged
126
121
127
- var featuresErr error
128
- plan , featuresErr = filterFeatures (plan )
129
- if featuresErr != nil {
130
- return fmt .Errorf ("error while retreiving features: %s" , featuresErr .Error ())
122
+ plan , err = filterFeatures (plan )
123
+ if err != nil {
124
+ return fmt .Errorf ("error while retreiving features: %s" , err .Error ())
131
125
}
132
126
133
127
clientArch , clientOS := env .GetClientArch ()
@@ -138,8 +132,7 @@ func runApplyCommandE(command *cobra.Command, _ []string) error {
138
132
fmt .Printf ("User dir: %s\n " , userDir )
139
133
140
134
install := []string {"kubectl" , "helm" , "faas-cli" , "arkade" , "kubeseal" }
141
- err = getTools (clientArch , clientOS , userDir , install )
142
- if err != nil {
135
+ if err := getTools (clientArch , clientOS , userDir , install ); err != nil {
143
136
return err
144
137
}
145
138
@@ -171,9 +164,8 @@ func runApplyCommandE(command *cobra.Command, _ []string) error {
171
164
}
172
165
173
166
if prefs .SkipCreateSecrets == false {
174
- validateErr := validatePlan (plan )
175
- if validateErr != nil {
176
- panic (validateErr )
167
+ if err := validatePlan (plan ); err != nil {
168
+ return errors .Wrap (err , "validatePlan" )
177
169
}
178
170
}
179
171
0 commit comments