Skip to content

Commit 2d82905

Browse files
Cr 11553 (#395)
* wip * wip * wip * bump * bump * resolve comments * wip * bump * wip * resolve comments * resolve comments * use go-sdk 0.43.7 * wip * wip
1 parent 71ec0ae commit 2d82905

File tree

8 files changed

+139
-63
lines changed

8 files changed

+139
-63
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.354
1+
VERSION=v0.0.355
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/runtime.go

Lines changed: 95 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ type (
8282
RuntimeToken string
8383
RuntimeStoreIV string
8484
HostName string
85+
InternalHostName string
8586
IngressHost string
8687
IngressClass string
88+
InternalIngressHost string
8789
IngressController ingressutil.IngressController
8890
Insecure bool
8991
InstallDemoResources bool
@@ -102,6 +104,8 @@ type (
102104
versionStr string
103105
kubeContext string
104106
kubeconfig string
107+
InternalIngressAnnotation map[string]string
108+
ExternalIngressAnnotation map[string]string
105109
}
106110

107111
RuntimeUninstallOptions struct {
@@ -230,6 +234,10 @@ func NewRuntimeInstallCommand() *cobra.Command {
230234
"Installing demo resources": strconv.FormatBool(installationOpts.InstallDemoResources),
231235
}
232236

237+
if installationOpts.InternalIngressHost != "" {
238+
finalParameters["Internal ingress host"] = installationOpts.InternalIngressHost
239+
}
240+
233241
if err := getApprovalFromUser(cmd.Context(), finalParameters, "runtime install"); err != nil {
234242
return err
235243
}
@@ -245,6 +253,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
245253

246254
cmd.Flags().StringVar(&installationOpts.IngressHost, "ingress-host", "", "The ingress host")
247255
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)")
248257
cmd.Flags().StringVar(&installationOpts.GitIntegrationRegistrationOpts.Token, "personal-git-token", "", "The Personal git token for your user")
249258
cmd.Flags().StringVar(&installationOpts.versionStr, "version", "", "The runtime version to install (default: latest)")
250259
cmd.Flags().BoolVar(&installationOpts.InstallDemoResources, "demo-resources", true, "Installs demo resources (default: true)")
@@ -258,6 +267,8 @@ func NewRuntimeInstallCommand() *cobra.Command {
258267
cmd.Flags().BoolVar(&store.Get().SetDefaultResources, "set-default-resources", false, "If true, will set default requests and limits on all of the runtime components")
259268
cmd.Flags().BoolVar(&installationOpts.FromRepo, "from-repo", false, "Installs a runtime from an existing repo. Used for recovery after cluster failure")
260269
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")
261272

262273
installationOpts.InsCloneOpts = apu.AddCloneFlags(cmd, &apu.CloneFlagsOptions{
263274
CreateIfNotExist: true,
@@ -434,32 +445,57 @@ func ensureIngressHost(cmd *cobra.Command, opts *RuntimeInstallOptions) error {
434445
}
435446
}
436447

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)
438478
if err != nil {
439479
return err
440480
}
441481

442482
isIP := util.IsIP(parsed.Host)
443483
if !isIP {
444-
opts.HostName, _, err = net.SplitHostPort(parsed.Host)
484+
*hostName, _, err = net.SplitHostPort(parsed.Host)
445485
if err != nil {
446486
if err.Error() == fmt.Sprintf("address %s: missing port in address", parsed.Host) {
447-
opts.HostName = parsed.Host
487+
*hostName = parsed.Host
448488
} else {
449489
return err
450490
}
451491
}
452492
}
453493

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+
}
461496

462-
certValid, err := checkIngressHostCertificate(opts.IngressHost)
497+
func validateIngressHostCertificate(cmd *cobra.Command, ingressHost string) error {
498+
certValid, err := checkIngressHostCertificate(ingressHost)
463499
if err != nil {
464500
log.G(cmd.Context()).Fatalf("failed to check ingress host: %v", err)
465501
}
@@ -600,15 +636,16 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
600636
ingressControllerName := opts.IngressController.Name()
601637

602638
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,
612649
})
613650
handleCliStep(reporter.InstallStepCreateRuntimeOnPlatform, "Creating runtime on platform", err, false, true)
614651
if err != nil {
@@ -620,6 +657,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
620657
rt.Spec.Cluster = server
621658
rt.Spec.IngressHost = opts.IngressHost
622659
rt.Spec.IngressClass = opts.IngressClass
660+
rt.Spec.InternalIngressHost = opts.InternalIngressHost
623661
rt.Spec.IngressController = string(opts.IngressController.Name())
624662
rt.Spec.Repo = opts.InsCloneOpts.Repo
625663

@@ -814,15 +852,21 @@ func createMasterIngressResource(ctx context.Context, opts *RuntimeInstallOption
814852
return err
815853
}
816854

817-
ingress := ingressutil.CreateIngress(&ingressutil.CreateIngressOptions{
855+
ingressOptions := ingressutil.CreateIngressOptions{
818856
Name: opts.RuntimeName + store.Get().MasterIngressName,
819857
Namespace: opts.RuntimeName,
820858
IngressClassName: opts.IngressClass,
821859
Host: opts.HostName,
822860
Annotations: map[string]string{
823861
"nginx.org/mergeable-ingress-type": "master",
824862
},
825-
})
863+
}
864+
865+
if opts.ExternalIngressAnnotation != nil {
866+
mergeAnnotations(ingressOptions.Annotations, opts.ExternalIngressAnnotation)
867+
}
868+
869+
ingress := ingressutil.CreateIngress(&ingressOptions)
826870

827871
if err = fs.WriteYamls(fs.Join(store.Get().InClusterPath, "master-ingress.yaml"), ingress); err != nil {
828872
return err
@@ -1329,6 +1373,7 @@ func RunRuntimeList(ctx context.Context) error {
13291373
healthMessage := "N/A"
13301374
installationStatus := rt.InstallationStatus
13311375
ingressHost := "N/A"
1376+
internalIngressHost := "N/A"
13321377
ingressClass := "N/A"
13331378

13341379
if rt.Metadata.Namespace != nil {
@@ -1351,11 +1396,15 @@ func RunRuntimeList(ctx context.Context) error {
13511396
ingressHost = *rt.IngressHost
13521397
}
13531398

1399+
if rt.InternalIngressHost != nil {
1400+
internalIngressHost = *rt.InternalIngressHost
1401+
}
1402+
13541403
if rt.IngressClass != nil {
13551404
ingressClass = *rt.IngressClass
13561405
}
13571406

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",
13591408
name,
13601409
namespace,
13611410
cluster,
@@ -1365,6 +1414,7 @@ func RunRuntimeList(ctx context.Context) error {
13651414
healthMessage,
13661415
installationStatus,
13671416
ingressHost,
1417+
internalIngressHost,
13681418
ingressClass,
13691419
)
13701420
if err != nil {
@@ -1842,6 +1892,10 @@ func createWorkflowsIngress(ctx context.Context, opts *RuntimeInstallOptions, rt
18421892
},
18431893
}
18441894

1895+
if opts.ExternalIngressAnnotation != nil {
1896+
mergeAnnotations(ingressOptions.Annotations, opts.ExternalIngressAnnotation)
1897+
}
1898+
18451899
ingress := ingressutil.CreateIngress(&ingressOptions)
18461900
opts.IngressController.Decorate(ingress)
18471901

@@ -1881,6 +1935,12 @@ func createWorkflowsIngress(ctx context.Context, opts *RuntimeInstallOptions, rt
18811935
return apu.PushWithMessage(ctx, r, "Created Workflows Ingress")
18821936
}
18831937

1938+
func mergeAnnotations(annotation map[string]string, newAnnotation map[string]string) {
1939+
for key, element := range newAnnotation {
1940+
annotation[key] = element
1941+
}
1942+
}
1943+
18841944
func configureAppProxy(ctx context.Context, opts *RuntimeInstallOptions, rt *runtime.Runtime) error {
18851945
r, fs, err := opts.InsCloneOpts.GetRepo(ctx)
18861946
if err != nil {
@@ -1912,12 +1972,17 @@ func configureAppProxy(ctx context.Context, opts *RuntimeInstallOptions, rt *run
19121972
},
19131973
})
19141974

1975+
hostName := opts.HostName
1976+
if opts.InternalHostName != "" {
1977+
hostName = opts.InternalHostName
1978+
}
1979+
19151980
if !store.Get().SkipIngress {
19161981
ingressOptions := ingressutil.CreateIngressOptions{
19171982
Name: rt.Name + store.Get().AppProxyIngressName,
19181983
Namespace: rt.Namespace,
19191984
IngressClassName: opts.IngressClass,
1920-
Host: opts.HostName,
1985+
Host: hostName,
19211986
Paths: []ingressutil.IngressPath{
19221987
{
19231988
Path: store.Get().AppProxyIngressPath,
@@ -1928,6 +1993,11 @@ func configureAppProxy(ctx context.Context, opts *RuntimeInstallOptions, rt *run
19281993
},
19291994
}
19301995

1996+
if opts.InternalIngressAnnotation != nil {
1997+
ingressOptions.Annotations = make(map[string]string)
1998+
mergeAnnotations(ingressOptions.Annotations, opts.InternalIngressAnnotation)
1999+
}
2000+
19312001
ingress := ingressutil.CreateIngress(&ingressOptions)
19322002
opts.IngressController.Decorate(ingress)
19332003

@@ -1969,6 +2039,7 @@ func updateCodefreshCM(ctx context.Context, opts *RuntimeInstallOptions, rt *run
19692039
runtime.Spec.IngressClass = opts.IngressClass
19702040
runtime.Spec.IngressController = opts.IngressController.Name()
19712041
runtime.Spec.IngressHost = opts.IngressHost
2042+
runtime.Spec.InternalIngressHost = opts.InternalIngressHost
19722043

19732044
marshalRuntime, err = yaml.Marshal(runtime)
19742045
if err != nil {

docs/commands/cli-v2_runtime_install.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,32 @@ cli-v2 runtime install [runtime_name] [flags]
2828
### Options
2929

3030
```
31-
--context string The name of the kubeconfig context to use
32-
--demo-resources Installs demo resources (default: true) (default true)
33-
--disable-rollback If true, will not perform installation rollback after a failed installation
34-
--disable-telemetry If true, will disable the analytics reporting for the installation process
35-
--from-repo Installs a runtime from an existing repo. Used for recovery after cluster failure
36-
-t, --git-token string Your git provider api token [GIT_TOKEN]
37-
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
38-
-h, --help help for install
39-
--ingress-class string The ingress class name
40-
--ingress-host string The ingress host
41-
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
42-
-n, --namespace string If present, the namespace scope for this CLI request
43-
--namespace-labels stringToString Optional labels that will be set on the namespace resource. (e.g. "key1=value1,key2=value2" (default [])
44-
--personal-git-token string The Personal git token for your user
45-
--provider string The git provider, one of: azure|gitea|github|gitlab
46-
--provider-api-url string Git provider API url
47-
--repo string Repository URL [GIT_REPO]
48-
--set-default-resources If true, will set default requests and limits on all of the runtime components
49-
--skip-cluster-checks Skips the cluster's checks
50-
--skip-ingress Skips the creation of ingress resources
51-
-b, --upsert-branch If true will try to checkout the specified branch and create it if it doesn't exist
52-
--version string The runtime version to install (default: latest)
53-
--wait-timeout duration How long to wait for the runtime components to be ready (default 8m0s)
31+
--context string The name of the kubeconfig context to use
32+
--demo-resources Installs demo resources (default: true) (default true)
33+
--disable-rollback If true, will not perform installation rollback after a failed installation
34+
--disable-telemetry If true, will disable the analytics reporting for the installation process
35+
--external-ingress-annotation stringToString Add annotations to the external ingress (default [])
36+
--from-repo Installs a runtime from an existing repo. Used for recovery after cluster failure
37+
-t, --git-token string Your git provider api token [GIT_TOKEN]
38+
-u, --git-user string Your git provider user name [GIT_USER] (not required in GitHub)
39+
-h, --help help for install
40+
--ingress-class string The ingress class name
41+
--ingress-host string The ingress host
42+
--internal-ingress-annotation stringToString Add annotations to the internal ingress (default [])
43+
--internal-ingress-host string The internal ingress host (by default the external ingress will be used for both internal and external traffic)
44+
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
45+
-n, --namespace string If present, the namespace scope for this CLI request
46+
--namespace-labels stringToString Optional labels that will be set on the namespace resource. (e.g. "key1=value1,key2=value2" (default [])
47+
--personal-git-token string The Personal git token for your user
48+
--provider string The git provider, one of: azure|gitea|github|gitlab
49+
--provider-api-url string Git provider API url
50+
--repo string Repository URL [GIT_REPO]
51+
--set-default-resources If true, will set default requests and limits on all of the runtime components
52+
--skip-cluster-checks Skips the cluster's checks
53+
--skip-ingress Skips the creation of ingress resources
54+
-b, --upsert-branch If true will try to checkout the specified branch and create it if it doesn't exist
55+
--version string The runtime version to install (default: latest)
56+
--wait-timeout duration How long to wait for the runtime components to be ready (default 8m0s)
5457
```
5558

5659
### Options inherited from parent commands

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.354/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.355/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.354/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.355/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/argoproj/argo-events v0.17.1-0.20220327045437-70eaafe9afec
1111
github.com/argoproj/argo-workflows/v3 v3.3.1
1212
github.com/briandowns/spinner v1.18.1
13-
github.com/codefresh-io/go-sdk v0.43.6
13+
github.com/codefresh-io/go-sdk v0.43.7
1414
github.com/fatih/color v1.13.0
1515
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
1616
github.com/go-git/go-billy/v5 v5.3.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h
254254
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
255255
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
256256
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
257-
github.com/codefresh-io/go-sdk v0.43.6 h1:y2CbRSM1gNNZC3GRpRLNzp3zyHGo+pmo8OTr3OQxr3I=
258-
github.com/codefresh-io/go-sdk v0.43.6/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
257+
github.com/codefresh-io/go-sdk v0.43.7 h1:s872fn7fD1S2gIy2sylgrtul4PBfabgE2jHWVFwgq3g=
258+
github.com/codefresh-io/go-sdk v0.43.7/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
259259
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
260260
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE=
261261
github.com/container-storage-interface/spec v1.5.0/go.mod h1:8K96oQNkJ7pFcC2R9Z1ynGGBB1I93kcS6PGg3SsOk8s=

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.1
8-
version: 0.0.354
8+
version: 0.0.355
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

0 commit comments

Comments
 (0)