From ecf630d8b6aa1a6a4d97d4a017678450e1a7bcdd Mon Sep 17 00:00:00 2001 From: "Yusuf A. Hasan Miyan" Date: Tue, 10 May 2022 10:23:21 +1000 Subject: [PATCH] feat: remove LagoonBaseUrl & only keep Hostname. --- README.md | 30 ++++++++---------- cmd/root.go | 17 ++++------ pkg/rockpool/gitea-api.go | 10 +++--- pkg/rockpool/lagoon-api.go | 2 +- pkg/rockpool/lagoon-components.go | 2 +- pkg/rockpool/rockpool.go | 12 +++---- pkg/rockpool/state.go | 4 +-- pkg/rockpool/types.go | 1 - templates/ca.yml.tmpl | 2 +- templates/gitea-values.yml.tmpl | 2 +- templates/gitlab.yml.tmpl | 2 +- templates/harbor-values.yml.tmpl | 4 +-- templates/lagoon-core-values.yml.tmpl | 42 ++++++++++++------------- templates/lagoon-remote-values.yml.tmpl | 12 +++---- templates/mailhog.yml.tmpl | 2 +- 15 files changed, 68 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index 5b29b00..bc38e66 100644 --- a/README.md +++ b/README.md @@ -102,24 +102,21 @@ up is for creating or starting all the clusters, or the ones specified in the arguments, e.g, 'rockpool up controller target-1' Usage: - rockpool up [cluster-name...] [flags] + rockpool up [name...] [flags] Flags: - -h, --help help for up - -l, --lagoon-base-url string The base Lagoon url of the cluster; - all Lagoon services will be created as subdomains of this url, e.g, - ui.lagoon.rockpool.k3d.local, harbor.lagoon.rockpool.k3d.local - (default "lagoon.rockpool.k3d.local") - --rendered-template-path string The directory where rendered template files are placed - (default "/var/folders/lq/gql2jg193ndbp64b2z32qp8r0000gn/T/rockpool/rendered") - --upgrade-components strings A list of components to upgrade, e.g, ingress-nginx,harbor - -u, --url string The base url of rockpool; ancillary services will be created - as subdomains of this url, e.g, gitlab.rockpool.k3d.local - (default "rockpool.k3d.local") + -h, --help help for up + -k, --ssh-key string The ssh key to add to the lagoonadmin user. If empty, rockpool tries + to use ~/.ssh/id_ed25519.pub first, then ~/.ssh/id_rsa.pub. + + -t, --targets int Number of targets (lagoon remotes) to create (default 1) + --upgrade-components strings A list of components to upgrade, e.g, ingress-nginx,harbor + -u, --url string The base url of rockpool; ancillary services will be created + as subdomains of this url, e.g, gitlab.rockpool.k3d.local + (default "rockpool.k3d.local") Global Flags: - -n, --cluster-name string The name of the cluster (default "rockpool") - -t, --targets int Number of targets (lagoon remotes) to create (default 1) + -n, --name string The name of the platform (default "rockpool") ``` There are also other commands for controlling the platform: @@ -140,9 +137,8 @@ Available Commands: up Create and/or start the clusters Flags: - -n, --cluster-name string The name of the cluster (default "rockpool") - -h, --help help for rockpool - -t, --targets int Number of targets (lagoon remotes) to create (default 1) + -h, --help help for rockpool + -n, --name string The name of the platform (default "rockpool") Use "rockpool [command] --help" for more information about a command. ``` diff --git a/cmd/root.go b/cmd/root.go index b3ef905..1ff81ff 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -32,7 +32,7 @@ var rootCmd = &cobra.Command{ } var upCmd = &cobra.Command{ - Use: "up [cluster-name...]", + Use: "up [name...]", Short: "Create and/or start the clusters", Long: `up is for creating or starting all the clusters, or the ones specified in the arguments, e.g, 'rockpool up controller target-1'`, @@ -44,7 +44,7 @@ specified in the arguments, e.g, 'rockpool up controller target-1'`, } var startCmd = &cobra.Command{ - Use: "start [cluster-name...]", + Use: "start [name...]", Short: "Start the clusters", Long: `start is for starting all the clusters, or the ones specified in the arguments, e.g, 'rockpool start controller target-1'`, @@ -56,7 +56,7 @@ specified in the arguments, e.g, 'rockpool start controller target-1'`, } var stopCmd = &cobra.Command{ - Use: "stop [cluster-name...]", + Use: "stop [name...]", Short: "Stop the clusters", Long: `stop is for stopping all the clusters, or the ones specified in the arguments, e.g, 'rockpool stop controller target-1'`, @@ -68,7 +68,7 @@ specified in the arguments, e.g, 'rockpool stop controller target-1'`, } var restartCmd = &cobra.Command{ - Use: "restart [cluster-name...]", + Use: "restart [name...]", Short: "Restart the clusters", Long: `restart is for stopping and starting all the clusters, or the ones specified in the arguments, e.g, 'rockpool restart controller target-1'`, @@ -89,7 +89,7 @@ var statusCmd = &cobra.Command{ } var downCmd = &cobra.Command{ - Use: "down [cluster-name...]", + Use: "down [name...]", Short: "Stop the clusters and delete them", Long: `down is for stopping and deleting all the clusters, or the ones specified in the arguments, e.g, 'rockpool down controller target-1'`, @@ -113,17 +113,12 @@ func init() { r.Spinner.Color("red", "bold") r.Config.Arch = runtime.GOARCH - rootCmd.PersistentFlags().StringVarP(&r.Config.Name, "cluster-name", "n", "rockpool", "The name of the cluster") + rootCmd.PersistentFlags().StringVarP(&r.Config.Name, "name", "n", "rockpool", "The name of the platform") upCmd.Flags().IntVarP(&r.Config.NumTargets, "targets", "t", 1, "Number of targets (lagoon remotes) to create") upCmd.Flags().StringVarP(&r.Config.Hostname, "url", "u", "rockpool.k3d.local", `The base url of rockpool; ancillary services will be created as subdomains of this url, e.g, gitlab.rockpool.k3d.local -`) - upCmd.Flags().StringVarP(&r.Config.LagoonBaseUrl, "lagoon-base-url", "l", "lagoon.rockpool.k3d.local", - `The base Lagoon url of the cluster; -all Lagoon services will be created as subdomains of this url, e.g, -ui.lagoon.rockpool.k3d.local, harbor.lagoon.rockpool.k3d.local `) upCmd.Flags().StringSliceVar(&r.Config.UpgradeComponents, "upgrade-components", []string{}, "A list of components to upgrade, e.g, ingress-nginx,harbor") diff --git a/pkg/rockpool/gitea-api.go b/pkg/rockpool/gitea-api.go index 678196d..6b8911d 100644 --- a/pkg/rockpool/gitea-api.go +++ b/pkg/rockpool/gitea-api.go @@ -12,7 +12,7 @@ import ( ) func (r *Rockpool) GiteaApiReq(method string, endpoint string, data []byte) (*http.Request, error) { - url := fmt.Sprintf("http://gitea.%s/api/v1/%s", r.Hostname, endpoint) + url := fmt.Sprintf("http://gitea.lagoon.%s/api/v1/%s", r.Hostname, endpoint) req, err := http.NewRequest(method, url, bytes.NewBuffer(data)) if err != nil { return nil, err @@ -65,13 +65,15 @@ func (r *Rockpool) GiteaHasToken() (string, error) { // finish. done := false retries := 12 + var resp *http.Response var err error + var dump []byte for !done && retries > 0 { - resp, err := r.GiteaTokenApiCall("GET", nil, false) + resp, err = r.GiteaTokenApiCall("GET", nil, false) if err != nil { return "", fmt.Errorf("error calling gitea token endpoint: %s", err) } - dump, _ := httputil.DumpResponse(resp, true) + dump, _ = httputil.DumpResponse(resp, true) if err = json.NewDecoder(resp.Body).Decode(&tokens); err != nil { if err.Error() == "invalid character '<' looking for beginning of value" { @@ -84,7 +86,7 @@ func (r *Rockpool) GiteaHasToken() (string, error) { done = true } if !done { - return "", fmt.Errorf("error decoding gitea token: %s", err) + return "", fmt.Errorf("error decoding gitea token: %s. response: %s", err, string(dump)) } for _, t := range tokens { if t.Name == "test" { diff --git a/pkg/rockpool/lagoon-api.go b/pkg/rockpool/lagoon-api.go index 0151d63..bcdf029 100644 --- a/pkg/rockpool/lagoon-api.go +++ b/pkg/rockpool/lagoon-api.go @@ -68,7 +68,7 @@ func (r *Rockpool) GetLagoonApiClient() { } src := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: r.lagoonFetchApiToken()}) httpClient := oauth2.NewClient(context.Background(), src) - r.GqlClient = graphql.NewClient(fmt.Sprintf("http://api.%s/graphql", r.Config.LagoonBaseUrl), httpClient) + r.GqlClient = graphql.NewClient(fmt.Sprintf("http://api.lagoon.%s/graphql", r.Config.Hostname), httpClient) } func (r *Rockpool) LagoonApiGetRemotes() { diff --git a/pkg/rockpool/lagoon-components.go b/pkg/rockpool/lagoon-components.go index 0334f5e..071543e 100644 --- a/pkg/rockpool/lagoon-components.go +++ b/pkg/rockpool/lagoon-components.go @@ -153,7 +153,7 @@ func (r *Rockpool) AddHarborHostEntries(cn string) { return } - entry := fmt.Sprintf("%s\tharbor.%s", r.ControllerIP(), r.Config.LagoonBaseUrl) + entry := fmt.Sprintf("%s\tharbor.lagoon.%s", r.ControllerIP(), r.Config.Hostname) entryCmdStr := fmt.Sprintf("echo '%s' >> /etc/hosts", entry) for _, n := range c.Nodes { if n.Role == "loadbalancer" { diff --git a/pkg/rockpool/rockpool.go b/pkg/rockpool/rockpool.go index fad0f23..df5e9cf 100644 --- a/pkg/rockpool/rockpool.go +++ b/pkg/rockpool/rockpool.go @@ -15,9 +15,9 @@ import ( func (c *Config) ToMap() map[string]string { return map[string]string{ - "Name": c.Name, - "LagoonBaseUrl": c.LagoonBaseUrl, - "Arch": c.Arch, + "Name": c.Name, + "Hostname": c.Hostname, + "Arch": c.Arch, } } @@ -410,7 +410,7 @@ func (r *Rockpool) ConfigureTargetCoreDNS(cn string) { corednsCm.Data.NodeHosts += gitea_entry } for _, h := range []string{"harbor", "broker", "ssh", "api"} { - entry := fmt.Sprintf("%s %s.%s\n", r.ControllerIP(), h, r.LagoonBaseUrl) + entry := fmt.Sprintf("%s %s.lagoon.%s\n", r.ControllerIP(), h, r.Hostname) if !strings.Contains(corednsCm.Data.NodeHosts, entry) { corednsCm.Data.NodeHosts += entry } @@ -432,8 +432,8 @@ func (r *Rockpool) ConfigureTargetCoreDNS(cn string) { } func (r *Rockpool) LagoonCliAddConfig() { - graphql := fmt.Sprintf("http://api.%s/graphql", r.LagoonBaseUrl) - ui := fmt.Sprintf("http://ui.%s", r.LagoonBaseUrl) + graphql := fmt.Sprintf("http://api.lagoon.%s/graphql", r.Hostname) + ui := fmt.Sprintf("http://ui.lagoon.%s", r.Hostname) // Get list of existing configs. cmd := exec.Command("lagoon", "config", "list", "--output-json") diff --git a/pkg/rockpool/state.go b/pkg/rockpool/state.go index 4aafae3..81fa78a 100644 --- a/pkg/rockpool/state.go +++ b/pkg/rockpool/state.go @@ -124,7 +124,7 @@ func (r *Rockpool) Status() { } fmt.Println("Gitea:") - fmt.Printf(" http://gitea.%s\n", r.Hostname) + fmt.Printf(" http://gitea.lagoon.%s\n", r.Hostname) fmt.Println(" User: rockpool") fmt.Println(" Pass: pass") @@ -194,5 +194,5 @@ func (r *Rockpool) RenderedTemplatesPath() string { } func (r *Rockpool) KeycloakUrl() string { - return fmt.Sprintf("http://keycloak.%s/auth", r.Config.LagoonBaseUrl) + return fmt.Sprintf("http://keycloak.lagoon.%s/auth", r.Config.Hostname) } diff --git a/pkg/rockpool/types.go b/pkg/rockpool/types.go index 456d1ce..1c48f93 100644 --- a/pkg/rockpool/types.go +++ b/pkg/rockpool/types.go @@ -76,7 +76,6 @@ type Config struct { ConfigDir string Name string Hostname string - LagoonBaseUrl string Arch string UpgradeComponents []string NumTargets int diff --git a/templates/ca.yml.tmpl b/templates/ca.yml.tmpl index 4d7101e..97b0f91 100644 --- a/templates/ca.yml.tmpl +++ b/templates/ca.yml.tmpl @@ -16,7 +16,7 @@ spec: isCA: true commonName: {{ .Hostname }} dnsNames: - - harbor.{{ .LagoonBaseUrl }} + - harbor.lagoon.{{ .Hostname }} secretName: rockpool-root-secret subject: organizations: diff --git a/templates/gitea-values.yml.tmpl b/templates/gitea-values.yml.tmpl index 86a48da..1f99f9b 100644 --- a/templates/gitea-values.yml.tmpl +++ b/templates/gitea-values.yml.tmpl @@ -12,7 +12,7 @@ gitea: ingress: enabled: true hosts: - - host: gitea.{{ .Hostname }} + - host: gitea.lagoon.{{ .Hostname }} paths: - path: / pathType: Prefix diff --git a/templates/gitlab.yml.tmpl b/templates/gitlab.yml.tmpl index c5e3e9a..bdb0790 100644 --- a/templates/gitlab.yml.tmpl +++ b/templates/gitlab.yml.tmpl @@ -12,7 +12,7 @@ metadata: name: gitlab spec: rules: - - host: gitlab.{{ .Hostname }} + - host: gitlab.lagoon.{{ .Hostname }} http: paths: - backend: diff --git a/templates/harbor-values.yml.tmpl b/templates/harbor-values.yml.tmpl index 49236a1..e2c1c95 100644 --- a/templates/harbor-values.yml.tmpl +++ b/templates/harbor-values.yml.tmpl @@ -4,13 +4,13 @@ expose: kubernetes.io/tls-acme: "true" cert-manager.io/cluster-issuer: "ca-issuer" hosts: - core: harbor.{{ .LagoonBaseUrl }} + core: harbor.lagoon.{{ .Hostname }} tls: enabled: true certSource: secret secret: secretName: harbor-harbor-ingress -externalURL: https://harbor.{{ .LagoonBaseUrl }} +externalURL: https://harbor.lagoon.{{ .Hostname }} harborAdminPassword: pass chartmuseum: enabled: false diff --git a/templates/lagoon-core-values.yml.tmpl b/templates/lagoon-core-values.yml.tmpl index 4d9619a..88c027e 100644 --- a/templates/lagoon-core-values.yml.tmpl +++ b/templates/lagoon-core-values.yml.tmpl @@ -1,5 +1,5 @@ elasticsearchURL: https://none.com -harborURL: "https://harbor.{{ .LagoonBaseUrl }}" +harborURL: "https://harbor.lagoon.{{ .Hostname }}" kibanaURL: https://none.com logsDBAdminPassword: none s3FilesAccessKeyID: none @@ -10,11 +10,11 @@ s3FilesRegion: none s3BAASAccessKeyID: none s3BAASSecretAccessKey: none imageTag: v2.5.0 -registry: "harbor.{{ .LagoonBaseUrl }}" +registry: "harbor.lagoon.{{ .Hostname }}" -keycloakAPIURL: http://keycloak.{{ .LagoonBaseUrl }}/auth -lagoonAPIURL: http://api.{{ .LagoonBaseUrl }}/graphql -lagoonUIURL: http://ui.{{ .LagoonBaseUrl }} +keycloakAPIURL: http://keycloak.lagoon.{{ .Hostname }}/auth +lagoonAPIURL: http://api.lagoon.{{ .Hostname }}/graphql +lagoonUIURL: http://ui.lagoon.{{ .Hostname }} harborAdminPassword: pass keycloakAdminPassword: pass @@ -28,13 +28,13 @@ api: {{/* annotations: kubernetes.io/tls-acme: "true" */}} hosts: - - host: api.{{ .LagoonBaseUrl }} + - host: api.lagoon.{{ .Hostname }} paths: - / {{/* tls: - secretName: api-tls hosts: - - api.{{ .LagoonBaseUrl }} */}} + - api.lagoon.{{ .Hostname }} */}} keycloak: {{- if eq .Arch "arm64" }} @@ -53,13 +53,13 @@ keycloak: {{/* annotations: kubernetes.io/tls-acme: "true" */}} hosts: - - host: keycloak.{{ .LagoonBaseUrl }} + - host: keycloak.lagoon.{{ .Hostname }} paths: - / {{/* tls: - secretName: keycloak-tls hosts: - - keycloak.{{ .LagoonBaseUrl }} */}} + - keycloak.lagoon.{{ .Hostname }} */}} webhookHandler: ingress: @@ -67,13 +67,13 @@ webhookHandler: {{/* annotations: kubernetes.io/tls-acme: "true" */}} hosts: - - host: webhookhandler.{{ .LagoonBaseUrl }} + - host: webhookhandler.lagoon.{{ .Hostname }} paths: - / {{/* tls: - secretName: webhookhandler-tls hosts: - - webhookhandler.{{ .LagoonBaseUrl }} */}} + - webhookhandler.lagoon.{{ .Hostname }} */}} ui: replicaCount: 1 @@ -82,13 +82,13 @@ ui: {{/* annotations: kubernetes.io/tls-acme: "true" */}} hosts: - - host: ui.{{ .LagoonBaseUrl }} + - host: ui.lagoon.{{ .Hostname }} paths: - / {{/* tls: - secretName: ui-tls hosts: - - ui.{{ .LagoonBaseUrl }} */}} + - ui.lagoon.{{ .Hostname }} */}} backupHandler: enabled: false @@ -98,13 +98,13 @@ backupHandler: annotations: kubernetes.io/tls-acme: "true" hosts: - - host: backuphandler.{{ .LagoonBaseUrl }} + - host: backuphandler.lagoon.{{ .Hostname }} paths: - / tls: - secretName: backuphandler-tls hosts: - - backuphandler.{{ .LagoonBaseUrl }} */}} + - backuphandler.lagoon.{{ .Hostname }} */}} drushAlias: ingress: @@ -112,13 +112,13 @@ drushAlias: {{/* annotations: kubernetes.io/tls-acme: "true" */}} hosts: - - host: drushalias.{{ .LagoonBaseUrl }} + - host: drushalias.lagoon.{{ .Hostname }} paths: - / {{/* tls: - secretName: drushalias-tls hosts: - - drushalias.{{ .LagoonBaseUrl }} */}} + - drushalias.lagoon.{{ .Hostname }} */}} ssh: replicaCount: 1 @@ -149,13 +149,13 @@ broker: {{/* annotations: kubernetes.io/tls-acme: "true" */}} hosts: - - host: broker.{{ .LagoonBaseUrl }} + - host: broker.lagoon.{{ .Hostname }} paths: - / {{/* tls: - secretName: broker-tls hosts: - - broker.{{ .LagoonBaseUrl }} */}} + - broker.lagoon.{{ .Hostname }} */}} authServer: replicaCount: 1 @@ -173,13 +173,13 @@ webhookHandler: {{/* annotations: kubernetes.io/tls-acme: "true" */}} hosts: - - host: webhookhandler.{{ .LagoonBaseUrl }} + - host: webhookhandler.lagoon.{{ .Hostname }} paths: - / {{/* tls: - secretName: webhookhandler-tls hosts: - - webhookhandler.{{ .LagoonBaseUrl }} */}} + - webhookhandler.lagoon.{{ .Hostname }} */}} {{- if eq .Arch "arm64" }} autoIdler: diff --git a/templates/lagoon-remote-values.yml.tmpl b/templates/lagoon-remote-values.yml.tmpl index 4f6d759..b1e5fbf 100644 --- a/templates/lagoon-remote-values.yml.tmpl +++ b/templates/lagoon-remote-values.yml.tmpl @@ -4,24 +4,24 @@ imageTag: v2.5.0 dockerHost: image: repository: ghcr.io/yusufhm/rockpool/lagoon/docker-host - registry: harbor.{{ .LagoonBaseUrl }} + registry: harbor.lagoon.{{ .Hostname }} {{- end }} lagoon-build-deploy: enabled: true extraArgs: - "--enable-harbor=true" - - "--harbor-url=https://harbor.{{ .LagoonBaseUrl }}" - - "--harbor-api=https://harbor.{{ .LagoonBaseUrl }}/api/" + - "--harbor-url=https://harbor.lagoon.{{ .Hostname }}" + - "--harbor-api=https://harbor.lagoon.{{ .Hostname }}/api/" - "--harbor-username=admin" - "--harbor-password=pass" rabbitMQUsername: lagoon rabbitMQPassword: {{ .RabbitMQPassword }} - rabbitMQHostname: broker.{{ .LagoonBaseUrl }} + rabbitMQHostname: broker.lagoon.{{ .Hostname }} lagoonTargetName: {{ .Name }}{{ .TargetId}} - taskSSHHost: ssh.{{ .LagoonBaseUrl }} + taskSSHHost: ssh.lagoon.{{ .Hostname }} taskSSHPort: "22" - taskAPIHost: "api.{{ .LagoonBaseUrl }}" + taskAPIHost: "api.lagoon.{{ .Hostname }}" dbaas-operator: enabled: false diff --git a/templates/mailhog.yml.tmpl b/templates/mailhog.yml.tmpl index 0f598c5..9df2d28 100644 --- a/templates/mailhog.yml.tmpl +++ b/templates/mailhog.yml.tmpl @@ -10,7 +10,7 @@ metadata: app.kubernetes.io/name: mailhog spec: rules: - - host: mailhog.{{ .LagoonBaseUrl }} + - host: mailhog.lagoon.{{ .Hostname }} http: paths: - backend: