@@ -42,6 +42,10 @@ type chartConfig struct {
42
42
Version string `json:"version,omitempty" validate:"omitempty"`
43
43
}
44
44
45
+ type dockerRegistry struct {
46
+ Chart * chartConfig `json:"chart,omitempty" validate:"required"`
47
+ }
48
+
45
49
type ingressConfig struct {
46
50
Chart * chartConfig `json:"chart,omitempty" validate:"required"`
47
51
ServiceType string `json:"serviceType,omitempty" validate:"required,eq=NodePort|eq=LoadBalancer|eq=ClusterIP"`
@@ -92,18 +96,19 @@ type imageRegistryConfig struct {
92
96
Username string `json:"username,omitempty" validate:"required"`
93
97
}
94
98
type dispatchInstallConfig struct {
95
- Chart * chartConfig `json:"chart,omitempty" validate:"required"`
96
- Host string `json:"host,omitempty" validate:"required,hostname|ip"`
97
- Port int `json:"port,omitempty" validate:"required"`
98
- Organization string `json:"organization,omitempty" validate:"required"`
99
- Image * imageConfig `json:"image,omitempty" validate:"omitempty"`
100
- Debug bool `json:"debug,omitempty" validate:"omitempty"`
101
- Trace bool `json:"trace,omitempty" validate:"omitempty"`
102
- Database string `json:"database,omitempty" validate:"required,eq=postgres"`
103
- PersistData bool `json:"persistData,omitempty" validate:"omitempty"`
104
- ImageRegistry imageRegistryConfig `json:"imageRegistry,omitempty" validate:"required"`
105
- OAuth2Proxy * oauth2ProxyConfig `json:"oauth2Proxy,omitempty" validate:"required"`
106
- TLS * tlsConfig `json:"tls,omitempty" validate:"required"`
99
+ Chart * chartConfig `json:"chart,omitempty" validate:"required"`
100
+ Host string `json:"host,omitempty" validate:"required,hostname|ip"`
101
+ Port int `json:"port,omitempty" validate:"required"`
102
+ Organization string `json:"organization,omitempty" validate:"required"`
103
+ Image * imageConfig `json:"image,omitempty" validate:"omitempty"`
104
+ Debug bool `json:"debug,omitempty" validate:"omitempty"`
105
+ Trace bool `json:"trace,omitempty" validate:"omitempty"`
106
+ Database string `json:"database,omitempty" validate:"required,eq=postgres"`
107
+ PersistData bool `json:"persistData,omitempty" validate:"omitempty"`
108
+ ImageRegistry * imageRegistryConfig `json:"imageRegistry,omitempty" validate:"omitempty"`
109
+ OAuth2Proxy * oauth2ProxyConfig `json:"oauth2Proxy,omitempty" validate:"required"`
110
+ TLS * tlsConfig `json:"tls,omitempty" validate:"required"`
111
+ SkipAuth bool `json:"skipAuth,omitempty" validate:"omitempty"`
107
112
}
108
113
109
114
type installConfig struct {
@@ -113,6 +118,7 @@ type installConfig struct {
113
118
APIGateway * apiGatewayConfig `json:"apiGateway,omitempty" validate:"required"`
114
119
OpenFaas * openfaasConfig `json:"openfaas,omitempty" validate:"required"`
115
120
DispatchConfig * dispatchInstallConfig `json:"dispatch,omitempty" validate:"required"`
121
+ DockerRegistry * dockerRegistry `json:"dockerRegistry,omitempty" validate:"omitempty"`
116
122
}
117
123
118
124
var (
@@ -303,6 +309,7 @@ func writeConfig(out, errOut io.Writer, configDir string, config *installConfig)
303
309
dispatchConfig .Organization = config .DispatchConfig .Organization
304
310
dispatchConfig .Host = config .DispatchConfig .Host
305
311
dispatchConfig .Port = config .DispatchConfig .Port
312
+ dispatchConfig .SkipAuth = config .DispatchConfig .SkipAuth
306
313
b , err := json .MarshalIndent (dispatchConfig , "" , " " )
307
314
if err != nil {
308
315
return err
@@ -384,6 +391,19 @@ func getK8sServiceNodePort(service, namespace string, https bool) (int, error) {
384
391
return nodePort , nil
385
392
}
386
393
394
+ func getK8sServiceClusterIP (service , namespace string ) (string , error ) {
395
+
396
+ kubectl := exec .Command (
397
+ "kubectl" , "get" , "svc" , service , "-n" , namespace ,
398
+ "-o" , fmt .Sprintf ("jsonpath={.spec.clusterIP}" ))
399
+
400
+ kubectlOut , err := kubectl .CombinedOutput ()
401
+ if err != nil {
402
+ return "" , errors .Wrapf (err , string (kubectlOut ))
403
+ }
404
+ return string (kubectlOut ), nil
405
+ }
406
+
387
407
func runInstall (out , errOut io.Writer , cmd * cobra.Command , args []string ) error {
388
408
389
409
config , err := readConfig (out , errOut , installConfigFile )
@@ -510,6 +530,29 @@ func runInstall(out, errOut io.Writer, cmd *cobra.Command, args []string) error
510
530
return errors .Wrapf (err , "Error installing openfaas chart" )
511
531
}
512
532
}
533
+
534
+ if config .DispatchConfig .ImageRegistry == nil && installService ("docker-registry" ) {
535
+ if config .DockerRegistry == nil {
536
+ return errors .New ("Missing docker-registry chart configuration" )
537
+ }
538
+ err = helmInstall (out , errOut , config .DockerRegistry .Chart , nil )
539
+ if err != nil {
540
+ return errors .Wrapf (err , "Error installing docker-registry chart" )
541
+ }
542
+ serviceName := fmt .Sprintf ("%s-%s" , config .DockerRegistry .Chart .Chart , config .DockerRegistry .Chart .Release )
543
+ serviceIP , err := getK8sServiceClusterIP (serviceName , config .DockerRegistry .Chart .Namespace )
544
+ if err != nil {
545
+ return err
546
+ }
547
+ registryName := fmt .Sprintf ("%s:5000" , serviceIP )
548
+ config .DispatchConfig .ImageRegistry = & imageRegistryConfig {
549
+ Name : registryName ,
550
+ Username : "" ,
551
+ Password : "" ,
552
+ Email : "" ,
553
+ }
554
+ }
555
+
513
556
if installService ("dispatch" ) {
514
557
chart := path .Join (installChartsDir , "dispatch" )
515
558
if installChartsDir != "dispatch" {
@@ -529,6 +572,10 @@ func runInstall(out, errOut io.Writer, cmd *cobra.Command, args []string) error
529
572
config .DispatchConfig .OAuth2Proxy .CookieSecret = base64 .StdEncoding .EncodeToString (cookie )
530
573
}
531
574
575
+ // To handle the case if only dispatch service was installed.
576
+ if config .DispatchConfig .ImageRegistry == nil {
577
+ return errors .New ("Missing Image Registry configuration" )
578
+ }
532
579
// we need to marshal username, password and email to ensure they are properly escaped
533
580
dockerAuth := struct {
534
581
Username string `json:"username"`
0 commit comments