Skip to content

Commit

Permalink
refactor: remove use of k8s deprecations (#2560)
Browse files Browse the repository at this point in the history
## Description

Removes use of k8s deprecations functions.

## Related Issue

Relates to #2507

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/.github/CONTRIBUTING.md#developer-workflow)
followed

Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
  • Loading branch information
phillebaba authored and AustinAbro321 committed Jul 23, 2024
1 parent 7957c78 commit f5cecd5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 56 deletions.
53 changes: 41 additions & 12 deletions src/internal/packager/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ import (
"fmt"
"time"

"github.com/defenseunicorns/pkg/helpers"

"github.com/Masterminds/semver/v3"
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/types"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"

"github.com/defenseunicorns/zarf/src/pkg/message"
plutoversionsfile "github.com/fairwindsops/pluto/v5"
plutoapi "github.com/fairwindsops/pluto/v5/pkg/api"
goyaml "github.com/goccy/go-yaml"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/releaseutil"

"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/releaseutil"
"helm.sh/helm/v3/pkg/storage/driver"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/yaml"

"github.com/defenseunicorns/pkg/helpers"

"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/types"
)

// InstallOrUpgradeChart performs a helm install of the given chart.
Expand Down Expand Up @@ -398,7 +400,7 @@ func (h *Helm) migrateDeprecatedAPIs(latestRelease *release.Release) error {
return fmt.Errorf("failed to unmarshal manifest: %#v", err)
}

rawData, manifestModified, _ := h.cluster.HandleDeprecations(rawData, *kubeGitVersion)
rawData, manifestModified, _ := handleDeprecations(rawData, *kubeGitVersion)
manifestContent, err := yaml.Marshal(rawData)
if err != nil {
return fmt.Errorf("failed to marshal raw manifest after deprecation check: %#v", err)
Expand Down Expand Up @@ -437,3 +439,30 @@ func (h *Helm) migrateDeprecatedAPIs(latestRelease *release.Release) error {

return nil
}

// handleDeprecations takes in an unstructured object and the k8s version and returns the latest version of the object and if it was modified.
func handleDeprecations(rawData *unstructured.Unstructured, kubernetesVersion semver.Version) (*unstructured.Unstructured, bool, error) {
deprecatedVersionContent := &plutoapi.VersionFile{}
err := goyaml.Unmarshal(plutoversionsfile.Content(), deprecatedVersionContent)
if err != nil {
return rawData, false, err
}
for _, deprecation := range deprecatedVersionContent.DeprecatedVersions {
if deprecation.Component == "k8s" && deprecation.Kind == rawData.GetKind() && deprecation.Name == rawData.GetAPIVersion() {
removedVersion, err := semver.NewVersion(deprecation.RemovedIn)
if err != nil {
return rawData, false, err
}

if removedVersion.LessThan(&kubernetesVersion) {
if deprecation.ReplacementAPI != "" {
rawData.SetAPIVersion(deprecation.ReplacementAPI)
return rawData, true, nil
}

return nil, true, nil
}
}
}
return rawData, false, nil
}
44 changes: 0 additions & 44 deletions src/pkg/k8s/deprecations.go

This file was deleted.

0 comments on commit f5cecd5

Please sign in to comment.