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

test: remove TestMismatchedVersions e2e test #2564

Merged
merged 2 commits into from
May 31, 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
8 changes: 7 additions & 1 deletion src/pkg/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package message
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"runtime/debug"
Expand Down Expand Up @@ -59,6 +60,11 @@ func (d *DebugWriter) Write(raw []byte) (int, error) {
}

func init() {
InitializePTerm(os.Stderr)
}

// InitializePTerm sets the default styles and output for pterm.
func InitializePTerm(w io.Writer) {
pterm.ThemeDefault.SuccessMessageStyle = *pterm.NewStyle(pterm.FgLightGreen)
// Customize default error.
pterm.Success.Prefix = pterm.Prefix{
Expand All @@ -73,7 +79,7 @@ func init() {
Text: " •",
}

pterm.SetDefaultOutput(os.Stderr)
pterm.SetDefaultOutput(w)
}

// UseLogFile wraps a given file in a PausableWriter
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/packager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (p *Packager) attemptClusterChecks(ctx context.Context) (err error) {
// Check for any breaking changes between the initialized Zarf version and this CLI
if existingInitPackage, _ := p.cluster.GetDeployedPackage(ctx, "init"); existingInitPackage != nil {
// Use the build version instead of the metadata since this will support older Zarf versions
deprecated.PrintBreakingChanges(existingInitPackage.Data.Build.Version)
deprecated.PrintBreakingChanges(os.Stderr, existingInitPackage.Data.Build.Version, config.CLIVersion)
}

spinner.Success()
Expand Down
77 changes: 40 additions & 37 deletions src/pkg/packager/deprecated/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,33 @@ package deprecated

import (
"fmt"
"io"
"strings"

"slices"

"github.com/Masterminds/semver/v3"
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/types"
"github.com/pterm/pterm"
)

// BreakingChange represents a breaking change that happened on a specified Zarf version
// BreakingChange represents a breaking change that happened on a specified Zarf version.
type BreakingChange struct {
version *semver.Version
title string
mitigation string
}

// String returns the string representation of the BreakingChange.
func (bc BreakingChange) String() string {
return fmt.Sprintf("%s\n\n - %s\n %s\n",
pterm.Bold.Sprintf(bc.title),
pterm.Bold.Sprint("Mitigation:"),
strings.ReplaceAll(message.Paragraphn(96, "%s", pterm.FgLightCyan.Sprint(bc.mitigation)), "\n", "\n "),
)
}

// List of migrations tracked in the zarf.yaml build data.
const (
// This should be updated when a breaking change is introduced to the Zarf package structure. See: https://github.com/defenseunicorns/zarf/releases/tag/v0.27.0
Expand All @@ -32,15 +41,6 @@ const (
PluralizeSetVariable = "pluralize-set-variable"
)

// List of breaking changes to warn the user of.
var breakingChanges = []BreakingChange{
{
version: semver.New(0, 26, 0, "", ""),
title: "Zarf container images are now mutated based on tag instead of repository name.",
mitigation: "Reinitialize the cluster using v0.26.0 or later and redeploy existing packages to update the image references (you can view existing packages with 'zarf package list' and view cluster images with 'zarf tools registry catalog').",
},
}

// MigrateComponent runs all migrations on a component.
// Build should be empty on package create, but include just in case someone copied a zarf.yaml from a zarf package.
func MigrateComponent(build types.ZarfBuildData, component types.ZarfComponent) (migratedComponent types.ZarfComponent, warnings []string) {
Expand Down Expand Up @@ -77,47 +77,50 @@ func MigrateComponent(build types.ZarfBuildData, component types.ZarfComponent)
return migratedComponent, warnings
}

// PrintBreakingChanges prints the breaking changes between the provided version and the current CLIVersion
func PrintBreakingChanges(deployedZarfVersion string) {
// PrintBreakingChanges prints the breaking changes between the provided version and the current CLIVersion.
func PrintBreakingChanges(w io.Writer, deployedZarfVersion, cliVersion string) {
deployedSemver, err := semver.NewVersion(deployedZarfVersion)
if err != nil {
message.Debugf("Unable to check for breaking changes between Zarf versions")
return
}

applicableBreakingChanges := []BreakingChange{}
// List of breaking changes to warn the user of.
var breakingChanges = []BreakingChange{
{
version: semver.MustParse("0.26.0"),
title: "Zarf container images are now mutated based on tag instead of repository name.",
mitigation: "Reinitialize the cluster using v0.26.0 or later and redeploy existing packages to update the image references (you can view existing packages with 'zarf package list' and view cluster images with 'zarf tools registry catalog').",
},
}

// Calculate the applicable breaking changes
// Calculate the applicable breaking changes.
var applicableBreakingChanges []BreakingChange
for _, breakingChange := range breakingChanges {
if deployedSemver.LessThan(breakingChange.version) {
applicableBreakingChanges = append(applicableBreakingChanges, breakingChange)
}
}

if len(applicableBreakingChanges) > 0 {
// Print header information
message.HorizontalRule()
message.Title("Potential Breaking Changes", "breaking changes that may cause issues with this package")

// Print information about the versions
format := pterm.FgYellow.Sprint("CLI version ") + "%s" + pterm.FgYellow.Sprint(" is being used to deploy to a cluster that was initialized with ") +
"%s" + pterm.FgYellow.Sprint(". Between these versions there are the following breaking changes to consider:")
cliVersion := pterm.Bold.Sprintf(config.CLIVersion)
deployedVersion := pterm.Bold.Sprintf(deployedZarfVersion)
message.Warnf(format, cliVersion, deployedVersion)

// Print each applicable breaking change
for idx, applicableBreakingChange := range applicableBreakingChanges {
titleFormat := pterm.Bold.Sprintf("\n %d. ", idx+1) + "%s"

pterm.Printfln(titleFormat, applicableBreakingChange.title)
if len(applicableBreakingChanges) == 0 {
return
}

mitigationText := message.Paragraphn(96, "%s", pterm.FgLightCyan.Sprint(applicableBreakingChange.mitigation))
// Print header information
message.HorizontalRule()
message.Title("Potential Breaking Changes", "breaking changes that may cause issues with this package")

pterm.Printfln("\n - %s", pterm.Bold.Sprint("Mitigation:"))
pterm.Printfln(" %s", strings.ReplaceAll(mitigationText, "\n", "\n "))
}
// Print information about the versions
format := pterm.FgYellow.Sprint("CLI version ") + "%s" + pterm.FgYellow.Sprint(" is being used to deploy to a cluster that was initialized with ") +
"%s" + pterm.FgYellow.Sprint(". Between these versions there are the following breaking changes to consider:")
cliVersion = pterm.Bold.Sprintf(cliVersion)
deployedZarfVersion = pterm.Bold.Sprintf(deployedZarfVersion)
message.Warnf(format, cliVersion, deployedZarfVersion)

message.HorizontalRule()
// Print each applicable breaking change
for i, applicableBreakingChange := range applicableBreakingChanges {
fmt.Fprintf(w, "\n %d. %s", i+1, applicableBreakingChange.String())
}

message.HorizontalRule()
}
58 changes: 58 additions & 0 deletions src/pkg/packager/deprecated/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package deprecated handles package deprecations and migrations
package deprecated

import (
"bytes"
"testing"

"github.com/Masterminds/semver/v3"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/stretchr/testify/require"
)

func TestPrintBreakingChanges(t *testing.T) {
t.Parallel()

tests := []struct {
name string
deployedVersion string
cliVersion string
breakingChanges []BreakingChange
}{
{
name: "No breaking changes",
deployedVersion: "0.26.0",
cliVersion: "0.26.0",
breakingChanges: []BreakingChange{},
},
{
name: "agent breaking change",
deployedVersion: "0.25.0",
cliVersion: "0.26.0",
breakingChanges: []BreakingChange{
{
version: semver.MustParse("0.26.0"),
title: "Zarf container images are now mutated based on tag instead of repository name.",
mitigation: "Reinitialize the cluster using v0.26.0 or later and redeploy existing packages to update the image references (you can view existing packages with 'zarf package list' and view cluster images with 'zarf tools registry catalog').",
},
},
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var output bytes.Buffer
message.InitializePTerm(&output)
PrintBreakingChanges(&output, tt.deployedVersion, tt.cliVersion)
for _, bc := range tt.breakingChanges {
require.Contains(t, output.String(), bc.String())
}
t.Log(output.String())
})
}
}
67 changes: 0 additions & 67 deletions src/test/e2e/29_mismatched_checks_test.go

This file was deleted.

Loading