Skip to content

Commit c92b0c2

Browse files
committed
install agent
1 parent 7642213 commit c92b0c2

7 files changed

Lines changed: 94 additions & 20 deletions

File tree

cmd/command/up/up.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (p *Plural) handleUp(c *cli.Context) error {
183183
}
184184

185185
utils.Success("Finished setting up your management cluster!\n")
186-
if byok {
186+
if byok && cloud {
187187
utils.Highlight("Since you're using BYOK, be sure to complete setup of your management cluster\n")
188188
utils.Highlight("IMPORTANT: You'll need to configure IAM permissions for the plrl-deploy-operator/stacks service account.\n")
189189
utils.Highlight("This is no longer handled automatically. See the terraform example in the docs for the required IAM policy.\n")

pkg/cd/control_plane_install.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ func ControlPlaneValues(conf config.Config, file, domain, dsn, name string) (str
108108
"clusterIssuer": "plural",
109109
}
110110

111+
if ingressClass := utils.ToString(prov.Context()["IngressClass"]); ingressClass != "" {
112+
configuration["ingressClass"] = ingressClass
113+
}
114+
111115
if existing.Secrets.AesKey != "" {
112116
configuration["aesKey"] = existing.Secrets.AesKey
113117
}

pkg/provider/byok.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func ByokFromManifest(man *manifest.ProjectManifest) (*ByokProvider, error) {
3535
return prov, nil
3636
}
3737

38-
func mkBYOK(conf config.Config, name string, dryRun bool) (prov *ByokProvider, err error) {
38+
func mkBYOK(conf config.Config, name string, dryRun, cloud bool) (prov *ByokProvider, err error) {
3939
prov = &ByokProvider{
4040
ctx: map[string]interface{}{},
4141
}
@@ -78,22 +78,31 @@ func mkBYOK(conf config.Config, name string, dryRun bool) (prov *ByokProvider, e
7878
kubeconfigBase64 := base64.StdEncoding.EncodeToString(kubeconfigData)
7979

8080
prov.ctx["kubeconfig"] = kubeconfigBase64
81-
82-
var dbURL string
83-
if err := survey.AskOne(&survey.Input{
84-
Message: "Enter the database URL for the Plural console (leave empty to skip):",
85-
}, &dbURL); err != nil {
86-
return nil, err
87-
}
88-
prov.ctx["DbUrl"] = dbURL
89-
9081
projectManifest := manifest.ProjectManifest{
9182
Cluster: name,
9283
Provider: api.BYOK,
9384
Owner: &manifest.Owner{Email: conf.Email, Endpoint: conf.Endpoint},
9485
Context: prov.Context(),
9586
}
96-
prov.writer = projectManifest.Configure(cloudFlag, prov.Cluster())
87+
if !cloud {
88+
var dbURL string
89+
if err := survey.AskOne(&survey.Input{
90+
Message: "Enter the jdbc connection string (postgres://<user>:<password>@<host>:5432/<db>) for the Plural console:",
91+
}, &dbURL); err != nil {
92+
return nil, err
93+
}
94+
prov.ctx["DbUrl"] = dbURL
95+
96+
var domain string
97+
if err := survey.AskOne(&survey.Input{
98+
Message: "Enter the domain you want to use for your Plural console:",
99+
}, &domain); err != nil {
100+
return nil, err
101+
}
102+
103+
projectManifest.Network = &manifest.NetworkConfig{Subdomain: domain, PluralDns: false}
104+
}
105+
prov.writer = func() error { return projectManifest.Write(manifest.ProjectManifestPath()) }
97106
return prov, nil
98107
}
99108

pkg/provider/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func New(provider string) (providerapi.Provider, error) {
8888
case api.ProviderAzure:
8989
return mkAzure(conf, dryRunFlag)
9090
case api.BYOK:
91-
return mkBYOK(conf, clusterFlag, dryRunFlag)
91+
return mkBYOK(conf, clusterFlag, dryRunFlag, cloudFlag)
9292
default:
9393
return nil, fmt.Errorf("invalid provider name: %s", provider)
9494
}

pkg/up/deploy.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,29 @@ func (ctx *Context) deployBYOK(commit func() error) error {
260260
return err
261261
}
262262

263+
subdomain := ctx.Manifest.Network.Subdomain
264+
if err := waitForConsole(); err != nil {
265+
return err
266+
}
267+
268+
utils.Success("Console is up! Access it at https://console.%s\n", subdomain)
269+
270+
if err := ctx.runCheckpoint(ctx.Manifest.Checkpoint, "commit", func() error {
271+
utils.Highlight("\nSetting up gitops management, first lets commit the changes made up to this point...\n\n")
272+
return commit()
273+
}); err != nil {
274+
return err
275+
}
276+
277+
if err := ctx.runCheckpoint(ctx.Manifest.Checkpoint, "apps", func() error {
278+
return runAll([]terraformCmd{
279+
{dir: "./terraform/mgmt", cmd: "apply", args: []string{"-auto-approve"}},
280+
{dir: "./terraform/apps", cmd: "init", args: []string{"-upgrade"}},
281+
{dir: "./terraform/apps", cmd: "apply", args: []string{"-auto-approve"}, retries: 1},
282+
})
283+
}); err != nil {
284+
return err
285+
}
286+
263287
return ctx.pruneBYOK()
264288
}
265-

pkg/up/ping.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88

99
"github.com/likexian/doh"
1010
"github.com/likexian/doh/dns"
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1112

13+
"github.com/pluralsh/plural-cli/pkg/kubernetes"
1214
"github.com/pluralsh/plural-cli/pkg/utils"
1315
)
1416

@@ -69,6 +71,35 @@ func ping(url string) error {
6971
})
7072
}
7173

