Skip to content

Commit

Permalink
handle arch mismatch on zarf package deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-mccoy committed Feb 8, 2022
1 parent 7ed3729 commit 5fb6ce3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
5 changes: 0 additions & 5 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"os"
"runtime"
"strings"

"github.com/defenseunicorns/zarf/cli/config"
Expand All @@ -22,10 +21,6 @@ var rootCmd = &cobra.Command{
if zarfLogLevel != "" {
setLogLevel(zarfLogLevel)
}
if arch == "" {
// Default to the current running arch for images
arch = runtime.GOARCH
}
config.SetAcrch(arch)
},
Short: "Small tool to bundle dependencies with K3s for air-gaped deployments",
Expand Down
17 changes: 15 additions & 2 deletions cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package config

import (
"fmt"
"github.com/defenseunicorns/zarf/cli/types"
"os"
"os/user"
"runtime"
"strings"
"time"

"github.com/defenseunicorns/zarf/cli/types"

"github.com/defenseunicorns/zarf/cli/internal/message"
"github.com/defenseunicorns/zarf/cli/internal/utils"
"github.com/google/go-containerregistry/pkg/crane"
Expand Down Expand Up @@ -58,8 +60,19 @@ func IsZarfInitConfig() bool {
}

func SetAcrch(arch string) {
if arch == "" {
// If not cli override for arch, set to the package arch
arch = config.Metadata.Architecture

if arch == "" {
// Finally, default to current system arch when all else fails
arch = runtime.GOARCH
}
}

message.Debugf("config.SetArch(%s)", arch)
config.Build.Arch = arch
config.Build.Architecture = arch
// Use the arch to define the image push/pull options for crane
ActiveCranePlatform = crane.WithPlatform(&v1.Platform{OS: "linux", Architecture: arch})
}

Expand Down
13 changes: 12 additions & 1 deletion cli/internal/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,26 @@ func deployComponents(tempPath tempPaths, component types.ZarfComponent) {
}

if !valueTemplate.Ready() && (hasImages || hasCharts || hasManifests || hasRepos) {
// If we are touching K8s, make sure we can talk to it once per deployment
spinner := message.NewProgressSpinner("Loading the Zarf State from the Kubernetes cluster")
defer spinner.Stop()

state := k8s.LoadZarfState()
config.InitState(state)
valueTemplate = template.Generate()

if state.Distro == "" {
spinner.Fatalf(nil, "Unable to load the zarf/zarf-state secret")
// If no distro the zarf secret did not load properly
spinner.Fatalf(nil, "Unable to load the zarf/zarf-state secret, did you remember to run zarf init first?")
}

if hasImages && state.Architecture != config.GetBuildData().Architecture {
// If the package has images but the architectures don't match warn the user to avoid ugly hidden errors with image push/pull
spinner.Fatalf(nil, "This package architecture is %s, but this cluster seems to be initailized with the %s architecture",
config.GetBuildData().Architecture,
state.Architecture)
}

spinner.Success()
}

Expand Down
1 change: 1 addition & 0 deletions cli/internal/packager/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func preSeedRegistry(tempPath tempPaths) {
state.Registry.NodePort = "31999"
state.Secret = utils.RandomString(120)
state.Distro = distro
state.Architecture = config.GetBuildData().Architecture
}

switch state.Distro {
Expand Down
12 changes: 7 additions & 5 deletions cli/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type ZarfMetadata struct {
Url string `yaml:"url,omitempty"`
Image string `yaml:"image,omitempty"`
Uncompressed bool `yaml:"uncompressed,omitempty"`
Architecture string `yaml:"architecture,omitempty"`
}

// ZarfContainerTarget defines the destination info for a ZarfData target
Expand All @@ -84,11 +85,11 @@ type ZarfData struct {

// ZarfBuildData is written during the packager.Create() operation to track details of the created package
type ZarfBuildData struct {
Terminal string `yaml:"terminal"`
User string `yaml:"user"`
Arch string `yaml:"arch"`
Timestamp string `yaml:"timestamp"`
Version string `yaml:"string"`
Terminal string `yaml:"terminal"`
User string `yaml:"user"`
Architecture string `yaml:"architecture"`
Timestamp string `yaml:"timestamp"`
Version string `yaml:"string"`
}

// ZarfPackage the top-level structure of a Zarf config file
Expand All @@ -105,6 +106,7 @@ type ZarfPackage struct {
type ZarfState struct {
ZarfAppliance bool `json:"zarfAppliance"`
Distro string `json:"distro"`
Architecture string `json:"architecture"`
StorageClass string `json:"storageClass"`
Secret string `json:"secret"`
Registry struct {
Expand Down
2 changes: 2 additions & 0 deletions examples/big-bang/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ kind: ZarfPackageConfig
metadata:
name: big-bang-core-demo
description: "Demo Zarf basic deployment of Big Bang core"
# Big Bang / Iron Bank are only amd64
architecture: amd64

components:
- name: flux
Expand Down

0 comments on commit 5fb6ce3

Please sign in to comment.