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

chore: remove nascent state tracking #942

Merged
merged 9 commits into from
Sep 25, 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
6 changes: 3 additions & 3 deletions .github/workflows/parallel-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
with:
suffix: ${{ matrix.test }}

test-dev-and-state:
test-dev:
runs-on: ubuntu-latest
needs: build
steps:
Expand All @@ -67,9 +67,9 @@ jobs:
- name: setup-using-previous-job
uses: ./.github/actions/setup-from-previous

- name: Run e2e dev and state tests
- name: Run e2e dev
run: |
build/uds run test:dev-and-state
build/uds run test:dev

- name: Save logs
if: always()
Expand Down
8 changes: 8 additions & 0 deletions design-docs/0001-bundle-state.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Bundle State

### Update September 24th, 2024

After initial rollout we decided to remove state due to unforeseen issues. For
posterity this document is left intact, but the state feature described has been
removed. We will very likely revisit the idea in the future.

------

## Context

The following 2 issues provide context driving the need for a UDS state tracking mechanism:
Expand Down
1 change: 0 additions & 1 deletion docs/command-reference/uds_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ uds deploy [BUNDLE_TARBALL|OCI_REF] [flags]
-c, --confirm Confirms bundle deployment without prompting. ONLY use with bundles you trust
-h, --help help for deploy
-p, --packages stringArray Specify which zarf packages you would like to deploy from the bundle. By default all zarf packages in the bundle are deployed.
-P, --prune Forces the removal of packages that are no longer in the bundle
-r, --resume Only deploys packages from the bundle which haven't already been deployed
--retries int Specify the number of retries for package deployments (applies to all pkgs in a bundle) (default 3)
--set stringToString Specify deployment variables to set on the command line (KEY=value) (default [])
Expand Down
1 change: 0 additions & 1 deletion docs/command-reference/uds_dev_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ uds dev deploy [BUNDLE_DIR|OCI_REF] [flags]
--force-create [beta] For local bundles with local packages, specify whether to create a zarf package even if it already exists.
-h, --help help for deploy
-p, --packages stringArray Specify which zarf packages you would like to deploy from the bundle. By default all zarf packages in the bundle are deployed.
-P, --prune Forces the removal of packages that are no longer in the bundle
-r, --ref stringToString Specify which zarf package ref you want to deploy. By default the ref set in the bundle yaml is used. (default [])
--set stringToString Specify deployment variables to set on the command line (KEY=value) (default [])
```
Expand Down
10 changes: 0 additions & 10 deletions docs/quickstart-and-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ As an example: `uds deploy uds-bundle-<name>.tar.zst --resume`

In the process of upgrading bundles, it's common to swap or remove packages from a `uds-bundle.yaml`. These packages can become `unreferenced`, meaning that they are still deployed to the cluster, but are no longer referenced by a bundle. To remove these packages from the cluster, you can use the `--prune` flag when deploying a bundle.

```bash
uds deploy <bundle> --prune
```

This command will prompt and inform the user of any packages that are unreferenced and will be pruned from the cluster. To skip the prompt, you can add the `--confirm` flag to the command.

{{% alert-note %}}
Currently, pruning will occur _after_ the bundle has been deployed.
{{% /alert-note %}}

#### Pre-Deploy View

When `uds deploy` is executed, the bundle's metadata, along with a list of its packages and each package's overrides and Zarf variables, will be outputted to the terminal. Unlike [`inspect --list-variables`](#viewing-variables), this output will show the value set for each override or Zarf variable. Overrides and variables that have not been set will not be shown in the output.
Expand Down
50 changes: 0 additions & 50 deletions hack/validate-uds-core-state.sh

This file was deleted.

1 change: 0 additions & 1 deletion src/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,4 @@ func init() {
devDeployCmd.Flags().StringVarP(&bundleCfg.DevDeployOpts.FlavorInput, "flavor", "f", "", lang.CmdBundleCreateFlagFlavor)
devDeployCmd.Flags().BoolVar(&bundleCfg.DevDeployOpts.ForceCreate, "force-create", false, lang.CmdBundleCreateForceCreate)
devDeployCmd.Flags().StringToStringVar(&bundleCfg.DeployOpts.SetVariables, "set", nil, lang.CmdBundleDeployFlagSet)
devDeployCmd.Flags().BoolVarP(&bundleCfg.DeployOpts.Prune, "prune", "P", false, lang.CmdBundleDeployFlagPrune)
}
1 change: 0 additions & 1 deletion src/cmd/uds.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ func init() {
deployCmd.Flags().StringArrayVarP(&bundleCfg.DeployOpts.Packages, "packages", "p", []string{}, lang.CmdBundleDeployFlagPackages)
deployCmd.Flags().BoolVarP(&bundleCfg.DeployOpts.Resume, "resume", "r", false, lang.CmdBundleDeployFlagResume)
deployCmd.Flags().IntVar(&bundleCfg.DeployOpts.Retries, "retries", 3, lang.CmdBundleDeployFlagRetries)
deployCmd.Flags().BoolVarP(&bundleCfg.DeployOpts.Prune, "prune", "P", false, lang.CmdBundleDeployFlagPrune)

// inspect cmd flags
rootCmd.AddCommand(inspectCmd)
Expand Down
5 changes: 0 additions & 5 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,3 @@ var (
// BundleAlwaysPull is a list of paths that will always be pulled from the remote repository.
BundleAlwaysPull = []string{BundleYAML, BundleYAMLSignature}
)

// feature flag to enable/disable features
const (
FF_STATE_ENABLED = false
)
1 change: 0 additions & 1 deletion src/config/lang/lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const (
CmdBundleDeployFlagSet = "Specify deployment variables to set on the command line (KEY=value)"
CmdBundleDeployFlagRetries = "Specify the number of retries for package deployments (applies to all pkgs in a bundle)"
CmdBundleDeployFlagRef = "Specify which zarf package ref you want to deploy. By default the ref set in the bundle yaml is used."
CmdBundleDeployFlagPrune = "Forces the removal of packages that are no longer in the bundle"

// bundle inspect
CmdBundleInspectShort = "Display the metadata of a bundle"
Expand Down
14 changes: 14 additions & 0 deletions src/pkg/bundle/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/defenseunicorns/uds-cli/src/types"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/zarf-dev/zarf/src/api/v1alpha1"
"github.com/zarf-dev/zarf/src/pkg/cluster"
"github.com/zarf-dev/zarf/src/pkg/message"
zarfUtils "github.com/zarf-dev/zarf/src/pkg/utils"
"github.com/zarf-dev/zarf/src/pkg/zoci"
Expand Down Expand Up @@ -361,3 +362,16 @@ func (b *Bundle) setPackageRef(pkg types.Package) (types.Package, error) {
}
return pkg, nil
}

// GetDeployedPackageNames returns the names of the packages that have been deployed
func GetDeployedPackageNames() []string {
var deployedPackageNames []string
c, _ := cluster.NewCluster()
if c != nil {
deployedPackages, _ := c.GetDeployedZarfPackages(context.TODO())
for _, pkg := range deployedPackages {
deployedPackageNames = append(deployedPackageNames, pkg.Name)
}
}
return deployedPackageNames
}
92 changes: 5 additions & 87 deletions src/pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ import (
"github.com/defenseunicorns/pkg/helpers/v2"
"github.com/defenseunicorns/uds-cli/src/config"
"github.com/defenseunicorns/uds-cli/src/pkg/sources"
"github.com/defenseunicorns/uds-cli/src/pkg/state"
"github.com/defenseunicorns/uds-cli/src/types"
"github.com/defenseunicorns/uds-cli/src/types/chartvariable"
"github.com/defenseunicorns/uds-cli/src/types/valuesources"
goyaml "github.com/goccy/go-yaml"
"github.com/zarf-dev/zarf/src/api/v1alpha1"
zarfConfig "github.com/zarf-dev/zarf/src/config"
"github.com/zarf-dev/zarf/src/pkg/cluster"
"github.com/zarf-dev/zarf/src/pkg/layout"
"github.com/zarf-dev/zarf/src/pkg/message"
"github.com/zarf-dev/zarf/src/pkg/packager"
Expand Down Expand Up @@ -57,70 +55,23 @@ func (b *Bundle) Deploy() error {
}
}

// get bundle state
var sc *state.Client
var kc *cluster.Cluster
if config.FF_STATE_ENABLED {
message.Debugf("state management disabled, skipping bundle state management")
var err error
var enabledState bool
kc, err = cluster.NewCluster()
if err != nil {
// common scenario for Zarf actions run before cluster is available
enabledState = false
}
sc, err = state.NewClient(kc, enabledState)
if err != nil {
return err
}

err = sc.InitBundleState(&b.bundle, state.Deploying)
if err != nil {
return err
}
} else {
sc = &state.Client{
Enabled: false,
}
}

// if resume, filter for packages not yet deployed
if b.cfg.DeployOpts.Resume {
deployedPackageNames := state.GetDeployedPackageNames()
deployedPackageNames := GetDeployedPackageNames()
var notDeployed []types.Package

for _, pkg := range packagesToDeploy {
if !slices.Contains(deployedPackageNames, pkg.Name) {
notDeployed = append(notDeployed, pkg)
}
packagesToDeploy = notDeployed
}
packagesToDeploy = notDeployed
}

deployErr := deployPackages(sc, packagesToDeploy, b)
if deployErr != nil {
_ = sc.UpdateBundleState(&b.bundle, state.Failed)
return deployErr
}

// update bundle state with success
err := sc.UpdateBundleState(&b.bundle, state.Success)
if err != nil {
return err
}

// prune unreferenced packages
if b.cfg.DeployOpts.Prune {
err = b.handlePrune(sc, kc)
if err != nil {
return err
}
}

return nil
return deployPackages(packagesToDeploy, b)
}

func deployPackages(sc *state.Client, packagesToDeploy []types.Package, b *Bundle) error {
func deployPackages(packagesToDeploy []types.Package, b *Bundle) error {
// map of Zarf pkgs and their vars
bundleExportedVars := make(map[string]map[string]string)

Expand Down Expand Up @@ -198,15 +149,7 @@ func deployPackages(sc *state.Client, packagesToDeploy []types.Package, b *Bundl
return err
}

if pkgDeployErr := pkgClient.Deploy(context.TODO()); pkgDeployErr != nil {
err = sc.UpdateBundlePkgState(&b.bundle, pkg, state.Failed)
if err != nil {
return err
}
return pkgDeployErr
}
err = sc.UpdateBundlePkgState(&b.bundle, pkg, state.Success)
if err != nil {
if err = pkgClient.Deploy(context.TODO()); err != nil {
return err
}

Expand All @@ -223,31 +166,6 @@ func deployPackages(sc *state.Client, packagesToDeploy []types.Package, b *Bundl
}
bundleExportedVars[pkg.Name] = pkgExportedVars

// if state client is still disabled, check for cluster connection
if config.FF_STATE_ENABLED {
if !sc.Enabled {
kc, err := cluster.NewCluster()
if err != nil {
message.Debugf("not connected to cluster, skipping bundle state management")
} else {
message.Debugf("connected to cluster, enabling bundle state management")
sc.Client = kc.Clientset
sc.Enabled = true
err = sc.InitBundleState(&b.bundle, state.Deploying)
if err != nil {
return err
}
// got a cluster now! update UDS state with the pkgs that were deployed before the cluster was up
for j := 0; j <= i; j++ {
err = sc.UpdateBundlePkgState(&b.bundle, packagesToDeploy[j], state.Success)
if err != nil {
return err
}
}
}
}
}

}
return nil
}
Expand Down
Loading
Loading