74+
// waitForConsole polls until the console deployment in plrl-console has at least
75+
// one ready replica. This works on local/BYOK clusters where TLS or public DNS
76+
// is not available.
77+
func waitForConsole() error {
78+
return retrier(
79+
"Waiting for console deployment to become ready...\n",
80+
"Console deployment is ready!\n",
81+
func() error {
82+
kube, err := kubernetes.Kubernetes()
83+
if err != nil {
84+
return err
85+
}
86+
87+
deploy, err := kube.GetClient().AppsV1().Deployments("plrl-console").
88+
Get(context.Background(), "console", metav1.GetOptions{})
89+
if err != nil {
90+
return err
91+
}
92+
93+
if deploy.Status.ReadyReplicas > 0 {
94+
return nil
95+
}
96+
97+
return fmt.Errorf("console deployment not ready yet (%d/%d replicas ready)",
98+
deploy.Status.ReadyReplicas, deploy.Status.Replicas)
99+
},
100+
)
101+
}
102+
72103
func retrier(retryMsg, successMsg string, f func() error) error {
73104
done := make(chan bool)
74105
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)

pkg/up/prune.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,29 @@ func stateRm(dir, field string) error {
7373
return cmd.Run()
7474
}
7575

76+
// stateRmBestEffort is like stateRm but silently ignores the case where the
77+
// resource was never in state (e.g. install_prereqs=false skipped certmanager/flux).
78+
func stateRmBestEffort(dir, field string) {
79+
_ = stateRm(dir, field)
80+
}
81+
7682
// pruneBYOK removes the bootstrap helm/null resources from terraform state and
7783
// cleans up the one-shot files used during installation (no cloud infra to touch).
7884
func (ctx *Context) pruneBYOK() error {
7985
return ctx.runCheckpoint(ctx.Manifest.Checkpoint, "prune:mgmt", func() error {
8086
utils.Highlight("\nCleaning up unneeded resources...\n\n")
8187

82-
toRemove := []string{
88+
// These may or may not be in state depending on install_prereqs value.
89+
stateRmBestEffort("./terraform/mgmt", "helm_release.certmanager")
90+
stateRmBestEffort("./terraform/mgmt", "helm_release.flux")
91+
92+
// These are always created for BYOK.
93+
required := []string{
8394
"null_resource.console",
84-
"helm_release.certmanager",
85-
"helm_release.flux",
8695
"helm_release.runtime",
8796
"helm_release.console",
8897
}
89-
90-
for _, field := range toRemove {
98+
for _, field := range required {
9199
if err := stateRm("./terraform/mgmt", field); err != nil {
92100
return err
93101
}
@@ -104,4 +112,3 @@ func (ctx *Context) pruneBYOK() error {
104112
return git.Sync(repoRoot, "Post-setup resource cleanup", true)
105113
})
106114
}
107-

0 commit comments

Comments
 (0)