From 5f4151fd7903ecd967aad525bb6d4f06c812c9d9 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Tue, 1 Aug 2023 17:22:06 -0500 Subject: [PATCH] Fix a bug with registry push/pull on detected but invalid clusters (#1930) ## Description This fixes an issue with zarf tools registry where an invalid cluster (one that was not connectable or did not have state) could cause a failure. ## Related Issue Fixes #1929 ## Type of change - [X] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Other (security config, docs update, etc) ## Checklist before merging - [X] Test, docs, adr added or updated as needed - [X] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow) followed --------- Co-authored-by: razzle --- src/cmd/tools/crane.go | 9 +++++---- src/config/lang/english.go | 7 ++++--- .../package/flux-overrides-helm-controller.yaml | 8 ++++---- .../flux-overrides-kustomize-controller.yaml | 17 +++++++++++++++++ .../flux-overrides-notification-controller.yaml | 17 +++++++++++++++++ .../flux-overrides-source-controller.yaml | 6 +++--- src/extensions/bigbang/test/package/zarf.yaml | 2 ++ 7 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 src/extensions/bigbang/test/package/flux-overrides-kustomize-controller.yaml create mode 100644 src/extensions/bigbang/test/package/flux-overrides-notification-controller.yaml diff --git a/src/cmd/tools/crane.go b/src/cmd/tools/crane.go index 8a9b82d445..d7461eef7f 100644 --- a/src/cmd/tools/crane.go +++ b/src/cmd/tools/crane.go @@ -56,7 +56,7 @@ func init() { if platform != "all" { v1Platform, err = v1.ParsePlatform(platform) if err != nil { - message.Fatalf(err, lang.CmdToolsRegistryInvalidPlatformErr, err.Error()) + message.Fatalf(err, lang.CmdToolsRegistryInvalidPlatformErr, platform, err.Error()) } } @@ -137,7 +137,7 @@ func zarfCraneInternalWrapper(commandToWrap func(*[]crane.Option) *cobra.Command wrappedCommand.RunE = func(cmd *cobra.Command, args []string) error { if len(args) < imageNameArgumentIndex+1 { - message.Fatal(nil, lang.CmdToolsCraneNotEnoughArgumentsSpecified) + message.Fatal(nil, lang.CmdToolsCraneNotEnoughArgumentsErr) } // Try to connect to a Zarf initialized cluster otherwise then pass it down to crane. @@ -146,10 +146,11 @@ func zarfCraneInternalWrapper(commandToWrap func(*[]crane.Option) *cobra.Command return originalListFn(cmd, args) } - // Load the state + // Load the state (if able) zarfState, err := zarfCluster.LoadZarfState() if err != nil { - return err + message.Warnf(lang.CmdToolsCraneConnectedButBadStateErr, err.Error()) + return originalListFn(cmd, args) } // Check to see if it matches the existing internal address. diff --git a/src/config/lang/english.go b/src/config/lang/english.go index e3287a6dd1..5ab24d2c93 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -375,7 +375,8 @@ const ( CmdToolsClearCacheSuccess = "Successfully cleared the cache from %s" CmdToolsClearCacheFlagCachePath = "Specify the location of the Zarf artifact cache (images and git repositories)" - CmdToolsCraneNotEnoughArgumentsSpecified = "You do not have enough arguments specified." + CmdToolsCraneNotEnoughArgumentsErr = "You do not have enough arguments specified for this command" + CmdToolsCraneConnectedButBadStateErr = "Detected a K8s cluster but was unable to get Zarf state - continuing without state information: %s" CmdToolsDownloadInitShort = "Downloads the init package for the current Zarf version into the specified directory" CmdToolsDownloadInitFlagOutputDirectory = "Specify a directory to place the init package in." @@ -421,7 +422,7 @@ const ( zarf tools wait-for http google.com success # wait for any 2xx response from http://google.com ` CmdToolsWaitForFlagTimeout = "Specify the timeout duration for the wait command." - CmdToolsWaitForErrTimeoutString = "Invalid timeout duration. Please use a valid duration string (e.g. 1s, 2m, 3h)." + CmdToolsWaitForErrTimeoutString = "Invalid timeout duration '%s'. Please use a valid duration string (e.g. 1s, 2m, 3h)." CmdToolsWaitForErrTimeout = "Wait timed out." CmdToolsWaitForErrConditionString = "Invalid HTTP status code. Please use a valid HTTP status code (e.g. 200, 404, 500)." CmdToolsWaitForErrZarfPath = "Could not locate the current Zarf binary path." @@ -513,7 +514,7 @@ const ( var ( ErrInitNotFound = errors.New("this command requires a zarf-init package, but one was not found on the local system. Re-run the last command again without '--confirm' to download the package") ErrUnableToCheckArch = errors.New("unable to get the configured cluster's architecture") - ErrInterrupt = errors.New("Failed due to interrupt") + ErrInterrupt = errors.New("execution cancelled due to an interrupt") ) // Collection of reusable warn messages. diff --git a/src/extensions/bigbang/test/package/flux-overrides-helm-controller.yaml b/src/extensions/bigbang/test/package/flux-overrides-helm-controller.yaml index db49be63ec..d5e68feaee 100644 --- a/src/extensions/bigbang/test/package/flux-overrides-helm-controller.yaml +++ b/src/extensions/bigbang/test/package/flux-overrides-helm-controller.yaml @@ -10,8 +10,8 @@ spec: - name: manager resources: limits: - cpu: 500m - memory: 1Gi + cpu: 200m + memory: 256Mi requests: - cpu: 500m - memory: 1Gi + cpu: 100m + memory: 64Mi diff --git a/src/extensions/bigbang/test/package/flux-overrides-kustomize-controller.yaml b/src/extensions/bigbang/test/package/flux-overrides-kustomize-controller.yaml new file mode 100644 index 0000000000..22e1d7d16b --- /dev/null +++ b/src/extensions/bigbang/test/package/flux-overrides-kustomize-controller.yaml @@ -0,0 +1,17 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: kustomize-controller + namespace: flux-system +spec: + template: + spec: + containers: + - name: manager + resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 100m + memory: 64Mi diff --git a/src/extensions/bigbang/test/package/flux-overrides-notification-controller.yaml b/src/extensions/bigbang/test/package/flux-overrides-notification-controller.yaml new file mode 100644 index 0000000000..a2476b01d2 --- /dev/null +++ b/src/extensions/bigbang/test/package/flux-overrides-notification-controller.yaml @@ -0,0 +1,17 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: notification-controller + namespace: flux-system +spec: + template: + spec: + containers: + - name: manager + resources: + limits: + cpu: 200m + memory: 256Mi + requests: + cpu: 100m + memory: 64Mi diff --git a/src/extensions/bigbang/test/package/flux-overrides-source-controller.yaml b/src/extensions/bigbang/test/package/flux-overrides-source-controller.yaml index f20c351c5d..292492775a 100644 --- a/src/extensions/bigbang/test/package/flux-overrides-source-controller.yaml +++ b/src/extensions/bigbang/test/package/flux-overrides-source-controller.yaml @@ -11,7 +11,7 @@ spec: resources: limits: cpu: 100m - memory: 384Mi + memory: 256Mi requests: - cpu: 100m - memory: 384Mi + cpu: 50m + memory: 64Mi diff --git a/src/extensions/bigbang/test/package/zarf.yaml b/src/extensions/bigbang/test/package/zarf.yaml index b90bc9953c..426fed8f54 100644 --- a/src/extensions/bigbang/test/package/zarf.yaml +++ b/src/extensions/bigbang/test/package/zarf.yaml @@ -21,6 +21,8 @@ components: fluxPatchFiles: - flux-overrides-helm-controller.yaml - flux-overrides-source-controller.yaml + - flux-overrides-kustomize-controller.yaml + - flux-overrides-notification-controller.yaml valuesFiles: - disable-all-bb###ZARF_PKG_TMPL_BB_MAJOR###.yaml - enable-twistlock.yaml