@@ -82,8 +82,10 @@ type (
82
82
RuntimeToken string
83
83
RuntimeStoreIV string
84
84
HostName string
85
+ InternalHostName string
85
86
IngressHost string
86
87
IngressClass string
88
+ InternalIngressHost string
87
89
IngressController ingressutil.IngressController
88
90
Insecure bool
89
91
InstallDemoResources bool
@@ -102,6 +104,8 @@ type (
102
104
versionStr string
103
105
kubeContext string
104
106
kubeconfig string
107
+ InternalIngressAnnotation map [string ]string
108
+ ExternalIngressAnnotation map [string ]string
105
109
}
106
110
107
111
RuntimeUninstallOptions struct {
@@ -230,6 +234,10 @@ func NewRuntimeInstallCommand() *cobra.Command {
230
234
"Installing demo resources" : strconv .FormatBool (installationOpts .InstallDemoResources ),
231
235
}
232
236
237
+ if installationOpts .InternalIngressHost != "" {
238
+ finalParameters ["Internal ingress host" ] = installationOpts .InternalIngressHost
239
+ }
240
+
233
241
if err := getApprovalFromUser (cmd .Context (), finalParameters , "runtime install" ); err != nil {
234
242
return err
235
243
}
@@ -245,6 +253,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
245
253
246
254
cmd .Flags ().StringVar (& installationOpts .IngressHost , "ingress-host" , "" , "The ingress host" )
247
255
cmd .Flags ().StringVar (& installationOpts .IngressClass , "ingress-class" , "" , "The ingress class name" )
256
+ cmd .Flags ().StringVar (& installationOpts .InternalIngressHost , "internal-ingress-host" , "" , "The internal ingress host (by default the external ingress will be used for both internal and external traffic)" )
248
257
cmd .Flags ().StringVar (& installationOpts .GitIntegrationRegistrationOpts .Token , "personal-git-token" , "" , "The Personal git token for your user" )
249
258
cmd .Flags ().StringVar (& installationOpts .versionStr , "version" , "" , "The runtime version to install (default: latest)" )
250
259
cmd .Flags ().BoolVar (& installationOpts .InstallDemoResources , "demo-resources" , true , "Installs demo resources (default: true)" )
@@ -258,6 +267,8 @@ func NewRuntimeInstallCommand() *cobra.Command {
258
267
cmd .Flags ().BoolVar (& store .Get ().SetDefaultResources , "set-default-resources" , false , "If true, will set default requests and limits on all of the runtime components" )
259
268
cmd .Flags ().BoolVar (& installationOpts .FromRepo , "from-repo" , false , "Installs a runtime from an existing repo. Used for recovery after cluster failure" )
260
269
cmd .Flags ().StringToStringVar (& installationOpts .NamespaceLabels , "namespace-labels" , nil , "Optional labels that will be set on the namespace resource. (e.g. \" key1=value1,key2=value2\" " )
270
+ cmd .Flags ().StringToStringVar (& installationOpts .InternalIngressAnnotation , "internal-ingress-annotation" , nil , "Add annotations to the internal ingress" )
271
+ cmd .Flags ().StringToStringVar (& installationOpts .ExternalIngressAnnotation , "external-ingress-annotation" , nil , "Add annotations to the external ingress" )
261
272
262
273
installationOpts .InsCloneOpts = apu .AddCloneFlags (cmd , & apu.CloneFlagsOptions {
263
274
CreateIfNotExist : true ,
@@ -434,32 +445,57 @@ func ensureIngressHost(cmd *cobra.Command, opts *RuntimeInstallOptions) error {
434
445
}
435
446
}
436
447
437
- parsed , err := url .Parse (opts .IngressHost )
448
+ if err := parseHostName (opts .IngressHost , & opts .HostName ); err != nil {
449
+ return err
450
+ }
451
+
452
+ if opts .InternalIngressHost != "" {
453
+ if err := parseHostName (opts .InternalIngressHost , & opts .InternalHostName ); err != nil {
454
+ return err
455
+ }
456
+ }
457
+
458
+ log .G (cmd .Context ()).Infof ("Using ingress host: %s" , opts .IngressHost )
459
+
460
+ if ! opts .SkipClusterChecks {
461
+ return nil
462
+ }
463
+
464
+ log .G (cmd .Context ()).Info ("Validating ingress host" )
465
+
466
+ if opts .InternalIngressHost != "" {
467
+ if err := validateIngressHostCertificate (cmd , opts .InternalIngressHost ); err != nil {
468
+ return err
469
+ }
470
+ log .G (cmd .Context ()).Infof ("Using internal ingress host: %s" , opts .InternalIngressHost )
471
+ }
472
+
473
+ return validateIngressHostCertificate (cmd , opts .IngressHost )
474
+ }
475
+
476
+ func parseHostName (ingressHost string , hostName * string ) error {
477
+ parsed , err := url .Parse (ingressHost )
438
478
if err != nil {
439
479
return err
440
480
}
441
481
442
482
isIP := util .IsIP (parsed .Host )
443
483
if ! isIP {
444
- opts . HostName , _ , err = net .SplitHostPort (parsed .Host )
484
+ * hostName , _ , err = net .SplitHostPort (parsed .Host )
445
485
if err != nil {
446
486
if err .Error () == fmt .Sprintf ("address %s: missing port in address" , parsed .Host ) {
447
- opts . HostName = parsed .Host
487
+ * hostName = parsed .Host
448
488
} else {
449
489
return err
450
490
}
451
491
}
452
492
}
453
493
454
- log .G (cmd .Context ()).Infof ("Using ingress host: %s" , opts .IngressHost )
455
-
456
- if ! opts .SkipClusterChecks {
457
- return nil
458
- }
459
-
460
- log .G (cmd .Context ()).Info ("Validating ingress host" )
494
+ return nil
495
+ }
461
496
462
- certValid , err := checkIngressHostCertificate (opts .IngressHost )
497
+ func validateIngressHostCertificate (cmd * cobra.Command , ingressHost string ) error {
498
+ certValid , err := checkIngressHostCertificate (ingressHost )
463
499
if err != nil {
464
500
log .G (cmd .Context ()).Fatalf ("failed to check ingress host: %v" , err )
465
501
}
@@ -600,15 +636,16 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
600
636
ingressControllerName := opts .IngressController .Name ()
601
637
602
638
token , iv , err := createRuntimeOnPlatform (ctx , & model.RuntimeInstallationArgs {
603
- RuntimeName : opts .RuntimeName ,
604
- Cluster : server ,
605
- RuntimeVersion : runtimeVersion ,
606
- IngressHost : & opts .IngressHost ,
607
- IngressClass : & opts .IngressClass ,
608
- IngressController : & ingressControllerName ,
609
- ComponentNames : componentNames ,
610
- Repo : & opts .InsCloneOpts .Repo ,
611
- Recover : & opts .FromRepo ,
639
+ RuntimeName : opts .RuntimeName ,
640
+ Cluster : server ,
641
+ RuntimeVersion : runtimeVersion ,
642
+ IngressHost : & opts .IngressHost ,
643
+ InternalIngressHost : & opts .InternalIngressHost ,
644
+ IngressClass : & opts .IngressClass ,
645
+ IngressController : & ingressControllerName ,
646
+ ComponentNames : componentNames ,
647
+ Repo : & opts .InsCloneOpts .Repo ,
648
+ Recover : & opts .FromRepo ,
612
649
})
613
650
handleCliStep (reporter .InstallStepCreateRuntimeOnPlatform , "Creating runtime on platform" , err , false , true )
614
651
if err != nil {
@@ -620,6 +657,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
620
657
rt .Spec .Cluster = server
621
658
rt .Spec .IngressHost = opts .IngressHost
622
659
rt .Spec .IngressClass = opts .IngressClass
660
+ rt .Spec .InternalIngressHost = opts .InternalIngressHost
623
661
rt .Spec .IngressController = string (opts .IngressController .Name ())
624
662
rt .Spec .Repo = opts .InsCloneOpts .Repo
625
663
@@ -814,15 +852,21 @@ func createMasterIngressResource(ctx context.Context, opts *RuntimeInstallOption
814
852
return err
815
853
}
816
854
817
- ingress := ingressutil . CreateIngress ( & ingressutil.CreateIngressOptions {
855
+ ingressOptions := ingressutil.CreateIngressOptions {
818
856
Name : opts .RuntimeName + store .Get ().MasterIngressName ,
819
857
Namespace : opts .RuntimeName ,
820
858
IngressClassName : opts .IngressClass ,
821
859
Host : opts .HostName ,
822
860
Annotations : map [string ]string {
823
861
"nginx.org/mergeable-ingress-type" : "master" ,
824
862
},
825
- })
863
+ }
864
+
865
+ if opts .ExternalIngressAnnotation != nil {
866
+ mergeAnnotations (ingressOptions .Annotations , opts .ExternalIngressAnnotation )
867
+ }
868
+
869
+ ingress := ingressutil .CreateIngress (& ingressOptions )
826
870
827
871
if err = fs .WriteYamls (fs .Join (store .Get ().InClusterPath , "master-ingress.yaml" ), ingress ); err != nil {
828
872
return err
@@ -1329,6 +1373,7 @@ func RunRuntimeList(ctx context.Context) error {
1329
1373
healthMessage := "N/A"
1330
1374
installationStatus := rt .InstallationStatus
1331
1375
ingressHost := "N/A"
1376
+ internalIngressHost := "N/A"
1332
1377
ingressClass := "N/A"
1333
1378
1334
1379
if rt .Metadata .Namespace != nil {
@@ -1351,11 +1396,15 @@ func RunRuntimeList(ctx context.Context) error {
1351
1396
ingressHost = * rt .IngressHost
1352
1397
}
1353
1398
1399
+ if rt .InternalIngressHost != nil {
1400
+ internalIngressHost = * rt .InternalIngressHost
1401
+ }
1402
+
1354
1403
if rt .IngressClass != nil {
1355
1404
ingressClass = * rt .IngressClass
1356
1405
}
1357
1406
1358
- _ , err = fmt .Fprintf (tb , "%s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\n " ,
1407
+ _ , err = fmt .Fprintf (tb , "%s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s\t %s \ n " ,
1359
1408
name ,
1360
1409
namespace ,
1361
1410
cluster ,
@@ -1365,6 +1414,7 @@ func RunRuntimeList(ctx context.Context) error {
1365
1414
healthMessage ,
1366
1415
installationStatus ,
1367
1416
ingressHost ,
1417
+ internalIngressHost ,
1368
1418
ingressClass ,
1369
1419
)
1370
1420
if err != nil {
@@ -1842,6 +1892,10 @@ func createWorkflowsIngress(ctx context.Context, opts *RuntimeInstallOptions, rt
1842
1892
},
1843
1893
}
1844
1894
1895
+ if opts .ExternalIngressAnnotation != nil {
1896
+ mergeAnnotations (ingressOptions .Annotations , opts .ExternalIngressAnnotation )
1897
+ }
1898
+
1845
1899
ingress := ingressutil .CreateIngress (& ingressOptions )
1846
1900
opts .IngressController .Decorate (ingress )
1847
1901
@@ -1881,6 +1935,12 @@ func createWorkflowsIngress(ctx context.Context, opts *RuntimeInstallOptions, rt
1881
1935
return apu .PushWithMessage (ctx , r , "Created Workflows Ingress" )
1882
1936
}
1883
1937
1938
+ func mergeAnnotations (annotation map [string ]string , newAnnotation map [string ]string ) {
1939
+ for key , element := range newAnnotation {
1940
+ annotation [key ] = element
1941
+ }
1942
+ }
1943
+
1884
1944
func configureAppProxy (ctx context.Context , opts * RuntimeInstallOptions , rt * runtime.Runtime ) error {
1885
1945
r , fs , err := opts .InsCloneOpts .GetRepo (ctx )
1886
1946
if err != nil {
@@ -1912,12 +1972,17 @@ func configureAppProxy(ctx context.Context, opts *RuntimeInstallOptions, rt *run
1912
1972
},
1913
1973
})
1914
1974
1975
+ hostName := opts .HostName
1976
+ if opts .InternalHostName != "" {
1977
+ hostName = opts .InternalHostName
1978
+ }
1979
+
1915
1980
if ! store .Get ().SkipIngress {
1916
1981
ingressOptions := ingressutil.CreateIngressOptions {
1917
1982
Name : rt .Name + store .Get ().AppProxyIngressName ,
1918
1983
Namespace : rt .Namespace ,
1919
1984
IngressClassName : opts .IngressClass ,
1920
- Host : opts . HostName ,
1985
+ Host : hostName ,
1921
1986
Paths : []ingressutil.IngressPath {
1922
1987
{
1923
1988
Path : store .Get ().AppProxyIngressPath ,
@@ -1928,6 +1993,11 @@ func configureAppProxy(ctx context.Context, opts *RuntimeInstallOptions, rt *run
1928
1993
},
1929
1994
}
1930
1995
1996
+ if opts .InternalIngressAnnotation != nil {
1997
+ ingressOptions .Annotations = make (map [string ]string )
1998
+ mergeAnnotations (ingressOptions .Annotations , opts .InternalIngressAnnotation )
1999
+ }
2000
+
1931
2001
ingress := ingressutil .CreateIngress (& ingressOptions )
1932
2002
opts .IngressController .Decorate (ingress )
1933
2003
@@ -1969,6 +2039,7 @@ func updateCodefreshCM(ctx context.Context, opts *RuntimeInstallOptions, rt *run
1969
2039
runtime .Spec .IngressClass = opts .IngressClass
1970
2040
runtime .Spec .IngressController = opts .IngressController .Name ()
1971
2041
runtime .Spec .IngressHost = opts .IngressHost
2042
+ runtime .Spec .InternalIngressHost = opts .InternalIngressHost
1972
2043
1973
2044
marshalRuntime , err = yaml .Marshal (runtime )
1974
2045
if err != nil {
0 commit comments