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

Move HelmChartInterface to KotsKinds #4056

Merged
merged 2 commits into from
Oct 4, 2023
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ require (
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0
github.com/replicatedhq/kotskinds v0.0.0-20230724164735-f83482cc9cfe
github.com/replicatedhq/kotskinds v0.0.0-20231004174055-e6676d808a82
github.com/replicatedhq/kurlkinds v1.3.6
github.com/replicatedhq/troubleshoot v0.72.1
github.com/replicatedhq/yaml/v3 v3.0.0-beta5-replicatedhq
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1525,8 +1525,8 @@ github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqn
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/replicatedhq/kotskinds v0.0.0-20230724164735-f83482cc9cfe h1:3AJInd06UxzqHmgy8+24CPsT2tYSE0zToJZyuX9q+MA=
github.com/replicatedhq/kotskinds v0.0.0-20230724164735-f83482cc9cfe/go.mod h1:QjhIUu3+OmHZ09u09j3FCoTt8F3BYtQglS+OLmftu9I=
github.com/replicatedhq/kotskinds v0.0.0-20231004174055-e6676d808a82 h1:QniKgIpcXu4wBMM4xIXGz+lkAU+hSIXFuVM+vxkNk0Y=
github.com/replicatedhq/kotskinds v0.0.0-20231004174055-e6676d808a82/go.mod h1:QjhIUu3+OmHZ09u09j3FCoTt8F3BYtQglS+OLmftu9I=
github.com/replicatedhq/kurlkinds v1.3.6 h1:/dhS32cSSZR4yS4vA8EquBvz+VgJCyTqBO9Xw+6eI4M=
github.com/replicatedhq/kurlkinds v1.3.6/go.mod h1:c5+hoAkuARgftB2Ft3RCyWRZZPhL0clHEaw7XoGDAg4=
github.com/replicatedhq/termui/v3 v3.1.1-0.20200811145416-f40076d26851 h1:eRlNDHxGfVkPCRXbA4BfQJvt5DHjFiTtWy3R/t4djyY=
Expand Down
3 changes: 2 additions & 1 deletion pkg/base/replicated.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
kotsv1beta2 "github.com/replicatedhq/kotskinds/apis/kots/v1beta2"
kotsscheme "github.com/replicatedhq/kotskinds/client/kotsclientset/scheme"
"github.com/replicatedhq/kotskinds/pkg/helmchart"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
troubleshootscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
Expand Down Expand Up @@ -502,7 +503,7 @@ func getKotsKinds(u *upstreamtypes.Upstream) (*kotsutil.KotsKinds, error) {

// FindHelmChartArchiveInRelease iterates through all files in the release (upstreamFiles), looking for a helm chart archive
// that matches the chart name and version specified in the kotsHelmChart parameter
func FindHelmChartArchiveInRelease(upstreamFiles []upstreamtypes.UpstreamFile, kotsHelmChart kotsutil.HelmChartInterface) ([]byte, error) {
func FindHelmChartArchiveInRelease(upstreamFiles []upstreamtypes.UpstreamFile, kotsHelmChart helmchart.HelmChartInterface) ([]byte, error) {
for _, upstreamFile := range upstreamFiles {
if !isHelmChart(upstreamFile.Content) {
continue
Expand Down
19 changes: 0 additions & 19 deletions pkg/kotsutil/kots.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,6 @@ type OverlySimpleMetadata struct {
Namespace string `yaml:"namespace"`
}

// HelmChartInterface represents any kots.io HelmChart (v1beta1 or v1beta2)
type HelmChartInterface interface {
GetAPIVersion() string
GetChartName() string
GetChartVersion() string
GetReleaseName() string
GetDirName() string
GetNamespace() string
GetUpgradeFlags() []string
GetWeight() int64
GetHelmVersion() string
GetBuilderValues() (map[string]interface{}, error)
SetChartNamespace(namespace string)
}

// v1beta1 and v1beta2 HelmChart structs must implement HelmChartInterface
var _ HelmChartInterface = (*kotsv1beta1.HelmChart)(nil)
var _ HelmChartInterface = (*kotsv1beta2.HelmChart)(nil)

// KotsKinds are all of the special "client-side" kinds that are packaged in
// an application. These should be pointers because they are all optional.
// But a few are still expected in the code later, so we make them not pointers,
Expand Down
12 changes: 6 additions & 6 deletions pkg/operator/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
appstatetypes "github.com/replicatedhq/kots/pkg/appstate/types"
"github.com/replicatedhq/kots/pkg/binaries"
"github.com/replicatedhq/kots/pkg/k8sutil"
"github.com/replicatedhq/kots/pkg/kotsutil"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/operator/applier"
operatortypes "github.com/replicatedhq/kots/pkg/operator/types"
Expand All @@ -32,6 +31,7 @@ import (
"github.com/replicatedhq/kots/pkg/supportbundle"
supportbundletypes "github.com/replicatedhq/kots/pkg/supportbundle/types"
"github.com/replicatedhq/kots/pkg/util"
"github.com/replicatedhq/kotskinds/pkg/helmchart"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -285,31 +285,31 @@ func (c *Client) deployHelmCharts(deployArgs operatortypes.DeployAppArgs) (*comm
defer os.RemoveAll(curV1Beta2HelmDir)

// find removed charts
prevKotsV1Beta1Charts := []kotsutil.HelmChartInterface{}
prevKotsV1Beta1Charts := []helmchart.HelmChartInterface{}
if deployArgs.PreviousKotsKinds != nil && deployArgs.PreviousKotsKinds.V1Beta1HelmCharts != nil {
for _, kotsChart := range deployArgs.PreviousKotsKinds.V1Beta1HelmCharts.Items {
kc := kotsChart
prevKotsV1Beta1Charts = append(prevKotsV1Beta1Charts, &kc)
}
}

curV1Beta1KotsCharts := []kotsutil.HelmChartInterface{}
curV1Beta1KotsCharts := []helmchart.HelmChartInterface{}
if deployArgs.KotsKinds != nil && deployArgs.KotsKinds.V1Beta1HelmCharts != nil {
for _, kotsChart := range deployArgs.KotsKinds.V1Beta1HelmCharts.Items {
kc := kotsChart
curV1Beta1KotsCharts = append(curV1Beta1KotsCharts, &kc)
}
}

prevKotsV1Beta2Charts := []kotsutil.HelmChartInterface{}
prevKotsV1Beta2Charts := []helmchart.HelmChartInterface{}
if deployArgs.PreviousKotsKinds != nil && deployArgs.PreviousKotsKinds.V1Beta2HelmCharts != nil {
for _, kotsChart := range deployArgs.PreviousKotsKinds.V1Beta2HelmCharts.Items {
kc := kotsChart
prevKotsV1Beta2Charts = append(prevKotsV1Beta2Charts, &kc)
}
}

curV1Beta2KotsCharts := []kotsutil.HelmChartInterface{}
curV1Beta2KotsCharts := []helmchart.HelmChartInterface{}
if deployArgs.KotsKinds != nil && deployArgs.KotsKinds.V1Beta2HelmCharts != nil {
for _, kotsChart := range deployArgs.KotsKinds.V1Beta2HelmCharts.Items {
kc := kotsChart
Expand Down Expand Up @@ -446,7 +446,7 @@ func (c *Client) undeployManifests(undeployArgs operatortypes.UndeployAppArgs) e
}

func (c *Client) undeployHelmCharts(undeployArgs operatortypes.UndeployAppArgs) error {
kotsCharts := []kotsutil.HelmChartInterface{}
kotsCharts := []helmchart.HelmChartInterface{}
if undeployArgs.KotsKinds != nil {
if undeployArgs.KotsKinds.V1Beta1HelmCharts != nil {
for _, v1Beta1Chart := range undeployArgs.KotsKinds.V1Beta1HelmCharts.Items {
Expand Down
28 changes: 14 additions & 14 deletions pkg/operator/client/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"github.com/replicatedhq/kots/pkg/archives"
"github.com/replicatedhq/kots/pkg/helm"
"github.com/replicatedhq/kots/pkg/k8sutil"
"github.com/replicatedhq/kots/pkg/kotsutil"
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/operator/applier"
operatortypes "github.com/replicatedhq/kots/pkg/operator/types"
"github.com/replicatedhq/kots/pkg/util"
"github.com/replicatedhq/kotskinds/pkg/helmchart"
"github.com/replicatedhq/yaml/v3"
corev1 "k8s.io/api/core/v1"
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -250,7 +250,7 @@ func (c *Client) ensureResourcesPresent(deployArgs operatortypes.DeployAppArgs)
return &deployRes, nil
}

func (c *Client) installWithHelm(v1Beta1ChartsDir, v1beta2ChartsDir string, kotsCharts []kotsutil.HelmChartInterface) (*commandResult, error) {
func (c *Client) installWithHelm(v1Beta1ChartsDir, v1beta2ChartsDir string, kotsCharts []helmchart.HelmChartInterface) (*commandResult, error) {
orderedDirs, err := getSortedCharts(v1Beta1ChartsDir, v1beta2ChartsDir, kotsCharts, c.TargetNamespace, false)
if err != nil {
return nil, errors.Wrap(err, "failed to get sorted charts")
Expand Down Expand Up @@ -331,7 +331,7 @@ type orderedDir struct {
APIVersion string
}

func getSortedCharts(v1Beta1ChartsDir string, v1Beta2ChartsDir string, kotsCharts []kotsutil.HelmChartInterface, targetNamespace string, isUninstall bool) ([]orderedDir, error) {
func getSortedCharts(v1Beta1ChartsDir string, v1Beta2ChartsDir string, kotsCharts []helmchart.HelmChartInterface, targetNamespace string, isUninstall bool) ([]orderedDir, error) {
// get a list of the chart directories
foundDirs := []orderedDir{}

Expand Down Expand Up @@ -505,7 +505,7 @@ func findChartNameAndVersionInArchive(archivePath string) (string, string, error
return findChartNameAndVersion(tmpDir)
}

func (c *Client) uninstallWithHelm(v1Beta1ChartsDir, v1Beta2ChartsDir string, kotsCharts []kotsutil.HelmChartInterface) error {
func (c *Client) uninstallWithHelm(v1Beta1ChartsDir, v1Beta2ChartsDir string, kotsCharts []helmchart.HelmChartInterface) error {
orderedDirs, err := getSortedCharts(v1Beta1ChartsDir, v1Beta2ChartsDir, kotsCharts, c.TargetNamespace, true)
if err != nil {
return errors.Wrap(err, "failed to get sorted charts")
Expand Down Expand Up @@ -540,17 +540,17 @@ func (c *Client) uninstallWithHelm(v1Beta1ChartsDir, v1Beta2ChartsDir string, ko
type getRemovedChartsOptions struct {
prevV1Beta1Dir string
curV1Beta1Dir string
previousV1Beta1KotsCharts []kotsutil.HelmChartInterface
currentV1Beta1KotsCharts []kotsutil.HelmChartInterface
previousV1Beta1KotsCharts []helmchart.HelmChartInterface
currentV1Beta1KotsCharts []helmchart.HelmChartInterface
prevV1Beta2Dir string
curV1Beta2Dir string
previousV1Beta2KotsCharts []kotsutil.HelmChartInterface
currentV1Beta2KotsCharts []kotsutil.HelmChartInterface
previousV1Beta2KotsCharts []helmchart.HelmChartInterface
currentV1Beta2KotsCharts []helmchart.HelmChartInterface
}

// getRemovedCharts returns a list of helm release names that were removed in the current version
func getRemovedCharts(opts getRemovedChartsOptions) ([]kotsutil.HelmChartInterface, error) {
prevCharts := []kotsutil.HelmChartInterface{}
func getRemovedCharts(opts getRemovedChartsOptions) ([]helmchart.HelmChartInterface, error) {
prevCharts := []helmchart.HelmChartInterface{}

if opts.prevV1Beta1Dir != "" {
prevV1Beta1ChartsDir := filepath.Join(opts.prevV1Beta1Dir, "charts")
Expand All @@ -570,7 +570,7 @@ func getRemovedCharts(opts getRemovedChartsOptions) ([]kotsutil.HelmChartInterfa
prevCharts = append(prevCharts, matching...)
}

curCharts := []kotsutil.HelmChartInterface{}
curCharts := []helmchart.HelmChartInterface{}

if opts.curV1Beta1Dir != "" {
curV1Beta1ChartsDir := filepath.Join(opts.curV1Beta1Dir, "charts")
Expand All @@ -590,7 +590,7 @@ func getRemovedCharts(opts getRemovedChartsOptions) ([]kotsutil.HelmChartInterfa
curCharts = append(curCharts, matching...)
}

removedCharts := []kotsutil.HelmChartInterface{}
removedCharts := []helmchart.HelmChartInterface{}
for _, prevChart := range prevCharts {
found := false
for _, curChart := range curCharts {
Expand All @@ -612,13 +612,13 @@ func getRemovedCharts(opts getRemovedChartsOptions) ([]kotsutil.HelmChartInterfa
return removedCharts, nil
}

func findMatchingHelmCharts(chartsDir string, kotsCharts []kotsutil.HelmChartInterface) ([]kotsutil.HelmChartInterface, error) {
func findMatchingHelmCharts(chartsDir string, kotsCharts []helmchart.HelmChartInterface) ([]helmchart.HelmChartInterface, error) {
dirContent, err := ioutil.ReadDir(chartsDir)
if err != nil {
return nil, errors.Wrapf(err, "failed to list chart dir %s", chartsDir)
}

matching := []kotsutil.HelmChartInterface{}
matching := []helmchart.HelmChartInterface{}

for _, kotsChart := range kotsCharts {
for _, f := range dirContent {
Expand Down
Loading
Loading