Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: err when deploying with BubbleTea with no cluster #527

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/actions/save-logs/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ runs:
steps:
- name: Fix log permissions
run: |
sudo chown $USER /tmp/uds-*.log || echo ""
sudo chown $USER /tmp/zarf-*.log || echo ""
shell: bash

- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: debug-log
path: /tmp/uds-*.log
path: /tmp/zarf-*.log
7 changes: 4 additions & 3 deletions .github/workflows/nightly-uds-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ jobs:
run: |
chmod +x build/uds

- name: Setup K3d
uses: ./.github/actions/k3d
- name: install-k3d
run: "curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash"
shell: bash

- name: Deploy UDS Core bundle
# renovate: datasource=github-tags depName=defenseunicorns/uds-core versioning=semver
run: build/uds deploy ghcr.io/defenseunicorns/packages/uds/bundles/k3d-core-istio-dev:0.13.1 --confirm --no-progress
run: build/uds deploy k3d-core-istio-dev:0.16.1 --confirm
shell: bash

- name: Validate UDS Core deployment
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/uds.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ var logsCmd = &cobra.Command{
Use: "logs",
Aliases: []string{"l"},
Short: "Display log file contents",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
logFilePath := filepath.Join(config.CommonOptions.CachePath, config.CachedLogs)

// Open the cached log file
Expand Down
20 changes: 6 additions & 14 deletions src/pkg/bundle/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/defenseunicorns/uds-cli/src/config"
"github.com/defenseunicorns/uds-cli/src/pkg/bundler/fetcher"
"github.com/defenseunicorns/uds-cli/src/types"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/oci"
Expand Down Expand Up @@ -264,22 +263,15 @@ func ValidateBundleSignature(bundleYAMLPath, signaturePath, publicKeyPath string
return zarfUtils.CosignVerifyBlob(bundleYAMLPath, signaturePath, publicKeyPath)
}

// GetDeployedPackages returns packages that have been deployed
func GetDeployedPackages() ([]zarfTypes.DeployedPackage, error) {
cluster := cluster.NewClusterOrDie()
deployedPackages, errs := cluster.GetDeployedZarfPackages()
if len(errs) > 0 {
return nil, lang.ErrUnableToGetPackages
}
return deployedPackages, nil
}

// GetDeployedPackageNames returns the names of the packages that have been deployed
func GetDeployedPackageNames() []string {
var deployedPackageNames []string
deployedPackages, _ := GetDeployedPackages()
for _, pkg := range deployedPackages {
deployedPackageNames = append(deployedPackageNames, pkg.Name)
c, _ := cluster.NewCluster()
if c != nil {
deployedPackages, _ := c.GetDeployedZarfPackages()
YrrepNoj marked this conversation as resolved.
Show resolved Hide resolved
for _, pkg := range deployedPackages {
deployedPackageNames = append(deployedPackageNames, pkg.Name)
}
}
return deployedPackageNames
}
Expand Down
10 changes: 10 additions & 0 deletions src/pkg/bundle/tui/common.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The UDS Authors

// Package tui contains logic for the TUI operations
package tui

import (
Expand All @@ -10,11 +11,20 @@ import (
"github.com/charmbracelet/lipgloss"
)

const (
// LIGHTBLUE is the common light blue color used in the TUI
LIGHTBLUE = lipgloss.Color("#4BFDEB")

// LIGHTGRAY is the common light gray color used in the TUI
LIGHTGRAY = lipgloss.Color("#7A7A78")
)

var (
// IndentStyle is the style for indenting text
IndentStyle = lipgloss.NewStyle().Padding(0, 4)
)

// Pause pauses the TUI for a short period of time
func Pause() tea.Cmd {
return tea.Tick(time.Millisecond*500, func(_ time.Time) tea.Msg {
return nil
Expand Down
32 changes: 24 additions & 8 deletions src/pkg/bundle/tui/deploy/handlers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The UDS Authors

// Package deploy contains the TUI logic for bundle deploys
package deploy

import (
Expand All @@ -14,13 +15,20 @@ import (
"github.com/defenseunicorns/uds-cli/src/config"
"github.com/defenseunicorns/uds-cli/src/pkg/bundle/tui"
"github.com/defenseunicorns/uds-cli/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/message"
zarfTypes "github.com/defenseunicorns/zarf/src/types"
)

func (m *model) handleNewPackage(pkgName string, currentPkgIdx int) tea.Cmd {
// see if pkg has already been deployed
deployedPkg, _ := c.GetDeployedPackage(pkgName)
func (m *Model) handleNewPackage(pkgName string, currentPkgIdx int) tea.Cmd {
// check if pkg has already been deployed
var deployedPkg *zarfTypes.DeployedPackage
if c != nil {
deployedPkg, _ = c.GetDeployedPackage(pkgName)
} else {
// keep checking for cluster connectivity
c, _ = cluster.NewCluster()
}
newPkg := pkgState{
name: pkgName,
}
Expand Down Expand Up @@ -56,7 +64,7 @@ func (m *model) handleNewPackage(pkgName string, currentPkgIdx int) tea.Cmd {
)
}

func (m *model) handlePreDeploy() tea.Cmd {
func (m *Model) handlePreDeploy() tea.Cmd {
cmd := func() tea.Msg {
name, bundleYAML, source, err := m.bndlClient.PreDeployValidation()
if err != nil {
Expand All @@ -75,7 +83,7 @@ func (m *model) handlePreDeploy() tea.Cmd {
return cmd
}

func (m *model) handleDeploy() tea.Cmd {
func (m *Model) handleDeploy() tea.Cmd {
// ensure bundle deployment is confirmed and is only being deployed once
if m.confirmed && !m.deploying {
// run Deploy concurrently so we can update the TUI while it runs
Expand All @@ -97,7 +105,7 @@ func (m *model) handleDeploy() tea.Cmd {
return nil
}

func (m *model) handleDone(err error) tea.Cmd {
func (m *Model) handleDone(err error) tea.Cmd {
cmds := []tea.Cmd{tea.Println(), tea.Println(m.udsTitle()), tea.Println()}
m.done = true // remove the current view
cmds = append(cmds, genSuccessCmds(m)...)
Expand All @@ -116,7 +124,7 @@ func (m *model) handleDone(err error) tea.Cmd {
return tea.Sequence(cmds...)
}

func (m *model) handleDeployTick() (tea.Model, tea.Cmd) {
func (m *Model) handleDeployTick() (tea.Model, tea.Cmd) {
// check if all pkgs are complete
numComplete := 0
if len(m.packages) == m.totalPkgs {
Expand All @@ -141,7 +149,15 @@ func (m *model) handleDeployTick() (tea.Model, tea.Cmd) {
if p.complete {
continue
}
deployedPkg, _ := c.GetDeployedPackage(p.name)

var deployedPkg *zarfTypes.DeployedPackage
if c != nil {
deployedPkg, _ = c.GetDeployedPackage(p.name)
} else {
// keep checking for cluster connectivity
c, _ = cluster.NewCluster()
}

// if deployedPkg is nil, the package hasn't been deployed yet
if deployedPkg == nil {
break
Expand Down
18 changes: 10 additions & 8 deletions src/pkg/bundle/tui/deploy/model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The UDS Authors

// Package deploy contains the TUI logic for bundle deploys
package deploy

import (
Expand Down Expand Up @@ -35,6 +36,7 @@
)

var (
// Program is the Bubbletea TUI main program
Program *tea.Program
c *cluster.Cluster
logVpWidthScale = 0.9
Expand Down Expand Up @@ -65,7 +67,7 @@
isRemote bool
}

type model struct {
type Model struct {

Check warning on line 70 in src/pkg/bundle/tui/deploy/model.go

View workflow job for this annotation

GitHub Actions / validate

exported type Model should have comment or be unexported
bndlClient bndlClientShim
bundleYAML string
doneChan chan int
Expand All @@ -86,7 +88,8 @@
validatingBundleSpinner spinner.Model
}

func InitModel(client bndlClientShim) model {
// InitModel initializes the model for the TUI
func InitModel(client bndlClientShim) Model {
var confirmed bool
var inProgress bool
var isRemoteBundle bool
Expand Down Expand Up @@ -120,7 +123,7 @@
numYAMLLines := 10
yamlViewport := viewport.New(termWidth, numYAMLLines)

return model{
return Model{
bndlClient: client,
doneChan: make(chan int),
errChan: make(chan error),
Expand All @@ -134,13 +137,13 @@
}
}

func (m *model) Init() tea.Cmd {
func (m *Model) Init() tea.Cmd {

Check warning on line 140 in src/pkg/bundle/tui/deploy/model.go

View workflow job for this annotation

GitHub Actions / validate

exported method Model.Init should have comment or be unexported
return func() tea.Msg {
return doPreDeploy
}
}

func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

Check warning on line 146 in src/pkg/bundle/tui/deploy/model.go

View workflow job for this annotation

GitHub Actions / validate

exported method Model.Update should have comment or be unexported
select {
case err := <-m.errChan:
cmd := m.handleDone(err)
Expand Down Expand Up @@ -273,7 +276,7 @@
return m, nil
}

func (m *model) View() string {
func (m *Model) View() string {

Check warning on line 279 in src/pkg/bundle/tui/deploy/model.go

View workflow job for this annotation

GitHub Actions / validate

exported method Model.View should have comment or be unexported
if m.done {
// no errors, clear the controlled Program's output
return ""
Expand All @@ -284,7 +287,6 @@
return fmt.Sprintf("\n%s\n\n%s\n%s\n\n%s\n", m.udsTitle(), m.bundleDeployProgress(), logMsg, m.logView())
} else if m.confirmed {
return fmt.Sprintf("\n%s\n\n%s\n%s\n%s\n", m.udsTitle(), m.bundleDeployProgress(), logMsg, m.deployView())
} else {
return fmt.Sprintf("%s\n", m.preDeployView())
}
return fmt.Sprintf("%s\n", m.preDeployView())
}
34 changes: 15 additions & 19 deletions src/pkg/bundle/tui/deploy/views.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The UDS Authors

// Package deploy contains the TUI logic for bundle deploys
package deploy

import (
Expand All @@ -16,17 +17,12 @@ import (
"github.com/goccy/go-yaml/printer"
)

const (
LIGHTBLUE = lipgloss.Color("#4BFDEB")
LIGHTGRAY = lipgloss.Color("#7A7A78")
)

var (
termWidth int
termHeight int
styledCheck = lipgloss.NewStyle().Foreground(lipgloss.Color("#00FF00")).Render("✔")
lightBlueText = lipgloss.NewStyle().Foreground(LIGHTBLUE)
lightGrayText = lipgloss.NewStyle().Foreground(LIGHTGRAY)
lightBlueText = lipgloss.NewStyle().Foreground(tui.LIGHTBLUE)
lightGrayText = lipgloss.NewStyle().Foreground(tui.LIGHTGRAY)
logMsg = tui.IndentStyle.Render(fmt.Sprintf("\n%s %s",
lightBlueText.Render("<l>"), lightGrayText.Render("Toggle logs")))
)
Expand All @@ -39,26 +35,26 @@ var (
}()
)

func (m *model) logView() string {
func (m *Model) logView() string {
headerMsg := fmt.Sprintf("%s %s", lightBlueText.Render(m.packages[m.pkgIdx].name), lightGrayText.Render("package logs"))
return tui.IndentStyle.Render(
fmt.Sprintf("%s\n%s\n%s\n\n", m.logHeaderView(headerMsg), m.logViewport.View(), m.logFooterView()),
)
}

func (m *model) yamlHeaderView() string {
func (m *Model) yamlHeaderView() string {
upArrow := "▲ "
styledUpArrow := lipgloss.NewStyle().Foreground(LIGHTGRAY).Render(upArrow)
styledUpArrow := lipgloss.NewStyle().Foreground(tui.LIGHTGRAY).Render(upArrow)
if !m.yamlViewport.AtTop() {
styledUpArrow = lipgloss.NewStyle().Foreground(lipgloss.Color("#FFF258")).Render(upArrow)
}
headerLine := strings.Repeat("─", max(0, m.logViewport.Width-lipgloss.Width(styledUpArrow)-1))
return lipgloss.JoinHorizontal(lipgloss.Center, styledUpArrow, headerLine)
}

func (m *model) yamlFooterView() string {
func (m *Model) yamlFooterView() string {
downArrow := "▼ "
styledDownArrow := lipgloss.NewStyle().Foreground(LIGHTGRAY).Render(downArrow)
styledDownArrow := lipgloss.NewStyle().Foreground(tui.LIGHTGRAY).Render(downArrow)
if !m.yamlViewport.AtBottom() {
styledDownArrow = lipgloss.NewStyle().Foreground(lipgloss.Color("#FFF258")).Render(downArrow)

Expand All @@ -67,7 +63,7 @@ func (m *model) yamlFooterView() string {
return lipgloss.JoinHorizontal(lipgloss.Center, styledDownArrow, footerLine)
}

func (m *model) logHeaderView(msg string) string {
func (m *Model) logHeaderView(msg string) string {
title := titleStyle.Render(msg)
if msg == "" {
title = ""
Expand All @@ -76,12 +72,12 @@ func (m *model) logHeaderView(msg string) string {
return lipgloss.JoinHorizontal(lipgloss.Center, title, headerLine)
}

func (m *model) logFooterView() string {
func (m *Model) logFooterView() string {
footerLine := strings.Repeat("─", max(0, m.logViewport.Width)-1)
return lipgloss.JoinHorizontal(lipgloss.Center, footerLine)
}

func (m *model) deployView() string {
func (m *Model) deployView() string {
view := ""
for _, p := range m.packages {
// count number of successful components
Expand Down Expand Up @@ -156,7 +152,7 @@ func genRemotePkgText(p pkgState, numComponentsSuccess int) string {
return text
}

func (m *model) preDeployView() string {
func (m *Model) preDeployView() string {
header := tui.IndentStyle.Render("📦 Bundle Definition (▲ / ▼)")
prompt := tui.IndentStyle.Render("❓ Deploy this bundle? (y/n)")
prettyYAML := tui.IndentStyle.Render(colorPrintYAML(m.bundleYAML))
Expand Down Expand Up @@ -231,7 +227,7 @@ func yamlFormat(attr color.Attribute) string {
}

// udsTitle returns the title header for the UDS bundle
func (m *model) udsTitle() string {
func (m *Model) udsTitle() string {
styledBundleName := lipgloss.NewStyle().Foreground(lipgloss.Color("#FFF258")).Render(m.bundleName + " ")
title := " UDS Bundle: "
styledTitle := lipgloss.NewStyle().Margin(0, 3).
Expand All @@ -243,7 +239,7 @@ func (m *model) udsTitle() string {
}

// genSuccessCmds generates the success or failure messages for each package
func genSuccessCmds(m *model) []tea.Cmd {
func genSuccessCmds(m *Model) []tea.Cmd {
var cmds []tea.Cmd
for i := 0; i < len(m.packages); i++ {
successMsg := fmt.Sprintf("%s Package %s deployed\n", styledCheck, lightBlueText.Render(m.packages[i].name))
Expand All @@ -252,7 +248,7 @@ func genSuccessCmds(m *model) []tea.Cmd {
return cmds
}

func (m *model) bundleDeployProgress() string {
func (m *Model) bundleDeployProgress() string {
styledText := lightGrayText.Render("📦 Deploying bundle package")
styledPkgCounter := lightGrayText.Render(fmt.Sprintf("(%d / %d)", m.pkgIdx+1, m.totalPkgs))
msg := fmt.Sprintf("%s %s", styledText, styledPkgCounter)
Expand Down
Loading