blob: c9b9dec49e00938302d40605a67a36b64e14e933 [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"
Tim Windelschmidtb765f242024-05-08 01:40:02 +020022 "os"
23 "os/signal"
Lorenz Brun52f7f292020-06-24 16:42:02 +020024
Serge Bazanski1f8cad72023-03-20 16:58:10 +010025 metroctl "source.monogon.dev/metropolis/cli/metroctl/core"
Serge Bazanski075465c2021-11-16 15:38:49 +010026 "source.monogon.dev/metropolis/test/launch/cluster"
Lorenz Brun52f7f292020-06-24 16:42:02 +020027)
28
29func main() {
Tim Windelschmidtb765f242024-05-08 01:40:02 +020030 ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt)
Serge Bazanski075465c2021-11-16 15:38:49 +010031 cl, err := cluster.LaunchCluster(ctx, cluster.ClusterOptions{
Serge Bazanski6a328e62024-02-12 17:37:50 +010032 NumNodes: 3,
Serge Bazanskid09c58f2023-03-17 00:25:08 +010033 NodeLogsToFiles: true,
Serge Bazanski075465c2021-11-16 15:38:49 +010034 })
35 if err != nil {
36 log.Fatalf("LaunchCluster: %v", err)
37 }
Serge Bazanski1f8cad72023-03-20 16:58:10 +010038
39 mpath, err := cluster.MetroctlRunfilePath()
40 if err != nil {
41 log.Fatalf("MetroctlRunfilePath: %v", err)
42 }
43 wpath, err := cl.MakeMetroctlWrapper()
44 if err != nil {
45 log.Fatalf("MakeWrapper: %v", err)
46 }
47
48 apiservers, err := cl.KubernetesControllerNodeAddresses(ctx)
49 if err != nil {
50 log.Fatalf("Could not get Kubernetes controller nodes: %v", err)
51 }
52 if len(apiservers) < 1 {
53 log.Fatalf("Cluster has no Kubernetes controller nodes")
54 }
55
Serge Bazanski6a328e62024-02-12 17:37:50 +010056 configName := "launch-cluster"
Serge Bazanski568c38c2024-02-05 14:40:39 +010057 if err := metroctl.InstallKubeletConfig(ctx, mpath, cl.ConnectOptions(), configName, apiservers[0]); err != nil {
Serge Bazanski1f8cad72023-03-20 16:58:10 +010058 log.Fatalf("InstallKubeletConfig: %v", err)
59 }
60
Serge Bazanski075465c2021-11-16 15:38:49 +010061 log.Printf("Launch: Cluster running!")
Serge Bazanski1f8cad72023-03-20 16:58:10 +010062 log.Printf(" To access cluster use: metroctl %s", cl.MetroctlFlags())
63 log.Printf(" Or use this handy wrapper: %s", wpath)
64 log.Printf(" To access Kubernetes, use kubectl --context=%s", configName)
Serge Bazanski075465c2021-11-16 15:38:49 +010065
66 <-ctx.Done()
67 cl.Close()
Lorenz Brun52f7f292020-06-24 16:42:02 +020068}