Skip to content

Commit a81e5d6

Browse files
committed
feat: improve local UX with up --create-cluster and --watch by default
This also updates the CI tests to improve test coverage of the create-cluster code paths. Signed-off-by: Nick Mitchell <[email protected]>
1 parent 142e30b commit a81e5d6

File tree

9 files changed

+57
-21
lines changed

9 files changed

+57
-21
lines changed

.github/workflows/actions.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ jobs:
2727
steps:
2828
- uses: actions/checkout@v4
2929

30-
- name: Create k8s Kind Cluster
31-
uses: helm/[email protected]
32-
with:
33-
install_only: true
30+
# we will also be testing installing kind, so we don't want to do
31+
# this as part of the github action workflow
32+
#- name: Create k8s Kind Cluster
33+
# uses: helm/[email protected]
34+
# with:
35+
# install_only: true
3436

3537
- name: Setup
3638
run: ./tests/bin/travis/setup.sh

cmd/subcommands/init/local.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ import (
66
)
77

88
func NewInitLocalCmd() *cobra.Command {
9+
var buildFlag bool
910
var verboseFlag bool
1011

1112
var cmd = &cobra.Command{
1213
Use: "local",
1314
Short: "Initialize a local control plane",
1415
Long: "Initialize a local control plane",
1516
RunE: func(cmd *cobra.Command, args []string) error {
16-
return initialize.Local(initialize.InitLocalOptions{Verbose: verboseFlag})
17+
return initialize.Local(initialize.InitLocalOptions{BuildImages: buildFlag, Verbose: verboseFlag})
1718
},
1819
}
1920

20-
cmd.Flags().BoolVarP(&verboseFlag, "verbose", "v", verboseFlag, "Verbose output")
21+
cmd.Flags().BoolVarP(&buildFlag, "build-images", "b", false, "Also build Lunchpail support images")
22+
cmd.Flags().BoolVarP(&verboseFlag, "verbose", "v", false, "Verbose output")
2123
return cmd
2224
}

cmd/subcommands/up.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"lunchpail.io/pkg/be"
66
"lunchpail.io/pkg/boot"
77
"lunchpail.io/pkg/fe/linker"
8+
initialize "lunchpail.io/pkg/lunchpail/init"
9+
"lunchpail.io/pkg/util"
810

911
"github.com/spf13/cobra"
1012
)
@@ -36,7 +38,8 @@ func addAssemblyOptions(cmd *cobra.Command) *assembly.Options {
3638
func newUpCmd() *cobra.Command {
3739
var verboseFlag bool
3840
var dryrunFlag bool
39-
var watchFlag bool
41+
watchFlag := false
42+
var createCluster bool
4043
var createNamespace bool
4144

4245
var cmd = &cobra.Command{
@@ -45,14 +48,29 @@ func newUpCmd() *cobra.Command {
4548
Long: "Deploy the application",
4649
}
4750

51+
if util.StdoutIsTty() {
52+
// default to watch if we are connected to a TTY
53+
watchFlag = true
54+
}
55+
4856
cmd.Flags().SortFlags = false
4957
appOpts := addAssemblyOptions(cmd)
5058
cmd.Flags().BoolVarP(&dryrunFlag, "dry-run", "", false, "Emit application yaml to stdout")
5159
cmd.Flags().BoolVarP(&verboseFlag, "verbose", "v", false, "Verbose output")
52-
cmd.Flags().BoolVarP(&watchFlag, "watch", "w", false, "After deployment, watch for status updates")
53-
cmd.Flags().BoolVarP(&createNamespace, "create-namespace", "N", false, "Create a new Kubernetes namespace")
60+
cmd.Flags().BoolVarP(&watchFlag, "watch", "w", watchFlag, "After deployment, watch for status updates")
61+
cmd.Flags().BoolVarP(&createCluster, "create-cluster", "I", false, "Create a new (local) Kubernetes cluster, if needed")
62+
cmd.Flags().BoolVarP(&createNamespace, "create-namespace", "N", false, "Create a new Kubernetes namespace, if needed")
5463

5564
cmd.RunE = func(cmd *cobra.Command, args []string) error {
65+
if appOpts.TargetPlatform == be.Kubernetes && createCluster {
66+
if err := initialize.Local(initialize.InitLocalOptions{BuildImages: false, Verbose: verboseFlag}); err != nil {
67+
return err
68+
}
69+
70+
// if we were asked to create a cluster, then certainly we will want to create a namespace
71+
createNamespace = true
72+
}
73+
5674
overrideValues, err := cmd.Flags().GetStringSlice("set")
5775
if err != nil {
5876
return err

hack/init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ if [ ! -f /tmp/lunchpail ]
99
then "$TOP"/hack/setup/cli.sh /tmp/lunchpail
1010
fi
1111

12-
/tmp/lunchpail init local
12+
/tmp/lunchpail init local --build-images

pkg/lunchpail/init/kind.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func createKindCluster() error {
6464
args = append(args, "/tmp/kindhack.yaml")
6565
}
6666

67-
fmt.Printf("Creating kind cluster " + lunchpail.LocalClusterName)
67+
fmt.Printf("Creating kind cluster %s\n", lunchpail.LocalClusterName)
6868

6969
cmd := exec.Command("kind", args...)
7070
cmd.Stdout = os.Stdout

pkg/lunchpail/init/local.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
)
99

1010
type InitLocalOptions struct {
11-
Verbose bool
11+
BuildImages bool
12+
Verbose bool
1213
}
1314

1415
func Local(opts InitLocalOptions) error {
@@ -37,7 +38,13 @@ func Local(opts InitLocalOptions) error {
3738
return err
3839
}
3940

40-
bopts := build.BuildOptions{}
41-
bopts.Verbose = opts.Verbose
42-
return images.Build(bopts)
41+
if opts.BuildImages {
42+
bopts := build.BuildOptions{}
43+
bopts.Verbose = opts.Verbose
44+
if err := images.Build(bopts); err != nil {
45+
return err
46+
}
47+
}
48+
49+
return nil
4350
}

pkg/util/term.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package util
2+
3+
import "os"
4+
5+
func StdoutIsTty() bool {
6+
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
7+
return true
8+
} else {
9+
return false
10+
}
11+
}

tests/bin/deploy-tests.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ repo_secret="" # e.g. user:pat@https://github.mycompany.com
7272
$repo_secret \
7373
$2
7474

75-
echo "!!!!!!!!!!!!!!!XXXXXXXXXXXXXXXXXXXXXXX $2"
7675
if [[ -d "$2" ]] && [[ -f "$2"/version ]]
7776
then
7877
# Check that app version passes through

tests/bin/travis/setup.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
#!/usr/bin/env bash
22

3-
set -e
4-
set -o pipefail
3+
set -eo pipefail
54

6-
# ibm travis currently runs ubuntu 20, for which there are no podman
7-
# v4 builds. We rely on v4 for the `podman machine init --rootful`
8-
# option
5+
# Keeping this here, in case we want to test podman in CI.
96
# if ! which podman >& /dev/null
107
# then
118
# echo "Installing podman"

0 commit comments

Comments
 (0)