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 3e9cea1
Show file tree
Hide file tree
Showing 3 changed files with 26 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
21 changes: 12 additions & 9 deletions pkg/helm/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ 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"
)

const (
certsDir = "certs"
)

func TestHelmRepositoryName(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -154,7 +156,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 +165,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 +175,7 @@ func TestAddRepoCommand(t *testing.T) {
}

func TestRegistryLoginCommand(t *testing.T) {

tests := []struct {
name string
host string
Expand Down Expand Up @@ -271,7 +274,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 +283,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 Down Expand Up @@ -451,7 +454,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 +473,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 +482,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 3e9cea1

Please sign in to comment.