Skip to content

Commit 8784242

Browse files
install openebs and admin console (#1577)
* install openebs * f * Make openebs addon install successfully (#1575) * Install openebs addon * add metadata and values yaml to addons2 pkg * add namespace * Install Admin Console as part of install2 (#1576) * Install Admin Console as part of install2 * errors wrap * updates --------- Co-authored-by: Salah Al Saleh <[email protected]>
1 parent 675ea51 commit 8784242

File tree

16 files changed

+714
-19
lines changed

16 files changed

+714
-19
lines changed

cmd/installer/cli/install2.go

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88

99
k0sconfig "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
1010
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
11+
"github.com/replicatedhq/embedded-cluster/pkg/addons2"
1112
"github.com/replicatedhq/embedded-cluster/pkg/configutils"
1213
"github.com/replicatedhq/embedded-cluster/pkg/helpers"
1314
"github.com/replicatedhq/embedded-cluster/pkg/k0s"
1415
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
16+
"github.com/replicatedhq/embedded-cluster/pkg/netutils"
1517
"github.com/replicatedhq/embedded-cluster/pkg/preflights"
1618
"github.com/replicatedhq/embedded-cluster/pkg/prompts"
1719
"github.com/replicatedhq/embedded-cluster/pkg/release"
@@ -183,14 +185,33 @@ func runInstall2(cmd *cobra.Command, args []string, name string, flags Install2C
183185
return err
184186
}
185187

186-
fmt.Printf("%#v\n", clusterConfig)
188+
logrus.Debugf("installing addons")
189+
if err := addons2.InstallAddons(cmd.Context(), addons2.InstallOptions{
190+
ClusterConfig: clusterConfig,
191+
AdminConsolePwd: flags.adminConsolePassword,
192+
License: flags.license,
193+
LicenseFile: flags.licenseFile,
194+
AirgapBundle: flags.airgapBundle,
195+
Proxy: flags.proxy,
196+
PrivateCAs: flags.privateCAs,
197+
ConfigValuesFile: flags.configValues,
198+
NetworkInterface: flags.networkInterface,
199+
}); err != nil {
200+
metrics.ReportApplyFinished(cmd.Context(), "", flags.license, err)
201+
return err
202+
}
187203

188204
logrus.Debugf("installing manager")
189205
if err := installAndEnableManager(); err != nil {
190206
metrics.ReportApplyFinished(cmd.Context(), "", flags.license, err)
191207
return err
192208
}
193209

210+
if err := printSuccessMessage(flags.license, flags.networkInterface); err != nil {
211+
metrics.ReportApplyFinished(cmd.Context(), "", flags.license, err)
212+
return err
213+
}
214+
194215
return nil
195216
}
196217

@@ -336,6 +357,42 @@ func installAndStartCluster(ctx context.Context, networkInterface string, airgap
336357
return nil, err
337358
}
338359

360+
// init the kubeconfig
361+
os.Setenv("KUBECONFIG", runtimeconfig.PathToKubeConfig())
362+
339363
loading.Infof("Node installation finished!")
340364
return cfg, nil
341365
}
366+
367+
func printSuccessMessage(license *kotsv1beta1.License, networkInterface string) error {
368+
adminConsoleURL := getAdminConsoleURL(networkInterface, runtimeconfig.AdminConsolePort())
369+
370+
successColor := "\033[32m"
371+
colorReset := "\033[0m"
372+
var successMessage string
373+
if license != nil {
374+
successMessage = fmt.Sprintf("Visit the Admin Console to configure and install %s: %s%s%s",
375+
license.Spec.AppSlug, successColor, adminConsoleURL, colorReset,
376+
)
377+
} else {
378+
successMessage = fmt.Sprintf("Visit the Admin Console to configure and install your application: %s%s%s",
379+
successColor, adminConsoleURL, colorReset,
380+
)
381+
}
382+
logrus.Info(successMessage)
383+
384+
return nil
385+
}
386+
387+
func getAdminConsoleURL(networkInterface string, port int) string {
388+
ipaddr := runtimeconfig.TryDiscoverPublicIP()
389+
if ipaddr == "" {
390+
var err error
391+
ipaddr, err = netutils.FirstValidAddress(networkInterface)
392+
if err != nil {
393+
logrus.Errorf("unable to determine node IP address: %v", err)
394+
ipaddr = "NODE-IP-ADDRESS"
395+
}
396+
}
397+
return fmt.Sprintf("http://%s:%v", ipaddr, port)
398+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ require (
4848
helm.sh/helm/v3 v3.16.3
4949
k8s.io/api v0.31.3
5050
k8s.io/apimachinery v0.31.3
51+
k8s.io/cli-runtime v0.31.3
5152
k8s.io/client-go v0.31.3
5253
k8s.io/kubectl v0.31.3
5354
k8s.io/utils v0.0.0-20240921022957-49e7df575cb6
@@ -296,7 +297,6 @@ require (
296297
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
297298
gopkg.in/ini.v1 v1.67.0 // indirect
298299
k8s.io/apiserver v0.31.3 // indirect
299-
k8s.io/cli-runtime v0.31.3 // indirect
300300
k8s.io/component-base v0.31.3 // indirect
301301
k8s.io/kubelet v0.31.2 // indirect
302302
k8s.io/metrics v0.31.3 // indirect

pkg/addons2/addons.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,67 @@
11
package addons2
2+
3+
import (
4+
"context"
5+
6+
k0sconfig "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
7+
"github.com/pkg/errors"
8+
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
9+
"github.com/replicatedhq/embedded-cluster/pkg/addons2/adminconsole"
10+
"github.com/replicatedhq/embedded-cluster/pkg/addons2/openebs"
11+
"github.com/replicatedhq/embedded-cluster/pkg/addons2/types"
12+
"github.com/replicatedhq/embedded-cluster/pkg/kubeutils"
13+
"github.com/replicatedhq/embedded-cluster/pkg/spinner"
14+
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
15+
)
16+
17+
type InstallOptions struct {
18+
ClusterConfig *k0sconfig.ClusterConfig
19+
AdminConsolePwd string
20+
License *kotsv1beta1.License
21+
LicenseFile string
22+
AirgapBundle string
23+
Proxy *ecv1beta1.ProxySpec
24+
PrivateCAs []string
25+
ConfigValuesFile string
26+
NetworkInterface string
27+
}
28+
29+
// this is a temp function that's much more specific than we actually need it to be
30+
// this is going to get us to working installs, and we refactor.
31+
// this is not configurable at all, it's not the way it needs to be in the product
32+
func InstallAddons(ctx context.Context, opts InstallOptions) error {
33+
addsOns := []types.AddOn{
34+
&openebs.OpenEBS{},
35+
&adminconsole.AdminConsole{
36+
Password: opts.AdminConsolePwd,
37+
License: opts.License,
38+
LicenseFile: opts.LicenseFile,
39+
AirgapBundle: opts.AirgapBundle,
40+
Proxy: opts.Proxy,
41+
PrivateCAs: opts.PrivateCAs,
42+
ConfigValuesFile: opts.ConfigValuesFile,
43+
NetworkInterface: opts.NetworkInterface,
44+
},
45+
}
46+
47+
kcli, err := kubeutils.KubeClient()
48+
if err != nil {
49+
return errors.Wrap(err, "create kube client")
50+
}
51+
52+
loading := spinner.Start()
53+
defer loading.Close()
54+
55+
for _, addon := range addsOns {
56+
loading.Infof("Installing %s addon", addon.Name())
57+
58+
if err := addon.Prepare(); err != nil {
59+
return errors.Wrap(err, "prepare addon")
60+
}
61+
if err := addon.Install(ctx, kcli, loading); err != nil {
62+
return errors.Wrap(err, "install addon")
63+
}
64+
}
65+
66+
return nil
67+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package adminconsole
2+
3+
import (
4+
_ "embed"
5+
6+
"github.com/pkg/errors"
7+
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
8+
"github.com/replicatedhq/embedded-cluster/pkg/release"
9+
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
10+
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
11+
"gopkg.in/yaml.v3"
12+
)
13+
14+
type AdminConsole struct {
15+
Password string
16+
License *kotsv1beta1.License
17+
LicenseFile string
18+
AirgapBundle string
19+
IsHA bool
20+
Proxy *ecv1beta1.ProxySpec
21+
PrivateCAs []string
22+
ConfigValuesFile string
23+
NetworkInterface string
24+
}
25+
26+
const (
27+
releaseName = "admin-console"
28+
namespace = runtimeconfig.KotsadmNamespace
29+
)
30+
31+
var (
32+
//go:embed static/values.tpl.yaml
33+
rawvalues []byte
34+
// helmValues is the unmarshal version of rawvalues.
35+
helmValues map[string]interface{}
36+
//go:embed static/metadata.yaml
37+
rawmetadata []byte
38+
// Metadata is the unmarshal version of rawmetadata.
39+
Metadata release.AddonMetadata
40+
)
41+
42+
func init() {
43+
if err := yaml.Unmarshal(rawmetadata, &Metadata); err != nil {
44+
panic(errors.Wrap(err, "unmarshal metadata"))
45+
}
46+
hv, err := release.RenderHelmValues(rawvalues, Metadata)
47+
if err != nil {
48+
panic(errors.Wrap(err, "unmarshal values"))
49+
}
50+
helmValues = hv
51+
}
52+
53+
func (a *AdminConsole) Name() string {
54+
return "Admin Console"
55+
}

0 commit comments

Comments
 (0)