Skip to content

Commit

Permalink
Merge branch 'v2-upgrades-without-manager' into laverya/fix-TestHostP…
Browse files Browse the repository at this point in the history
…reflightCustomSpec-TestUnsupportedOverrides
  • Loading branch information
laverya committed Feb 1, 2025
2 parents ad3a456 + fbdee2d commit d14ee8e
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 224 deletions.
5 changes: 0 additions & 5 deletions cmd/buildtools/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ var metadataExtractHelmChartImagesCommand = &cli.Command{

repos := metadata.Configs.Repositories
charts := metadata.Configs.Charts
//nolint:staticcheck // SA1019 explanation Using deprecated BuiltinConfigs for backwards compatibility
for _, chart := range metadata.BuiltinConfigs {
repos = append(repos, chart.Repositories...)
charts = append(charts, chart.Charts...)
}

images, err := extractImagesFromHelmExtensions(repos, charts, metadata.Versions["Kubernetes"])
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions cmd/installer/cli/install2.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,10 @@ func gatherVersionMetadata(withChannelRelease bool) (*types.ReleaseMetadata, err
for name, version := range addons2.Versions() {
versionsMap[name] = version
}
for name, version := range extensions.Versions() {
versionsMap[name] = version
if withChannelRelease {
for name, version := range extensions.Versions() {
versionsMap[name] = version
}
}

versionsMap["Kubernetes"] = versions.K0sVersion
Expand Down
40 changes: 1 addition & 39 deletions e2e/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestVersion(t *testing.T) {
}
}

expectedCharts := []string{"openebs", "embedded-cluster-operator", "admin-console", "ingress-nginx", "goldpinger"}
expectedCharts := []string{"openebs", "embedded-cluster-operator", "admin-console", "velero", "seaweedfs", "docker-registry", "ingress-nginx", "goldpinger"}
if len(parsed.Configs.Charts) != len(expectedCharts) {
t.Log(output)
t.Fatalf("found %d charts in metadata, expected %d", len(parsed.Configs.Charts), len(expectedCharts))
Expand All @@ -132,44 +132,6 @@ func TestVersion(t *testing.T) {
}
}

expectedBuiltinConfigsCharts := []string{"velero", "seaweedfs", "registry", "registry-ha"}
//nolint:staticcheck // SA1019 explanation Using deprecated BuiltinConfigs for testing
if len(parsed.BuiltinConfigs) != len(expectedBuiltinConfigsCharts) {
t.Log(output)
//nolint:staticcheck // SA1019 explanation Using deprecated BuiltinConfigs for testing
t.Fatalf("found %d builtin charts in metadata, expected %d", len(parsed.BuiltinConfigs), len(expectedBuiltinConfigsCharts))
}
for _, expectedName := range expectedBuiltinConfigsCharts {
//nolint:staticcheck // SA1019 explanation Using deprecated BuiltinConfigs for testing
if _, ok := parsed.BuiltinConfigs[expectedName]; !ok {
t.Errorf("failed to find builtin chart %s in 'metadata' output", expectedName)
failed = true
}
}

expectedVeleroCharts := []string{"velero"}
//nolint:staticcheck // SA1019 explanation Using deprecated BuiltinConfigs for testing
if len(parsed.BuiltinConfigs["velero"].Charts) != len(expectedVeleroCharts) {
t.Log(output)
//nolint:staticcheck // SA1019 explanation Using deprecated BuiltinConfigs for testing
t.Fatalf("found %d velero charts in metadata, expected %d", len(parsed.BuiltinConfigs["velero"].Charts), len(expectedVeleroCharts))
}

for _, expectedName := range expectedVeleroCharts {
foundName := false
//nolint:staticcheck // SA1019 explanation Using deprecated BuiltinConfigs for testing
for _, foundChart := range parsed.BuiltinConfigs["velero"].Charts {
if foundChart.Name == expectedName {
foundName = true
break
}
}
if !foundName {
t.Errorf("failed to find velero chart %s in 'metadata' output", expectedName)
failed = true
}
}

expectedArtifacts := []string{"k0s", "kots", "operator", "local-artifact-mirror-image"}
if len(parsed.Artifacts) != len(expectedArtifacts) {
t.Log(output)
Expand Down
8 changes: 4 additions & 4 deletions operator/pkg/cli/upgrade_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func UpgradeJobCmd() *cobra.Command {
return fmt.Errorf("failed to create kubernetes client: %w", err)
}

if err := performUpgrade(cmd.Context(), kcli, in); err != nil {
if upgradeErr := performUpgrade(cmd.Context(), kcli, in); upgradeErr != nil {
// if this is the last attempt, mark the installation as failed
if err := maybeMarkAsFailed(cmd.Context(), kcli, in); err != nil {
if err := maybeMarkAsFailed(cmd.Context(), kcli, in, upgradeErr); err != nil {
fmt.Printf("Failed to mark installation as failed: %v", err)
}
return err
Expand Down Expand Up @@ -124,15 +124,15 @@ func attemptUpgrade(ctx context.Context, kcli client.Client, in *ecv1beta1.Insta
return nil
}

func maybeMarkAsFailed(ctx context.Context, kcli client.Client, in *ecv1beta1.Installation) error {
func maybeMarkAsFailed(ctx context.Context, kcli client.Client, in *ecv1beta1.Installation, upgradeErr error) error {
lastAttempt, err := isLastAttempt(ctx, kcli)
if err != nil {
return fmt.Errorf("check if last attempt: %w", err)
}
if !lastAttempt {
return nil
}
if err := k8sutil.SetInstallationState(ctx, kcli, in.Name, ecv1beta1.InstallationStateFailed, helpers.CleanErrorMessage(err)); err != nil {
if err := k8sutil.SetInstallationState(ctx, kcli, in.Name, ecv1beta1.InstallationStateFailed, helpers.CleanErrorMessage(upgradeErr)); err != nil {
return fmt.Errorf("set installation state: %w", err)
}
return nil
Expand Down
153 changes: 0 additions & 153 deletions operator/pkg/release/release_test.go

This file was deleted.

2 changes: 2 additions & 0 deletions operator/pkg/upgrade/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ func CreateUpgradeJob(
Name: "ec-charts-dir",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
// the job gets created by a process inside the kotsadm pod during an upgrade,
// and kots doesn't (and shouldn't) have permissions to create this directory
Path: runtimeconfig.EmbeddedClusterChartsSubDirNoCreate(),
},
},
Expand Down
28 changes: 22 additions & 6 deletions pkg/addons2/embeddedclusteroperator/embeddedclusteroperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
)

type EmbeddedClusterOperator struct {
IsAirgap bool
Proxy *ecv1beta1.ProxySpec
BinaryNameOverride string
ImageRepoOverride string
ImageTagOverride string
UtilsImageOverride string
IsAirgap bool
Proxy *ecv1beta1.ProxySpec
ChartLocationOverride string
ChartVersionOverride string
BinaryNameOverride string
ImageRepoOverride string
ImageTagOverride string
UtilsImageOverride string
}

const (
Expand Down Expand Up @@ -61,3 +63,17 @@ func (e *EmbeddedClusterOperator) ReleaseName() string {
func (e *EmbeddedClusterOperator) Namespace() string {
return namespace
}

func (e *EmbeddedClusterOperator) ChartLocation() string {
if e.ChartLocationOverride != "" {
return e.ChartLocationOverride
}
return Metadata.Location
}

func (e *EmbeddedClusterOperator) ChartVersion() string {
if e.ChartVersionOverride != "" {
return e.ChartVersionOverride
}
return Metadata.Version
}
4 changes: 2 additions & 2 deletions pkg/addons2/embeddedclusteroperator/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func (e *EmbeddedClusterOperator) Install(ctx context.Context, kcli client.Clien

_, err = hcli.Install(ctx, helm.InstallOptions{
ReleaseName: releaseName,
ChartPath: Metadata.Location,
ChartVersion: Metadata.Version,
ChartPath: e.ChartLocation(),
ChartVersion: e.ChartVersion(),
Values: values,
Namespace: namespace,
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/addons2/embeddedclusteroperator/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func (e *EmbeddedClusterOperator) Upgrade(ctx context.Context, kcli client.Clien

_, err = hcli.Upgrade(ctx, helm.UpgradeOptions{
ReleaseName: releaseName,
ChartPath: Metadata.Location,
ChartVersion: Metadata.Version,
ChartPath: e.ChartLocation(),
ChartVersion: e.ChartVersion(),
Values: values,
Namespace: namespace,
Force: true,
Expand Down
6 changes: 4 additions & 2 deletions pkg/addons2/registry/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ func (r *Registry) Upgrade(ctx context.Context, kcli client.Client, hcli *helm.H
}

func (r *Registry) createUpgradePreRequisites(ctx context.Context, kcli client.Client) error {
if err := createS3Secret(ctx, kcli); err != nil {
return errors.Wrap(err, "create s3 secret")
if r.IsHA {
if err := createS3Secret(ctx, kcli); err != nil {
return errors.Wrap(err, "create s3 secret")
}
}

return nil
Expand Down
25 changes: 18 additions & 7 deletions pkg/addons2/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,33 @@ func getAddOnsForUpgrade(in *ecv1beta1.Installation, meta *ectypes.ReleaseMetada
&openebs.OpenEBS{},
}

ecoRepo, ecoTag, ecoUtilsImage, err := operatorImages(meta.Images)
// ECO's embedded (wrong) metadata values do not match the published (correct) metadata values.
// This is because we re-generate the metadata.yaml file _after_ building the ECO binary / image.
// We do that because the SHA of the image needs to be included in the metadata.yaml file.
// HACK: to work around this, override the embedded metadata values with the published ones.
ecoChartLocation, ecoChartVersion, err := operatorChart(meta)
if err != nil {
return nil, errors.Wrap(err, "get operator chart location")
}
ecoImageRepo, ecoImageTag, ecoUtilsImage, err := operatorImages(meta.Images)
if err != nil {
return nil, errors.Wrap(err, "get operator images")
}
addOns = append(addOns, &embeddedclusteroperator.EmbeddedClusterOperator{
IsAirgap: in.Spec.AirGap,
Proxy: in.Spec.Proxy,
BinaryNameOverride: in.Spec.BinaryName,
ImageRepoOverride: ecoRepo,
ImageTagOverride: ecoTag,
UtilsImageOverride: ecoUtilsImage,
IsAirgap: in.Spec.AirGap,
Proxy: in.Spec.Proxy,
ChartLocationOverride: ecoChartLocation,
ChartVersionOverride: ecoChartVersion,
BinaryNameOverride: in.Spec.BinaryName,
ImageRepoOverride: ecoImageRepo,
ImageTagOverride: ecoImageTag,
UtilsImageOverride: ecoUtilsImage,
})

if in.Spec.AirGap {
addOns = append(addOns, &registry.Registry{
ServiceCIDR: in.Spec.Network.ServiceCIDR,
IsHA: in.Spec.HighAvailability,
})

if in.Spec.HighAvailability {
Expand Down
Loading

0 comments on commit d14ee8e

Please sign in to comment.