@@ -97,12 +97,9 @@ func DefaultImage() string {
9797 return image
9898}
9999
100- func validMailAddress (address string ) (string , bool ) {
101- addr , err := mail .ParseAddress (address )
102- if err != nil {
103- return "" , false
104- }
105- return addr .Address , true
100+ func validMailAddress (address string ) bool {
101+ _ , err := mail .ParseAddress (address )
102+ return err == nil
106103}
107104
108105func Install (ctx context.Context , image string , opts * Options ) error {
@@ -117,9 +114,23 @@ func Install(ctx context.Context, image string, opts *Options) error {
117114 }
118115 }
119116
117+ c , err := k8sclient .Default ()
118+ if err != nil {
119+ return err
120+ }
121+
122+ serverConf , err := config .Incomplete (ctx , c )
123+ if err != nil {
124+ return err
125+ }
126+
120127 // Require E-Mail address when using Let's Encrypt production
121128 if opts .Config .LetsEncrypt != nil && * opts .Config .LetsEncrypt == "enabled" {
122- if opts .Config .LetsEncryptTOSAgree == nil || ! * opts .Config .LetsEncryptTOSAgree {
129+ agreed := opts .Config .GetLetsEncryptTOSAgree ()
130+ if ! agreed && opts .Config .LetsEncryptTOSAgree == nil && serverConf .GetLetsEncryptTOSAgree () {
131+ agreed = true
132+ }
133+ if ! agreed {
123134 ok , err := prompt .Bool ("You are choosing to enable Let's Encrypt for TLS certificates. To do so, you must agree to their Terms of Service: https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf\n Tip: use --lets-encrypt-tos-agree to skip this prompt\n Do you agree to Let's Encrypt TOS?" , false )
124135 if err != nil {
125136 return err
@@ -129,7 +140,7 @@ func Install(ctx context.Context, image string, opts *Options) error {
129140 }
130141 opts .Config .LetsEncryptTOSAgree = & ok
131142 }
132- if opts .Config .LetsEncryptEmail == "" {
143+ if opts .Config .LetsEncryptEmail == "" && serverConf . LetsEncryptEmail == "" {
133144 result , err := pterm .DefaultInteractiveTextInput .WithMultiLine (false ).Show ("Enter your email address for Let's Encrypt" )
134145 if err != nil {
135146 return err
@@ -141,11 +152,13 @@ func Install(ctx context.Context, image string, opts *Options) error {
141152
142153 // Validate E-Mail address provided for Let's Encrypt registration
143154 if opts .Config .LetsEncryptEmail != "" || (opts .Config .LetsEncrypt != nil && * opts .Config .LetsEncrypt == "enabled" ) {
144- mail , ok := validMailAddress (opts .Config .LetsEncryptEmail )
145- if ! ok {
155+ email := opts .Config .LetsEncryptEmail
156+ if email == "" {
157+ email = serverConf .LetsEncryptEmail
158+ }
159+ if ! validMailAddress (email ) {
146160 return fmt .Errorf ("invalid email address '%s' provided for Let's Encrypt" , opts .Config .LetsEncryptEmail )
147161 }
148- opts .Config .LetsEncryptEmail = mail
149162 }
150163
151164 opts = opts .complete ()
@@ -170,17 +183,12 @@ func Install(ctx context.Context, image string, opts *Options) error {
170183 }
171184 }
172185
173- kclient , err := k8sclient .Default ()
174- if err != nil {
175- return err
176- }
177-
178186 var installIngressController bool
179- if ok , err := config .IsDockerDesktop (ctx , kclient ); err != nil {
187+ if ok , err := config .IsDockerDesktop (ctx , c ); err != nil {
180188 return err
181189 } else if ok {
182190 if opts .Config .IngressClassName == nil {
183- installIngressController , err = missingIngressClass (ctx , kclient )
191+ installIngressController , err = missingIngressClass (ctx , c )
184192 if err != nil {
185193 return err
186194 }
@@ -195,10 +203,6 @@ func Install(ctx context.Context, image string, opts *Options) error {
195203 return err
196204 }
197205
198- c , err := k8sclient .Default ()
199- if err != nil {
200- return err
201- }
202206 if err := config .Set (ctx , c , & opts .Config ); err != nil {
203207 return err
204208 }
@@ -209,28 +213,23 @@ func Install(ctx context.Context, image string, opts *Options) error {
209213 }
210214 s .Success ()
211215
212- kclient , err = k8sclient .Default ()
213- if err != nil {
214- return err
215- }
216-
217216 s = opts .Progress .New (fmt .Sprintf ("Installing APIServer and Controller (image %s)" , image ))
218- if err := applyDeployments (ctx , image , * opts .APIServerReplicas , * opts .ControllerReplicas , apply , kclient ); err != nil {
217+ if err := applyDeployments (ctx , image , * opts .APIServerReplicas , * opts .ControllerReplicas , apply , c ); err != nil {
219218 return s .Fail (err )
220219 }
221220 s .Success ()
222221
223222 if installIngressController {
224- if err := installTraefik (ctx , opts .Progress , kclient , apply ); err != nil {
223+ if err := installTraefik (ctx , opts .Progress , c , apply ); err != nil {
225224 return err
226225 }
227226 }
228227
229- if err := waitController (ctx , opts .Progress , * opts .ControllerReplicas , image , kclient ); err != nil {
228+ if err := waitController (ctx , opts .Progress , * opts .ControllerReplicas , image , c ); err != nil {
230229 return err
231230 }
232231
233- if err := waitAPI (ctx , opts .Progress , * opts .APIServerReplicas , image , kclient ); err != nil {
232+ if err := waitAPI (ctx , opts .Progress , * opts .APIServerReplicas , image , c ); err != nil {
234233 return err
235234 }
236235
0 commit comments