Skip to content

Commit

Permalink
refactor: remove hpa modified from packager
Browse files Browse the repository at this point in the history
  • Loading branch information
phillebaba committed Jul 3, 2024
1 parent 43e50bb commit b334201
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
8 changes: 8 additions & 0 deletions src/pkg/cluster/zarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ func (c *Cluster) RecordPackageDeployment(ctx context.Context, pkg types.ZarfPac
// EnableRegHPAScaleDown enables the HPA scale down for the Zarf Registry.
func (c *Cluster) EnableRegHPAScaleDown(ctx context.Context) error {
hpa, err := c.Clientset.AutoscalingV2().HorizontalPodAutoscalers(ZarfNamespaceName).Get(ctx, "zarf-docker-registry", metav1.GetOptions{})
// Ignore not found error when HPA is disabled.
if kerrors.IsNotFound(err) {
return err

Check warning on line 255 in src/pkg/cluster/zarf.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/cluster/zarf.go#L255

Added line #L255 was not covered by tests
}
if err != nil {
return err
}
Expand All @@ -265,6 +269,10 @@ func (c *Cluster) EnableRegHPAScaleDown(ctx context.Context) error {
// DisableRegHPAScaleDown disables the HPA scale down for the Zarf Registry.
func (c *Cluster) DisableRegHPAScaleDown(ctx context.Context) error {
hpa, err := c.Clientset.AutoscalingV2().HorizontalPodAutoscalers(ZarfNamespaceName).Get(ctx, "zarf-docker-registry", metav1.GetOptions{})
// Ignore not found error when HPA is disabled.
if kerrors.IsNotFound(err) {
return err

Check warning on line 274 in src/pkg/cluster/zarf.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/cluster/zarf.go#L274

Added line #L274 was not covered by tests
}
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion src/pkg/packager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type Packager struct {
state *types.ZarfState
cluster *cluster.Cluster
layout *layout.PackagePaths
hpaModified bool
connectStrings types.ConnectStrings
sbomViewFiles []string
source sources.PackageSource
Expand Down
25 changes: 10 additions & 15 deletions src/pkg/packager/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ import (
)

func (p *Packager) resetRegistryHPA(ctx context.Context) {
if p.isConnectedToCluster() && p.hpaModified {
if err := p.cluster.EnableRegHPAScaleDown(ctx); err != nil {
message.Debugf("unable to reenable the registry HPA scale down: %s", err.Error())
}
if !p.isConnectedToCluster() {
return

Check warning on line 43 in src/pkg/packager/deploy.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/packager/deploy.go#L42-L43

Added lines #L42 - L43 were not covered by tests
}
err := p.cluster.EnableRegHPAScaleDown(ctx)
if err != nil {
message.Debugf("unable to reenable the registry HPA scale down: %s", err.Error())

Check warning on line 47 in src/pkg/packager/deploy.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/packager/deploy.go#L45-L47

Added lines #L45 - L47 were not covered by tests
}
}

Expand Down Expand Up @@ -106,7 +108,6 @@ func (p *Packager) Deploy(ctx context.Context) error {
}
}

p.hpaModified = false
p.connectStrings = make(types.ConnectStrings)
// Reset registry HPA scale down whether an error occurs or not
defer p.resetRegistryHPA(ctx)
Expand Down Expand Up @@ -249,11 +250,6 @@ func (p *Packager) deployInitComponent(ctx context.Context, component types.Zarf
return nil, nil
}

if isRegistry {
// If we are deploying the registry then mark the HPA as "modified" to set it to Min later
p.hpaModified = true
}

// Before deploying the seed registry, start the injector
if isSeedRegistry {
err := p.cluster.StartInjection(ctx, p.layout.Base, p.layout.Images.Base, component.Images)
Expand Down Expand Up @@ -304,11 +300,10 @@ func (p *Packager) deployComponent(ctx context.Context, component types.ZarfComp
}

// Disable the registry HPA scale down if we are deploying images and it is not already disabled
if hasImages && !p.hpaModified && p.state.RegistryInfo.InternalRegistry {
if err := p.cluster.DisableRegHPAScaleDown(ctx); err != nil {
message.Debugf("unable to disable the registry HPA scale down: %s", err.Error())
} else {
p.hpaModified = true
if hasImages && p.state.RegistryInfo.InternalRegistry {
err := p.cluster.DisableRegHPAScaleDown(ctx)
if err != nil {
return nil, err

Check warning on line 306 in src/pkg/packager/deploy.go

View check run for this annotation

Codecov / codecov/patch

src/pkg/packager/deploy.go#L303-L306

Added lines #L303 - L306 were not covered by tests
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/pkg/packager/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func (p *Packager) DevDeploy(ctx context.Context) error {
if !p.cfg.CreateOpts.NoYOLO {
p.cfg.Pkg.Metadata.YOLO = true
} else {
p.hpaModified = false
// Reset registry HPA scale down whether an error occurs or not
defer p.resetRegistryHPA(ctx)
}
Expand Down

0 comments on commit b334201

Please sign in to comment.