blob: 141ad93f8889eec7c649f4baefe0f2b669522614 [file] [log] [blame]
Lorenz Brun52f7f292020-06-24 16:42:02 +02001// Copyright 2020 The Monogon Project Authors.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17package main
18
19import (
Serge Bazanski075465c2021-11-16 15:38:49 +010020 "context"
Lorenz Brun52f7f292020-06-24 16:42:02 +020021 "log"
Lorenz Brun52f7f292020-06-24 16:42:02 +020022
Serge Bazanski1f8cad72023-03-20 16:58:10 +010023 metroctl "source.monogon.dev/metropolis/cli/metroctl/core"
Serge Bazanski075465c2021-11-16 15:38:49 +010024 clicontext "source.monogon.dev/metropolis/cli/pkg/context"
25 "source.monogon.dev/metropolis/test/launch/cluster"
Lorenz Brun52f7f292020-06-24 16:42:02 +020026)
27
28func main() {
Serge Bazanski075465c2021-11-16 15:38:49 +010029 ctx := clicontext.WithInterrupt(context.Background())
30 cl, err := cluster.LaunchCluster(ctx, cluster.ClusterOptions{
Serge Bazanskid09c58f2023-03-17 00:25:08 +010031 NumNodes: 2,
32 NodeLogsToFiles: true,
Serge Bazanski075465c2021-11-16 15:38:49 +010033 })
34 if err != nil {
35 log.Fatalf("LaunchCluster: %v", err)
36 }
Serge Bazanski1f8cad72023-03-20 16:58:10 +010037
38 mpath, err := cluster.MetroctlRunfilePath()
39 if err != nil {
40 log.Fatalf("MetroctlRunfilePath: %v", err)
41 }
42 wpath, err := cl.MakeMetroctlWrapper()
43 if err != nil {
44 log.Fatalf("MakeWrapper: %v", err)
45 }
46
47 apiservers, err := cl.KubernetesControllerNodeAddresses(ctx)
48 if err != nil {
49 log.Fatalf("Could not get Kubernetes controller nodes: %v", err)
50 }
51 if len(apiservers) < 1 {
52 log.Fatalf("Cluster has no Kubernetes controller nodes")
53 }
54
55 configName := "launch-multi2"
56 if err := metroctl.InstallKubeletConfig(mpath, cl.ConnectOptions(), configName, apiservers[0]); err != nil {
57 log.Fatalf("InstallKubeletConfig: %v", err)
58 }
59
Serge Bazanski075465c2021-11-16 15:38:49 +010060 log.Printf("Launch: Cluster running!")
Serge Bazanski1f8cad72023-03-20 16:58:10 +010061 log.Printf(" To access cluster use: metroctl %s", cl.MetroctlFlags())
62 log.Printf(" Or use this handy wrapper: %s", wpath)
63 log.Printf(" To access Kubernetes, use kubectl --context=%s", configName)
Serge Bazanski075465c2021-11-16 15:38:49 +010064
65 <-ctx.Done()
66 cl.Close()
Lorenz Brun52f7f292020-06-24 16:42:02 +020067}