Skip to content

Commit

Permalink
remove combustion dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
dbw7 committed Mar 14, 2024
1 parent 6f15cb8 commit cb884bb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
3 changes: 2 additions & 1 deletion pkg/cli/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ func bootstrapDependencyServices(ctx *image.Context, rootDir string) bool {
}

if combustion.IsEmbeddedArtifactRegistryConfigured(ctx) {
ctx.HelmClient = helm.New(ctx.BuildDir)
certsDir := filepath.Join(ctx.ImageConfigDir, combustion.K8sDir, combustion.HelmDir, combustion.CertsDir)
ctx.HelmClient = helm.New(ctx.BuildDir, certsDir)
}

if ctx.ImageDefinition.Kubernetes.Version != "" {
Expand Down
23 changes: 12 additions & 11 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"
"strings"

"github.com/suse-edge/edge-image-builder/pkg/combustion"
"github.com/suse-edge/edge-image-builder/pkg/fileio"
"github.com/suse-edge/edge-image-builder/pkg/image"
"go.uber.org/zap"
Expand All @@ -27,11 +26,13 @@ const (

type Helm struct {
outputDir string
certsDir string
}

func New(outputDir string) *Helm {
func New(outputDir, certsDir string) *Helm {
return &Helm{
outputDir: outputDir,
certsDir: certsDir,
}
}

Expand All @@ -56,7 +57,7 @@ func (h *Helm) AddRepo(repo *image.HelmRepository) error {
}
}()

cmd := addRepoCommand(repo, file)
cmd := addRepoCommand(repo, h.certsDir, file)

if _, err = fmt.Fprintf(file, "command: %s\n", cmd); err != nil {
return fmt.Errorf("writing command prefix to log file: %w", err)
Expand All @@ -65,7 +66,7 @@ func (h *Helm) AddRepo(repo *image.HelmRepository) error {
return cmd.Run()
}

func addRepoCommand(repo *image.HelmRepository, output io.Writer) *exec.Cmd {
func addRepoCommand(repo *image.HelmRepository, certsDir string, output io.Writer) *exec.Cmd {
var args []string
args = append(args, "repo", "add", repo.Name, repo.URL)

Expand All @@ -76,7 +77,7 @@ func addRepoCommand(repo *image.HelmRepository, output io.Writer) *exec.Cmd {
if repo.SkipTLSVerify {
args = append(args, "--insecure-skip-tls-verify")
} else if repo.CAFile != "" {
caFilePath := filepath.Join(combustion.K8sDir, combustion.HelmDir, combustion.CertsDir, repo.CAFile)
caFilePath := filepath.Join(certsDir, repo.CAFile)
args = append(args, "--ca-file", caFilePath)
}

Expand Down Expand Up @@ -105,7 +106,7 @@ func (h *Helm) RegistryLogin(repo *image.HelmRepository) error {
return fmt.Errorf("getting host url: %w", err)
}

cmd := registryLoginCommand(host, repo, file)
cmd := registryLoginCommand(host, repo, h.certsDir, file)

if _, err = fmt.Fprintf(file, "command: %s\n", cmd); err != nil {
return fmt.Errorf("writing command prefix to log file: %w", err)
Expand All @@ -114,7 +115,7 @@ func (h *Helm) RegistryLogin(repo *image.HelmRepository) error {
return cmd.Run()
}

func registryLoginCommand(host string, repo *image.HelmRepository, output io.Writer) *exec.Cmd {
func registryLoginCommand(host string, repo *image.HelmRepository, certsDir string, output io.Writer) *exec.Cmd {
var args []string
args = append(args, "registry", "login", host)

Expand All @@ -125,7 +126,7 @@ func registryLoginCommand(host string, repo *image.HelmRepository, output io.Wri
if repo.SkipTLSVerify || repo.PlainHTTP {
args = append(args, "--insecure")
} else if repo.CAFile != "" {
caFilePath := filepath.Join(combustion.K8sDir, combustion.HelmDir, combustion.CertsDir, repo.CAFile)
caFilePath := filepath.Join(certsDir, repo.CAFile)
args = append(args, "--ca-file", caFilePath)
}

Expand All @@ -149,7 +150,7 @@ func (h *Helm) Pull(chart string, repo *image.HelmRepository, version, destDir s
}
}()

cmd := pullCommand(chart, repo, version, destDir, file)
cmd := pullCommand(chart, repo, version, destDir, h.certsDir, file)

if _, err = fmt.Fprintf(file, "command: %s\n", cmd); err != nil {
return "", fmt.Errorf("writing command prefix to log file: %w", err)
Expand All @@ -172,7 +173,7 @@ func (h *Helm) Pull(chart string, repo *image.HelmRepository, version, destDir s
return chartPath, nil
}

func pullCommand(chart string, repo *image.HelmRepository, version, destDir string, output io.Writer) *exec.Cmd {
func pullCommand(chart string, repo *image.HelmRepository, version, destDir, certsDir string, output io.Writer) *exec.Cmd {
repository := repositoryName(repo.Name, repo.URL, chart)

var args []string
Expand All @@ -191,7 +192,7 @@ func pullCommand(chart string, repo *image.HelmRepository, version, destDir stri
case repo.PlainHTTP:
args = append(args, "--plain-http")
case repo.CAFile != "":
caFilePath := filepath.Join(combustion.K8sDir, combustion.HelmDir, combustion.CertsDir, repo.CAFile)
caFilePath := filepath.Join(certsDir, repo.CAFile)
args = append(args, "--ca-file", caFilePath)
}

Expand Down
22 changes: 13 additions & 9 deletions pkg/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package helm

import (
"bytes"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/suse-edge/edge-image-builder/pkg/combustion"
"github.com/suse-edge/edge-image-builder/pkg/image"
)

Expand Down Expand Up @@ -44,6 +42,8 @@ func TestHelmRepositoryName(t *testing.T) {
}

func TestAddRepoCommand(t *testing.T) {
certsDir := "certs"

Check failure on line 45 in pkg/helm/helm_test.go

View workflow job for this annotation

GitHub Actions / lint

string `certs` has 3 occurrences, make it a constant (goconst)

tests := []struct {
name string
repo *image.HelmRepository
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestAddRepoCommand(t *testing.T) {
"--password",
"pass",
"--ca-file",
filepath.Join(combustion.K8sDir, combustion.HelmDir, combustion.CertsDir, "suse-edge.crt"),
"certs/suse-edge.crt",
},
},
}
Expand All @@ -163,7 +163,7 @@ func TestAddRepoCommand(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cmd := addRepoCommand(test.repo, &buf)
cmd := addRepoCommand(test.repo, certsDir, &buf)

assert.Equal(t, test.expectedArgs, cmd.Args)
assert.Equal(t, &buf, cmd.Stdout)
Expand All @@ -173,6 +173,8 @@ func TestAddRepoCommand(t *testing.T) {
}

func TestRegistryLoginCommand(t *testing.T) {
certsDir := "certs"

tests := []struct {
name string
host string
Expand Down Expand Up @@ -271,7 +273,7 @@ func TestRegistryLoginCommand(t *testing.T) {
"--password",
"pass",
"--ca-file",
filepath.Join(combustion.K8sDir, combustion.HelmDir, combustion.CertsDir, "apache.crt"),
"certs/apache.crt",
},
},
}
Expand All @@ -280,7 +282,7 @@ func TestRegistryLoginCommand(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cmd := registryLoginCommand(test.host, test.repo, &buf)
cmd := registryLoginCommand(test.host, test.repo, certsDir, &buf)

assert.Equal(t, test.expectedArgs, cmd.Args)
assert.Equal(t, &buf, cmd.Stdout)
Expand All @@ -290,6 +292,8 @@ func TestRegistryLoginCommand(t *testing.T) {
}

func TestPullCommand(t *testing.T) {
certsDir := "certs"

tests := []struct {
name string
repo *image.HelmRepository
Expand Down Expand Up @@ -451,7 +455,7 @@ func TestPullCommand(t *testing.T) {
"pull",
"suse-edge/kubevirt",
"--ca-file",
filepath.Join(combustion.K8sDir, combustion.HelmDir, combustion.CertsDir, "suse-edge.crt"),
"certs/suse-edge.crt",
},
},
{
Expand All @@ -470,7 +474,7 @@ func TestPullCommand(t *testing.T) {
"pull",
"oci://registry-1.docker.io/bitnamicharts/apache",
"--ca-file",
filepath.Join(combustion.K8sDir, combustion.HelmDir, combustion.CertsDir, "apache.crt"),
"certs/apache.crt",
},
},
}
Expand All @@ -479,7 +483,7 @@ func TestPullCommand(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
cmd := pullCommand(test.chart, test.repo, test.version, test.destDir, &buf)
cmd := pullCommand(test.chart, test.repo, test.version, test.destDir, certsDir, &buf)

assert.Equal(t, test.expectedArgs, cmd.Args)
assert.Equal(t, &buf, cmd.Stdout)
Expand Down

0 comments on commit cb884bb

Please sign in to comment.