Skip to content

Commit

Permalink
feat: remove LagoonBaseUrl & only keep Hostname.
Browse files Browse the repository at this point in the history
  • Loading branch information
yusufhm committed May 10, 2022
1 parent 3431000 commit ecf630d
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 76 deletions.
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
```
17 changes: 6 additions & 11 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'`,
Expand All @@ -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'`,
Expand All @@ -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'`,
Expand All @@ -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'`,
Expand All @@ -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'`,
Expand All @@ -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")
Expand Down
10 changes: 6 additions & 4 deletions pkg/rockpool/gitea-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" {
Expand All @@ -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" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/rockpool/lagoon-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/rockpool/lagoon-components.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
12 changes: 6 additions & 6 deletions pkg/rockpool/rockpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions pkg/rockpool/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
}
1 change: 0 additions & 1 deletion pkg/rockpool/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ type Config struct {
ConfigDir string
Name string
Hostname string
LagoonBaseUrl string
Arch string
UpgradeComponents []string
NumTargets int
Expand Down
2 changes: 1 addition & 1 deletion templates/ca.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
isCA: true
commonName: {{ .Hostname }}
dnsNames:
- harbor.{{ .LagoonBaseUrl }}
- harbor.lagoon.{{ .Hostname }}
secretName: rockpool-root-secret
subject:
organizations:
Expand Down
2 changes: 1 addition & 1 deletion templates/gitea-values.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gitea:
ingress:
enabled: true
hosts:
- host: gitea.{{ .Hostname }}
- host: gitea.lagoon.{{ .Hostname }}
paths:
- path: /
pathType: Prefix
Expand Down
2 changes: 1 addition & 1 deletion templates/gitlab.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ metadata:
name: gitlab
spec:
rules:
- host: gitlab.{{ .Hostname }}
- host: gitlab.lagoon.{{ .Hostname }}
http:
paths:
- backend:
Expand Down
4 changes: 2 additions & 2 deletions templates/harbor-values.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit ecf630d

Please sign in to comment.