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

refactor: remove use of k8s deprecations #2560

Merged
merged 3 commits into from
May 30, 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
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.

Loading